chunpu / escape-filename

:pencil: Convert string to safe filename for Unix or Windows, But still look similar

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

escape-filename

Convert string to safe filename for Unix or Windows, But still look similar for reading

  • Unix-like System Rereserved: /
  • Windows System Rereserved: <>:"/\|?*

Install

$ npm install escape-filename

Usage

const escapeFile = require('escape-filename')
const fs = require('fs')

const str = 'foo / bar : | * \\.test'
const escaped = escapeFile.escape(str)
// => "foo ∕ bar ꞉ ❘ ﹡ ﹨.test"

fs.writeFile(escaped, 'test filename', err => {
  if (!err) {
    console.log('write success')
  }
})

Api

escapeFile.escape(fileName)

Escape filename

escapeFile.unescape(escapedFileName)

Unescape filename

escapeFile.isEqual(fileName, escapedFileName)

Compare two string after unescape filename

Reference

License

ISC

About

:pencil: Convert string to safe filename for Unix or Windows, But still look similar


Languages

Language:JavaScript 100.0%