@samline/string 1.0.0 → 1.5.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 +66 -3
- package/README.md +95 -32
- package/dist/browser/string.global.js +1 -1
- package/dist/browser/string.global.js.map +1 -1
- package/dist/chunk-3EFE2B7D.js +567 -0
- package/dist/chunk-3EFE2B7D.js.map +1 -0
- package/dist/index.cjs +503 -15
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +280 -9
- package/dist/index.d.ts +280 -9
- package/dist/index.js +1 -1
- package/dist/vanilla/index.cjs +1239 -15
- package/dist/vanilla/index.cjs.map +1 -1
- package/dist/vanilla/index.d.cts +254 -1
- package/dist/vanilla/index.d.ts +254 -1
- package/dist/vanilla/index.js +714 -1
- package/dist/vanilla/index.js.map +1 -1
- package/package.json +56 -8
- package/dist/chunk-7CEOX6CZ.js +0 -105
- package/dist/chunk-7CEOX6CZ.js.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,7 +1,70 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Changelog
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
All notable changes to this package. Format: [Keep a Changelog](https://keepachangelog.com/en/1.1.0/); versions follow [semver](https://semver.org/).
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
## Unreleased
|
|
6
|
+
|
|
7
|
+
## [1.5.0] - 2026-11-15
|
|
8
|
+
|
|
9
|
+
### Added
|
|
10
|
+
|
|
11
|
+
- `count` / `autoCount` and `data-string-count`: characters (graphemes) or words in a field, the remaining count from `maxlength` or `max`, a `{count}`/`{max}`/`{remaining}` template, `ok`/`near`/`over` states and a `string:count` event.
|
|
12
|
+
- `fit` / `autoFit` and `data-string-fit`: text cut in the middle (or at the end or start) to fit its box, fitted again on resize and when fonts load, with the full text in `title`.
|
|
13
|
+
- `copy` / `autoCopy` and `data-string-copy`: copy a field's or element's text to the clipboard, optionally converted with `data-string-copy-as`, with `copied`/`error` states and a `string:copy` event.
|
|
14
|
+
- `hashColor(text)` and `data-string-color` (`color` option): a stable `--string-color` per name for avatar backgrounds, dark enough for white text at 4.5:1 by default.
|
|
15
|
+
- The browser bundle starts every behavior; `SamlineString.auto()` takes per-behavior options under `search`, `count`, `fit` and `copy`.
|
|
16
|
+
|
|
17
|
+
## [1.4.0] - 2026-11-15
|
|
18
|
+
|
|
19
|
+
### Added
|
|
20
|
+
|
|
21
|
+
- `graphemes(text)`: user-perceived characters with `Intl.Segmenter` (code points as the fallback).
|
|
22
|
+
- `wordCount` and `readingTime`, with locale-aware word boundaries.
|
|
23
|
+
- `pluralize(count, forms, { locale, ordinal })` with `Intl.PluralRules`, a formatted `#` count and an explicit `zero` form.
|
|
24
|
+
- `template(text, values, { missing })` with nested paths and `{{ }}` for literal braces.
|
|
25
|
+
- `escapeHtml`, `unescapeHtml` and `stripTags`.
|
|
26
|
+
- `closest` `partial` option (on by default): compares the input with the start of each word of longer candidates, so `horchatta` finds `Horchata de arroz`.
|
|
27
|
+
|
|
28
|
+
### Fixed
|
|
29
|
+
|
|
30
|
+
- `truncate` and `initials` count graphemes instead of code points, so emoji sequences (👨👩👧, flags) and letters with combining accents are never split.
|
|
31
|
+
- `words` (and every case function) and `titleCase` keep combining accents inside their word: decomposed `é` no longer splits `élan` into two words.
|
|
32
|
+
|
|
33
|
+
## [1.3.0] - 2026-11-15
|
|
34
|
+
|
|
35
|
+
### Added
|
|
36
|
+
|
|
37
|
+
- `uniqueSlug(text, taken, options)`: the first free slug (`hola-3`), with the number kept inside `maxLength`; `taken` is a list, a `Set` or a function. `convert(text, 'slug', { taken })` uses it.
|
|
38
|
+
- Transliteration presets `CYRILLIC`, `GREEK` and `GERMAN` (plus `CHAR_MAPS`), and a `charMap` option for `slugify`, `removeAccents` and `convert`.
|
|
39
|
+
- `slugify` `preserve` option to keep characters such as `.` or `_`, and replacement pairs with regular expressions.
|
|
40
|
+
- `data-string-taken`, `data-string-transliterate` and `data-string-preserve` attributes. A slug field moves to a free slug on blur, not while the user types.
|
|
41
|
+
|
|
42
|
+
## [1.2.0] - 2026-11-15
|
|
43
|
+
|
|
44
|
+
### Added
|
|
45
|
+
|
|
46
|
+
- Search and comparison: `fold` (case, accents, full-width), `contains` (every query word, accent-insensitive), `highlight` (matching pieces of the original text, without HTML), `compareNatural` (numeric, locale-aware, accent-insensitive sorting), `distance`, `similarity` and `closest` for typo suggestions.
|
|
47
|
+
- `search(target, options)` and `autoSearch(options)` in `@samline/string/vanilla`: `data-string-search="#q"` filters a list as the user types, wraps matches in `<mark>`, shows a `data-string-search-empty` message, reports `data-string-search-state` and a `string:search` event, and restores the markup on `destroy()`.
|
|
48
|
+
- The browser bundle also starts `[data-string-search]` lists; `SamlineString.auto({ search })` takes search-only options.
|
|
49
|
+
|
|
50
|
+
## [1.1.0] - 2026-11-15
|
|
51
|
+
|
|
52
|
+
### Added
|
|
53
|
+
|
|
54
|
+
- HTML layer in `@samline/string/vanilla`: `string(target, options)` and `autoString(options)` convert any element with `data-string="<conversion>"` and restore the original markup on `destroy()`. Inputs and textareas convert while the user types (keeping a just-typed separator and the caret, skipping IME composition) and finalize on blur.
|
|
55
|
+
- `data-string-source`: a field or preview follows another one. A slug field follows the title until the user edits it and follows again when emptied; sources chain. State in `data-string-state` (`ready`, `following`, `edited`) and a bubbling `string:change` event.
|
|
56
|
+
- Every option as a `data-string-*` attribute, the locale taken from the closest `lang`, `title` on truncated text and an accessible label on initials.
|
|
57
|
+
- The browser bundle converts `[data-string]` on load and for elements added later; `data-manual` on the script tag waits for `SamlineString.auto()`.
|
|
58
|
+
- `convert(text, to, options)`, `CONVERSIONS` and `isConversion` to run any conversion by name.
|
|
59
|
+
- `pathCase` (`hello/world`) and `trainCase` (`Content-Type`).
|
|
60
|
+
- `truncate` `position` option: `'middle'` keeps both ends of file names and IDs, `'start'` keeps the ending.
|
|
61
|
+
|
|
62
|
+
### Changed
|
|
63
|
+
|
|
64
|
+
- The package moved from the `samline/utils` monorepo to its own repository, [samline/string](https://github.com/samline/string). Homepage, repository and documentation links point to the package's own site.
|
|
65
|
+
|
|
66
|
+
## [1.0.0] - 2026-11-13
|
|
67
|
+
|
|
68
|
+
### Added
|
|
6
69
|
|
|
7
70
|
- 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/README.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
# @samline/string
|
|
2
2
|
|
|
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.
|
|
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. Accent-insensitive search, highlighting, natural sorting and typo suggestions use the same rules. Call the functions from code, or convert text, fill form fields and filter lists straight from HTML attributes.
|
|
4
4
|
|
|
5
|
-
[Demo](https://samline.github.io/
|
|
5
|
+
[Demo](https://samline.github.io/string/) · [Examples](https://samline.github.io/string/examples/) · [Documentation](https://samline.github.io/string/docs/) · [Changelog](CHANGELOG.md)
|
|
6
6
|
|
|
7
7
|
## Table of contents
|
|
8
8
|
|
|
@@ -30,18 +30,54 @@ pnpm add @samline/string
|
|
|
30
30
|
bun add @samline/string
|
|
31
31
|
```
|
|
32
32
|
|
|
33
|
-
|
|
33
|
+
The functions are pure, with no DOM access: browsers, Node 20 or newer, workers and edge runtimes. The optional HTML layer in `@samline/string/vanilla` needs a DOM and does nothing without one. No runtime dependencies.
|
|
34
34
|
|
|
35
35
|
## Quick start
|
|
36
36
|
|
|
37
37
|
```js
|
|
38
|
-
import { camelCase, kebabCase, slugify, titleCase, truncate } from '@samline/string'
|
|
38
|
+
import { camelCase, convert, kebabCase, slugify, titleCase, truncate } from '@samline/string'
|
|
39
39
|
|
|
40
40
|
camelCase('XMLHttp request_id') // 'xmlHttpRequestId'
|
|
41
41
|
kebabCase('someLongName') // 'some-long-name'
|
|
42
42
|
titleCase('el señor de los anillos', { smallWords: ['de', 'los'] }) // 'El Señor de los Anillos'
|
|
43
43
|
slugify('¡Hola, Ñandú & Café!', { replacements: { '&': 'y' } }) // 'hola-nandu-y-cafe'
|
|
44
44
|
truncate('The quick brown fox jumps', 15) // 'The quick…'
|
|
45
|
+
truncate('annual-report-2026-final.pdf', 19, { position: 'middle' }) // 'annual-re…final.pdf'
|
|
46
|
+
convert('content type', 'train') // 'Content-Type'
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
Or let HTML attributes do the work. This slug field fills itself from the title until the user edits it:
|
|
50
|
+
|
|
51
|
+
```html
|
|
52
|
+
<input id="title" value="Café & Té" />
|
|
53
|
+
<input data-string="slug" data-string-source="#title" />
|
|
54
|
+
<span data-string="initials">Samuel Olvera</span>
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
```js
|
|
58
|
+
import { string } from '@samline/string/vanilla'
|
|
59
|
+
|
|
60
|
+
string() // converts every [data-string] element; returns { refresh, destroy }
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
Search without worrying about accents or case:
|
|
64
|
+
|
|
65
|
+
```js
|
|
66
|
+
import { closest, compareNatural, contains, highlight } from '@samline/string'
|
|
67
|
+
|
|
68
|
+
contains('México: Café de olla', 'cafe mex') // true
|
|
69
|
+
highlight('Café de olla', 'cafe') // [{ text: 'Café', match: true }, { text: ' de olla', match: false }]
|
|
70
|
+
;['file10', 'file2', 'File1'].sort(compareNatural) // ['File1', 'file2', 'file10']
|
|
71
|
+
closest('te vrde', ['Café de olla', 'Té verde']) // 'Té verde'
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
```html
|
|
75
|
+
<input id="q" type="search" />
|
|
76
|
+
<ul data-string-search="#q">
|
|
77
|
+
<li>Café de olla</li>
|
|
78
|
+
<li>Té verde</li>
|
|
79
|
+
<li hidden data-string-search-empty>No results</li>
|
|
80
|
+
</ul>
|
|
45
81
|
```
|
|
46
82
|
|
|
47
83
|
## HTML / CDN
|
|
@@ -49,14 +85,14 @@ truncate('The quick brown fox jumps', 15) // 'The quick…'
|
|
|
49
85
|
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
86
|
|
|
51
87
|
```html
|
|
52
|
-
<script src="https://cdn.jsdelivr.net/npm/@samline/string@1.
|
|
88
|
+
<script src="https://cdn.jsdelivr.net/npm/@samline/string@1.5.0/dist/browser/string.global.js"></script>
|
|
53
89
|
<script>
|
|
54
90
|
const { slugify } = window.SamlineString
|
|
55
91
|
console.log(slugify('Café & Té')) // 'cafe-te'
|
|
56
92
|
</script>
|
|
57
93
|
```
|
|
58
94
|
|
|
59
|
-
The bundle defines `window.SamlineString` with every function.
|
|
95
|
+
The bundle defines `window.SamlineString` with every function and converts every `[data-string]` element and filters every `[data-string-search]` list when the DOM is ready, including elements added later. Add `data-manual` to the script tag to start it yourself with `SamlineString.auto(options)`.
|
|
60
96
|
|
|
61
97
|
## Capabilities
|
|
62
98
|
|
|
@@ -66,58 +102,85 @@ The bundle defines `window.SamlineString` with every function.
|
|
|
66
102
|
|
|
67
103
|
### Every case
|
|
68
104
|
|
|
69
|
-
`camelCase`, `pascalCase`, `kebabCase`, `snakeCase`, `dotCase` and `
|
|
105
|
+
`camelCase`, `pascalCase`, `kebabCase`, `snakeCase`, `dotCase`, `pathCase`, `constantCase` and `trainCase` (`Content-Type`) for identifiers; `titleCase` (with `smallWords`), `sentenceCase`, `capitalize` and `uncapitalize` for human text. Every function takes a `locale`, so Turkish İ and ı convert correctly.
|
|
70
106
|
|
|
71
107
|
### Slugs and accents
|
|
72
108
|
|
|
73
|
-
`slugify` removes accents, transliterates ß, æ, œ, ø, đ, ł and þ, applies your `replacements
|
|
109
|
+
`slugify` removes accents, transliterates ß, æ, œ, ø, đ, ł and þ, applies your `replacements` (literal or regex pairs), collapses separators and cuts at a separator with `maxLength`. `trim: false` keeps a trailing separator for live slug fields, and `preserve: '.'` keeps characters such as the dot in `v1.2`. `charMap` adds transliteration: the `CYRILLIC`, `GREEK` and `GERMAN` presets (`Москва` → `moskva`, `Müller` → `mueller`) or your own map. `uniqueSlug(text, taken)` returns the first free slug (`hola-3`), keeping the number inside `maxLength`. `removeAccents` gives accent-insensitive text for search.
|
|
74
110
|
|
|
75
111
|
### Display helpers
|
|
76
112
|
|
|
77
|
-
`truncate` counts
|
|
113
|
+
`truncate` counts graphemes, so emoji such as 👨👩👧 or 🇲🇽 and accented letters are never split, and cuts at the last whole word. `position: 'middle'` keeps both ends of file names and IDs, `position: 'start'` keeps the ending. `initials` builds avatar letters.
|
|
114
|
+
|
|
115
|
+
### Text helpers
|
|
116
|
+
|
|
117
|
+
`wordCount` and `readingTime` count words with `Intl.Segmenter`, so punctuation is ignored and Chinese or Japanese text is split correctly. `pluralize(count, { one: '# file', other: '# files' })` picks the right form for any language with `Intl.PluralRules`, formats the count and supports ordinals (`22nd`). `template('Hola {user.name}', values)` fills placeholders. `escapeHtml`, `unescapeHtml` and `stripTags` move text in and out of HTML, and `graphemes` splits text into user-perceived characters.
|
|
118
|
+
|
|
119
|
+
### Conversions by name
|
|
120
|
+
|
|
121
|
+
`convert(text, 'kebab')` runs any conversion from a string, so it can come from configuration, a select menu or an attribute. `CONVERSIONS` lists the names and `isConversion` checks one.
|
|
122
|
+
|
|
123
|
+
### Search and comparison
|
|
124
|
+
|
|
125
|
+
`fold` lowers case, removes accents and maps full-width forms, so `contains` finds `Café` with `cafe` and every query word counts. `highlight` splits the original text into matching and non-matching pieces, without building HTML, and keeps decomposed accents with their letter. `compareNatural` sorts `file2` before `file10` and ignores accents. `distance`, `similarity` and `closest` measure typos and suggest the nearest candidate; `closest` also compares with the start of each word, so `horchatta` finds `Horchata de arroz`.
|
|
126
|
+
|
|
127
|
+
### HTML attributes
|
|
128
|
+
|
|
129
|
+
`data-string="<conversion>"` converts any element's text, and the original markup comes back on `destroy()`. Inputs and textareas convert while the user types, keep a separator they just typed, keep the caret in place, skip IME composition and finalize on blur. `data-string-taken` keeps a slug field off slugs in use and `data-string-transliterate="cyrillic"` reads other scripts. `data-string-source` makes a field or preview follow another one: a slug follows the title until the user edits it and follows again when emptied, and sources chain (title → slug → URL preview). Truncated text keeps the full text in `title`, initials become an image labelled with the full name, and `data-string-state` plus a `string:change` event report every change. `data-string-search="#q"` filters a list as the user types, wraps matches in `<mark>`, shows a `data-string-search-empty` message and reports results in a `string:search` event.
|
|
130
|
+
|
|
131
|
+
`data-string-count="#bio"` shows the characters (graphemes) or words left in a field, with `ok`, `near` and `over` states. `data-string-fit` cuts text in the middle to fit its box and fits again when the box resizes. `data-string-copy="#name"` with `data-string-copy-as="slug"` copies converted text to the clipboard. `data-string-color` sets `--string-color` to a stable color for the text, for avatar backgrounds; `hashColor(text)` gives the same color in code.
|
|
78
132
|
|
|
79
133
|
## API at a glance
|
|
80
134
|
|
|
81
|
-
| API
|
|
82
|
-
|
|
|
83
|
-
| `camelCase`, `pascalCase`, `kebabCase`, `snakeCase`, `dotCase`, `constantCase`
|
|
84
|
-
| `titleCase`, `sentenceCase`, `capitalize`, `uncapitalize`
|
|
85
|
-
| `slugify(text, options?)`, `removeAccents(text)`
|
|
86
|
-
| `truncate(text, length, options?)`, `initials(text, options?)`
|
|
87
|
-
| `
|
|
135
|
+
| API | Purpose |
|
|
136
|
+
| ------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------- |
|
|
137
|
+
| `camelCase`, `pascalCase`, `kebabCase`, `snakeCase`, `dotCase`, `pathCase`, `constantCase`, `trainCase` | Identifier cases. |
|
|
138
|
+
| `titleCase`, `sentenceCase`, `capitalize`, `uncapitalize` | Human-readable casing. |
|
|
139
|
+
| `slugify(text, options?)`, `uniqueSlug(text, taken, options?)`, `removeAccents(text, options?)`, `CYRILLIC`, `GREEK`, `GERMAN` | URL slugs, free slugs and accent-free text. |
|
|
140
|
+
| `truncate(text, length, options?)`, `initials(text, options?)`, `graphemes(text)` | Display helpers. |
|
|
141
|
+
| `convert(text, to, options?)`, `CONVERSIONS`, `isConversion(value)` | Any conversion by name. |
|
|
142
|
+
| `wordCount`, `readingTime`, `pluralize`, `template`, `escapeHtml`, `unescapeHtml`, `stripTags` | Prose, plurals, placeholders and HTML text. |
|
|
143
|
+
| `fold`, `contains`, `highlight`, `compareNatural`, `distance`, `similarity`, `closest` | Search, sorting and typo suggestions. |
|
|
144
|
+
| `words(text)` | The shared word splitter. |
|
|
145
|
+
| `string(target?, options?)`, `autoString(options?)` from `/vanilla` | Convert elements and fields from HTML. |
|
|
146
|
+
| `count`, `fit`, `copy` and their `auto*()` from `/vanilla` | Counters, fitted text and copy buttons. |
|
|
147
|
+
| `hashColor(text, options?)` | A stable color for a name. |
|
|
148
|
+
| `search(target?, options?)`, `autoSearch(options?)` from `/vanilla` | Filter and highlight lists from HTML. |
|
|
88
149
|
|
|
89
150
|
### Entrypoints
|
|
90
151
|
|
|
91
|
-
| Entrypoint | When to use
|
|
92
|
-
| ------------------------- |
|
|
93
|
-
| `@samline/string` | ESM or CommonJS, every function.
|
|
94
|
-
| `@samline/string/vanilla` |
|
|
95
|
-
| `@samline/string/browser` | Classic script that defines `window.SamlineString
|
|
152
|
+
| Entrypoint | When to use |
|
|
153
|
+
| ------------------------- | ------------------------------------------------------------------------------------------------------------- |
|
|
154
|
+
| `@samline/string` | ESM or CommonJS, every pure function. |
|
|
155
|
+
| `@samline/string/vanilla` | Every function plus the HTML layer: `string()`, `search()`, `count()`, `fit()`, `copy()` and their `auto*()`. |
|
|
156
|
+
| `@samline/string/browser` | Classic script that defines `window.SamlineString` and starts the HTML layer. |
|
|
96
157
|
|
|
97
158
|
## Documentation
|
|
98
159
|
|
|
99
|
-
Read the [documentation](https://samline.github.io/
|
|
160
|
+
Read the [documentation](https://samline.github.io/string/docs/) for the full guides and API contracts, and explore [working examples](https://samline.github.io/string/examples/) with complete and separate source files.
|
|
100
161
|
|
|
101
|
-
| Guide
|
|
102
|
-
|
|
|
103
|
-
| [Installation](https://samline.github.io/
|
|
104
|
-
| [API reference](https://samline.github.io/
|
|
105
|
-
| [Options](https://samline.github.io/
|
|
106
|
-
| [Word splitting](https://samline.github.io/
|
|
162
|
+
| Guide | What it covers |
|
|
163
|
+
| ------------------------------------------------------------------------- | --------------------------------------------------- |
|
|
164
|
+
| [Installation](https://samline.github.io/string/docs/getting-started/) | npm, CDN and the first conversions. |
|
|
165
|
+
| [API reference](https://samline.github.io/string/docs/reference/api/) | Every function with examples. |
|
|
166
|
+
| [Options](https://samline.github.io/string/docs/reference/configuration/) | slugify, titleCase, truncate, initials and locales. |
|
|
167
|
+
| [Word splitting](https://samline.github.io/string/docs/guides/words/) | Exactly how words are detected. |
|
|
168
|
+
| [HTML attributes](https://samline.github.io/string/docs/guides/html/) | `data-string`, fields, sources, state and events. |
|
|
169
|
+
| [Search](https://samline.github.io/string/docs/guides/search/) | Folding, highlighting, sorting and list filtering. |
|
|
107
170
|
|
|
108
171
|
## Changelog
|
|
109
172
|
|
|
110
|
-
Read [CHANGELOG.md](CHANGELOG.md) or the [published changelog](https://samline.github.io/
|
|
173
|
+
Read [CHANGELOG.md](CHANGELOG.md) or the [published changelog](https://samline.github.io/string/docs/changelog/) for release history and explicitly marked breaking and behavior changes. Review the notes before upgrading.
|
|
111
174
|
|
|
112
175
|
## AI agent skill
|
|
113
176
|
|
|
114
|
-
The [String skill](https://samline.github.io/
|
|
177
|
+
The [String skill](https://samline.github.io/string/skills/string/SKILL.md) teaches verified package integration. Its maintained [repository source](skills/string/SKILL.md) and website download are the same file. Verify the installed package version before applying its guidance.
|
|
115
178
|
|
|
116
|
-
Download [SKILL.md](https://samline.github.io/
|
|
179
|
+
Download [SKILL.md](https://samline.github.io/string/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
180
|
|
|
118
181
|
```sh
|
|
119
182
|
mkdir -p .agents/skills/string
|
|
120
|
-
curl --fail --location https://samline.github.io/
|
|
183
|
+
curl --fail --location https://samline.github.io/string/skills/string/SKILL.md \
|
|
121
184
|
--output .agents/skills/string/SKILL.md
|
|
122
185
|
```
|
|
123
186
|
|
|
@@ -1,2 +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;})();
|
|
1
|
+
"use strict";(()=>{var ve=Object.defineProperty;var Ae=(t,r)=>{for(var n in r)ve(t,n,{get:r[n],enumerable:!0})};var Ht={};Ae(Ht,{CHAR_MAPS:()=>G,CONVERSIONS:()=>Nt,CYRILLIC:()=>Tt,GERMAN:()=>Mt,GREEK:()=>wt,camelCase:()=>Z,capitalize:()=>ut,closest:()=>le,compareNatural:()=>ae,constantCase:()=>at,contains:()=>dt,convert:()=>k,distance:()=>It,dotCase:()=>ot,escapeHtml:()=>ge,fold:()=>H,graphemes:()=>N,hashColor:()=>Ct,highlight:()=>mt,initials:()=>gt,isConversion:()=>B,kebabCase:()=>rt,pascalCase:()=>tt,pathCase:()=>st,pluralize:()=>fe,readingTime:()=>pe,removeAccents:()=>I,sentenceCase:()=>ct,similarity:()=>ht,slugify:()=>Y,snakeCase:()=>nt,stripTags:()=>de,template:()=>yt,titleCase:()=>lt,trainCase:()=>it,truncate:()=>j,uncapitalize:()=>pt,unescapeHtml:()=>kt,uniqueSlug:()=>ft,wordCount:()=>V,words:()=>L});var L=t=>typeof t!="string"||t===""?[]:t.replace(/([\p{Ll}\p{N}]\p{M}*)(\p{Lu})/gu,"$1 $2").replace(/(\p{Lu})(\p{Lu}\p{Ll})/gu,"$1 $2").split(/[^\p{L}\p{M}\p{N}]+/u).filter(Boolean);var Xt={\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"},Te=new RegExp(`[${Object.keys(Xt).join("")}]`,"g"),we=t=>t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),vt=new WeakMap,Me=t=>{if(vt.has(t))return vt.get(t);let r=Object.keys(t).filter(Boolean).sort((e,o)=>o.length-e.length),n=r.length?new RegExp(r.map(we).join("|"),"gu"):null;return vt.set(t,n),n},Qt=(t,r)=>{let n=Me(r);return n?t.replace(n,e=>r[e]??e):t},I=(t,{charMap:r}={})=>{let n=String(t??"");return r&&(n=Qt(n,r)),n=n.normalize("NFKD").replace(/\p{M}+/gu,"").replace(Te,e=>Xt[e]??e),r?Qt(n,r):n};var At=t=>{let r={...t};for(let[n,e]of Object.entries(t)){let o=n.toUpperCase();o!==n&&!(o in r)&&(r[o]=e.charAt(0).toUpperCase()+e.slice(1))}return r},Tt=At({\u0430:"a",\u0431:"b",\u0432:"v",\u0433:"g",\u0491:"g",\u0434:"d",\u0435:"e",\u0451:"yo",\u0454:"ye",\u0436:"zh",\u0437:"z",\u0438:"i",\u0456:"i",\u0457:"yi",\u0439:"y",\u043A:"k",\u043B:"l",\u043C:"m",\u043D:"n",\u043E:"o",\u043F:"p",\u0440:"r",\u0441:"s",\u0442:"t",\u0443:"u",\u045E:"u",\u0444:"f",\u0445:"kh",\u0446:"ts",\u0447:"ch",\u0448:"sh",\u0449:"shch",\u044A:"",\u044B:"y",\u044C:"",\u044D:"e",\u044E:"yu",\u044F:"ya"}),wt=At({\u03B1:"a",\u03B2:"v",\u03B3:"g",\u03B4:"d",\u03B5:"e",\u03B6:"z",\u03B7:"i",\u03B8:"th",\u03B9:"i",\u03BA:"k",\u03BB:"l",\u03BC:"m",\u03BD:"n",\u03BE:"x",\u03BF:"o",\u03C0:"p",\u03C1:"r",\u03C3:"s",\u03C2:"s",\u03C4:"t",\u03C5:"y",\u03C6:"f",\u03C7:"ch",\u03C8:"ps",\u03C9:"o"}),Mt=At({\u00E4:"ae",\u00F6:"oe",\u00FC:"ue"}),G={cyrillic:Tt,greek:wt,german:Mt};var _=(t,r)=>t.toLocaleLowerCase(r),Zt=(t,r)=>t.toLocaleUpperCase(r),X=(t,r)=>{let[n="",...e]=Array.from(t);return Zt(n,r)+e.join("")},Rt=(t,r)=>X(_(t,r),r),Z=(t,{locale:r}={})=>L(t).map((n,e)=>e===0?_(n,r):Rt(n,r)).join(""),tt=(t,{locale:r}={})=>L(t).map(n=>Rt(n,r)).join(""),et=t=>(r,{locale:n}={})=>L(r).map(e=>_(e,n)).join(t),rt=et("-"),nt=et("_"),ot=et("."),st=et("/"),it=(t,{locale:r}={})=>L(t).map(n=>Rt(n,r)).join("-"),at=(t,{locale:r}={})=>L(t).map(n=>Zt(n,r)).join("_"),lt=(t,{locale:r,smallWords:n=[]}={})=>{let e=new Set(n.map(s=>_(s,r))),o=0;return String(t??"").replace(/[\p{L}\p{M}\p{N}]+/gu,s=>{let l=o++===0,c=_(s,r);return!l&&e.has(c)?c:X(c,r)})},ct=(t,{locale:r}={})=>X(_(String(t??""),r),r),ut=(t,{locale:r}={})=>X(String(t??""),r),pt=(t,{locale:r}={})=>{let[n="",...e]=Array.from(String(t??""));return _(n,r)+e.join("")};var Re=t=>t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),Y=(t,{separator:r="-",lower:n=!0,replacements:e={},maxLength:o,trim:s=!0,locale:l,charMap:c,preserve:f=""}={})=>{let a=String(t??""),p=Array.isArray(e)?e:Object.entries(e);for(let[d,h]of p)a=typeof d=="string"?a.split(d).join(` ${h} `):a.replace(d,` ${h} `);n&&(a=a.toLocaleLowerCase(l)),a=I(a,c?{charMap:c}:{});let i=Re(r),u=f.replace(/[\]\\^-]/g,"\\$&");if(a=a.replace(new RegExp(`[^A-Za-z0-9${u}]+`,"g"),r),r&&(a=a.replace(new RegExp(`(?:${i}){2,}`,"g"),r)),s&&r?a=a.replace(new RegExp(`^(?:${i})+|(?:${i})+$`,"g"),""):r&&(a=a.replace(new RegExp(`^(?:${i})+`),"")),o!==void 0&&Number.isFinite(o)&&o>=0&&a.length>o){let d=a.slice(0,o),h=r?d.lastIndexOf(r):-1;a=h>0&&a[o]!==r?d.slice(0,h):d,r&&(a=a.replace(new RegExp(`(?:${i})+$`),""))}return a},te=1e5,ft=(t,r,{start:n=2,...e}={})=>{let o=Y(t,e),s;if(typeof r=="function")s=r;else{let a=new Set(r);s=p=>a.has(p)}if(o&&!s(o))return o;let l=e.separator??"-",{maxLength:c}=e,f=Number.isFinite(n)?Math.floor(n):2;for(let a=f;a<f+te;a++){let p=o?`${l}${a}`:String(a),i=o;if(c!==void 0&&c>=0&&i.length+p.length>c&&(i=i.slice(0,Math.max(0,c-p.length)),l))for(;i.endsWith(l);)i=i.slice(0,-l.length);let u=i?i+p:String(a);if(!s(u))return u}throw new RangeError(`uniqueSlug: no free slug for "${o}" after ${te} tries`)};var ee=globalThis.Intl?.Segmenter,re=new Map,Lt=(t,r)=>{if(!ee)return;let n=`${t}|${r===void 0?"":[r].flat().join(",")}`,e=re.get(n);return e||(e=new ee(r,{granularity:t}),re.set(n,e)),e},N=t=>{let r=String(t??""),n=Lt("grapheme");return n?Array.from(n.segment(r),e=>e.segment):Array.from(r)};var ne=/[\p{L}\p{N}]/u,oe="[\\s.,;:!?-]+",Le=new RegExp(`${oe}$`,"u"),Ne=new RegExp(`^${oe}`,"u"),j=(t,r,{ellipsis:n="\u2026",wordBoundary:e=!0,position:o="end"}={})=>{let s=N(t);if(!Number.isFinite(r)||r<0||s.length<=r)return s.join("");let l=Math.max(0,r-N(n).length);if(o==="middle"){let f=s.slice(0,Math.ceil(l/2)).join(""),a=l>1?s.slice(s.length-Math.floor(l/2)).join(""):"";return f.replace(/\s+$/u,"")+n+a.replace(/^\s+/u,"")}if(o==="start"){let f=s.length-l,a=s.slice(f).join("");if(e&&l>0&&ne.test(s[f-1])){let p=a.search(/\s/u);p>=0&&p<a.length-1&&(a=a.slice(p))}return n+a.replace(Ne,"")}let c=s.slice(0,l).join("");if(e&&s[l]!==void 0&&ne.test(s[l])){let f=c.search(/\s\S*$/u);f>0&&(c=c.slice(0,f))}return c.replace(Le,"")+n},gt=(t,{max:r=2,locale:n}={})=>L(String(t??"")).slice(0,Math.max(0,r)).map(e=>N(e)[0].toLocaleUpperCase(n)).join("");var Nt=["camel","pascal","kebab","snake","dot","path","constant","train","title","sentence","capitalize","uncapitalize","lower","upper","slug","accents","truncate","initials"],B=t=>Nt.includes(t),k=(t,r,n={})=>{let e=String(t??""),{locale:o}=n,s=o===void 0?{}:{locale:o};switch(r){case"camel":return Z(e,s);case"pascal":return tt(e,s);case"kebab":return rt(e,s);case"snake":return nt(e,s);case"dot":return ot(e,s);case"path":return st(e,s);case"constant":return at(e,s);case"train":return it(e,s);case"title":return lt(e,n);case"sentence":return ct(e,s);case"capitalize":return ut(e,s);case"uncapitalize":return pt(e,s);case"lower":return e.toLocaleLowerCase(o);case"upper":return e.toLocaleUpperCase(o);case"slug":return n.taken===void 0?Y(e,n):ft(e,n.taken,n);case"accents":return I(e,n.charMap?{charMap:n.charMap}:{});case"truncate":return n.length===void 0?e:j(e,n.length,n);case"initials":return gt(e,n);default:return e}};var H=(t,{locale:r}={})=>I(String(t??"").toLocaleLowerCase(r)),ie=(t,{locale:r,split:n=!0})=>{let e=H(t,r===void 0?{}:{locale:r}).trim();return e?n?Array.from(new Set(e.split(/\s+/u))):[e]:[]},dt=(t,r,n={})=>{let e=ie(r,n);if(e.length===0)return!0;let o=H(t,n.locale===void 0?{}:{locale:n.locale});return e.every(s=>o.includes(s))},Ie=/^[\u0000-\u007f]*$/,mt=(t,r,n={})=>{let e=Array.from(String(t??""));if(e.length===0)return[];let o=ie(r,n);if(o.length===0)return[{text:e.join(""),match:!1}];let s=n.locale,l="",c=[],f=new Set;e.forEach((i,u)=>{let d=i.toLocaleLowerCase(s),h=Ie.test(d)?d:I(d);l+=h,h===""&&f.add(u);for(let C=0;C<h.length;C++)c.push(u)});let a=new Array(e.length).fill(!1);for(let i of o)for(let u=l.indexOf(i);u!==-1;u=l.indexOf(i,u+i.length))for(let d=c[u];d<=c[u+i.length-1];d++)a[d]=!0;f.forEach(i=>{i>0&&(a[i]=a[i-1])});let p=[];return e.forEach((i,u)=>{let d=a[u],h=p[p.length-1];h&&h.match===d?h.text+=i:p.push({text:i,match:d})}),p},se=new Map,ae=(t,r,{locale:n,sensitivity:e="base"}={})=>{let o=`${n===void 0?"":[n].flat().join(",")}|${e}`,s=se.get(o);return s||(s=new Intl.Collator(n,{numeric:!0,sensitivity:e}),se.set(o,s)),s.compare(String(t??""),String(r??""))},It=(t,r)=>{let n=Array.from(String(t??"")),e=Array.from(String(r??""));if(n.length===0)return e.length;if(e.length===0)return n.length;let o=Array.from({length:e.length+1},(s,l)=>l);for(let s=1;s<=n.length;s++){let l=[s];for(let c=1;c<=e.length;c++){let f=n[s-1]===e[c-1]?0:1;l[c]=Math.min(o[c]+1,l[c-1]+1,o[c-1]+f)}o=l}return o[e.length]},ht=(t,r,{fold:n=!0,locale:e}={})=>{let o=e===void 0?{}:{locale:e},s=n?H(t,o):String(t??""),l=n?H(r,o):String(r??""),c=Math.max(Array.from(s).length,Array.from(l).length);return c===0?1:1-It(s,l)/c},ke=.98,He=(t,r)=>{let n=Array.from(t),e=Array.from(r);if(n.length<3||e.length<=n.length)return 0;let o=n.join(""),s=0;return e.forEach((l,c)=>{if(c>0&&!/[\s\p{P}]/u.test(e[c-1])||/\s/u.test(l))return;let f=e.slice(c,c+n.length).join("");s=Math.max(s,ht(o,f,{fold:!1}))}),s*ke},le=(t,r,{threshold:n=.5,partial:e=!0,...o}={})=>{let s=o.fold??!0,l=o.locale===void 0?{}:{locale:o.locale},c=i=>s?H(i,l):String(i??""),f=c(t),a,p=-1;for(let i of r){let u=ht(t,i,o),d=e?Math.max(u,He(f,c(i))):u;d>p&&(a=i,p=d)}return p>=n?a:void 0};var V=(t,{locale:r}={})=>{let n=String(t??""),e=Lt("word",r);if(!e)return n.split(/[^\p{L}\p{M}\p{N}'’]+/u).filter(Boolean).length;let o=0;for(let s of e.segment(n))s.isWordLike&&o++;return o},pe=(t,{wordsPerMinute:r=200,...n}={})=>{let e=V(t,n),o=Number.isFinite(r)&&r>0?r:200;return{words:e,minutes:e===0?0:Math.max(1,Math.ceil(e/o))}},ce=new Map,ue=new Map,$e=t=>t===void 0?"":[t].flat().join(","),fe=(t,r,{locale:n,ordinal:e=!1}={})=>{let o=$e(n),s=`${o}|${e}`,l=ce.get(s);l||(l=new Intl.PluralRules(n,{type:e?"ordinal":"cardinal"}),ce.set(s,l));let c=ue.get(o);c||(c=new Intl.NumberFormat(n),ue.set(o,c));let f=l.select(t);return(t===0&&r.zero||r[f]||r.other).replace(/#/g,c.format(t))},yt=(t,r,{missing:n}={})=>String(t??"").replace(/\{\{|\}\}|\{\s*([^{}\s]+)\s*\}/g,(e,o)=>{if(o===void 0)return e[0];let s=r;for(let l of o.split("."))s=s!==null&&typeof s=="object"&&Object.prototype.hasOwnProperty.call(s,l)?s[l]:void 0;return s!=null?String(s):n===void 0?e:typeof n=="function"?n(o):n});var Fe={"&":"&","<":"<",">":">",'"':""","'":"'"},ge=t=>String(t??"").replace(/[&<>"']/g,r=>Fe[r]),Pe={amp:"&",lt:"<",gt:">",quot:'"',apos:"'",nbsp:"\xA0",copy:"\xA9",reg:"\xAE",hellip:"\u2026",mdash:"\u2014",ndash:"\u2013",laquo:"\xAB",raquo:"\xBB"},_e=(t,r)=>Number.isInteger(t)&&t>0&&t<=1114111&&(t<55296||t>57343)?String.fromCodePoint(t):r,kt=t=>String(t??"").replace(/&(#x[\da-f]+|#\d+|[a-z]+);/gi,(r,n)=>{if(n[0]!=="#")return Pe[n.toLowerCase()]??r;let e=n[1]==="x"||n[1]==="X";return _e(parseInt(n.slice(e?2:1),e?16:10),r)}),je=/<\/?(?:p|div|br|li|ul|ol|h[1-6]|tr|td|th|table|section|article|header|footer|blockquote|pre|hr)\b[^>]*>/gi,de=t=>kt(String(t??"").replace(/<!--[\s\S]*?-->/g,"").replace(/<(script|style|template|noscript)\b[\s\S]*?<\/\1\s*>/gi,"").replace(je," ").replace(/<[^>]*>/g,"")).replace(/\s+/g," ").trim();var Be=t=>{let r=2166136261;for(let n=0;n<t.length;n++)r^=t.charCodeAt(n),r=Math.imul(r,16777619);return r>>>0},ze=(t,r,n)=>{let e=r/100,o=n/100,s=c=>{let f=(c+t/30)%12,a=o-e*Math.min(o,1-o)*Math.max(-1,Math.min(f-3,9-f,1));return a<=.04045?a/12.92:((a+.055)/1.055)**2.4};return 1.05/(.2126*s(0)+.7152*s(8)+.0722*s(4)+.05)},Ct=(t,{saturation:r=55,lightness:n=45,contrast:e=4.5}={})=>{let o=Be(H(String(t??"").trim()))%360,s=Math.max(0,Math.min(100,n));for(;s>0&&ze(o,r,s)<e;)s--;return`hsl(${o} ${r}% ${s}%)`};var F=()=>typeof window<"u"&&typeof document<"u",b=()=>{},me=t=>typeof Element<"u"&&t instanceof Element,A=(t,r=F()?document:null)=>{if(t==null)return[];if(me(t))return[t];if(typeof t=="string")return r?Array.from(r.querySelectorAll(t)):[];let n=(typeof t[Symbol.iterator]=="function",Array.from(t));return Array.from(new Set(n.filter(me)))},xt=(t,r)=>t.hasAttribute(r)?t.getAttribute(r):null,S=(t,r,n)=>{let e=xt(t,r);return e===null||e.trim()===""?n:e.trim()},P=(t,r,n)=>{let e=xt(t,r);if(e===null)return n;let o=e.trim().toLowerCase();return o===""||o==="true"||o===r.toLowerCase()?!0:o==="false"?!1:n},M=(t,r,n)=>{let e=xt(t,r);if(e===null||e.trim()==="")return n;let o=Number(e);return Number.isFinite(o)?o:n};var z=(t,r,n,e)=>{let o=xt(t,r)?.trim();return o!==void 0&&n.includes(o)?o:e};var U=({selector:t,init:r,root:n,observe:e=!0})=>{if(!F())return{refresh:b,destroy:b};let o=n??document,s=new Map,l=i=>{s.has(i)||s.set(i,r(i)??b)},c=i=>{let u=s.get(i);u&&(s.delete(i),u())},f=(i,u)=>{i instanceof Element&&(i.matches(t)&&u(i),i.querySelectorAll(t).forEach(u))},a=()=>o.querySelectorAll(t).forEach(l),p=null;if(e&&typeof MutationObserver=="function"){p=new MutationObserver(u=>{for(let d of u)d.removedNodes.forEach(h=>f(h,C=>{C.isConnected||c(C)})),d.addedNodes.forEach(h=>f(h,l))});let i=o instanceof Document?o.documentElement:o;p.observe(i,{childList:!0,subtree:!0})}return a(),{refresh:a,destroy:()=>{p?.disconnect(),p=null,Array.from(s.keys()).forEach(c)}}};var q=(t,r)=>(n=t,e={})=>{if(!F())return{refresh:b,destroy:b};let o=A(n).filter(s=>s instanceof HTMLElement).map(s=>r(s,e)).filter(s=>s!==null);return{refresh:()=>o.forEach(s=>s.refresh()),destroy:()=>o.forEach(s=>s.destroy())}},W=(t,r)=>({selector:n=t,scope:e,observe:o=!0,...s}={})=>U({selector:n,observe:o,...e&&{root:e},init:l=>r(l,s).destroy}),Ot=t=>{let r=Array.from(t.childNodes);return()=>t.replaceChildren(...r)},he=t=>{let r=new Map;return{set:(n,e)=>{r.has(n)||r.set(n,t.getAttribute(n)),r.get(n)===null&&(e===null?t.removeAttribute(n):t.setAttribute(n,e))},restore:()=>r.forEach((n,e)=>n===null&&t.removeAttribute(e))}},ye=(t,r,n)=>t.getAttribute(r)?.trim()||n||t.closest("[lang]")?.getAttribute("lang")||void 0,Ce=t=>t instanceof HTMLInputElement||t instanceof HTMLTextAreaElement?t.value:t.textContent??"";var K="data-string-copy",$t="data-string-copy-state",Ue="string:copy",qe=(t,r)=>{let{source:n,as:e,reset:o,onCopy:s,...l}=r,c,f=i=>{clearTimeout(c),t.setAttribute($t,i.ok?"copied":"error");let u=M(t,`${K}-reset`,o??2e3);c=setTimeout(()=>t.removeAttribute($t),u),s?.(i,t),t.dispatchEvent(new CustomEvent(Ue,{bubbles:!0,detail:i}))},a=async()=>{let i=A(S(t,K,"")||n)[0],u=i?Ce(i):"",d=S(t,`${K}-as`,""),h=B(d)?d:e,C=h?k(u,h,l):u;try{if(!i||!navigator.clipboard)throw new Error("No source or clipboard");await navigator.clipboard.writeText(C),f({value:C,ok:!0})}catch{f({value:C,ok:!1})}};t.addEventListener("click",a);let p=!0;return{refresh:()=>{},destroy:()=>{p&&(p=!1,clearTimeout(c),t.removeEventListener("click",a),t.removeAttribute($t))}}},Ft=q(`[${K}]`,qe),Pt=W(`[${K}]`,Ft);var Et="data-string-count",xe="data-string-count-state",We="string:count",De=["characters","words"],Ge=(t,r)=>{let n=c=>`${Et}-${c}`,e=A(S(t,Et,"")||r.field)[0];if(!(e instanceof HTMLInputElement||e instanceof HTMLTextAreaElement))return null;let o=Ot(t),s=()=>{let c=z(t,n("unit"),De,r.unit??"characters"),f=ye(t,n("locale"),r.locale),a=c==="words"?V(e.value,f?{locale:f}:{}):N(e.value).length,p=r.max??(e.maxLength>0?e.maxLength:NaN),i=M(t,n("max"),p),u=Number.isFinite(i)&&i>=0?i:void 0,d=u===void 0?void 0:u-a,h=M(t,n("near"),r.near??Math.ceil((u??0)*.1)),C=d===void 0?"ok":d<0?"over":d<=h?"near":"ok",y={count:a,max:u,remaining:d,state:C},m=t.hasAttribute(n("format"))?t.getAttribute(n("format"))??"":r.format??(u===void 0?"{count}":"{remaining}");t.textContent=typeof m=="function"?m(y):yt(m,{count:a,max:u,remaining:d},{missing:""}),t.setAttribute(xe,C),r.onCount?.(y,t),t.dispatchEvent(new CustomEvent(We,{bubbles:!0,detail:y}))};e.addEventListener("input",s),s();let l=!0;return{refresh:()=>l&&s(),destroy:()=>{l&&(l=!1,e.removeEventListener("input",s),o(),t.removeAttribute(xe))}}},_t=q(`[${Et}]`,Ge),jt=W(`[${Et}]`,_t);var J="data-string-fit",Bt="data-string-fit-state",Ye=["end","middle","start"],Ve=(t,r)=>{let n=Ot(t),e=he(t),o=t.textContent??"",s=t.getAttribute("style"),l=!0;t.style.whiteSpace="nowrap",t.style.overflow="hidden";let c=()=>t.scrollWidth<=t.clientWidth,f=()=>{let u=z(t,J,Ye,r.position??"middle"),d=t.hasAttribute(`${J}-ellipsis`)?t.getAttribute(`${J}-ellipsis`)??"":r.ellipsis??"\u2026";if(t.textContent!==o&&(t.textContent=o),t.clientWidth===0||c()){t.setAttribute(Bt,"full"),e.set("title",null);return}let h=0,C=N(o).length-1,y=j(o,0,{position:u,ellipsis:d,wordBoundary:!1});for(;h<=C;){let m=Math.floor((h+C)/2),x=j(o,m,{position:u,ellipsis:d,wordBoundary:!1});t.textContent=x,c()?(y=x,h=m+1):C=m-1}t.textContent=y,t.setAttribute(Bt,"truncated"),e.set("title",o)},a=0,p=()=>{cancelAnimationFrame(a),a=requestAnimationFrame(f)},i=null;return typeof ResizeObserver=="function"?(i=new ResizeObserver(p),i.observe(t)):window.addEventListener("resize",p),t.ownerDocument.fonts?.ready.then(()=>l&&f()),f(),{refresh:()=>l&&f(),destroy:()=>{l&&(l=!1,cancelAnimationFrame(a),i?.disconnect(),window.removeEventListener("resize",p),n(),e.restore(),s===null?t.removeAttribute("style"):t.setAttribute("style",s),t.removeAttribute(Bt))}}},zt=q(`[${J}]`,Ve),Ut=W(`[${J}]`,zt);var bt="data-string-search",Oe="data-string-search-state",Ke="data-string-search-empty",Je="string:search",Qe=t=>{let r=t.ownerDocument.createTreeWalker(t,NodeFilter.SHOW_TEXT),n=[];for(let e=r.nextNode();e;e=r.nextNode())n.push(e);return n},Xe=(t,r)=>{let n=m=>`${bt}-${m}`,e=S(t,bt,""),o=A(e||r.input)[0];if(!(o instanceof HTMLInputElement||o instanceof HTMLTextAreaElement))return null;let s=t.ownerDocument,l=new Map,c=[],f=[],a=null,p=()=>{let m=S(t,n("locale"),"")||r.locale||t.closest("[lang]")?.getAttribute("lang")||"";return{match:{split:P(t,n("split"),r.split??!0),...m&&{locale:m}},mark:P(t,n("highlight"),r.highlight??!0),min:Math.max(1,M(t,n("min"),r.min??1)),items:S(t,n("items"),r.items??"")}},i=m=>{l.has(m)||l.set(m,m.hidden)},u=()=>{let{items:m}=p(),x=Array.from(m?t.querySelectorAll(m):t.children),v=A(r.empty)[0];a=t.querySelector(`[${Ke}]`)??(v instanceof HTMLElement?v:null),f=x.filter(E=>E instanceof HTMLElement&&E!==a&&!E.contains(a)),f.forEach(i),a&&i(a),f=f.filter(E=>!l.get(E))},d=()=>{for(let{original:m,nodes:x}of c){let v=x[0];v?.parentNode&&v.parentNode.insertBefore(m,v),x.forEach(E=>E.parentNode?.removeChild(E))}c=[]},h=(m,x,v)=>{for(let E of Qe(m)){let w=mt(E.data,x,v);if(!w.some(g=>g.match))continue;let $=w.map(g=>{if(!g.match)return s.createTextNode(g.text);let O=s.createElement("mark");return O.textContent=g.text,O}),R=E.parentNode;$.forEach(g=>R.insertBefore(g,E)),R.removeChild(E),c.push({original:E,nodes:$})}},C=()=>{let{match:m,mark:x,min:v}=p(),E=o.value;d();let w=Array.from(E.trim()).length>=v,$=f.filter(O=>{let T=!w||dt(O.textContent??"",E,m);return O.hidden=T?l.get(O):!0,T&&w&&x&&h(O,E,m),T&&w}),R=w?$.length>0?"results":"empty":"idle";t.setAttribute(Oe,R),a&&(a.hidden=R!=="empty");let g={query:E,matches:w?$:[...f],total:f.length,state:R};r.onSearch?.(g,t),t.dispatchEvent(new CustomEvent(Je,{bubbles:!0,detail:g}))};o.addEventListener("input",C),u(),C();let y=!0;return{refresh:()=>{y&&(d(),u(),C())},destroy:()=>{y&&(y=!1,o.removeEventListener("input",C),d(),l.forEach((m,x)=>x.hidden=m),t.removeAttribute(Oe))}}},qt=(t=`[${bt}]`,r={})=>{if(!F())return{refresh:b,destroy:b};let n=A(t).filter(e=>e instanceof HTMLElement).map(e=>Xe(e,r)).filter(e=>e!==null);return{refresh:()=>n.forEach(e=>e.refresh()),destroy:()=>n.forEach(e=>e.destroy())}},Wt=({selector:t=`[${bt}]`,scope:r,observe:n=!0,...e}={})=>U({selector:t,observe:n,...r&&{root:r},init:o=>qt(o,e).destroy});var St="data-string",Ee="data-string-state",Dt="string:change",Gt="--string-color",Ze=["end","middle","start"],tr={kebab:"-",snake:"_",dot:".",path:"/",constant:"_",train:"-",camel:" ",pascal:" "},Se=t=>t instanceof HTMLInputElement||t instanceof HTMLTextAreaElement,Yt=t=>Se(t)?t.value:t.textContent??"",er=t=>{try{let r=JSON.parse(t);if(r&&typeof r=="object"&&!Array.isArray(r))return Object.fromEntries(Object.entries(r).filter(n=>typeof n[1]=="string"))}catch{}},be=(t,r)=>{let n=t.getAttribute(St)?.trim(),e=B(n)?n:r.to;if(!e)return null;let{to:o,source:s,live:l,onChange:c,color:f,...a}=r,p={...a},i=y=>`${St}-${y}`,u=y=>t.hasAttribute(i(y)),d=S(t,i("locale"),"")||a.locale||t.closest("[lang]")?.getAttribute("lang")||"";if(d?p.locale=d:delete p.locale,u("separator")&&(p.separator=t.getAttribute(i("separator"))??""),u("lower")&&(p.lower=P(t,i("lower"),a.lower??!0)),u("max-length")){let y=M(t,i("max-length"),NaN);Number.isFinite(y)&&(p.maxLength=y)}if(u("replacements")){let y=er(t.getAttribute(i("replacements"))??"");y&&(p.replacements=y)}if(u("preserve")&&(p.preserve=t.getAttribute(i("preserve"))??""),u("transliterate")){let m=S(t,i("transliterate"),"").split(/[\s,]+/).filter(x=>x in G).map(x=>G[x]);m.length&&(p.charMap=Object.assign({},a.charMap,...m))}if(u("taken")){let y=t.getAttribute(i("taken"))??"",m;try{m=JSON.parse(y)}catch{m=y.split(/[\s,]+/)}Array.isArray(m)&&(p.taken=m.filter(x=>typeof x=="string"&&x!==""))}if(u("small-words")&&(p.smallWords=S(t,i("small-words"),"").split(/[\s,]+/).filter(Boolean)),u("length")){let y=M(t,i("length"),NaN);Number.isFinite(y)&&(p.length=y)}if(u("ellipsis")&&(p.ellipsis=t.getAttribute(i("ellipsis"))??""),u("position")&&(p.position=z(t,i("position"),Ze,a.position??"end")),u("word-boundary")&&(p.wordBoundary=P(t,i("word-boundary"),!0)),u("max")){let y=M(t,i("max"),NaN);Number.isFinite(y)&&(p.max=y)}let h=S(t,i("source"),""),C=A(h||s)[0]??null;return{to:e,options:p,source:C===t?null:C,live:P(t,i("live"),l??!0),color:P(t,i("color"),!!f)?typeof f=="object"?f:{}:null}},rr=(t,{to:r,options:n})=>{if(r==="slug"){let{taken:s,...l}=n;return k(t,r,{...l,trim:!1})}let e=tr[r],o=k(t,r,n);return e!==void 0&&o&&/[^\p{L}\p{N}]$/u.test(t)?o+e:o},nr=(t,r)=>{let n=be(t,r);if(!n)return null;let e=Se(t)?t:null,o=Array.from(t.childNodes),s=Yt(t),l=b,c="ready",f=!1,a=g=>{c=g,t.setAttribute(Ee,g)},p=g=>{r.onChange?.(g,t),t.dispatchEvent(new CustomEvent(Dt,{bubbles:!0,detail:{value:g,state:c}}))},i=new Map,u=(g,O)=>{i.has(g)||i.set(g,t.getAttribute(g)),i.get(g)===null&&(O===null?t.removeAttribute(g):t.setAttribute(g,O))},d=g=>{if(!e||e.value===g)return;let O=e.ownerDocument.activeElement===e,T=0;try{T=e.value.length-(e.selectionEnd??e.value.length)}catch{}if(e.value=g,O){let D=Math.max(0,g.length-T);try{e.setSelectionRange(D,D)}catch{}}p(g)},h=g=>{let O=n,T=k(g,O.to,O.options);if(e)return d(T);t.textContent!==T&&(t.textContent=T,p(T)),u("title",O.to==="truncate"&&T!==g?g:null);let D=O.to==="initials"?g.trim():"";u("role",D?"img":null),u("aria-label",D||null),O.color?t.style.setProperty(Gt,Ct(g,O.color)):t.style.removeProperty(Gt)},C=()=>n.source&&h(Yt(n.source)),y=()=>{(!e||c==="following")&&C()},m=()=>{if(!(!e||f)){if(n.source){if(e.value==="")return a("following");c!=="edited"&&a("edited")}n.live&&n.to!=="truncate"&&n.to!=="initials"&&d(rr(e.value,n))}},x=()=>{if(e){if(n.source&&c==="following")return C();h(e.value)}},v=()=>f=!0,E=()=>{f=!1,m()},w=()=>{l();let g=n.source;if(!g)return l=b;g.addEventListener("input",y),g.addEventListener(Dt,y),l=()=>{g.removeEventListener("input",y),g.removeEventListener(Dt,y)}},$=()=>{let g=n;if(w(),e&&g.source){let O=k(Yt(g.source),g.to,g.options);a(e.value===""||e.value===O?"following":"edited"),c==="following"?C():h(e.value)}else a("ready"),g.source?C():h(e?e.value:s)};e&&(e.addEventListener("input",m),e.addEventListener("blur",x),e.addEventListener("compositionstart",v),e.addEventListener("compositionend",E)),$();let R=!0;return{refresh:()=>{if(!R)return;let g=be(t,r);if(g){if(n=g,e&&n.source&&c!=="ready")return w(),c==="following"?C():h(e.value);$()}},destroy:()=>{R&&(R=!1,l(),e?(e.removeEventListener("input",m),e.removeEventListener("blur",x),e.removeEventListener("compositionstart",v),e.removeEventListener("compositionend",E)):t.replaceChildren(...o),i.forEach((g,O)=>g===null&&t.removeAttribute(O)),t.style.removeProperty(Gt),t.getAttribute("style")===""&&t.removeAttribute("style"),t.removeAttribute(Ee))}}},Vt=(t=`[${St}]`,r={})=>{if(!F())return{refresh:b,destroy:b};let n=A(t).filter(e=>e instanceof HTMLElement).map(e=>nr(e,r)).filter(e=>e!==null);return{refresh:()=>n.forEach(e=>e.refresh()),destroy:()=>n.forEach(e=>e.destroy())}},Kt=({selector:t=`[${St}]`,scope:r,observe:n=!0,...e}={})=>U({selector:t,observe:n,...r&&{root:r},init:o=>Vt(o,e).destroy});var or=typeof document<"u"?document.currentScript:null,sr=or?.hasAttribute("data-manual")??!1,Q=null,Jt={...Ht,string:Vt,autoString:Kt,search:qt,autoSearch:Wt,count:_t,autoCount:jt,fit:zt,autoFit:Ut,copy:Ft,autoCopy:Pt,auto:(t={})=>{Q?.destroy();let{search:r,count:n,fit:e,copy:o,...s}=t,l={...s.scope&&{scope:s.scope},...s.locale!==void 0&&{locale:s.locale}},{locale:c,...f}=l,a=[Kt(s),Wt({...l,...r}),jt({...l,...n}),Ut({...f,...e}),Pt({...l,...o})];return Q={refresh:()=>a.forEach(p=>p.refresh()),destroy:()=>a.forEach(p=>p.destroy())},Q},get controller(){return Q}},ir=globalThis;ir.SamlineString=Jt;!sr&&typeof document<"u"&&(document.readyState==="loading"?document.addEventListener("DOMContentLoaded",()=>Q??Jt.auto(),{once:!0}):Jt.auto());})();
|
|
2
2
|
//# sourceMappingURL=string.global.js.map
|