@oscarpalmer/atoms 0.201.0 → 0.203.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 (156) hide show
  1. package/dist/array/difference.d.mts +4 -5
  2. package/dist/array/exists.d.mts +5 -6
  3. package/dist/array/filter.d.mts +10 -11
  4. package/dist/array/find.d.mts +10 -11
  5. package/dist/array/first.d.mts +10 -11
  6. package/dist/array/flatten.d.mts +2 -3
  7. package/dist/array/from.d.mts +7 -8
  8. package/dist/array/group-by.d.mts +16 -185
  9. package/dist/array/insert.d.mts +3 -4
  10. package/dist/array/intersection.d.mts +4 -5
  11. package/dist/array/last.d.mts +10 -11
  12. package/dist/array/move.d.mts +9 -10
  13. package/dist/array/partition.d.mts +5 -6
  14. package/dist/array/push.d.mts +2 -3
  15. package/dist/array/reverse.d.mts +2 -3
  16. package/dist/array/select.d.mts +11 -12
  17. package/dist/array/single.d.mts +4 -5
  18. package/dist/array/slice.d.mts +12 -13
  19. package/dist/array/sort.d.mts +31 -32
  20. package/dist/array/sort.mjs +41 -33
  21. package/dist/array/splice.d.mts +5 -6
  22. package/dist/array/swap.d.mts +8 -9
  23. package/dist/array/to-map.d.mts +18 -175
  24. package/dist/array/to-record.d.mts +18 -175
  25. package/dist/array/to-set.d.mts +4 -5
  26. package/dist/array/toggle.d.mts +4 -5
  27. package/dist/array/union.d.mts +4 -5
  28. package/dist/array/unique.d.mts +4 -5
  29. package/dist/array/update.d.mts +4 -5
  30. package/dist/beacon.d.mts +8 -9
  31. package/dist/beacon.mjs +90 -65
  32. package/dist/color/constants.d.mts +14 -13
  33. package/dist/color/constants.mjs +9 -2
  34. package/dist/color/index.d.mts +2 -2
  35. package/dist/color/instance.d.mts +3 -3
  36. package/dist/color/instance.mjs +125 -61
  37. package/dist/color/misc/alpha.d.mts +4 -5
  38. package/dist/color/misc/format.d.mts +6 -7
  39. package/dist/color/misc/format.mjs +15 -12
  40. package/dist/color/misc/get.d.mts +14 -15
  41. package/dist/color/misc/is.d.mts +16 -17
  42. package/dist/color/misc/is.mjs +3 -4
  43. package/dist/color/misc/state.d.mts +8 -10
  44. package/dist/color/misc/state.mjs +22 -20
  45. package/dist/color/models.d.mts +25 -19
  46. package/dist/color/space/hex.d.mts +9 -10
  47. package/dist/color/space/hsl.d.mts +8 -9
  48. package/dist/color/space/hwb.d.mts +9 -10
  49. package/dist/color/space/rgb.d.mts +11 -12
  50. package/dist/function/limit.d.mts +9 -8
  51. package/dist/function/limit.mjs +5 -5
  52. package/dist/function/once.d.mts +26 -6
  53. package/dist/function/once.mjs +135 -76
  54. package/dist/function/retry.d.mts +5 -6
  55. package/dist/function/retry.mjs +3 -3
  56. package/dist/index.d.mts +244 -584
  57. package/dist/index.mjs +1191 -810
  58. package/dist/internal/abort.d.mts +3 -4
  59. package/dist/internal/array/callbacks.d.mts +4 -5
  60. package/dist/internal/array/chunk.d.mts +2 -3
  61. package/dist/internal/array/compact.d.mts +3 -4
  62. package/dist/internal/array/find.d.mts +10 -11
  63. package/dist/internal/array/get.d.mts +7 -8
  64. package/dist/internal/array/group.d.mts +2 -3
  65. package/dist/internal/array/index-of.d.mts +10 -11
  66. package/dist/internal/array/insert.d.mts +5 -6
  67. package/dist/internal/array/match.d.mts +17 -18
  68. package/dist/internal/array/overlap.d.mts +2 -3
  69. package/dist/internal/array/sets.d.mts +5 -6
  70. package/dist/internal/array/shuffle.d.mts +2 -3
  71. package/dist/internal/array/update.d.mts +2 -3
  72. package/dist/internal/defaults.d.mts +3 -4
  73. package/dist/internal/function/assert.d.mts +10 -11
  74. package/dist/internal/function/limit.d.mts +41 -0
  75. package/dist/internal/function/limit.mjs +110 -0
  76. package/dist/internal/function/memoize.d.mts +4 -5
  77. package/dist/internal/function/memoize.mjs +53 -31
  78. package/dist/internal/function/misc.d.mts +2 -3
  79. package/dist/internal/function/work.d.mts +53 -54
  80. package/dist/internal/herald.d.mts +8 -9
  81. package/dist/internal/herald.mjs +38 -26
  82. package/dist/internal/is.d.mts +19 -20
  83. package/dist/internal/math/aggregate.d.mts +14 -15
  84. package/dist/internal/math/misc.d.mts +3 -4
  85. package/dist/internal/number.d.mts +4 -5
  86. package/dist/internal/random.d.mts +3 -4
  87. package/dist/internal/result/misc.d.mts +29 -14
  88. package/dist/internal/result/misc.mjs +4 -0
  89. package/dist/internal/result/models.d.mts +9 -10
  90. package/dist/internal/sized/map.d.mts +2 -3
  91. package/dist/internal/sized/misc.d.mts +2 -3
  92. package/dist/internal/string/case.d.mts +9 -10
  93. package/dist/internal/string/misc.d.mts +8 -9
  94. package/dist/internal/subscription.d.mts +14 -15
  95. package/dist/internal/subscription.mjs +69 -57
  96. package/dist/internal/value/compare.d.mts +17 -9
  97. package/dist/internal/value/compare.mjs +7 -7
  98. package/dist/internal/value/equal.d.mts +34 -15
  99. package/dist/internal/value/equal.mjs +28 -13
  100. package/dist/internal/value/get.d.mts +3 -4
  101. package/dist/internal/value/handlers.d.mts +19 -9
  102. package/dist/internal/value/handlers.mjs +50 -50
  103. package/dist/internal/value/has.d.mts +6 -7
  104. package/dist/internal/value/misc.d.mts +6 -7
  105. package/dist/internal/value/partial.d.mts +3 -4
  106. package/dist/internal/value/set.d.mts +4 -5
  107. package/dist/is.d.mts +13 -13
  108. package/dist/logger.d.mts +5 -4
  109. package/dist/logger.mjs +61 -54
  110. package/dist/math.d.mts +20 -20
  111. package/dist/models.d.mts +58 -46
  112. package/dist/promise/constants.d.mts +14 -15
  113. package/dist/promise/delay.d.mts +3 -4
  114. package/dist/promise/delay.mjs +4 -4
  115. package/dist/promise/helpers.d.mts +7 -8
  116. package/dist/promise/index.d.mts +13 -14
  117. package/dist/promise/misc.d.mts +6 -6
  118. package/dist/promise/models.d.mts +16 -17
  119. package/dist/promise/timed.d.mts +4 -5
  120. package/dist/promise/timed.mjs +5 -5
  121. package/dist/query.d.mts +3 -4
  122. package/dist/queue.d.mts +14 -15
  123. package/dist/queue.mjs +185 -129
  124. package/dist/random.d.mts +8 -8
  125. package/dist/result/index.d.mts +8 -9
  126. package/dist/result/match.d.mts +6 -7
  127. package/dist/result/misc.d.mts +3 -3
  128. package/dist/result/work/flow.d.mts +28 -29
  129. package/dist/result/work/pipe.d.mts +24 -25
  130. package/dist/sized/set.d.mts +2 -3
  131. package/dist/string/fuzzy.d.mts +21 -12
  132. package/dist/string/fuzzy.mjs +77 -49
  133. package/dist/string/index.d.mts +8 -8
  134. package/dist/string/match.d.mts +4 -5
  135. package/dist/string/normalize.d.mts +8 -9
  136. package/dist/string/normalize.mjs +9 -4
  137. package/dist/string/template.d.mts +9 -9
  138. package/dist/string/template.mjs +11 -4
  139. package/dist/value/clone.d.mts +21 -13
  140. package/dist/value/clone.mjs +22 -20
  141. package/dist/value/collection.d.mts +4 -5
  142. package/dist/value/diff.d.mts +5 -6
  143. package/dist/value/freeze.d.mts +18 -19
  144. package/dist/value/freeze.mjs +1 -1
  145. package/dist/value/merge.d.mts +13 -14
  146. package/dist/value/merge.mjs +21 -5
  147. package/dist/value/omit.d.mts +2 -3
  148. package/dist/value/pick.d.mts +2 -3
  149. package/dist/value/shake.d.mts +3 -4
  150. package/dist/value/smush.d.mts +3 -4
  151. package/dist/value/transform.d.mts +15 -10
  152. package/dist/value/transform.mjs +12 -7
  153. package/dist/value/unsmush.d.mts +3 -4
  154. package/package.json +1 -1
  155. package/dist/internal/function/timer.d.mts +0 -10
  156. package/dist/internal/function/timer.mjs +0 -87
