@oscarpalmer/atoms 0.74.1 → 0.76.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 (282) hide show
  1. package/dist/js/array/chunk.cjs +18 -0
  2. package/dist/js/array/{chunk.mjs → chunk.js} +2 -2
  3. package/dist/js/array/compact.cjs +6 -0
  4. package/dist/js/array/{compact.mjs → compact.js} +0 -1
  5. package/dist/js/array/count.cjs +14 -0
  6. package/dist/js/array/count.js +14 -0
  7. package/dist/js/array/exists.cjs +14 -0
  8. package/dist/js/array/exists.js +14 -0
  9. package/dist/js/array/filter.cjs +14 -0
  10. package/dist/js/array/filter.js +14 -0
  11. package/dist/js/array/find.cjs +14 -0
  12. package/dist/js/array/find.js +14 -0
  13. package/dist/js/array/group-by.cjs +35 -0
  14. package/dist/js/array/group-by.js +35 -0
  15. package/dist/js/array/index-of.cjs +14 -0
  16. package/dist/js/array/index-of.js +14 -0
  17. package/dist/js/array/index.cjs +40 -0
  18. package/dist/js/array/index.js +34 -381
  19. package/dist/js/array/insert.cjs +31 -0
  20. package/dist/js/array/insert.js +31 -0
  21. package/dist/js/array/models.cjs +1 -0
  22. package/dist/js/array/models.js +1 -0
  23. package/dist/js/array/shuffle.cjs +13 -0
  24. package/dist/js/array/{shuffle.mjs → shuffle.js} +2 -3
  25. package/dist/js/array/sort.cjs +53 -0
  26. package/dist/js/array/{sort.mjs → sort.js} +13 -9
  27. package/dist/js/array/splice.cjs +14 -0
  28. package/dist/js/array/splice.js +14 -0
  29. package/dist/js/array/to-map.cjs +27 -0
  30. package/dist/js/array/to-map.js +27 -0
  31. package/dist/js/array/to-record.cjs +12 -0
  32. package/dist/js/array/to-record.js +12 -0
  33. package/dist/js/array/unique.cjs +7 -0
  34. package/dist/js/array/unique.js +7 -0
  35. package/dist/js/colour/base.cjs +18 -0
  36. package/dist/js/colour/{base.mjs → base.js} +4 -3
  37. package/dist/js/colour/functions.cjs +96 -0
  38. package/dist/js/colour/{functions.mjs → functions.js} +18 -19
  39. package/dist/js/colour/hex.cjs +56 -0
  40. package/dist/js/colour/{hex.mjs → hex.js} +34 -15
  41. package/dist/js/colour/hsl.cjs +85 -0
  42. package/dist/js/colour/{hsl.mjs → hsl.js} +40 -12
  43. package/dist/js/colour/index.cjs +29 -0
  44. package/dist/js/colour/index.js +14 -272
  45. package/dist/js/colour/is.cjs +27 -0
  46. package/dist/js/colour/{is.mjs → is.js} +7 -6
  47. package/dist/js/colour/rgb.cjs +87 -0
  48. package/dist/js/colour/{rgb.mjs → rgb.js} +43 -12
  49. package/dist/js/{emitter.mjs → emitter.cjs} +88 -56
  50. package/dist/js/emitter.js +85 -56
  51. package/dist/js/{function.mjs → function.cjs} +66 -46
  52. package/dist/js/function.js +61 -48
  53. package/dist/js/index.cjs +136 -0
  54. package/dist/js/index.js +133 -1724
  55. package/dist/js/internal/array/callbacks.cjs +23 -0
  56. package/dist/js/internal/array/callbacks.js +23 -0
  57. package/dist/js/internal/array/find.cjs +51 -0
  58. package/dist/js/internal/array/find.js +51 -0
  59. package/dist/js/internal/value/handle.cjs +21 -0
  60. package/dist/js/internal/{value-handle.mjs → value/handle.js} +0 -1
  61. package/dist/js/{is.mjs → is.cjs} +17 -18
  62. package/dist/js/is.js +15 -27
  63. package/dist/js/logger.cjs +108 -0
  64. package/dist/js/logger.js +44 -8
  65. package/dist/js/{math.mjs → math.cjs} +7 -8
  66. package/dist/js/math.js +4 -5
  67. package/dist/js/models.cjs +1 -0
  68. package/dist/js/models.js +1 -0
  69. package/dist/js/{number.mjs → number.cjs} +8 -8
  70. package/dist/js/number.js +5 -5
  71. package/dist/js/{query.mjs → query.cjs} +18 -18
  72. package/dist/js/query.js +17 -86
  73. package/dist/js/{queue.mjs → queue.cjs} +12 -13
  74. package/dist/js/queue.js +9 -10
  75. package/dist/js/{random.mjs → random.cjs} +14 -21
  76. package/dist/js/random.js +9 -26
  77. package/dist/js/{sized.mjs → sized.cjs} +68 -33
  78. package/dist/js/sized.js +66 -38
  79. package/dist/js/string/case.cjs +41 -0
  80. package/dist/js/string/{case.mjs → case.js} +13 -9
  81. package/dist/js/string/index.cjs +59 -0
  82. package/dist/js/string/index.js +30 -100
  83. package/dist/js/string/template.cjs +21 -0
  84. package/dist/js/string/{template.mjs → template.js} +4 -5
  85. package/dist/js/{touch.mjs → touch.cjs} +4 -7
  86. package/dist/js/touch.js +3 -5
  87. package/dist/js/value/clone.cjs +76 -0
  88. package/dist/js/value/{clone.mjs → clone.js} +5 -6
  89. package/dist/js/value/compare.cjs +59 -0
  90. package/dist/js/value/{compare.mjs → compare.js} +4 -6
  91. package/dist/js/value/diff.cjs +75 -0
  92. package/dist/js/value/{diff.mjs → diff.js} +13 -11
  93. package/dist/js/value/equal.cjs +106 -0
  94. package/dist/js/value/{equal.mjs → equal.js} +13 -8
  95. package/dist/js/value/get.cjs +21 -0
  96. package/dist/js/value/{get.mjs → get.js} +9 -4
  97. package/dist/js/value/index.cjs +30 -0
  98. package/dist/js/value/index.js +19 -510
  99. package/dist/js/value/merge.cjs +35 -0
  100. package/dist/js/value/{merge.mjs → merge.js} +7 -6
  101. package/dist/js/value/set.cjs +25 -0
  102. package/dist/js/value/{set.mjs → set.js} +3 -4
  103. package/dist/js/value/smush.cjs +26 -0
  104. package/dist/js/value/{smush.mjs → smush.js} +3 -4
  105. package/dist/js/value/unsmush.cjs +39 -0
  106. package/dist/js/value/{unsmush.mjs → unsmush.js} +10 -7
  107. package/package.json +50 -47
  108. package/src/js/array/chunk.ts +6 -5
  109. package/src/js/array/compact.ts +8 -10
  110. package/src/js/array/count.ts +39 -19
  111. package/src/js/array/exists.ts +39 -15
  112. package/src/js/array/filter.ts +42 -20
  113. package/src/js/array/find.ts +45 -20
  114. package/src/js/array/group-by.ts +158 -27
  115. package/src/js/array/index-of.ts +40 -18
  116. package/src/js/array/index.ts +10 -9
  117. package/src/js/array/insert.ts +28 -14
  118. package/src/js/array/models.ts +18 -15
  119. package/src/js/array/shuffle.ts +3 -3
  120. package/src/js/array/sort.ts +32 -34
  121. package/src/js/array/splice.ts +22 -26
  122. package/src/js/array/to-map.ts +133 -45
  123. package/src/js/array/to-record.ts +137 -39
  124. package/src/js/array/unique.ts +20 -15
  125. package/src/js/colour/base.ts +3 -3
  126. package/src/js/colour/functions.ts +4 -6
  127. package/src/js/colour/hex.ts +5 -5
  128. package/src/js/colour/hsl.ts +18 -12
  129. package/src/js/colour/index.ts +1 -1
  130. package/src/js/colour/is.ts +3 -3
  131. package/src/js/colour/rgb.ts +17 -11
  132. package/src/js/emitter.ts +12 -9
  133. package/src/js/function.ts +17 -17
  134. package/src/js/index.ts +16 -16
  135. package/src/js/internal/array/callbacks.ts +33 -0
  136. package/src/js/internal/{array-find.ts → array/find.ts} +23 -24
  137. package/src/js/internal/{value-handle.ts → value/handle.ts} +1 -1
  138. package/src/js/is.ts +2 -2
  139. package/src/js/logger.ts +14 -14
  140. package/src/js/math.ts +1 -1
  141. package/src/js/models.ts +5 -5
  142. package/src/js/number.ts +2 -2
  143. package/src/js/query.ts +6 -10
  144. package/src/js/queue.ts +1 -1
  145. package/src/js/random.ts +9 -19
  146. package/src/js/sized.ts +145 -145
  147. package/src/js/string/case.ts +1 -1
  148. package/src/js/string/index.ts +13 -7
  149. package/src/js/string/template.ts +6 -3
  150. package/src/js/value/clone.ts +3 -7
  151. package/src/js/value/compare.ts +3 -5
  152. package/src/js/value/diff.ts +4 -4
  153. package/src/js/value/equal.ts +2 -2
  154. package/src/js/value/get.ts +3 -3
  155. package/src/js/value/index.ts +2 -2
  156. package/src/js/value/merge.ts +3 -3
  157. package/src/js/value/set.ts +3 -4
  158. package/src/js/value/smush.ts +4 -4
  159. package/src/js/value/unsmush.ts +4 -4
  160. package/types/array/chunk.d.cts +8 -0
  161. package/types/array/chunk.d.ts +2 -2
  162. package/types/array/compact.d.cts +12 -0
  163. package/types/array/compact.d.ts +4 -4
  164. package/types/array/count.d.cts +24 -0
  165. package/types/array/count.d.ts +13 -7
  166. package/types/array/exists.d.cts +26 -0
  167. package/types/array/exists.d.ts +11 -3
  168. package/types/array/filter.d.cts +26 -0
  169. package/types/array/filter.d.ts +14 -6
  170. package/types/array/find.d.cts +26 -0
  171. package/types/array/find.d.ts +14 -6
  172. package/types/array/group-by.d.cts +58 -0
  173. package/types/array/group-by.d.ts +49 -5
  174. package/types/array/index-of.d.cts +26 -0
  175. package/types/array/index-of.d.ts +14 -6
  176. package/types/array/index.d.cts +239 -95
  177. package/types/array/index.d.ts +7 -6
  178. package/types/array/insert.d.cts +16 -0
  179. package/types/array/insert.d.ts +10 -5
  180. package/types/array/models.d.cts +14 -11
  181. package/types/array/models.d.ts +14 -12
  182. package/types/array/shuffle.d.cts +8 -0
  183. package/types/array/shuffle.d.ts +2 -2
  184. package/types/array/sort.d.cts +24 -0
  185. package/types/array/sort.d.ts +10 -10
  186. package/types/array/splice.d.cts +22 -0
  187. package/types/array/splice.d.ts +4 -4
  188. package/types/array/to-map.d.cts +61 -0
  189. package/types/array/to-map.d.ts +42 -20
  190. package/types/array/to-record.d.cts +61 -0
  191. package/types/array/to-record.d.ts +42 -20
  192. package/types/array/unique.d.cts +21 -0
  193. package/types/array/unique.d.ts +10 -6
  194. package/types/colour/base.d.cts +153 -0
  195. package/types/colour/base.d.ts +2 -2
  196. package/types/colour/functions.d.cts +173 -0
  197. package/types/colour/functions.d.ts +3 -3
  198. package/types/colour/hex.d.cts +157 -0
  199. package/types/colour/hex.d.ts +4 -4
  200. package/types/colour/hsl.d.cts +157 -0
  201. package/types/colour/hsl.d.ts +16 -10
  202. package/types/colour/index.d.cts +28 -16
  203. package/types/colour/index.d.ts +1 -1
  204. package/types/colour/is.d.cts +170 -0
  205. package/types/colour/is.d.ts +3 -3
  206. package/types/colour/rgb.d.cts +157 -0
  207. package/types/colour/rgb.d.ts +15 -9
  208. package/types/emitter.d.cts +11 -8
  209. package/types/emitter.d.ts +11 -8
  210. package/types/function.d.cts +10 -10
  211. package/types/function.d.ts +11 -11
  212. package/types/index.d.cts +1120 -736
  213. package/types/index.d.ts +16 -16
  214. package/types/internal/array/callbacks.d.cts +11 -0
  215. package/types/internal/array/callbacks.d.ts +2 -0
  216. package/types/internal/array/find.d.cts +7 -0
  217. package/types/internal/array/find.d.ts +3 -0
  218. package/types/internal/value/handle.d.cts +37 -0
  219. package/types/internal/{value-handle.d.ts → value/handle.d.ts} +1 -1
  220. package/types/is.d.ts +1 -1
  221. package/types/logger.d.cts +13 -21
  222. package/types/logger.d.ts +13 -21
  223. package/types/math.d.cts +1 -1
  224. package/types/math.d.ts +1 -1
  225. package/types/models.d.cts +4 -4
  226. package/types/models.d.ts +1 -4
  227. package/types/number.d.cts +2 -2
  228. package/types/number.d.ts +2 -2
  229. package/types/query.d.cts +2 -2
  230. package/types/query.d.ts +3 -3
  231. package/types/queue.d.cts +1 -1
  232. package/types/queue.d.ts +1 -1
  233. package/types/random.d.cts +8 -12
  234. package/types/random.d.ts +8 -12
  235. package/types/sized.d.cts +6 -6
  236. package/types/sized.d.ts +6 -6
  237. package/types/string/case.d.cts +28 -0
  238. package/types/string/index.d.cts +30 -27
  239. package/types/string/index.d.ts +3 -3
  240. package/types/string/template.d.cts +50 -0
  241. package/types/string/template.d.ts +4 -1
  242. package/types/value/clone.d.cts +8 -0
  243. package/types/value/clone.d.ts +4 -2
  244. package/types/value/compare.d.cts +8 -0
  245. package/types/value/diff.d.cts +25 -0
  246. package/types/value/equal.d.cts +12 -0
  247. package/types/value/get.d.cts +1319 -0
  248. package/types/value/get.d.ts +1 -1
  249. package/types/value/index.d.cts +8 -6
  250. package/types/value/index.d.ts +2 -2
  251. package/types/value/merge.d.cts +72 -0
  252. package/types/value/merge.d.ts +2 -2
  253. package/types/value/set.d.cts +1011 -0
  254. package/types/value/set.d.ts +1 -1
  255. package/types/value/smush.d.cts +1368 -0
  256. package/types/value/smush.d.ts +2 -2
  257. package/types/value/unsmush.d.cts +141 -0
  258. package/types/value/unsmush.d.ts +2 -2
  259. package/dist/js/array/count.mjs +0 -8
  260. package/dist/js/array/exists.mjs +0 -8
  261. package/dist/js/array/filter.mjs +0 -8
  262. package/dist/js/array/find.mjs +0 -8
  263. package/dist/js/array/group-by.mjs +0 -33
  264. package/dist/js/array/index-of.mjs +0 -8
  265. package/dist/js/array/index.mjs +0 -34
  266. package/dist/js/array/insert.mjs +0 -22
  267. package/dist/js/array/models.mjs +0 -0
  268. package/dist/js/array/splice.mjs +0 -9
  269. package/dist/js/array/to-map.mjs +0 -27
  270. package/dist/js/array/to-record.mjs +0 -8
  271. package/dist/js/array/unique.mjs +0 -8
  272. package/dist/js/colour/index.mjs +0 -30
  273. package/dist/js/index.mjs +0 -17
  274. package/dist/js/internal/array-callbacks.mjs +0 -19
  275. package/dist/js/internal/array-find.mjs +0 -51
  276. package/dist/js/logger.mjs +0 -69
  277. package/dist/js/models.mjs +0 -0
  278. package/dist/js/string/index.mjs +0 -44
  279. package/dist/js/value/index.mjs +0 -23
  280. package/src/js/internal/array-callbacks.ts +0 -28
  281. package/types/internal/array-callbacks.d.ts +0 -2
  282. package/types/internal/array-find.d.ts +0 -4
