@necto/slugify 0.1.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/dist/index.cjs ADDED
@@ -0,0 +1 @@
1
+ "use strict";var e,r=Object.defineProperty,t=Object.getOwnPropertyDescriptor,o=Object.getOwnPropertyNames,n=Object.prototype.hasOwnProperty,c={};((e,t)=>{for(var o in t)r(e,o,{get:t[o],enumerable:!0})})(c,{slugify:()=>u}),module.exports=(e=c,((e,c,p,a)=>{if(c&&"object"==typeof c||"function"==typeof c)for(let l of o(c))n.call(e,l)||l===p||r(e,l,{get:()=>c[l],enumerable:!(a=t(c,l))||a.enumerable});return e})(r({},"__esModule",{value:!0}),e));var p=require("@necto/constants"),a=p.CHAR_MAP,l=p.LOCALE_MAP,g=new RegExp("[\\s\\-_~]+","g"),i=new RegExp("[.*+?^${}()|[\\]\\\\]","g"),s=new RegExp("[\\u0300-\\u036f]","g");function u(e,r={}){const{remove:t,locale:o,trim:n=!0,lower:c=!0,strict:p=!1,replacement:u="-"}=r,f=o?l[o]:void 0,w=u.replace(i,"\\$&");let m="";for(const r of e)m+=f&&r in f?f[r]:r in a?a[r]:r;return m=m.normalize("NFKD").replace(s,""),u?(m=m.replace(g,u),m=m.replace(new RegExp(`${w}{2,}`,"g"),u)):m=m.replace(g,""),t&&(m=m.replace(t,"")),p&&(m=m.replace(new RegExp(`[^a-zA-Z0-9${w}]`,"g"),""),u&&(m=m.replace(new RegExp(`${w}{2,}`,"g"),u))),c&&(m=m.toLocaleLowerCase(o)),n&&u&&(m=m.replace(new RegExp(`^${w}+|${w}+$`,"g"),"")),m}
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Copyright (c) Corinvo, LLC. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+ interface SlugifyOptions {
8
+ /** Character to replace spaces/separators with. Defaults to `'-'`. */
9
+ replacement?: string;
10
+ /** Regex pattern — matching characters are removed. */
11
+ remove?: RegExp;
12
+ /** Convert to lowercase. Defaults to `true`. */
13
+ lower?: boolean;
14
+ /** Strip all characters that aren't alphanumeric or the replacement. Defaults to `false`. */
15
+ strict?: boolean;
16
+ /** BCP 47 locale tag used for transliteration (e.g. `'de'` for German). */
17
+ locale?: string;
18
+ /** Trim leading/trailing replacement characters. Defaults to `true`. */
19
+ trim?: boolean;
20
+ }
21
+ type CharMap = Record<string, string>;
22
+ type LocaleMap = Record<string, CharMap>;
23
+
24
+ /**
25
+ * Copyright (c) Corinvo, LLC. and affiliates.
26
+ *
27
+ * This source code is licensed under the MIT license found in the
28
+ * LICENSE file in the root directory of this source tree.
29
+ */
30
+
31
+ declare function slugify(input: string, options?: SlugifyOptions): string;
32
+
33
+ export { type CharMap, type LocaleMap, type SlugifyOptions, slugify };
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Copyright (c) Corinvo, LLC. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+ interface SlugifyOptions {
8
+ /** Character to replace spaces/separators with. Defaults to `'-'`. */
9
+ replacement?: string;
10
+ /** Regex pattern — matching characters are removed. */
11
+ remove?: RegExp;
12
+ /** Convert to lowercase. Defaults to `true`. */
13
+ lower?: boolean;
14
+ /** Strip all characters that aren't alphanumeric or the replacement. Defaults to `false`. */
15
+ strict?: boolean;
16
+ /** BCP 47 locale tag used for transliteration (e.g. `'de'` for German). */
17
+ locale?: string;
18
+ /** Trim leading/trailing replacement characters. Defaults to `true`. */
19
+ trim?: boolean;
20
+ }
21
+ type CharMap = Record<string, string>;
22
+ type LocaleMap = Record<string, CharMap>;
23
+
24
+ /**
25
+ * Copyright (c) Corinvo, LLC. and affiliates.
26
+ *
27
+ * This source code is licensed under the MIT license found in the
28
+ * LICENSE file in the root directory of this source tree.
29
+ */
30
+
31
+ declare function slugify(input: string, options?: SlugifyOptions): string;
32
+
33
+ export { type CharMap, type LocaleMap, type SlugifyOptions, slugify };
package/dist/index.mjs ADDED
@@ -0,0 +1 @@
1
+ import{CHAR_MAP as e,LOCALE_MAP as r}from"@necto/constants";var n=e,p=r,c=new RegExp("[\\s\\-_~]+","g"),o=new RegExp("[.*+?^${}()|[\\]\\\\]","g"),a=new RegExp("[\\u0300-\\u036f]","g");function l(e,r={}){const{remove:l,locale:t,trim:g=!0,lower:w=!0,strict:i=!1,replacement:x="-"}=r,$=t?p[t]:void 0,s=x.replace(o,"\\$&");let E="";for(const r of e)E+=$&&r in $?$[r]:r in n?n[r]:r;return E=E.normalize("NFKD").replace(a,""),x?(E=E.replace(c,x),E=E.replace(new RegExp(`${s}{2,}`,"g"),x)):E=E.replace(c,""),l&&(E=E.replace(l,"")),i&&(E=E.replace(new RegExp(`[^a-zA-Z0-9${s}]`,"g"),""),x&&(E=E.replace(new RegExp(`${s}{2,}`,"g"),x))),w&&(E=E.toLocaleLowerCase(t)),g&&x&&(E=E.replace(new RegExp(`^${s}+|${s}+$`,"g"),"")),E}export{l as slugify};
package/package.json ADDED
@@ -0,0 +1,33 @@
1
+ {
2
+ "name": "@necto/slugify",
3
+ "version": "0.1.0",
4
+ "description": "Necto's slugify engine for generating URL-safe slugs from strings.",
5
+ "scripts": {
6
+ "build": "tsup --minify terser",
7
+ "test": "vitest"
8
+ },
9
+ "author": "Corinvo OSS Team",
10
+ "license": "MIT",
11
+ "devDependencies": {
12
+ "@types/node": "^22.14.1",
13
+ "tsup": "^8.4.0"
14
+ },
15
+ "dependencies": {
16
+ "@necto/constants": "workspace:*"
17
+ },
18
+ "files": [
19
+ "dist",
20
+ "README.md"
21
+ ],
22
+ "type": "module",
23
+ "types": "./dist/index.d.ts",
24
+ "main": "./dist/index.cjs",
25
+ "module": "./dist/index.mjs",
26
+ "exports": {
27
+ ".": {
28
+ "types": "./dist/index.d.ts",
29
+ "import": "./dist/index.mjs",
30
+ "require": "./dist/index.cjs"
31
+ }
32
+ }
33
+ }