@@ -3,7 +3,7 @@ import { PlainObject } from "../models.mjs";
3
3
  /**
4
4
  * Fuzzy searcher for an array of items
5
5
  */
6
- type Fuzzy<Item> = {
6
+ export type Fuzzy<Item> = {
7
7
  /**
8
8
  * Get items currently being searched through
9
9
  *
@@ -39,7 +39,7 @@ type Fuzzy<Item> = {
39
39
  */
40
40
  search(value: string, limit: number): FuzzyResult<Item>;
41
41
  };
42
- type FuzzyConfiguration<Item> = {
42
+ export type FuzzyConfiguration<Item> = {
43
43
  /**
44
44
  * Handler to stringify items
45
45
  *
@@ -55,7 +55,7 @@ type FuzzyConfiguration<Item> = {
55
55
  */
56
56
  key?: keyof Item;
57
57
  } : {}) & FuzzyOptions;
58
- type FuzzyOptions = {
58
+ export type FuzzyOptions = {
59
59
  /**
60
60
  * Maximum number of combined items to return in `exact` and `similar` _(defaults to all matches)_
61
61
  */
@@ -71,7 +71,7 @@ type FuzzyOptions = {
71
71
  /**
72
72
  * Search results from a fuzzy search, with exact and similar matches
73
73
  */
74
- type FuzzyResult<Item> = {
74
+ export type FuzzyResult<Item> = {
75
75
  /**
76
76
  * Ordered items that exactly match the search value
77
77
  */
@@ -84,7 +84,7 @@ type FuzzyResult<Item> = {
84
84
  /**
85
85
  * Options for fuzzy searching
86
86
  */
87
- type FuzzySearchOptions = FuzzyOptions;
87
+ export type FuzzySearchOptions = FuzzyOptions;
88
88
  /**
89
89
  * Create a fuzzy searcher for an array of items
90
90
  *
@@ -92,7 +92,7 @@ type FuzzySearchOptions = FuzzyOptions;
92
92
  * @param key Key to use to stringify items
93
93
  * @returns Fuzzy searcher
94
94
  */
95
- declare function fuzzy<Item extends PlainObject, ItemKey extends keyof Item>(items: Item[], key?: ItemKey): Fuzzy<Item>;
95
+ export declare function fuzzy<Item extends PlainObject, ItemKey extends keyof Item>(items: Item[], key?: ItemKey): Fuzzy<Item>;
96
96
  /**
97
97
  * Create a fuzzy searcher for an array of items
98
98
  *
@@ -100,7 +100,7 @@ declare function fuzzy<Item extends PlainObject, ItemKey extends keyof Item>(ite
100
100
  * @param handler Handler to stringify items
101
101
  * @returns Fuzzy searcher
102
102
  */
103
- declare function fuzzy<Item>(items: Item[], handler?: (item: Item) => string): Fuzzy<Item>;
103
+ export declare function fuzzy<Item>(items: Item[], handler?: (item: Item) => string): Fuzzy<Item>;
104
104
  /**
105
105
  * Create a fuzzy searcher for an array of items
106
106
  *
@@ -108,8 +108,9 @@ declare function fuzzy<Item>(items: Item[], handler?: (item: Item) => string): F
108
108
  * @param configuration Fuzzy configuration
109
109
  * @returns Fuzzy searcher
110
110
  */
111
- declare function fuzzy<Item>(items: Item[], configuration?: FuzzyConfiguration<Item>): Fuzzy<Item>;
112
- declare namespace fuzzy {
111
+ export declare function fuzzy<Item>(items: Item[], configuration?: FuzzyConfiguration<Item>): Fuzzy<Item>;
112
+ export declare namespace fuzzy {
113
+ var is: typeof isFuzzy;
113
114
  var match: typeof fuzzyMatch;
114
115
  }
115
116
  /**
@@ -121,6 +122,14 @@ declare namespace fuzzy {
121
122
  * @param needle Needle to search for
122
123
  * @returns `true` if the needle matches the haystack in a fuzzy way, otherwise `false`
123
124
  */
124
- declare function fuzzyMatch(haystack: string, needle: string): boolean;
125
- //#endregion
126
- export { Fuzzy, FuzzyConfiguration, FuzzyOptions, FuzzyResult, FuzzySearchOptions, fuzzy, fuzzyMatch };
125
+ export declare function fuzzyMatch(haystack: string, needle: string): boolean;
126
+ /**
127
+ * Is the value a fuzzy searcher?
128
+ *
129
+ * _Available as `isFuzzy` and `fuzzy.is`_
130
+ *
131
+ * @param value Value to check
132
+ * @returns `true` if the value is a fuzzy searcher, otherwise `false`
133
+ */
134
+ export declare function isFuzzy<Item = unknown>(value: unknown): value is Fuzzy<Item>;
135
+ //#endregion
@@ -3,6 +3,30 @@ import { getString } from "../internal/string/misc.mjs";
3
3
  import { lowerCase } from "../internal/string/case.mjs";
4
4
  import { includes } from "./match.mjs";
5
5
  //#region src/string/fuzzy.ts
6
+ const FUZZY_PROPERTY = "$fuzzy";
7
+ const FUZZY_SYMBOL = Symbol(FUZZY_PROPERTY);
8
+ function Fuzzy(state) {
9
+ Object.defineProperty(this, FUZZY_SYMBOL, { value: state });
10
+ }
11
+ Object.defineProperties(Fuzzy.prototype, {
12
+ [FUZZY_PROPERTY]: { value: true },
13
+ items: {
14
+ enumerable: true,
15
+ get() {
16
+ return this[FUZZY_SYMBOL].items.slice();
17
+ },
18
+ set(value) {
19
+ setItems(this[FUZZY_SYMBOL], value);
20
+ }
21
+ },
22
+ search: { value: search },
23
+ strings: {
24
+ enumerable: true,
25
+ get() {
26
+ return this[FUZZY_SYMBOL].strings.slice();
27
+ }
28
+ }
29
+ });
6
30
  function createFuzzyOptions(input, state) {
7
31
  const options = isPlainObject(input) ? input : {};
8
32
  const limit = typeof input === "number" ? input : options.limit;
@@ -22,43 +46,13 @@ function createFuzzyState(items, input) {
22
46
  tolerance: options.tolerance
23
47
  };
24
48
  }
25
- function getHandler(input) {
26
- if (input == null || input === getString) return getString;
27
- switch (typeof input) {
28
- case "function": return input;
29
- case "string": return (item) => item[input];
30
- default:
31
- if (isPlainObject(input)) return getHandler(input.key ?? input.handler);
32
- throw new TypeError(FUZZY_MESSAGE_HANDLER);
33
- }
34
- }
35
- function getFuzzyItems(items) {
36
- return items.sort((first, second) => first.haystack.localeCompare(second.haystack)).map(({ item }) => item);
37
- }
38
- function getTolerance(input, state) {
39
- if (typeof input === "number" && !Number.isNaN(input)) return input < 0 ? 0 : Math.floor(input);
40
- return state?.tolerance ?? FUZZY_PROXIMITY_THRESHOLD;
41
- }
42
49
  function fuzzy(items, configuration) {
43
50
  if (!Array.isArray(items)) throw new TypeError(FUZZY_MESSAGE_ARRAY);
44
- const state = createFuzzyState(items, configuration);
45
- const instance = { search: (value, options) => search(state.items, state.strings, value, options == null ? state : createFuzzyOptions(options, state)) };
46
- Object.defineProperties(instance, {
47
- items: {
48
- enumerable: true,
49
- get: () => state.items.slice(),
50
- set: (value) => setItems(state, value)
51
- },
52
- strings: {
53
- enumerable: true,
54
- get: () => state.strings.slice()
55
- }
56
- });
57
- return Object.freeze(instance);
51
+ return new Fuzzy(createFuzzyState(items, configuration));
58
52
  }
59
53
  /**
60
54
  * Does the needle match the haystack in a fuzzy way?
61
- *
55
+ *
62
56
  * _Available as `fuzzyMatch` and `fuzzy.match`_
63
57
  *
64
58
  * @param haystack Haystack to search through
@@ -71,17 +65,18 @@ function fuzzyMatch(haystack, needle) {
71
65
  if (includes(haystack, trimmed, true)) return true;
72
66
  return getScore(haystack, trimmed) > -1;
73
67
  }
74
- function isSubsequence(haystack, needle) {
75
- const lowerCaseHaystack = lowerCase(haystack);
76
- const lowerCaseNeedle = lowerCase(needle);
77
- const haystackLength = lowerCaseHaystack.length;
78
- const needleLength = lowerCaseNeedle.length;
79
- let needleIndex = 0;
80
- for (let haystackIndex = 0; haystackIndex < haystackLength; haystackIndex += 1) {
81
- if (lowerCaseHaystack[haystackIndex] === lowerCaseNeedle[needleIndex]) needleIndex += 1;
82
- if (needleIndex === needleLength) return true;
68
+ function getHandler(input) {
69
+ if (input == null || input === getString) return getString;
70
+ switch (typeof input) {
71
+ case "function": return input;
72
+ case "string": return (item) => item[input];
73
+ default:
74
+ if (isPlainObject(input)) return getHandler(input.key ?? input.handler);
75
+ throw new TypeError(FUZZY_MESSAGE_HANDLER);
83
76
  }
84
- return false;
77
+ }
78
+ function getFuzzyItems(items) {
79
+ return items.sort((first, second) => first.haystack.localeCompare(second.haystack)).map(({ item }) => item);
85
80
  }
86
81
  function getScore(haystack, needle) {
87
82
  if (!isSubsequence(haystack, needle)) return -1;
@@ -107,23 +102,52 @@ function getScore(haystack, needle) {
107
102
  score -= Math.floor(lowerCaseHaystack.length / FUZZY_LENGTH_DIVISOR);
108
103
  return Math.max(0, score);
109
104
  }
110
- function search(items, strings, input, options) {
105
+ function getTolerance(input, state) {
106
+ if (typeof input === "number" && !Number.isNaN(input)) return input < 0 ? 0 : Math.floor(input);
107
+ return state?.tolerance ?? FUZZY_PROXIMITY_THRESHOLD;
108
+ }
109
+ /**
110
+ * Is the value a fuzzy searcher?
111
+ *
112
+ * _Available as `isFuzzy` and `fuzzy.is`_
113
+ *
114
+ * @param value Value to check
115
+ * @returns `true` if the value is a fuzzy searcher, otherwise `false`
116
+ */
117
+ function isFuzzy(value) {
118
+ return typeof value === "object" && value !== null && FUZZY_PROPERTY in value && value[FUZZY_PROPERTY] === true;
119
+ }
120
+ function isSubsequence(haystack, needle) {
121
+ const lowerCaseHaystack = lowerCase(haystack);
122
+ const lowerCaseNeedle = lowerCase(needle);
123
+ const haystackLength = lowerCaseHaystack.length;
124
+ const needleLength = lowerCaseNeedle.length;
125
+ let needleIndex = 0;
126
+ for (let haystackIndex = 0; haystackIndex < haystackLength; haystackIndex += 1) {
127
+ if (lowerCaseHaystack[haystackIndex] === lowerCaseNeedle[needleIndex]) needleIndex += 1;
128
+ if (needleIndex === needleLength) return true;
129
+ }
130
+ return false;
131
+ }
132
+ function search(input, option) {
133
+ const state = this[FUZZY_SYMBOL];
134
+ const options = option == null ? state : createFuzzyOptions(option, state);
111
135
  const result = {
112
136
  exact: [],
113
137
  similar: []
114
138
  };
115
139
  const value = typeof input === "string" ? input.trim() : "";
116
140
  if (value.length === 0) {
117
- result.exact = items.slice(0, options.limit);
141
+ result.exact = state.items.slice(0, options.limit);
118
142
  return result;
119
143
  }
120
- let { length } = items;
144
+ let { length } = state.items;
121
145
  const exact = [];
122
146
  const similar = [];
123
147
  const scored = {};
124
148
  for (let index = 0; index < length; index += 1) {
125
- const item = items[index];
126
- const haystack = strings[index];
149
+ const item = state.items[index];
150
+ const haystack = state.strings[index];
127
151
  if (includes(haystack, value, true)) {
128
152
  exact.push({
129
153
  item,
@@ -164,7 +188,11 @@ const FUZZY_LENGTH_DIVISOR = 3;
164
188
  const FUZZY_MESSAGE_ARRAY = "Fuzzy requires an array of items";
165
189
  const FUZZY_MESSAGE_HANDLER = "Fuzzy requires a key or function to stringify items";
166
190
  const FUZZY_PROXIMITY_THRESHOLD = 5;
191
+ fuzzy.is = isFuzzy;
167
192
  fuzzy.match = fuzzyMatch;
168
- Object.defineProperty(fuzzy, "match", { value: fuzzyMatch });
193
+ Object.defineProperties(fuzzy, {
194
+ is: { value: isFuzzy },
195
+ match: { value: fuzzyMatch }
196
+ });
169
197
  //#endregion
170
- export { fuzzy, fuzzyMatch };
198
+ export { fuzzy, fuzzyMatch, isFuzzy };
@@ -5,27 +5,27 @@ import { getString, join, words } from "../internal/string/misc.mjs";
5
5
  *
6
6
  * @returns Dedented string
7
7
  */
8
- declare function dedent(strings: TemplateStringsArray, ...values: unknown[]): string;
8
+ export declare function dedent(strings: TemplateStringsArray, ...values: unknown[]): string;
9
9
  /**
10
10
  * Dedent a string, removing common leading whitespace from each line
11
11
  *
12
12
  * @param value String to dedent
13
13
  * @returns Dedented string
14
14
  */
15
- declare function dedent(value: string): string;
15
+ export declare function dedent(value: string): string;
16
16
  /**
17
17
  * Get a new UUID string _(version 4)_ for use in _HTML_
18
18
  *
19
19
  * @param html Use _HTML_-friendly format
20
20
  * @returns UUID string
21
21
  */
22
- declare function getUuid(html: true): string;
22
+ export declare function getUuid(html: true): string;
23
23
  /**
24
24
  * Get a new UUID string _(version 4)_
25
25
  *
26
26
  * @returns UUID string
27
27
  */
28
- declare function getUuid(): string;
28
+ export declare function getUuid(): string;
29
29
  /**
30
30
  * Parse a JSON string into its proper value _(or `undefined` if it fails)_
31
31
  *
@@ -33,14 +33,14 @@ declare function getUuid(): string;
33
33
  * @param reviver Reviver function to transform the parsed values
34
34
  * @returns Parsed value or `undefined` if parsing fails
35
35
  */
36
- declare function parse(value: string, reviver?: (this: unknown, key: string, value: unknown) => unknown): unknown;
36
+ export declare function parse(value: string, reviver?: (this: unknown, key: string, value: unknown) => unknown): unknown;
37
37
  /**
38
38
  * Trim a string _(removing whitespace from both ends)_
39
39
  *
40
40
  * @param value String to trim
41
41
  * @returns Trimmed string
42
42
  */
43
- declare function trim(value: string): string;
43
+ export declare function trim(value: string): string;
44
44
  /**
45
45
  * Truncate a string to a specified length
46
46
  *
@@ -49,6 +49,6 @@ declare function trim(value: string): string;
49
49
  * @param suffix Suffix to append to the truncated string
50
50
  * @returns Truncated string
51
51
  */
52
- declare function truncate(value: string, length: number, suffix?: string): string;
52
+ export declare function truncate(value: string, length: number, suffix?: string): string;
53
53
  //#endregion
54
- export { dedent, getString, getUuid, join, parse, trim, truncate, words };
54
+ export { getString, join, words };
@@ -7,7 +7,7 @@
7
7
  * @param ignoreCase Ignore case when matching? _(defaults to `false`)_
8
8
  * @returns `true` if the string ends with the given substring, otherwise `false`
9
9
  */
10
- declare function endsWith(haystack: string, needle: string, ignoreCase?: boolean): boolean;
10
+ export declare function endsWith(haystack: string, needle: string, ignoreCase?: boolean): boolean;
11
11
  /**
12
12
  * Check if a string includes a specified substring
13
13
  *
@@ -16,7 +16,7 @@ declare function endsWith(haystack: string, needle: string, ignoreCase?: boolean
16
16
  * @param ignoreCase Ignore case when matching? _(defaults to `false`)_
17
17
  * @returns `true` if the string includes the given substring, otherwise `false`
18
18
  */
19
- declare function includes(haystack: string, needle: string, ignoreCase?: boolean): boolean;
19
+ export declare function includes(haystack: string, needle: string, ignoreCase?: boolean): boolean;
20
20
  /**
21
21
  * Check if a string starts with a specified substring
22
22
  *
@@ -25,6 +25,5 @@ declare function includes(haystack: string, needle: string, ignoreCase?: boolean
25
25
  * @param ignoreCase Ignore case when matching? _(defaults to `false`)_
26
26
  * @returns `true` if the string starts with the given substring, otherwise `false`
27
27
  */
28
- declare function startsWith(haystack: string, needle: string, ignoreCase?: boolean): boolean;
29
- //#endregion
30
- export { endsWith, includes, startsWith };
28
+ export declare function startsWith(haystack: string, needle: string, ignoreCase?: boolean): boolean;
29
+ //#endregion
@@ -2,7 +2,7 @@
2
2
  /**
3
3
  * Options for normalizing a string
4
4
  */
5
- type NormalizeOptions = {
5
+ export type NormalizeOptions = {
6
6
  /**
7
7
  * Remove diacritical marks from the string? _(defaults to `true`)_
8
8
  */
@@ -29,14 +29,14 @@ type NormalizeOptions = {
29
29
  /**
30
30
  * String normalizer function
31
31
  */
32
- type Normalizer = {
32
+ export type Normalizer = {
33
33
  /**
34
34
  * Normalize a string
35
35
  *
36
36
  * @param value String to normalize
37
37
  * @returns Normalized string
38
38
  */
39
- (value: string): string;
39
+ normalize(value: string): string;
40
40
  };
41
41
  /**
42
42
  * Deburr a string, removing diacritical marks
@@ -44,7 +44,7 @@ type Normalizer = {
44
44
  * @param value String to deburr
45
45
  * @returns Deburred string
46
46
  */
47
- declare function deburr(value: string): string;
47
+ export declare function deburr(value: string): string;
48
48
  /**
49
49
  * Initialize a string normalizer
50
50
  *
@@ -53,7 +53,7 @@ declare function deburr(value: string): string;
53
53
  * @param options Normalization options
54
54
  * @returns Normalizer function
55
55
  */
56
- declare function initializeNormalizer(options?: NormalizeOptions): Normalizer;
56
+ export declare function initializeNormalizer(options?: NormalizeOptions): Normalizer;
57
57
  /**
58
58
  * Normalize a string
59
59
  *
@@ -63,9 +63,8 @@ declare function initializeNormalizer(options?: NormalizeOptions): Normalizer;
63
63
  * @param options Normalization options
64
64
  * @returns Normalized string
65
65
  */
66
- declare function normalize(value: string, options?: NormalizeOptions): string;
67
- declare namespace normalize {
66
+ export declare function normalize(value: string, options?: NormalizeOptions): string;
67
+ export declare namespace normalize {
68
68
  var initialize: typeof initializeNormalizer;
69
69
  }
70
- //#endregion
71
- export { NormalizeOptions, Normalizer, deburr, initializeNormalizer, normalize };
70
+ //#endregion
@@ -2,6 +2,10 @@ import { isPlainObject } from "../internal/is.mjs";
2
2
  import { memoize } from "../internal/function/memoize.mjs";
3
3
  import { lowerCase } from "../internal/string/case.mjs";
4
4
  //#region src/string/normalize.ts
5
+ function Normalizer(options) {
6
+ Object.defineProperty(this, NORMALIZE_SYMBOL, { value: options });
7
+ }
8
+ Object.defineProperties(Normalizer.prototype, { normalize: { value: normalizeString } });
5
9
  function createNormalizeOptions(input) {
6
10
  const options = isPlainObject(input) ? input : {};
7
11
  return {
@@ -36,8 +40,7 @@ function deburr(value) {
36
40
  * @returns Normalizer function
37
41
  */
38
42
  function initializeNormalizer(options) {
39
- const normalization = createNormalizeOptions(options);
40
- return (value) => normalizeString(value, normalization);
43
+ return new Normalizer(createNormalizeOptions(options));
41
44
  }
42
45
  /**
43
46
  * Normalize a string
@@ -49,10 +52,11 @@ function initializeNormalizer(options) {
49
52
  * @returns Normalized string
50
53
  */
51
54
  function normalize(value, options) {
52
- return normalizeString(value, createNormalizeOptions(options));
55
+ return normalizeString.call(createNormalizeOptions(options), value);
53
56
  }
54
- function normalizeString(value, options) {
57
+ function normalizeString(value) {
55
58
  if (typeof value !== "string") return "";
59
+ const options = NORMALIZE_SYMBOL in this ? this[NORMALIZE_SYMBOL] : this;
56
60
  let result = value;
57
61
  if (options.trim) result = result.trim();
58
62
  if (options.whitespace) result = result.replace(NORMALIZE_WHITESPACE_PATTERN, NORMALIZE_WHITESPACE_REPLACEMENT);
@@ -99,6 +103,7 @@ const NORMALIZE_DEBURR_PATTERN_SIMPLE = /[\u0300-\u036f]/g;
99
103
  const NORMALIZE_NORMALIZATION_NORMALIZATION = "NFC";
100
104
  const NORMALIZE_SPECIAL_PATTERN = /[\p{P}\p{S}]/gu;
101
105
  const NORMALIZE_SPECIAL_REPLACEMENT = "";
106
+ const NORMALIZE_SYMBOL = Symbol("normalize");
102
107
  const NORMALIZE_WHITESPACE_PATTERN = /\s+/g;
103
108
  const NORMALIZE_WHITESPACE_REPLACEMENT = " ";
104
109
  let deburrMemoizer;
@@ -11,7 +11,7 @@ type Renderer = (variables?: PlainObject, options?: Partial<TemplateOptions>) =>
11
11
  /**
12
12
  * Options for templating strings
13
13
  */
14
- type TemplateOptions = {
14
+ export type TemplateOptions = {
15
15
  /**
16
16
  * Ignore case when searching for variables?
17
17
  */
@@ -27,7 +27,7 @@ type Templater = {
27
27
  *
28
28
  * @returns Templated string
29
29
  */
30
- (strings: TemplateStringsArray, ...values: unknown[]): TemplaterRenderer;
30
+ render(strings: TemplateStringsArray, ...values: unknown[]): TemplaterRenderer;
31
31
  /**
32
32
  * Render a string from a template with variables
33
33
  *
@@ -35,12 +35,13 @@ type Templater = {
35
35
  * @param variables Variables to use
36
36
  * @returns Templated string
37
37
  */
38
- (value: string, variables?: PlainObject): string;
38
+ render(value: string, variables?: PlainObject): string;
39
39
  };
40
40
  /**
41
41
  * Render a template string with variables
42
42
  */
43
43
  type TemplaterRenderer = (variables?: PlainObject) => string;
44
+ declare function Templater(this: any, options: Required<TemplateOptions>): void;
44
45
  /**
45
46
  * Create a _Templater_ with predefined options
46
47
  *
@@ -49,13 +50,13 @@ type TemplaterRenderer = (variables?: PlainObject) => string;
49
50
  * @param options Templating options
50
51
  * @returns _Templater_ function
51
52
  */
52
- declare function initializeTemplater(options?: Partial<TemplateOptions>): Templater;
53
+ export declare function initializeTemplater(options?: Partial<TemplateOptions>): Templater;
53
54
  /**
54
55
  * Get a _Renderer_ for a string template
55
56
  *
56
57
  * @returns _Renderer_ function
57
58
  */
58
- declare function template(strings: TemplateStringsArray, ...values: unknown[]): Renderer;
59
+ export declare function template(strings: TemplateStringsArray, ...values: unknown[]): Renderer;
59
60
  /**
60
61
  * Render a string from a template with variables
61
62
  *
@@ -64,9 +65,8 @@ declare function template(strings: TemplateStringsArray, ...values: unknown[]):
64
65
  * @param options Templating options
65
66
  * @returns Templated string
66
67
  */
67
- declare function template(value: string, variables?: PlainObject, options?: Partial<TemplateOptions>): string;
68
- declare namespace template {
68
+ export declare function template(value: string, variables?: PlainObject, options?: Partial<TemplateOptions>): string;
69
+ export declare namespace template {
69
70
  var initialize: typeof initializeTemplater;
70
71
  }
71
- //#endregion
72
- export { TemplateOptions, initializeTemplater, template };
72
+ //#endregion
@@ -2,6 +2,10 @@ import { isPlainObject, isTemplateStringsArray } from "../internal/is.mjs";
2
2
  import { getString, interpolate } from "../internal/string/misc.mjs";
3
3
  import { getValue } from "../internal/value/get.mjs";
4
4
  //#region src/string/template.ts
5
+ function Templater(options) {
6
+ Object.defineProperty(this, TEMPLATE_SYMBOL, { value: options });
7
+ }
8
+ Object.defineProperties(Templater.prototype, { render: { value: render } });
5
9
  function createTemplateOptions(input) {
6
10
  const options = isPlainObject(input) ? input : {};
7
11
  return {
@@ -35,10 +39,12 @@ function handleTemplate(value, pattern, ignoreCase, variables) {
35
39
  * @returns _Templater_ function
36
40
  */
37
41
  function initializeTemplater(options) {
38
- const { ignoreCase, pattern } = createTemplateOptions(options);
39
- return ((value, ...parameters) => {
40
- return isTemplateStringsArray(value) ? (variables) => handleTemplate(interpolate(value, parameters), pattern, ignoreCase, variables) : handleTemplate(value, pattern, ignoreCase, parameters[0]);
41
- });
42
+ return new Templater(createTemplateOptions(options));
43
+ }
44
+ function render(value, ...parameters) {
45
+ const { ignoreCase, pattern } = this[TEMPLATE_SYMBOL];
46
+ if (isTemplateStringsArray(value)) return (variables) => handleTemplate(interpolate(value, parameters), pattern, ignoreCase, variables);
47
+ return handleTemplate(value, pattern, ignoreCase, parameters[0]);
42
48
  }
43
49
  function template(value, ...parameters) {
44
50
  if (isTemplateStringsArray(value)) return getRenderer(value, parameters);
@@ -46,6 +52,7 @@ function template(value, ...parameters) {
46
52
  return handleTemplate(value, pattern, ignoreCase, parameters[0]);
47
53
  }
48
54
  const TEMPLATE_EXPRESSION_VARIABLE = /{{([\s\S]+?)}}/g;
55
+ const TEMPLATE_SYMBOL = Symbol("template");
49
56
  template.initialize = initializeTemplater;
50
57
  Object.defineProperty(template, "initialize", { value: initializeTemplater });
51
58
  //#endregion
@@ -1,6 +1,6 @@
1
1
  import { Constructor, GenericCallback } from "../models.mjs";
2
2
  //#region src/value/clone.d.ts
3
- type CloneOptions = {
3
+ export type CloneOptions = {
4
4
  /**
5
5
  * Copy functions instead of returning `undefined`? _(defaults to `false`)_
6
6
  */
@@ -13,14 +13,14 @@ type CloneOptions = {
13
13
  /**
14
14
  * A cloning function with predefined options
15
15
  */
16
- type Cloner = {
16
+ export type Cloner = {
17
17
  /**
18
18
  * Clone any kind of value
19
19
  *
20
20
  * @param value Value to clone
21
21
  * @returns Cloned value
22
22
  */
23
- <Value>(value: Value): Value;
23
+ clone<Value>(value: Value): Value;
24
24
  /**
25
25
  * Deregister a clone handler for a specific class
26
26
  *
@@ -46,13 +46,22 @@ type Cloner = {
46
46
  * @param options Clone options
47
47
  * @returns Cloned value
48
48
  */
49
- declare function clone<Value>(value: Value, options?: CloneOptions): Value;
50
- declare namespace clone {
49
+ export declare function clone<Value>(value: Value, options?: CloneOptions): Value;
50
+ export declare namespace clone {
51
51
  var deregister: typeof deregisterCloner;
52
52
  var handlers: {
53
- deregister(constructor: Constructor): void;
53
+ base: {
54
+ handlers: WeakMap<Constructor, string | GenericCallback>;
55
+ options: {
56
+ callback: GenericCallback;
57
+ method?: string;
58
+ };
59
+ owner: GenericCallback;
60
+ deregister: (constructor: Constructor) => void;
61
+ get: (first: unknown, second: unknown) => string | GenericCallback | undefined;
62
+ register: (constructor: Constructor, handler?: string | GenericCallback) => void;
63
+ };
54
64
  handle(value: unknown, ...parameters: unknown[]): unknown;
55
- register(constructor: Constructor, handler?: string | GenericCallback): void;
56
65
  };
57
66
  var initialize: typeof initializeCloner;
58
67
  var register: typeof registerCloner;
@@ -66,7 +75,7 @@ declare namespace clone {
66
75
  * @param value Value to copy
67
76
  * @returns Copied value
68
77
  */
69
- declare function copy<Value>(value: Value): Value;
78
+ export declare function copy<Value>(value: Value): Value;
70
79
  /**
71
80
  * Deregister a clone handler for a specific class
72
81
  *
@@ -74,7 +83,7 @@ declare function copy<Value>(value: Value): Value;
74
83
  *
75
84
  * @param constructor Class constructor
76
85
  */
77
- declare function deregisterCloner<Instance>(constructor: Constructor<Instance>): void;
86
+ export declare function deregisterCloner<Instance>(constructor: Constructor<Instance>): void;
78
87
  /**
79
88
  * Create a cloner with predefined options
80
89
  *
@@ -83,7 +92,7 @@ declare function deregisterCloner<Instance>(constructor: Constructor<Instance>):
83
92
  * @param options Clone options
84
93
  * @returns Cloner function
85
94
  */
86
- declare function initializeCloner(options?: CloneOptions): Cloner;
95
+ export declare function initializeCloner(options?: CloneOptions): Cloner;
87
96
  /**
88
97
  * Register a clone handler for a specific class
89
98
  *
@@ -92,6 +101,5 @@ declare function initializeCloner(options?: CloneOptions): Cloner;
92
101
  * @param constructor Class constructor
93
102
  * @param handler Method name or clone function _(defaults to method name `clone`)_
94
103
  */
95
- declare function registerCloner<Instance>(constructor: Constructor<Instance>, handler?: string | ((value: Instance) => Instance)): void;
96
- //#endregion
97
- export { CloneOptions, Cloner, clone, copy, deregisterCloner, initializeCloner, registerCloner };
104
+ export declare function registerCloner<Instance>(constructor: Constructor<Instance>, handler?: string | ((value: Instance) => Instance)): void;
105
+ //#endregion