@oscarpalmer/atoms 0.193.0 → 0.194.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 (204) hide show
  1. package/dist/array/difference.mjs +2 -2
  2. package/dist/array/intersection.mjs +2 -2
  3. package/dist/array/match.mjs +13 -13
  4. package/dist/array/slice.mjs +5 -5
  5. package/dist/array/sort.d.mts +5 -1
  6. package/dist/array/sort.mjs +4 -2
  7. package/dist/array/union.mjs +2 -2
  8. package/dist/beacon.d.mts +8 -1
  9. package/dist/beacon.mjs +52 -60
  10. package/dist/color/constants.d.mts +1 -1
  11. package/dist/color/constants.mjs +3 -5
  12. package/dist/color/instance.mjs +34 -41
  13. package/dist/color/misc/format.d.mts +3 -2
  14. package/dist/color/misc/format.mjs +4 -1
  15. package/dist/color/misc/is.d.mts +9 -1
  16. package/dist/color/misc/is.mjs +11 -1
  17. package/dist/color/misc/state.d.mts +6 -6
  18. package/dist/color/misc/state.mjs +11 -14
  19. package/dist/color/models.d.mts +23 -68
  20. package/dist/function/assert.mjs +2 -2
  21. package/dist/function/limit.d.mts +0 -6
  22. package/dist/function/limit.mjs +2 -2
  23. package/dist/function/memoize.mjs +19 -32
  24. package/dist/function/once.d.mts +0 -3
  25. package/dist/function/once.mjs +16 -13
  26. package/dist/function/retry.d.mts +1 -24
  27. package/dist/function/retry.mjs +1 -1
  28. package/dist/function/work.mjs +13 -11
  29. package/dist/herald.d.mts +30 -31
  30. package/dist/herald.mjs +74 -56
  31. package/dist/index.d.mts +100 -185
  32. package/dist/index.mjs +680 -702
  33. package/dist/internal/abort.d.mts +10 -0
  34. package/dist/internal/abort.mjs +14 -0
  35. package/dist/internal/array/chunk.mjs +2 -2
  36. package/dist/internal/array/find.mjs +2 -2
  37. package/dist/internal/array/sets.d.mts +4 -4
  38. package/dist/internal/array/sets.mjs +7 -7
  39. package/dist/internal/function/timer.mjs +19 -15
  40. package/dist/internal/number.mjs +7 -7
  41. package/dist/internal/result.mjs +3 -3
  42. package/dist/internal/sized.mjs +4 -4
  43. package/dist/internal/string.mjs +4 -4
  44. package/dist/internal/subscription.d.mts +24 -8
  45. package/dist/internal/subscription.mjs +49 -36
  46. package/dist/internal/value/equal.mjs +6 -6
  47. package/dist/internal/value/misc.mjs +14 -14
  48. package/dist/internal/value/set.mjs +2 -2
  49. package/dist/logger.mjs +15 -39
  50. package/dist/promise/constants.d.mts +17 -0
  51. package/dist/promise/constants.mjs +14 -0
  52. package/dist/promise/delay.mjs +7 -10
  53. package/dist/promise/helpers.mjs +1 -1
  54. package/dist/promise/index.mjs +14 -17
  55. package/dist/promise/misc.d.mts +2 -1
  56. package/dist/promise/misc.mjs +8 -7
  57. package/dist/promise/models.d.mts +4 -16
  58. package/dist/promise/models.mjs +4 -13
  59. package/dist/promise/timed.mjs +9 -10
  60. package/dist/query.mjs +15 -15
  61. package/dist/queue.mjs +103 -116
  62. package/dist/random.mjs +7 -7
  63. package/dist/result/index.d.mts +0 -3
  64. package/dist/result/index.mjs +1 -1
  65. package/dist/result/match.d.mts +0 -3
  66. package/dist/result/match.mjs +4 -4
  67. package/dist/result/misc.mjs +2 -2
  68. package/dist/result/work/flow.d.mts +0 -3
  69. package/dist/result/work/flow.mjs +5 -5
  70. package/dist/result/work/pipe.d.mts +0 -3
  71. package/dist/result/work/pipe.mjs +3 -3
  72. package/dist/string/case.mjs +20 -20
  73. package/dist/string/fuzzy.mjs +23 -18
  74. package/dist/string/index.mjs +7 -7
  75. package/dist/string/normalize.mjs +14 -14
  76. package/dist/string/template.mjs +2 -2
  77. package/dist/value/clone.mjs +10 -10
  78. package/dist/value/smush.mjs +2 -2
  79. package/package.json +13 -5
  80. package/src/array/difference.ts +0 -73
  81. package/src/array/exists.ts +0 -93
  82. package/src/array/filter.ts +0 -182
  83. package/src/array/find.ts +0 -183
  84. package/src/array/first.ts +0 -196
  85. package/src/array/flatten.ts +0 -20
  86. package/src/array/from.ts +0 -129
  87. package/src/array/get.ts +0 -131
  88. package/src/array/group-by.ts +0 -369
  89. package/src/array/index.ts +0 -26
  90. package/src/array/insert.ts +0 -52
  91. package/src/array/intersection.ts +0 -72
  92. package/src/array/last.ts +0 -194
  93. package/src/array/match.ts +0 -436
  94. package/src/array/move.ts +0 -315
  95. package/src/array/partition.ts +0 -91
  96. package/src/array/push.ts +0 -23
  97. package/src/array/reverse.ts +0 -33
  98. package/src/array/select.ts +0 -260
  99. package/src/array/single.ts +0 -93
  100. package/src/array/slice.ts +0 -335
  101. package/src/array/sort.ts +0 -607
  102. package/src/array/splice.ts +0 -106
  103. package/src/array/swap.ts +0 -322
  104. package/src/array/to-map.ts +0 -371
  105. package/src/array/to-record.ts +0 -351
  106. package/src/array/to-set.ts +0 -80
  107. package/src/array/toggle.ts +0 -79
  108. package/src/array/union.ts +0 -72
  109. package/src/array/unique.ts +0 -67
  110. package/src/array/update.ts +0 -75
  111. package/src/beacon.ts +0 -378
  112. package/src/color/constants.ts +0 -137
  113. package/src/color/index.ts +0 -83
  114. package/src/color/instance.ts +0 -162
  115. package/src/color/misc/alpha.ts +0 -56
  116. package/src/color/misc/format.ts +0 -29
  117. package/src/color/misc/get.ts +0 -210
  118. package/src/color/misc/is.ts +0 -221
  119. package/src/color/misc/state.ts +0 -243
  120. package/src/color/models.ts +0 -389
  121. package/src/color/space/hex.ts +0 -184
  122. package/src/color/space/hsl.ts +0 -174
  123. package/src/color/space/hwb.ts +0 -153
  124. package/src/color/space/rgb.ts +0 -240
  125. package/src/function/assert.ts +0 -174
  126. package/src/function/index.ts +0 -2
  127. package/src/function/limit.ts +0 -83
  128. package/src/function/memoize.ts +0 -202
  129. package/src/function/once.ts +0 -200
  130. package/src/function/retry.ts +0 -175
  131. package/src/function/work.ts +0 -1007
  132. package/src/herald.ts +0 -216
  133. package/src/index.ts +0 -68
  134. package/src/internal/array/callbacks.ts +0 -46
  135. package/src/internal/array/chunk.ts +0 -51
  136. package/src/internal/array/compact.ts +0 -56
  137. package/src/internal/array/find.ts +0 -200
  138. package/src/internal/array/group.ts +0 -42
  139. package/src/internal/array/index-of.ts +0 -182
  140. package/src/internal/array/insert.ts +0 -80
  141. package/src/internal/array/overlap.ts +0 -35
  142. package/src/internal/array/sets.ts +0 -74
  143. package/src/internal/array/shuffle.ts +0 -33
  144. package/src/internal/array/update.ts +0 -52
  145. package/src/internal/function/misc.ts +0 -8
  146. package/src/internal/function/timer.ts +0 -168
  147. package/src/internal/is.ts +0 -244
  148. package/src/internal/math/aggregate.ts +0 -164
  149. package/src/internal/math/misc.ts +0 -28
  150. package/src/internal/number.ts +0 -129
  151. package/src/internal/random.ts +0 -49
  152. package/src/internal/result.ts +0 -92
  153. package/src/internal/sized.ts +0 -25
  154. package/src/internal/string.ts +0 -128
  155. package/src/internal/subscription.ts +0 -264
  156. package/src/internal/value/compare.ts +0 -170
  157. package/src/internal/value/equal.ts +0 -465
  158. package/src/internal/value/get.ts +0 -57
  159. package/src/internal/value/handlers.ts +0 -95
  160. package/src/internal/value/has.ts +0 -118
  161. package/src/internal/value/misc.ts +0 -125
  162. package/src/internal/value/partial.ts +0 -46
  163. package/src/internal/value/set.ts +0 -132
  164. package/src/is.ts +0 -182
  165. package/src/logger.ts +0 -230
  166. package/src/math.ts +0 -281
  167. package/src/models.ts +0 -286
  168. package/src/number.ts +0 -1
  169. package/src/promise/delay.ts +0 -62
  170. package/src/promise/helpers.ts +0 -96
  171. package/src/promise/index.ts +0 -300
  172. package/src/promise/misc.ts +0 -96
  173. package/src/promise/models.ts +0 -195
  174. package/src/promise/timed.ts +0 -91
  175. package/src/query.ts +0 -147
  176. package/src/queue.ts +0 -814
  177. package/src/random.ts +0 -125
  178. package/src/result/index.ts +0 -105
  179. package/src/result/match.ts +0 -124
  180. package/src/result/misc.ts +0 -129
  181. package/src/result/models.ts +0 -83
  182. package/src/result/work/flow.ts +0 -488
  183. package/src/result/work/pipe.ts +0 -496
  184. package/src/sized/map.ts +0 -110
  185. package/src/sized/set.ts +0 -107
  186. package/src/string/case.ts +0 -236
  187. package/src/string/fuzzy.ts +0 -444
  188. package/src/string/index.ts +0 -199
  189. package/src/string/match.ts +0 -80
  190. package/src/string/normalize.ts +0 -205
  191. package/src/string/template.ts +0 -161
  192. package/src/value/clone.ts +0 -319
  193. package/src/value/collection.ts +0 -63
  194. package/src/value/diff.ts +0 -232
  195. package/src/value/freeze.ts +0 -322
  196. package/src/value/handle.ts +0 -3
  197. package/src/value/index.ts +0 -5
  198. package/src/value/merge.ts +0 -278
  199. package/src/value/omit.ts +0 -20
  200. package/src/value/pick.ts +0 -20
  201. package/src/value/shake.ts +0 -45
  202. package/src/value/smush.ts +0 -89
  203. package/src/value/transform.ts +0 -153
  204. package/src/value/unsmush.ts +0 -84
