@oscarpalmer/atoms 0.213.0 → 0.214.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 (252) hide show
  1. package/dist/array/difference.d.mts +1 -1
  2. package/dist/array/difference.mjs +3 -2
  3. package/dist/array/exists.d.mts +1 -1
  4. package/dist/array/exists.mjs +3 -2
  5. package/dist/array/filter.d.mts +1 -1
  6. package/dist/array/filter.mjs +1 -0
  7. package/dist/array/find.d.mts +1 -1
  8. package/dist/array/find.mjs +4 -3
  9. package/dist/array/first.d.mts +1 -1
  10. package/dist/array/flatten.d.mts +1 -1
  11. package/dist/array/group-by.d.mts +1 -1
  12. package/dist/array/index.d.mts +2 -2
  13. package/dist/array/insert.mjs +3 -2
  14. package/dist/array/intersection.mjs +3 -2
  15. package/dist/array/last.d.mts +1 -1
  16. package/dist/array/move.d.mts +1 -1
  17. package/dist/array/partition.d.mts +1 -1
  18. package/dist/array/partition.mjs +1 -0
  19. package/dist/array/push.mjs +3 -2
  20. package/dist/array/select.d.mts +10 -12
  21. package/dist/array/select.mjs +1 -0
  22. package/dist/array/single.d.mts +1 -1
  23. package/dist/array/single.mjs +1 -0
  24. package/dist/array/slice.d.mts +1 -1
  25. package/dist/array/slice.mjs +4 -5
  26. package/dist/array/sort.d.mts +4 -103
  27. package/dist/array/sort.mjs +6 -14
  28. package/dist/array/splice.mjs +3 -2
  29. package/dist/array/swap.d.mts +1 -1
  30. package/dist/array/to-map.d.mts +1 -1
  31. package/dist/array/to-record.d.mts +1 -1
  32. package/dist/array/to-set.d.mts +1 -1
  33. package/dist/array/toggle.d.mts +1 -1
  34. package/dist/array/union.mjs +3 -2
  35. package/dist/array/unique.d.mts +1 -1
  36. package/dist/array/unique.mjs +3 -2
  37. package/dist/array/update.d.mts +1 -1
  38. package/dist/beacon.d.mts +6 -92
  39. package/dist/beacon.mjs +6 -16
  40. package/dist/color/constants.d.mts +2 -2
  41. package/dist/color/constants.mjs +1 -1
  42. package/dist/color/index.d.mts +1 -1
  43. package/dist/color/instance.d.mts +1 -1
  44. package/dist/color/misc/alpha.d.mts +1 -1
  45. package/dist/color/misc/format.d.mts +1 -1
  46. package/dist/color/misc/get.d.mts +1 -1
  47. package/dist/color/misc/is.d.mts +2 -2
  48. package/dist/color/misc/is.mjs +1 -0
  49. package/dist/color/misc/state.d.mts +1 -1
  50. package/dist/color/space/hex.d.mts +1 -1
  51. package/dist/color/space/hsl.d.mts +1 -1
  52. package/dist/color/space/hwb.d.mts +1 -1
  53. package/dist/color/space/rgb.d.mts +1 -1
  54. package/dist/function/limit.d.mts +2 -2
  55. package/dist/function/limit.mjs +2 -1
  56. package/dist/function/once.d.mts +7 -3
  57. package/dist/function/once.mjs +5 -10
  58. package/dist/function/retry.d.mts +4 -14
  59. package/dist/function/retry.mjs +3 -15
  60. package/dist/herald.d.mts +2 -2
  61. package/dist/index.d.mts +425 -318
  62. package/dist/index.mjs +454 -408
  63. package/dist/internal/aborter.d.mts +1 -6
  64. package/dist/internal/aborter.mjs +3 -4
  65. package/dist/internal/array/callbacks.d.mts +3 -7
  66. package/dist/internal/array/chunk.mjs +2 -2
  67. package/dist/internal/array/find.d.mts +5 -23
  68. package/dist/internal/array/find.mjs +5 -9
  69. package/dist/internal/array/get.d.mts +1 -1
  70. package/dist/internal/array/group.d.mts +1 -1
  71. package/dist/internal/array/index-of.d.mts +1 -1
  72. package/dist/internal/array/index-of.mjs +4 -3
  73. package/dist/internal/array/insert.d.mts +2 -5
  74. package/dist/internal/array/insert.mjs +2 -4
  75. package/dist/internal/array/match.d.mts +2 -5
  76. package/dist/internal/array/match.mjs +10 -20
  77. package/dist/internal/array/overlap.d.mts +2 -10
  78. package/dist/internal/array/sets.d.mts +2 -5
  79. package/dist/internal/array/sets.mjs +5 -7
  80. package/dist/internal/function/assert.d.mts +5 -12
  81. package/dist/internal/function/assert.mjs +2 -2
  82. package/dist/internal/function/limit.d.mts +2 -37
  83. package/dist/internal/function/limit.mjs +4 -15
  84. package/dist/internal/function/memoize.d.mts +5 -70
  85. package/dist/internal/function/memoize.mjs +2 -5
  86. package/dist/internal/function/work.d.mts +16 -22
  87. package/dist/internal/function/work.mjs +1 -8
  88. package/dist/internal/herald.d.mts +3 -3
  89. package/dist/internal/herald.mjs +2 -1
  90. package/dist/internal/is.d.mts +1 -1
  91. package/dist/internal/math/aggregate.d.mts +2 -14
  92. package/dist/internal/math/aggregate.mjs +2 -5
  93. package/dist/internal/number.mjs +4 -7
  94. package/dist/internal/result/attempt.d.mts +1 -1
  95. package/dist/internal/result/misc.d.mts +1 -1
  96. package/dist/internal/string/case.mjs +6 -16
  97. package/dist/internal/string/misc.mjs +1 -2
  98. package/dist/internal/subscription.d.mts +1 -100
  99. package/dist/internal/subscription.mjs +3 -9
  100. package/dist/internal/value/compare.d.mts +4 -4
  101. package/dist/internal/value/compare.mjs +1 -1
  102. package/dist/internal/value/equal.d.mts +6 -57
  103. package/dist/internal/value/equal.mjs +5 -10
  104. package/dist/internal/value/get.d.mts +1 -1
  105. package/dist/internal/value/handlers.d.mts +2 -21
  106. package/dist/internal/value/has.d.mts +2 -2
  107. package/dist/internal/value/misc.d.mts +1 -1
  108. package/dist/internal/value/misc.mjs +8 -14
  109. package/dist/internal/value/set.d.mts +1 -1
  110. package/dist/internal/value/set.mjs +2 -2
  111. package/dist/is.mjs +3 -3
  112. package/dist/logger.d.mts +3 -70
  113. package/dist/logger.mjs +2 -5
  114. package/dist/math.d.mts +1 -1
  115. package/dist/math.mjs +2 -1
  116. package/dist/models/aborter.model.d.mts +12 -0
  117. package/dist/models/aborter.model.mjs +5 -0
  118. package/dist/models/array/array.find.model.d.mts +22 -0
  119. package/dist/models/array/array.find.model.mjs +8 -0
  120. package/dist/models/array/array.match.model.d.mts +14 -0
  121. package/dist/models/array/array.match.model.mjs +14 -0
  122. package/dist/models/array/array.misc.model.d.mts +36 -0
  123. package/dist/models/array/array.misc.model.mjs +12 -0
  124. package/dist/models/array/array.sort.model.d.mts +122 -0
  125. package/dist/models/array/array.sort.model.mjs +12 -0
  126. package/dist/models/beacon.model.d.mts +119 -0
  127. package/dist/models/beacon.model.mjs +16 -0
  128. package/dist/{color/models.d.mts → models/color.model.d.mts} +4 -4
  129. package/dist/models/function/assert.model.d.mts +13 -0
  130. package/dist/models/function/assert.model.mjs +4 -0
  131. package/dist/models/function/limiter.model.d.mts +71 -0
  132. package/dist/models/function/limiter.model.mjs +15 -0
  133. package/dist/models/function/memoize.model.d.mts +88 -0
  134. package/dist/models/function/memoize.model.mjs +7 -0
  135. package/dist/models/function/once.model.d.mts +76 -0
  136. package/dist/models/function/once.model.mjs +9 -0
  137. package/dist/models/function/retry.model.d.mts +17 -0
  138. package/dist/models/function/retry.model.mjs +17 -0
  139. package/dist/models/function/work.model.d.mts +20 -0
  140. package/dist/models/function/work.model.mjs +11 -0
  141. package/dist/{internal/models → models}/herald.model.d.mts +3 -3
  142. package/dist/{internal/models → models}/herald.model.mjs +2 -2
  143. package/dist/{models.d.mts → models/index.d.mts} +5 -47
  144. package/dist/models/logger.model.d.mts +83 -0
  145. package/dist/models/logger.model.mjs +7 -0
  146. package/dist/models/math.model.d.mts +16 -0
  147. package/dist/models/math.model.mjs +7 -0
  148. package/dist/models/misc.model.d.mts +10 -0
  149. package/dist/models/misc.model.mjs +11 -0
  150. package/dist/{internal/models → models}/plan.model.d.mts +3 -3
  151. package/dist/{internal/models → models}/plan.model.mjs +1 -1
  152. package/dist/models/promise.model.d.mts +119 -0
  153. package/dist/models/promise.model.mjs +47 -0
  154. package/dist/models/query.model.d.mts +9 -0
  155. package/dist/models/query.model.mjs +14 -0
  156. package/dist/models/queue.model.d.mts +251 -0
  157. package/dist/models/queue.model.mjs +29 -0
  158. package/dist/models/random.model.d.mts +6 -0
  159. package/dist/models/random.model.mjs +7 -0
  160. package/dist/{internal/models → models}/result.model.d.mts +10 -2
  161. package/dist/models/string/string.case.model.d.mts +19 -0
  162. package/dist/models/string/string.case.model.mjs +14 -0
  163. package/dist/models/string/string.fuzzy.model.d.mts +108 -0
  164. package/dist/models/string/string.fuzzy.model.mjs +9 -0
  165. package/dist/models/string/string.misc.model.d.mts +13 -0
  166. package/dist/models/string/string.misc.model.mjs +13 -0
  167. package/dist/models/string/string.normalize.model.d.mts +85 -0
  168. package/dist/models/string/string.normalize.model.mjs +43 -0
  169. package/dist/models/string/string.template.model.d.mts +50 -0
  170. package/dist/models/string/string.template.model.mjs +5 -0
  171. package/dist/models/subscription.model.d.mts +127 -0
  172. package/dist/models/subscription.model.mjs +10 -0
  173. package/dist/models/value/value.clone.model.d.mts +56 -0
  174. package/dist/models/value/value.clone.model.mjs +24 -0
  175. package/dist/models/value/value.diff.model.d.mts +61 -0
  176. package/dist/models/value/value.diff.model.mjs +6 -0
  177. package/dist/models/value/value.equal.model.d.mts +76 -0
  178. package/dist/models/value/value.equal.model.mjs +9 -0
  179. package/dist/models/value/value.handler.model.d.mts +27 -0
  180. package/dist/models/value/value.handler.model.mjs +1 -0
  181. package/dist/models/value/value.merge.model.d.mts +82 -0
  182. package/dist/models/value/value.merge.model.mjs +5 -0
  183. package/dist/models/value/value.misc.model.d.mts +33 -0
  184. package/dist/models/value/value.misc.model.mjs +12 -0
  185. package/dist/models/value/value.transform.model.d.mts +28 -0
  186. package/dist/models/value/value.transform.model.mjs +4 -0
  187. package/dist/plan/generate.d.mts +3 -2
  188. package/dist/plan/generate.mjs +11 -7
  189. package/dist/plan/index.d.mts +1 -1
  190. package/dist/plan/index.mjs +1 -1
  191. package/dist/plan/is.d.mts +1 -1
  192. package/dist/plan/is.mjs +1 -1
  193. package/dist/plan/misc.d.mts +1 -1
  194. package/dist/plan/models.d.mts +1 -1
  195. package/dist/plan/result.d.mts +2 -2
  196. package/dist/plan/result.mjs +3 -3
  197. package/dist/plan/run.d.mts +1 -1
  198. package/dist/plan/run.mjs +3 -3
  199. package/dist/promise/delay.d.mts +1 -1
  200. package/dist/promise/delay.mjs +2 -1
  201. package/dist/promise/helpers.d.mts +2 -2
  202. package/dist/promise/helpers.mjs +6 -6
  203. package/dist/promise/index.d.mts +2 -2
  204. package/dist/promise/index.mjs +1 -1
  205. package/dist/promise/misc.d.mts +3 -3
  206. package/dist/promise/misc.mjs +7 -4
  207. package/dist/promise/models.d.mts +2 -106
  208. package/dist/promise/models.mjs +1 -35
  209. package/dist/promise/timed.d.mts +2 -2
  210. package/dist/promise/timed.mjs +3 -3
  211. package/dist/query.d.mts +1 -1
  212. package/dist/query.mjs +5 -15
  213. package/dist/queue.d.mts +6 -200
  214. package/dist/queue.mjs +9 -34
  215. package/dist/random.mjs +2 -5
  216. package/dist/result/match.d.mts +1 -1
  217. package/dist/result/match.mjs +27 -15
  218. package/dist/result/misc.d.mts +1 -1
  219. package/dist/result/work/flow.d.mts +13 -21
  220. package/dist/result/work/pipe.d.mts +2 -2
  221. package/dist/string/fuzzy.d.mts +5 -87
  222. package/dist/string/fuzzy.mjs +6 -11
  223. package/dist/string/index.mjs +6 -8
  224. package/dist/string/match.mjs +4 -6
  225. package/dist/string/normalize.d.mts +4 -40
  226. package/dist/string/normalize.mjs +9 -48
  227. package/dist/string/template.d.mts +5 -43
  228. package/dist/string/template.mjs +1 -2
  229. package/dist/subscription.d.mts +2 -1
  230. package/dist/value/clone.d.mts +6 -42
  231. package/dist/value/clone.mjs +10 -30
  232. package/dist/value/collection.mjs +2 -0
  233. package/dist/value/diff.d.mts +3 -44
  234. package/dist/value/diff.mjs +1 -3
  235. package/dist/value/freeze.d.mts +1 -5
  236. package/dist/value/index.d.mts +4 -3
  237. package/dist/value/merge.d.mts +6 -64
  238. package/dist/value/merge.mjs +8 -8
  239. package/dist/value/omit.d.mts +1 -1
  240. package/dist/value/pick.d.mts +1 -1
  241. package/dist/value/shake.d.mts +4 -6
  242. package/dist/value/smush.d.mts +4 -6
  243. package/dist/value/smush.mjs +2 -2
  244. package/dist/value/transform.d.mts +6 -22
  245. package/dist/value/transform.mjs +1 -1
  246. package/dist/value/unsmush.d.mts +4 -10
  247. package/package.json +12 -4
  248. package/dist/promise/constants.d.mts +0 -17
  249. package/dist/promise/constants.mjs +0 -15
  250. /package/dist/{color/models.mjs → models/color.model.mjs} +0 -0
  251. /package/dist/{internal/models/result.model.mjs → models/index.mjs} +0 -0
  252. /package/dist/{models.mjs → models/result.model.mjs} +0 -0
