@constructive-io/upload-names 2.5.0 → 2.7.0
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/esm/index.js +6 -4
- package/esm/slugify.js +6 -4
- package/index.d.ts +2 -2
- package/index.js +6 -4
- package/package.json +3 -3
- package/slugify.js +6 -4
package/esm/index.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { basename, extname } from 'path';
|
|
2
2
|
import slugify from './slugify';
|
|
3
|
-
export default (filename, { english = true, lower = true,
|
|
3
|
+
export default (filename, { english = true, lower = true, delimiter = '-' } = {}) => {
|
|
4
4
|
// Step 1: Normalize input
|
|
5
5
|
filename = filename.trim().replace(/\.{2,}/g, '.'); // collapse double dots
|
|
6
6
|
const ext = extname(filename);
|
|
7
7
|
const base = basename(filename, ext);
|
|
8
8
|
// Step 2: Normalize base name
|
|
9
9
|
const name = base
|
|
10
|
-
.replace(/\s+/g,
|
|
11
|
-
.replace(new RegExp(`${
|
|
10
|
+
.replace(/\s+/g, delimiter)
|
|
11
|
+
.replace(new RegExp(`${delimiter}{2,}`, 'g'), delimiter)
|
|
12
12
|
.trim();
|
|
13
13
|
// Step 3: Sluggify (ASCII-only if english = true)
|
|
14
14
|
let slug = name;
|
|
@@ -20,6 +20,8 @@ export default (filename, { english = true, lower = true, delimeter = '-' } = {}
|
|
|
20
20
|
throw new Error(`BAD_FILE_NAME ${name}`);
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
|
-
|
|
23
|
+
// Slugify extension separately; re-add the dot since slugify strips leading dots
|
|
24
|
+
const sanitizedExt = ext ? `.${slugify(ext)}` : '';
|
|
25
|
+
const result = english ? `${slug}${sanitizedExt}` : `${name}${ext}`;
|
|
24
26
|
return lower ? result.toLowerCase() : result;
|
|
25
27
|
};
|
package/esm/slugify.js
CHANGED
|
@@ -2,8 +2,10 @@ export default (text) => {
|
|
|
2
2
|
text = text.toString().trim();
|
|
3
3
|
text = text.normalize('NFD').replace(/[\u0300-\u036f]/g, '');
|
|
4
4
|
return text
|
|
5
|
-
.replace(
|
|
6
|
-
.replace(
|
|
7
|
-
.replace(
|
|
8
|
-
.replace(
|
|
5
|
+
.replace(/[^a-zA-Z0-9._-]/g, '-')
|
|
6
|
+
.replace(/\.{2,}/g, '.')
|
|
7
|
+
.replace(/--+/g, '-')
|
|
8
|
+
.replace(/^[.-]+/, '')
|
|
9
|
+
.replace(/[.-]+$/, '')
|
|
10
|
+
|| 'unnamed';
|
|
9
11
|
};
|
package/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
interface Options {
|
|
2
2
|
english?: boolean;
|
|
3
3
|
lower?: boolean;
|
|
4
|
-
|
|
4
|
+
delimiter?: string;
|
|
5
5
|
}
|
|
6
|
-
declare const _default: (filename: string, { english, lower,
|
|
6
|
+
declare const _default: (filename: string, { english, lower, delimiter }?: Options) => string;
|
|
7
7
|
export default _default;
|
package/index.js
CHANGED
|
@@ -5,15 +5,15 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const path_1 = require("path");
|
|
7
7
|
const slugify_1 = __importDefault(require("./slugify"));
|
|
8
|
-
exports.default = (filename, { english = true, lower = true,
|
|
8
|
+
exports.default = (filename, { english = true, lower = true, delimiter = '-' } = {}) => {
|
|
9
9
|
// Step 1: Normalize input
|
|
10
10
|
filename = filename.trim().replace(/\.{2,}/g, '.'); // collapse double dots
|
|
11
11
|
const ext = (0, path_1.extname)(filename);
|
|
12
12
|
const base = (0, path_1.basename)(filename, ext);
|
|
13
13
|
// Step 2: Normalize base name
|
|
14
14
|
const name = base
|
|
15
|
-
.replace(/\s+/g,
|
|
16
|
-
.replace(new RegExp(`${
|
|
15
|
+
.replace(/\s+/g, delimiter)
|
|
16
|
+
.replace(new RegExp(`${delimiter}{2,}`, 'g'), delimiter)
|
|
17
17
|
.trim();
|
|
18
18
|
// Step 3: Sluggify (ASCII-only if english = true)
|
|
19
19
|
let slug = name;
|
|
@@ -25,6 +25,8 @@ exports.default = (filename, { english = true, lower = true, delimeter = '-' } =
|
|
|
25
25
|
throw new Error(`BAD_FILE_NAME ${name}`);
|
|
26
26
|
}
|
|
27
27
|
}
|
|
28
|
-
|
|
28
|
+
// Slugify extension separately; re-add the dot since slugify strips leading dots
|
|
29
|
+
const sanitizedExt = ext ? `.${(0, slugify_1.default)(ext)}` : '';
|
|
30
|
+
const result = english ? `${slug}${sanitizedExt}` : `${name}${ext}`;
|
|
29
31
|
return lower ? result.toLowerCase() : result;
|
|
30
32
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@constructive-io/upload-names",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.7.0",
|
|
4
4
|
"author": "Constructive <developers@constructive.io>",
|
|
5
5
|
"description": "upload names",
|
|
6
6
|
"main": "index.js",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"build": "makage build",
|
|
26
26
|
"build:dev": "makage build --dev",
|
|
27
27
|
"lint": "eslint . --fix",
|
|
28
|
-
"test": "jest
|
|
28
|
+
"test": "jest",
|
|
29
29
|
"test:watch": "jest --watch"
|
|
30
30
|
},
|
|
31
31
|
"keywords": [],
|
|
@@ -33,5 +33,5 @@
|
|
|
33
33
|
"glob": "^13.0.0",
|
|
34
34
|
"makage": "^0.1.12"
|
|
35
35
|
},
|
|
36
|
-
"gitHead": "
|
|
36
|
+
"gitHead": "b758178b808ce0bf451e86c0bd7e92079155db7c"
|
|
37
37
|
}
|
package/slugify.js
CHANGED
|
@@ -4,8 +4,10 @@ exports.default = (text) => {
|
|
|
4
4
|
text = text.toString().trim();
|
|
5
5
|
text = text.normalize('NFD').replace(/[\u0300-\u036f]/g, '');
|
|
6
6
|
return text
|
|
7
|
-
.replace(
|
|
8
|
-
.replace(
|
|
9
|
-
.replace(
|
|
10
|
-
.replace(
|
|
7
|
+
.replace(/[^a-zA-Z0-9._-]/g, '-')
|
|
8
|
+
.replace(/\.{2,}/g, '.')
|
|
9
|
+
.replace(/--+/g, '-')
|
|
10
|
+
.replace(/^[.-]+/, '')
|
|
11
|
+
.replace(/[.-]+$/, '')
|
|
12
|
+
|| 'unnamed';
|
|
11
13
|
};
|