atomic-fns 1.2.0 → 2.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.
Files changed (216) hide show
  1. package/README.md +397 -91
  2. package/dist/array/index.d.ts +9 -0
  3. package/dist/array/index.js +9 -0
  4. package/dist/array/list.d.ts +99 -0
  5. package/dist/array/list.js +133 -0
  6. package/dist/array/sets.d.ts +130 -0
  7. package/dist/array/sets.js +213 -0
  8. package/dist/async/index.d.ts +6 -0
  9. package/dist/async/index.js +6 -0
  10. package/dist/async/retry.d.ts +38 -0
  11. package/dist/async/retry.js +56 -0
  12. package/dist/async/sleep.d.ts +42 -0
  13. package/dist/async/sleep.js +76 -0
  14. package/dist/collections/bisect.d.ts +103 -0
  15. package/dist/collections/bisect.js +157 -0
  16. package/dist/collections/deque.d.ts +67 -97
  17. package/dist/collections/deque.js +197 -256
  18. package/dist/collections/entries.d.ts +89 -0
  19. package/dist/collections/entries.js +131 -0
  20. package/dist/collections/frozen-set.d.ts +42 -0
  21. package/dist/collections/frozen-set.js +64 -0
  22. package/dist/collections/group.d.ts +141 -0
  23. package/dist/collections/group.js +241 -0
  24. package/dist/collections/heap.d.ts +64 -0
  25. package/dist/collections/heap.js +205 -0
  26. package/dist/collections/index.d.ts +15 -623
  27. package/dist/collections/index.js +14 -844
  28. package/dist/collections/internal/arrayKeys.d.ts +19 -0
  29. package/dist/collections/internal/arrayKeys.js +83 -0
  30. package/dist/collections/internal/invariants.d.ts +4 -0
  31. package/dist/collections/internal/invariants.js +12 -0
  32. package/dist/collections/internal/iterable.d.ts +25 -0
  33. package/dist/collections/internal/iterable.js +62 -0
  34. package/dist/collections/iterate.d.ts +162 -0
  35. package/dist/collections/iterate.js +188 -0
  36. package/dist/collections/lru-cache.d.ts +58 -0
  37. package/dist/collections/lru-cache.js +164 -0
  38. package/dist/collections/order.d.ts +19 -0
  39. package/dist/collections/order.js +38 -0
  40. package/dist/collections/shape.d.ts +32 -0
  41. package/dist/collections/shape.js +86 -0
  42. package/dist/collections/sorted-map.d.ts +171 -0
  43. package/dist/collections/sorted-map.js +845 -0
  44. package/dist/collections/sorted-set.d.ts +103 -0
  45. package/dist/collections/sorted-set.js +147 -0
  46. package/dist/collections/splay-tree.d.ts +82 -0
  47. package/dist/collections/splay-tree.js +354 -0
  48. package/dist/collections/trie.d.ts +58 -0
  49. package/dist/collections/trie.js +196 -0
  50. package/dist/decimal/currency.d.ts +211 -0
  51. package/dist/decimal/currency.js +321 -0
  52. package/dist/decimal/decimal.d.ts +299 -0
  53. package/dist/decimal/decimal.js +660 -0
  54. package/dist/decimal/index.d.ts +11 -148
  55. package/dist/decimal/index.js +10 -410
  56. package/dist/decimal/internal/bits.d.ts +2 -0
  57. package/dist/decimal/internal/bits.js +7 -0
  58. package/dist/decimal/internal/echo.d.ts +4 -0
  59. package/dist/decimal/internal/echo.js +6 -0
  60. package/dist/decimal/internal/isqrt.d.ts +9 -0
  61. package/dist/decimal/internal/isqrt.js +34 -0
  62. package/dist/decimal/internal/locale.d.ts +7 -0
  63. package/dist/decimal/internal/locale.js +24 -0
  64. package/dist/decimal/internal/minor-units.d.ts +2 -0
  65. package/dist/decimal/internal/minor-units.js +33 -0
  66. package/dist/decimal/internal/pow10.d.ts +24 -0
  67. package/dist/decimal/internal/pow10.js +96 -0
  68. package/dist/encoding/base64.d.ts +39 -0
  69. package/dist/encoding/base64.js +53 -0
  70. package/dist/encoding/hex.d.ts +23 -0
  71. package/dist/encoding/hex.js +34 -0
  72. package/dist/encoding/index.d.ts +6 -0
  73. package/dist/encoding/index.js +6 -0
  74. package/dist/function/debounce.d.ts +68 -0
  75. package/dist/function/debounce.js +203 -0
  76. package/dist/function/index.d.ts +6 -0
  77. package/dist/function/index.js +6 -0
  78. package/dist/function/shared.d.ts +2 -0
  79. package/dist/function/shared.js +5 -0
  80. package/dist/function/wrap.d.ts +130 -0
  81. package/dist/function/wrap.js +113 -0
  82. package/dist/hash/digest.d.ts +18 -0
  83. package/dist/hash/digest.js +26 -0
  84. package/dist/hash/hash.d.ts +22 -0
  85. package/dist/hash/hash.js +252 -0
  86. package/dist/hash/hashString.d.ts +13 -0
  87. package/dist/hash/hashString.js +53 -0
  88. package/dist/hash/index.d.ts +8 -0
  89. package/dist/hash/index.js +8 -0
  90. package/dist/hash/stableStringify.d.ts +19 -0
  91. package/dist/hash/stableStringify.js +102 -0
  92. package/dist/id/index.d.ts +7 -0
  93. package/dist/id/index.js +7 -0
  94. package/dist/id/nanoid.d.ts +16 -0
  95. package/dist/id/nanoid.js +65 -0
  96. package/dist/id/uniqueId.d.ts +14 -0
  97. package/dist/id/uniqueId.js +20 -0
  98. package/dist/id/uuid.d.ts +25 -0
  99. package/dist/id/uuid.js +64 -0
  100. package/dist/index.d.ts +15 -8
  101. package/dist/index.js +15 -8
  102. package/dist/internal/bytes.d.ts +11 -0
  103. package/dist/internal/bytes.js +33 -0
  104. package/dist/internal/codec.d.ts +11 -0
  105. package/dist/internal/codec.js +84 -0
  106. package/dist/internal/compare.d.ts +10 -0
  107. package/dist/internal/compare.js +26 -0
  108. package/dist/internal/crypto.d.ts +5 -0
  109. package/dist/internal/crypto.js +11 -0
  110. package/dist/internal/keys.d.ts +12 -0
  111. package/dist/internal/keys.js +23 -0
  112. package/dist/internal/kind.d.ts +44 -0
  113. package/dist/internal/kind.js +139 -0
  114. package/dist/internal/sparse.d.ts +51 -0
  115. package/dist/internal/sparse.js +104 -0
  116. package/dist/internal/text.d.ts +7 -0
  117. package/dist/internal/text.js +15 -0
  118. package/dist/internal/timer.d.ts +10 -0
  119. package/dist/internal/timer.js +17 -0
  120. package/dist/internal/truncate.d.ts +10 -0
  121. package/dist/internal/truncate.js +22 -0
  122. package/dist/internal/walk.d.ts +47 -0
  123. package/dist/internal/walk.js +100 -0
  124. package/dist/is/index.d.ts +8 -0
  125. package/dist/is/index.js +8 -0
  126. package/dist/is/isArrayLike.d.ts +18 -0
  127. package/dist/is/isArrayLike.js +25 -0
  128. package/dist/is/isError.d.ts +13 -0
  129. package/dist/is/isError.js +18 -0
  130. package/dist/is/isNil.d.ts +12 -0
  131. package/dist/is/isNil.js +14 -0
  132. package/dist/is/isPlainObject.d.ts +15 -0
  133. package/dist/is/isPlainObject.js +34 -0
  134. package/dist/number/index.d.ts +7 -0
  135. package/dist/number/index.js +7 -0
  136. package/dist/number/round.d.ts +86 -0
  137. package/dist/number/round.js +130 -0
  138. package/dist/number/stats.d.ts +52 -0
  139. package/dist/number/stats.js +115 -0
  140. package/dist/object/cloneDeep.d.ts +28 -0
  141. package/dist/object/cloneDeep.js +200 -0
  142. package/dist/object/index.d.ts +14 -0
  143. package/dist/object/index.js +13 -0
  144. package/dist/object/isEqual.d.ts +64 -0
  145. package/dist/object/isEqual.js +289 -0
  146. package/dist/object/matches.d.ts +40 -0
  147. package/dist/object/matches.js +284 -0
  148. package/dist/object/merge.d.ts +66 -0
  149. package/dist/object/merge.js +272 -0
  150. package/dist/object/parsePath.d.ts +22 -0
  151. package/dist/object/parsePath.js +111 -0
  152. package/dist/object/path.d.ts +85 -0
  153. package/dist/object/path.js +208 -0
  154. package/dist/object/pick.d.ts +91 -0
  155. package/dist/object/pick.js +180 -0
  156. package/dist/object/reshape.d.ts +73 -0
  157. package/dist/object/reshape.js +144 -0
  158. package/dist/random/index.d.ts +96 -32
  159. package/dist/random/index.js +215 -53
  160. package/dist/string/case.d.ts +71 -0
  161. package/dist/string/case.js +152 -0
  162. package/dist/string/fold.d.ts +35 -0
  163. package/dist/string/fold.js +100 -0
  164. package/dist/string/index.d.ts +6 -187
  165. package/dist/string/index.js +6 -224
  166. package/dist/string/truncate.d.ts +25 -0
  167. package/dist/string/truncate.js +44 -0
  168. package/dist/string/words.d.ts +27 -0
  169. package/dist/string/words.js +241 -0
  170. package/package.json +99 -51
  171. package/dist/collections/BTree.d.ts +0 -230
  172. package/dist/collections/BTree.js +0 -1143
  173. package/dist/collections/Heap.d.ts +0 -69
  174. package/dist/collections/Heap.js +0 -181
  175. package/dist/collections/LRUCache.d.ts +0 -83
  176. package/dist/collections/LRUCache.js +0 -139
  177. package/dist/collections/SortedMap.d.ts +0 -92
  178. package/dist/collections/SortedMap.js +0 -131
  179. package/dist/collections/SortedSet.d.ts +0 -69
  180. package/dist/collections/SortedSet.js +0 -99
  181. package/dist/collections/SortedTree.d.ts +0 -103
  182. package/dist/collections/SortedTree.js +0 -142
  183. package/dist/collections/SplayTree.d.ts +0 -107
  184. package/dist/collections/SplayTree.js +0 -351
  185. package/dist/collections/Trie.d.ts +0 -42
  186. package/dist/collections/Trie.js +0 -104
  187. package/dist/collections/abc.d.ts +0 -152
  188. package/dist/collections/abc.js +0 -39
  189. package/dist/collections/frozenset.d.ts +0 -19
  190. package/dist/collections/frozenset.js +0 -33
  191. package/dist/functools/index.d.ts +0 -106
  192. package/dist/functools/index.js +0 -203
  193. package/dist/globals/index.d.ts +0 -268
  194. package/dist/globals/index.js +0 -447
  195. package/dist/i18n/currency.d.ts +0 -27
  196. package/dist/i18n/currency.js +0 -100
  197. package/dist/i18n/date/index.d.ts +0 -210
  198. package/dist/i18n/date/index.js +0 -552
  199. package/dist/i18n/date/utils.d.ts +0 -64
  200. package/dist/i18n/date/utils.js +0 -192
  201. package/dist/i18n/duration.d.ts +0 -113
  202. package/dist/i18n/duration.js +0 -398
  203. package/dist/i18n/format.d.ts +0 -34
  204. package/dist/i18n/format.js +0 -378
  205. package/dist/i18n/index.d.ts +0 -9
  206. package/dist/i18n/index.js +0 -8
  207. package/dist/itertools/index.d.ts +0 -251
  208. package/dist/itertools/index.js +0 -434
  209. package/dist/math/index.d.ts +0 -79
  210. package/dist/math/index.js +0 -81
  211. package/dist/mod.d.ts +0 -1
  212. package/dist/mod.js +0 -1
  213. package/dist/operators/index.d.ts +0 -148
  214. package/dist/operators/index.js +0 -325
  215. package/dist/types.d.ts +0 -19
  216. package/dist/types.js +0 -1
