@samline/string 0.0.0-stage → 1.0.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/CHANGELOG.md ADDED
@@ -0,0 +1,7 @@
1
+ # @samline/string
2
+
3
+ ## 1.0.0
4
+
5
+ ### Major Changes
6
+
7
+ - First release: case conversion (camel, Pascal, kebab, snake, dot, constant, title and sentence case, capitalize and uncapitalize), `slugify` with replacements, `maxLength` and a typing-friendly `trim: false`, `removeAccents` with transliteration, `truncate`, `initials` and the shared `words` splitter. ESM, CommonJS and a browser global (`window.SamlineString`).
package/LICENSE.md ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Samuel Olvera (samline)
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,128 @@
1
- # Temporary Holding Version
1
+ # @samline/string
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Case conversion, URL slugs, accent removal, truncation and initials for JavaScript, TypeScript and plain HTML, all built on one Unicode-aware word splitter, so every case agrees.
4
+
5
+ [Demo](https://samline.github.io/utils/string/) · [Examples](https://samline.github.io/utils/string/examples/) · [Documentation](https://samline.github.io/utils/docs/string/) · [Changelog](CHANGELOG.md)
6
+
7
+ ## Table of contents
8
+
9
+ - [Installation](#installation)
10
+ - [Quick start](#quick-start)
11
+ - [HTML / CDN](#html--cdn)
12
+ - [Capabilities](#capabilities)
13
+ - [API at a glance](#api-at-a-glance)
14
+ - [Documentation](#documentation)
15
+ - [Changelog](#changelog)
16
+ - [AI agent skill](#ai-agent-skill)
17
+ - [License](#license)
18
+
19
+ ## Installation
20
+
21
+ ```sh
22
+ npm install @samline/string
23
+ ```
24
+
25
+ ```sh
26
+ pnpm add @samline/string
27
+ ```
28
+
29
+ ```sh
30
+ bun add @samline/string
31
+ ```
32
+
33
+ Pure functions with no DOM access: browsers, Node 20 or newer, workers and edge runtimes. No runtime dependencies.
34
+
35
+ ## Quick start
36
+
37
+ ```js
38
+ import { camelCase, kebabCase, slugify, titleCase, truncate } from '@samline/string'
39
+
40
+ camelCase('XMLHttp request_id') // 'xmlHttpRequestId'
41
+ kebabCase('someLongName') // 'some-long-name'
42
+ titleCase('el señor de los anillos', { smallWords: ['de', 'los'] }) // 'El Señor de los Anillos'
43
+ slugify('¡Hola, Ñandú & Café!', { replacements: { '&': 'y' } }) // 'hola-nandu-y-cafe'
44
+ truncate('The quick brown fox jumps', 15) // 'The quick…'
45
+ ```
46
+
47
+ ## HTML / CDN
48
+
49
+ For Shopify, WordPress or plain HTML pages without a build step, load the browser bundle with a classic script tag. Pin the version in production.
50
+
51
+ ```html
52
+ <script src="https://cdn.jsdelivr.net/npm/@samline/string@1.0.0/dist/browser/string.global.js"></script>
53
+ <script>
54
+ const { slugify } = window.SamlineString
55
+ console.log(slugify('Café & Té')) // 'cafe-te'
56
+ </script>
57
+ ```
58
+
59
+ The bundle defines `window.SamlineString` with every function.
60
+
61
+ ## Capabilities
62
+
63
+ ### One word splitter
64
+
65
+ `words()` splits on any non-letter, non-digit character, on lower-to-upper transitions and before the last capital of an acronym (`XMLHttpRequest` → `XML`, `Http`, `Request`). Digits stay with their word and letters from any script count, so every case function agrees.
66
+
67
+ ### Every case
68
+
69
+ `camelCase`, `pascalCase`, `kebabCase`, `snakeCase`, `dotCase` and `constantCase` for identifiers; `titleCase` (with `smallWords`), `sentenceCase`, `capitalize` and `uncapitalize` for human text. Every function takes a `locale`, so Turkish İ and ı convert correctly.
70
+
71
+ ### Slugs and accents
72
+
73
+ `slugify` removes accents, transliterates ß, æ, œ, ø, đ, ł and þ, applies your `replacements`, collapses separators and cuts at a separator with `maxLength`. `trim: false` keeps a trailing separator for live slug fields. `removeAccents` gives accent-insensitive text for search.
74
+
75
+ ### Display helpers
76
+
77
+ `truncate` counts code points, so emoji and accents are never split, and cuts at the last whole word; `initials` builds avatar letters.
78
+
79
+ ## API at a glance
80
+
81
+ | API | Purpose |
82
+ | ------------------------------------------------------------------------------ | ------------------------------- |
83
+ | `camelCase`, `pascalCase`, `kebabCase`, `snakeCase`, `dotCase`, `constantCase` | Identifier cases. |
84
+ | `titleCase`, `sentenceCase`, `capitalize`, `uncapitalize` | Human-readable casing. |
85
+ | `slugify(text, options?)`, `removeAccents(text)` | URL slugs and accent-free text. |
86
+ | `truncate(text, length, options?)`, `initials(text, options?)` | Display helpers. |
87
+ | `words(text)` | The shared word splitter. |
88
+
89
+ ### Entrypoints
90
+
91
+ | Entrypoint | When to use |
92
+ | ------------------------- | --------------------------------------------------- |
93
+ | `@samline/string` | ESM or CommonJS, every function. |
94
+ | `@samline/string/vanilla` | The same API as an explicit subpath. |
95
+ | `@samline/string/browser` | Classic script that defines `window.SamlineString`. |
96
+
97
+ ## Documentation
98
+
99
+ Read the [documentation](https://samline.github.io/utils/docs/string/) for the full guides and API contracts, and explore [working examples](https://samline.github.io/utils/string/examples/) with complete and separate source files.
100
+
101
+ | Guide | What it covers |
102
+ | ------------------------------------------------------------------------------- | --------------------------------------------------- |
103
+ | [Installation](https://samline.github.io/utils/docs/string/getting-started/) | npm, CDN and the first conversions. |
104
+ | [API reference](https://samline.github.io/utils/docs/string/reference/api/) | Every function with examples. |
105
+ | [Options](https://samline.github.io/utils/docs/string/reference/configuration/) | slugify, titleCase, truncate, initials and locales. |
106
+ | [Word splitting](https://samline.github.io/utils/docs/string/guides/words/) | Exactly how words are detected. |
107
+
108
+ ## Changelog
109
+
110
+ Read [CHANGELOG.md](CHANGELOG.md) or the [published changelog](https://samline.github.io/utils/docs/string/changelog/) for release history and explicitly marked breaking and behavior changes. Review the notes before upgrading.
111
+
112
+ ## AI agent skill
113
+
114
+ The [String skill](https://samline.github.io/utils/skills/string/SKILL.md) teaches verified package integration. Its maintained [repository source](site/SKILL.md) and website download are the same file. Verify the installed package version before applying its guidance.
115
+
116
+ Download [SKILL.md](https://samline.github.io/utils/skills/string/SKILL.md) into a `string/` folder in your agent's supported skill directory. For agents that discover project skills from `.agents/skills/`:
117
+
118
+ ```sh
119
+ mkdir -p .agents/skills/string
120
+ curl --fail --location https://samline.github.io/utils/skills/string/SKILL.md \
121
+ --output .agents/skills/string/SKILL.md
122
+ ```
123
+
124
+ Keep the filename `SKILL.md`; discovery paths and invocation syntax depend on the agent.
125
+
126
+ ## License
127
+
128
+ MIT — [LICENSE.md](LICENSE.md).
@@ -0,0 +1,2 @@
1
+ "use strict";(()=>{var k=Object.defineProperty;var v=(e,t)=>{for(var s in t)k(e,s,{get:t[s],enumerable:!0})};var C={};v(C,{camelCase:()=>y,capitalize:()=>R,constantCase:()=>L,dotCase:()=>j,initials:()=>z,kebabCase:()=>$,pascalCase:()=>b,removeAccents:()=>u,sentenceCase:()=>T,slugify:()=>N,snakeCase:()=>w,titleCase:()=>A,truncate:()=>I,uncapitalize:()=>E,words:()=>a});var a=e=>typeof e!="string"||e===""?[]:e.replace(/([\p{Ll}\p{N}])(\p{Lu})/gu,"$1 $2").replace(/(\p{Lu})(\p{Lu}\p{Ll})/gu,"$1 $2").split(/[^\p{L}\p{N}]+/u).filter(Boolean);var O={\u00DF:"ss","\u1E9E":"SS",\u00E6:"ae",\u00C6:"AE",\u0153:"oe",\u0152:"OE",\u00F8:"o",\u00D8:"O",\u0111:"d",\u0110:"D",\u0142:"l",\u0141:"L",\u00FE:"th",\u00DE:"TH",\u00F0:"d",\u00D0:"D",\u0131:"i"},F=new RegExp(`[${Object.keys(O).join("")}]`,"g"),u=e=>String(e??"").normalize("NFKD").replace(/\p{M}+/gu,"").replace(F,t=>O[t]??t);var c=(e,t)=>e.toLocaleLowerCase(t),S=(e,t)=>e.toLocaleUpperCase(t),m=(e,t)=>{let[s="",...r]=Array.from(e);return S(s,t)+r.join("")},d=(e,t)=>m(c(e,t),t),y=(e,{locale:t}={})=>a(e).map((s,r)=>r===0?c(s,t):d(s,t)).join(""),b=(e,{locale:t}={})=>a(e).map(s=>d(s,t)).join(""),x=e=>(t,{locale:s}={})=>a(t).map(r=>c(r,s)).join(e),$=x("-"),w=x("_"),j=x("."),L=(e,{locale:t}={})=>a(e).map(s=>S(s,t)).join("_"),A=(e,{locale:t,smallWords:s=[]}={})=>{let r=new Set(s.map(o=>c(o,t))),i=0;return String(e??"").replace(/[\p{L}\p{N}]+/gu,o=>{let p=i++===0,n=c(o,t);return!p&&r.has(n)?n:m(n,t)})},T=(e,{locale:t}={})=>m(c(String(e??""),t),t),R=(e,{locale:t}={})=>m(String(e??""),t),E=(e,{locale:t}={})=>{let[s="",...r]=Array.from(String(e??""));return c(s,t)+r.join("")};var h=e=>e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),N=(e,{separator:t="-",lower:s=!0,replacements:r={},maxLength:i,trim:o=!0,locale:p}={})=>{let n=String(e??"");for(let[l,f]of Object.entries(r))n=n.split(l).join(` ${f} `);s&&(n=n.toLocaleLowerCase(p)),n=u(n);let g=h(t);if(n=n.replace(/[^A-Za-z0-9]+/g,t),t&&(n=n.replace(new RegExp(`(?:${g}){2,}`,"g"),t)),o&&t?n=n.replace(new RegExp(`^(?:${g})+|(?:${g})+$`,"g"),""):t&&(n=n.replace(new RegExp(`^(?:${g})+`),"")),i!==void 0&&Number.isFinite(i)&&i>=0&&n.length>i){let l=n.slice(0,i),f=t?l.lastIndexOf(t):-1;n=f>0&&n[i]!==t?l.slice(0,f):l,t&&(n=n.replace(new RegExp(`(?:${g})+$`),""))}return n};var I=(e,t,{ellipsis:s="\u2026",wordBoundary:r=!0}={})=>{let i=Array.from(String(e??""));if(!Number.isFinite(t)||t<0||i.length<=t)return i.join("");let o=Math.max(0,t-Array.from(s).length),p=i.slice(0,o).join("");if(r&&i[o]!==void 0&&/[\p{L}\p{N}]/u.test(i[o])){let n=p.search(/\s\S*$/u);n>0&&(p=p.slice(0,n))}return p.replace(/[\s.,;:!?-]+$/u,"")+s},z=(e,{max:t=2,locale:s}={})=>a(String(e??"")).slice(0,Math.max(0,t)).map(r=>Array.from(r)[0].toLocaleUpperCase(s)).join("");globalThis.SamlineString=C;})();
2
+ //# sourceMappingURL=string.global.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/core/index.ts","../../src/core/words.ts","../../src/core/accents.ts","../../src/core/case.ts","../../src/core/slugify.ts","../../src/core/text.ts","../../src/browser/global.ts"],"sourcesContent":["export { words } from './words.js'\nexport { removeAccents } from './accents.js'\nexport {\n camelCase,\n capitalize,\n constantCase,\n dotCase,\n kebabCase,\n pascalCase,\n sentenceCase,\n snakeCase,\n titleCase,\n uncapitalize,\n type CaseOptions,\n type TitleCaseOptions,\n} from './case.js'\nexport { slugify, type SlugifyOptions } from './slugify.js'\nexport { initials, truncate, type InitialsOptions, type TruncateOptions } from './text.js'\n","/**\n * Split any identifier or phrase into words.\n *\n * Handles separators (spaces, `-`, `_`, `.`, `/`, punctuation), camelCase,\n * PascalCase and acronyms (`XMLHttpRequest` → `XML`, `Http`, `Request`), keeps\n * digits attached to their word (`version2` stays one word) and works with any\n * script (`añoNuevo` → `año`, `Nuevo`).\n */\nexport const words = (input: string): string[] => {\n if (typeof input !== 'string' || input === '') return []\n return (\n input\n // fooBar → foo Bar, foo2Bar → foo2 Bar\n .replace(/([\\p{Ll}\\p{N}])(\\p{Lu})/gu, '$1 $2')\n // XMLHttp → XML Http\n .replace(/(\\p{Lu})(\\p{Lu}\\p{Ll})/gu, '$1 $2')\n .split(/[^\\p{L}\\p{N}]+/u)\n .filter(Boolean)\n )\n}\n","/** Letters that Unicode normalization does not decompose into ASCII. */\nconst TRANSLITERATIONS: Record<string, string> = {\n ß: 'ss',\n ẞ: 'SS',\n æ: 'ae',\n Æ: 'AE',\n œ: 'oe',\n Œ: 'OE',\n ø: 'o',\n Ø: 'O',\n đ: 'd',\n Đ: 'D',\n ł: 'l',\n Ł: 'L',\n þ: 'th',\n Þ: 'TH',\n ð: 'd',\n Ð: 'D',\n ı: 'i',\n}\nconst SPECIAL = new RegExp(`[${Object.keys(TRANSLITERATIONS).join('')}]`, 'g')\n\n/** Remove diacritics and transliterate common Latin letters: `Ñandú Straße` → `Nandu Strasse`. */\nexport const removeAccents = (input: string): string =>\n String(input ?? '')\n .normalize('NFKD')\n .replace(/\\p{M}+/gu, '')\n .replace(SPECIAL, char => TRANSLITERATIONS[char] ?? char)\n","import { words } from './words.js'\n\nexport interface CaseOptions {\n /** Locale for upper/lower casing, for example `'tr'` for Turkish dotted i. */\n locale?: string | string[]\n}\n\nconst lower = (value: string, locale?: string | string[]) => value.toLocaleLowerCase(locale)\nconst upper = (value: string, locale?: string | string[]) => value.toLocaleUpperCase(locale)\nconst upperFirst = (value: string, locale?: string | string[]) => {\n const [first = '', ...rest] = Array.from(value)\n return upper(first, locale) + rest.join('')\n}\nconst titleWord = (value: string, locale?: string | string[]) =>\n upperFirst(lower(value, locale), locale)\n\n/** `hello world` → `helloWorld` */\nexport const camelCase = (input: string, { locale }: CaseOptions = {}): string =>\n words(input)\n .map((word, index) => (index === 0 ? lower(word, locale) : titleWord(word, locale)))\n .join('')\n\n/** `hello world` → `HelloWorld` */\nexport const pascalCase = (input: string, { locale }: CaseOptions = {}): string =>\n words(input)\n .map(word => titleWord(word, locale))\n .join('')\n\nconst joinLower =\n (separator: string) =>\n (input: string, { locale }: CaseOptions = {}) =>\n words(input)\n .map(word => lower(word, locale))\n .join(separator)\n\n/** `Hello World` → `hello-world` */\nexport const kebabCase = joinLower('-')\n/** `Hello World` → `hello_world` */\nexport const snakeCase = joinLower('_')\n/** `Hello World` → `hello.world` */\nexport const dotCase = joinLower('.')\n\n/** `Hello World` → `HELLO_WORLD` */\nexport const constantCase = (input: string, { locale }: CaseOptions = {}): string =>\n words(input)\n .map(word => upper(word, locale))\n .join('_')\n\nexport interface TitleCaseOptions extends CaseOptions {\n /**\n * Words kept in lower case unless they come first, for example\n * `['de', 'la', 'y']` or `['of', 'the', 'and']`. Defaults to none.\n */\n smallWords?: readonly string[]\n}\n\n/**\n * `the lord of the rings` → `The Lord Of The Rings` (or `The Lord of the Rings`\n * with `smallWords`). Keeps the original spacing and punctuation.\n */\nexport const titleCase = (\n input: string,\n { locale, smallWords = [] }: TitleCaseOptions = {}\n): string => {\n const small = new Set(smallWords.map(word => lower(word, locale)))\n let index = 0\n return String(input ?? '').replace(/[\\p{L}\\p{N}]+/gu, word => {\n const first = index++ === 0\n const lowered = lower(word, locale)\n return !first && small.has(lowered) ? lowered : upperFirst(lowered, locale)\n })\n}\n\n/** `HELLO world. NEW sentence` → `Hello world. new sentence`; only the first letter is upper case. */\nexport const sentenceCase = (input: string, { locale }: CaseOptions = {}): string =>\n upperFirst(lower(String(input ?? ''), locale), locale)\n\n/** Upper-case the first letter and leave the rest untouched: `hello World` → `Hello World`. */\nexport const capitalize = (input: string, { locale }: CaseOptions = {}): string =>\n upperFirst(String(input ?? ''), locale)\n\n/** Lower-case the first letter and leave the rest untouched: `Hello` → `hello`. */\nexport const uncapitalize = (input: string, { locale }: CaseOptions = {}): string => {\n const [first = '', ...rest] = Array.from(String(input ?? ''))\n return lower(first, locale) + rest.join('')\n}\n","import { removeAccents } from './accents.js'\n\nexport interface SlugifyOptions {\n /** Word separator. Defaults to `'-'`. */\n separator?: string\n /** Lower-case the result. Defaults to `true`. */\n lower?: boolean\n /**\n * Replacements applied before anything else, for example\n * `{ '&': 'y', '%': 'por ciento' }`. Keys are matched literally.\n */\n replacements?: Readonly<Record<string, string>>\n /** Maximum length; cuts at a separator when possible. */\n maxLength?: number\n /**\n * Remove leading and trailing separators. Defaults to `true`. Use `false`\n * while the user is typing, so a trailing space can become a separator.\n */\n trim?: boolean\n /** Locale for lower-casing. */\n locale?: string | string[]\n}\n\nconst escape = (value: string) => value.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&')\n\n/**\n * `¡Hola, Ñandú & Café!` → `hola-nandu-cafe`\n *\n * Removes accents, transliterates common letters (ß, æ, ø, œ, ł…), keeps\n * only ASCII letters and digits, and collapses everything else into one\n * separator.\n */\nexport const slugify = (\n input: string,\n {\n separator = '-',\n lower = true,\n replacements = {},\n maxLength,\n trim = true,\n locale,\n }: SlugifyOptions = {}\n): string => {\n let value = String(input ?? '')\n for (const [from, to] of Object.entries(replacements)) value = value.split(from).join(` ${to} `)\n // Lower-case first: some locales produce letters (Turkish ı) that removeAccents transliterates.\n if (lower) value = value.toLocaleLowerCase(locale)\n value = removeAccents(value)\n\n const sep = escape(separator)\n value = value.replace(/[^A-Za-z0-9]+/g, separator)\n if (separator) value = value.replace(new RegExp(`(?:${sep}){2,}`, 'g'), separator)\n if (trim && separator) value = value.replace(new RegExp(`^(?:${sep})+|(?:${sep})+$`, 'g'), '')\n else if (separator) value = value.replace(new RegExp(`^(?:${sep})+`), '')\n\n if (\n maxLength !== undefined &&\n Number.isFinite(maxLength) &&\n maxLength >= 0 &&\n value.length > maxLength\n ) {\n const cut = value.slice(0, maxLength)\n const boundary = separator ? cut.lastIndexOf(separator) : -1\n value = boundary > 0 && value[maxLength] !== separator ? cut.slice(0, boundary) : cut\n if (separator) value = value.replace(new RegExp(`(?:${sep})+$`), '')\n }\n return value\n}\n","import { words } from './words.js'\n\nexport interface TruncateOptions {\n /** Appended when the text is cut. Defaults to `'…'`. Counts toward `length`. */\n ellipsis?: string\n /** Cut at the last whole word instead of mid-word. Defaults to `true`. */\n wordBoundary?: boolean\n}\n\n/**\n * Shorten text to at most `length` characters (code points, so emoji and\n * accents are never split).\n */\nexport const truncate = (\n input: string,\n length: number,\n { ellipsis = '…', wordBoundary = true }: TruncateOptions = {}\n): string => {\n const chars = Array.from(String(input ?? ''))\n if (!Number.isFinite(length) || length < 0 || chars.length <= length) return chars.join('')\n const room = Math.max(0, length - Array.from(ellipsis).length)\n let cut = chars.slice(0, room).join('')\n if (wordBoundary && chars[room] !== undefined && /[\\p{L}\\p{N}]/u.test(chars[room]!)) {\n const lastSpace = cut.search(/\\s\\S*$/u)\n if (lastSpace > 0) cut = cut.slice(0, lastSpace)\n }\n return cut.replace(/[\\s.,;:!?-]+$/u, '') + ellipsis\n}\n\nexport interface InitialsOptions {\n /** Maximum number of letters. Defaults to `2`. */\n max?: number\n locale?: string | string[]\n}\n\n/** `Samuel Olvera` → `SO`, `ana maría lópez` → `AM` */\nexport const initials = (input: string, { max = 2, locale }: InitialsOptions = {}): string =>\n words(String(input ?? ''))\n .slice(0, Math.max(0, max))\n .map(word => Array.from(word)[0]!.toLocaleUpperCase(locale))\n .join('')\n","import * as api from '../core/index.js'\n\nexport type SamlineStringGlobal = typeof api\n\n;(globalThis as typeof globalThis & { SamlineString?: SamlineStringGlobal }).SamlineString = api\n\nexport * from '../core/index.js'\n"],"mappings":"6GAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,eAAAE,EAAA,eAAAC,EAAA,iBAAAC,EAAA,YAAAC,EAAA,aAAAC,EAAA,cAAAC,EAAA,eAAAC,EAAA,kBAAAC,EAAA,iBAAAC,EAAA,YAAAC,EAAA,cAAAC,EAAA,cAAAC,EAAA,aAAAC,EAAA,iBAAAC,EAAA,UA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AAK,EAAG,EAAE,EACrE,CACA,OAAOZ,CACT,ECtDO,IAAMe,EAAW,CACtBC,EACAC,EACA,CAAE,SAAAC,EAAW,SAAK,aAAAC,EAAe,EAAK,EAAqB,CAAC,IACjD,CACX,IAAMC,EAAQ,MAAM,KAAK,OAAOJ,GAAS,EAAE,CAAC,EAC5C,GAAI,CAAC,OAAO,SAASC,CAAM,GAAKA,EAAS,GAAKG,EAAM,QAAUH,EAAQ,OAAOG,EAAM,KAAK,EAAE,EAC1F,IAAMC,EAAO,KAAK,IAAI,EAAGJ,EAAS,MAAM,KAAKC,CAAQ,EAAE,MAAM,EACzDI,EAAMF,EAAM,MAAM,EAAGC,CAAI,EAAE,KAAK,EAAE,EACtC,GAAIF,GAAgBC,EAAMC,CAAI,IAAM,QAAa,gBAAgB,KAAKD,EAAMC,CAAI,CAAE,EAAG,CACnF,IAAME,EAAYD,EAAI,OAAO,SAAS,EAClCC,EAAY,IAAGD,EAAMA,EAAI,MAAM,EAAGC,CAAS,EACjD,CACA,OAAOD,EAAI,QAAQ,iBAAkB,EAAE,EAAIJ,CAC7C,EASaM,EAAW,CAACR,EAAe,CAAE,IAAAS,EAAM,EAAG,OAAAC,CAAO,EAAqB,CAAC,IAC9EC,EAAM,OAAOX,GAAS,EAAE,CAAC,EACtB,MAAM,EAAG,KAAK,IAAI,EAAGS,CAAG,CAAC,EACzB,IAAIG,GAAQ,MAAM,KAAKA,CAAI,EAAE,CAAC,EAAG,kBAAkBF,CAAM,CAAC,EAC1D,KAAK,EAAE,ECpCV,WAA2E,cAAgBG","names":["core_exports","__export","camelCase","capitalize","constantCase","dotCase","initials","kebabCase","pascalCase","removeAccents","sentenceCase","slugify","snakeCase","titleCase","truncate","uncapitalize","words","words","input","TRANSLITERATIONS","SPECIAL","removeAccents","input","char","lower","value","locale","upper","upperFirst","first","rest","titleWord","camelCase","input","words","word","index","pascalCase","joinLower","separator","kebabCase","snakeCase","dotCase","constantCase","titleCase","smallWords","small","lowered","sentenceCase","capitalize","uncapitalize","escape","value","slugify","input","separator","lower","replacements","maxLength","trim","locale","from","to","removeAccents","sep","cut","boundary","truncate","input","length","ellipsis","wordBoundary","chars","room","cut","lastSpace","initials","max","locale","words","word","core_exports"]}
@@ -0,0 +1,105 @@
1
+ // src/core/words.ts
2
+ var words = (input) => {
3
+ if (typeof input !== "string" || input === "") return [];
4
+ return input.replace(/([\p{Ll}\p{N}])(\p{Lu})/gu, "$1 $2").replace(/(\p{Lu})(\p{Lu}\p{Ll})/gu, "$1 $2").split(/[^\p{L}\p{N}]+/u).filter(Boolean);
5
+ };
6
+
7
+ // src/core/accents.ts
8
+ var TRANSLITERATIONS = {
9
+ \u00DF: "ss",
10
+ "\u1E9E": "SS",
11
+ \u00E6: "ae",
12
+ \u00C6: "AE",
13
+ \u0153: "oe",
14
+ \u0152: "OE",
15
+ \u00F8: "o",
16
+ \u00D8: "O",
17
+ \u0111: "d",
18
+ \u0110: "D",
19
+ \u0142: "l",
20
+ \u0141: "L",
21
+ \u00FE: "th",
22
+ \u00DE: "TH",
23
+ \u00F0: "d",
24
+ \u00D0: "D",
25
+ \u0131: "i"
26
+ };
27
+ var SPECIAL = new RegExp(`[${Object.keys(TRANSLITERATIONS).join("")}]`, "g");
28
+ var removeAccents = (input) => String(input ?? "").normalize("NFKD").replace(/\p{M}+/gu, "").replace(SPECIAL, (char) => TRANSLITERATIONS[char] ?? char);
29
+
30
+ // src/core/case.ts
31
+ var lower = (value, locale) => value.toLocaleLowerCase(locale);
32
+ var upper = (value, locale) => value.toLocaleUpperCase(locale);
33
+ var upperFirst = (value, locale) => {
34
+ const [first = "", ...rest] = Array.from(value);
35
+ return upper(first, locale) + rest.join("");
36
+ };
37
+ var titleWord = (value, locale) => upperFirst(lower(value, locale), locale);
38
+ var camelCase = (input, { locale } = {}) => words(input).map((word, index) => index === 0 ? lower(word, locale) : titleWord(word, locale)).join("");
39
+ var pascalCase = (input, { locale } = {}) => words(input).map((word) => titleWord(word, locale)).join("");
40
+ var joinLower = (separator) => (input, { locale } = {}) => words(input).map((word) => lower(word, locale)).join(separator);
41
+ var kebabCase = joinLower("-");
42
+ var snakeCase = joinLower("_");
43
+ var dotCase = joinLower(".");
44
+ var constantCase = (input, { locale } = {}) => words(input).map((word) => upper(word, locale)).join("_");
45
+ var titleCase = (input, { locale, smallWords = [] } = {}) => {
46
+ const small = new Set(smallWords.map((word) => lower(word, locale)));
47
+ let index = 0;
48
+ return String(input ?? "").replace(/[\p{L}\p{N}]+/gu, (word) => {
49
+ const first = index++ === 0;
50
+ const lowered = lower(word, locale);
51
+ return !first && small.has(lowered) ? lowered : upperFirst(lowered, locale);
52
+ });
53
+ };
54
+ var sentenceCase = (input, { locale } = {}) => upperFirst(lower(String(input ?? ""), locale), locale);
55
+ var capitalize = (input, { locale } = {}) => upperFirst(String(input ?? ""), locale);
56
+ var uncapitalize = (input, { locale } = {}) => {
57
+ const [first = "", ...rest] = Array.from(String(input ?? ""));
58
+ return lower(first, locale) + rest.join("");
59
+ };
60
+
61
+ // src/core/slugify.ts
62
+ var escape = (value) => value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
63
+ var slugify = (input, {
64
+ separator = "-",
65
+ lower: lower2 = true,
66
+ replacements = {},
67
+ maxLength,
68
+ trim = true,
69
+ locale
70
+ } = {}) => {
71
+ let value = String(input ?? "");
72
+ for (const [from, to] of Object.entries(replacements)) value = value.split(from).join(` ${to} `);
73
+ if (lower2) value = value.toLocaleLowerCase(locale);
74
+ value = removeAccents(value);
75
+ const sep = escape(separator);
76
+ value = value.replace(/[^A-Za-z0-9]+/g, separator);
77
+ if (separator) value = value.replace(new RegExp(`(?:${sep}){2,}`, "g"), separator);
78
+ if (trim && separator) value = value.replace(new RegExp(`^(?:${sep})+|(?:${sep})+$`, "g"), "");
79
+ else if (separator) value = value.replace(new RegExp(`^(?:${sep})+`), "");
80
+ if (maxLength !== void 0 && Number.isFinite(maxLength) && maxLength >= 0 && value.length > maxLength) {
81
+ const cut = value.slice(0, maxLength);
82
+ const boundary = separator ? cut.lastIndexOf(separator) : -1;
83
+ value = boundary > 0 && value[maxLength] !== separator ? cut.slice(0, boundary) : cut;
84
+ if (separator) value = value.replace(new RegExp(`(?:${sep})+$`), "");
85
+ }
86
+ return value;
87
+ };
88
+
89
+ // src/core/text.ts
90
+ var truncate = (input, length, { ellipsis = "\u2026", wordBoundary = true } = {}) => {
91
+ const chars = Array.from(String(input ?? ""));
92
+ if (!Number.isFinite(length) || length < 0 || chars.length <= length) return chars.join("");
93
+ const room = Math.max(0, length - Array.from(ellipsis).length);
94
+ let cut = chars.slice(0, room).join("");
95
+ if (wordBoundary && chars[room] !== void 0 && /[\p{L}\p{N}]/u.test(chars[room])) {
96
+ const lastSpace = cut.search(/\s\S*$/u);
97
+ if (lastSpace > 0) cut = cut.slice(0, lastSpace);
98
+ }
99
+ return cut.replace(/[\s.,;:!?-]+$/u, "") + ellipsis;
100
+ };
101
+ var initials = (input, { max = 2, locale } = {}) => words(String(input ?? "")).slice(0, Math.max(0, max)).map((word) => Array.from(word)[0].toLocaleUpperCase(locale)).join("");
102
+
103
+ export { camelCase, capitalize, constantCase, dotCase, initials, kebabCase, pascalCase, removeAccents, sentenceCase, slugify, snakeCase, titleCase, truncate, uncapitalize, words };
104
+ //# sourceMappingURL=chunk-7CEOX6CZ.js.map
105
+ //# sourceMappingURL=chunk-7CEOX6CZ.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/core/words.ts","../src/core/accents.ts","../src/core/case.ts","../src/core/slugify.ts","../src/core/text.ts"],"names":["lower"],"mappings":";AAQO,IAAM,KAAA,GAAQ,CAAC,KAAA,KAA4B;AAChD,EAAA,IAAI,OAAO,KAAA,KAAU,QAAA,IAAY,KAAA,KAAU,EAAA,SAAW,EAAC;AACvD,EAAA,OACE,KAAA,CAEG,OAAA,CAAQ,2BAAA,EAA6B,OAAO,CAAA,CAE5C,OAAA,CAAQ,0BAAA,EAA4B,OAAO,CAAA,CAC3C,KAAA,CAAM,iBA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,KAAA,CAAM,GAAG,IAAI,CAAA,CAAE,KAAK,EAAE,CAAA;AACtC,EAAA,IAAI,YAAA,IAAgB,KAAA,CAAM,IAAI,CAAA,KAAM,MAAA,IAAa,gBAAgB,IAAA,CAAK,KAAA,CAAM,IAAI,CAAE,CAAA,EAAG;AACnF,IAAA,MAAM,SAAA,GAAY,GAAA,CAAI,MAAA,CAAO,SAAS,CAAA;AACtC,IAAA,IAAI,YAAY,CAAA,EAAG,GAAA,GAAM,GAAA,CAAI,KAAA,CAAM,GAAG,SAAS,CAAA;AAAA,EACjD;AACA,EAAA,OAAO,GAAA,CAAI,OAAA,CAAQ,gBAAA,EAAkB,EAAE,CAAA,GAAI,QAAA;AAC7C;AASO,IAAM,WAAW,CAAC,KAAA,EAAe,EAAE,GAAA,GAAM,GAAG,MAAA,EAAO,GAAqB,EAAC,KAC9E,MAAM,MAAA,CAAO,KAAA,IAAS,EAAE,CAAC,EACtB,KAAA,CAAM,CAAA,EAAG,IAAA,CAAK,GAAA,CAAI,GAAG,GAAG,CAAC,CAAA,CACzB,GAAA,CAAI,UAAQ,KAAA,CAAM,IAAA,CAAK,IAAI,CAAA,CAAE,CAAC,CAAA,CAAG,iBAAA,CAAkB,MAAM,CAAC,CAAA,CAC1D,KAAK,EAAE","file":"chunk-7CEOX6CZ.js","sourcesContent":["/**\n * Split any identifier or phrase into words.\n *\n * Handles separators (spaces, `-`, `_`, `.`, `/`, punctuation), camelCase,\n * PascalCase and acronyms (`XMLHttpRequest` → `XML`, `Http`, `Request`), keeps\n * digits attached to their word (`version2` stays one word) and works with any\n * script (`añoNuevo` → `año`, `Nuevo`).\n */\nexport const words = (input: string): string[] => {\n if (typeof input !== 'string' || input === '') return []\n return (\n input\n // fooBar → foo Bar, foo2Bar → foo2 Bar\n .replace(/([\\p{Ll}\\p{N}])(\\p{Lu})/gu, '$1 $2')\n // XMLHttp → XML Http\n .replace(/(\\p{Lu})(\\p{Lu}\\p{Ll})/gu, '$1 $2')\n .split(/[^\\p{L}\\p{N}]+/u)\n .filter(Boolean)\n )\n}\n","/** Letters that Unicode normalization does not decompose into ASCII. */\nconst TRANSLITERATIONS: Record<string, string> = {\n ß: 'ss',\n ẞ: 'SS',\n æ: 'ae',\n Æ: 'AE',\n œ: 'oe',\n Œ: 'OE',\n ø: 'o',\n Ø: 'O',\n đ: 'd',\n Đ: 'D',\n ł: 'l',\n Ł: 'L',\n þ: 'th',\n Þ: 'TH',\n ð: 'd',\n Ð: 'D',\n ı: 'i',\n}\nconst SPECIAL = new RegExp(`[${Object.keys(TRANSLITERATIONS).join('')}]`, 'g')\n\n/** Remove diacritics and transliterate common Latin letters: `Ñandú Straße` → `Nandu Strasse`. */\nexport const removeAccents = (input: string): string =>\n String(input ?? '')\n .normalize('NFKD')\n .replace(/\\p{M}+/gu, '')\n .replace(SPECIAL, char => TRANSLITERATIONS[char] ?? char)\n","import { words } from './words.js'\n\nexport interface CaseOptions {\n /** Locale for upper/lower casing, for example `'tr'` for Turkish dotted i. */\n locale?: string | string[]\n}\n\nconst lower = (value: string, locale?: string | string[]) => value.toLocaleLowerCase(locale)\nconst upper = (value: string, locale?: string | string[]) => value.toLocaleUpperCase(locale)\nconst upperFirst = (value: string, locale?: string | string[]) => {\n const [first = '', ...rest] = Array.from(value)\n return upper(first, locale) + rest.join('')\n}\nconst titleWord = (value: string, locale?: string | string[]) =>\n upperFirst(lower(value, locale), locale)\n\n/** `hello world` → `helloWorld` */\nexport const camelCase = (input: string, { locale }: CaseOptions = {}): string =>\n words(input)\n .map((word, index) => (index === 0 ? lower(word, locale) : titleWord(word, locale)))\n .join('')\n\n/** `hello world` → `HelloWorld` */\nexport const pascalCase = (input: string, { locale }: CaseOptions = {}): string =>\n words(input)\n .map(word => titleWord(word, locale))\n .join('')\n\nconst joinLower =\n (separator: string) =>\n (input: string, { locale }: CaseOptions = {}) =>\n words(input)\n .map(word => lower(word, locale))\n .join(separator)\n\n/** `Hello World` → `hello-world` */\nexport const kebabCase = joinLower('-')\n/** `Hello World` → `hello_world` */\nexport const snakeCase = joinLower('_')\n/** `Hello World` → `hello.world` */\nexport const dotCase = joinLower('.')\n\n/** `Hello World` → `HELLO_WORLD` */\nexport const constantCase = (input: string, { locale }: CaseOptions = {}): string =>\n words(input)\n .map(word => upper(word, locale))\n .join('_')\n\nexport interface TitleCaseOptions extends CaseOptions {\n /**\n * Words kept in lower case unless they come first, for example\n * `['de', 'la', 'y']` or `['of', 'the', 'and']`. Defaults to none.\n */\n smallWords?: readonly string[]\n}\n\n/**\n * `the lord of the rings` → `The Lord Of The Rings` (or `The Lord of the Rings`\n * with `smallWords`). Keeps the original spacing and punctuation.\n */\nexport const titleCase = (\n input: string,\n { locale, smallWords = [] }: TitleCaseOptions = {}\n): string => {\n const small = new Set(smallWords.map(word => lower(word, locale)))\n let index = 0\n return String(input ?? '').replace(/[\\p{L}\\p{N}]+/gu, word => {\n const first = index++ === 0\n const lowered = lower(word, locale)\n return !first && small.has(lowered) ? lowered : upperFirst(lowered, locale)\n })\n}\n\n/** `HELLO world. NEW sentence` → `Hello world. new sentence`; only the first letter is upper case. */\nexport const sentenceCase = (input: string, { locale }: CaseOptions = {}): string =>\n upperFirst(lower(String(input ?? ''), locale), locale)\n\n/** Upper-case the first letter and leave the rest untouched: `hello World` → `Hello World`. */\nexport const capitalize = (input: string, { locale }: CaseOptions = {}): string =>\n upperFirst(String(input ?? ''), locale)\n\n/** Lower-case the first letter and leave the rest untouched: `Hello` → `hello`. */\nexport const uncapitalize = (input: string, { locale }: CaseOptions = {}): string => {\n const [first = '', ...rest] = Array.from(String(input ?? ''))\n return lower(first, locale) + rest.join('')\n}\n","import { removeAccents } from './accents.js'\n\nexport interface SlugifyOptions {\n /** Word separator. Defaults to `'-'`. */\n separator?: string\n /** Lower-case the result. Defaults to `true`. */\n lower?: boolean\n /**\n * Replacements applied before anything else, for example\n * `{ '&': 'y', '%': 'por ciento' }`. Keys are matched literally.\n */\n replacements?: Readonly<Record<string, string>>\n /** Maximum length; cuts at a separator when possible. */\n maxLength?: number\n /**\n * Remove leading and trailing separators. Defaults to `true`. Use `false`\n * while the user is typing, so a trailing space can become a separator.\n */\n trim?: boolean\n /** Locale for lower-casing. */\n locale?: string | string[]\n}\n\nconst escape = (value: string) => value.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&')\n\n/**\n * `¡Hola, Ñandú & Café!` → `hola-nandu-cafe`\n *\n * Removes accents, transliterates common letters (ß, æ, ø, œ, ł…), keeps\n * only ASCII letters and digits, and collapses everything else into one\n * separator.\n */\nexport const slugify = (\n input: string,\n {\n separator = '-',\n lower = true,\n replacements = {},\n maxLength,\n trim = true,\n locale,\n }: SlugifyOptions = {}\n): string => {\n let value = String(input ?? '')\n for (const [from, to] of Object.entries(replacements)) value = value.split(from).join(` ${to} `)\n // Lower-case first: some locales produce letters (Turkish ı) that removeAccents transliterates.\n if (lower) value = value.toLocaleLowerCase(locale)\n value = removeAccents(value)\n\n const sep = escape(separator)\n value = value.replace(/[^A-Za-z0-9]+/g, separator)\n if (separator) value = value.replace(new RegExp(`(?:${sep}){2,}`, 'g'), separator)\n if (trim && separator) value = value.replace(new RegExp(`^(?:${sep})+|(?:${sep})+$`, 'g'), '')\n else if (separator) value = value.replace(new RegExp(`^(?:${sep})+`), '')\n\n if (\n maxLength !== undefined &&\n Number.isFinite(maxLength) &&\n maxLength >= 0 &&\n value.length > maxLength\n ) {\n const cut = value.slice(0, maxLength)\n const boundary = separator ? cut.lastIndexOf(separator) : -1\n value = boundary > 0 && value[maxLength] !== separator ? cut.slice(0, boundary) : cut\n if (separator) value = value.replace(new RegExp(`(?:${sep})+$`), '')\n }\n return value\n}\n","import { words } from './words.js'\n\nexport interface TruncateOptions {\n /** Appended when the text is cut. Defaults to `'…'`. Counts toward `length`. */\n ellipsis?: string\n /** Cut at the last whole word instead of mid-word. Defaults to `true`. */\n wordBoundary?: boolean\n}\n\n/**\n * Shorten text to at most `length` characters (code points, so emoji and\n * accents are never split).\n */\nexport const truncate = (\n input: string,\n length: number,\n { ellipsis = '…', wordBoundary = true }: TruncateOptions = {}\n): string => {\n const chars = Array.from(String(input ?? ''))\n if (!Number.isFinite(length) || length < 0 || chars.length <= length) return chars.join('')\n const room = Math.max(0, length - Array.from(ellipsis).length)\n let cut = chars.slice(0, room).join('')\n if (wordBoundary && chars[room] !== undefined && /[\\p{L}\\p{N}]/u.test(chars[room]!)) {\n const lastSpace = cut.search(/\\s\\S*$/u)\n if (lastSpace > 0) cut = cut.slice(0, lastSpace)\n }\n return cut.replace(/[\\s.,;:!?-]+$/u, '') + ellipsis\n}\n\nexport interface InitialsOptions {\n /** Maximum number of letters. Defaults to `2`. */\n max?: number\n locale?: string | string[]\n}\n\n/** `Samuel Olvera` → `SO`, `ana maría lópez` → `AM` */\nexport const initials = (input: string, { max = 2, locale }: InitialsOptions = {}): string =>\n words(String(input ?? ''))\n .slice(0, Math.max(0, max))\n .map(word => Array.from(word)[0]!.toLocaleUpperCase(locale))\n .join('')\n"]}
package/dist/index.cjs ADDED
@@ -0,0 +1,121 @@
1
+ 'use strict';
2
+
3
+ // src/core/words.ts
4
+ var words = (input) => {
5
+ if (typeof input !== "string" || input === "") return [];
6
+ return input.replace(/([\p{Ll}\p{N}])(\p{Lu})/gu, "$1 $2").replace(/(\p{Lu})(\p{Lu}\p{Ll})/gu, "$1 $2").split(/[^\p{L}\p{N}]+/u).filter(Boolean);
7
+ };
8
+
9
+ // src/core/accents.ts
10
+ var TRANSLITERATIONS = {
11
+ \u00DF: "ss",
12
+ "\u1E9E": "SS",
13
+ \u00E6: "ae",
14
+ \u00C6: "AE",
15
+ \u0153: "oe",
16
+ \u0152: "OE",
17
+ \u00F8: "o",
18
+ \u00D8: "O",
19
+ \u0111: "d",
20
+ \u0110: "D",
21
+ \u0142: "l",
22
+ \u0141: "L",
23
+ \u00FE: "th",
24
+ \u00DE: "TH",
25
+ \u00F0: "d",
26
+ \u00D0: "D",
27
+ \u0131: "i"
28
+ };
29
+ var SPECIAL = new RegExp(`[${Object.keys(TRANSLITERATIONS).join("")}]`, "g");
30
+ var removeAccents = (input) => String(input ?? "").normalize("NFKD").replace(/\p{M}+/gu, "").replace(SPECIAL, (char) => TRANSLITERATIONS[char] ?? char);
31
+
32
+ // src/core/case.ts
33
+ var lower = (value, locale) => value.toLocaleLowerCase(locale);
34
+ var upper = (value, locale) => value.toLocaleUpperCase(locale);
35
+ var upperFirst = (value, locale) => {
36
+ const [first = "", ...rest] = Array.from(value);
37
+ return upper(first, locale) + rest.join("");
38
+ };
39
+ var titleWord = (value, locale) => upperFirst(lower(value, locale), locale);
40
+ var camelCase = (input, { locale } = {}) => words(input).map((word, index) => index === 0 ? lower(word, locale) : titleWord(word, locale)).join("");
41
+ var pascalCase = (input, { locale } = {}) => words(input).map((word) => titleWord(word, locale)).join("");
42
+ var joinLower = (separator) => (input, { locale } = {}) => words(input).map((word) => lower(word, locale)).join(separator);
43
+ var kebabCase = joinLower("-");
44
+ var snakeCase = joinLower("_");
45
+ var dotCase = joinLower(".");
46
+ var constantCase = (input, { locale } = {}) => words(input).map((word) => upper(word, locale)).join("_");
47
+ var titleCase = (input, { locale, smallWords = [] } = {}) => {
48
+ const small = new Set(smallWords.map((word) => lower(word, locale)));
49
+ let index = 0;
50
+ return String(input ?? "").replace(/[\p{L}\p{N}]+/gu, (word) => {
51
+ const first = index++ === 0;
52
+ const lowered = lower(word, locale);
53
+ return !first && small.has(lowered) ? lowered : upperFirst(lowered, locale);
54
+ });
55
+ };
56
+ var sentenceCase = (input, { locale } = {}) => upperFirst(lower(String(input ?? ""), locale), locale);
57
+ var capitalize = (input, { locale } = {}) => upperFirst(String(input ?? ""), locale);
58
+ var uncapitalize = (input, { locale } = {}) => {
59
+ const [first = "", ...rest] = Array.from(String(input ?? ""));
60
+ return lower(first, locale) + rest.join("");
61
+ };
62
+
63
+ // src/core/slugify.ts
64
+ var escape = (value) => value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
65
+ var slugify = (input, {
66
+ separator = "-",
67
+ lower: lower2 = true,
68
+ replacements = {},
69
+ maxLength,
70
+ trim = true,
71
+ locale
72
+ } = {}) => {
73
+ let value = String(input ?? "");
74
+ for (const [from, to] of Object.entries(replacements)) value = value.split(from).join(` ${to} `);
75
+ if (lower2) value = value.toLocaleLowerCase(locale);
76
+ value = removeAccents(value);
77
+ const sep = escape(separator);
78
+ value = value.replace(/[^A-Za-z0-9]+/g, separator);
79
+ if (separator) value = value.replace(new RegExp(`(?:${sep}){2,}`, "g"), separator);
80
+ if (trim && separator) value = value.replace(new RegExp(`^(?:${sep})+|(?:${sep})+$`, "g"), "");
81
+ else if (separator) value = value.replace(new RegExp(`^(?:${sep})+`), "");
82
+ if (maxLength !== void 0 && Number.isFinite(maxLength) && maxLength >= 0 && value.length > maxLength) {
83
+ const cut = value.slice(0, maxLength);
84
+ const boundary = separator ? cut.lastIndexOf(separator) : -1;
85
+ value = boundary > 0 && value[maxLength] !== separator ? cut.slice(0, boundary) : cut;
86
+ if (separator) value = value.replace(new RegExp(`(?:${sep})+$`), "");
87
+ }
88
+ return value;
89
+ };
90
+
91
+ // src/core/text.ts
92
+ var truncate = (input, length, { ellipsis = "\u2026", wordBoundary = true } = {}) => {
93
+ const chars = Array.from(String(input ?? ""));
94
+ if (!Number.isFinite(length) || length < 0 || chars.length <= length) return chars.join("");
95
+ const room = Math.max(0, length - Array.from(ellipsis).length);
96
+ let cut = chars.slice(0, room).join("");
97
+ if (wordBoundary && chars[room] !== void 0 && /[\p{L}\p{N}]/u.test(chars[room])) {
98
+ const lastSpace = cut.search(/\s\S*$/u);
99
+ if (lastSpace > 0) cut = cut.slice(0, lastSpace);
100
+ }
101
+ return cut.replace(/[\s.,;:!?-]+$/u, "") + ellipsis;
102
+ };
103
+ var initials = (input, { max = 2, locale } = {}) => words(String(input ?? "")).slice(0, Math.max(0, max)).map((word) => Array.from(word)[0].toLocaleUpperCase(locale)).join("");
104
+
105
+ exports.camelCase = camelCase;
106
+ exports.capitalize = capitalize;
107
+ exports.constantCase = constantCase;
108
+ exports.dotCase = dotCase;
109
+ exports.initials = initials;
110
+ exports.kebabCase = kebabCase;
111
+ exports.pascalCase = pascalCase;
112
+ exports.removeAccents = removeAccents;
113
+ exports.sentenceCase = sentenceCase;
114
+ exports.slugify = slugify;
115
+ exports.snakeCase = snakeCase;
116
+ exports.titleCase = titleCase;
117
+ exports.truncate = truncate;
118
+ exports.uncapitalize = uncapitalize;
119
+ exports.words = words;
120
+ //# sourceMappingURL=index.cjs.map
121
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/core/words.ts","../src/core/accents.ts","../src/core/case.ts","../src/core/slugify.ts","../src/core/text.ts"],"names":["lower"],"mappings":";;;AAQO,IAAM,KAAA,GAAQ,CAAC,KAAA,KAA4B;AAChD,EAAA,IAAI,OAAO,KAAA,KAAU,QAAA,IAAY,KAAA,KAAU,EAAA,SAAW,EAAC;AACvD,EAAA,OACE,KAAA,CAEG,OAAA,CAAQ,2BAAA,EAA6B,OAAO,CAAA,CAE5C,OAAA,CAAQ,0BAAA,EAA4B,OAAO,CAAA,CAC3C,KAAA,CAAM,iBAAiB,CAAA,CACvB,OAAO,OAAO,CAAA;AAErB;;;AClBA,IAAM,gBAAA,GAA2C;AAAA,EAC/C,MAAA,EAAG,IAAA;AAAA,EACH,QAAA,EAAG,IAAA;AAAA,EACH,MAAA,EAAG,IAAA;AAAA,EACH,MAAA,EAAG,IAAA;AAAA,EACH,MAAA,EAAG,IAAA;AAAA,EACH,MAAA,EAAG,IAAA;AAAA,EACH,MAAA,EAAG,GAAA;AAAA,EACH,MAAA,EAAG,GAAA;AAAA,EACH,MAAA,EAAG,GAAA;AAAA,EACH,MAAA,EAAG,GAAA;AAAA,EACH,MAAA,EAAG,GAAA;AAAA,EACH,MAAA,EAAG,GAAA;AAAA,EACH,MAAA,EAAG,IAAA;AAAA,EACH,MAAA,EAAG,IAAA;AAAA,EACH,MAAA,EAAG,GAAA;AAAA,EACH,MAAA,EA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,KAC9E,MAAM,MAAA,CAAO,KAAA,IAAS,EAAE,CAAC,EACtB,KAAA,CAAM,CAAA,EAAG,IAAA,CAAK,GAAA,CAAI,GAAG,GAAG,CAAC,CAAA,CACzB,GAAA,CAAI,UAAQ,KAAA,CAAM,IAAA,CAAK,IAAI,CAAA,CAAE,CAAC,CAAA,CAAG,iBAAA,CAAkB,MAAM,CAAC,CAAA,CAC1D,KAAK,EAAE","file":"index.cjs","sourcesContent":["/**\n * Split any identifier or phrase into words.\n *\n * Handles separators (spaces, `-`, `_`, `.`, `/`, punctuation), camelCase,\n * PascalCase and acronyms (`XMLHttpRequest` → `XML`, `Http`, `Request`), keeps\n * digits attached to their word (`version2` stays one word) and works with any\n * script (`añoNuevo` → `año`, `Nuevo`).\n */\nexport const words = (input: string): string[] => {\n if (typeof input !== 'string' || input === '') return []\n return (\n input\n // fooBar → foo Bar, foo2Bar → foo2 Bar\n .replace(/([\\p{Ll}\\p{N}])(\\p{Lu})/gu, '$1 $2')\n // XMLHttp → XML Http\n .replace(/(\\p{Lu})(\\p{Lu}\\p{Ll})/gu, '$1 $2')\n .split(/[^\\p{L}\\p{N}]+/u)\n .filter(Boolean)\n )\n}\n","/** Letters that Unicode normalization does not decompose into ASCII. */\nconst TRANSLITERATIONS: Record<string, string> = {\n ß: 'ss',\n ẞ: 'SS',\n æ: 'ae',\n Æ: 'AE',\n œ: 'oe',\n Œ: 'OE',\n ø: 'o',\n Ø: 'O',\n đ: 'd',\n Đ: 'D',\n ł: 'l',\n Ł: 'L',\n þ: 'th',\n Þ: 'TH',\n ð: 'd',\n Ð: 'D',\n ı: 'i',\n}\nconst SPECIAL = new RegExp(`[${Object.keys(TRANSLITERATIONS).join('')}]`, 'g')\n\n/** Remove diacritics and transliterate common Latin letters: `Ñandú Straße` → `Nandu Strasse`. */\nexport const removeAccents = (input: string): string =>\n String(input ?? '')\n .normalize('NFKD')\n .replace(/\\p{M}+/gu, '')\n .replace(SPECIAL, char => TRANSLITERATIONS[char] ?? char)\n","import { words } from './words.js'\n\nexport interface CaseOptions {\n /** Locale for upper/lower casing, for example `'tr'` for Turkish dotted i. */\n locale?: string | string[]\n}\n\nconst lower = (value: string, locale?: string | string[]) => value.toLocaleLowerCase(locale)\nconst upper = (value: string, locale?: string | string[]) => value.toLocaleUpperCase(locale)\nconst upperFirst = (value: string, locale?: string | string[]) => {\n const [first = '', ...rest] = Array.from(value)\n return upper(first, locale) + rest.join('')\n}\nconst titleWord = (value: string, locale?: string | string[]) =>\n upperFirst(lower(value, locale), locale)\n\n/** `hello world` → `helloWorld` */\nexport const camelCase = (input: string, { locale }: CaseOptions = {}): string =>\n words(input)\n .map((word, index) => (index === 0 ? lower(word, locale) : titleWord(word, locale)))\n .join('')\n\n/** `hello world` → `HelloWorld` */\nexport const pascalCase = (input: string, { locale }: CaseOptions = {}): string =>\n words(input)\n .map(word => titleWord(word, locale))\n .join('')\n\nconst joinLower =\n (separator: string) =>\n (input: string, { locale }: CaseOptions = {}) =>\n words(input)\n .map(word => lower(word, locale))\n .join(separator)\n\n/** `Hello World` → `hello-world` */\nexport const kebabCase = joinLower('-')\n/** `Hello World` → `hello_world` */\nexport const snakeCase = joinLower('_')\n/** `Hello World` → `hello.world` */\nexport const dotCase = joinLower('.')\n\n/** `Hello World` → `HELLO_WORLD` */\nexport const constantCase = (input: string, { locale }: CaseOptions = {}): string =>\n words(input)\n .map(word => upper(word, locale))\n .join('_')\n\nexport interface TitleCaseOptions extends CaseOptions {\n /**\n * Words kept in lower case unless they come first, for example\n * `['de', 'la', 'y']` or `['of', 'the', 'and']`. Defaults to none.\n */\n smallWords?: readonly string[]\n}\n\n/**\n * `the lord of the rings` → `The Lord Of The Rings` (or `The Lord of the Rings`\n * with `smallWords`). Keeps the original spacing and punctuation.\n */\nexport const titleCase = (\n input: string,\n { locale, smallWords = [] }: TitleCaseOptions = {}\n): string => {\n const small = new Set(smallWords.map(word => lower(word, locale)))\n let index = 0\n return String(input ?? '').replace(/[\\p{L}\\p{N}]+/gu, word => {\n const first = index++ === 0\n const lowered = lower(word, locale)\n return !first && small.has(lowered) ? lowered : upperFirst(lowered, locale)\n })\n}\n\n/** `HELLO world. NEW sentence` → `Hello world. new sentence`; only the first letter is upper case. */\nexport const sentenceCase = (input: string, { locale }: CaseOptions = {}): string =>\n upperFirst(lower(String(input ?? ''), locale), locale)\n\n/** Upper-case the first letter and leave the rest untouched: `hello World` → `Hello World`. */\nexport const capitalize = (input: string, { locale }: CaseOptions = {}): string =>\n upperFirst(String(input ?? ''), locale)\n\n/** Lower-case the first letter and leave the rest untouched: `Hello` → `hello`. */\nexport const uncapitalize = (input: string, { locale }: CaseOptions = {}): string => {\n const [first = '', ...rest] = Array.from(String(input ?? ''))\n return lower(first, locale) + rest.join('')\n}\n","import { removeAccents } from './accents.js'\n\nexport interface SlugifyOptions {\n /** Word separator. Defaults to `'-'`. */\n separator?: string\n /** Lower-case the result. Defaults to `true`. */\n lower?: boolean\n /**\n * Replacements applied before anything else, for example\n * `{ '&': 'y', '%': 'por ciento' }`. Keys are matched literally.\n */\n replacements?: Readonly<Record<string, string>>\n /** Maximum length; cuts at a separator when possible. */\n maxLength?: number\n /**\n * Remove leading and trailing separators. Defaults to `true`. Use `false`\n * while the user is typing, so a trailing space can become a separator.\n */\n trim?: boolean\n /** Locale for lower-casing. */\n locale?: string | string[]\n}\n\nconst escape = (value: string) => value.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&')\n\n/**\n * `¡Hola, Ñandú & Café!` → `hola-nandu-cafe`\n *\n * Removes accents, transliterates common letters (ß, æ, ø, œ, ł…), keeps\n * only ASCII letters and digits, and collapses everything else into one\n * separator.\n */\nexport const slugify = (\n input: string,\n {\n separator = '-',\n lower = true,\n replacements = {},\n maxLength,\n trim = true,\n locale,\n }: SlugifyOptions = {}\n): string => {\n let value = String(input ?? '')\n for (const [from, to] of Object.entries(replacements)) value = value.split(from).join(` ${to} `)\n // Lower-case first: some locales produce letters (Turkish ı) that removeAccents transliterates.\n if (lower) value = value.toLocaleLowerCase(locale)\n value = removeAccents(value)\n\n const sep = escape(separator)\n value = value.replace(/[^A-Za-z0-9]+/g, separator)\n if (separator) value = value.replace(new RegExp(`(?:${sep}){2,}`, 'g'), separator)\n if (trim && separator) value = value.replace(new RegExp(`^(?:${sep})+|(?:${sep})+$`, 'g'), '')\n else if (separator) value = value.replace(new RegExp(`^(?:${sep})+`), '')\n\n if (\n maxLength !== undefined &&\n Number.isFinite(maxLength) &&\n maxLength >= 0 &&\n value.length > maxLength\n ) {\n const cut = value.slice(0, maxLength)\n const boundary = separator ? cut.lastIndexOf(separator) : -1\n value = boundary > 0 && value[maxLength] !== separator ? cut.slice(0, boundary) : cut\n if (separator) value = value.replace(new RegExp(`(?:${sep})+$`), '')\n }\n return value\n}\n","import { words } from './words.js'\n\nexport interface TruncateOptions {\n /** Appended when the text is cut. Defaults to `'…'`. Counts toward `length`. */\n ellipsis?: string\n /** Cut at the last whole word instead of mid-word. Defaults to `true`. */\n wordBoundary?: boolean\n}\n\n/**\n * Shorten text to at most `length` characters (code points, so emoji and\n * accents are never split).\n */\nexport const truncate = (\n input: string,\n length: number,\n { ellipsis = '…', wordBoundary = true }: TruncateOptions = {}\n): string => {\n const chars = Array.from(String(input ?? ''))\n if (!Number.isFinite(length) || length < 0 || chars.length <= length) return chars.join('')\n const room = Math.max(0, length - Array.from(ellipsis).length)\n let cut = chars.slice(0, room).join('')\n if (wordBoundary && chars[room] !== undefined && /[\\p{L}\\p{N}]/u.test(chars[room]!)) {\n const lastSpace = cut.search(/\\s\\S*$/u)\n if (lastSpace > 0) cut = cut.slice(0, lastSpace)\n }\n return cut.replace(/[\\s.,;:!?-]+$/u, '') + ellipsis\n}\n\nexport interface InitialsOptions {\n /** Maximum number of letters. Defaults to `2`. */\n max?: number\n locale?: string | string[]\n}\n\n/** `Samuel Olvera` → `SO`, `ana maría lópez` → `AM` */\nexport const initials = (input: string, { max = 2, locale }: InitialsOptions = {}): string =>\n words(String(input ?? ''))\n .slice(0, Math.max(0, max))\n .map(word => Array.from(word)[0]!.toLocaleUpperCase(locale))\n .join('')\n"]}
@@ -0,0 +1,97 @@
1
+ /**
2
+ * Split any identifier or phrase into words.
3
+ *
4
+ * Handles separators (spaces, `-`, `_`, `.`, `/`, punctuation), camelCase,
5
+ * PascalCase and acronyms (`XMLHttpRequest` → `XML`, `Http`, `Request`), keeps
6
+ * digits attached to their word (`version2` stays one word) and works with any
7
+ * script (`añoNuevo` → `año`, `Nuevo`).
8
+ */
9
+ declare const words: (input: string) => string[];
10
+
11
+ /** Remove diacritics and transliterate common Latin letters: `Ñandú Straße` → `Nandu Strasse`. */
12
+ declare const removeAccents: (input: string) => string;
13
+
14
+ interface CaseOptions {
15
+ /** Locale for upper/lower casing, for example `'tr'` for Turkish dotted i. */
16
+ locale?: string | string[];
17
+ }
18
+ /** `hello world` → `helloWorld` */
19
+ declare const camelCase: (input: string, { locale }?: CaseOptions) => string;
20
+ /** `hello world` → `HelloWorld` */
21
+ declare const pascalCase: (input: string, { locale }?: CaseOptions) => string;
22
+ /** `Hello World` → `hello-world` */
23
+ declare const kebabCase: (input: string, { locale }?: CaseOptions) => string;
24
+ /** `Hello World` → `hello_world` */
25
+ declare const snakeCase: (input: string, { locale }?: CaseOptions) => string;
26
+ /** `Hello World` → `hello.world` */
27
+ declare const dotCase: (input: string, { locale }?: CaseOptions) => string;
28
+ /** `Hello World` → `HELLO_WORLD` */
29
+ declare const constantCase: (input: string, { locale }?: CaseOptions) => string;
30
+ interface TitleCaseOptions extends CaseOptions {
31
+ /**
32
+ * Words kept in lower case unless they come first, for example
33
+ * `['de', 'la', 'y']` or `['of', 'the', 'and']`. Defaults to none.
34
+ */
35
+ smallWords?: readonly string[];
36
+ }
37
+ /**
38
+ * `the lord of the rings` → `The Lord Of The Rings` (or `The Lord of the Rings`
39
+ * with `smallWords`). Keeps the original spacing and punctuation.
40
+ */
41
+ declare const titleCase: (input: string, { locale, smallWords }?: TitleCaseOptions) => string;
42
+ /** `HELLO world. NEW sentence` → `Hello world. new sentence`; only the first letter is upper case. */
43
+ declare const sentenceCase: (input: string, { locale }?: CaseOptions) => string;
44
+ /** Upper-case the first letter and leave the rest untouched: `hello World` → `Hello World`. */
45
+ declare const capitalize: (input: string, { locale }?: CaseOptions) => string;
46
+ /** Lower-case the first letter and leave the rest untouched: `Hello` → `hello`. */
47
+ declare const uncapitalize: (input: string, { locale }?: CaseOptions) => string;
48
+
49
+ interface SlugifyOptions {
50
+ /** Word separator. Defaults to `'-'`. */
51
+ separator?: string;
52
+ /** Lower-case the result. Defaults to `true`. */
53
+ lower?: boolean;
54
+ /**
55
+ * Replacements applied before anything else, for example
56
+ * `{ '&': 'y', '%': 'por ciento' }`. Keys are matched literally.
57
+ */
58
+ replacements?: Readonly<Record<string, string>>;
59
+ /** Maximum length; cuts at a separator when possible. */
60
+ maxLength?: number;
61
+ /**
62
+ * Remove leading and trailing separators. Defaults to `true`. Use `false`
63
+ * while the user is typing, so a trailing space can become a separator.
64
+ */
65
+ trim?: boolean;
66
+ /** Locale for lower-casing. */
67
+ locale?: string | string[];
68
+ }
69
+ /**
70
+ * `¡Hola, Ñandú & Café!` → `hola-nandu-cafe`
71
+ *
72
+ * Removes accents, transliterates common letters (ß, æ, ø, œ, ł…), keeps
73
+ * only ASCII letters and digits, and collapses everything else into one
74
+ * separator.
75
+ */
76
+ declare const slugify: (input: string, { separator, lower, replacements, maxLength, trim, locale, }?: SlugifyOptions) => string;
77
+
78
+ interface TruncateOptions {
79
+ /** Appended when the text is cut. Defaults to `'…'`. Counts toward `length`. */
80
+ ellipsis?: string;
81
+ /** Cut at the last whole word instead of mid-word. Defaults to `true`. */
82
+ wordBoundary?: boolean;
83
+ }
84
+ /**
85
+ * Shorten text to at most `length` characters (code points, so emoji and
86
+ * accents are never split).
87
+ */
88
+ declare const truncate: (input: string, length: number, { ellipsis, wordBoundary }?: TruncateOptions) => string;
89
+ interface InitialsOptions {
90
+ /** Maximum number of letters. Defaults to `2`. */
91
+ max?: number;
92
+ locale?: string | string[];
93
+ }
94
+ /** `Samuel Olvera` → `SO`, `ana maría lópez` → `AM` */
95
+ declare const initials: (input: string, { max, locale }?: InitialsOptions) => string;
96
+
97
+ export { type CaseOptions, type InitialsOptions, type SlugifyOptions, type TitleCaseOptions, type TruncateOptions, camelCase, capitalize, constantCase, dotCase, initials, kebabCase, pascalCase, removeAccents, sentenceCase, slugify, snakeCase, titleCase, truncate, uncapitalize, words };
@@ -0,0 +1,97 @@
1
+ /**
2
+ * Split any identifier or phrase into words.
3
+ *
4
+ * Handles separators (spaces, `-`, `_`, `.`, `/`, punctuation), camelCase,
5
+ * PascalCase and acronyms (`XMLHttpRequest` → `XML`, `Http`, `Request`), keeps
6
+ * digits attached to their word (`version2` stays one word) and works with any
7
+ * script (`añoNuevo` → `año`, `Nuevo`).
8
+ */
9
+ declare const words: (input: string) => string[];
10
+
11
+ /** Remove diacritics and transliterate common Latin letters: `Ñandú Straße` → `Nandu Strasse`. */
12
+ declare const removeAccents: (input: string) => string;
13
+
14
+ interface CaseOptions {
15
+ /** Locale for upper/lower casing, for example `'tr'` for Turkish dotted i. */
16
+ locale?: string | string[];
17
+ }
18
+ /** `hello world` → `helloWorld` */
19
+ declare const camelCase: (input: string, { locale }?: CaseOptions) => string;
20
+ /** `hello world` → `HelloWorld` */
21
+ declare const pascalCase: (input: string, { locale }?: CaseOptions) => string;
22
+ /** `Hello World` → `hello-world` */
23
+ declare const kebabCase: (input: string, { locale }?: CaseOptions) => string;
24
+ /** `Hello World` → `hello_world` */
25
+ declare const snakeCase: (input: string, { locale }?: CaseOptions) => string;
26
+ /** `Hello World` → `hello.world` */
27
+ declare const dotCase: (input: string, { locale }?: CaseOptions) => string;
28
+ /** `Hello World` → `HELLO_WORLD` */
29
+ declare const constantCase: (input: string, { locale }?: CaseOptions) => string;
30
+ interface TitleCaseOptions extends CaseOptions {
31
+ /**
32
+ * Words kept in lower case unless they come first, for example
33
+ * `['de', 'la', 'y']` or `['of', 'the', 'and']`. Defaults to none.
34
+ */
35
+ smallWords?: readonly string[];
36
+ }
37
+ /**
38
+ * `the lord of the rings` → `The Lord Of The Rings` (or `The Lord of the Rings`
39
+ * with `smallWords`). Keeps the original spacing and punctuation.
40
+ */
41
+ declare const titleCase: (input: string, { locale, smallWords }?: TitleCaseOptions) => string;
42
+ /** `HELLO world. NEW sentence` → `Hello world. new sentence`; only the first letter is upper case. */
43
+ declare const sentenceCase: (input: string, { locale }?: CaseOptions) => string;
44
+ /** Upper-case the first letter and leave the rest untouched: `hello World` → `Hello World`. */
45
+ declare const capitalize: (input: string, { locale }?: CaseOptions) => string;
46
+ /** Lower-case the first letter and leave the rest untouched: `Hello` → `hello`. */
47
+ declare const uncapitalize: (input: string, { locale }?: CaseOptions) => string;
48
+
49
+ interface SlugifyOptions {
50
+ /** Word separator. Defaults to `'-'`. */
51
+ separator?: string;
52
+ /** Lower-case the result. Defaults to `true`. */
53
+ lower?: boolean;
54
+ /**
55
+ * Replacements applied before anything else, for example
56
+ * `{ '&': 'y', '%': 'por ciento' }`. Keys are matched literally.
57
+ */
58
+ replacements?: Readonly<Record<string, string>>;
59
+ /** Maximum length; cuts at a separator when possible. */
60
+ maxLength?: number;
61
+ /**
62
+ * Remove leading and trailing separators. Defaults to `true`. Use `false`
63
+ * while the user is typing, so a trailing space can become a separator.
64
+ */
65
+ trim?: boolean;
66
+ /** Locale for lower-casing. */
67
+ locale?: string | string[];
68
+ }
69
+ /**
70
+ * `¡Hola, Ñandú & Café!` → `hola-nandu-cafe`
71
+ *
72
+ * Removes accents, transliterates common letters (ß, æ, ø, œ, ł…), keeps
73
+ * only ASCII letters and digits, and collapses everything else into one
74
+ * separator.
75
+ */
76
+ declare const slugify: (input: string, { separator, lower, replacements, maxLength, trim, locale, }?: SlugifyOptions) => string;
77
+
78
+ interface TruncateOptions {
79
+ /** Appended when the text is cut. Defaults to `'…'`. Counts toward `length`. */
80
+ ellipsis?: string;
81
+ /** Cut at the last whole word instead of mid-word. Defaults to `true`. */
82
+ wordBoundary?: boolean;
83
+ }
84
+ /**
85
+ * Shorten text to at most `length` characters (code points, so emoji and
86
+ * accents are never split).
87
+ */
88
+ declare const truncate: (input: string, length: number, { ellipsis, wordBoundary }?: TruncateOptions) => string;
89
+ interface InitialsOptions {
90
+ /** Maximum number of letters. Defaults to `2`. */
91
+ max?: number;
92
+ locale?: string | string[];
93
+ }
94
+ /** `Samuel Olvera` → `SO`, `ana maría lópez` → `AM` */
95
+ declare const initials: (input: string, { max, locale }?: InitialsOptions) => string;
96
+
97
+ export { type CaseOptions, type InitialsOptions, type SlugifyOptions, type TitleCaseOptions, type TruncateOptions, camelCase, capitalize, constantCase, dotCase, initials, kebabCase, pascalCase, removeAccents, sentenceCase, slugify, snakeCase, titleCase, truncate, uncapitalize, words };
package/dist/index.js ADDED
@@ -0,0 +1,3 @@
1
+ export { camelCase, capitalize, constantCase, dotCase, initials, kebabCase, pascalCase, removeAccents, sentenceCase, slugify, snakeCase, titleCase, truncate, uncapitalize, words } from './chunk-7CEOX6CZ.js';
2
+ //# sourceMappingURL=index.js.map
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"index.js"}
@@ -0,0 +1,121 @@
1
+ 'use strict';
2
+
3
+ // src/core/words.ts
4
+ var words = (input) => {
5
+ if (typeof input !== "string" || input === "") return [];
6
+ return input.replace(/([\p{Ll}\p{N}])(\p{Lu})/gu, "$1 $2").replace(/(\p{Lu})(\p{Lu}\p{Ll})/gu, "$1 $2").split(/[^\p{L}\p{N}]+/u).filter(Boolean);
7
+ };
8
+
9
+ // src/core/accents.ts
10
+ var TRANSLITERATIONS = {
11
+ \u00DF: "ss",
12
+ "\u1E9E": "SS",
13
+ \u00E6: "ae",
14
+ \u00C6: "AE",
15
+ \u0153: "oe",
16
+ \u0152: "OE",
17
+ \u00F8: "o",
18
+ \u00D8: "O",
19
+ \u0111: "d",
20
+ \u0110: "D",
21
+ \u0142: "l",
22
+ \u0141: "L",
23
+ \u00FE: "th",
24
+ \u00DE: "TH",
25
+ \u00F0: "d",
26
+ \u00D0: "D",
27
+ \u0131: "i"
28
+ };
29
+ var SPECIAL = new RegExp(`[${Object.keys(TRANSLITERATIONS).join("")}]`, "g");
30
+ var removeAccents = (input) => String(input ?? "").normalize("NFKD").replace(/\p{M}+/gu, "").replace(SPECIAL, (char) => TRANSLITERATIONS[char] ?? char);
31
+
32
+ // src/core/case.ts
33
+ var lower = (value, locale) => value.toLocaleLowerCase(locale);
34
+ var upper = (value, locale) => value.toLocaleUpperCase(locale);
35
+ var upperFirst = (value, locale) => {
36
+ const [first = "", ...rest] = Array.from(value);
37
+ return upper(first, locale) + rest.join("");
38
+ };
39
+ var titleWord = (value, locale) => upperFirst(lower(value, locale), locale);
40
+ var camelCase = (input, { locale } = {}) => words(input).map((word, index) => index === 0 ? lower(word, locale) : titleWord(word, locale)).join("");
41
+ var pascalCase = (input, { locale } = {}) => words(input).map((word) => titleWord(word, locale)).join("");
42
+ var joinLower = (separator) => (input, { locale } = {}) => words(input).map((word) => lower(word, locale)).join(separator);
43
+ var kebabCase = joinLower("-");
44
+ var snakeCase = joinLower("_");
45
+ var dotCase = joinLower(".");
46
+ var constantCase = (input, { locale } = {}) => words(input).map((word) => upper(word, locale)).join("_");
47
+ var titleCase = (input, { locale, smallWords = [] } = {}) => {
48
+ const small = new Set(smallWords.map((word) => lower(word, locale)));
49
+ let index = 0;
50
+ return String(input ?? "").replace(/[\p{L}\p{N}]+/gu, (word) => {
51
+ const first = index++ === 0;
52
+ const lowered = lower(word, locale);
53
+ return !first && small.has(lowered) ? lowered : upperFirst(lowered, locale);
54
+ });
55
+ };
56
+ var sentenceCase = (input, { locale } = {}) => upperFirst(lower(String(input ?? ""), locale), locale);
57
+ var capitalize = (input, { locale } = {}) => upperFirst(String(input ?? ""), locale);
58
+ var uncapitalize = (input, { locale } = {}) => {
59
+ const [first = "", ...rest] = Array.from(String(input ?? ""));
60
+ return lower(first, locale) + rest.join("");
61
+ };
62
+
63
+ // src/core/slugify.ts
64
+ var escape = (value) => value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
65
+ var slugify = (input, {
66
+ separator = "-",
67
+ lower: lower2 = true,
68
+ replacements = {},
69
+ maxLength,
70
+ trim = true,
71
+ locale
72
+ } = {}) => {
73
+ let value = String(input ?? "");
74
+ for (const [from, to] of Object.entries(replacements)) value = value.split(from).join(` ${to} `);
75
+ if (lower2) value = value.toLocaleLowerCase(locale);
76
+ value = removeAccents(value);
77
+ const sep = escape(separator);
78
+ value = value.replace(/[^A-Za-z0-9]+/g, separator);
79
+ if (separator) value = value.replace(new RegExp(`(?:${sep}){2,}`, "g"), separator);
80
+ if (trim && separator) value = value.replace(new RegExp(`^(?:${sep})+|(?:${sep})+$`, "g"), "");
81
+ else if (separator) value = value.replace(new RegExp(`^(?:${sep})+`), "");
82
+ if (maxLength !== void 0 && Number.isFinite(maxLength) && maxLength >= 0 && value.length > maxLength) {
83
+ const cut = value.slice(0, maxLength);
84
+ const boundary = separator ? cut.lastIndexOf(separator) : -1;
85
+ value = boundary > 0 && value[maxLength] !== separator ? cut.slice(0, boundary) : cut;
86
+ if (separator) value = value.replace(new RegExp(`(?:${sep})+$`), "");
87
+ }
88
+ return value;
89
+ };
90
+
91
+ // src/core/text.ts
92
+ var truncate = (input, length, { ellipsis = "\u2026", wordBoundary = true } = {}) => {
93
+ const chars = Array.from(String(input ?? ""));
94
+ if (!Number.isFinite(length) || length < 0 || chars.length <= length) return chars.join("");
95
+ const room = Math.max(0, length - Array.from(ellipsis).length);
96
+ let cut = chars.slice(0, room).join("");
97
+ if (wordBoundary && chars[room] !== void 0 && /[\p{L}\p{N}]/u.test(chars[room])) {
98
+ const lastSpace = cut.search(/\s\S*$/u);
99
+ if (lastSpace > 0) cut = cut.slice(0, lastSpace);
100
+ }
101
+ return cut.replace(/[\s.,;:!?-]+$/u, "") + ellipsis;
102
+ };
103
+ var initials = (input, { max = 2, locale } = {}) => words(String(input ?? "")).slice(0, Math.max(0, max)).map((word) => Array.from(word)[0].toLocaleUpperCase(locale)).join("");
104
+
105
+ exports.camelCase = camelCase;
106
+ exports.capitalize = capitalize;
107
+ exports.constantCase = constantCase;
108
+ exports.dotCase = dotCase;
109
+ exports.initials = initials;
110
+ exports.kebabCase = kebabCase;
111
+ exports.pascalCase = pascalCase;
112
+ exports.removeAccents = removeAccents;
113
+ exports.sentenceCase = sentenceCase;
114
+ exports.slugify = slugify;
115
+ exports.snakeCase = snakeCase;
116
+ exports.titleCase = titleCase;
117
+ exports.truncate = truncate;
118
+ exports.uncapitalize = uncapitalize;
119
+ exports.words = words;
120
+ //# sourceMappingURL=index.cjs.map
121
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/core/words.ts","../../src/core/accents.ts","../../src/core/case.ts","../../src/core/slugify.ts","../../src/core/text.ts"],"names":["lower"],"mappings":";;;AAQO,IAAM,KAAA,GAAQ,CAAC,KAAA,KAA4B;AAChD,EAAA,IAAI,OAAO,KAAA,KAAU,QAAA,IAAY,KAAA,KAAU,EAAA,SAAW,EAAC;AACvD,EAAA,OACE,KAAA,CAEG,OAAA,CAAQ,2BAAA,EAA6B,OAAO,CAAA,CAE5C,OAAA,CAAQ,0BAAA,EAA4B,OAAO,CAAA,CAC3C,KAAA,CAAM,iBAAiB,CAAA,CACvB,OAAO,OAAO,CAAA;AAErB;;;AClBA,IAAM,gBAAA,GAA2C;AAAA,EAC/C,MAAA,EAAG,IAAA;AAAA,EACH,QAAA,EAAG,IAAA;AAAA,EACH,MAAA,EAAG,IAAA;AAAA,EACH,MAAA,EAAG,IAAA;AAAA,EACH,MAAA,EAAG,IAAA;AAAA,EACH,MAAA,EAAG,IAAA;AAAA,EACH,MAAA,EAAG,GAAA;AAAA,EACH,MAAA,EAAG,GAAA;AAAA,EACH,MAAA,EAAG,GAAA;AAAA,EACH,MAAA,EAAG,GAAA;AAAA,EACH,MAAA,EAAG,GA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A,CAAQ,gBAAA,EAAkB,EAAE,CAAA,GAAI,QAAA;AAC7C;AASO,IAAM,WAAW,CAAC,KAAA,EAAe,EAAE,GAAA,GAAM,GAAG,MAAA,EAAO,GAAqB,EAAC,KAC9E,MAAM,MAAA,CAAO,KAAA,IAAS,EAAE,CAAC,EACtB,KAAA,CAAM,CAAA,EAAG,IAAA,CAAK,GAAA,CAAI,GAAG,GAAG,CAAC,CAAA,CACzB,GAAA,CAAI,UAAQ,KAAA,CAAM,IAAA,CAAK,IAAI,CAAA,CAAE,CAAC,CAAA,CAAG,iBAAA,CAAkB,MAAM,CAAC,CAAA,CAC1D,KAAK,EAAE","file":"index.cjs","sourcesContent":["/**\n * Split any identifier or phrase into words.\n *\n * Handles separators (spaces, `-`, `_`, `.`, `/`, punctuation), camelCase,\n * PascalCase and acronyms (`XMLHttpRequest` → `XML`, `Http`, `Request`), keeps\n * digits attached to their word (`version2` stays one word) and works with any\n * script (`añoNuevo` → `año`, `Nuevo`).\n */\nexport const words = (input: string): string[] => {\n if (typeof input !== 'string' || input === '') return []\n return (\n input\n // fooBar → foo Bar, foo2Bar → foo2 Bar\n .replace(/([\\p{Ll}\\p{N}])(\\p{Lu})/gu, '$1 $2')\n // XMLHttp → XML Http\n .replace(/(\\p{Lu})(\\p{Lu}\\p{Ll})/gu, '$1 $2')\n .split(/[^\\p{L}\\p{N}]+/u)\n .filter(Boolean)\n )\n}\n","/** Letters that Unicode normalization does not decompose into ASCII. */\nconst TRANSLITERATIONS: Record<string, string> = {\n ß: 'ss',\n ẞ: 'SS',\n æ: 'ae',\n Æ: 'AE',\n œ: 'oe',\n Œ: 'OE',\n ø: 'o',\n Ø: 'O',\n đ: 'd',\n Đ: 'D',\n ł: 'l',\n Ł: 'L',\n þ: 'th',\n Þ: 'TH',\n ð: 'd',\n Ð: 'D',\n ı: 'i',\n}\nconst SPECIAL = new RegExp(`[${Object.keys(TRANSLITERATIONS).join('')}]`, 'g')\n\n/** Remove diacritics and transliterate common Latin letters: `Ñandú Straße` → `Nandu Strasse`. */\nexport const removeAccents = (input: string): string =>\n String(input ?? '')\n .normalize('NFKD')\n .replace(/\\p{M}+/gu, '')\n .replace(SPECIAL, char => TRANSLITERATIONS[char] ?? char)\n","import { words } from './words.js'\n\nexport interface CaseOptions {\n /** Locale for upper/lower casing, for example `'tr'` for Turkish dotted i. */\n locale?: string | string[]\n}\n\nconst lower = (value: string, locale?: string | string[]) => value.toLocaleLowerCase(locale)\nconst upper = (value: string, locale?: string | string[]) => value.toLocaleUpperCase(locale)\nconst upperFirst = (value: string, locale?: string | string[]) => {\n const [first = '', ...rest] = Array.from(value)\n return upper(first, locale) + rest.join('')\n}\nconst titleWord = (value: string, locale?: string | string[]) =>\n upperFirst(lower(value, locale), locale)\n\n/** `hello world` → `helloWorld` */\nexport const camelCase = (input: string, { locale }: CaseOptions = {}): string =>\n words(input)\n .map((word, index) => (index === 0 ? lower(word, locale) : titleWord(word, locale)))\n .join('')\n\n/** `hello world` → `HelloWorld` */\nexport const pascalCase = (input: string, { locale }: CaseOptions = {}): string =>\n words(input)\n .map(word => titleWord(word, locale))\n .join('')\n\nconst joinLower =\n (separator: string) =>\n (input: string, { locale }: CaseOptions = {}) =>\n words(input)\n .map(word => lower(word, locale))\n .join(separator)\n\n/** `Hello World` → `hello-world` */\nexport const kebabCase = joinLower('-')\n/** `Hello World` → `hello_world` */\nexport const snakeCase = joinLower('_')\n/** `Hello World` → `hello.world` */\nexport const dotCase = joinLower('.')\n\n/** `Hello World` → `HELLO_WORLD` */\nexport const constantCase = (input: string, { locale }: CaseOptions = {}): string =>\n words(input)\n .map(word => upper(word, locale))\n .join('_')\n\nexport interface TitleCaseOptions extends CaseOptions {\n /**\n * Words kept in lower case unless they come first, for example\n * `['de', 'la', 'y']` or `['of', 'the', 'and']`. Defaults to none.\n */\n smallWords?: readonly string[]\n}\n\n/**\n * `the lord of the rings` → `The Lord Of The Rings` (or `The Lord of the Rings`\n * with `smallWords`). Keeps the original spacing and punctuation.\n */\nexport const titleCase = (\n input: string,\n { locale, smallWords = [] }: TitleCaseOptions = {}\n): string => {\n const small = new Set(smallWords.map(word => lower(word, locale)))\n let index = 0\n return String(input ?? '').replace(/[\\p{L}\\p{N}]+/gu, word => {\n const first = index++ === 0\n const lowered = lower(word, locale)\n return !first && small.has(lowered) ? lowered : upperFirst(lowered, locale)\n })\n}\n\n/** `HELLO world. NEW sentence` → `Hello world. new sentence`; only the first letter is upper case. */\nexport const sentenceCase = (input: string, { locale }: CaseOptions = {}): string =>\n upperFirst(lower(String(input ?? ''), locale), locale)\n\n/** Upper-case the first letter and leave the rest untouched: `hello World` → `Hello World`. */\nexport const capitalize = (input: string, { locale }: CaseOptions = {}): string =>\n upperFirst(String(input ?? ''), locale)\n\n/** Lower-case the first letter and leave the rest untouched: `Hello` → `hello`. */\nexport const uncapitalize = (input: string, { locale }: CaseOptions = {}): string => {\n const [first = '', ...rest] = Array.from(String(input ?? ''))\n return lower(first, locale) + rest.join('')\n}\n","import { removeAccents } from './accents.js'\n\nexport interface SlugifyOptions {\n /** Word separator. Defaults to `'-'`. */\n separator?: string\n /** Lower-case the result. Defaults to `true`. */\n lower?: boolean\n /**\n * Replacements applied before anything else, for example\n * `{ '&': 'y', '%': 'por ciento' }`. Keys are matched literally.\n */\n replacements?: Readonly<Record<string, string>>\n /** Maximum length; cuts at a separator when possible. */\n maxLength?: number\n /**\n * Remove leading and trailing separators. Defaults to `true`. Use `false`\n * while the user is typing, so a trailing space can become a separator.\n */\n trim?: boolean\n /** Locale for lower-casing. */\n locale?: string | string[]\n}\n\nconst escape = (value: string) => value.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&')\n\n/**\n * `¡Hola, Ñandú & Café!` → `hola-nandu-cafe`\n *\n * Removes accents, transliterates common letters (ß, æ, ø, œ, ł…), keeps\n * only ASCII letters and digits, and collapses everything else into one\n * separator.\n */\nexport const slugify = (\n input: string,\n {\n separator = '-',\n lower = true,\n replacements = {},\n maxLength,\n trim = true,\n locale,\n }: SlugifyOptions = {}\n): string => {\n let value = String(input ?? '')\n for (const [from, to] of Object.entries(replacements)) value = value.split(from).join(` ${to} `)\n // Lower-case first: some locales produce letters (Turkish ı) that removeAccents transliterates.\n if (lower) value = value.toLocaleLowerCase(locale)\n value = removeAccents(value)\n\n const sep = escape(separator)\n value = value.replace(/[^A-Za-z0-9]+/g, separator)\n if (separator) value = value.replace(new RegExp(`(?:${sep}){2,}`, 'g'), separator)\n if (trim && separator) value = value.replace(new RegExp(`^(?:${sep})+|(?:${sep})+$`, 'g'), '')\n else if (separator) value = value.replace(new RegExp(`^(?:${sep})+`), '')\n\n if (\n maxLength !== undefined &&\n Number.isFinite(maxLength) &&\n maxLength >= 0 &&\n value.length > maxLength\n ) {\n const cut = value.slice(0, maxLength)\n const boundary = separator ? cut.lastIndexOf(separator) : -1\n value = boundary > 0 && value[maxLength] !== separator ? cut.slice(0, boundary) : cut\n if (separator) value = value.replace(new RegExp(`(?:${sep})+$`), '')\n }\n return value\n}\n","import { words } from './words.js'\n\nexport interface TruncateOptions {\n /** Appended when the text is cut. Defaults to `'…'`. Counts toward `length`. */\n ellipsis?: string\n /** Cut at the last whole word instead of mid-word. Defaults to `true`. */\n wordBoundary?: boolean\n}\n\n/**\n * Shorten text to at most `length` characters (code points, so emoji and\n * accents are never split).\n */\nexport const truncate = (\n input: string,\n length: number,\n { ellipsis = '…', wordBoundary = true }: TruncateOptions = {}\n): string => {\n const chars = Array.from(String(input ?? ''))\n if (!Number.isFinite(length) || length < 0 || chars.length <= length) return chars.join('')\n const room = Math.max(0, length - Array.from(ellipsis).length)\n let cut = chars.slice(0, room).join('')\n if (wordBoundary && chars[room] !== undefined && /[\\p{L}\\p{N}]/u.test(chars[room]!)) {\n const lastSpace = cut.search(/\\s\\S*$/u)\n if (lastSpace > 0) cut = cut.slice(0, lastSpace)\n }\n return cut.replace(/[\\s.,;:!?-]+$/u, '') + ellipsis\n}\n\nexport interface InitialsOptions {\n /** Maximum number of letters. Defaults to `2`. */\n max?: number\n locale?: string | string[]\n}\n\n/** `Samuel Olvera` → `SO`, `ana maría lópez` → `AM` */\nexport const initials = (input: string, { max = 2, locale }: InitialsOptions = {}): string =>\n words(String(input ?? ''))\n .slice(0, Math.max(0, max))\n .map(word => Array.from(word)[0]!.toLocaleUpperCase(locale))\n .join('')\n"]}
@@ -0,0 +1 @@
1
+ export { CaseOptions, InitialsOptions, SlugifyOptions, TitleCaseOptions, TruncateOptions, camelCase, capitalize, constantCase, dotCase, initials, kebabCase, pascalCase, removeAccents, sentenceCase, slugify, snakeCase, titleCase, truncate, uncapitalize, words } from '../index.cjs';
@@ -0,0 +1 @@
1
+ export { CaseOptions, InitialsOptions, SlugifyOptions, TitleCaseOptions, TruncateOptions, camelCase, capitalize, constantCase, dotCase, initials, kebabCase, pascalCase, removeAccents, sentenceCase, slugify, snakeCase, titleCase, truncate, uncapitalize, words } from '../index.js';
@@ -0,0 +1,3 @@
1
+ export { camelCase, capitalize, constantCase, dotCase, initials, kebabCase, pascalCase, removeAccents, sentenceCase, slugify, snakeCase, titleCase, truncate, uncapitalize, words } from '../chunk-7CEOX6CZ.js';
2
+ //# sourceMappingURL=index.js.map
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"index.js"}
package/package.json CHANGED
@@ -1,6 +1,74 @@
1
1
  {
2
2
  "name": "@samline/string",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "1.0.0",
4
+ "description": "Case conversion, slugify, accents, truncate and initials built on one Unicode-aware word splitter, for vanilla JavaScript, TypeScript and plain HTML.",
5
+ "keywords": [
6
+ "string",
7
+ "case",
8
+ "camelcase",
9
+ "kebab-case",
10
+ "snake-case",
11
+ "slugify",
12
+ "slug",
13
+ "title-case",
14
+ "accents",
15
+ "truncate"
16
+ ],
17
+ "author": "Samuel Olvera (samline)",
18
+ "license": "MIT",
19
+ "homepage": "https://samline.github.io/utils/string/",
20
+ "repository": {
21
+ "type": "git",
22
+ "url": "git+https://github.com/samline/utils.git",
23
+ "directory": "packages/string"
24
+ },
25
+ "bugs": {
26
+ "url": "https://github.com/samline/utils/issues"
27
+ },
28
+ "type": "module",
29
+ "sideEffects": [
30
+ "./dist/browser/string.global.js"
31
+ ],
32
+ "files": [
33
+ "dist",
34
+ "CHANGELOG.md",
35
+ "LICENSE.md"
36
+ ],
37
+ "engines": {
38
+ "node": ">=20"
39
+ },
40
+ "publishConfig": {
41
+ "access": "public"
42
+ },
43
+ "main": "./dist/index.cjs",
44
+ "module": "./dist/index.js",
45
+ "types": "./dist/index.d.ts",
46
+ "unpkg": "./dist/browser/string.global.js",
47
+ "jsdelivr": "./dist/browser/string.global.js",
48
+ "exports": {
49
+ ".": {
50
+ "types": "./dist/index.d.ts",
51
+ "import": "./dist/index.js",
52
+ "require": "./dist/index.cjs"
53
+ },
54
+ "./vanilla": {
55
+ "types": "./dist/vanilla/index.d.ts",
56
+ "import": "./dist/vanilla/index.js",
57
+ "require": "./dist/vanilla/index.cjs"
58
+ },
59
+ "./browser": "./dist/browser/string.global.js",
60
+ "./package.json": "./package.json"
61
+ },
62
+ "scripts": {
63
+ "clean": "rm -rf dist coverage",
64
+ "build": "tsup",
65
+ "typecheck": "tsc --noEmit -p tsconfig.json",
66
+ "test": "vitest run",
67
+ "test:coverage": "vitest run --coverage",
68
+ "prepublishOnly": "bun run clean && bun run build && bun run typecheck && bun run test:coverage"
69
+ },
70
+ "size": {
71
+ "./dist/index.js": 1500,
72
+ "./dist/browser/string.global.js": 1500
73
+ }
74
+ }