@@ -3,10 +3,9 @@ import { floor } from "../internal/math/misc.mjs";
3
3
  import { max } from "../internal/math/aggregate.mjs";
4
4
  import { getString } from "../internal/string/misc.mjs";
5
5
  import { lowerCase } from "../internal/string/case.mjs";
6
+ import { FUZZY_MESSAGE_ARRAY, FUZZY_MESSAGE_HANDLER, FUZZY_PROPERTY, FUZZY_SYMBOL } from "../models/string/string.fuzzy.model.mjs";
6
7
  import { includes } from "./match.mjs";
7
8
  //#region src/string/fuzzy.ts
8
- const FUZZY_PROPERTY = "$fuzzy";
9
- const FUZZY_SYMBOL = Symbol(FUZZY_PROPERTY);
10
9
  function Fuzzy(state) {
11
10
  this[FUZZY_SYMBOL] = state;
12
11
  }
@@ -94,19 +93,19 @@ function getScore(haystack, needle) {
94
93
  if (haystackIndex === 0) score += 1;
95
94
  if (previousMatchIndex !== -1) {
96
95
  const gap = haystackIndex - previousMatchIndex - 1;
97
- score += max([0, FUZZY_PROXIMITY_THRESHOLD - gap]);
96
+ score += max([0, 5 - gap]);
98
97
  }
99
98
  previousMatchIndex = haystackIndex;
100
99
  needleIndex += 1;
101
100
  }
