aboutsummaryrefslogtreecommitdiff
path: root/node_modules/filenamify
diff options
context:
space:
mode:
authorMinteck <nekostarfan@gmail.com>2021-08-24 14:41:48 +0200
committerMinteck <nekostarfan@gmail.com>2021-08-24 14:41:48 +0200
commitd25e11bee6ca5ca523884da132d18e1400e077b9 (patch)
tree8af39fde19f7ed640a60fb397c7edd647dff1c4c /node_modules/filenamify
downloadkartik-iridium-d25e11bee6ca5ca523884da132d18e1400e077b9.tar.gz
kartik-iridium-d25e11bee6ca5ca523884da132d18e1400e077b9.tar.bz2
kartik-iridium-d25e11bee6ca5ca523884da132d18e1400e077b9.zip
Initial commit
Diffstat (limited to 'node_modules/filenamify')
-rw-r--r--node_modules/filenamify/index.d.ts30
-rw-r--r--node_modules/filenamify/index.js45
-rw-r--r--node_modules/filenamify/license9
-rw-r--r--node_modules/filenamify/package.json45
-rw-r--r--node_modules/filenamify/readme.md69
5 files changed, 198 insertions, 0 deletions
diff --git a/node_modules/filenamify/index.d.ts b/node_modules/filenamify/index.d.ts
new file mode 100644
index 0000000..9f6ce0a
--- /dev/null
+++ b/node_modules/filenamify/index.d.ts
@@ -0,0 +1,30 @@
+export interface Options {
+ /**
+ * String to use as replacement for reserved filename characters.
+ *
+ * Cannot contain: `<` `>` `:` `"` `/` `\` `|` `?` `*`
+ *
+ * @default '!'
+ */
+ readonly replacement?: string;
+}
+
+/**
+ * Accepts a filename and returns a valid filename.
+ *
+ * @param input - A string to convert to a valid filename.
+ */
+export interface Filenamify {
+ (input: string, options?: Options): string;
+
+ /**
+ * Accepts a path and returns the path with a valid filename.
+ *
+ * @param input - A string to convert to a valid path with a filename.
+ */
+ path(input: string, options?: Options): string;
+}
+
+declare const filenamify: Filenamify;
+
+export default filenamify;
diff --git a/node_modules/filenamify/index.js b/node_modules/filenamify/index.js
new file mode 100644
index 0000000..7993d46
--- /dev/null
+++ b/node_modules/filenamify/index.js
@@ -0,0 +1,45 @@
+'use strict';
+const path = require('path');
+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 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);
+
+ 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, MAX_FILENAME_LENGTH);
+
+ return string;
+};
+
+filenamify.path = (filePath, options) => {
+ filePath = path.resolve(filePath);
+ return path.join(path.dirname(filePath), filenamify(path.basename(filePath), options));
+};
+
+module.exports = filenamify;
+module.exports.default = filenamify;
diff --git a/node_modules/filenamify/license b/node_modules/filenamify/license
new file mode 100644
index 0000000..e7af2f7
--- /dev/null
+++ b/node_modules/filenamify/license
@@ -0,0 +1,9 @@
+MIT License
+
+Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (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/node_modules/filenamify/package.json b/node_modules/filenamify/package.json
new file mode 100644
index 0000000..11f7625
--- /dev/null
+++ b/node_modules/filenamify/package.json
@@ -0,0 +1,45 @@
+{
+ "name": "filenamify",
+ "version": "3.0.0",
+ "description": "Convert a string to a valid safe filename",
+ "license": "MIT",
+ "repository": "sindresorhus/filenamify",
+ "author": {
+ "name": "Sindre Sorhus",
+ "email": "sindresorhus@gmail.com",
+ "url": "sindresorhus.com"
+ },
+ "engines": {
+ "node": ">=6"
+ },
+ "scripts": {
+ "test": "xo && ava && tsd-check"
+ },
+ "files": [
+ "index.js",
+ "index.d.ts"
+ ],
+ "keywords": [
+ "filename",
+ "safe",
+ "sanitize",
+ "file",
+ "name",
+ "string",
+ "path",
+ "filepath",
+ "convert",
+ "valid",
+ "dirname"
+ ],
+ "dependencies": {
+ "filename-reserved-regex": "^2.0.0",
+ "strip-outer": "^1.0.0",
+ "trim-repeated": "^1.0.0"
+ },
+ "devDependencies": {
+ "ava": "^1.3.1",
+ "tsd-check": "^0.3.0",
+ "xo": "^0.24.0"
+ }
+}
diff --git a/node_modules/filenamify/readme.md b/node_modules/filenamify/readme.md
new file mode 100644
index 0000000..b0365e6
--- /dev/null
+++ b/node_modules/filenamify/readme.md
@@ -0,0 +1,69 @@
+# filenamify [![Build Status](https://travis-ci.org/sindresorhus/filenamify.svg?branch=master)](https://travis-ci.org/sindresorhus/filenamify)
+
+> Convert a string to a valid safe filename
+
+On Unix-like systems `/` is reserved and [`<>:"/\|?*`](http://msdn.microsoft.com/en-us/library/aa365247%28VS.85%29#naming_conventions) on Windows.
+
+
+## Install
+
+```
+$ npm install filenamify
+```
+
+
+## Usage
+
+```js
+const filenamify = require('filenamify');
+
+filenamify('<foo/bar>');
+//=> 'foo!bar'
+
+filenamify('foo:"bar"', {replacement: '🐴'});
+//=> 'foo🐴bar'
+```
+
+
+## API
+
+### filenamify(input, [options])
+
+Accepts a filename and returns a valid filename.
+
+### filenamify.path(input, [options])
+
+Accepts a path and returns the path with a valid filename.
+
+#### input
+
+Type: `string`
+
+A string to convert to a valid filename.
+
+#### options
+
+Type: `Object`
+
+##### replacement
+
+Type: `string`<br>
+Default: `'!'`
+
+String to use as replacement for reserved filename characters.
+
+Cannot contain: `<` `>` `:` `"` `/` `\` `|` `?` `*`
+
+
+## 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
+
+
+## License
+
+MIT © [Sindre Sorhus](https://sindresorhus.com)