@cjser/filenamify 7.0.1-cjser.2 → 7.0.2-cjser.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist-cjser/browser.cjs +10 -4
- package/dist-cjser/index.cjs +12 -6
- package/filenamify.js +14 -3
- package/package.json +3 -3
package/dist-cjser/browser.cjs
CHANGED
|
@@ -26,7 +26,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
26
26
|
));
|
|
27
27
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
28
|
|
|
29
|
-
// packages/@cjser/filenamify.tmp-26-
|
|
29
|
+
// packages/@cjser/filenamify.tmp-26-1781714412105/filenamify.js
|
|
30
30
|
var filenamify_exports = {};
|
|
31
31
|
__export(filenamify_exports, {
|
|
32
32
|
default: () => filenamify
|
|
@@ -61,6 +61,14 @@ function truncateFilename(filename, maxLength) {
|
|
|
61
61
|
const truncatedBase = truncateByGraphemeBudget(base, baseBudget);
|
|
62
62
|
return truncatedBase.replace(/ +$/, "") + extension;
|
|
63
63
|
}
|
|
64
|
+
function ensureNonWindowsReservedName(filename, replacement) {
|
|
65
|
+
const extensionIndex = filename.indexOf(".");
|
|
66
|
+
const base = extensionIndex === -1 ? filename : filename.slice(0, extensionIndex);
|
|
67
|
+
if (!(0, import_filename_reserved_regex.windowsReservedNameRegex)().test(base)) {
|
|
68
|
+
return filename;
|
|
69
|
+
}
|
|
70
|
+
return extensionIndex === -1 ? filename + replacement : base + replacement + filename.slice(extensionIndex);
|
|
71
|
+
}
|
|
64
72
|
function filenamify(string, options = {}) {
|
|
65
73
|
if (typeof string !== "string") {
|
|
66
74
|
throw new TypeError("Expected a string");
|
|
@@ -90,9 +98,7 @@ function filenamify(string, options = {}) {
|
|
|
90
98
|
const allowedLength = typeof options.maxLength === "number" ? options.maxLength : MAX_FILENAME_LENGTH;
|
|
91
99
|
string = truncateFilename(string, allowedLength);
|
|
92
100
|
string = string.replace(reTrailingDotsAndSpaces, "");
|
|
93
|
-
|
|
94
|
-
string += replacement;
|
|
95
|
-
}
|
|
101
|
+
string = ensureNonWindowsReservedName(string, replacement);
|
|
96
102
|
return string;
|
|
97
103
|
}
|
|
98
104
|
function truncateByGraphemeBudget(input, budget) {
|
package/dist-cjser/index.cjs
CHANGED
|
@@ -26,7 +26,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
26
26
|
));
|
|
27
27
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
28
|
|
|
29
|
-
// packages/@cjser/filenamify.tmp-26-
|
|
29
|
+
// packages/@cjser/filenamify.tmp-26-1781714412105/index.js
|
|
30
30
|
var index_exports = {};
|
|
31
31
|
__export(index_exports, {
|
|
32
32
|
default: () => filenamify,
|
|
@@ -34,7 +34,7 @@ __export(index_exports, {
|
|
|
34
34
|
});
|
|
35
35
|
module.exports = __toCommonJS(index_exports);
|
|
36
36
|
|
|
37
|
-
// packages/@cjser/filenamify.tmp-26-
|
|
37
|
+
// packages/@cjser/filenamify.tmp-26-1781714412105/filenamify.js
|
|
38
38
|
var import_filename_reserved_regex = __toESM(require("@cjser/filename-reserved-regex"), 1);
|
|
39
39
|
var MAX_FILENAME_LENGTH = 100;
|
|
40
40
|
var reRelativePath = /^\.+(\\|\/)|^\.+$/;
|
|
@@ -64,6 +64,14 @@ function truncateFilename(filename, maxLength) {
|
|
|
64
64
|
const truncatedBase = truncateByGraphemeBudget(base, baseBudget);
|
|
65
65
|
return truncatedBase.replace(/ +$/, "") + extension;
|
|
66
66
|
}
|
|
67
|
+
function ensureNonWindowsReservedName(filename, replacement) {
|
|
68
|
+
const extensionIndex = filename.indexOf(".");
|
|
69
|
+
const base = extensionIndex === -1 ? filename : filename.slice(0, extensionIndex);
|
|
70
|
+
if (!(0, import_filename_reserved_regex.windowsReservedNameRegex)().test(base)) {
|
|
71
|
+
return filename;
|
|
72
|
+
}
|
|
73
|
+
return extensionIndex === -1 ? filename + replacement : base + replacement + filename.slice(extensionIndex);
|
|
74
|
+
}
|
|
67
75
|
function filenamify(string, options = {}) {
|
|
68
76
|
if (typeof string !== "string") {
|
|
69
77
|
throw new TypeError("Expected a string");
|
|
@@ -93,9 +101,7 @@ function filenamify(string, options = {}) {
|
|
|
93
101
|
const allowedLength = typeof options.maxLength === "number" ? options.maxLength : MAX_FILENAME_LENGTH;
|
|
94
102
|
string = truncateFilename(string, allowedLength);
|
|
95
103
|
string = string.replace(reTrailingDotsAndSpaces, "");
|
|
96
|
-
|
|
97
|
-
string += replacement;
|
|
98
|
-
}
|
|
104
|
+
string = ensureNonWindowsReservedName(string, replacement);
|
|
99
105
|
return string;
|
|
100
106
|
}
|
|
101
107
|
function truncateByGraphemeBudget(input, budget) {
|
|
@@ -115,7 +121,7 @@ function truncateByGraphemeBudget(input, budget) {
|
|
|
115
121
|
return output;
|
|
116
122
|
}
|
|
117
123
|
|
|
118
|
-
// packages/@cjser/filenamify.tmp-26-
|
|
124
|
+
// packages/@cjser/filenamify.tmp-26-1781714412105/filenamify-path.js
|
|
119
125
|
var import_node_path = __toESM(require("node:path"), 1);
|
|
120
126
|
function filenamifyPath(filePath, options) {
|
|
121
127
|
filePath = import_node_path.default.resolve(filePath);
|
package/filenamify.js
CHANGED
|
@@ -47,6 +47,19 @@ function truncateFilename(filename, maxLength) {
|
|
|
47
47
|
return truncatedBase.replace(/ +$/, '') + extension;
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
+
function ensureNonWindowsReservedName(filename, replacement) {
|
|
51
|
+
const extensionIndex = filename.indexOf('.');
|
|
52
|
+
const base = extensionIndex === -1 ? filename : filename.slice(0, extensionIndex);
|
|
53
|
+
|
|
54
|
+
if (!windowsReservedNameRegex().test(base)) {
|
|
55
|
+
return filename;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return extensionIndex === -1
|
|
59
|
+
? filename + replacement
|
|
60
|
+
: base + replacement + filename.slice(extensionIndex);
|
|
61
|
+
}
|
|
62
|
+
|
|
50
63
|
export default function filenamify(string, options = {}) {
|
|
51
64
|
if (typeof string !== 'string') {
|
|
52
65
|
throw new TypeError('Expected a string');
|
|
@@ -100,9 +113,7 @@ export default function filenamify(string, options = {}) {
|
|
|
100
113
|
|
|
101
114
|
// Check for Windows reserved names after truncation and stripping
|
|
102
115
|
// Windows compatibility takes precedence over maxLength, so we add suffix even if it exceeds limit
|
|
103
|
-
|
|
104
|
-
string += replacement;
|
|
105
|
-
}
|
|
116
|
+
string = ensureNonWindowsReservedName(string, replacement);
|
|
106
117
|
|
|
107
118
|
return string;
|
|
108
119
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cjser/filenamify",
|
|
3
|
-
"version": "7.0.
|
|
3
|
+
"version": "7.0.2-cjser.2",
|
|
4
4
|
"description": "Convert a string to a valid safe filename",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -65,11 +65,11 @@
|
|
|
65
65
|
"types": "./index.d.ts",
|
|
66
66
|
"main": "./dist-cjser/index.cjs",
|
|
67
67
|
"cjser": {
|
|
68
|
-
"sourceVersion": "7.0.
|
|
68
|
+
"sourceVersion": "7.0.2",
|
|
69
69
|
"cjserVersion": 2,
|
|
70
70
|
"original": {
|
|
71
71
|
"name": "filenamify",
|
|
72
|
-
"version": "7.0.
|
|
72
|
+
"version": "7.0.2",
|
|
73
73
|
"exports": {
|
|
74
74
|
".": {
|
|
75
75
|
"types": "./index.d.ts",
|