filenamify
Advanced tools
Comparing version 5.1.1 to 6.0.0
@@ -1,2 +0,2 @@ | ||
import {Options} from './filenamify.js'; | ||
import {type Options} from './filenamify.js'; | ||
@@ -16,2 +16,2 @@ /** | ||
export {Options} from './filenamify.js'; | ||
export type {Options} from './filenamify.js'; |
@@ -1,2 +0,2 @@ | ||
export interface Options { | ||
export type Options = { | ||
/** | ||
@@ -21,3 +21,3 @@ String to use as replacement for reserved filename characters. | ||
readonly maxLength?: number; | ||
} | ||
}; | ||
@@ -32,8 +32,8 @@ /** | ||
filenamify('<foo/bar>'); | ||
//=> 'foo!bar' | ||
//=> '!foo!bar!' | ||
filenamify('foo:"bar"', {replacement: '🐴'}); | ||
//=> 'foo🐴bar' | ||
//=> 'foo🐴bar🐴' | ||
``` | ||
*/ | ||
export default function filenamify(string: string, options?: Options): string; |
@@ -1,4 +0,2 @@ | ||
import trimRepeated from 'trim-repeated'; | ||
import filenameReservedRegex, {windowsReservedNameRegex} from 'filename-reserved-regex'; | ||
import stripOuter from 'strip-outer'; | ||
@@ -8,3 +6,2 @@ // Doesn't make sense to have longer filenames | ||
const reControlChars = /[\u0000-\u001F\u0080-\u009F]/g; // eslint-disable-line no-control-regex | ||
const reRelativePath = /^\.+(\\|\/)|^\.+$/; | ||
@@ -14,2 +11,5 @@ const reTrailingPeriods = /\.+$/; | ||
export default function filenamify(string, options = {}) { | ||
const reControlChars = /[\u0000-\u001F\u0080-\u009F]/g; // eslint-disable-line no-control-regex | ||
const reRepeatedReservedCharacters = /([<>:"/\\|?*\u0000-\u001F]){2,}/g; // eslint-disable-line no-control-regex | ||
if (typeof string !== 'string') { | ||
@@ -25,2 +25,6 @@ throw new TypeError('Expected a string'); | ||
if (replacement.length > 0) { | ||
string = string.replace(reRepeatedReservedCharacters, '$1'); | ||
} | ||
string = string.normalize('NFD'); | ||
@@ -35,5 +39,2 @@ string = string.replace(reRelativePath, replacement); | ||
string = trimRepeated(string, replacement); | ||
string = string.length > 1 ? stripOuter(string, replacement) : string; | ||
// We removed the whole filename | ||
@@ -40,0 +41,0 @@ if (!startedWithDot && string[0] === '.') { |
{ | ||
"name": "filenamify", | ||
"version": "5.1.1", | ||
"version": "6.0.0", | ||
"description": "Convert a string to a valid safe filename", | ||
@@ -19,3 +19,3 @@ "license": "MIT", | ||
"engines": { | ||
"node": ">=12.20" | ||
"node": ">=16" | ||
}, | ||
@@ -47,11 +47,9 @@ "scripts": { | ||
"dependencies": { | ||
"filename-reserved-regex": "^3.0.0", | ||
"strip-outer": "^2.0.0", | ||
"trim-repeated": "^2.0.0" | ||
"filename-reserved-regex": "^3.0.0" | ||
}, | ||
"devDependencies": { | ||
"ava": "^3.15.0", | ||
"tsd": "^0.18.0", | ||
"xo": "^0.45.0" | ||
"ava": "^5.2.0", | ||
"tsd": "^0.28.1", | ||
"xo": "^0.54.1" | ||
} | ||
} |
@@ -19,6 +19,6 @@ # filenamify | ||
filenamify('<foo/bar>'); | ||
//=> 'foo!bar' | ||
//=> '!foo!bar!' | ||
filenamify('foo:"bar"', {replacement: '🐴'}); | ||
//=> 'foo🐴bar' | ||
//=> 'foo🐴bar🐴' | ||
``` | ||
@@ -75,3 +75,3 @@ | ||
filenamify('<foo/bar>'); | ||
//=> 'foo!bar' | ||
//=> '!foo!bar!' | ||
``` | ||
@@ -78,0 +78,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1
8288
- Removedstrip-outer@^2.0.0
- Removedtrim-repeated@^2.0.0
- Removedescape-string-regexp@5.0.0(transitive)
- Removedstrip-outer@2.0.0(transitive)
- Removedtrim-repeated@2.0.0(transitive)