@oscarpalmer/atoms 0.75.0 → 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 (215) hide show
  1. package/dist/js/array/chunk.cjs +2 -1
  2. package/dist/js/array/chunk.js +2 -1
  3. package/dist/js/array/count.cjs +10 -3
  4. package/dist/js/array/count.js +10 -3
  5. package/dist/js/array/exists.cjs +10 -3
  6. package/dist/js/array/exists.js +10 -3
  7. package/dist/js/array/filter.cjs +10 -3
  8. package/dist/js/array/filter.js +10 -3
  9. package/dist/js/array/find.cjs +10 -3
  10. package/dist/js/array/find.js +10 -3
  11. package/dist/js/array/group-by.cjs +18 -16
  12. package/dist/js/array/group-by.js +18 -16
  13. package/dist/js/array/index-of.cjs +10 -3
  14. package/dist/js/array/index-of.js +10 -3
  15. package/dist/js/array/index.cjs +2 -2
  16. package/dist/js/array/index.js +2 -2
  17. package/dist/js/array/insert.cjs +10 -4
  18. package/dist/js/array/insert.js +10 -4
  19. package/dist/js/array/splice.cjs +4 -4
  20. package/dist/js/array/splice.js +4 -4
  21. package/dist/js/array/to-map.cjs +11 -11
  22. package/dist/js/array/to-map.js +11 -11
  23. package/dist/js/array/to-record.cjs +3 -3
  24. package/dist/js/array/to-record.js +3 -3
  25. package/dist/js/array/unique.cjs +2 -2
  26. package/dist/js/array/unique.js +2 -2
  27. package/dist/js/colour/base.cjs +1 -1
  28. package/dist/js/colour/base.js +1 -1
  29. package/dist/js/colour/hex.cjs +2 -2
  30. package/dist/js/colour/hex.js +2 -2
  31. package/dist/js/colour/hsl.cjs +13 -7
  32. package/dist/js/colour/hsl.js +13 -7
  33. package/dist/js/colour/rgb.cjs +12 -6
  34. package/dist/js/colour/rgb.js +12 -6
  35. package/dist/js/emitter.cjs +8 -5
  36. package/dist/js/emitter.js +8 -5
  37. package/dist/js/function.cjs +6 -6
  38. package/dist/js/function.js +6 -6
  39. package/dist/js/index.cjs +0 -1
  40. package/dist/js/index.js +1 -2
  41. package/dist/js/internal/array/callbacks.cjs +23 -0
  42. package/dist/js/internal/array/callbacks.js +23 -0
  43. package/dist/js/internal/{array-find.cjs → array/find.cjs} +11 -12
  44. package/dist/js/internal/{array-find.js → array/find.js} +11 -12
  45. package/dist/js/logger.cjs +13 -13
  46. package/dist/js/logger.js +13 -13
  47. package/dist/js/query.cjs +0 -3
  48. package/dist/js/query.js +1 -4
  49. package/dist/js/random.cjs +0 -6
  50. package/dist/js/random.js +0 -6
  51. package/dist/js/sized.cjs +1 -1
  52. package/dist/js/sized.js +1 -1
  53. package/dist/js/string/index.cjs +7 -1
  54. package/dist/js/string/index.js +7 -1
  55. package/dist/js/value/compare.cjs +0 -1
  56. package/dist/js/value/compare.js +0 -1
  57. package/dist/js/value/get.cjs +3 -3
  58. package/dist/js/value/get.js +2 -2
  59. package/dist/js/value/set.cjs +4 -4
  60. package/dist/js/value/set.js +2 -2
  61. package/package.json +3 -2
  62. package/src/js/array/chunk.ts +6 -5
  63. package/src/js/array/compact.ts +8 -10
  64. package/src/js/array/count.ts +39 -19
  65. package/src/js/array/exists.ts +40 -16
  66. package/src/js/array/filter.ts +42 -20
  67. package/src/js/array/find.ts +45 -20
  68. package/src/js/array/group-by.ts +158 -27
  69. package/src/js/array/index-of.ts +40 -18
  70. package/src/js/array/index.ts +10 -9
  71. package/src/js/array/insert.ts +28 -14
  72. package/src/js/array/models.ts +18 -15
  73. package/src/js/array/shuffle.ts +3 -3
  74. package/src/js/array/sort.ts +28 -34
  75. package/src/js/array/splice.ts +22 -26
  76. package/src/js/array/to-map.ts +133 -45
  77. package/src/js/array/to-record.ts +137 -39
  78. package/src/js/array/unique.ts +20 -15
  79. package/src/js/colour/base.ts +3 -3
  80. package/src/js/colour/functions.ts +4 -6
  81. package/src/js/colour/hex.ts +5 -5
  82. package/src/js/colour/hsl.ts +18 -12
  83. package/src/js/colour/index.ts +1 -1
  84. package/src/js/colour/is.ts +3 -3
  85. package/src/js/colour/rgb.ts +17 -11
  86. package/src/js/emitter.ts +12 -9
  87. package/src/js/function.ts +12 -12
  88. package/src/js/index.ts +16 -16
  89. package/src/js/internal/array/callbacks.ts +33 -0
  90. package/src/js/internal/{array-find.ts → array/find.ts} +23 -24
  91. package/src/js/internal/{value-handle.ts → value/handle.ts} +1 -1
  92. package/src/js/is.ts +2 -2
  93. package/src/js/logger.ts +14 -14
  94. package/src/js/math.ts +1 -1
  95. package/src/js/models.ts +5 -5
  96. package/src/js/number.ts +2 -2
  97. package/src/js/query.ts +6 -10
  98. package/src/js/queue.ts +1 -1
  99. package/src/js/random.ts +9 -19
  100. package/src/js/sized.ts +145 -145
  101. package/src/js/string/case.ts +1 -1
  102. package/src/js/string/index.ts +13 -7
  103. package/src/js/string/template.ts +6 -3
  104. package/src/js/value/clone.ts +3 -7
  105. package/src/js/value/compare.ts +3 -5
  106. package/src/js/value/diff.ts +4 -4
  107. package/src/js/value/equal.ts +2 -2
  108. package/src/js/value/get.ts +3 -3
  109. package/src/js/value/index.ts +2 -2
  110. package/src/js/value/merge.ts +3 -3
  111. package/src/js/value/set.ts +3 -4
  112. package/src/js/value/smush.ts +4 -4
  113. package/src/js/value/unsmush.ts +4 -4
  114. package/types/array/chunk.d.cts +2 -2
  115. package/types/array/chunk.d.ts +2 -2
  116. package/types/array/compact.d.cts +4 -4
  117. package/types/array/compact.d.ts +4 -4
  118. package/types/array/count.d.cts +15 -8
  119. package/types/array/count.d.ts +13 -7
  120. package/types/array/exists.d.cts +14 -5
  121. package/types/array/exists.d.ts +12 -4
  122. package/types/array/filter.d.cts +16 -7
  123. package/types/array/filter.d.ts +14 -6
  124. package/types/array/find.d.cts +16 -7
  125. package/types/array/find.d.ts +14 -6
  126. package/types/array/group-by.d.cts +51 -5
  127. package/types/array/group-by.d.ts +49 -5
  128. package/types/array/index-of.d.cts +16 -7
  129. package/types/array/index-of.d.ts +14 -6
  130. package/types/array/index.d.cts +239 -95
  131. package/types/array/index.d.ts +7 -6
  132. package/types/array/insert.d.cts +9 -4
  133. package/types/array/insert.d.ts +10 -5
  134. package/types/array/models.d.cts +14 -11
  135. package/types/array/models.d.ts +14 -12
  136. package/types/array/shuffle.d.cts +2 -2
  137. package/types/array/shuffle.d.ts +2 -2
  138. package/types/array/sort.d.cts +11 -11
  139. package/types/array/sort.d.ts +10 -10
  140. package/types/array/splice.d.cts +4 -4
  141. package/types/array/splice.d.ts +4 -4
  142. package/types/array/to-map.d.cts +44 -20
  143. package/types/array/to-map.d.ts +42 -20
  144. package/types/array/to-record.d.cts +44 -20
  145. package/types/array/to-record.d.ts +42 -20
  146. package/types/array/unique.d.cts +11 -6
  147. package/types/array/unique.d.ts +10 -6
  148. package/types/colour/base.d.cts +28 -16
  149. package/types/colour/base.d.ts +2 -2
  150. package/types/colour/functions.d.cts +28 -16
  151. package/types/colour/functions.d.ts +3 -3
  152. package/types/colour/hex.d.cts +28 -16
  153. package/types/colour/hex.d.ts +4 -4
  154. package/types/colour/hsl.d.cts +28 -16
  155. package/types/colour/hsl.d.ts +16 -10
  156. package/types/colour/index.d.cts +28 -16
  157. package/types/colour/index.d.ts +1 -1
  158. package/types/colour/is.d.cts +28 -16
  159. package/types/colour/is.d.ts +3 -3
  160. package/types/colour/rgb.d.cts +28 -16
  161. package/types/colour/rgb.d.ts +15 -9
  162. package/types/emitter.d.cts +11 -8
  163. package/types/emitter.d.ts +11 -8
  164. package/types/function.d.cts +10 -10
  165. package/types/function.d.ts +11 -11
  166. package/types/index.d.cts +1061 -669
  167. package/types/index.d.ts +16 -16
  168. package/types/internal/array/callbacks.d.cts +11 -0
  169. package/types/internal/array/callbacks.d.ts +2 -0
  170. package/types/internal/array/find.d.cts +7 -0
  171. package/types/internal/array/find.d.ts +3 -0
  172. package/types/internal/{value-handle.d.ts → value/handle.d.ts} +1 -1
  173. package/types/is.d.ts +1 -1
  174. package/types/logger.d.cts +13 -13
  175. package/types/logger.d.ts +13 -13
  176. package/types/math.d.cts +1 -1
  177. package/types/math.d.ts +1 -1
  178. package/types/models.d.cts +4 -4
  179. package/types/models.d.ts +1 -4
  180. package/types/number.d.cts +2 -2
  181. package/types/number.d.ts +2 -2
  182. package/types/query.d.cts +2 -2
  183. package/types/query.d.ts +3 -3
  184. package/types/queue.d.cts +1 -1
  185. package/types/queue.d.ts +1 -1
  186. package/types/random.d.cts +8 -12
  187. package/types/random.d.ts +8 -12
  188. package/types/sized.d.cts +6 -6
  189. package/types/sized.d.ts +6 -6
  190. package/types/string/index.d.cts +6 -3
  191. package/types/string/index.d.ts +3 -3
  192. package/types/string/template.d.cts +3 -0
  193. package/types/string/template.d.ts +4 -1
  194. package/types/value/clone.d.cts +4 -2
  195. package/types/value/clone.d.ts +4 -2
  196. package/types/value/get.d.ts +1 -1
  197. package/types/value/index.d.cts +8 -6
  198. package/types/value/index.d.ts +2 -2
  199. package/types/value/merge.d.cts +1 -1
  200. package/types/value/merge.d.ts +2 -2
  201. package/types/value/set.d.ts +1 -1
  202. package/types/value/smush.d.cts +1 -1
  203. package/types/value/smush.d.ts +2 -2
  204. package/types/value/unsmush.d.cts +1 -1
  205. package/types/value/unsmush.d.ts +2 -2
  206. package/dist/js/internal/array-callbacks.cjs +0 -18
  207. package/dist/js/internal/array-callbacks.js +0 -18
  208. package/src/js/internal/array-callbacks.ts +0 -28
  209. package/types/internal/array-callbacks.d.cts +0 -13
  210. package/types/internal/array-callbacks.d.ts +0 -2
  211. package/types/internal/array-find.d.cts +0 -11
  212. package/types/internal/array-find.d.ts +0 -4
  213. /package/dist/js/internal/{value-handle.cjs → value/handle.cjs} +0 -0
  214. /package/dist/js/internal/{value-handle.js → value/handle.js} +0 -0
  215. /package/types/internal/{value-handle.d.cts → value/handle.d.cts} +0 -0
