@visulima/string 1.0.5 → 1.2.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 +12 -0
- package/README.md +201 -2
- package/dist/case/camel-case.d.cts +3 -3
- package/dist/case/camel-case.d.mts +3 -3
- package/dist/case/camel-case.d.ts +3 -3
- package/dist/case/capital-case.d.cts +3 -3
- package/dist/case/capital-case.d.mts +3 -3
- package/dist/case/capital-case.d.ts +3 -3
- package/dist/case/constant-case.d.cts +3 -3
- package/dist/case/constant-case.d.mts +3 -3
- package/dist/case/constant-case.d.ts +3 -3
- package/dist/case/dot-case.d.cts +3 -3
- package/dist/case/dot-case.d.mts +3 -3
- package/dist/case/dot-case.d.ts +3 -3
- package/dist/case/flat-case.d.cts +3 -3
- package/dist/case/flat-case.d.mts +3 -3
- package/dist/case/flat-case.d.ts +3 -3
- package/dist/case/flip-case.d.cts +3 -3
- package/dist/case/flip-case.d.mts +3 -3
- package/dist/case/flip-case.d.ts +3 -3
- package/dist/case/identify-case.cjs +47 -8
- package/dist/case/identify-case.d.cts +3 -3
- package/dist/case/identify-case.d.mts +3 -3
- package/dist/case/identify-case.d.ts +3 -3
- package/dist/case/identify-case.mjs +47 -8
- package/dist/case/index.d.cts +3 -3
- package/dist/case/index.d.mts +3 -3
- package/dist/case/index.d.ts +3 -3
- package/dist/case/kebab-case.d.cts +3 -3
- package/dist/case/kebab-case.d.mts +3 -3
- package/dist/case/kebab-case.d.ts +3 -3
- package/dist/case/lower-first.d.cts +3 -3
- package/dist/case/lower-first.d.mts +3 -3
- package/dist/case/lower-first.d.ts +3 -3
- package/dist/case/no-case.d.cts +3 -3
- package/dist/case/no-case.d.mts +3 -3
- package/dist/case/no-case.d.ts +3 -3
- package/dist/case/pascal-case.d.cts +3 -3
- package/dist/case/pascal-case.d.mts +3 -3
- package/dist/case/pascal-case.d.ts +3 -3
- package/dist/case/pascal-snake-case.d.cts +3 -3
- package/dist/case/pascal-snake-case.d.mts +3 -3
- package/dist/case/pascal-snake-case.d.ts +3 -3
- package/dist/case/path-case.d.cts +3 -3
- package/dist/case/path-case.d.mts +3 -3
- package/dist/case/path-case.d.ts +3 -3
- package/dist/case/sentence-case.d.cts +3 -3
- package/dist/case/sentence-case.d.mts +3 -3
- package/dist/case/sentence-case.d.ts +3 -3
- package/dist/case/snake-case.d.cts +3 -3
- package/dist/case/snake-case.d.mts +3 -3
- package/dist/case/snake-case.d.ts +3 -3
- package/dist/case/split-by-case.d.cts +3 -3
- package/dist/case/split-by-case.d.mts +3 -3
- package/dist/case/split-by-case.d.ts +3 -3
- package/dist/case/title-case.d.cts +3 -3
- package/dist/case/title-case.d.mts +3 -3
- package/dist/case/title-case.d.ts +3 -3
- package/dist/case/train-case.d.cts +3 -3
- package/dist/case/train-case.d.mts +3 -3
- package/dist/case/train-case.d.ts +3 -3
- package/dist/case/upper-first.d.cts +3 -3
- package/dist/case/upper-first.d.mts +3 -3
- package/dist/case/upper-first.d.ts +3 -3
- package/dist/index.cjs +6 -0
- package/dist/index.d.cts +11 -4
- package/dist/index.d.mts +11 -4
- package/dist/index.d.ts +11 -4
- package/dist/index.mjs +3 -0
- package/dist/native-string-types.d.cts +1 -1
- package/dist/native-string-types.d.mts +1 -1
- package/dist/native-string-types.d.ts +1 -1
- package/dist/packem_shared/lru-cache-B_t27XwI.d.cts +14 -0
- package/dist/packem_shared/lru-cache-B_t27XwI.d.mts +14 -0
- package/dist/packem_shared/lru-cache-B_t27XwI.d.ts +14 -0
- package/dist/packem_shared/replaceString-C7Dp5vAg.mjs +200 -0
- package/dist/packem_shared/replaceString-iYo1cDfZ.cjs +202 -0
- package/dist/packem_shared/slugify-B9zJ8G7m.cjs +50 -0
- package/dist/packem_shared/slugify-C7by01BU.mjs +48 -0
- package/dist/packem_shared/transliterate-BUI0uSNe.cjs +46092 -0
- package/dist/packem_shared/transliterate-DPctxBml.mjs +46090 -0
- package/dist/packem_shared/{types-BttWSSIk.d.ts → types-C5Pk8B8Q.d.cts} +3 -3
- package/dist/packem_shared/{types-BAd3WDHo.d.mts → types-DcGtApe2.d.ts} +3 -3
- package/dist/packem_shared/{types-BNbQJg02.d.cts → types-DmfKbIaI.d.cts} +23 -1
- package/dist/packem_shared/{types-BNbQJg02.d.mts → types-DmfKbIaI.d.mts} +23 -1
- package/dist/packem_shared/{types-BNbQJg02.d.ts → types-DmfKbIaI.d.ts} +23 -1
- package/dist/packem_shared/{types-D2-6p7t1.d.cts → types-_jqW_ZOt.d.mts} +3 -3
- package/dist/truncate.cjs +1 -0
- package/dist/truncate.mjs +1 -0
- package/dist/utils.cjs +57 -1
- package/dist/utils.d.cts +9 -13
- package/dist/utils.d.mts +9 -13
- package/dist/utils.d.ts +9 -13
- package/dist/utils.mjs +55 -0
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,15 @@
|
|
|
1
|
+
## @visulima/string [1.2.0](https://github.com/visulima/visulima/compare/@visulima/string@1.1.0...@visulima/string@1.2.0) (2025-05-07)
|
|
2
|
+
|
|
3
|
+
### Features
|
|
4
|
+
|
|
5
|
+
* added transliterate, slugify and replaceString ([#502](https://github.com/visulima/visulima/issues/502)) ([d2b1918](https://github.com/visulima/visulima/commit/d2b1918dd9ed87584ed3c05b11aceca581437c89))
|
|
6
|
+
|
|
7
|
+
## @visulima/string [1.1.0](https://github.com/visulima/visulima/compare/@visulima/string@1.0.5...@visulima/string@1.1.0) (2025-05-04)
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* **string:** enhance identifyCase function to support additional cases ([#501](https://github.com/visulima/visulima/issues/501)) ([8f8ecee](https://github.com/visulima/visulima/commit/8f8eceefef3f4ce332eb702979291a4db010256c))
|
|
12
|
+
|
|
1
13
|
## @visulima/string [1.0.5](https://github.com/visulima/visulima/compare/@visulima/string@1.0.4...@visulima/string@1.0.5) (2025-05-02)
|
|
2
14
|
|
|
3
15
|
### Bug Fixes
|
package/README.md
CHANGED
|
@@ -240,6 +240,75 @@ const customWrapped = wordWrap("Text with\u200Bzero-width characters and\u200Btr
|
|
|
240
240
|
});
|
|
241
241
|
```
|
|
242
242
|
|
|
243
|
+
### String Replacement with Ignore Ranges
|
|
244
|
+
|
|
245
|
+
The `replaceString` function provides advanced string replacement capabilities, allowing multiple search/replace operations (using strings or RegExps) while respecting specified index ranges that should be ignored. It also handles match precedence correctly (earlier start index wins, then longer match wins if starts are identical) and ensures only the highest-priority, non-overlapping, non-ignored match is applied in any given segment.
|
|
246
|
+
|
|
247
|
+
> **Note:** Use this function when you need fine-grained control over multiple replacements, especially when needing to ignore specific index ranges or handle complex overlapping matches with defined precedence rules. For simple, non-overlapping replacements without ignore ranges, native `String.prototype.replaceAll` might be sufficient.
|
|
248
|
+
|
|
249
|
+
```typescript
|
|
250
|
+
import replaceString from "@visulima/string/replace-string"; // Adjust import path if needed
|
|
251
|
+
import type { IntervalArray, OptionReplaceArray } from "@visulima/string";
|
|
252
|
+
|
|
253
|
+
// Basic Usage
|
|
254
|
+
const source1 = "Replace AB and CD";
|
|
255
|
+
const searches1: OptionReplaceArray = [
|
|
256
|
+
["AB", "ab"],
|
|
257
|
+
["CD", "cd"],
|
|
258
|
+
];
|
|
259
|
+
const result1 = replaceString(source1, searches1, []);
|
|
260
|
+
// result1: "Replace ab and cd"
|
|
261
|
+
|
|
262
|
+
// With Ignore Ranges
|
|
263
|
+
const source2 = "Replace AB and ignore CD and replace XY";
|
|
264
|
+
const searches2: OptionReplaceArray = [
|
|
265
|
+
["AB", "ab"],
|
|
266
|
+
["CD", "cd"], // This should be ignored by the range
|
|
267
|
+
["XY", "xy"],
|
|
268
|
+
];
|
|
269
|
+
// Ignore indices 19-20 (targets "re" in "ignore")
|
|
270
|
+
const ignoreRanges2: IntervalArray = [[19, 20]];
|
|
271
|
+
const result2 = replaceString(source2, searches2, ignoreRanges2);
|
|
272
|
+
// result2: "Replace ab and ignore cd and replace xy"
|
|
273
|
+
// Note: "CD" is replaced because it doesn't overlap the ignore range [19, 20].
|
|
274
|
+
|
|
275
|
+
// With Overlapping Matches (Longer match takes precedence)
|
|
276
|
+
const source3 = "abcde";
|
|
277
|
+
const searches3: OptionReplaceArray = [
|
|
278
|
+
["abc", "123"], // Lower precedence
|
|
279
|
+
["abcde", "54321"], // Higher precedence (longer)
|
|
280
|
+
];
|
|
281
|
+
const result3 = replaceString(source3, searches3, []);
|
|
282
|
+
// result3: "54321"
|
|
283
|
+
|
|
284
|
+
// With Overlapping Matches (Earlier start index takes precedence)
|
|
285
|
+
const source4 = "ababab";
|
|
286
|
+
const searches4: OptionReplaceArray = [
|
|
287
|
+
["aba", "X"], // Starts at 0
|
|
288
|
+
["bab", "Y"], // Starts at 1
|
|
289
|
+
];
|
|
290
|
+
const result4 = replaceString(source4, searches4, []);
|
|
291
|
+
// result4: "Xbab" (Applies "X" at 0, which covers indices 0-2. Skips "Y" at 1. Appends rest.)
|
|
292
|
+
|
|
293
|
+
// With Zero-Length Matches (e.g., inserting before each char)
|
|
294
|
+
const source5 = "abc";
|
|
295
|
+
const searches5: OptionReplaceArray = [[/(?=.)/g, "^"]]; // Lookahead for position before char
|
|
296
|
+
const result5 = replaceString(source5, searches5, []);
|
|
297
|
+
// result5: "^a^b^c"
|
|
298
|
+
|
|
299
|
+
// Zero-Length Match at End
|
|
300
|
+
const source6 = "abc";
|
|
301
|
+
const searches6: OptionReplaceArray = [[/$/g, "$"]]; // Matches end of string
|
|
302
|
+
const result6 = replaceString(source6, searches6, []);
|
|
303
|
+
// result6: "abc$"
|
|
304
|
+
|
|
305
|
+
// Using $& and $n replacements
|
|
306
|
+
const source7 = "Firstname Lastname";
|
|
307
|
+
const searches7: OptionReplaceArray = [[/(\w+)\s+(\w+)/, "$2, $1 ($& - Group 1: $1)"]];
|
|
308
|
+
const result7 = replaceString(source7, searches7, []);
|
|
309
|
+
// result7: "Lastname, Firstname (Firstname Lastname - Group 1: Firstname)"
|
|
310
|
+
```
|
|
311
|
+
|
|
243
312
|
### String Splitting
|
|
244
313
|
|
|
245
314
|
The `splitByCase` function is a powerful utility that splits strings based on various patterns:
|
|
@@ -838,6 +907,131 @@ The custom matcher provides detailed error messages when tests fail, showing:
|
|
|
838
907
|
- Whether the visible content matches but the colors differ
|
|
839
908
|
- Length information for both strings
|
|
840
909
|
|
|
910
|
+
### `replaceString(source, searches, ignoreRanges?)`
|
|
911
|
+
|
|
912
|
+
Replaces occurrences of search patterns within a string, respecting ignored ranges.
|
|
913
|
+
This function is designed to handle overlapping matches and ignore ranges correctly.
|
|
914
|
+
It prioritizes matches that start earlier and, for matches starting at the same position,
|
|
915
|
+
prefers longer matches. Replacements within ignored ranges are skipped.
|
|
916
|
+
|
|
917
|
+
**Parameters:**
|
|
918
|
+
|
|
919
|
+
- `source`: The input string.
|
|
920
|
+
- `searches`: An array of search pairs. Each pair can be:
|
|
921
|
+
- `[string | RegExp, string]`: A literal string or regex to search for, and its replacement string.
|
|
922
|
+
Regex flags like `g` (global) are respected.
|
|
923
|
+
- `ignoreRanges?`: Optional. An array of `[start, end]` index pairs (inclusive) specifying ranges within the
|
|
924
|
+
`source` string that should be ignored during replacement.
|
|
925
|
+
|
|
926
|
+
**Returns:**
|
|
927
|
+
|
|
928
|
+
- `string`: The string with replacements applied, respecting ignore ranges.
|
|
929
|
+
|
|
930
|
+
**Usage:**
|
|
931
|
+
|
|
932
|
+
```typescript
|
|
933
|
+
import { replaceString } from "@visulima/string";
|
|
934
|
+
|
|
935
|
+
const text = "abc abc abc";
|
|
936
|
+
const searches = [
|
|
937
|
+
[/a/g, "X"],
|
|
938
|
+
["abc", "YYY"],
|
|
939
|
+
];
|
|
940
|
+
const ignoreRanges = [[4, 6]]; // Ignore the second "abc"
|
|
941
|
+
|
|
942
|
+
const result = replaceString(text, searches, ignoreRanges);
|
|
943
|
+
// result will be: "YYY abc YYY"
|
|
944
|
+
// First 'abc' is replaced by 'YYY' (longer match takes precedence over 'X').
|
|
945
|
+
// Second 'abc' is ignored.
|
|
946
|
+
// Third 'abc' is replaced by 'YYY'.
|
|
947
|
+
```
|
|
948
|
+
|
|
949
|
+
### `transliterate(source, options?)`
|
|
950
|
+
|
|
951
|
+
Performs transliteration of characters in a string based on an extensive character map and provided options. This function is useful for converting characters from one script to another (e.g., Latin with diacritics to basic Latin, Cyrillic to Latin) or for custom character replacements.
|
|
952
|
+
|
|
953
|
+
**Parameters:**
|
|
954
|
+
|
|
955
|
+
- `source: string`: The input string to transliterate.
|
|
956
|
+
- `options?`: Optional `OptionsTransliterate` object:
|
|
957
|
+
- `fixChineseSpacing?: boolean`: If `true`, adds a space between transliterated Chinese Pinyin syllables. (Default: `true`).
|
|
958
|
+
- `ignore?: string[]`: An array of strings or characters to ignore during transliteration. These segments will be preserved in their original form. (Default: `[]`).
|
|
959
|
+
- `replaceBefore?: Array<[string | RegExp, string]> | Record<string, string>`: Custom replacement rules to apply _before_ the main character map transliteration. (Default: `[]`).
|
|
960
|
+
- `replaceAfter?: Array<[string | RegExp, string]> | Record<string, string>`: Custom replacement rules to apply _after_ the main character map transliteration. (Default: `[]`).
|
|
961
|
+
- `trim?: boolean`: If `true`, trims whitespace from the beginning and end of the result. (Default: `false`).
|
|
962
|
+
- `unknown?: string`: The character or string to use for characters that are not found in the character map and are not covered by other rules. (Default: `""` - removes unknown characters).
|
|
963
|
+
|
|
964
|
+
**Returns:**
|
|
965
|
+
|
|
966
|
+
- `string`: The transliterated string.
|
|
967
|
+
|
|
968
|
+
**Usage:**
|
|
969
|
+
|
|
970
|
+
```typescript
|
|
971
|
+
import { transliterate } from "@visulima/string"; // Assuming named export from package root
|
|
972
|
+
|
|
973
|
+
// Basic transliteration
|
|
974
|
+
transliterate("Crème brûlée"); // Expected: 'Creme brulee'
|
|
975
|
+
transliterate("你好世界"); // Expected: 'Ni Hao Shi Jie' (due to fixChineseSpacing: true)
|
|
976
|
+
transliterate("你好世界", { fixChineseSpacing: false }); // Expected: 'NiHaoShiJie'
|
|
977
|
+
|
|
978
|
+
// Using ignore
|
|
979
|
+
transliterate("Don't change THIS, but change that.", { ignore: ["THIS"] });
|
|
980
|
+
// Expected: 'Dont change THIS, but change that.'
|
|
981
|
+
|
|
982
|
+
// Using replaceBefore
|
|
983
|
+
transliterate("Replace C++ before map.", { replaceBefore: { "C++": "cpp" } });
|
|
984
|
+
// Expected: 'Replace cpp before map.'
|
|
985
|
+
|
|
986
|
+
// Using replaceAfter
|
|
987
|
+
// Example: charmap turns é -> e, then replaceAfter turns e -> E
|
|
988
|
+
transliterate("café", { replaceAfter: { e: "E" } });
|
|
989
|
+
// Expected: 'cafE'
|
|
990
|
+
|
|
991
|
+
// Handling unknown characters
|
|
992
|
+
transliterate("a🚀b", { unknown: "[?]" }); // Expected: 'a[?]b'
|
|
993
|
+
```
|
|
994
|
+
|
|
995
|
+
### `slugify(input, options?)`
|
|
996
|
+
|
|
997
|
+
Converts a string into a URL-friendly slug.
|
|
998
|
+
|
|
999
|
+
It transliterates non-ASCII characters using the `transliterate` function (if enabled), optionally converts case, removes disallowed characters (replacing with separator), and collapses separators.
|
|
1000
|
+
|
|
1001
|
+
**Parameters:**
|
|
1002
|
+
|
|
1003
|
+
- `input`: The string to convert.
|
|
1004
|
+
- `options?`: Optional `SlugifyOptions` object:
|
|
1005
|
+
- `allowedChars?: string`: Characters allowed in the slug. Others are replaced by `separator`. (Default: `"a-zA-Z0-9-_.~"`)
|
|
1006
|
+
- `fixChineseSpacing?: boolean`: Passed to `transliterate`. Determines if a space is added between transliterated Chinese characters (default: `true`).
|
|
1007
|
+
- `ignore?: string[]`: Passed to `transliterate`. Characters/strings to ignore during the initial transliteration phase (default: `[]`).
|
|
1008
|
+
- `lowercase?: boolean`: Convert to lowercase. (Default: `true`). Cannot be true if `uppercase` is true.
|
|
1009
|
+
- `replaceAfter?: OptionReplaceCombined`: Passed to `transliterate`. Search/replace pairs to apply _after_ the character map transliteration but _before_ slugification logic (default: `[]`).
|
|
1010
|
+
- `replaceBefore?: OptionReplaceCombined`: Passed to `transliterate`. Search/replace pairs to apply _before_ any transliteration (default: `[]`).
|
|
1011
|
+
- `separator?: string`: Custom separator. (Default: `"-"`).
|
|
1012
|
+
- `transliterate?: boolean`: Whether to perform the initial transliteration of non-ASCII characters. If `false`, only case conversion and character filtering/replacement are performed on the input string. (Default: `true`).
|
|
1013
|
+
- `unknown?: string`: Passed to `transliterate`. Character to use for unknown characters during transliteration (default: `""`).
|
|
1014
|
+
- `uppercase?: boolean`: Convert to uppercase. (Default: `false`). Cannot be true if `lowercase` is true.
|
|
1015
|
+
|
|
1016
|
+
**Returns:**
|
|
1017
|
+
|
|
1018
|
+
- `string`: The generated slug.
|
|
1019
|
+
|
|
1020
|
+
**Usage:**
|
|
1021
|
+
|
|
1022
|
+
```typescript
|
|
1023
|
+
import { slugify } from "@visulima/string";
|
|
1024
|
+
|
|
1025
|
+
slugify("你好 World!"); // 'ni-hao-world' (fixChineseSpacing=true by default)
|
|
1026
|
+
slugify("你好World!", { fixChineseSpacing: false }); // 'nihaoworld'
|
|
1027
|
+
slugify("Crème Brûlée"); // 'creme-brulee'
|
|
1028
|
+
slugify("foo & bar * baz"); // 'foo-bar-baz' (&, *, space are disallowed)
|
|
1029
|
+
slugify("FOO BAR", { lowercase: false, uppercase: true }); // 'FOO-BAR'
|
|
1030
|
+
slugify("foo bar baz", { separator: "_", allowedChars: "a-z_" }); // 'foo_bar_baz'
|
|
1031
|
+
slugify("Keep C++", { replaceBefore: { "C++": "cpp" } }); // 'keep-cpp'
|
|
1032
|
+
slugify("Keep !@#$", { allowedChars: "a-z!@$" }); // 'keep!@$'
|
|
1033
|
+
```
|
|
1034
|
+
|
|
841
1035
|
## Related
|
|
842
1036
|
|
|
843
1037
|
- [change-case](https://github.com/blakeembrey/change-case) - Simple string case utilities
|
|
@@ -850,11 +1044,16 @@ The custom matcher provides detailed error messages when tests fail, showing:
|
|
|
850
1044
|
- [fast-string-truncated-width](https://github.com/fabiospampinato/fast-string-truncated-width) - Fast string truncated width
|
|
851
1045
|
- [ansi-truncate](https://github.com/fabiospampinato/ansi-truncate) - Truncate strings with ANSI escape codes
|
|
852
1046
|
- [string-ts](https://github.com/gustavoguichard/string-ts) - Strongly typed string functions
|
|
1047
|
+
- [@sindresorhus/slugify](https://github.com/sindresorhus/slugify) - Slugify a string
|
|
1048
|
+
- [slugify](https://github.com/simov/slugify) - Slugify a string
|
|
1049
|
+
- [@sindresorhus/transliterate](https://github.com/sindresorhus/transliterate) - Convert Unicode characters to Latin characters using transliteration
|
|
1050
|
+
- [transliteration](https://github.com/yf-hk/transliteration/tree/main) - UTF-8 to ASCII transliteration / slugify module for node.js, browser, Web Worker, React Native, Electron and CLI.
|
|
1051
|
+
- [unidecode](https://github.com/FGRibreau/node-unidecode) - 📃 ASCII transliterations of Unicode text
|
|
853
1052
|
|
|
854
1053
|
## Supported Node.js Versions
|
|
855
1054
|
|
|
856
|
-
Libraries in this ecosystem make the best effort to track [Node.js
|
|
857
|
-
Here
|
|
1055
|
+
Libraries in this ecosystem make the best effort to track [Node.js' release schedule](https://github.com/nodejs/release#release-schedule).
|
|
1056
|
+
Here's [a post on why we think this is important](https://medium.com/the-node-js-collection/maintainers-should-consider-following-node-js-release-schedule-ab08ed4de71a).
|
|
858
1057
|
|
|
859
1058
|
## Contributing
|
|
860
1059
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import '../packem_shared/types-
|
|
3
|
-
import '../
|
|
1
|
+
import { C as CaseOptions, a as CamelCase } from '../packem_shared/types-C5Pk8B8Q.cjs';
|
|
2
|
+
import '../packem_shared/types-DmfKbIaI.cjs';
|
|
3
|
+
import '../packem_shared/lru-cache-B_t27XwI.cjs';
|
|
4
4
|
|
|
5
5
|
declare const camelCase: <T extends string = string>(value?: T, options?: CaseOptions) => CamelCase<T>;
|
|
6
6
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import '../packem_shared/types-
|
|
3
|
-
import '../
|
|
1
|
+
import { C as CaseOptions, a as CamelCase } from '../packem_shared/types-_jqW_ZOt.mjs';
|
|
2
|
+
import '../packem_shared/types-DmfKbIaI.mjs';
|
|
3
|
+
import '../packem_shared/lru-cache-B_t27XwI.mjs';
|
|
4
4
|
|
|
5
5
|
declare const camelCase: <T extends string = string>(value?: T, options?: CaseOptions) => CamelCase<T>;
|
|
6
6
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import '../packem_shared/types-
|
|
3
|
-
import '../
|
|
1
|
+
import { C as CaseOptions, a as CamelCase } from '../packem_shared/types-DcGtApe2.js';
|
|
2
|
+
import '../packem_shared/types-DmfKbIaI.js';
|
|
3
|
+
import '../packem_shared/lru-cache-B_t27XwI.js';
|
|
4
4
|
|
|
5
5
|
declare const camelCase: <T extends string = string>(value?: T, options?: CaseOptions) => CamelCase<T>;
|
|
6
6
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import '../packem_shared/types-
|
|
3
|
-
import '../
|
|
1
|
+
import { C as CaseOptions, b as CapitalCase } from '../packem_shared/types-C5Pk8B8Q.cjs';
|
|
2
|
+
import '../packem_shared/types-DmfKbIaI.cjs';
|
|
3
|
+
import '../packem_shared/lru-cache-B_t27XwI.cjs';
|
|
4
4
|
|
|
5
5
|
declare const capitalCase: <T extends string = string>(value?: T, options?: CaseOptions) => CapitalCase<T>;
|
|
6
6
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import '../packem_shared/types-
|
|
3
|
-
import '../
|
|
1
|
+
import { C as CaseOptions, b as CapitalCase } from '../packem_shared/types-_jqW_ZOt.mjs';
|
|
2
|
+
import '../packem_shared/types-DmfKbIaI.mjs';
|
|
3
|
+
import '../packem_shared/lru-cache-B_t27XwI.mjs';
|
|
4
4
|
|
|
5
5
|
declare const capitalCase: <T extends string = string>(value?: T, options?: CaseOptions) => CapitalCase<T>;
|
|
6
6
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import '../packem_shared/types-
|
|
3
|
-
import '../
|
|
1
|
+
import { C as CaseOptions, b as CapitalCase } from '../packem_shared/types-DcGtApe2.js';
|
|
2
|
+
import '../packem_shared/types-DmfKbIaI.js';
|
|
3
|
+
import '../packem_shared/lru-cache-B_t27XwI.js';
|
|
4
4
|
|
|
5
5
|
declare const capitalCase: <T extends string = string>(value?: T, options?: CaseOptions) => CapitalCase<T>;
|
|
6
6
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import '../packem_shared/types-
|
|
3
|
-
import '../
|
|
1
|
+
import { C as CaseOptions, c as ConstantCase } from '../packem_shared/types-C5Pk8B8Q.cjs';
|
|
2
|
+
import '../packem_shared/types-DmfKbIaI.cjs';
|
|
3
|
+
import '../packem_shared/lru-cache-B_t27XwI.cjs';
|
|
4
4
|
|
|
5
5
|
declare const constantCase: <T extends string = string>(value?: T, options?: CaseOptions) => ConstantCase<T>;
|
|
6
6
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import '../packem_shared/types-
|
|
3
|
-
import '../
|
|
1
|
+
import { C as CaseOptions, c as ConstantCase } from '../packem_shared/types-_jqW_ZOt.mjs';
|
|
2
|
+
import '../packem_shared/types-DmfKbIaI.mjs';
|
|
3
|
+
import '../packem_shared/lru-cache-B_t27XwI.mjs';
|
|
4
4
|
|
|
5
5
|
declare const constantCase: <T extends string = string>(value?: T, options?: CaseOptions) => ConstantCase<T>;
|
|
6
6
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import '../packem_shared/types-
|
|
3
|
-
import '../
|
|
1
|
+
import { C as CaseOptions, c as ConstantCase } from '../packem_shared/types-DcGtApe2.js';
|
|
2
|
+
import '../packem_shared/types-DmfKbIaI.js';
|
|
3
|
+
import '../packem_shared/lru-cache-B_t27XwI.js';
|
|
4
4
|
|
|
5
5
|
declare const constantCase: <T extends string = string>(value?: T, options?: CaseOptions) => ConstantCase<T>;
|
|
6
6
|
|
package/dist/case/dot-case.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import '../packem_shared/types-
|
|
3
|
-
import '../
|
|
1
|
+
import { C as CaseOptions, D as DotCase } from '../packem_shared/types-C5Pk8B8Q.cjs';
|
|
2
|
+
import '../packem_shared/types-DmfKbIaI.cjs';
|
|
3
|
+
import '../packem_shared/lru-cache-B_t27XwI.cjs';
|
|
4
4
|
|
|
5
5
|
declare const dotCase: <T extends string = string>(value?: T, options?: CaseOptions) => DotCase<T>;
|
|
6
6
|
|
package/dist/case/dot-case.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import '../packem_shared/types-
|
|
3
|
-
import '../
|
|
1
|
+
import { C as CaseOptions, D as DotCase } from '../packem_shared/types-_jqW_ZOt.mjs';
|
|
2
|
+
import '../packem_shared/types-DmfKbIaI.mjs';
|
|
3
|
+
import '../packem_shared/lru-cache-B_t27XwI.mjs';
|
|
4
4
|
|
|
5
5
|
declare const dotCase: <T extends string = string>(value?: T, options?: CaseOptions) => DotCase<T>;
|
|
6
6
|
|
package/dist/case/dot-case.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import '../packem_shared/types-
|
|
3
|
-
import '../
|
|
1
|
+
import { C as CaseOptions, D as DotCase } from '../packem_shared/types-DcGtApe2.js';
|
|
2
|
+
import '../packem_shared/types-DmfKbIaI.js';
|
|
3
|
+
import '../packem_shared/lru-cache-B_t27XwI.js';
|
|
4
4
|
|
|
5
5
|
declare const dotCase: <T extends string = string>(value?: T, options?: CaseOptions) => DotCase<T>;
|
|
6
6
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import '../packem_shared/types-
|
|
3
|
-
import '../
|
|
1
|
+
import { C as CaseOptions, F as FlatCase } from '../packem_shared/types-C5Pk8B8Q.cjs';
|
|
2
|
+
import '../packem_shared/types-DmfKbIaI.cjs';
|
|
3
|
+
import '../packem_shared/lru-cache-B_t27XwI.cjs';
|
|
4
4
|
|
|
5
5
|
declare const flatCase: <T extends string = string>(value?: T, options?: CaseOptions) => FlatCase<T>;
|
|
6
6
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import '../packem_shared/types-
|
|
3
|
-
import '../
|
|
1
|
+
import { C as CaseOptions, F as FlatCase } from '../packem_shared/types-_jqW_ZOt.mjs';
|
|
2
|
+
import '../packem_shared/types-DmfKbIaI.mjs';
|
|
3
|
+
import '../packem_shared/lru-cache-B_t27XwI.mjs';
|
|
4
4
|
|
|
5
5
|
declare const flatCase: <T extends string = string>(value?: T, options?: CaseOptions) => FlatCase<T>;
|
|
6
6
|
|
package/dist/case/flat-case.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import '../packem_shared/types-
|
|
3
|
-
import '../
|
|
1
|
+
import { C as CaseOptions, F as FlatCase } from '../packem_shared/types-DcGtApe2.js';
|
|
2
|
+
import '../packem_shared/types-DmfKbIaI.js';
|
|
3
|
+
import '../packem_shared/lru-cache-B_t27XwI.js';
|
|
4
4
|
|
|
5
5
|
declare const flatCase: <T extends string = string>(value?: T, options?: CaseOptions) => FlatCase<T>;
|
|
6
6
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import '../packem_shared/types-
|
|
3
|
-
import '../
|
|
1
|
+
import { C as CaseOptions, d as FlipCase } from '../packem_shared/types-C5Pk8B8Q.cjs';
|
|
2
|
+
import '../packem_shared/types-DmfKbIaI.cjs';
|
|
3
|
+
import '../packem_shared/lru-cache-B_t27XwI.cjs';
|
|
4
4
|
|
|
5
5
|
type FlipOptions = Omit<CaseOptions, "handleEmoji">;
|
|
6
6
|
declare const flipCase: <T extends string = string>(value?: T, options?: FlipOptions) => FlipCase<T>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import '../packem_shared/types-
|
|
3
|
-
import '../
|
|
1
|
+
import { C as CaseOptions, d as FlipCase } from '../packem_shared/types-_jqW_ZOt.mjs';
|
|
2
|
+
import '../packem_shared/types-DmfKbIaI.mjs';
|
|
3
|
+
import '../packem_shared/lru-cache-B_t27XwI.mjs';
|
|
4
4
|
|
|
5
5
|
type FlipOptions = Omit<CaseOptions, "handleEmoji">;
|
|
6
6
|
declare const flipCase: <T extends string = string>(value?: T, options?: FlipOptions) => FlipCase<T>;
|
package/dist/case/flip-case.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import '../packem_shared/types-
|
|
3
|
-
import '../
|
|
1
|
+
import { C as CaseOptions, d as FlipCase } from '../packem_shared/types-DcGtApe2.js';
|
|
2
|
+
import '../packem_shared/types-DmfKbIaI.js';
|
|
3
|
+
import '../packem_shared/lru-cache-B_t27XwI.js';
|
|
4
4
|
|
|
5
5
|
type FlipOptions = Omit<CaseOptions, "handleEmoji">;
|
|
6
6
|
declare const flipCase: <T extends string = string>(value?: T, options?: FlipOptions) => FlipCase<T>;
|
|
@@ -2,28 +2,67 @@
|
|
|
2
2
|
|
|
3
3
|
var __defProp = Object.defineProperty;
|
|
4
4
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
5
|
+
const IS_PASCAL_CASE = /^([A-Z][a-z]*)+$/;
|
|
6
|
+
const CONTAINS_LETTER_CASE_INSENSITIVE = /[a-z]/i;
|
|
7
|
+
const IS_UPPER_SNAKE_CASE = /^[A-Z0-9_]+$/;
|
|
8
|
+
const IS_LOWER_SNAKE_CASE = /^[a-z0-9_]+$/;
|
|
9
|
+
const IS_KEBAB_CASE = /^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/;
|
|
10
|
+
const IS_LOWERCASE_WITH_SPACE = /^[a-z ]+$/;
|
|
11
|
+
const IS_UPPERCASE = /^[A-Z][A-Z0-9]*$/;
|
|
12
|
+
const WHITESPACE_REGEX = /\s+/;
|
|
13
|
+
const IS_NUMERIC = /^\d+$/;
|
|
14
|
+
const IS_CAMEL_CASE_LIKE = /^[a-z][a-z0-9]*(?:[A-Z][a-z0-9]*)+$/;
|
|
15
|
+
const CONTAINS_PUNCTUATION_MID_WORD = /[.!?;:,](?!\s|$)/;
|
|
5
16
|
const identifyCase = /* @__PURE__ */ __name((value) => {
|
|
6
|
-
if (typeof value !== "string"
|
|
7
|
-
|
|
17
|
+
if (typeof value !== "string") {
|
|
18
|
+
throw new TypeError("Expected input to be a string");
|
|
19
|
+
}
|
|
20
|
+
if (!value) {
|
|
21
|
+
return "unknown";
|
|
22
|
+
}
|
|
23
|
+
if (!CONTAINS_LETTER_CASE_INSENSITIVE.test(value)) {
|
|
24
|
+
return "unknown";
|
|
8
25
|
}
|
|
9
|
-
if (value
|
|
10
|
-
if (
|
|
26
|
+
if (value.includes("_")) {
|
|
27
|
+
if (IS_UPPER_SNAKE_CASE.test(value)) {
|
|
28
|
+
return "upper_snake";
|
|
29
|
+
}
|
|
30
|
+
if (IS_LOWER_SNAKE_CASE.test(value)) {
|
|
11
31
|
return "snake";
|
|
12
32
|
}
|
|
13
|
-
|
|
33
|
+
return "mixed";
|
|
34
|
+
}
|
|
35
|
+
if (value.includes("-")) {
|
|
36
|
+
if (IS_KEBAB_CASE.test(value)) {
|
|
14
37
|
return "kebab";
|
|
15
38
|
}
|
|
39
|
+
return "mixed";
|
|
40
|
+
}
|
|
41
|
+
if (IS_LOWERCASE_WITH_SPACE.test(value)) {
|
|
16
42
|
return "lower";
|
|
17
43
|
}
|
|
18
|
-
if (
|
|
44
|
+
if (IS_UPPERCASE.test(value)) {
|
|
19
45
|
return "upper";
|
|
20
46
|
}
|
|
21
|
-
|
|
47
|
+
const words = value.split(WHITESPACE_REGEX);
|
|
48
|
+
if (words.length > 1 && words.every((word) => IS_PASCAL_CASE.test(word))) {
|
|
49
|
+
return "title";
|
|
50
|
+
}
|
|
51
|
+
if (words.length > 1 && IS_NUMERIC.test(words[0]) && IS_PASCAL_CASE.test(words[1])) {
|
|
52
|
+
return "title";
|
|
53
|
+
}
|
|
54
|
+
if (words.length > 1 && IS_PASCAL_CASE.test(words[0]) && /^[a-z]/.test(words[1])) {
|
|
55
|
+
return "sentence";
|
|
56
|
+
}
|
|
57
|
+
if (IS_PASCAL_CASE.test(value)) {
|
|
22
58
|
return "pascal";
|
|
23
59
|
}
|
|
24
|
-
if (
|
|
60
|
+
if (IS_CAMEL_CASE_LIKE.test(value)) {
|
|
25
61
|
return "camel";
|
|
26
62
|
}
|
|
63
|
+
if (CONTAINS_PUNCTUATION_MID_WORD.test(value)) {
|
|
64
|
+
return "unknown";
|
|
65
|
+
}
|
|
27
66
|
return "mixed";
|
|
28
67
|
}, "identifyCase");
|
|
29
68
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { I as IdentifyCase } from '../packem_shared/types-
|
|
2
|
-
import '../packem_shared/types-
|
|
3
|
-
import '../
|
|
1
|
+
import { I as IdentifyCase } from '../packem_shared/types-C5Pk8B8Q.cjs';
|
|
2
|
+
import '../packem_shared/types-DmfKbIaI.cjs';
|
|
3
|
+
import '../packem_shared/lru-cache-B_t27XwI.cjs';
|
|
4
4
|
|
|
5
5
|
declare const identifyCase: <T extends string = string>(value?: T) => IdentifyCase<T>;
|
|
6
6
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { I as IdentifyCase } from '../packem_shared/types-
|
|
2
|
-
import '../packem_shared/types-
|
|
3
|
-
import '../
|
|
1
|
+
import { I as IdentifyCase } from '../packem_shared/types-_jqW_ZOt.mjs';
|
|
2
|
+
import '../packem_shared/types-DmfKbIaI.mjs';
|
|
3
|
+
import '../packem_shared/lru-cache-B_t27XwI.mjs';
|
|
4
4
|
|
|
5
5
|
declare const identifyCase: <T extends string = string>(value?: T) => IdentifyCase<T>;
|
|
6
6
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { I as IdentifyCase } from '../packem_shared/types-
|
|
2
|
-
import '../packem_shared/types-
|
|
3
|
-
import '../
|
|
1
|
+
import { I as IdentifyCase } from '../packem_shared/types-DcGtApe2.js';
|
|
2
|
+
import '../packem_shared/types-DmfKbIaI.js';
|
|
3
|
+
import '../packem_shared/lru-cache-B_t27XwI.js';
|
|
4
4
|
|
|
5
5
|
declare const identifyCase: <T extends string = string>(value?: T) => IdentifyCase<T>;
|
|
6
6
|
|
|
@@ -1,27 +1,66 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
2
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
const IS_PASCAL_CASE = /^([A-Z][a-z]*)+$/;
|
|
4
|
+
const CONTAINS_LETTER_CASE_INSENSITIVE = /[a-z]/i;
|
|
5
|
+
const IS_UPPER_SNAKE_CASE = /^[A-Z0-9_]+$/;
|
|
6
|
+
const IS_LOWER_SNAKE_CASE = /^[a-z0-9_]+$/;
|
|
7
|
+
const IS_KEBAB_CASE = /^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/;
|
|
8
|
+
const IS_LOWERCASE_WITH_SPACE = /^[a-z ]+$/;
|
|
9
|
+
const IS_UPPERCASE = /^[A-Z][A-Z0-9]*$/;
|
|
10
|
+
const WHITESPACE_REGEX = /\s+/;
|
|
11
|
+
const IS_NUMERIC = /^\d+$/;
|
|
12
|
+
const IS_CAMEL_CASE_LIKE = /^[a-z][a-z0-9]*(?:[A-Z][a-z0-9]*)+$/;
|
|
13
|
+
const CONTAINS_PUNCTUATION_MID_WORD = /[.!?;:,](?!\s|$)/;
|
|
3
14
|
const identifyCase = /* @__PURE__ */ __name((value) => {
|
|
4
|
-
if (typeof value !== "string"
|
|
5
|
-
|
|
15
|
+
if (typeof value !== "string") {
|
|
16
|
+
throw new TypeError("Expected input to be a string");
|
|
17
|
+
}
|
|
18
|
+
if (!value) {
|
|
19
|
+
return "unknown";
|
|
20
|
+
}
|
|
21
|
+
if (!CONTAINS_LETTER_CASE_INSENSITIVE.test(value)) {
|
|
22
|
+
return "unknown";
|
|
6
23
|
}
|
|
7
|
-
if (value
|
|
8
|
-
if (
|
|
24
|
+
if (value.includes("_")) {
|
|
25
|
+
if (IS_UPPER_SNAKE_CASE.test(value)) {
|
|
26
|
+
return "upper_snake";
|
|
27
|
+
}
|
|
28
|
+
if (IS_LOWER_SNAKE_CASE.test(value)) {
|
|
9
29
|
return "snake";
|
|
10
30
|
}
|
|
11
|
-
|
|
31
|
+
return "mixed";
|
|
32
|
+
}
|
|
33
|
+
if (value.includes("-")) {
|
|
34
|
+
if (IS_KEBAB_CASE.test(value)) {
|
|
12
35
|
return "kebab";
|
|
13
36
|
}
|
|
37
|
+
return "mixed";
|
|
38
|
+
}
|
|
39
|
+
if (IS_LOWERCASE_WITH_SPACE.test(value)) {
|
|
14
40
|
return "lower";
|
|
15
41
|
}
|
|
16
|
-
if (
|
|
42
|
+
if (IS_UPPERCASE.test(value)) {
|
|
17
43
|
return "upper";
|
|
18
44
|
}
|
|
19
|
-
|
|
45
|
+
const words = value.split(WHITESPACE_REGEX);
|
|
46
|
+
if (words.length > 1 && words.every((word) => IS_PASCAL_CASE.test(word))) {
|
|
47
|
+
return "title";
|
|
48
|
+
}
|
|
49
|
+
if (words.length > 1 && IS_NUMERIC.test(words[0]) && IS_PASCAL_CASE.test(words[1])) {
|
|
50
|
+
return "title";
|
|
51
|
+
}
|
|
52
|
+
if (words.length > 1 && IS_PASCAL_CASE.test(words[0]) && /^[a-z]/.test(words[1])) {
|
|
53
|
+
return "sentence";
|
|
54
|
+
}
|
|
55
|
+
if (IS_PASCAL_CASE.test(value)) {
|
|
20
56
|
return "pascal";
|
|
21
57
|
}
|
|
22
|
-
if (
|
|
58
|
+
if (IS_CAMEL_CASE_LIKE.test(value)) {
|
|
23
59
|
return "camel";
|
|
24
60
|
}
|
|
61
|
+
if (CONTAINS_PUNCTUATION_MID_WORD.test(value)) {
|
|
62
|
+
return "unknown";
|
|
63
|
+
}
|
|
25
64
|
return "mixed";
|
|
26
65
|
}, "identifyCase");
|
|
27
66
|
|