102
101
  if (needleIndex === needleLength) break;
103
102
  }
104
- score -= floor(lowerCaseHaystack.length / FUZZY_LENGTH_DIVISOR);
103
+ score -= floor(lowerCaseHaystack.length / 3);
105
104
  return max([0, score]);
106
105
  }
107
106
  function getTolerance(input, state) {
108
107
  if (typeof input === "number" && !Number.isNaN(input)) return input < 0 ? 0 : floor(input);
109
- return state?.tolerance ?? FUZZY_PROXIMITY_THRESHOLD;
108
+ return state?.tolerance ?? 5;
110
109
  }
111
110
  /**
112
111
  * Is the value a fuzzy searcher?
@@ -117,7 +116,7 @@ function getTolerance(input, state) {
117
116
  * @returns `true` if the value is a fuzzy searcher, otherwise `false`
118
117
  */
119
118
  function isFuzzy(value) {
120
- return typeof value === "object" && value !== null && FUZZY_PROPERTY in value && value[FUZZY_PROPERTY] === true;
119
+ return typeof value === "object" && value !== null && "$fuzzy" in value && value["$fuzzy"] === true;
121
120
  }
122
121
  function isSubsequence(haystack, needle) {
123
122
  const lowerCaseHaystack = lowerCase(haystack);
@@ -185,12 +184,8 @@ function setFuzzyItems(value) {
185
184
  if (!Array.isArray(value)) throw new TypeError(FUZZY_MESSAGE_ARRAY);
186
185
  const state = this[FUZZY_SYMBOL];
187
186
  state.items = value.slice();
188
- state.strings = value.map(state.handler);
187
+ state.strings = value.map((item) => state.handler(item));
189
188
  }
190
- const FUZZY_LENGTH_DIVISOR = 3;
191
- const FUZZY_MESSAGE_ARRAY = "Fuzzy requires an array of items";
192
- const FUZZY_MESSAGE_HANDLER = "Fuzzy requires a key or function to stringify items";
193
- const FUZZY_PROXIMITY_THRESHOLD = 5;
194
189
  fuzzy.is = isFuzzy;
195
190
  fuzzy.match = fuzzyMatch;
196
191
  //#endregion
@@ -1,6 +1,8 @@
1
1
  import { isTemplateStringsArray } from "../internal/is.mjs";
2
2
  import { min } from "../internal/math/aggregate.mjs";
3
+ import { STRING_EXPRESSION_WHITESPACE_PREFIX } from "../models/string/string.misc.model.mjs";
3
4
  import { getString, interpolate, join, words } from "../internal/string/misc.mjs";
5
+ import { EXPRESSION_NUMERICAL_PREFIX } from "../models/misc.model.mjs";
4
6
  //#region src/string/index.ts
5
7
  function dedent(value, ...values) {
6
8
  let actual;
@@ -13,7 +15,7 @@ function dedent(value, ...values) {
13
15
  const lastIndex = length - 1;
14
16
  const lengths = [];
15
17
  for (let index = 0; index < length; index += 1) {
16
- const [, indentation] = /^(\s+)/.exec(lines[index]) ?? [];
18
+ const [, indentation] = STRING_EXPRESSION_WHITESPACE_PREFIX.exec(lines[index]) ?? [];
17
19
  if (indentation != null) lengths.push(indentation.length);
18
20
  }
19
21
  if (lengths.length === 0) return actual.trim();
@@ -38,16 +40,16 @@ function getUuid(html) {
38
40
  crypto.getRandomValues(bytes);
39
41
  bytes[6] = bytes[6] & 15 | 64;
40
42
  bytes[8] = bytes[8] & 63 | 128;
41
- const hex = Array.from(bytes, (byte) => byte.toString(16).padStart(2, STRING_ZERO)).join("");
43
+ const hex = Array.from(bytes, (byte) => byte.toString(16).padStart(2, "0")).join("");
42
44
  const first = hex.substring(0, 8);
43
- if (forHTML && STRING_NUMERICAL_PREFIX_PATTERN.test(first)) continue;
45
+ if (forHTML && EXPRESSION_NUMERICAL_PREFIX.test(first)) continue;
44
46
  return [
45
47
  first,
46
48
  hex.substring(8, 12),
47
49
  hex.substring(12, 16),
48
50
  hex.substring(16, 20),
49
51
  hex.substring(20, 32)
50
- ].join(forHTML ? STRING_DELIMITER_UUID_HTML : STRING_DELIMITER_UUID_DEFAULT);
52
+ ].join(forHTML ? "_" : "-");
51
53
  }
52
54
  }
53
55
  /**
@@ -90,9 +92,5 @@ function truncate(value, length, suffix) {
90
92
  const truncatedLength = length - actualSuffixLength;
91
93
  return `${value.slice(0, truncatedLength)}${actualSuffix}`;
92
94
  }
93
- const STRING_DELIMITER_UUID_DEFAULT = "-";
94
- const STRING_DELIMITER_UUID_HTML = "_";
95
- const STRING_NUMERICAL_PREFIX_PATTERN = /^\d/;
96
- const STRING_ZERO = "0";
97
95
  //#endregion
98
96
  export { dedent, getString, getUuid, join, parse, trim, truncate, words };
@@ -1,3 +1,4 @@
1
+ import { STRING_MATCH_ENDS_WITH, STRING_MATCH_INCLUDES, STRING_MATCH_STARTS_WITH } from "../models/string/string.misc.model.mjs";
1
2
  import { memoize } from "../internal/function/memoize.mjs";
2
3
  //#region src/string/match.ts
3
4
  /**
@@ -9,7 +10,7 @@ import { memoize } from "../internal/function/memoize.mjs";
9
10
  * @returns `true` if the string ends with the given substring, otherwise `false`
10
11
  */
11
12
  function endsWith(haystack, needle, ignoreCase) {
12
- return match(MATCH_ENDS_WITH, haystack, needle, ignoreCase === true);
13
+ return match(STRING_MATCH_ENDS_WITH, haystack, needle, ignoreCase === true);
13
14
  }
14
15
  /**
15
16
  * Check if a string includes a specified substring
@@ -20,7 +21,7 @@ function endsWith(haystack, needle, ignoreCase) {
20
21
  * @returns `true` if the string includes the given substring, otherwise `false`
21
22
  */
22
23
  function includes(haystack, needle, ignoreCase) {
23
- return match(MATCH_INCLUDES, haystack, needle, ignoreCase === true);
24
+ return match(STRING_MATCH_INCLUDES, haystack, needle, ignoreCase === true);
24
25
  }
25
26
  function match(type, haystack, needle, ignoreCase) {
26
27
  if (typeof haystack !== "string" || typeof needle !== "string") return false;
@@ -39,11 +40,8 @@ function matchCallback(haystack, needle, ignoreCase) {
39
40
  * @returns `true` if the string starts with the given substring, otherwise `false`
40
41
  */
41
42
  function startsWith(haystack, needle, ignoreCase) {
42
- return match(MATCH_STARTS_WITH, haystack, needle, ignoreCase === true);
43
+ return match(STRING_MATCH_STARTS_WITH, haystack, needle, ignoreCase === true);
43
44
  }
44
- const MATCH_ENDS_WITH = "endsWith";
45
- const MATCH_INCLUDES = "includes";
46
- const MATCH_STARTS_WITH = "startsWith";
47
45
  const matchMemoizers = {};
48
46
  //#endregion
49
47
  export { endsWith, includes, startsWith };
@@ -1,43 +1,6 @@
1
+ import { NormalizeOptions, Normalizer, NormalizerOptions } from "../models/string/string.normalize.model.mjs";
1
2
  //#region src/string/normalize.d.ts
2
- /**
3
- * Options for normalizing a string
4
- */
5
- export type NormalizeOptions = {
6
- /**
7
- * Remove diacritical marks from the string? _(defaults to `true`)_
8
- */
9
- deburr?: boolean;
10
- /**
11
- * Convert the string to lower case? _(defaults to `true`)_
12
- */
13
- lowerCase?: boolean;
14
- /**
15
- * Remove special characters from the string? _(defaults to `false`)_
16
- *
17
- * _(Punctuation and symbol characters are considered special)_
18
- */
19
- special?: boolean;
20
- /**
21
- * Trim the string? _(defaults to `true`)_
22
- */
23
- trim?: boolean;
24
- /**
25
- * Shorten consecutive whitespace characters to a single space? _(defaults to `true`)_
26
- */
27
- whitespace?: boolean;
28
- };
29
- /**
30
- * String normalizer function
31
- */
32
- export type Normalizer = {
33
- /**
34
- * Normalize a string
35
- *
36
- * @param value String to normalize
37
- * @returns Normalized string
38
- */
39
- normalize(value: string): string;
40
- };
3
+ declare function Normalizer(this: any, options: NormalizerOptions): void;
41
4
  /**
42
5
  * Deburr a string, removing diacritical marks
43
6
  *
@@ -67,4 +30,5 @@ export declare function normalize(value: string, options?: NormalizeOptions): st
67
30
  export declare namespace normalize {
68
31
  export var initialize: typeof initializeNormalizer;
69
32
  }
70
- //#endregion
33
+ //#endregion
34
+ export type { NormalizeOptions, Normalizer };
@@ -1,12 +1,14 @@
1
1
  import { isPlainObject } from "../internal/is.mjs";
2
+ import { EXPRESSION_WHITESPACE_MULTIPLE } from "../models/misc.model.mjs";
2
3
  import { memoize } from "../internal/function/memoize.mjs";
3
4
  import { lowerCase } from "../internal/string/case.mjs";
5
+ import { NORMALIZE_DEBURR_CHARACTERS, NORMALIZE_DEBURR_PATTERN_CHARACTERS, NORMALIZE_DEBURR_PATTERN_SIMPLE, NORMALIZE_SPECIAL_PATTERN, NORMALIZE_SYMBOL } from "../models/string/string.normalize.model.mjs";
4
6
  //#region src/string/normalize.ts
5
7
  function Normalizer(options) {
6
8
  this[NORMALIZE_SYMBOL] = options;
7
9
  }
8
10
  Normalizer.prototype.normalize = normalizeString;
9
- function createNormalizeOptions(input) {
11
+ function createNormalizerOptions(input) {
10
12
  const options = isPlainObject(input) ? input : {};
11
13
  return {
12
14
  deburr: options.deburr !== false,
@@ -25,7 +27,7 @@ function createNormalizeOptions(input) {
25
27
  function deburr(value) {
26
28
  if (typeof value !== "string") return "";
27
29
  deburrMemoizer ??= memoize((value) => {
28
- let deburred = value.normalize(NORMALIZE_DEBURR_NORMALIZATION).replace(NORMALIZE_DEBURR_PATTERN_SIMPLE, "");
30
+ let deburred = value.normalize("NFD").replace(NORMALIZE_DEBURR_PATTERN_SIMPLE, "");
29
31
  deburred = deburred.replace(NORMALIZE_DEBURR_PATTERN_CHARACTERS, (_, character) => NORMALIZE_DEBURR_CHARACTERS[character]);
30
32
  return deburred;
31
33
  });
@@ -40,7 +42,7 @@ function deburr(value) {
40
42
  * @returns Normalizer function
41
43
  */
42
44
  function initializeNormalizer(options) {
43
- return new Normalizer(createNormalizeOptions(options));
45
+ return new Normalizer(createNormalizerOptions(options));
44
46
  }
45
47
  /**
46
48
  * Normalize a string
@@ -52,60 +54,19 @@ function initializeNormalizer(options) {
52
54
  * @returns Normalized string
53
55
  */
54
56
  function normalize(value, options) {
55
- return normalizeString.call(createNormalizeOptions(options), value);
57
+ return normalizeString.call(createNormalizerOptions(options), value);
56
58
  }
57
59
  function normalizeString(value) {
58
60
  if (typeof value !== "string") return "";
59
61
  const options = NORMALIZE_SYMBOL in this ? this[NORMALIZE_SYMBOL] : this;
60
62
  let result = value;
61
63
  if (options.trim) result = result.trim();
62
- if (options.whitespace) result = result.replace(NORMALIZE_WHITESPACE_PATTERN, NORMALIZE_WHITESPACE_REPLACEMENT);
64
+ if (options.whitespace) result = result.replace(EXPRESSION_WHITESPACE_MULTIPLE, " ");
63
65
  if (options.deburr) result = deburr(result);
64
66
  if (options.lowerCase) result = lowerCase(result);
65
- if (options.special) result = result.replace(NORMALIZE_SPECIAL_PATTERN, NORMALIZE_SPECIAL_REPLACEMENT);
66
- return result.normalize(NORMALIZE_NORMALIZATION_NORMALIZATION);
67
+ if (options.special) result = result.replace(NORMALIZE_SPECIAL_PATTERN, "");
68
+ return result.normalize("NFC");
67
69
  }
68
- const NORMALIZE_DEBURR_CHARACTERS = {
69
- Æ: "AE",
70
- æ: "ae",
71
- Ð: "D",
72
- ð: "d",
73
- Đ: "D",
74
- đ: "d",
75
- Ħ: "H",
76
- ħ: "h",
77
- IJ: "IJ",
78
- ij: "ij",
79
- İ: "I",
80
- ı: "i",
81
- ĸ: "k",
82
- Ŀ: "L",
83
- ŀ: "l",
84
- Ł: "L",
85
- ł: "l",
86
- Ŋ: "N",
87
- ŋ: "n",
88
- ʼn: "'n",
89
- Œ: "OE",
90
- œ: "oe",
91
- Ø: "O",
92
- ø: "o",
93
- ſ: "s",
94
- ß: "ss",
95
- Þ: "TH",
96
- þ: "th",
97
- Ŧ: "T",
98
- ŧ: "t"
99
- };
100
- const NORMALIZE_DEBURR_NORMALIZATION = "NFD";
101
- const NORMALIZE_DEBURR_PATTERN_CHARACTERS = new RegExp(`(${Object.keys(NORMALIZE_DEBURR_CHARACTERS).join("|")})`, "g");
102
- const NORMALIZE_DEBURR_PATTERN_SIMPLE = /[\u0300-\u036f]/g;
103
- const NORMALIZE_NORMALIZATION_NORMALIZATION = "NFC";
104
- const NORMALIZE_SPECIAL_PATTERN = /[\p{P}\p{S}]/gu;
105
- const NORMALIZE_SPECIAL_REPLACEMENT = "";
106
- const NORMALIZE_SYMBOL = Symbol("normalize");
107
- const NORMALIZE_WHITESPACE_PATTERN = /\s+/g;
108
- const NORMALIZE_WHITESPACE_REPLACEMENT = " ";
109
70
  let deburrMemoizer;
110
71
  normalize.initialize = initializeNormalizer;
111
72
  //#endregion
@@ -1,46 +1,7 @@
1
- import { PlainObject } from "../models.mjs";
1
+ import { PlainObject } from "../models/index.mjs";
2
+ import { Renderer, TemplateOptions, Templater, TemplaterOptions, TemplaterRenderer } from "../models/string/string.template.model.mjs";
2
3
  //#region src/string/template.d.ts
3
- /**
4
- * Renderer for a string template with variables
5
- *
6
- * @param variables Variables to use
7
- * @param options Templating options
8
- * @returns Templated string
9
- */
10
- type Renderer = (variables?: PlainObject, options?: Partial<TemplateOptions>) => string;
11
- /**
12
- * Options for templating strings
13
- */
14
- export type TemplateOptions = {
15
- /**
16
- * Ignore case when searching for variables?
17
- */
18
- ignoreCase?: boolean;
19
- /**
20
- * Custom pattern for outputting variables
21
- */
22
- pattern?: RegExp;
23
- };
24
- type Templater = {
25
- /**
26
- * Render a string from a template with variables
27
- *
28
- * @returns Templated string
29
- */
30
- render(strings: TemplateStringsArray, ...values: unknown[]): TemplaterRenderer;
31
- /**
32
- * Render a string from a template with variables
33
- *
34
- * @param value Template string
35
- * @param variables Variables to use
36
- * @returns Templated string
37
- */
38
- render(value: string, variables?: PlainObject): string;
39
- };
40
- /**
41
- * Render a template string with variables
42
- */
43
- type TemplaterRenderer = (variables?: PlainObject) => string;
4
+ declare function Templater(this: any, options: TemplaterOptions): void;
44
5
  /**
45
6
  * Create a _Templater_ with predefined options
46
7
  *
@@ -68,4 +29,5 @@ export declare function template(value: string, variables?: PlainObject, options
68
29
  export declare namespace template {
69
30
  export var initialize: typeof initializeTemplater;
70
31
  }
71
- //#endregion
32
+ //#endregion
33
+ export type { Renderer, TemplateOptions, Templater, TemplaterOptions, TemplaterRenderer };
@@ -1,6 +1,7 @@
1
1
  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
+ import { TEMPLATE_EXPRESSION_VARIABLE, TEMPLATE_SYMBOL } from "../models/string/string.template.model.mjs";
4
5
  //#region src/string/template.ts
5
6
  function Templater(options) {
6
7
  this[TEMPLATE_SYMBOL] = options;
@@ -51,8 +52,6 @@ function template(value, ...parameters) {
51
52
  const { ignoreCase, pattern } = createTemplateOptions(parameters[1]);
52
53
  return handleTemplate(value, pattern, ignoreCase, parameters[0]);
53
54
  }
54
- const TEMPLATE_EXPRESSION_VARIABLE = /{{([\s\S]+?)}}/g;
55
- const TEMPLATE_SYMBOL = Symbol("template");
56
55
  template.initialize = initializeTemplater;
57
56
  //#endregion
58
57
  export { initializeTemplater, template };
@@ -1,2 +1,3 @@
1
- import { Subscription, SubscriptionParameters, SubscriptionProperty, Subscriptions, SubscriptionsParameters, isSubscription, isSubscriptions, subscriptions } from "./internal/subscription.mjs";
1
+ import { Subscription, SubscriptionParameters, SubscriptionProperty, Subscriptions, SubscriptionsParameters } from "./models/subscription.model.mjs";
2
+ import { isSubscription, isSubscriptions, subscriptions } from "./internal/subscription.mjs";
2
3
  export { type Subscription, type SubscriptionParameters, type SubscriptionProperty, type Subscriptions, type SubscriptionsParameters, isSubscription, isSubscriptions, subscriptions };
@@ -1,45 +1,8 @@
1
- import { Constructor } from "../models.mjs";
2
- import { ValueHandler } from "../internal/value/handlers.mjs";
1
+ import { Constructor } from "../models/index.mjs";
2
+ import { ValueHandler } from "../models/value/value.handler.model.mjs";
3
+ import { CloneOptions, Cloner } from "../models/value/value.clone.model.mjs";
3
4
  //#region src/value/clone.d.ts
4
- export type CloneOptions = {
5
- /**
6
- * Copy functions instead of returning `undefined`? _(defaults to `false`)_
7
- */
8
- copyFunctions?: boolean;
9
- /**
10
- * Copy symbols instead of returning `Symbol(description)`? _(defaults to `false`)_
11
- */
12
- copySymbols?: boolean;
13
- };
14
- /**
15
- * A cloning function with predefined options
16
- */
17
- export type Cloner = {
18
- /**
19
- * Clone any kind of value
20
- *
21
- * @param value Value to clone
22
- * @returns Cloned value
23
- */
24
- clone<Value>(value: Value): Value;
25
- /**
26
- * Deregister a clone handler for a specific class
27
- *
28
- * _Available as `deregisterCloner` and `template.deregister`_
29
- *
30
- * @param constructor Class constructor
31
- */
32
- deregister: typeof deregisterCloner;
33
- /**
34
- * Register a clone handler for a specific class
35
- *
36
- * _Available as `registerCloner` and `template.register`_
37
- *
38
- * @param constructor Class constructor
39
- * @param handler Method name or clone function _(defaults to method name `clone`)_
40
- */
41
- register: typeof registerCloner;
42
- };
5
+ declare function Cloner(this: any, options: Required<CloneOptions>): void;
43
6
  /**
44
7
  * Clone any kind of value _(deeply, if needed)_
45
8
  *
@@ -90,4 +53,5 @@ export declare namespace clone {
90
53
  export var initialize: typeof initializeCloner;
91
54
  export var register: typeof registerCloner;
92
55
  }
93
- //#endregion
56
+ //#endregion
57
+ export type { CloneOptions, Cloner };
@@ -2,8 +2,8 @@ import { isArrayOrPlainObject, isTypedArray } from "../internal/is.mjs";
2
2
  import { unwrap } from "../internal/result/misc.mjs";
3
3
  import { attempt } from "../internal/result/attempt.mjs";
4
4
  import { createValueHandler } from "../internal/value/handlers.mjs";
5
+ import { CLONE_COPY_OPTIONS, CLONE_DEFAULT_OPTIONS, CLONE_NAME, CLONE_PRIMITIVES, CLONE_SYMBOL } from "../models/value/value.clone.model.mjs";
5
6
  //#region src/value/clone.ts
6
- const CLONE_NAME = "clone";
7
7
  function Cloner(options) {
8
8
  this[CLONE_SYMBOL] = options;
9
9
  }
@@ -40,14 +40,14 @@ function cloneAny(value, parameters, depth, options) {
40
40
  }
41
41
  }
42
42
  function cloneArrayBuffer(value, parameters, depth) {
43
- if (parameters.copy || depth >= CLONE_MAX_DEPTH) return value;
43
+ if (parameters.copy || depth >= 100) return value;
44
44
  const cloned = new ArrayBuffer(value.byteLength);
45
45
  new Uint8Array(cloned).set(new Uint8Array(value));
46
46
  parameters.references.set(value, cloned);
47
47
  return cloned;
48
48
  }
49
49
  function cloneDataView(value, parameters, depth) {
50
- if (parameters.copy || depth >= CLONE_MAX_DEPTH) return value;
50
+ if (parameters.copy || depth >= 100) return value;
51
51
  const buffer = cloneArrayBuffer(value.buffer, parameters, depth);
52
52
  const cloned = new DataView(buffer, value.byteOffset, value.byteLength);
53
53
  parameters.references.set(value, cloned);
@@ -60,7 +60,7 @@ function cloneFromCloner(value) {
60
60
  }, 0);
61
61
  }
62
62
  function cloneMap(map, parameters, depth) {
63
- if (depth >= CLONE_MAX_DEPTH) return map;
63
+ if (depth >= 100) return map;
64
64
  if (parameters.copy) return new Map(map);
65
65
  const cloned = /* @__PURE__ */ new Map();
66
66
  for (const [key, value] of map.entries()) cloned.set(cloneAny(key, parameters, depth + 1), cloneAny(value, parameters, depth + 1));
@@ -68,13 +68,13 @@ function cloneMap(map, parameters, depth) {
68
68
  return cloned;
69
69
  }
70
70
  function cloneNode(node, parameters, depth) {
71
- if (parameters.copy || depth >= CLONE_MAX_DEPTH) return node;
71
+ if (parameters.copy || depth >= 100) return node;
72
72
  const cloned = node.cloneNode(true);
73
73
  parameters.references.set(node, cloned);
74
74
  return cloned;
75
75
  }
76
76
  function cloneObject(value, parameters, depth) {
77
- if (depth >= CLONE_MAX_DEPTH) return value;
77
+ if (depth >= 100) return value;
78
78
  const isArray = Array.isArray(value);
79
79
  if (parameters.copy) return isArray ? value.slice() : { ...value };
80
80
  const cloned = isArray ? [] : {};
@@ -88,14 +88,14 @@ function cloneObject(value, parameters, depth) {
88
88
  return cloned;
89
89
  }
90
90
  function cloneRegularExpression(value, parameters, depth) {
91
- if (parameters.copy || depth >= CLONE_MAX_DEPTH) return value;
91
+ if (parameters.copy || depth >= 100) return value;
92
92
  const cloned = new RegExp(value.source, value.flags);
93
93
  cloned.lastIndex = value.lastIndex;
94
94
  parameters.references.set(value, cloned);
95
95
  return cloned;
96
96
  }
97
97
  function cloneSet(set, parameters, depth) {
98
- if (depth >= CLONE_MAX_DEPTH) return set;
98
+ if (depth >= 100) return set;
99
99
  if (parameters.copy) return new Set(set);
100
100
  const cloned = /* @__PURE__ */ new Set();
101
101
  for (const value of set.values()) cloned.add(cloneAny(value, parameters, depth + 1));
@@ -103,7 +103,7 @@ function cloneSet(set, parameters, depth) {
103
103
  return cloned;
104
104
  }
105
105
  function cloneTypedArray(value, parameters, depth) {
106
- if (parameters.copy || depth >= CLONE_MAX_DEPTH) return value;
106
+ if (parameters.copy || depth >= 100) return value;
107
107
  const cloned = new value.constructor(value);
108
108
  parameters.references.set(value, cloned);
109
109
  return cloned;
@@ -155,35 +155,15 @@ function registerCloner(constructor, handler) {
155
155
  cloneHandler.base.register(constructor, handler);
156
156
  }
157
157
  function tryStructuredClone(value, parameters, depth) {
158
- if (depth >= CLONE_MAX_DEPTH) return value;
158
+ if (depth >= 100) return value;
159
159
  const cloned = unwrap(attempt(() => structuredClone(value)), value);
160
160
  parameters.references.set(value, cloned);
161
161
  return cloned;
162
162
  }
163
- const CLONE_COPY_OPTIONS = {
164
- copyFunctions: true,
165
- copySymbols: true
166
- };
167
- const CLONE_DEFAULT_OPTIONS = {
168
- copyFunctions: false,
169
- copySymbols: false
170
- };
171
- const CLONE_MAX_DEPTH = 100;
172
163
  const cloneHandler = createValueHandler(clone, {
173
164
  callback: tryStructuredClone,
174
165
  method: CLONE_NAME
175
166
  });
176
- const CLONE_PRIMITIVES = {
177
- bigint: true,
178
- boolean: true,
179
- function: false,
180
- number: true,
181
- object: false,
182
- string: true,
183
- symbol: false,
184
- undefined: true
185
- };
186
- const CLONE_SYMBOL = Symbol(CLONE_NAME);
187
167
  clone.deregister = deregisterCloner;
188
168
  clone.handlers = cloneHandler;
189
169
  clone.initialize = initializeCloner;
@@ -1,3 +1,4 @@
1
+ import { isPrimitive } from "../internal/is.mjs";
1
2
  import { equal } from "../internal/value/equal.mjs";
2
3
  //#region src/value/collection.ts
3
4
  function inMap(map, value, key) {
@@ -18,6 +19,7 @@ function inMap(map, value, key) {
18
19
  function inSet(set, value) {
19
20
  if (!(set instanceof Set)) return false;
20
21
  if (set.has(value)) return true;
22
+ if (isPrimitive(value)) return false;
21
23
  for (const item of set) if (equal(item, value)) return true;
22
24
  return false;
23
25
  }
@@ -1,47 +1,5 @@
1
+ import { DiffOptions, DiffResult } from "../models/value/value.diff.model.mjs";
1
2
  //#region src/value/diff.d.ts
2
- /**
3
- * Options for value comparison
4
- */
5
- export type DiffOptions = {
6
- /**
7
- * Should `null` and `undefined` be considered equal and ignored in results?
8
- */
9
- relaxedNullish?: boolean;
10
- };
11
- /**
12
- * The result of a comparison beteen two values
13
- */
14
- export type DiffResult<First, Second = First> = {
15
- /**
16
- * The original values that were compared
17
- */
18
- original: DiffValue<First, Second>;
19
- /**
20
- * The type of difference between the two values
21
- */
22
- type: DiffType;
23
- /**
24
- * The differences between the two values
25
- *
26
- * - Keys are in dot notation
27
- * - Values are objects with `from` and `to` properties
28
- */
29
- values: Record<string, DiffValue>;
30
- };
31
- type DiffType = "full" | "none" | "partial";
32
- /**
33
- * The difference between two values
34
- */
35
- export type DiffValue<First = unknown, Second = First> = {
36
- /**
37
- * The value from the first value
38
- */
39
- from: First;
40
- /**
41
- * The value from the second value
42
- */
43
- to: Second;
44
- };
45
3
  /**
46
4
  * Find the differences between two values
47
5
  *
@@ -51,4 +9,5 @@ export type DiffValue<First = unknown, Second = First> = {
51
9
  * @returns Difference result
52
10
  */
53
11
  export declare function diff<First, Second = First>(first: First, second: Second, options?: DiffOptions): DiffResult<First, Second>;
54
- //#endregion
12
+ //#endregion
13
+ export type { DiffOptions, DiffResult };
@@ -2,6 +2,7 @@ import { isArrayOrPlainObject } from "../internal/is.mjs";
2
2
  import { max, min } from "../internal/math/aggregate.mjs";
3
3
  import { join } from "../internal/string/misc.mjs";
4
4
  import { equal } from "../internal/value/equal.mjs";
5
+ import { DIFF_FULL, DIFF_NONE, DIFF_PARTIAL } from "../models/value/value.diff.model.mjs";
5
6
  //#region src/value/diff.ts
6
7
  /**
7
8
  * Find the differences between two values
@@ -101,8 +102,5 @@ function setChanges(parameters) {
101
102
  const diffsLength = diffs.length;
102
103
  for (let diffIndex = 0; diffIndex < diffsLength; diffIndex += 1) changes.push(diffs[diffIndex]);
103
104
  }
104
- const DIFF_FULL = "full";
105
- const DIFF_NONE = "none";
106
- const DIFF_PARTIAL = "partial";
107
105
  //#endregion
108
106
  export { diff };
@@ -1,9 +1,5 @@
1
- import { PlainObject } from "../models.mjs";
1
+ import { Frozen, PlainObject } from "../models/index.mjs";
2
2
  //#region src/value/freeze.d.ts
3
- /**
4
- * A frozen value with readonly properties _(going as deep as possible)_
5
- */
6
- export type Frozen<Value> = Value extends unknown[] ? Readonly<Value> : Value extends PlainObject ? { readonly [Key in keyof Value]: Frozen<Value[Key]>; } : Value extends Map<infer Key, infer Value> ? ReadonlyMap<Key, Frozen<Value>> : Value extends Set<infer Item> ? ReadonlySet<Frozen<Item>> : Readonly<Value>;
7
3
  /**
8
4
  * Freeze an array and its indiced values, but not any nested values
9
5
  *
@@ -1,6 +1,7 @@
1
+ import { Shaken, Smushed, Unsmushed } from "../models/value/value.misc.model.mjs";
1
2
  import { omit } from "./omit.mjs";
2
3
  import { pick } from "./pick.mjs";
3
- import { Shaken, shake } from "./shake.mjs";
4
- import { Smushed, smush } from "./smush.mjs";
5
- import { Unsmushed, unsmush } from "./unsmush.mjs";
4
+ import { shake } from "./shake.mjs";
5
+ import { smush } from "./smush.mjs";
6
+ import { unsmush } from "./unsmush.mjs";
6
7
  export { type Shaken, type Smushed, type Unsmushed, omit, pick, shake, smush, unsmush };