CityBEM-CityLayers-SaeedRay.../node_modules/filenamify
2024-11-05 15:01:14 -05:00
..
filenamify-path.d.ts This commit pushes the node_modules folder separately due to its large size. 2024-11-05 15:01:14 -05:00
filenamify-path.js This commit pushes the node_modules folder separately due to its large size. 2024-11-05 15:01:14 -05:00
filenamify.d.ts This commit pushes the node_modules folder separately due to its large size. 2024-11-05 15:01:14 -05:00
filenamify.js This commit pushes the node_modules folder separately due to its large size. 2024-11-05 15:01:14 -05:00
index.d.ts This commit pushes the node_modules folder separately due to its large size. 2024-11-05 15:01:14 -05:00
index.js This commit pushes the node_modules folder separately due to its large size. 2024-11-05 15:01:14 -05:00
license This commit pushes the node_modules folder separately due to its large size. 2024-11-05 15:01:14 -05:00
package.json This commit pushes the node_modules folder separately due to its large size. 2024-11-05 15:01:14 -05:00
readme.md This commit pushes the node_modules folder separately due to its large size. 2024-11-05 15:01:14 -05:00

filenamify

Convert a string to a valid safe filename

On Unix-like systems, / is reserved. On Windows, <>:"/\|?* along with trailing periods are reserved.

Install

$ npm install filenamify

Usage

const filenamify = require('filenamify');

filenamify('<foo/bar>');
//=> 'foo!bar'

filenamify('foo:"bar"', {replacement: '🐴'});
//=> 'foo🐴bar'

API

filenamify(string, options?)

Convert a string to a valid filename.

filenamify.path(path, options?)

Convert the filename in a path a valid filename and return the augmented path.

options

Type: object

replacement

Type: string
Default: '!'

String to use as replacement for reserved filename characters.

Cannot contain: < > : " / \ | ? *

maxLength

Type: number
Default: 100

Truncate the filename to the given length.

Systems generally allow up to 255 characters, but we default to 100 for usability reasons.

Browser-only import

You can also import filenamify/browser, which only imports filenamify and not filenamify.path, which relies on path being available or polyfilled. Importing filenamify this way is therefore useful when it is shipped using webpack or similar tools, and if filenamify.path is not needed.

const filenamify = require('filenamify/browser');

filenamify('<foo/bar>');
//=> 'foo!bar'