@oscarpalmer/atoms 0.192.0 → 0.193.1

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 (130) hide show
  1. package/dist/index.d.mts +25 -23
  2. package/dist/index.mjs +30 -31
  3. package/dist/queue.d.mts +25 -23
  4. package/dist/queue.mjs +27 -28
  5. package/package.json +3 -4
  6. package/src/array/difference.ts +0 -73
  7. package/src/array/exists.ts +0 -93
  8. package/src/array/filter.ts +0 -182
  9. package/src/array/find.ts +0 -183
  10. package/src/array/first.ts +0 -196
  11. package/src/array/flatten.ts +0 -20
  12. package/src/array/from.ts +0 -129
  13. package/src/array/get.ts +0 -131
  14. package/src/array/group-by.ts +0 -369
  15. package/src/array/index.ts +0 -26
  16. package/src/array/insert.ts +0 -52
  17. package/src/array/intersection.ts +0 -72
  18. package/src/array/last.ts +0 -194
  19. package/src/array/match.ts +0 -436
  20. package/src/array/move.ts +0 -315
  21. package/src/array/partition.ts +0 -91
  22. package/src/array/push.ts +0 -23
  23. package/src/array/reverse.ts +0 -33
  24. package/src/array/select.ts +0 -260
  25. package/src/array/single.ts +0 -93
  26. package/src/array/slice.ts +0 -335
  27. package/src/array/sort.ts +0 -607
  28. package/src/array/splice.ts +0 -106
  29. package/src/array/swap.ts +0 -322
  30. package/src/array/to-map.ts +0 -371
  31. package/src/array/to-record.ts +0 -351
  32. package/src/array/to-set.ts +0 -80
  33. package/src/array/toggle.ts +0 -79
  34. package/src/array/union.ts +0 -72
  35. package/src/array/unique.ts +0 -67
  36. package/src/array/update.ts +0 -75
  37. package/src/beacon.ts +0 -378
  38. package/src/color/constants.ts +0 -137
  39. package/src/color/index.ts +0 -83
  40. package/src/color/instance.ts +0 -162
  41. package/src/color/misc/alpha.ts +0 -56
  42. package/src/color/misc/format.ts +0 -29
  43. package/src/color/misc/get.ts +0 -210
  44. package/src/color/misc/is.ts +0 -221
  45. package/src/color/misc/state.ts +0 -243
  46. package/src/color/models.ts +0 -389
  47. package/src/color/space/hex.ts +0 -184
  48. package/src/color/space/hsl.ts +0 -174
  49. package/src/color/space/hwb.ts +0 -153
  50. package/src/color/space/rgb.ts +0 -240
  51. package/src/function/assert.ts +0 -174
  52. package/src/function/index.ts +0 -2
  53. package/src/function/limit.ts +0 -83
  54. package/src/function/memoize.ts +0 -202
  55. package/src/function/once.ts +0 -200
  56. package/src/function/retry.ts +0 -175
  57. package/src/function/work.ts +0 -1007
  58. package/src/herald.ts +0 -216
  59. package/src/index.ts +0 -68
  60. package/src/internal/array/callbacks.ts +0 -46
  61. package/src/internal/array/chunk.ts +0 -51
  62. package/src/internal/array/compact.ts +0 -56
  63. package/src/internal/array/find.ts +0 -200
  64. package/src/internal/array/group.ts +0 -42
  65. package/src/internal/array/index-of.ts +0 -182
  66. package/src/internal/array/insert.ts +0 -80
  67. package/src/internal/array/overlap.ts +0 -35
  68. package/src/internal/array/sets.ts +0 -74
  69. package/src/internal/array/shuffle.ts +0 -33
  70. package/src/internal/array/update.ts +0 -52
  71. package/src/internal/function/misc.ts +0 -8
  72. package/src/internal/function/timer.ts +0 -168
  73. package/src/internal/is.ts +0 -244
  74. package/src/internal/math/aggregate.ts +0 -164
  75. package/src/internal/math/misc.ts +0 -28
  76. package/src/internal/number.ts +0 -129
  77. package/src/internal/random.ts +0 -49
  78. package/src/internal/result.ts +0 -92
  79. package/src/internal/sized.ts +0 -25
  80. package/src/internal/string.ts +0 -128
  81. package/src/internal/subscription.ts +0 -264
  82. package/src/internal/value/compare.ts +0 -170
  83. package/src/internal/value/equal.ts +0 -465
  84. package/src/internal/value/get.ts +0 -57
  85. package/src/internal/value/handlers.ts +0 -95
  86. package/src/internal/value/has.ts +0 -118
  87. package/src/internal/value/misc.ts +0 -125
  88. package/src/internal/value/partial.ts +0 -46
  89. package/src/internal/value/set.ts +0 -132
  90. package/src/is.ts +0 -182
  91. package/src/logger.ts +0 -230
  92. package/src/math.ts +0 -281
  93. package/src/models.ts +0 -286
  94. package/src/number.ts +0 -1
  95. package/src/promise/delay.ts +0 -62
  96. package/src/promise/helpers.ts +0 -96
  97. package/src/promise/index.ts +0 -300
  98. package/src/promise/misc.ts +0 -96
  99. package/src/promise/models.ts +0 -195
  100. package/src/promise/timed.ts +0 -91
  101. package/src/query.ts +0 -147
  102. package/src/queue.ts +0 -814
  103. package/src/random.ts +0 -125
  104. package/src/result/index.ts +0 -105
  105. package/src/result/match.ts +0 -124
  106. package/src/result/misc.ts +0 -129
  107. package/src/result/models.ts +0 -83
  108. package/src/result/work/flow.ts +0 -488
  109. package/src/result/work/pipe.ts +0 -496
  110. package/src/sized/map.ts +0 -110
  111. package/src/sized/set.ts +0 -107
  112. package/src/string/case.ts +0 -236
  113. package/src/string/fuzzy.ts +0 -444
  114. package/src/string/index.ts +0 -199
  115. package/src/string/match.ts +0 -80
  116. package/src/string/normalize.ts +0 -205
  117. package/src/string/template.ts +0 -161
  118. package/src/value/clone.ts +0 -319
  119. package/src/value/collection.ts +0 -63
  120. package/src/value/diff.ts +0 -232
  121. package/src/value/freeze.ts +0 -322
  122. package/src/value/handle.ts +0 -3
  123. package/src/value/index.ts +0 -5
  124. package/src/value/merge.ts +0 -278
  125. package/src/value/omit.ts +0 -20
  126. package/src/value/pick.ts +0 -20
  127. package/src/value/shake.ts +0 -45
  128. package/src/value/smush.ts +0 -89
  129. package/src/value/transform.ts +0 -153
  130. 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