@@ -0,0 +1,71 @@
1
+ /**
2
+ * Converts a string to camel case: the words of {@link words}, without apostrophes, the first
3
+ * lowercased and each later one with its first code point uppercased.
4
+ * @param s The string to convert.
5
+ * @returns The camel-cased string.
6
+ * @example
7
+ * ```ts
8
+ * camelCase('Foo Bar') // 'fooBar'
9
+ * camelCase('--foo-bar--') // 'fooBar'
10
+ * ```
11
+ */
12
+ export declare function camelCase(s: unknown): string;
13
+ /**
14
+ * Converts a string to Pascal case: as {@link camelCase}, with the first word capitalized too.
15
+ * Each first code point is uppercased, as lodash's `upperFirst` does, not titlecased: `džemal`
16
+ * becomes `DŽemal`.
17
+ * @param s The string to convert.
18
+ * @returns The Pascal-cased string.
19
+ * @example
20
+ * ```ts
21
+ * pascalCase('foo bar') // 'FooBar'
22
+ * ```
23
+ */
24
+ export declare function pascalCase(s: unknown): string;
25
+ /**
26
+ * Converts a string to snake case: the lowercased words joined with `_`.
27
+ * @param s The string to convert.
28
+ * @returns The snake-cased string.
29
+ * @example
30
+ * ```ts
31
+ * snakeCase('fooBar') // 'foo_bar'
32
+ * ```
33
+ */
34
+ export declare function snakeCase(s: unknown): string;
35
+ /**
36
+ * Converts a string to kebab case: the lowercased words joined with `-`.
37
+ * @param s The string to convert.
38
+ * @returns The kebab-cased string.
39
+ * @example
40
+ * ```ts
41
+ * kebabCase('fooBar') // 'foo-bar'
42
+ * ```
43
+ */
44
+ export declare function kebabCase(s: unknown): string;
45
+ /**
46
+ * Converts a string to start case: the words joined with spaces, each with its first code point
47
+ * uppercased and the rest kept, as lodash does. Uppercased, not titlecased: `džemal` becomes
48
+ * `DŽemal`, where {@link capitalize} gives `Džemal`.
49
+ * @param s The string to convert.
50
+ * @returns The start-cased string.
51
+ * @example
52
+ * ```ts
53
+ * startCase('--foo-bar--') // 'Foo Bar'
54
+ * startCase('fooBar') // 'Foo Bar'
55
+ * startCase('__FOO_BAR__') // 'FOO BAR'
56
+ * ```
57
+ */
58
+ export declare function startCase(s: unknown): string;
59
+ /**
60
+ * Converts the first code point to Unicode title case and the rest to lower case. Digraphs take
61
+ * their titlecase form (`dž` becomes `Dž`), and a final sigma lowercases in context. The mapping is
62
+ * the locale-independent Unicode default, so the result is the same on every host.
63
+ * @param s The string to capitalize.
64
+ * @returns The capitalized string.
65
+ * @example
66
+ * ```ts
67
+ * capitalize('FRED') // 'Fred'
68
+ * capitalize('džemal') // 'Džemal'
69
+ * ```
70
+ */
71
+ export declare function capitalize(s: unknown): string;
@@ -0,0 +1,152 @@
1
+ import { toText } from '../internal/text.js';
2
+ import { words } from './words.js';
3
+ /** The words of `s` without apostrophes, as lodash's compound converters read them. */
4
+ function toParts(s) {
5
+ return words(s).map((w) => w.replace(/['’]/g, ''));
6
+ }
7
+ /** The lowercased words of `s` joined with `separator`. */
8
+ function joinLower(s, separator) {
9
+ return toParts(s)
10
+ .map((w) => w.toLowerCase())
11
+ .join(separator);
12
+ }
13
+ /** Uppercases the part's first code point and lowercases the rest, so `dž` and `İ` stay one letter. */
14
+ function upperFirstLowerRest(part) {
15
+ const [first = ''] = part;
16
+ return first.toUpperCase() + part.toLowerCase().slice(first.toLowerCase().length);
17
+ }
18
+ /**
19
+ * Converts a string to camel case: the words of {@link words}, without apostrophes, the first
20
+ * lowercased and each later one with its first code point uppercased.
21
+ * @param s The string to convert.
22
+ * @returns The camel-cased string.
23
+ * @example
24
+ * ```ts
25
+ * camelCase('Foo Bar') // 'fooBar'
26
+ * camelCase('--foo-bar--') // 'fooBar'
27
+ * ```
28
+ */
29
+ export function camelCase(s) {
30
+ return toParts(s)
31
+ .map((w, i) => (i === 0 ? w.toLowerCase() : upperFirstLowerRest(w)))
32
+ .join('');
33
+ }
34
+ /**
35
+ * Converts a string to Pascal case: as {@link camelCase}, with the first word capitalized too.
36
+ * Each first code point is uppercased, as lodash's `upperFirst` does, not titlecased: `džemal`
37
+ * becomes `DŽemal`.
38
+ * @param s The string to convert.
39
+ * @returns The Pascal-cased string.
40
+ * @example
41
+ * ```ts
42
+ * pascalCase('foo bar') // 'FooBar'
43
+ * ```
44
+ */
45
+ export function pascalCase(s) {
46
+ return toParts(s).map(upperFirstLowerRest).join('');
47
+ }
48
+ /**
49
+ * Converts a string to snake case: the lowercased words joined with `_`.
50
+ * @param s The string to convert.
51
+ * @returns The snake-cased string.
52
+ * @example
53
+ * ```ts
54
+ * snakeCase('fooBar') // 'foo_bar'
55
+ * ```
56
+ */
57
+ export function snakeCase(s) {
58
+ return joinLower(s, '_');
59
+ }
60
+ /**
61
+ * Converts a string to kebab case: the lowercased words joined with `-`.
62
+ * @param s The string to convert.
63
+ * @returns The kebab-cased string.
64
+ * @example
65
+ * ```ts
66
+ * kebabCase('fooBar') // 'foo-bar'
67
+ * ```
68
+ */
69
+ export function kebabCase(s) {
70
+ return joinLower(s, '-');
71
+ }
72
+ /**
73
+ * Converts a string to start case: the words joined with spaces, each with its first code point
74
+ * uppercased and the rest kept, as lodash does. Uppercased, not titlecased: `džemal` becomes
75
+ * `DŽemal`, where {@link capitalize} gives `Džemal`.
76
+ * @param s The string to convert.
77
+ * @returns The start-cased string.
78
+ * @example
79
+ * ```ts
80
+ * startCase('--foo-bar--') // 'Foo Bar'
81
+ * startCase('fooBar') // 'Foo Bar'
82
+ * startCase('__FOO_BAR__') // 'FOO BAR'
83
+ * ```
84
+ */
85
+ export function startCase(s) {
86
+ return toParts(s)
87
+ .map((part) => {
88
+ const [first = ''] = part;
89
+ return first.toUpperCase() + part.slice(first.length);
90
+ })
91
+ .join(' ');
92
+ }
93
+ /** Unicode titlecase forms, keyed by lowercase, that no uppercase or range rule can derive. */
94
+ const TITLECASE_FIRST = Object.freeze({
95
+ '\u0149': '\u02BCN',
96
+ '\u01C6': '\u01C5',
97
+ '\u01C9': '\u01C8',
98
+ '\u01CC': '\u01CB',
99
+ '\u01F3': '\u01F2',
100
+ '\u1FB2': '\u1FBA\u0345',
101
+ '\u1FB3': '\u1FBC',
102
+ '\u1FB4': '\u0386\u0345',
103
+ '\u1FB7': '\u0391\u0342\u0345',
104
+ '\u1FC2': '\u1FCA\u0345',
105
+ '\u1FC3': '\u1FCC',
106
+ '\u1FC4': '\u0389\u0345',
107
+ '\u1FC7': '\u0397\u0342\u0345',
108
+ '\u1FF2': '\u1FFA\u0345',
109
+ '\u1FF3': '\u1FFC',
110
+ '\u1FF4': '\u038F\u0345',
111
+ '\u1FF7': '\u03A9\u0342\u0345'
112
+ });
113
+ /** Georgian Mkhedruli has an uppercase (Mtavruli), but a letter's titlecase is itself. */
114
+ const IS_MKHEDRULI = /^[\u10D0-\u10FF]$/;
115
+ /** Greek letters with ypogegrammeni (U+1F80-U+1FAF): each titlecase form is the lowercase plus 8. */
116
+ const YPOGEGRAMMENI_FIRST = 0x1f80;
117
+ const YPOGEGRAMMENI_LAST = 0x1faf;
118
+ const YPOGEGRAMMENI_TITLECASE_OFFSET = 8;
119
+ function titleCaseFirstChar(ch) {
120
+ if (IS_MKHEDRULI.test(ch))
121
+ return ch;
122
+ const lower = ch.toLowerCase();
123
+ const listed = TITLECASE_FIRST[lower];
124
+ if (listed !== undefined)
125
+ return listed;
126
+ const cp = lower.codePointAt(0);
127
+ if (cp !== undefined && cp >= YPOGEGRAMMENI_FIRST && cp <= YPOGEGRAMMENI_LAST) {
128
+ return String.fromCodePoint(cp + YPOGEGRAMMENI_TITLECASE_OFFSET);
129
+ }
130
+ const upper = ch.toUpperCase();
131
+ // Multi-char uppercase (e.g. ß -> SS): titlecase is first upper + rest lower.
132
+ return upper.length > 1 ? upper[0] + upper.slice(1).toLowerCase() : upper;
133
+ }
134
+ /**
135
+ * Converts the first code point to Unicode title case and the rest to lower case. Digraphs take
136
+ * their titlecase form (`dž` becomes `Dž`), and a final sigma lowercases in context. The mapping is
137
+ * the locale-independent Unicode default, so the result is the same on every host.
138
+ * @param s The string to capitalize.
139
+ * @returns The capitalized string.
140
+ * @example
141
+ * ```ts
142
+ * capitalize('FRED') // 'Fred'
143
+ * capitalize('džemal') // 'Džemal'
144
+ * ```
145
+ */
146
+ export function capitalize(s) {
147
+ const text = toText(s);
148
+ const [first = ''] = text;
149
+ // Lowercasing the whole string lets a final sigma see the letter before it.
150
+ const rest = text.toLowerCase().slice(first.toLowerCase().length);
151
+ return `${titleCaseFirstChar(first)}${rest}`;
152
+ }
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Removes accents from Latin letters with a subset of the Unicode CLDR Latin-ASCII transform:
3
+ * combining marks after Latin letters and digits, and the common letter folds (`ß` to `ss`,
4
+ * `Æ` to `AE`, `ø` to `o`). Marks on other scripts and variation selectors stay (`й`, `が`,
5
+ * `1️⃣`), the result is NFC, and a run of marks is cut to 30 so normalizing stays linear.
6
+ * @param s The string to fold.
7
+ * @returns The folded string.
8
+ * @example
9
+ * ```ts
10
+ * deburr('déjà vu') // 'deja vu'
11
+ * deburr('Œuvre ß ø') // 'OEuvre ss o'
12
+ * ```
13
+ */
14
+ export declare function deburr(s: unknown): string;
15
+ /** Options for {@link slugify}. */
16
+ export interface SlugifyOptions {
17
+ /** Lowercase the slug (default `true`); `false` keeps the case of the input. */
18
+ lower?: boolean;
19
+ }
20
+ /**
21
+ * Returns a URL slug: {@link deburr}, lowercased unless `lower` is `false`, default-ignorable
22
+ * code points (soft hyphen, ZWNJ, variation selectors, Hangul fillers) and apostrophes inside
23
+ * words dropped, then runs of Unicode letters, marks and digits joined with `-`. Letters of other
24
+ * scripts stay.
25
+ * @param s The string to slugify.
26
+ * @param options `lower`.
27
+ * @returns The slug.
28
+ * @example
29
+ * ```ts
30
+ * slugify('Antoine de Saint-Exupéry') // 'antoine-de-saint-exupery'
31
+ * slugify("Don't Stop", { lower: false }) // 'Dont-Stop'
32
+ * slugify('Café Привет') // 'cafe-привет'
33
+ * ```
34
+ */
35
+ export declare function slugify(s: unknown, options?: SlugifyOptions): string;
@@ -0,0 +1,100 @@
1
+ import { isAsciiString, toText } from '../internal/text.js';
2
+ /** Letter folds from a subset of the Unicode CLDR Latin-ASCII transform. */
3
+ const CLDR_LATIN_ASCII_FOLDS = Object.freeze({
4
+ '\u00C6': 'AE',
5
+ '\u00D0': 'D',
6
+ '\u00D8': 'O',
7
+ '\u00DE': 'TH',
8
+ '\u00DF': 'ss',
9
+ '\u00E6': 'ae',
10
+ '\u00F0': 'd',
11
+ '\u00F8': 'o',
12
+ '\u00FE': 'th',
13
+ '\u0110': 'D',
14
+ '\u0111': 'd',
15
+ '\u0126': 'H',
16
+ '\u0127': 'h',
17
+ '\u0131': 'i',
18
+ '\u0132': 'IJ',
19
+ '\u0133': 'ij',
20
+ '\u0138': 'q',
21
+ '\u013F': 'L',
22
+ '\u0140': 'l',
23
+ '\u0141': 'L',
24
+ '\u0142': 'l',
25
+ '\u0149': "'n",
26
+ '\u014A': 'N',
27
+ '\u014B': 'n',
28
+ '\u0152': 'OE',
29
+ '\u0153': 'oe',
30
+ '\u0166': 'T',
31
+ '\u0167': 't',
32
+ '\u017F': 's',
33
+ '\u1E9E': 'SS'
34
+ });
35
+ /**
36
+ * A run of more than 30 marks, past the UAX #15 Stream-Safe limit that keeps `normalize` linear.
37
+ * Matched from the start of the run only, so each mark is read once.
38
+ */
39
+ const EXCESS_MARKS = /(?<!\p{M})(\p{M}{30})\p{M}+/gu;
40
+ /** One forward pass, so a long run of marks after another script is never rescanned. */
41
+ const MARK_RUN_AFTER_LATIN = /(?<=[\p{Script=Latin}0-9])\p{Mn}+/gu;
42
+ /** Variation selectors are Mn but pick a presentation, such as VS16 in the keycap `1️⃣`. */
43
+ const NOT_VARIATION_SELECTOR = /\P{Variation_Selector}/gu;
44
+ const FOLDABLE_LETTER = /[\u00C6-\u017F\u1E9E]/g;
45
+ /**
46
+ * Removes accents from Latin letters with a subset of the Unicode CLDR Latin-ASCII transform:
47
+ * combining marks after Latin letters and digits, and the common letter folds (`ß` to `ss`,
48
+ * `Æ` to `AE`, `ø` to `o`). Marks on other scripts and variation selectors stay (`й`, `が`,
49
+ * `1️⃣`), the result is NFC, and a run of marks is cut to 30 so normalizing stays linear.
50
+ * @param s The string to fold.
51
+ * @returns The folded string.
52
+ * @example
53
+ * ```ts
54
+ * deburr('déjà vu') // 'deja vu'
55
+ * deburr('Œuvre ß ø') // 'OEuvre ss o'
56
+ * ```
57
+ */
58
+ export function deburr(s) {
59
+ const text = toText(s);
60
+ if (isAsciiString(text))
61
+ return text;
62
+ return text
63
+ .replace(EXCESS_MARKS, '$1')
64
+ .normalize('NFD')
65
+ .replace(MARK_RUN_AFTER_LATIN, (marks) => marks.replace(NOT_VARIATION_SELECTOR, ''))
66
+ .normalize('NFC')
67
+ .replace(FOLDABLE_LETTER, (ch) => CLDR_LATIN_ASCII_FOLDS[ch] ?? ch);
68
+ }
69
+ /** Bounded so a long two-byte run cannot overflow the regexp stack; `-+` merges the chunks. */
70
+ const SEPARATORS = /[^\p{L}\p{M}\p{N}]{1,1024}/gu;
71
+ /** Invisible, so dropped as UTS #46 drops them: no word splits on one and no slug hides one. */
72
+ const DEFAULT_IGNORABLE = /\p{Default_Ignorable_Code_Point}/gu;
73
+ /** Mark runs are cut to 30 by {@link deburr}, so the lookbehind stays bounded. */
74
+ const MID_WORD_APOSTROPHE = /(?<=[\p{L}\p{N}]\p{M}*)['\u2019](?=[\p{L}\p{N}])/gu;
75
+ const ORPHAN_MARKS = /(^|-)\p{M}+/gu;
76
+ /**
77
+ * Returns a URL slug: {@link deburr}, lowercased unless `lower` is `false`, default-ignorable
78
+ * code points (soft hyphen, ZWNJ, variation selectors, Hangul fillers) and apostrophes inside
79
+ * words dropped, then runs of Unicode letters, marks and digits joined with `-`. Letters of other
80
+ * scripts stay.
81
+ * @param s The string to slugify.
82
+ * @param options `lower`.
83
+ * @returns The slug.
84
+ * @example
85
+ * ```ts
86
+ * slugify('Antoine de Saint-Exupéry') // 'antoine-de-saint-exupery'
87
+ * slugify("Don't Stop", { lower: false }) // 'Dont-Stop'
88
+ * slugify('Café Привет') // 'cafe-привет'
89
+ * ```
90
+ */
91
+ export function slugify(s, options) {
92
+ const folded = deburr(s);
93
+ return (options?.lower === false ? folded : folded.toLowerCase())
94
+ .replace(DEFAULT_IGNORABLE, '')
95
+ .replace(MID_WORD_APOSTROPHE, '')
96
+ .replace(SEPARATORS, '-')
97
+ .replace(ORPHAN_MARKS, '$1')
98
+ .replace(/-+/g, '-')
99
+ .replace(/^-|-$/g, '');
100
+ }
@@ -1,190 +1,9 @@
1
1
  /**
2
- * This module includes utilities for working with strings.
3
- *
2
+ * String helpers: `words`, the case converters `camelCase`, `pascalCase`, `snakeCase`,
3
+ * `kebabCase`, `startCase` and `capitalize`, and `deburr`, `slugify` and `truncate`.
4
4
  * @module string
5
5
  */
6
- /**
7
- * Converts only the first character of the given string to upper case. Note that the rest of the characters are preserved.
8
- * @param {string} s The string
9
- * @returns {string} Returns the sentence string.
10
- * @example
11
- ```js
12
- sentenceCase('a test')
13
- // 'A test'
14
-
15
- sentenceCase('TEST')
16
- // 'TEST'
17
- ```
18
- * @see {@link capitalize}
19
- */
20
- export declare function sentenceCase(s: string): string;
21
- /**
22
- * Converts the first character of the given string to upper case and the rest to lower case.
23
- * @param {string} s The string to capitalize
24
- * @returns {string} Returns the capitalized string.
25
- * @example
26
- ```js
27
- capitalize('TEST')
28
- // 'Test'
29
- ```
30
- * @see {@link titleCase}
31
- */
32
- export declare function capitalize(s: string): string;
33
- /**
34
- * Split a string into an array of its words.
35
- * @param {string} s The string to split
36
- * @param {RegExp | string} [pattern] The separator to split on, instead of matching words
37
- * @returns {string[]} Returns the words array.
38
- * @example
39
- ```js
40
- words('lord of the rings')
41
- // ['lord', 'of', 'the', 'rings']
42
- ```
43
- */
44
- export declare function words(s: string, pattern?: RegExp | string): string[];
45
- /**
46
- * Create a new string which is the concatenation of the words in the given input.
47
- * @param {string} s The string to join
48
- * @param {string} [sep=' '] The separator to use
49
- * @returns {string} Returns the joined string.
50
- * @example
51
- ```js
52
- join('Lord Of The Rings', '-')
53
- // 'Lord-Of-The-Rings'
54
- ```
55
- */
56
- export declare function join(s: string, sep?: string): string;
57
- /**
58
- * Checks if a string contains only alphanumeric characters.
59
- * @param {string} s The string
60
- * @returns {boolean} Returns `true` if the string contains only alphanumeric.
61
- * @example
62
- ```js
63
- isAlnum('alpha1234')
64
- // true
65
-
66
- isAlnum('oops!')
67
- // false
68
- ```
69
- */
70
- export declare function isAlnum(s: string): boolean;
71
- /**
72
- * Checks if a string contains only alphabetic characters.
73
- * @param {string} s The string
74
- * @returns {boolean} Returns `true` if the string contains only alphabetic.
75
- * @example
76
- ```js
77
- isAlpha('alpha1234')
78
- // false
79
-
80
- isAlpha('letters')
81
- // true
82
- ```
83
- */
84
- export declare function isAlpha(s: string): boolean;
85
- /**
86
- * Checks if a string contains only numeric characters.
87
- * @param {string} s The string
88
- * @returns {boolean} Returns `true` if the string contains only numeric.
89
- * @example
90
- ```js
91
- isNumeric('alpha1234')
92
- // false
93
-
94
- isNumeric('1234')
95
- // true
96
- ```
97
- */
98
- export declare function isNumeric(s: string): boolean;
99
- /**
100
- * Returns a new string with only valid ASCII characters
101
- * @param {string} s The string
102
- * @returns {string} The ASCII characters in the given string
103
- * @example
104
- ```js
105
- asciify('äÄçÇéÉêPHP-MySQLöÖÐþúÚ')
106
- // 'PHP-MySQL'
107
- ```
108
- */
109
- export declare function asciify(s: string): string;
110
- /**
111
- * Replaces any accent characters in the string with non accents.
112
- * @param {string} s The string
113
- * @returns {string} The new string without accents
114
- * @example
115
- ```js
116
- removeAccents('Antoine de Saint-Exupéry')
117
- // 'Antoine de Saint-Exupery'
118
- ```
119
- */
120
- export declare function removeAccents(s: string): string;
121
- /**
122
- * Capitalizes the first letter of every word in the string.
123
- * @param {string} s The string to capitalize
124
- * @returns {string} Returns the title cased string.
125
- * @example
126
- ```js
127
- titleCase('lord of the rings')
128
- // 'Lord Of The Rings'
129
- ```
130
- @see {@link capitalize}
131
- */
132
- export declare function titleCase(s: string): string;
133
- /**
134
- * Converts the string to camel case.
135
- * @param {string} s The string to convert
136
- * @returns {string} Returns the camel cased string.
137
- * @example
138
- ```js
139
- camelCase('Equipment class name')
140
- // 'equipmentClassName'
141
- ```
142
- */
143
- export declare function camelCase(s: string): string;
144
- /**
145
- * Converts the string to Pascal case.
146
- * @param {string} s The string to convert
147
- * @returns {string} Returns the Pascal cased string.
148
- * @example
149
- ```js
150
- pascalCase('equipment class name')
151
- // 'EquipmentClassName'
152
- ```
153
- */
154
- export declare function pascalCase(s: string): string;
155
- /**
156
- * Converts the string to snake case.
157
- * @param {string} s The string to convert
158
- * @returns {string} Returns the snake cased string.
159
- * @example
160
- ```js
161
- snakeCase('Equipment Class Name')
162
- // 'equipment_class_name'
163
- ```
164
- */
165
- export declare function snakeCase(s: string): string;
166
- /**
167
- * Converts a string to kebab case.
168
- * @param {string} s The string
169
- * @returns {string} Returns the kebab cased string.
170
- * @example
171
- ```js
172
- kebabCase('Equipment Class Name')
173
- // 'equipment-class-name'
174
-
175
- kebabCase('equipment_class_name')
176
- // 'equipment-class-name'
177
- ```
178
- */
179
- export declare function kebabCase(s: string): string;
180
- /**
181
- * Returns a url-safe slug for the given string. Note that by default it will preserve any capitalization in the given string.
182
- * @param {string} s The string
183
- * @returns {string} A url-safe slug version of the string
184
- * @example
185
- ```js
186
- slugify('Antoine de Saint-Exupéry')
187
- // 'Antoine-de-Saint-Exupery'
188
- ```
189
- */
190
- export declare function slugify(s: string): string;
6
+ export { camelCase, capitalize, kebabCase, pascalCase, snakeCase, startCase } from './case.js';
7
+ export { deburr, type SlugifyOptions, slugify } from './fold.js';
8
+ export { type TruncateOptions, truncate } from './truncate.js';
9
+ export { words } from './words.js';