@oscarpalmer/atoms 0.186.2 → 0.187.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 (229) hide show
  1. package/dist/array/filter.d.mts +4 -4
  2. package/dist/array/find.d.mts +4 -4
  3. package/dist/array/first.d.mts +4 -4
  4. package/dist/array/get.d.mts +27 -1
  5. package/dist/array/get.mjs +5 -3
  6. package/dist/array/group-by.d.mts +6 -6
  7. package/dist/array/last.d.mts +4 -4
  8. package/dist/array/match.d.mts +7 -6
  9. package/dist/array/move.d.mts +7 -7
  10. package/dist/array/move.mjs +1 -1
  11. package/dist/array/select.d.mts +1 -0
  12. package/dist/array/slice.d.mts +3 -3
  13. package/dist/array/sort.d.mts +10 -7
  14. package/dist/array/sort.mjs +4 -3
  15. package/dist/array/swap.d.mts +1 -1
  16. package/dist/array/swap.mjs +1 -1
  17. package/dist/array/to-map.d.mts +32 -32
  18. package/dist/array/to-record.d.mts +6 -6
  19. package/dist/array/to-set.d.mts +6 -6
  20. package/dist/beacon.d.mts +6 -0
  21. package/dist/beacon.mjs +3 -0
  22. package/dist/color/index.d.mts +6 -2
  23. package/dist/color/index.mjs +6 -2
  24. package/dist/color/instance.d.mts +78 -14
  25. package/dist/color/instance.mjs +78 -14
  26. package/dist/color/misc/get.d.mts +39 -11
  27. package/dist/color/misc/get.mjs +39 -11
  28. package/dist/color/misc/is.d.mts +26 -11
  29. package/dist/color/misc/is.mjs +26 -11
  30. package/dist/color/misc/state.mjs +1 -1
  31. package/dist/color/models.d.mts +7 -4
  32. package/dist/color/space/hex.d.mts +15 -6
  33. package/dist/color/space/hex.mjs +15 -6
  34. package/dist/color/space/hsl.d.mts +10 -4
  35. package/dist/color/space/hsl.mjs +10 -4
  36. package/dist/color/space/rgb.d.mts +21 -12
  37. package/dist/color/space/rgb.mjs +21 -12
  38. package/dist/function/assert.d.mts +20 -14
  39. package/dist/function/assert.mjs +19 -13
  40. package/dist/function/limit.d.mts +8 -6
  41. package/dist/function/limit.mjs +8 -6
  42. package/dist/function/memoize.d.mts +15 -4
  43. package/dist/function/memoize.mjs +18 -4
  44. package/dist/function/once.d.mts +5 -3
  45. package/dist/function/once.mjs +5 -3
  46. package/dist/function/retry.d.mts +5 -2
  47. package/dist/function/retry.mjs +3 -1
  48. package/dist/function/work.d.mts +146 -98
  49. package/dist/{kalas.d.mts → herald.d.mts} +17 -8
  50. package/dist/{kalas.mjs → herald.mjs} +22 -13
  51. package/dist/index.d.mts +1464 -708
  52. package/dist/index.mjs +677 -324
  53. package/dist/internal/array/index-of.d.mts +4 -4
  54. package/dist/internal/array/insert.mjs +1 -1
  55. package/dist/internal/array/shuffle.d.mts +1 -0
  56. package/dist/internal/array/shuffle.mjs +2 -1
  57. package/dist/internal/is.d.mts +26 -8
  58. package/dist/internal/is.mjs +26 -8
  59. package/dist/internal/math/aggregate.d.mts +9 -9
  60. package/dist/internal/number.d.mts +13 -2
  61. package/dist/internal/number.mjs +13 -2
  62. package/dist/internal/random.d.mts +4 -2
  63. package/dist/internal/random.mjs +7 -5
  64. package/dist/internal/result.d.mts +17 -11
  65. package/dist/internal/result.mjs +10 -14
  66. package/dist/internal/string.d.mts +16 -1
  67. package/dist/internal/string.mjs +24 -1
  68. package/dist/internal/value/compare.d.mts +5 -2
  69. package/dist/internal/value/compare.mjs +5 -2
  70. package/dist/internal/value/equal.d.mts +12 -3
  71. package/dist/internal/value/equal.mjs +7 -4
  72. package/dist/internal/value/get.d.mts +17 -17
  73. package/dist/internal/value/has.d.mts +55 -11
  74. package/dist/internal/value/set.d.mts +24 -0
  75. package/dist/is.d.mts +12 -0
  76. package/dist/is.mjs +16 -1
  77. package/dist/logger.d.mts +7 -6
  78. package/dist/logger.mjs +6 -5
  79. package/dist/math.d.mts +36 -18
  80. package/dist/math.mjs +6 -3
  81. package/dist/models.d.mts +3 -3
  82. package/dist/promise/delay.d.mts +2 -0
  83. package/dist/promise/helpers.d.mts +6 -4
  84. package/dist/promise/helpers.mjs +6 -4
  85. package/dist/promise/index.d.mts +49 -38
  86. package/dist/promise/misc.d.mts +10 -7
  87. package/dist/promise/misc.mjs +4 -3
  88. package/dist/promise/models.d.mts +18 -19
  89. package/dist/promise/models.mjs +4 -3
  90. package/dist/promise/timed.d.mts +8 -6
  91. package/dist/query.d.mts +2 -0
  92. package/dist/query.mjs +2 -0
  93. package/dist/queue.d.mts +15 -4
  94. package/dist/queue.mjs +10 -3
  95. package/dist/random.d.mts +9 -2
  96. package/dist/random.mjs +7 -2
  97. package/dist/result/index.d.mts +14 -8
  98. package/dist/result/match.d.mts +18 -10
  99. package/dist/result/misc.d.mts +14 -7
  100. package/dist/result/misc.mjs +4 -2
  101. package/dist/result/models.d.mts +2 -0
  102. package/dist/result/work/flow.d.mts +86 -62
  103. package/dist/result/work/pipe.d.mts +55 -33
  104. package/dist/sized/map.d.mts +19 -16
  105. package/dist/sized/map.mjs +4 -4
  106. package/dist/sized/set.d.mts +20 -16
  107. package/dist/sized/set.mjs +8 -7
  108. package/dist/string/case.d.mts +8 -0
  109. package/dist/string/case.mjs +8 -0
  110. package/dist/string/fuzzy.d.mts +19 -5
  111. package/dist/string/fuzzy.mjs +7 -0
  112. package/dist/string/index.d.mts +17 -2
  113. package/dist/string/index.mjs +7 -9
  114. package/dist/string/match.d.mts +3 -0
  115. package/dist/string/match.mjs +3 -0
  116. package/dist/string/normalize.d.mts +6 -2
  117. package/dist/string/normalize.mjs +5 -2
  118. package/dist/string/template.d.mts +38 -9
  119. package/dist/string/template.mjs +19 -19
  120. package/dist/value/clone.d.mts +25 -4
  121. package/dist/value/clone.mjs +36 -22
  122. package/dist/value/collection.d.mts +9 -6
  123. package/dist/value/collection.mjs +3 -2
  124. package/dist/value/diff.d.mts +3 -1
  125. package/dist/value/diff.mjs +1 -0
  126. package/dist/value/freeze.d.mts +118 -9
  127. package/dist/value/freeze.mjs +56 -14
  128. package/dist/value/index.d.mts +1 -2
  129. package/dist/value/index.mjs +1 -2
  130. package/dist/value/merge.d.mts +11 -5
  131. package/dist/value/merge.mjs +2 -2
  132. package/dist/value/omit.d.mts +1 -0
  133. package/dist/value/omit.mjs +1 -0
  134. package/dist/value/pick.d.mts +1 -0
  135. package/dist/value/pick.mjs +1 -0
  136. package/dist/value/shake.d.mts +1 -0
  137. package/dist/value/shake.mjs +1 -0
  138. package/dist/value/smush.d.mts +1 -0
  139. package/dist/value/smush.mjs +1 -0
  140. package/dist/value/transform.d.mts +7 -3
  141. package/dist/value/unsmush.d.mts +1 -0
  142. package/dist/value/unsmush.mjs +1 -0
  143. package/package.json +11 -7
  144. package/src/array/filter.ts +4 -4
  145. package/src/array/find.ts +4 -4
  146. package/src/array/first.ts +4 -4
  147. package/src/array/get.ts +40 -5
  148. package/src/array/group-by.ts +6 -6
  149. package/src/array/last.ts +4 -4
  150. package/src/array/match.ts +7 -6
  151. package/src/array/move.ts +7 -7
  152. package/src/array/select.ts +1 -0
  153. package/src/array/slice.ts +3 -3
  154. package/src/array/sort.ts +15 -10
  155. package/src/array/swap.ts +1 -1
  156. package/src/array/to-map.ts +32 -32
  157. package/src/array/to-record.ts +6 -6
  158. package/src/array/to-set.ts +6 -6
  159. package/src/beacon.ts +6 -0
  160. package/src/color/index.ts +6 -2
  161. package/src/color/instance.ts +78 -14
  162. package/src/color/misc/get.ts +39 -11
  163. package/src/color/misc/is.ts +26 -11
  164. package/src/color/misc/state.ts +1 -1
  165. package/src/color/models.ts +7 -4
  166. package/src/color/space/hex.ts +15 -6
  167. package/src/color/space/hsl.ts +10 -4
  168. package/src/color/space/rgb.ts +21 -12
  169. package/src/function/assert.ts +20 -14
  170. package/src/function/limit.ts +8 -6
  171. package/src/function/memoize.ts +24 -5
  172. package/src/function/once.ts +5 -3
  173. package/src/function/retry.ts +7 -3
  174. package/src/function/work.ts +146 -98
  175. package/src/{kalas.ts → herald.ts} +23 -14
  176. package/src/index.ts +3 -2
  177. package/src/internal/array/index-of.ts +4 -4
  178. package/src/internal/array/insert.ts +1 -1
  179. package/src/internal/array/shuffle.ts +2 -1
  180. package/src/internal/is.ts +26 -8
  181. package/src/internal/math/aggregate.ts +9 -9
  182. package/src/internal/number.ts +13 -2
  183. package/src/internal/random.ts +10 -4
  184. package/src/internal/result.ts +30 -29
  185. package/src/internal/string.ts +28 -0
  186. package/src/internal/value/compare.ts +5 -2
  187. package/src/internal/value/equal.ts +13 -4
  188. package/src/internal/value/get.ts +17 -17
  189. package/src/internal/value/has.ts +54 -11
  190. package/src/internal/value/set.ts +24 -0
  191. package/src/is.ts +15 -1
  192. package/src/logger.ts +8 -7
  193. package/src/math.ts +36 -18
  194. package/src/models.ts +3 -3
  195. package/src/promise/delay.ts +2 -0
  196. package/src/promise/helpers.ts +6 -4
  197. package/src/promise/index.ts +49 -38
  198. package/src/promise/misc.ts +10 -7
  199. package/src/promise/models.ts +18 -19
  200. package/src/promise/timed.ts +8 -6
  201. package/src/query.ts +2 -0
  202. package/src/queue.ts +15 -4
  203. package/src/random.ts +8 -1
  204. package/src/result/index.ts +14 -8
  205. package/src/result/match.ts +18 -10
  206. package/src/result/misc.ts +17 -9
  207. package/src/result/models.ts +2 -0
  208. package/src/result/work/flow.ts +86 -62
  209. package/src/result/work/pipe.ts +55 -33
  210. package/src/sized/map.ts +20 -17
  211. package/src/sized/set.ts +21 -17
  212. package/src/string/case.ts +8 -0
  213. package/src/string/fuzzy.ts +19 -5
  214. package/src/string/index.ts +18 -15
  215. package/src/string/match.ts +3 -0
  216. package/src/string/normalize.ts +6 -2
  217. package/src/string/template.ts +69 -18
  218. package/src/value/clone.ts +51 -26
  219. package/src/value/collection.ts +9 -6
  220. package/src/value/diff.ts +3 -1
  221. package/src/value/freeze.ts +239 -25
  222. package/src/value/index.ts +0 -1
  223. package/src/value/merge.ts +11 -5
  224. package/src/value/omit.ts +1 -0
  225. package/src/value/pick.ts +1 -0
  226. package/src/value/shake.ts +1 -0
  227. package/src/value/smush.ts +1 -0
  228. package/src/value/transform.ts +7 -3
  229. package/src/value/unsmush.ts +1 -0
