diff options
Diffstat (limited to 'desktop/node_modules/filenamify')
-rw-r--r-- | desktop/node_modules/filenamify/filenamify-path.d.ts | 8 | ||||
-rw-r--r-- | desktop/node_modules/filenamify/filenamify-path.js | 10 | ||||
-rw-r--r-- | desktop/node_modules/filenamify/filenamify.d.ts | 39 | ||||
-rw-r--r-- | desktop/node_modules/filenamify/filenamify.js | 40 | ||||
-rw-r--r-- | desktop/node_modules/filenamify/index.d.ts | 24 | ||||
-rw-r--r-- | desktop/node_modules/filenamify/index.js | 8 | ||||
-rw-r--r-- | desktop/node_modules/filenamify/license | 9 | ||||
-rw-r--r-- | desktop/node_modules/filenamify/package.json | 54 | ||||
-rw-r--r-- | desktop/node_modules/filenamify/readme.md | 74 |
9 files changed, 266 insertions, 0 deletions
diff --git a/desktop/node_modules/filenamify/filenamify-path.d.ts b/desktop/node_modules/filenamify/filenamify-path.d.ts new file mode 100644 index 0000000..2346602 --- /dev/null +++ b/desktop/node_modules/filenamify/filenamify-path.d.ts @@ -0,0 +1,8 @@ +import filenamify = require('./filenamify'); + +/** +Convert the filename in a path a valid filename and return the augmented path. +*/ +declare const filenamifyPath: (path: string, options?: filenamify.Options) => string; + +export = filenamifyPath; diff --git a/desktop/node_modules/filenamify/filenamify-path.js b/desktop/node_modules/filenamify/filenamify-path.js new file mode 100644 index 0000000..359c119 --- /dev/null +++ b/desktop/node_modules/filenamify/filenamify-path.js @@ -0,0 +1,10 @@ +'use strict'; +const path = require('path'); +const filenamify = require('./filenamify'); + +const filenamifyPath = (filePath, options) => { + filePath = path.resolve(filePath); + return path.join(path.dirname(filePath), filenamify(path.basename(filePath), options)); +}; + +module.exports = filenamifyPath; diff --git a/desktop/node_modules/filenamify/filenamify.d.ts b/desktop/node_modules/filenamify/filenamify.d.ts new file mode 100644 index 0000000..cc17d11 --- /dev/null +++ b/desktop/node_modules/filenamify/filenamify.d.ts @@ -0,0 +1,39 @@ +declare namespace filenamify { + interface Options { + /** + String to use as replacement for reserved filename characters. + + Cannot contain: `<` `>` `:` `"` `/` `\` `|` `?` `*` + + @default '!' + */ + readonly replacement?: string; + + /** + Truncate the filename to the given length. + + Systems generally allow up to 255 characters, but we default to 100 for usability reasons. + + @default 100 + */ + readonly maxLength?: number; + } +} + +/** +Convert a string to a valid filename. + +@example +``` +import filenamify = require('filenamify'); + +filenamify('<foo/bar>'); +//=> 'foo!bar' + +filenamify('foo:"bar"', {replacement: '🐴'}); +//=> 'foo🐴bar' +``` +*/ +declare const filenamify: (string: string, options?: filenamify.Options) => string; + +export = filenamify; diff --git a/desktop/node_modules/filenamify/filenamify.js b/desktop/node_modules/filenamify/filenamify.js new file mode 100644 index 0000000..a548430 --- /dev/null +++ b/desktop/node_modules/filenamify/filenamify.js @@ -0,0 +1,40 @@ +'use strict'; +const trimRepeated = require('trim-repeated'); +const filenameReservedRegex = require('filename-reserved-regex'); +const stripOuter = require('strip-outer'); + +// Doesn't make sense to have longer filenames +const MAX_FILENAME_LENGTH = 100; + +const reControlChars = /[\u0000-\u001f\u0080-\u009f]/g; // eslint-disable-line no-control-regex +const reRelativePath = /^\.+/; +const reTrailingPeriods = /\.+$/; + +const filenamify = (string, options = {}) => { + if (typeof string !== 'string') { + throw new TypeError('Expected a string'); + } + + const replacement = options.replacement === undefined ? '!' : options.replacement; + + if (filenameReservedRegex().test(replacement) && reControlChars.test(replacement)) { + throw new Error('Replacement string cannot contain reserved filename characters'); + } + + string = string.replace(filenameReservedRegex(), replacement); + string = string.replace(reControlChars, replacement); + string = string.replace(reRelativePath, replacement); + string = string.replace(reTrailingPeriods, ''); + + if (replacement.length > 0) { + string = trimRepeated(string, replacement); + string = string.length > 1 ? stripOuter(string, replacement) : string; + } + + string = filenameReservedRegex.windowsNames().test(string) ? string + replacement : string; + string = string.slice(0, typeof options.maxLength === 'number' ? options.maxLength : MAX_FILENAME_LENGTH); + + return string; +}; + +module.exports = filenamify; diff --git a/desktop/node_modules/filenamify/index.d.ts b/desktop/node_modules/filenamify/index.d.ts new file mode 100644 index 0000000..4aea46f --- /dev/null +++ b/desktop/node_modules/filenamify/index.d.ts @@ -0,0 +1,24 @@ +import filenamify = require('./filenamify'); +import filenamifyPath = require('./filenamify-path'); + +declare const filenamifyCombined: { + /** + Convert a string to a valid filename. + + @example + ``` + import filenamify = require('filenamify'); + + filenamify('<foo/bar>'); + //=> 'foo!bar' + + filenamify('foo:"bar"', {replacement: '🐴'}); + //=> 'foo🐴bar' + ``` + */ + (string: string, options?: filenamify.Options): string; + + path: typeof filenamifyPath; +}; + +export = filenamifyCombined; diff --git a/desktop/node_modules/filenamify/index.js b/desktop/node_modules/filenamify/index.js new file mode 100644 index 0000000..260bbd1 --- /dev/null +++ b/desktop/node_modules/filenamify/index.js @@ -0,0 +1,8 @@ +'use strict'; +const filenamify = require('./filenamify'); +const filenamifyPath = require('./filenamify-path'); + +const filenamifyCombined = filenamify; +filenamifyCombined.path = filenamifyPath; + +module.exports = filenamify; diff --git a/desktop/node_modules/filenamify/license b/desktop/node_modules/filenamify/license new file mode 100644 index 0000000..fa7ceba --- /dev/null +++ b/desktop/node_modules/filenamify/license @@ -0,0 +1,9 @@ +MIT License + +Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com) + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/desktop/node_modules/filenamify/package.json b/desktop/node_modules/filenamify/package.json new file mode 100644 index 0000000..9b22083 --- /dev/null +++ b/desktop/node_modules/filenamify/package.json @@ -0,0 +1,54 @@ +{ + "name": "filenamify", + "version": "4.3.0", + "description": "Convert a string to a valid safe filename", + "license": "MIT", + "repository": "sindresorhus/filenamify", + "funding": "https://github.com/sponsors/sindresorhus", + "author": { + "name": "Sindre Sorhus", + "email": "sindresorhus@gmail.com", + "url": "https://sindresorhus.com" + }, + "engines": { + "node": ">=8" + }, + "scripts": { + "test": "xo && ava && tsd" + }, + "files": [ + "filenamify-path.d.ts", + "filenamify-path.js", + "filenamify.d.ts", + "filenamify.js", + "index.d.ts", + "index.js" + ], + "exports": { + ".": "./index.js", + "./browser": "./filenamify.js" + }, + "keywords": [ + "filename", + "safe", + "sanitize", + "file", + "name", + "string", + "path", + "filepath", + "convert", + "valid", + "dirname" + ], + "dependencies": { + "filename-reserved-regex": "^2.0.0", + "strip-outer": "^1.0.1", + "trim-repeated": "^1.0.0" + }, + "devDependencies": { + "ava": "^1.4.1", + "tsd": "^0.7.1", + "xo": "^0.24.0" + } +} diff --git a/desktop/node_modules/filenamify/readme.md b/desktop/node_modules/filenamify/readme.md new file mode 100644 index 0000000..3b0d747 --- /dev/null +++ b/desktop/node_modules/filenamify/readme.md @@ -0,0 +1,74 @@ +# filenamify + +> Convert a string to a valid safe filename + +On Unix-like systems, `/` is reserved. On Windows, [`<>:"/\|?*`](http://msdn.microsoft.com/en-us/library/aa365247%28VS.85%29#naming_conventions) along with trailing periods are reserved. + +## Install + +``` +$ npm install filenamify +``` + +## Usage + +```js +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. + +```js +const filenamify = require('filenamify/browser'); + +filenamify('<foo/bar>'); +//=> 'foo!bar' +``` + +## Related + +- [filenamify-cli](https://github.com/sindresorhus/filenamify-cli) - CLI for this module +- [filenamify-url](https://github.com/sindresorhus/filenamify-url) - Convert a URL to a valid filename +- [valid-filename](https://github.com/sindresorhus/valid-filename) - Check if a string is a valid filename +- [unused-filename](https://github.com/sindresorhus/unused-filename) - Get a unused filename by appending a number if it exists +- [slugify](https://github.com/sindresorhus/slugify) - Slugify a string |