@constructive-io/upload-names 2.6.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 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, delimeter = '-' } = {}) => {
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, delimeter)
11
- .replace(new RegExp(`${delimeter}{2,}`, 'g'), delimeter)
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
- const result = english ? `${slug}${slugify(ext)}` : `${name}${ext}`;
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(/\s+/g, '-') // Replace spaces with -
6
- .replace(/--+/g, '-') // Replace multiple - with single -
7
- .replace(/^-+/, '') // Trim - from start of text
8
- .replace(/-+$/, ''); // Trim - from end of text
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
- delimeter?: string;
4
+ delimiter?: string;
5
5
  }
6
- declare const _default: (filename: string, { english, lower, delimeter }?: Options) => string;
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, delimeter = '-' } = {}) => {
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, delimeter)
16
- .replace(new RegExp(`${delimeter}{2,}`, 'g'), delimeter)
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
- const result = english ? `${slug}${(0, slugify_1.default)(ext)}` : `${name}${ext}`;
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.6.0",
3
+ "version": "2.7.0",
4
4
  "author": "Constructive <developers@constructive.io>",
5
5
  "description": "upload names",
6
6
  "main": "index.js",
@@ -33,5 +33,5 @@
33
33
  "glob": "^13.0.0",
34
34
  "makage": "^0.1.12"
35
35
  },
36
- "gitHead": "6dac0247c675de94b41038ac1e5095dc5df0c753"
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(/\s+/g, '-') // Replace spaces with -
8
- .replace(/--+/g, '-') // Replace multiple - with single -
9
- .replace(/^-+/, '') // Trim - from start of text
10
- .replace(/-+$/, ''); // Trim - from end of text
7
+ .replace(/[^a-zA-Z0-9._-]/g, '-')
8
+ .replace(/\.{2,}/g, '.')
9
+ .replace(/--+/g, '-')
10
+ .replace(/^[.-]+/, '')
11
+ .replace(/[.-]+$/, '')
12
+ || 'unnamed';
11
13
  };