@@ -1,521 +1,30 @@
1
- // src/js/value/index.ts
1
+ import { clone } from "./clone.js";
2
+ import { compare } from "./compare.js";
3
+ import { diff } from "./diff.js";
4
+ import { equal } from "./equal.js";
5
+ import { getValue } from "./get.js";
6
+ import { merge } from "./merge.js";
7
+ import { setValue } from "./set.js";
8
+ import { smush } from "./smush.js";
9
+ import { unsmush } from "./unsmush.js";
2
10
  function partial(value, keys) {
3
11
  const result = {};
4
12
  const { length } = keys;
5
- for (let index = 0;index < length; index += 1) {
13
+ for (let index = 0; index < length; index += 1) {
6
14
  const key = keys[index];
7
15
  result[key] = value[key];
8
16
  }
9
17
  return result;
10
18
  }
11
- // src/js/array/compact.ts
12
- function compact(array, strict) {
13
- return strict === true ? array.filter((item) => !!item) : array.filter((item) => item != null);
14
- }
15
- // src/js/math.ts
16
- function max(values) {
17
- return values.length > 0 ? Math.max(...values) : Number.NaN;
18
- }
19
-
20
- // src/js/number.ts
21
- function getNumber(value) {
22
- if (typeof value === "number") {
23
- return value;
24
- }
25
- if (typeof value === "symbol") {
26
- return Number.NaN;
27
- }
28
- let parsed = value?.valueOf?.() ?? value;
29
- if (typeof parsed === "object") {
30
- parsed = parsed?.toString() ?? parsed;
31
- }
32
- if (typeof parsed !== "string") {
33
- return parsed == null ? Number.NaN : typeof parsed === "number" ? parsed : +parsed;
34
- }
35
- if (/^\s*0+\s*$/.test(parsed)) {
36
- return 0;
37
- }
38
- const trimmed = parsed.trim();
39
- if (trimmed.length === 0) {
40
- return Number.NaN;
41
- }
42
- const isBinary = /^0b[01]+$/i.test(trimmed);
43
- if (isBinary || /^0o[0-7]+$/i.test(trimmed)) {
44
- return Number.parseInt(trimmed.slice(2), isBinary ? 2 : 8);
45
- }
46
- return +(/^0x[0-9a-f]+$/i.test(trimmed) ? trimmed : trimmed.replace(/_/g, ""));
47
- }
48
-
49
- // src/js/value/compare.ts
50
- function compare(first, second) {
51
- const firstParts = getParts(first);
52
- const secondParts = getParts(second);
53
- const length = max([firstParts.length, secondParts.length]);
54
- const lastIndex = length - 1;
55
- for (let index = 0;index < length; index += 1) {
56
- const firstPart = firstParts[index];
57
- const secondPart = secondParts[index];
58
- if (firstPart === secondPart) {
59
- if (index === lastIndex) {
60
- return 0;
61
- }
62
- continue;
63
- }
64
- if (firstPart == null || typeof firstPart === "string" && firstPart.length === 0) {
65
- return -1;
66
- }
67
- if (secondPart == null || typeof secondPart === "string" && secondPart.length === 0) {
68
- return 1;
69
- }
70
- const firstNumber = getNumber(firstPart);
71
- const secondNumber = getNumber(secondPart);
72
- const firstIsNaN = Number.isNaN(firstNumber);
73
- const secondIsNaN = Number.isNaN(secondNumber);
74
- if (firstIsNaN || secondIsNaN) {
75
- if (firstIsNaN && secondIsNaN) {
76
- return getString(firstPart).localeCompare(getString(secondPart));
77
- }
78
- if (firstIsNaN) {
79
- return 1;
80
- }
81
- if (secondIsNaN) {
82
- return -1;
83
- }
84
- }
85
- if (firstNumber === secondNumber) {
86
- if (index === lastIndex) {
87
- return 0;
88
- }
89
- continue;
90
- }
91
- return firstNumber - secondNumber;
92
- }
93
- return join(firstParts).localeCompare(join(secondParts));
94
- }
95
- function getParts(value) {
96
- if (value == null) {
97
- return [""];
98
- }
99
- if (Array.isArray(value)) {
100
- return value;
101
- }
102
- return typeof value === "object" ? [value] : words(getString(value));
103
- }
104
- // src/js/string/index.ts
105
- function getString(value) {
106
- if (typeof value === "string") {
107
- return value;
108
- }
109
- if (typeof value !== "object" || value == null) {
110
- return String(value);
111
- }
112
- const valueOff = value.valueOf?.() ?? value;
113
- const asString = valueOff?.toString?.() ?? String(valueOff);
114
- return asString.startsWith("[object ") ? JSON.stringify(value) : asString;
115
- }
116
- function join(value, delimiter) {
117
- return compact(value).map(getString).filter((value2) => value2.trim().length > 0).join(typeof delimiter === "string" ? delimiter : "");
118
- }
119
- function words(value) {
120
- return value.match(/[^\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\x7f]+/g) ?? [];
121
- }
122
-
123
- // src/js/is.ts
124
- function isArrayOrPlainObject(value) {
125
- return Array.isArray(value) || isPlainObject(value);
126
- }
127
- function isPlainObject(value) {
128
- if (typeof value !== "object" || value === null) {
129
- return false;
130
- }
131
- const prototype = Object.getPrototypeOf(value);
132
- return (prototype === null || prototype === Object.prototype || Object.getPrototypeOf(prototype) === null) && !(Symbol.toStringTag in value) && !(Symbol.iterator in value);
133
- }
134
-
135
- // src/js/value/clone.ts
136
- function clone(value) {
137
- switch (true) {
138
- case value == null:
139
- return value;
140
- case typeof value === "bigint":
141
- return BigInt(value);
142
- case typeof value === "boolean":
143
- return Boolean(value);
144
- case typeof value === "function":
145
- return;
146
- case typeof value === "number":
147
- return Number(value);
148
- case typeof value === "string":
149
- return String(value);
150
- case typeof value === "symbol":
151
- return Symbol(value.description);
152
- case value instanceof ArrayBuffer:
153
- return cloneArrayBuffer(value);
154
- case value instanceof DataView:
155
- return cloneDataView(value);
156
- case value instanceof Map:
157
- case value instanceof Set:
158
- return cloneMapOrSet(value);
159
- case value instanceof Node:
160
- return value.cloneNode(true);
161
- case value instanceof RegExp:
162
- return cloneRegularExpression(value);
163
- case isArrayOrPlainObject(value):
164
- return cloneObject(value);
165
- default:
166
- return structuredClone(value);
167
- }
168
- }
169
- function cloneArrayBuffer(value) {
170
- const cloned = new ArrayBuffer(value.byteLength);
171
- new Uint8Array(cloned).set(new Uint8Array(value));
172
- return cloned;
173
- }
174
- function cloneDataView(value) {
175
- const buffer = cloneArrayBuffer(value.buffer);
176
- return new DataView(buffer, value.byteOffset, value.byteLength);
177
- }
178
- function cloneMapOrSet(value) {
179
- const isMap = value instanceof Map;
180
- const cloned = isMap ? new Map : new Set;
181
- const entries = [...value.entries()];
182
- const { length } = entries;
183
- for (let index = 0;index < length; index += 1) {
184
- const entry = entries[index];
185
- if (isMap) {
186
- cloned.set(clone(entry[0]), clone(entry[1]));
187
- } else {
188
- cloned.add(clone(entry[0]));
189
- }
190
- }
191
- return cloned;
192
- }
193
- function cloneObject(value) {
194
- const cloned = Array.isArray(value) ? [] : {};
195
- const keys = Object.keys(value);
196
- const { length } = keys;
197
- for (let index = 0;index < length; index += 1) {
198
- const key = keys[index];
199
- cloned[key] = clone(value[key]);
200
- }
201
- return cloned;
202
- }
203
- function cloneRegularExpression(value) {
204
- const cloned = new RegExp(value.source, value.flags);
205
- cloned.lastIndex = value.lastIndex;
206
- return cloned;
207
- }
208
- // src/js/value/equal.ts
209
- function equal(first, second, ignoreCase) {
210
- switch (true) {
211
- case first === second:
212
- return true;
213
- case (first == null || second == null):
214
- return first === second;
215
- case typeof first !== typeof second:
216
- return false;
217
- case (first instanceof ArrayBuffer && second instanceof ArrayBuffer):
218
- return equalArrayBuffer(first, second);
219
- case typeof first === "boolean":
220
- case (first instanceof Date && second instanceof Date):
221
- return Object.is(Number(first), Number(second));
222
- case (first instanceof DataView && second instanceof DataView):
223
- return equalDataView(first, second);
224
- case (first instanceof Error && second instanceof Error):
225
- return equalProperties(first, second, ["name", "message"]);
226
- case (first instanceof Map && second instanceof Map):
227
- return equalMap(first, second);
228
- case (first instanceof RegExp && second instanceof RegExp):
229
- return equalProperties(first, second, ["source", "flags"]);
230
- case (first instanceof Set && second instanceof Set):
231
- return equalSet(first, second);
232
- case (Array.isArray(first) && Array.isArray(second)):
233
- case (isPlainObject(first) && isPlainObject(second)):
234
- return equalObject(first, second);
235
- case (typeof first === "string" && ignoreCase === true):
236
- return Object.is(first.toLowerCase(), second.toLowerCase());
237
- default:
238
- return Object.is(first, second);
239
- }
240
- }
241
- function equalArrayBuffer(first, second) {
242
- return first.byteLength === second.byteLength ? equalObject(new Uint8Array(first), new Uint8Array(second)) : false;
243
- }
244
- function equalDataView(first, second) {
245
- return first.byteOffset === second.byteOffset ? equalArrayBuffer(first.buffer, second.buffer) : false;
246
- }
247
- function equalMap(first, second) {
248
- const { size } = first;
249
- if (size !== second.size) {
250
- return false;
251
- }
252
- const firstKeys = [...first.keys()];
253
- const secondKeys = [...second.keys()];
254
- if (firstKeys.some((key) => !secondKeys.includes(key))) {
255
- return false;
256
- }
257
- for (let index = 0;index < size; index += 1) {
258
- const key = firstKeys[index];
259
- if (!equal(first.get(key), second.get(key))) {
260
- return false;
261
- }
262
- }
263
- return true;
264
- }
265
- function equalObject(first, second) {
266
- const firstKeys = Object.keys(first);
267
- const secondKeys = Object.keys(second);
268
- const { length } = firstKeys;
269
- if (length !== secondKeys.length || firstKeys.some((key) => !secondKeys.includes(key))) {
270
- return false;
271
- }
272
- for (let index = 0;index < length; index += 1) {
273
- const key = firstKeys[index];
274
- if (!equal(first[key], second[key])) {
275
- return false;
276
- }
277
- }
278
- return true;
279
- }
280
- function equalProperties(first, second, properties) {
281
- const { length } = properties;
282
- for (let index = 0;index < length; index += 1) {
283
- const property = properties[index];
284
- if (!equal(first[property], second[property])) {
285
- return false;
286
- }
287
- }
288
- return true;
289
- }
290
- function equalSet(first, second) {
291
- const { size } = first;
292
- if (size !== second.size) {
293
- return false;
294
- }
295
- const firstValues = [...first];
296
- const secondValues = [...second];
297
- for (let index = 0;index < size; index += 1) {
298
- const firstValue = firstValues[index];
299
- if (!secondValues.some((secondValue) => equal(firstValue, secondValue))) {
300
- return false;
301
- }
302
- }
303
- return true;
304
- }
305
-
306
- // src/js/value/diff.ts
307
- function diff(first, second) {
308
- const result = {
309
- original: {
310
- from: first,
311
- to: second
312
- },
313
- type: "partial",
314
- values: {}
315
- };
316
- const same = Object.is(first, second);
317
- const firstIsArrayOrObject = isArrayOrPlainObject(first);
318
- const secondIsArrayOrObject = isArrayOrPlainObject(second);
319
- if (same || !firstIsArrayOrObject && !secondIsArrayOrObject) {
320
- result.type = same ? "none" : "full";
321
- return result;
322
- }
323
- if (firstIsArrayOrObject !== secondIsArrayOrObject) {
324
- result.type = "full";
325
- }
326
- const diffs = getDiffs(first, second);
327
- const { length } = diffs;
328
- if (length === 0) {
329
- result.type = "none";
330
- }
331
- for (let index = 0;index < length; index += 1) {
332
- const diff2 = diffs[index];
333
- result.values[diff2.key] = { from: diff2.from, to: diff2.to };
334
- }
335
- return result;
336
- }
337
- function getDiffs(first, second, prefix) {
338
- const changes = [];
339
- const checked = new Set;
340
- for (let outerIndex = 0;outerIndex < 2; outerIndex += 1) {
341
- const value = outerIndex === 0 ? first : second;
342
- if (!value) {
343
- continue;
344
- }
345
- const keys = Object.keys(value);
346
- const { length } = keys;
347
- for (let innerIndex = 0;innerIndex < length; innerIndex += 1) {
348
- const key = keys[innerIndex];
349
- if (checked.has(key)) {
350
- continue;
351
- }
352
- const from = first?.[key];
353
- const to = second?.[key];
354
- if (!equal(from, to)) {
355
- const prefixed = join([prefix, key], ".");
356
- const change = {
357
- from,
358
- to,
359
- key: prefixed
360
- };
361
- const nested = isArrayOrPlainObject(from) || isArrayOrPlainObject(to);
362
- const diffs = nested ? getDiffs(from, to, prefixed) : [];
363
- if (!nested || nested && diffs.length > 0) {
364
- changes.push(change);
365
- }
366
- changes.push(...diffs);
367
- }
368
- checked.add(key);
369
- }
370
- }
371
- return changes;
372
- }
373
- // src/js/internal/value-handle.ts
374
- function findKey(needle, haystack, ignoreCase) {
375
- if (!ignoreCase) {
376
- return needle;
377
- }
378
- const keys = Object.keys(haystack);
379
- const normalised = keys.map((key) => key.toLowerCase());
380
- const index = normalised.indexOf(needle.toLowerCase());
381
- return index > -1 ? keys[index] : needle;
382
- }
383
- function handleValue(data, path, value, get, ignoreCase) {
384
- if (typeof data === "object" && data !== null && !/^(__proto__|constructor|prototype)$/i.test(path)) {
385
- const key = findKey(path, data, ignoreCase);
386
- if (get) {
387
- return data[key];
388
- }
389
- data[key] = value;
390
- }
391
- }
392
-
393
- // src/js/value/get.ts
394
- function getValue(data, path, ignoreCase) {
395
- const shouldIgnoreCase = ignoreCase === true;
396
- const parts = (shouldIgnoreCase ? path.toLowerCase() : path).split(".");
397
- const { length } = parts;
398
- let index = 0;
399
- let value = typeof data === "object" ? data ?? {} : {};
400
- while (index < length && value != null) {
401
- value = handleValue(value, parts[index++], null, true, shouldIgnoreCase);
402
- }
403
- return value;
404
- }
405
- // src/js/value/merge.ts
406
- function merge(values, options) {
407
- if (values.length === 0) {
408
- return {};
409
- }
410
- const skipNullable = options?.skipNullable ?? false;
411
- const actual = values.filter((value) => isArrayOrPlainObject(value));
412
- const result = actual.every(Array.isArray) ? [] : {};
413
- const isArray = Array.isArray(result);
414
- const { length } = actual;
415
- for (let outerIndex = 0;outerIndex < length; outerIndex += 1) {
416
- const item = actual[outerIndex];
417
- const keys = Object.keys(item);
418
- const size = keys.length;
419
- for (let innerIndex = 0;innerIndex < size; innerIndex += 1) {
420
- const key = keys[innerIndex];
421
- const next = item[key];
422
- const previous = result[key];
423
- if (isArray && skipNullable && next == null) {
424
- continue;
425
- }
426
- if (isArrayOrPlainObject(next)) {
427
- result[key] = isArrayOrPlainObject(previous) ? merge([previous, next]) : merge([next]);
428
- } else {
429
- result[key] = next;
430
- }
431
- }
432
- }
433
- return result;
434
- }
435
- // src/js/value/set.ts
436
- function setValue(data, path, value, ignoreCase) {
437
- const shouldIgnoreCase = ignoreCase === true;
438
- const parts = (shouldIgnoreCase ? path.toLowerCase() : path).split(".");
439
- const { length } = parts;
440
- const lastIndex = length - 1;
441
- let target = typeof data === "object" && data !== null ? data : {};
442
- for (let index = 0;index < length; index += 1) {
443
- const part = parts[index];
444
- if (index === lastIndex) {
445
- handleValue(target, part, value, false, shouldIgnoreCase);
446
- break;
447
- }
448
- let next = handleValue(target, part, null, true, shouldIgnoreCase);
449
- if (typeof next !== "object" || next === null) {
450
- next = {};
451
- target[part] = next;
452
- }
453
- target = next;
454
- }
455
- return data;
456
- }
457
- // src/js/value/smush.ts
458
- function flatten(value, prefix) {
459
- const keys = Object.keys(value);
460
- const { length } = keys;
461
- const smushed = {};
462
- for (let index = 0;index < length; index += 1) {
463
- const key = keys[index];
464
- const val = value[key];
465
- if (isArrayOrPlainObject(val)) {
466
- Object.assign(smushed, {
467
- [join([prefix, key], ".")]: Array.isArray(val) ? [...val] : { ...val },
468
- ...flatten(val, join([prefix, key], "."))
469
- });
470
- } else {
471
- smushed[join([prefix, key], ".")] = val;
472
- }
473
- }
474
- return smushed;
475
- }
476
- function smush(value) {
477
- return flatten(value);
478
- }
479
- // src/js/value/unsmush.ts
480
- function getKeyGroups(value) {
481
- const keys = Object.keys(value);
482
- const { length } = keys;
483
- const grouped = [];
484
- for (let index = 0;index < length; index += 1) {
485
- const key = keys[index];
486
- const dots = key.split(".");
487
- if (grouped[dots.length] == null) {
488
- grouped[dots.length] = [key];
489
- } else {
490
- grouped[dots.length].push(key);
491
- }
492
- }
493
- return grouped;
494
- }
495
- function unsmush(value) {
496
- const groups = getKeyGroups(value);
497
- const { length } = groups;
498
- const unsmushed = {};
499
- for (let groupIndex = 1;groupIndex < length; groupIndex += 1) {
500
- const group = groups[groupIndex];
501
- const groupLength = group.length;
502
- for (let keyIndex = 0;keyIndex < groupLength; keyIndex += 1) {
503
- const key = group[keyIndex];
504
- const val = value[key];
505
- setValue(unsmushed, key, isArrayOrPlainObject(val) ? Array.isArray(val) ? [...val] : { ...val } : val);
506
- }
507
- }
508
- return unsmushed;
509
- }
510
19
  export {
511
- unsmush,
512
- smush,
513
- setValue,
514
- partial,
515
- merge,
516
- getValue,
517
- equal,
518
- diff,
20
+ clone,
519
21
  compare,
520
- clone
22
+ diff,
23
+ equal,
24
+ getValue,
25
+ merge,
26
+ partial,
27
+ setValue,
28
+ smush,
29
+ unsmush
521
30
  };
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const is = require("../is.cjs");
4
+ function merge(values, options) {
5
+ if (values.length === 0) {
6
+ return {};
7
+ }
8
+ const skipNullable = (options == null ? void 0 : options.skipNullable) ?? false;
9
+ const actual = values.filter(
10
+ (value) => is.isArrayOrPlainObject(value)
11
+ );
12
+ const result = actual.every(Array.isArray) ? [] : {};
13
+ const isArray = Array.isArray(result);
14
+ const { length } = actual;
15
+ for (let outerIndex = 0; outerIndex < length; outerIndex += 1) {
16
+ const item = actual[outerIndex];
17
+ const keys = Object.keys(item);
18
+ const size = keys.length;
19
+ for (let innerIndex = 0; innerIndex < size; innerIndex += 1) {
20
+ const key = keys[innerIndex];
21
+ const next = item[key];
22
+ const previous = result[key];
23
+ if (isArray && skipNullable && next == null) {
24
+ continue;
25
+ }
26
+ if (is.isArrayOrPlainObject(next)) {
27
+ result[key] = is.isArrayOrPlainObject(previous) ? merge([previous, next]) : merge([next]);
28
+ } else {
29
+ result[key] = next;
30
+ }
31
+ }
32
+ }
33
+ return result;
34
+ }
35
+ exports.merge = merge;
@@ -1,19 +1,20 @@
1
- // src/js/value/merge.ts
2
- import { isArrayOrPlainObject } from "../is";
1
+ import { isArrayOrPlainObject } from "../is.js";
3
2
  function merge(values, options) {
4
3
  if (values.length === 0) {
5
4
  return {};
6
5
  }
7
- const skipNullable = options?.skipNullable ?? false;
8
- const actual = values.filter((value) => isArrayOrPlainObject(value));
6
+ const skipNullable = (options == null ? void 0 : options.skipNullable) ?? false;
7
+ const actual = values.filter(
8
+ (value) => isArrayOrPlainObject(value)
9
+ );
9
10
  const result = actual.every(Array.isArray) ? [] : {};
10
11
  const isArray = Array.isArray(result);
11
12
  const { length } = actual;
12
- for (let outerIndex = 0;outerIndex < length; outerIndex += 1) {
13
+ for (let outerIndex = 0; outerIndex < length; outerIndex += 1) {
13
14
  const item = actual[outerIndex];
14
15
  const keys = Object.keys(item);
15
16
  const size = keys.length;
16
- for (let innerIndex = 0;innerIndex < size; innerIndex += 1) {
17
+ for (let innerIndex = 0; innerIndex < size; innerIndex += 1) {
17
18
  const key = keys[innerIndex];
18
19
  const next = item[key];
19
20
  const previous = result[key];
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const internal_value_handle = require("../internal/value/handle.cjs");
4
+ function setValue(data, path, value, ignoreCase) {
5
+ const shouldIgnoreCase = ignoreCase === true;
6
+ const parts = (shouldIgnoreCase ? path.toLowerCase() : path).split(".");
7
+ const { length } = parts;
8
+ const lastIndex = length - 1;
9
+ let target = data;
10
+ for (let index = 0; index < length; index += 1) {
11
+ const part = parts[index];
12
+ if (index === lastIndex) {
13
+ internal_value_handle.handleValue(target, part, value, false, shouldIgnoreCase);
14
+ break;
15
+ }
16
+ let next = internal_value_handle.handleValue(target, part, null, true, shouldIgnoreCase);
17
+ if (typeof next !== "object" || next === null) {
18
+ next = {};
19
+ target[part] = next;
20
+ }
21
+ target = next;
22
+ }
23
+ return data;
24
+ }
25
+ exports.setValue = setValue;
@@ -1,12 +1,11 @@
1
- // src/js/value/set.ts
2
- import { handleValue } from "../internal/value-handle";
1
+ import { handleValue } from "../internal/value/handle.js";
3
2
  function setValue(data, path, value, ignoreCase) {
4
3
  const shouldIgnoreCase = ignoreCase === true;
5
4
  const parts = (shouldIgnoreCase ? path.toLowerCase() : path).split(".");
6
5
  const { length } = parts;
7
6
  const lastIndex = length - 1;
8
- let target = typeof data === "object" && data !== null ? data : {};
9
- for (let index = 0;index < length; index += 1) {
7
+ let target = data;
8
+ for (let index = 0; index < length; index += 1) {
10
9
  const part = parts[index];
11
10
  if (index === lastIndex) {
12
11
  handleValue(target, part, value, false, shouldIgnoreCase);
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const is = require("../is.cjs");
4
+ const string_index = require("../string/index.cjs");
5
+ function flatten(value, prefix) {
6
+ const keys = Object.keys(value);
7
+ const { length } = keys;
8
+ const smushed = {};
9
+ for (let index = 0; index < length; index += 1) {
10
+ const key = keys[index];
11
+ const val = value[key];
12
+ if (is.isArrayOrPlainObject(val)) {
13
+ Object.assign(smushed, {
14
+ [string_index.join([prefix, key], ".")]: Array.isArray(val) ? [...val] : { ...val },
15
+ ...flatten(val, string_index.join([prefix, key], "."))
16
+ });
17
+ } else {
18
+ smushed[string_index.join([prefix, key], ".")] = val;
19
+ }
20
+ }
21
+ return smushed;
22
+ }
23
+ function smush(value) {
24
+ return flatten(value);
25
+ }
26
+ exports.smush = smush;
@@ -1,11 +1,10 @@
1
- // src/js/value/smush.ts
2
- import { isArrayOrPlainObject } from "../is";
3
- import { join } from "../string";
1
+ import { isArrayOrPlainObject } from "../is.js";
2
+ import { join } from "../string/index.js";
4
3
  function flatten(value, prefix) {
5
4
  const keys = Object.keys(value);
6
5
  const { length } = keys;
7
6
  const smushed = {};
8
- for (let index = 0;index < length; index += 1) {
7
+ for (let index = 0; index < length; index += 1) {
9
8
  const key = keys[index];
10
9
  const val = value[key];
11
10
  if (isArrayOrPlainObject(val)) {