@@ -1,199 +0,0 @@
1
- import {isTemplateStringsArray} from '../internal/is';
2
- import {interpolate} from '../internal/string';
3
-
4
- // #region Functions
5
-
6
- /**
7
- * Dedent a string template, removing common leading whitespace from each line
8
- *
9
- * @returns Dedented string
10
- */
11
- export function dedent(strings: TemplateStringsArray, ...values: unknown[]): string;
12
-
13
- /**
14
- * Dedent a string, removing common leading whitespace from each line
15
- *
16
- * @param value String to dedent
17
- * @returns Dedented string
18
- */
19
- export function dedent(value: string): string;
20
-
21
- export function dedent(value: string | TemplateStringsArray, ...values: unknown[]): string {
22
- let actual: string;
23
-
24
- if (isTemplateStringsArray(value)) {
25
- actual = interpolate(value, values);
26
- } else {
27
- actual = value;
28
- }
29
-
30
- if (typeof actual !== 'string') {
31
- return '';
32
- }
33
-
34
- const lines = actual.split('\n');
35
- const {length} = lines;
36
-
37
- if (length === 1) {
38
- return actual.trim();
39
- }
40
-
41
- const lastIndex = length - 1;
42
-
43
- const lengths: number[] = [];
44
-
45
- for (let index = 0; index < length; index += 1) {
46
- const [, indentation] = /^(\s+)/.exec(lines[index]) ?? [];
47
-
48
- if (indentation != null) {
49
- lengths.push(indentation.length);
50
- }
51
- }
52
-
53
- if (lengths.length === 0) {
54
- return actual.trim();
55
- }
56
-
57
- const minimum = Math.min(...lengths);
58
-
59
- const pattern = new RegExp(`^\\s{0,${minimum}}`);
60
-
61
- let result = '';
62
-
63
- for (let index = 0; index < length; index += 1) {
64
- const line = lines[index];
65
-
66
- result += line.replace(pattern, '') + (index === lastIndex ? '' : '\n');
67
- }
68
-
69
- return result.trim();
70
- }
71
-
72
- /**
73
- * Get a new UUID string _(version 4)_ for use in _HTML_
74
- *
75
- * @param html Use _HTML_-friendly format
76
- * @returns UUID string
77
- */
78
- export function getUuid(html: true): string;
79
-
80
- /**
81
- * Get a new UUID string _(version 4)_
82
- *
83
- * @returns UUID string
84
- */
85
- export function getUuid(): string;
86
-
87
- /**
88
- * Get a new UUID string _(version 4)_
89
- *
90
- * @returns UUID string
91
- */
92
- export function getUuid(html?: unknown): string {
93
- const forHTML = html === true;
94
-
95
- while (true) {
96
- const bytes = new Uint8Array(16);
97
-
98
- crypto.getRandomValues(bytes);
99
-
100
- bytes[6] = (bytes[6] & 0x0f) | 0x40;
101
-
102
- bytes[8] = (bytes[8] & 0x3f) | 0x80;
103
-
104
- const hex = Array.from(bytes, byte => byte.toString(16).padStart(2, ZERO)).join('');
105
-
106
- const first = hex.substring(0, 8);
107
-
108
- if (forHTML && NUMERICAL_PREFIX_PATTERN.test(first)) {
109
- continue;
110
- }
111
-
112
- return [
113
- first,
114
- hex.substring(8, 12),
115
- hex.substring(12, 16),
116
- hex.substring(16, 20),
117
- hex.substring(20, 32),
118
- ].join(forHTML ? DELIMITER_UUID_HTML : DELIMITER_UUID_DEFAULT);
119
- }
120
- }
121
-
122
- /**
123
- * Parse a JSON string into its proper value _(or `undefined` if it fails)_
124
- *
125
- * @param value JSON string to parse
126
- * @param reviver Reviver function to transform the parsed values
127
- * @returns Parsed value or `undefined` if parsing fails
128
- */
129
- export function parse(
130
- value: string,
131
- reviver?: (this: unknown, key: string, value: unknown) => unknown,
132
- ): unknown {
133
- try {
134
- return JSON.parse(value, reviver);
135
- } catch {
136
- return undefined;
137
- }
138
- }
139
-
140
- /**
141
- * Trim a string _(removing whitespace from both ends)_
142
- *
143
- * @param value String to trim
144
- * @returns Trimmed string
145
- */
146
- export function trim(value: string): string {
147
- return typeof value === 'string' ? value.trim() : '';
148
- }
149
-
150
- /**
151
- * Truncate a string to a specified length
152
- *
153
- * @param value String to truncate
154
- * @param length Maximum length of the string after truncation
155
- * @param suffix Suffix to append to the truncated string
156
- * @returns Truncated string
157
- */
158
- export function truncate(value: string, length: number, suffix?: string): string {
159
- if (typeof value !== 'string' || typeof length !== 'number' || length === 0) {
160
- return '';
161
- }
162
-
163
- if (length >= value.length) {
164
- return value;
165
- }
166
-
167
- const actualSuffix = typeof suffix === 'string' ? suffix : '';
168
- const actualSuffixLength = actualSuffix.length;
169
-
170
- if (length <= actualSuffixLength) {
171
- return actualSuffix;
172
- }
173
-
174
- const truncatedLength = length - actualSuffixLength;
175
-
176
- return `${value.slice(0, truncatedLength)}${actualSuffix}`;
177
- }
178
-
179
- // #endregion
180
-
181
- // #region Variables
182
-
183
- const DELIMITER_UUID_DEFAULT = '-';
184
-
185
- const DELIMITER_UUID_HTML = '_';
186
-
187
- const NUMERICAL_PREFIX_PATTERN = /^\d/;
188
-
189
- const ZERO = '0';
190
-
191
- // #endregion
192
-
193
- // #endregion
194
-
195
- // #region Exports
196
-
197
- export {getString, join, words} from '../internal/string';
198
-
199
- // #endregion
@@ -1,80 +0,0 @@
1
- import {memoize, type Memoized} from '../function/memoize';
2
-
3
- // #region Types
4
-
5
- type Match = 'endsWith' | 'includes' | 'startsWith';
6
-
7
- // #endregion
8
-
9
- // #region Functions
10
-
11
- /**
12
- * Check if a string ends with a specified substring
13
- *
14
- * @param haystack String to look in
15
- * @param needle String to look for
16
- * @param ignoreCase Ignore case when matching? _(defaults to `false`)_
17
- * @returns `true` if the string ends with the given substring, otherwise `false`
18
- */
19
- export function endsWith(haystack: string, needle: string, ignoreCase?: boolean): boolean {
20
- return match(MATCH_ENDS_WITH, haystack, needle, ignoreCase === true);
21
- }
22
-
23
- /**
24
- * Check if a string includes a specified substring
25
- *
26
- * @param haystack String to look in
27
- * @param needle String to look for
28
- * @param ignoreCase Ignore case when matching? _(defaults to `false`)_
29
- * @returns `true` if the string includes the given substring, otherwise `false`
30
- */
31
- export function includes(haystack: string, needle: string, ignoreCase?: boolean): boolean {
32
- return match(MATCH_INCLUDES, haystack, needle, ignoreCase === true);
33
- }
34
-
35
- function match(type: Match, haystack: string, needle: string, ignoreCase: boolean): boolean {
36
- if (typeof haystack !== 'string' || typeof needle !== 'string') {
37
- return false;
38
- }
39
-
40
- matchMemoizers[type] ??= memoize(matchCallback.bind(type));
41
-
42
- return matchMemoizers[type].run(haystack, needle, ignoreCase);
43
- }
44
-
45
- function matchCallback(
46
- this: Match,
47
- haystack: string,
48
- needle: string,
49
- ignoreCase: boolean,
50
- ): boolean {
51
- return (ignoreCase ? haystack.toLocaleLowerCase() : haystack)[this](
52
- ignoreCase ? needle.toLocaleLowerCase() : needle,
53
- );
54
- }
55
-
56
- /**
57
- * Check if a string starts with a specified substring
58
- *
59
- * @param haystack String to look in
60
- * @param needle String to look for
61
- * @param ignoreCase Ignore case when matching? _(defaults to `false`)_
62
- * @returns `true` if the string starts with the given substring, otherwise `false`
63
- */
64
- export function startsWith(haystack: string, needle: string, ignoreCase?: boolean): boolean {
65
- return match(MATCH_STARTS_WITH, haystack, needle, ignoreCase === true);
66
- }
67
-
68
- // #endregion
69
-
70
- // #region Variables
71
-
72
- const MATCH_ENDS_WITH: Match = 'endsWith';
73
-
74
- const MATCH_INCLUDES: Match = 'includes';
75
-
76
- const MATCH_STARTS_WITH: Match = 'startsWith';
77
-
78
- const matchMemoizers: Partial<Record<Match, Memoized<typeof matchCallback>>> = {};
79
-
80
- // #endregion
@@ -1,205 +0,0 @@
1
- import {memoize, type Memoized} from '../function/memoize';
2
- import {isPlainObject} from '../internal/is';
3
- import {lowerCase} from './case';
4
-
5
- // #region Types
6
-
7
- /**
8
- * Options for normalizing a string
9
- */
10
- export type NormalizeOptions = {
11
- /**
12
- * Remove diacritical marks from the string? _(defaults to `true`)_
13
- */
14
- deburr?: boolean;
15
- /**
16
- * Convert the string to lower case? _(defaults to `true`)_
17
- */
18
- lowerCase?: boolean;
19
- /**
20
- * Remove special characters from the string? _(defaults to `false`)_
21
- *
22
- * _(Punctuation and symbol characters are considered special)_
23
- */
24
- special?: boolean;
25
- /**
26
- * Trim the string? _(defaults to `true`)_
27
- */
28
- trim?: boolean;
29
- /**
30
- * Shorten consecutive whitespace characters to a single space? _(defaults to `true`)_
31
- */
32
- whitespace?: boolean;
33
- };
34
-
35
- /**
36
- * String normalizer function
37
- */
38
- export type Normalizer = {
39
- /**
40
- * Normalize a string
41
- *
42
- * @param value String to normalize
43
- * @returns Normalized string
44
- */
45
- (value: string): string;
46
- };
47
-
48
- type Options = Required<NormalizeOptions>;
49
-
50
- // #endregion
51
-
52
- // #region Functions
53
-
54
- /**
55
- * Deburr a string, removing diacritical marks
56
- *
57
- * @param value String to deburr
58
- * @returns Deburred string
59
- */
60
- export function deburr(value: string): string {
61
- if (typeof value !== 'string') {
62
- return '';
63
- }
64
-
65
- deburrMemoizer ??= memoize(value => {
66
- let deburred = value.normalize(DEBURR_NORMALIZATION).replace(DEBURR_PATTERN_SIMPLE, '');
67
-
68
- deburred = deburred.replace(
69
- DEBURR_PATTERN_CHARACTERS,
70
- (_, character) => DEBURR_CHARACTERS[character as keyof typeof DEBURR_CHARACTERS],
71
- );
72
-
73
- return deburred;
74
- });
75
-
76
- return deburrMemoizer.run(value);
77
- }
78
-
79
- function getNormalizeOptions(input?: NormalizeOptions): Options {
80
- const options = isPlainObject(input) ? input : {};
81
-
82
- return {
83
- deburr: options.deburr !== false,
84
- lowerCase: options.lowerCase !== false,
85
- special: options.special === true,
86
- trim: options.trim !== false,
87
- whitespace: options.whitespace !== false,
88
- };
89
- }
90
-
91
- /**
92
- * Initialize a string normalizer
93
- *
94
- * _Available as `initializeNormalizer` and `normalize.initialize`_
95
- *
96
- * @param options Normalization options
97
- * @returns Normalizer function
98
- */
99
- export function initializeNormalizer(options?: NormalizeOptions): Normalizer {
100
- const normalization = getNormalizeOptions(options);
101
-
102
- return (value: string) => normalizeString(value, normalization);
103
- }
104
-
105
- /**
106
- * Normalize a string
107
- *
108
- * _By default, the string will be trimmed, deburred, and then lowercased_
109
- *
110
- * @param value String to normalize
111
- * @param options Normalization options
112
- * @returns Normalized string
113
- */
114
- export function normalize(value: string, options?: NormalizeOptions): string {
115
- return normalizeString(value, getNormalizeOptions(options));
116
- }
117
-
118
- normalize.initialize = initializeNormalizer;
119
-
120
- function normalizeString(value: string, options: Options): string {
121
- if (typeof value !== 'string') {
122
- return '';
123
- }
124
-
125
- let result = value;
126
-
127
- if (options.trim) {
128
- result = result.trim();
129
- }
130
-
131
- if (options.whitespace) {
132
- result = result.replace(WHITESPACE_PATTERN, WHITESPACE_REPLACEMENT);
133
- }
134
-
135
- if (options.deburr) {
136
- result = deburr(result);
137
- }
138
-
139
- if (options.lowerCase) {
140
- result = lowerCase(result);
141
- }
142
-
143
- if (options.special) {
144
- result = result.replace(SPECIAL_PATTERN, SPECIAL_REPLACEMENT);
145
- }
146
-
147
- return result.normalize(NORMALIZATION_NORMALIZATION);
148
- }
149
-
150
- // #endregion
151
-
152
- // #region Variables
153
-
154
- const DEBURR_CHARACTERS = {
155
- Æ: 'AE',
156
- æ: 'ae',
157
- Ð: 'D',
158
- ð: 'd',
159
- Đ: 'D',
160
- đ: 'd',
161
- Ħ: 'H',
162
- ħ: 'h',
163
- IJ: 'IJ',
164
- ij: 'ij',
165
- İ: 'I',
166
- ı: 'i',
167
- ĸ: 'k',
168
- Ŀ: 'L',
169
- ŀ: 'l',
170
- Ł: 'L',
171
- ł: 'l',
172
- Ŋ: 'N',
173
- ŋ: 'n',
174
- ʼn: "'n",
175
- Œ: 'OE',
176
- œ: 'oe',
177
- Ø: 'O',
178
- ø: 'o',
179
- ſ: 's',
180
- ß: 'ss',
181
- Þ: 'TH',
182
- þ: 'th',
183
- Ŧ: 'T',
184
- ŧ: 't',
185
- };
186
-
187
- const DEBURR_NORMALIZATION = 'NFD';
188
-
189
- const DEBURR_PATTERN_CHARACTERS = new RegExp(`(${Object.keys(DEBURR_CHARACTERS).join('|')})`, 'g');
190
-
191
- const DEBURR_PATTERN_SIMPLE = /[\u0300-\u036f]/g;
192
-
193
- const NORMALIZATION_NORMALIZATION = 'NFC';
194
-
195
- const SPECIAL_PATTERN = /[\p{P}\p{S}]/gu;
196
-
197
- const SPECIAL_REPLACEMENT = '';
198
-
199
- const WHITESPACE_PATTERN = /\s+/g;
200
-
201
- const WHITESPACE_REPLACEMENT = ' ';
202
-
203
- let deburrMemoizer: Memoized<typeof deburr>;
204
-
205
- // #endregion
@@ -1,161 +0,0 @@
1
- import {isPlainObject, isTemplateStringsArray} from '../internal/is';
2
- import {getString, interpolate} from '../internal/string';
3
- import {getValue} from '../internal/value/get';
4
- import type {PlainObject} from '../models';
5
-
6
- // #region Types
7
-
8
- /**
9
- * Renderer for a string template with variables
10
- *
11
- * @param variables Variables to use
12
- * @param options Templating options
13
- * @returns Templated string
14
- */
15
- type Renderer = (variables?: PlainObject, options?: Partial<TemplateOptions>) => string;
16
-
17
- /**
18
- * Options for templating strings
19
- */
20
- export type TemplateOptions = {
21
- /**
22
- * Ignore case when searching for variables?
23
- */
24
- ignoreCase?: boolean;
25
- /**
26
- * Custom pattern for outputting variables
27
- */
28
- pattern?: RegExp;
29
- };
30
-
31
- type Templater = {
32
- /**
33
- * Render a string from a template with variables
34
- *
35
- * @returns Templated string
36
- */
37
- (strings: TemplateStringsArray, ...values: unknown[]): TemplaterRenderer;
38
-
39
- /**
40
- * Render a string from a template with variables
41
- *
42
- * @param value Template string
43
- * @param variables Variables to use
44
- * @returns Templated string
45
- */
46
- (value: string, variables?: PlainObject): string;
47
- };
48
-
49
- /**
50
- * Render a template string with variables
51
- */
52
- type TemplaterRenderer = (variables?: PlainObject) => string;
53
-
54
- // #endregion
55
-
56
- // #region Functions
57
-
58
- function getRenderer(strings: TemplateStringsArray, values: unknown[]): Renderer {
59
- return (variables?: PlainObject, options?: Partial<TemplateOptions>) => {
60
- return template(interpolate(strings, values), variables, options);
61
- };
62
- }
63
-
64
- function getTemplateOptions(input?: Partial<TemplateOptions>): Required<TemplateOptions> {
65
- const options = isPlainObject(input) ? (input as TemplateOptions) : {};
66
-
67
- return {
68
- ignoreCase: options.ignoreCase === true,
69
- pattern: options.pattern instanceof RegExp ? options.pattern : EXPRESSION_VARIABLE,
70
- };
71
- }
72
-
73
- function handleTemplate(
74
- value: string,
75
- pattern: RegExp,
76
- ignoreCase: boolean,
77
- variables?: PlainObject,
78
- ): string {
79
- if (typeof value !== 'string') {
80
- return '';
81
- }
82
-
83
- if (typeof variables !== 'object' || variables === null || Object.keys(variables).length === 0) {
84
- return value;
85
- }
86
-
87
- const values: Record<string, string> = {};
88
-
89
- return value.replace(pattern, (_, key) => {
90
- if (values[key] == null) {
91
- const templateValue = getValue(variables, key, ignoreCase);
92
-
93
- values[key] = templateValue == null ? '' : getString(templateValue);
94
- }
95
-
96
- return values[key];
97
- });
98
- }
99
-
100
- /**
101
- * Create a _Templater_ with predefined options
102
- *
103
- * _Available as `initializeTemplater` and `template.initialize`_
104
- *
105
- * @param options Templating options
106
- * @returns _Templater_ function
107
- */
108
- export function initializeTemplater(options?: Partial<TemplateOptions>): Templater {
109
- const {ignoreCase, pattern} = getTemplateOptions(options);
110
-
111
- return ((value: string | TemplateStringsArray, ...parameters: unknown[]) => {
112
- return isTemplateStringsArray(value)
113
- ? (variables?: PlainObject) =>
114
- handleTemplate(interpolate(value, parameters), pattern, ignoreCase, variables)
115
- : handleTemplate(value, pattern, ignoreCase, parameters[0] as PlainObject);
116
- }) as Templater;
117
- }
118
-
119
- /**
120
- * Get a _Renderer_ for a string template
121
- *
122
- * @returns _Renderer_ function
123
- */
124
- export function template(strings: TemplateStringsArray, ...values: unknown[]): Renderer;
125
-
126
- /**
127
- * Render a string from a template with variables
128
- *
129
- * @param value Template string
130
- * @param variables Variables to use
131
- * @param options Templating options
132
- * @returns Templated string
133
- */
134
- export function template(
135
- value: string,
136
- variables?: PlainObject,
137
- options?: Partial<TemplateOptions>,
138
- ): string;
139
-
140
- export function template(
141
- value: string | TemplateStringsArray,
142
- ...parameters: unknown[]
143
- ): string | Renderer {
144
- if (isTemplateStringsArray(value)) {
145
- return getRenderer(value, parameters);
146
- }
147
-
148
- const {ignoreCase, pattern} = getTemplateOptions(parameters[1] as Partial<TemplateOptions>);
149
-
150
- return handleTemplate(value, pattern, ignoreCase, parameters[0] as PlainObject);
151
- }
152
-
153
- template.initialize = initializeTemplater;
154
-
155
- // #endregion
156
-
157
- // #region Variables
158
-
159
- const EXPRESSION_VARIABLE = /{{([\s\S]+?)}}/g;
160
-
161
- // #endregion