@@ -6,13 +6,13 @@ if (globalThis._atomic_logging == null) {
6
6
  }
7
7
  class Logger {
8
8
  /**
9
- * Logs any number of values at the "debug" log level
9
+ * Log any number of values at the "debug" log level
10
10
  */
11
11
  get debug() {
12
12
  return this.enabled ? console.debug : _function.noop;
13
13
  }
14
14
  /**
15
- * Logs the value and shows all its properties
15
+ * Log the value and shows all its properties
16
16
  */
17
17
  get dir() {
18
18
  return this.enabled ? console.dir : _function.noop;
@@ -30,43 +30,43 @@ class Logger {
30
30
  globalThis._atomic_logging = value;
31
31
  }
32
32
  /**
33
- * Logs any number of values at the "error" log level
33
+ * Log any number of values at the "error" log level
34
34
  */
35
35
  get error() {
36
36
  return this.enabled ? console.error : _function.noop;
37
37
  }
38
38
  /**
39
- * Logs any number of values at the "info" log level
39
+ * Log any number of values at the "info" log level
40
40
  */
41
41
  get info() {
42
42
  return this.enabled ? console.info : _function.noop;
43
43
  }
44
44
  /**
45
- * Logs any number of values at the "log" log level
45
+ * Log any number of values at the "log" log level
46
46
  */
47
47
  get log() {
48
48
  return this.enabled ? console.log : _function.noop;
49
49
  }
50
50
  /**
51
- * Logs data as a table, with optional properties to use as columns
51
+ * Log data as a table, with optional properties to use as columns
52
52
  */
53
53
  get table() {
54
54
  return this.enabled ? console.table : _function.noop;
55
55
  }
56
56
  /**
57
- * Logs any number of values together with a trace from where it was called
57
+ * Log any number of values together with a trace from where it was called
58
58
  */
59
59
  get trace() {
60
60
  return this.enabled ? console.trace : _function.noop;
61
61
  }
62
62
  /**
63
- * Logs any number of values at the "warn" log level
63
+ * Log any number of values at the "warn" log level
64
64
  */
65
65
  get warn() {
66
66
  return this.enabled ? console.warn : _function.noop;
67
67
  }
68
68
  /**
69
- * - Starts a logged timer with a label
69
+ * - Start a logged timer with a label
70
70
  * - Returns a `Time`-object for logging the current duration of the timer and stopping the timer _(and logging the total duration)_
71
71
  */
72
72
  time(label) {
@@ -85,8 +85,8 @@ class Time {
85
85
  }
86
86
  }
87
87
  /**
88
- * - Logs the current duration of the timer
89
- * - Ignored if logging is disabled
88
+ * - Log the current duration of the timer
89
+ * - _(Ignored if logging is disabled)_
90
90
  */
91
91
  log() {
92
92
  if (this.state.started && !this.state.stopped && logger.enabled) {
@@ -94,8 +94,8 @@ class Time {
94
94
  }
95
95
  }
96
96
  /**
97
- * - Stops the timer and logs the total duration
98
- * - Will always log the total duration, even if logging is disabled
97
+ * - Stop the timer and logs the total duration
98
+ * - _(Will always log the total duration, even if logging is disabled)_
99
99
  */
100
100
  stop() {
101
101
  if (this.state.started && !this.state.stopped) {
package/dist/js/logger.js CHANGED
@@ -4,13 +4,13 @@ if (globalThis._atomic_logging == null) {
4
4
  }
5
5
  class Logger {
6
6
  /**
7
- * Logs any number of values at the "debug" log level
7
+ * Log any number of values at the "debug" log level
8
8
  */
9
9
  get debug() {
10
10
  return this.enabled ? console.debug : noop;
11
11
  }
12
12
  /**
13
- * Logs the value and shows all its properties
13
+ * Log the value and shows all its properties
14
14
  */
15
15
  get dir() {
16
16
  return this.enabled ? console.dir : noop;
@@ -28,43 +28,43 @@ class Logger {
28
28
  globalThis._atomic_logging = value;
29
29
  }
30
30
  /**
31
- * Logs any number of values at the "error" log level
31
+ * Log any number of values at the "error" log level
32
32
  */
33
33
  get error() {
34
34
  return this.enabled ? console.error : noop;
35
35
  }
36
36
  /**
37
- * Logs any number of values at the "info" log level
37
+ * Log any number of values at the "info" log level
38
38
  */
39
39
  get info() {
40
40
  return this.enabled ? console.info : noop;
41
41
  }
42
42
  /**
43
- * Logs any number of values at the "log" log level
43
+ * Log any number of values at the "log" log level
44
44
  */
45
45
  get log() {
46
46
  return this.enabled ? console.log : noop;
47
47
  }
48
48
  /**
49
- * Logs data as a table, with optional properties to use as columns
49
+ * Log data as a table, with optional properties to use as columns
50
50
  */
51
51
  get table() {
52
52
  return this.enabled ? console.table : noop;
53
53
  }
54
54
  /**
55
- * Logs any number of values together with a trace from where it was called
55
+ * Log any number of values together with a trace from where it was called
56
56
  */
57
57
  get trace() {
58
58
  return this.enabled ? console.trace : noop;
59
59
  }
60
60
  /**
61
- * Logs any number of values at the "warn" log level
61
+ * Log any number of values at the "warn" log level
62
62
  */
63
63
  get warn() {
64
64
  return this.enabled ? console.warn : noop;
65
65
  }
66
66
  /**
67
- * - Starts a logged timer with a label
67
+ * - Start a logged timer with a label
68
68
  * - Returns a `Time`-object for logging the current duration of the timer and stopping the timer _(and logging the total duration)_
69
69
  */
70
70
  time(label) {
@@ -83,8 +83,8 @@ class Time {
83
83
  }
84
84
  }
85
85
  /**
86
- * - Logs the current duration of the timer
87
- * - Ignored if logging is disabled
86
+ * - Log the current duration of the timer
87
+ * - _(Ignored if logging is disabled)_
88
88
  */
89
89
  log() {
90
90
  if (this.state.started && !this.state.stopped && logger.enabled) {
@@ -92,8 +92,8 @@ class Time {
92
92
  }
93
93
  }
94
94
  /**
95
- * - Stops the timer and logs the total duration
96
- * - Will always log the total duration, even if logging is disabled
95
+ * - Stop the timer and logs the total duration
96
+ * - _(Will always log the total duration, even if logging is disabled)_
97
97
  */
98
98
  stop() {
99
99
  if (this.state.started && !this.state.stopped) {
package/dist/js/query.cjs CHANGED
@@ -9,9 +9,6 @@ function fromQuery(query) {
9
9
  const parameters = {};
10
10
  for (let index = 0; index < length; index += 1) {
11
11
  const [key, value] = parts[index].split("=").map(decodeURIComponent);
12
- if (is.isNullableOrWhitespace(key)) {
13
- continue;
14
- }
15
12
  if (key.includes(".")) {
16
13
  value_set.setValue(parameters, key, getValue(value));
17
14
  } else {
package/dist/js/query.js CHANGED
@@ -1,4 +1,4 @@
1
- import { isNullableOrWhitespace, isPlainObject } from "./is.js";
1
+ import { isPlainObject } from "./is.js";
2
2
  import { join } from "./string/index.js";
3
3
  import { setValue } from "./value/set.js";
4
4
  function fromQuery(query) {
@@ -7,9 +7,6 @@ function fromQuery(query) {
7
7
  const parameters = {};
8
8
  for (let index = 0; index < length; index += 1) {
9
9
  const [key, value] = parts[index].split("=").map(decodeURIComponent);
10
- if (isNullableOrWhitespace(key)) {
11
- continue;
12
- }
13
10
  if (key.includes(".")) {
14
11
  setValue(parameters, key, getValue(value));
15
12
  } else {
@@ -18,11 +18,6 @@ function getRandomCharacters(length, selection) {
18
18
  function getRandomColour() {
19
19
  return `#${Array.from({ length: 6 }, getRandomHex).join("")}`;
20
20
  }
21
- function getRandomDate(earliest, latest) {
22
- const earliestTime = (earliest == null ? void 0 : earliest.getTime()) ?? -864e13;
23
- const latestTime = (latest == null ? void 0 : latest.getTime()) ?? 864e13;
24
- return new Date(getRandomInteger(earliestTime, latestTime));
25
- }
26
21
  function getRandomFloat(min, max) {
27
22
  const minimum = min ?? Number.MIN_SAFE_INTEGER;
28
23
  return Math.random() * ((max ?? Number.MAX_SAFE_INTEGER) - minimum) + minimum;
@@ -45,7 +40,6 @@ function getRandomItems(array, amount) {
45
40
  exports.getRandomBoolean = getRandomBoolean;
46
41
  exports.getRandomCharacters = getRandomCharacters;
47
42
  exports.getRandomColour = getRandomColour;
48
- exports.getRandomDate = getRandomDate;
49
43
  exports.getRandomFloat = getRandomFloat;
50
44
  exports.getRandomHex = getRandomHex;
51
45
  exports.getRandomInteger = getRandomInteger;
package/dist/js/random.js CHANGED
@@ -16,11 +16,6 @@ function getRandomCharacters(length, selection) {
16
16
  function getRandomColour() {
17
17
  return `#${Array.from({ length: 6 }, getRandomHex).join("")}`;
18
18
  }
19
- function getRandomDate(earliest, latest) {
20
- const earliestTime = (earliest == null ? void 0 : earliest.getTime()) ?? -864e13;
21
- const latestTime = (latest == null ? void 0 : latest.getTime()) ?? 864e13;
22
- return new Date(getRandomInteger(earliestTime, latestTime));
23
- }
24
19
  function getRandomFloat(min, max) {
25
20
  const minimum = min ?? Number.MIN_SAFE_INTEGER;
26
21
  return Math.random() * ((max ?? Number.MAX_SAFE_INTEGER) - minimum) + minimum;
@@ -44,7 +39,6 @@ export {
44
39
  getRandomBoolean,
45
40
  getRandomCharacters,
46
41
  getRandomColour,
47
- getRandomDate,
48
42
  getRandomFloat,
49
43
  getRandomHex,
50
44
  getRandomInteger,
package/dist/js/sized.cjs CHANGED
@@ -35,7 +35,7 @@ class SizedMap extends Map {
35
35
  */
36
36
  get(key) {
37
37
  const value = super.get(key);
38
- if (value === void 0 && !this.has(key)) {
38
+ if (value == null && !this.has(key)) {
39
39
  return;
40
40
  }
41
41
  this.set(key, value);
package/dist/js/sized.js CHANGED
@@ -33,7 +33,7 @@ class SizedMap extends Map {
33
33
  */
34
34
  get(key) {
35
35
  const value = super.get(key);
36
- if (value === void 0 && !this.has(key)) {
36
+ if (value == null && !this.has(key)) {
37
37
  return;
38
38
  }
39
39
  this.set(key, value);
@@ -31,9 +31,15 @@ function parse(value, reviver) {
31
31
  }
32
32
  }
33
33
  function truncate(value, length, suffix) {
34
+ if (length <= 0) {
35
+ return "";
36
+ }
37
+ if (length >= value.length) {
38
+ return value;
39
+ }
34
40
  const suffixLength = (suffix == null ? void 0 : suffix.length) ?? 0;
35
41
  const truncatedLength = length - suffixLength;
36
- return value.length <= length ? value : `${value.slice(0, truncatedLength)}${suffix ?? ""}`;
42
+ return `${value.slice(0, truncatedLength)}${suffix ?? ""}`;
37
43
  }
38
44
  function words(value) {
39
45
  return value.match(/[^\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\x7f]+/g) ?? [];
@@ -29,9 +29,15 @@ function parse(value, reviver) {
29
29
  }
30
30
  }
31
31
  function truncate(value, length, suffix) {
32
+ if (length <= 0) {
33
+ return "";
34
+ }
35
+ if (length >= value.length) {
36
+ return value;
37
+ }
32
38
  const suffixLength = (suffix == null ? void 0 : suffix.length) ?? 0;
33
39
  const truncatedLength = length - suffixLength;
34
- return value.length <= length ? value : `${value.slice(0, truncatedLength)}${suffix ?? ""}`;
40
+ return `${value.slice(0, truncatedLength)}${suffix ?? ""}`;
35
41
  }
36
42
  function words(value) {
37
43
  return value.match(/[^\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\x7f]+/g) ?? [];
@@ -42,7 +42,6 @@ function compare(first, second) {
42
42
  if (index === lastIndex) {
43
43
  return 0;
44
44
  }
45
- continue;
46
45
  }
47
46
  return firstNumber - secondNumber;
48
47
  }
@@ -40,7 +40,6 @@ function compare(first, second) {
40
40
  if (index === lastIndex) {
41
41
  return 0;
42
42
  }
43
- continue;
44
43
  }
45
44
  return firstNumber - secondNumber;
46
45
  }
@@ -1,14 +1,14 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const internal_valueHandle = require("../internal/value-handle.cjs");
3
+ const internal_value_handle = require("../internal/value/handle.cjs");
4
4
  function getValue(data, path, ignoreCase) {
5
5
  const shouldIgnoreCase = ignoreCase === true;
6
6
  const parts = (shouldIgnoreCase ? path.toLowerCase() : path).split(".");
7
7
  const { length } = parts;
8
8
  let index = 0;
9
- let value = typeof data === "object" ? data ?? {} : {};
9
+ let value = data;
10
10
  while (index < length && value != null) {
11
- value = internal_valueHandle.handleValue(
11
+ value = internal_value_handle.handleValue(
12
12
  value,
13
13
  parts[index++],
14
14
  null,
@@ -1,10 +1,10 @@
1
- import { handleValue } from "../internal/value-handle.js";
1
+ import { handleValue } from "../internal/value/handle.js";
2
2
  function getValue(data, path, ignoreCase) {
3
3
  const shouldIgnoreCase = ignoreCase === true;
4
4
  const parts = (shouldIgnoreCase ? path.toLowerCase() : path).split(".");
5
5
  const { length } = parts;
6
6
  let index = 0;
7
- let value = typeof data === "object" ? data ?? {} : {};
7
+ let value = data;
8
8
  while (index < length && value != null) {
9
9
  value = handleValue(
10
10
  value,
@@ -1,19 +1,19 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const internal_valueHandle = require("../internal/value-handle.cjs");
3
+ const internal_value_handle = require("../internal/value/handle.cjs");
4
4
  function setValue(data, path, value, ignoreCase) {
5
5
  const shouldIgnoreCase = ignoreCase === true;
6
6
  const parts = (shouldIgnoreCase ? path.toLowerCase() : path).split(".");
7
7
  const { length } = parts;
8
8
  const lastIndex = length - 1;
9
- let target = typeof data === "object" && data !== null ? data : {};
9
+ let target = data;
10
10
  for (let index = 0; index < length; index += 1) {
11
11
  const part = parts[index];
12
12
  if (index === lastIndex) {
13
- internal_valueHandle.handleValue(target, part, value, false, shouldIgnoreCase);
13
+ internal_value_handle.handleValue(target, part, value, false, shouldIgnoreCase);
14
14
  break;
15
15
  }
16
- let next = internal_valueHandle.handleValue(target, part, null, true, shouldIgnoreCase);
16
+ let next = internal_value_handle.handleValue(target, part, null, true, shouldIgnoreCase);
17
17
  if (typeof next !== "object" || next === null) {
18
18
  next = {};
19
19
  target[part] = next;
@@ -1,10 +1,10 @@
1
- import { handleValue } from "../internal/value-handle.js";
1
+ import { handleValue } from "../internal/value/handle.js";
2
2
  function setValue(data, path, value, ignoreCase) {
3
3
  const shouldIgnoreCase = ignoreCase === true;
4
4
  const parts = (shouldIgnoreCase ? path.toLowerCase() : path).split(".");
5
5
  const { length } = parts;
6
6
  const lastIndex = length - 1;
7
- let target = typeof data === "object" && data !== null ? data : {};
7
+ let target = data;
8
8
  for (let index = 0; index < length; index += 1) {
9
9
  const part = parts[index];
10
10
  if (index === lastIndex) {
package/package.json CHANGED
@@ -12,6 +12,7 @@
12
12
  "@types/node": "^22.7",
13
13
  "@vitest/coverage-istanbul": "^2.1",
14
14
  "dts-bundle-generator": "^9.5",
15
+ "glob": "^11",
15
16
  "happy-dom": "^15.7",
16
17
  "sass": "^1.79",
17
18
  "typescript": "^5.6",
@@ -223,11 +224,11 @@
223
224
  "build:js": "npx vite build && npm run types",
224
225
  "clean": "rm -rf ./dist && rm -rf ./types && rm -f ./tsconfig.tsbuildinfo",
225
226
  "test": "npx vitest --coverage",
226
- "types": "npx tsc && npx dts-bundle-generator --config ./dts.config.ts",
227
+ "types": "npx tsc && npx dts-bundle-generator --config ./dts.config.ts --silent",
227
228
  "watch:css": "npx sass ./src/css:./dist/css --no-source-map --watch",
228
229
  "watch:js": "npx vite build --watch"
229
230
  },
230
231
  "type": "module",
231
232
  "types": "./types/index.d.cts",
232
- "version": "0.75.0"
233
+ "version": "0.76.0"
233
234
  }
@@ -1,16 +1,17 @@
1
+ import {clamp} from '~/number';
2
+
1
3
  /**
2
- * Chunks an array into smaller arrays of a specified size
4
+ * Chunk an array _(into smaller arrays of a specified size)_
3
5
  */
4
- export function chunk<Value>(array: Value[], size?: number): Value[][] {
6
+ export function chunk<Item>(array: Item[], size?: number): Item[][] {
7
+ const chunkSize = clamp(size ?? 64_000, 1, 64_000);
5
8
  const {length} = array;
6
9
 
7
- const chunkSize = typeof size === 'number' && size > 0 ? size : 64_000;
8
-
9
10
  if (length <= chunkSize) {
10
11
  return [array];
11
12
  }
12
13
 
13
- const chunks: Value[][] = [];
14
+ const chunks: Item[][] = [];
14
15
 
15
16
  let remaining = Number(length);
16
17
 
@@ -1,19 +1,17 @@
1
1
  /**
2
- * Compacts and returns an array with all falsey values removed
2
+ * Compact an array _(removing all `null` and `undefined` values)_
3
3
  */
4
- export function compact<Value>(
5
- array: Value[],
6
- strict: true,
7
- ): Exclude<Value, 0 | '' | false | null | undefined>[];
4
+ export function compact<Item>(array: Item[]): Exclude<Item, null | undefined>[];
8
5
 
9
6
  /**
10
- * Compacts and returns an array with all `null` and `undefined` values removed
7
+ * Compact an array _(removing all falsey values)_
11
8
  */
12
- export function compact<Value>(
13
- array: Value[],
14
- ): Exclude<Value, null | undefined>[];
9
+ export function compact<Item>(
10
+ array: Item[],
11
+ strict: true,
12
+ ): Exclude<Item, 0 | '' | false | null | undefined>[];
15
13
 
16
- export function compact<Value>(array: Value[], strict?: boolean): Value[] {
14
+ export function compact<Item>(array: Item[], strict?: boolean): Item[] {
17
15
  return strict === true
18
16
  ? array.filter(item => !!item)
19
17
  : array.filter(item => item != null);
@@ -1,29 +1,49 @@
1
- import type {BooleanCallback, KeyCallback} from '@/array/models';
2
- import {findValues} from '@/internal/array-find';
3
- import type {Key} from '@/models';
1
+ import {findValues} from '~/internal/array/find';
2
+ import type {BooleanCallback, KeyCallback} from '~/array/models';
4
3
 
5
4
  /**
6
- * Returns the number of items _(count)_ that match the given value
5
+ * Get the number of items _(count)_ that match the given value
7
6
  */
8
- export function count<Model, Value>(
9
- array: Model[],
10
- value: Value | BooleanCallback<Model>,
7
+ export function count<Item>(array: Item[], value: Item): number;
8
+
9
+ /**
10
+ * Get the number of items _(count)_ that match the given value
11
+ */
12
+ export function count<Item>(
13
+ array: Item[],
14
+ matches: BooleanCallback<Item>,
15
+ ): number;
16
+
17
+ /**
18
+ * Get the number of items _(count)_ that match the given value
19
+ */
20
+ export function count<Item, Key extends keyof Item>(
21
+ array: Item[],
22
+ key: Key,
23
+ value: Item[Key],
11
24
  ): number;
12
25
 
13
26
  /**
14
- * - Returns the number of items _(count)_ that match the given value
15
- * - Use `key` to find a comparison value to match with `value`
27
+ * Get the number of items _(count)_ that match the given value
16
28
  */
17
- export function count<Model, Value = Model>(
18
- array: Model[],
19
- value: Value,
20
- key: Key | KeyCallback<Model>,
29
+ export function count<Item, Key extends KeyCallback<Item>>(
30
+ array: Item[],
31
+ key: Key,
32
+ value: ReturnType<Key>,
21
33
  ): number;
22
34
 
23
- export function count<Model, Value = Model>(
24
- array: Model[],
25
- value: Value | BooleanCallback<Model>,
26
- key?: Key | KeyCallback<Model>,
27
- ): number {
28
- return findValues('all', array, value, key).length;
35
+ export function count(array: unknown[], ...parameters: unknown[]): number {
36
+ const {length} = parameters;
37
+
38
+ return findValues(
39
+ 'all',
40
+ array,
41
+ length === 1 && typeof parameters[0] === 'function'
42
+ ? parameters[0]
43
+ : undefined,
44
+ length === 2 ? parameters[0] : undefined,
45
+ length === 1 && typeof parameters[0] !== 'function'
46
+ ? parameters[0]
47
+ : parameters[1],
48
+ ).length;
29
49
  }
@@ -1,29 +1,53 @@
1
- import type {BooleanCallback, KeyCallback} from '@/array/models';
2
- import {findValue} from '@/internal/array-find';
3
- import type {Key} from '@/models';
1
+ import {findValue} from '~/internal/array/find';
2
+ import type {BooleanCallback, KeyCallback} from './models';
4
3
 
5
4
  /**
6
5
  * Does the value exist in array?
7
6
  */
8
- export function exists<Model, Value>(
9
- array: Model[],
10
- value: Value | BooleanCallback<Model>,
7
+ export function exists<Item>(array: Item[], value: Item): boolean;
8
+
9
+ /**
10
+ * Does the value exist in array?
11
+ */
12
+ export function exists<Item>(
13
+ array: Item[],
14
+ matches: BooleanCallback<Item>,
11
15
  ): boolean;
12
16
 
13
17
  /**
14
18
  * - Does the value exist in array?
15
19
  * - Use `key` to find a comparison value to match with `value`
16
20
  */
17
- export function exists<Model, Value = Model>(
18
- array: Model[],
19
- value: Value,
20
- key: Key | KeyCallback<Model>,
21
+ export function exists<Item, Key extends keyof Item>(
22
+ array: Item[],
23
+ key: Key,
24
+ value: Item[Key],
21
25
  ): boolean;
22
26
 
23
- export function exists<Model, Value = Model>(
24
- array: Model[],
25
- value: Value | BooleanCallback<Model>,
26
- key?: Key | KeyCallback<Model>,
27
- ): boolean {
28
- return (findValue('index', array, value, key) as number) > -1;
27
+ /**
28
+ * - Does the value exist in array?
29
+ * - Use `key` to find a comparison value to match with `value`
30
+ */
31
+ export function exists<Item, Key extends KeyCallback<Item>>(
32
+ array: Item[],
33
+ key: Key,
34
+ value: ReturnType<Key>,
35
+ ): boolean;
36
+
37
+ export function exists(array: unknown[], ...parameters: unknown[]): boolean {
38
+ const {length} = parameters;
39
+
40
+ return (
41
+ (findValue(
42
+ 'index',
43
+ array,
44
+ length === 1 && typeof parameters[0] === 'function'
45
+ ? parameters[0]
46
+ : undefined,
47
+ length === 2 ? parameters[0] : undefined,
48
+ length === 1 && typeof parameters[0] !== 'function'
49
+ ? parameters[0]
50
+ : parameters[1],
51
+ ) as number) > -1
52
+ );
29
53
  }