@@ -1,17 +1,17 @@
1
1
  import { getSizedMaximum } from "../internal/sized.mjs";
2
2
  //#region src/sized/set.ts
3
3
  /**
4
- * A Set with a maximum size
4
+ * A _Set_ with a maximum size
5
5
  *
6
- * Behavior is similar to a _LRU_-cache, where the oldest values are removed
6
+ * Behavior is similar to a _LRU_ cache, where the oldest values are removed
7
7
  */
8
8
  var SizedSet = class extends Set {
9
9
  /**
10
- * The maximum size of the Set
10
+ * The maximum size of the _Set_
11
11
  */
12
12
  #maximumSize;
13
13
  /**
14
- * Is the Set full?
14
+ * Is the _Set_ full?
15
15
  */
16
16
  get full() {
17
17
  return this.size >= this.#maximumSize;
@@ -38,9 +38,10 @@ var SizedSet = class extends Set {
38
38
  return super.add(value);
39
39
  }
40
40
  /**
41
- * Get a value from the SizedSet, if it exists _(and move it to the end)_
42
- * @param value Value to get from the SizedSet
43
- * @param update Update the value's position in the SizedSet? _(defaults to `false`)_
41
+ * Get a value from the _SizedSet_, if it exists _(and optionally move it to the end)_
42
+ *
43
+ * @param value Value to get from the _SizedSet_
44
+ * @param update Update the value's position in the _SizedSet_? _(defaults to `false`)_
44
45
  * @returns Found value if it exists, otherwise `undefined`
45
46
  */
46
47
  get(value, update) {
@@ -1,48 +1,56 @@
1
1
  //#region src/string/case.d.ts
2
2
  /**
3
3
  * Convert a string to camel case _(thisIsCamelCase)_
4
+ *
4
5
  * @param value String to convert
5
6
  * @returns Camel-cased string
6
7
  */
7
8
  declare function camelCase(value: string): string;
8
9
  /**
9
10
  * Capitalize the first letter of a string _(and lowercase the rest)_
11
+ *
10
12
  * @param value String to capitalize
11
13
  * @returns Capitalized string
12
14
  */
13
15
  declare function capitalize(value: string): string;
14
16
  /**
15
17
  * Convert a string to kebab case _(this-is-kebab-case)_
18
+ *
16
19
  * @param value String to convert
17
20
  * @returns Kebab-cased string
18
21
  */
19
22
  declare function kebabCase(value: string): string;
20
23
  /**
21
24
  * Convert a string to lower case
25
+ *
22
26
  * @param value String to convert
23
27
  * @returns Lower-cased string
24
28
  */
25
29
  declare function lowerCase(value: string): string;
26
30
  /**
27
31
  * Convert a string to pascal case _(ThisIsPascalCase)_
32
+ *
28
33
  * @param value String to convert
29
34
  * @returns Pascal-cased string
30
35
  */
31
36
  declare function pascalCase(value: string): string;
32
37
  /**
33
38
  * Convert a string to snake case _(this_is_snake_case)_
39
+ *
34
40
  * @param value String to convert
35
41
  * @returns Snake-cased string
36
42
  */
37
43
  declare function snakeCase(value: string): string;
38
44
  /**
39
45
  * Convert a string to title case _(Capitalizing Every Word)_
46
+ *
40
47
  * @param value String to convert
41
48
  * @returns Title-cased string
42
49
  */
43
50
  declare function titleCase(value: string): string;
44
51
  /**
45
52
  * Convert a string to upper case
53
+ *
46
54
  * @param value String to convert
47
55
  * @returns Upper-cased string
48
56
  */
@@ -3,6 +3,7 @@ import { memoize } from "../function/memoize.mjs";
3
3
  //#region src/string/case.ts
4
4
  /**
5
5
  * Convert a string to camel case _(thisIsCamelCase)_
6
+ *
6
7
  * @param value String to convert
7
8
  * @returns Camel-cased string
8
9
  */
@@ -11,6 +12,7 @@ function camelCase(value) {
11
12
  }
12
13
  /**
13
14
  * Capitalize the first letter of a string _(and lowercase the rest)_
15
+ *
14
16
  * @param value String to capitalize
15
17
  * @returns Capitalized string
16
18
  */
@@ -21,6 +23,7 @@ function capitalize(value) {
21
23
  }
22
24
  /**
23
25
  * Convert a string to kebab case _(this-is-kebab-case)_
26
+ *
24
27
  * @param value String to convert
25
28
  * @returns Kebab-cased string
26
29
  */
@@ -29,6 +32,7 @@ function kebabCase(value) {
29
32
  }
30
33
  /**
31
34
  * Convert a string to lower case
35
+ *
32
36
  * @param value String to convert
33
37
  * @returns Lower-cased string
34
38
  */
@@ -39,6 +43,7 @@ function lowerCase(value) {
39
43
  }
40
44
  /**
41
45
  * Convert a string to pascal case _(ThisIsPascalCase)_
46
+ *
42
47
  * @param value String to convert
43
48
  * @returns Pascal-cased string
44
49
  */
@@ -47,6 +52,7 @@ function pascalCase(value) {
47
52
  }
48
53
  /**
49
54
  * Convert a string to snake case _(this_is_snake_case)_
55
+ *
50
56
  * @param value String to convert
51
57
  * @returns Snake-cased string
52
58
  */
@@ -55,6 +61,7 @@ function snakeCase(value) {
55
61
  }
56
62
  /**
57
63
  * Convert a string to title case _(Capitalizing Every Word)_
64
+ *
58
65
  * @param value String to convert
59
66
  * @returns Title-cased string
60
67
  */
@@ -96,6 +103,7 @@ function toCaseCallback(value) {
96
103
  }
97
104
  /**
98
105
  * Convert a string to upper case
106
+ *
99
107
  * @param value String to convert
100
108
  * @returns Upper-cased string
101
109
  */
@@ -8,19 +8,26 @@ declare class Fuzzy<Item> {
8
8
  #private;
9
9
  /**
10
10
  * Get items currently being searched through
11
+ *
12
+ * @returns Original items
11
13
  */
12
14
  get items(): Item[];
13
15
  /**
14
16
  * Set new items to search through
17
+ *
18
+ * @param items New items to search through
15
19
  */
16
20
  set items(items: Item[]);
17
21
  /**
18
22
  * Get strings currently being searched through _(the stringified version of `items`)_
23
+ *
24
+ * @returns Stringified items
19
25
  */
20
26
  get strings(): string[];
21
27
  constructor(state: FuzzyState<Item>);
22
28
  /**
23
29
  * Search for items matching the given value
30
+ *
24
31
  * @param value Value to search for
25
32
  * @param options Search options
26
33
  * @returns Search results, with exact matches _(ordered)_ and similar matches _(ordered by relevance)_
@@ -28,6 +35,7 @@ declare class Fuzzy<Item> {
28
35
  search(value: string, options?: FuzzyOptions): FuzzyResult<Item>;
29
36
  /**
30
37
  * Search for items matching the given value
38
+ *
31
39
  * @param value Value to search for
32
40
  * @param limit Maximum number of combined items to return in `exact` and `similar`
33
41
  * @returns Search results, with exact matches _(ordered)_ and similar matches _(ordered by relevance)_
@@ -38,16 +46,15 @@ type FuzzyConfiguration<Item> = {
38
46
  /**
39
47
  * Handler to stringify items
40
48
  *
41
- * May be a function that takes an item and returns a string, or if items are plain objects, a key of the item to use to grab a string value from
42
- *
43
- * Defaults to `getString`
49
+ * - May be a function that takes an item and returns a string, or if items are plain objects, a key of the item to use to grab a string value from
50
+ * - Defaults to `getString`
44
51
  */
45
52
  handler?: (item: Item) => string;
46
53
  } & (Item extends PlainObject ? {
47
54
  /**
48
55
  * Key to use to stringify items
49
56
  *
50
- * Prioritized over `handler`
57
+ * _Prioritized over `handler`_
51
58
  */
52
59
  key?: keyof Item;
53
60
  } : {}) & FuzzyOptions;
@@ -57,7 +64,10 @@ type FuzzyOptions = {
57
64
  */
58
65
  limit?: number;
59
66
  /**
60
- * Maximum score difference between the best and worst similar matches included in results; higher values cast a wider net _(defaults to 5)_
67
+ * Maximum score difference between the best and worst similar matches included in results
68
+ *
69
+ * - Higher values cast a wider net
70
+ * - Defaults to `5`
61
71
  */
62
72
  tolerance?: number;
63
73
  };
@@ -87,6 +97,7 @@ type FuzzyState<Item> = {
87
97
  };
88
98
  /**
89
99
  * Create a fuzzy searcher for an array of items
100
+ *
90
101
  * @param items Items to search through
91
102
  * @param key Key to use to stringify items
92
103
  * @returns Fuzzy searcher
@@ -94,6 +105,7 @@ type FuzzyState<Item> = {
94
105
  declare function fuzzy<Item extends PlainObject, ItemKey extends keyof Item>(items: Item[], key?: ItemKey): Fuzzy<Item>;
95
106
  /**
96
107
  * Create a fuzzy searcher for an array of items
108
+ *
97
109
  * @param items Items to search through
98
110
  * @param handler Handler to stringify items
99
111
  * @returns Fuzzy searcher
@@ -101,6 +113,7 @@ declare function fuzzy<Item extends PlainObject, ItemKey extends keyof Item>(ite
101
113
  declare function fuzzy<Item>(items: Item[], handler?: (item: Item) => string): Fuzzy<Item>;
102
114
  /**
103
115
  * Create a fuzzy searcher for an array of items
116
+ *
104
117
  * @param items Items to search through
105
118
  * @param configuration Fuzzy configuration
106
119
  * @returns Fuzzy searcher
@@ -111,6 +124,7 @@ declare namespace fuzzy {
111
124
  }
112
125
  /**
113
126
  * Does the needle match the haystack in a fuzzy way?
127
+ *
114
128
  * @param haystack Haystack to search through
115
129
  * @param needle Needle to search for
116
130
  * @returns `true` if the needle matches the haystack in a fuzzy way, `false` otherwise
@@ -10,12 +10,16 @@ var Fuzzy = class {
10
10
  #state;
11
11
  /**
12
12
  * Get items currently being searched through
13
+ *
14
+ * @returns Original items
13
15
  */
14
16
  get items() {
15
17
  return this.#state.items.slice();
16
18
  }
17
19
  /**
18
20
  * Set new items to search through
21
+ *
22
+ * @param items New items to search through
19
23
  */
20
24
  set items(items) {
21
25
  if (Array.isArray(items)) {
@@ -25,6 +29,8 @@ var Fuzzy = class {
25
29
  }
26
30
  /**
27
31
  * Get strings currently being searched through _(the stringified version of `items`)_
32
+ *
33
+ * @returns Stringified items
28
34
  */
29
35
  get strings() {
30
36
  return this.#state.strings.slice();
@@ -79,6 +85,7 @@ function fuzzy(items, configuration) {
79
85
  fuzzy.match = fuzzyMatch;
80
86
  /**
81
87
  * Does the needle match the haystack in a fuzzy way?
88
+ *
82
89
  * @param haystack Haystack to search through
83
90
  * @param needle Needle to search for
84
91
  * @returns `true` if the needle matches the haystack in a fuzzy way, `false` otherwise
@@ -1,15 +1,28 @@
1
1
  import { getString, join, words } from "../internal/string.mjs";
2
2
 
3
3
  //#region src/string/index.d.ts
4
+ /**
5
+ * Dedent a string template, removing common leading whitespace from each line
6
+ *
7
+ * @returns Dedented string
8
+ */
4
9
  declare function dedent(strings: TemplateStringsArray, ...values: unknown[]): string;
10
+ /**
11
+ * Dedent a string, removing common leading whitespace from each line
12
+ *
13
+ * @param value String to dedent
14
+ * @returns Dedented string
15
+ */
5
16
  declare function dedent(value: string): string;
6
17
  /**
7
- * Get a new UUID-string _(version 4)_
18
+ * Get a new UUID string _(version 4)_
19
+ *
8
20
  * @returns UUID string
9
21
  */
10
22
  declare function getUuid(): string;
11
23
  /**
12
24
  * Parse a JSON string into its proper value _(or `undefined` if it fails)_
25
+ *
13
26
  * @param value JSON string to parse
14
27
  * @param reviver Reviver function to transform the parsed values
15
28
  * @returns Parsed value or `undefined` if parsing fails
@@ -17,12 +30,14 @@ declare function getUuid(): string;
17
30
  declare function parse(value: string, reviver?: (this: unknown, key: string, value: unknown) => unknown): unknown;
18
31
  /**
19
32
  * Trim a string _(removing whitespace from both ends)_
33
+ *
20
34
  * @param value String to trim
21
35
  * @returns Trimmed string
22
36
  */
23
37
  declare function trim(value: string): string;
24
38
  /**
25
- * Truncate a string to a specified length, when possible
39
+ * Truncate a string to a specified length
40
+ *
26
41
  * @param value String to truncate
27
42
  * @param length Maximum length of the string after truncation
28
43
  * @param suffix Suffix to append to the truncated string
@@ -1,5 +1,5 @@
1
1
  import { isTemplateStringsArray } from "../internal/is.mjs";
2
- import { getString, join, words } from "../internal/string.mjs";
2
+ import { getString, interpolate, join, words } from "../internal/string.mjs";
3
3
  //#region src/string/index.ts
4
4
  function dedent(value, ...values) {
5
5
  let actual;
@@ -26,7 +26,8 @@ function dedent(value, ...values) {
26
26
  return result.trim();
27
27
  }
28
28
  /**
29
- * Get a new UUID-string _(version 4)_
29
+ * Get a new UUID string _(version 4)_
30
+ *
30
31
  * @returns UUID string
31
32
  */
32
33
  function getUuid() {
@@ -43,14 +44,9 @@ function getUuid() {
43
44
  hex.substring(20, 32)
44
45
  ].join("-");
45
46
  }
46
- function interpolate(strings, values) {
47
- const { length } = strings;
48
- let interpolated = "";
49
- for (let index = 0; index < length; index += 1) interpolated += `${strings[index]}${getString(values[index])}`;
50
- return interpolated;
51
- }
52
47
  /**
53
48
  * Parse a JSON string into its proper value _(or `undefined` if it fails)_
49
+ *
54
50
  * @param value JSON string to parse
55
51
  * @param reviver Reviver function to transform the parsed values
56
52
  * @returns Parsed value or `undefined` if parsing fails
@@ -64,6 +60,7 @@ function parse(value, reviver) {
64
60
  }
65
61
  /**
66
62
  * Trim a string _(removing whitespace from both ends)_
63
+ *
67
64
  * @param value String to trim
68
65
  * @returns Trimmed string
69
66
  */
@@ -71,7 +68,8 @@ function trim(value) {
71
68
  return typeof value === "string" ? value.trim() : "";
72
69
  }
73
70
  /**
74
- * Truncate a string to a specified length, when possible
71
+ * Truncate a string to a specified length
72
+ *
75
73
  * @param value String to truncate
76
74
  * @param length Maximum length of the string after truncation
77
75
  * @param suffix Suffix to append to the truncated string
@@ -1,6 +1,7 @@
1
1
  //#region src/string/match.d.ts
2
2
  /**
3
3
  * Check if a string ends with a specified substring
4
+ *
4
5
  * @param haystack String to look in
5
6
  * @param needle String to look for
6
7
  * @param ignoreCase Ignore case when matching? _(defaults to `false`)_
@@ -9,6 +10,7 @@
9
10
  declare function endsWith(haystack: string, needle: string, ignoreCase?: boolean): boolean;
10
11
  /**
11
12
  * Check if a string includes a specified substring
13
+ *
12
14
  * @param haystack String to look in
13
15
  * @param needle String to look for
14
16
  * @param ignoreCase Ignore case when matching? _(defaults to `false`)_
@@ -17,6 +19,7 @@ declare function endsWith(haystack: string, needle: string, ignoreCase?: boolean
17
19
  declare function includes(haystack: string, needle: string, ignoreCase?: boolean): boolean;
18
20
  /**
19
21
  * Check if a string starts with a specified substring
22
+ *
20
23
  * @param haystack String to look in
21
24
  * @param needle String to look for
22
25
  * @param ignoreCase Ignore case when matching? _(defaults to `false`)_
@@ -2,6 +2,7 @@ import { memoize } from "../function/memoize.mjs";
2
2
  //#region src/string/match.ts
3
3
  /**
4
4
  * Check if a string ends with a specified substring
5
+ *
5
6
  * @param haystack String to look in
6
7
  * @param needle String to look for
7
8
  * @param ignoreCase Ignore case when matching? _(defaults to `false`)_
@@ -12,6 +13,7 @@ function endsWith(haystack, needle, ignoreCase) {
12
13
  }
13
14
  /**
14
15
  * Check if a string includes a specified substring
16
+ *
15
17
  * @param haystack String to look in
16
18
  * @param needle String to look for
17
19
  * @param ignoreCase Ignore case when matching? _(defaults to `false`)_
@@ -30,6 +32,7 @@ function matchCallback(haystack, needle, ignoreCase) {
30
32
  }
31
33
  /**
32
34
  * Check if a string starts with a specified substring
35
+ *
33
36
  * @param haystack String to look in
34
37
  * @param needle String to look for
35
38
  * @param ignoreCase Ignore case when matching? _(defaults to `false`)_
@@ -32,6 +32,7 @@ type NormalizeOptions = {
32
32
  type Normalizer = {
33
33
  /**
34
34
  * Normalize a string
35
+ *
35
36
  * @param value String to normalize
36
37
  * @returns Normalized string
37
38
  */
@@ -39,6 +40,7 @@ type Normalizer = {
39
40
  };
40
41
  /**
41
42
  * Deburr a string, removing diacritical marks
43
+ *
42
44
  * @param value String to deburr
43
45
  * @returns Deburred string
44
46
  */
@@ -46,7 +48,8 @@ declare function deburr(value: string): string;
46
48
  /**
47
49
  * Initialize a string normalizer
48
50
  *
49
- * Available as `initializeNormalizer` and `normalize.initialize`
51
+ * _Available as `initializeNormalizer` and `normalize.initialize`_
52
+ *
50
53
  * @param options Normalization options
51
54
  * @returns Normalizer function
52
55
  */
@@ -54,7 +57,8 @@ declare function initializeNormalizer(options?: NormalizeOptions): Normalizer;
54
57
  /**
55
58
  * Normalize a string
56
59
  *
57
- * By default, the string will be trimmed, deburred, and then lowercased
60
+ * _By default, the string will be trimmed, deburred, and then lowercased_
61
+ *
58
62
  * @param value String to normalize
59
63
  * @param options Normalization options
60
64
  * @returns Normalized string
@@ -4,6 +4,7 @@ import { lowerCase } from "./case.mjs";
4
4
  //#region src/string/normalize.ts
5
5
  /**
6
6
  * Deburr a string, removing diacritical marks
7
+ *
7
8
  * @param value String to deburr
8
9
  * @returns Deburred string
9
10
  */
@@ -29,7 +30,8 @@ function getNormalizeOptions(input) {
29
30
  /**
30
31
  * Initialize a string normalizer
31
32
  *
32
- * Available as `initializeNormalizer` and `normalize.initialize`
33
+ * _Available as `initializeNormalizer` and `normalize.initialize`_
34
+ *
33
35
  * @param options Normalization options
34
36
  * @returns Normalizer function
35
37
  */
@@ -40,7 +42,8 @@ function initializeNormalizer(options) {
40
42
  /**
41
43
  * Normalize a string
42
44
  *
43
- * By default, the string will be trimmed, deburred, and then lowercased
45
+ * _By default, the string will be trimmed, deburred, and then lowercased_
46
+ *
44
47
  * @param value String to normalize
45
48
  * @param options Normalization options
46
49
  * @returns Normalized string
@@ -1,6 +1,14 @@
1
1
  import { PlainObject } from "../models.mjs";
2
2
 
3
3
  //#region src/string/template.d.ts
4
+ /**
5
+ * Renderer for a string template with variables
6
+ *
7
+ * @param variables Variables to use
8
+ * @param options Templating options
9
+ * @returns Templated string
10
+ */
11
+ type Renderer = (variables?: PlainObject, options?: Partial<TemplateOptions>) => string;
4
12
  /**
5
13
  * Options for templating strings
6
14
  */
@@ -14,29 +22,50 @@ type TemplateOptions = {
14
22
  */
15
23
  pattern?: RegExp;
16
24
  };
25
+ type Templater = {
26
+ /**
27
+ * Render a string from a template with variables
28
+ *
29
+ * @returns Templated string
30
+ */
31
+ (strings: TemplateStringsArray, ...values: unknown[]): TemplaterRenderer;
32
+ /**
33
+ * Render a string from a template with variables
34
+ *
35
+ * @param value Template string
36
+ * @param variables Variables to use
37
+ * @returns Templated string
38
+ */
39
+ (value: string, variables?: PlainObject): string;
40
+ };
17
41
  /**
18
- * Render a string from a template with variables
19
- * @param value Template string
20
- * @param variables Variables to use
21
- * @returns Templated string
42
+ * Render a template string with variables
22
43
  */
23
- type Templater = (value: string, variables?: PlainObject) => string;
44
+ type TemplaterRenderer = (variables?: PlainObject) => string;
24
45
  /**
25
- * Create a templater with predefined options
46
+ * Create a _Templater_ with predefined options
47
+ *
48
+ * _Available as `initializeTemplater` and `template.initialize`_
26
49
  *
27
- * Available as `initializeTemplater` and `template.initialize`
28
50
  * @param options Templating options
29
- * @returns Templater function
51
+ * @returns _Templater_ function
30
52
  */
31
53
  declare function initializeTemplater(options?: Partial<TemplateOptions>): Templater;
54
+ /**
55
+ * Get a _Renderer_ for a string template
56
+ *
57
+ * @returns _Renderer_ function
58
+ */
59
+ declare function template(strings: TemplateStringsArray, ...values: unknown[]): Renderer;
32
60
  /**
33
61
  * Render a string from a template with variables
62
+ *
34
63
  * @param value Template string
35
64
  * @param variables Variables to use
36
65
  * @param options Templating options
37
66
  * @returns Templated string
38
67
  */
39
- declare function template(value: string, variables: PlainObject, options?: Partial<TemplateOptions>): string;
68
+ declare function template(value: string, variables?: PlainObject, options?: Partial<TemplateOptions>): string;
40
69
  declare namespace template {
41
70
  var initialize: typeof initializeTemplater;
42
71
  }
@@ -1,7 +1,12 @@
1
- import { isPlainObject } from "../internal/is.mjs";
2
- import { getString } from "../internal/string.mjs";
1
+ import { isPlainObject, isTemplateStringsArray } from "../internal/is.mjs";
2
+ import { getString, interpolate } from "../internal/string.mjs";
3
3
  import { getValue } from "../internal/value/get.mjs";
4
4
  //#region src/string/template.ts
5
+ function getRenderer(strings, values) {
6
+ return (variables, options) => {
7
+ return template(interpolate(strings, values), variables, options);
8
+ };
9
+ }
5
10
  function getTemplateOptions(input) {
6
11
  const options = isPlainObject(input) ? input : {};
7
12
  return {
@@ -11,7 +16,7 @@ function getTemplateOptions(input) {
11
16
  }
12
17
  function handleTemplate(value, pattern, ignoreCase, variables) {
13
18
  if (typeof value !== "string") return "";
14
- if (typeof variables !== "object" || variables === null) return value;
19
+ if (typeof variables !== "object" || variables === null || Object.keys(variables).length === 0) return value;
15
20
  const values = {};
16
21
  return value.replace(pattern, (_, key) => {
17
22
  if (values[key] == null) {
@@ -22,28 +27,23 @@ function handleTemplate(value, pattern, ignoreCase, variables) {
22
27
  });
23
28
  }
24
29
  /**
25
- * Create a templater with predefined options
30
+ * Create a _Templater_ with predefined options
31
+ *
32
+ * _Available as `initializeTemplater` and `template.initialize`_
26
33
  *
27
- * Available as `initializeTemplater` and `template.initialize`
28
34
  * @param options Templating options
29
- * @returns Templater function
35
+ * @returns _Templater_ function
30
36
  */
31
37
  function initializeTemplater(options) {
32
38
  const { ignoreCase, pattern } = getTemplateOptions(options);
33
- return (value, variables) => {
34
- return handleTemplate(value, pattern, ignoreCase, variables);
35
- };
39
+ return ((value, ...parameters) => {
40
+ return isTemplateStringsArray(value) ? (variables) => handleTemplate(interpolate(value, parameters), pattern, ignoreCase, variables) : handleTemplate(value, pattern, ignoreCase, parameters[0]);
41
+ });
36
42
  }
37
- /**
38
- * Render a string from a template with variables
39
- * @param value Template string
40
- * @param variables Variables to use
41
- * @param options Templating options
42
- * @returns Templated string
43
- */
44
- function template(value, variables, options) {
45
- const { ignoreCase, pattern } = getTemplateOptions(options);
46
- return handleTemplate(value, pattern, ignoreCase, variables);
43
+ function template(value, ...parameters) {
44
+ if (isTemplateStringsArray(value)) return getRenderer(value, parameters);
45
+ const { ignoreCase, pattern } = getTemplateOptions(parameters[1]);
46
+ return handleTemplate(value, pattern, ignoreCase, parameters[0]);
47
47
  }
48
48
  template.initialize = initializeTemplater;
49
49
  const EXPRESSION_VARIABLE = /{{([\s\S]+?)}}/g;
@@ -1,8 +1,17 @@
1
1
  import { Constructor, GenericCallback } from "../models.mjs";
2
2
 
3
3
  //#region src/value/clone.d.ts
4
+ /**
5
+ * Clone any kind of value _(shallowly)_
6
+ *
7
+ * @param value Value to clone
8
+ * @param flat Clone only the value itself, without cloning nested values
9
+ * @returns Cloned value
10
+ */
11
+ declare function clone<Value>(value: Value, flat: true): Value;
4
12
  /**
5
13
  * Clone any kind of value _(deeply, if needed)_
14
+ *
6
15
  * @param value Value to clone
7
16
  * @returns Cloned value
8
17
  */
@@ -16,20 +25,32 @@ declare namespace clone {
16
25
  var deregister: typeof deregisterCloner;
17
26
  var register: typeof registerCloner;
18
27
  }
28
+ /**
29
+ * Copy any kind of value
30
+ *
31
+ * - Clones the value shallowly, without cloning nested values
32
+ * - To copy a value deeply, use `clone` instead
33
+ *
34
+ * @param value Value to copy
35
+ * @returns Copied value
36
+ */
37
+ declare function copy<Value>(value: Value): Value;
19
38
  /**
20
39
  * Deregister a clone handler for a specific class
21
40
  *
22
- * Available as `deregisterCloner` and `template.deregister`
41
+ * _Available as `deregisterCloner` and `template.deregister`_
42
+ *
23
43
  * @param constructor Class constructor
24
44
  */
25
45
  declare function deregisterCloner<Instance>(constructor: Constructor<Instance>): void;
26
46
  /**
27
47
  * Register a clone handler for a specific class
28
48
  *
29
- * Available as `registerCloner` and `template.register`
49
+ * _Available as `registerCloner` and `template.register`_
50
+ *
30
51
  * @param constructor Class constructor
31
- * @param handler Method name or clone function _(defaults to `clone`)_
52
+ * @param handler Method name or clone function _(defaults to method name `clone`)_
32
53
  */
33
54
  declare function registerCloner<Instance>(constructor: Constructor<Instance>, handler?: string | ((value: Instance) => Instance)): void;
34
55
  //#endregion
35
- export { clone, deregisterCloner, registerCloner };
56
+ export { clone, copy, deregisterCloner, registerCloner };