@oscarpalmer/atoms 0.186.2 → 0.187.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (229) hide show
  1. package/dist/array/filter.d.mts +4 -4
  2. package/dist/array/find.d.mts +4 -4
  3. package/dist/array/first.d.mts +4 -4
  4. package/dist/array/get.d.mts +27 -1
  5. package/dist/array/get.mjs +5 -3
  6. package/dist/array/group-by.d.mts +6 -6
  7. package/dist/array/last.d.mts +4 -4
  8. package/dist/array/match.d.mts +7 -6
  9. package/dist/array/move.d.mts +7 -7
  10. package/dist/array/move.mjs +1 -1
  11. package/dist/array/select.d.mts +1 -0
  12. package/dist/array/slice.d.mts +3 -3
  13. package/dist/array/sort.d.mts +10 -7
  14. package/dist/array/sort.mjs +4 -3
  15. package/dist/array/swap.d.mts +1 -1
  16. package/dist/array/swap.mjs +1 -1
  17. package/dist/array/to-map.d.mts +32 -32
  18. package/dist/array/to-record.d.mts +6 -6
  19. package/dist/array/to-set.d.mts +6 -6
  20. package/dist/beacon.d.mts +6 -0
  21. package/dist/beacon.mjs +3 -0
  22. package/dist/color/index.d.mts +6 -2
  23. package/dist/color/index.mjs +6 -2
  24. package/dist/color/instance.d.mts +78 -14
  25. package/dist/color/instance.mjs +78 -14
  26. package/dist/color/misc/get.d.mts +39 -11
  27. package/dist/color/misc/get.mjs +39 -11
  28. package/dist/color/misc/is.d.mts +26 -11
  29. package/dist/color/misc/is.mjs +26 -11
  30. package/dist/color/misc/state.mjs +1 -1
  31. package/dist/color/models.d.mts +7 -4
  32. package/dist/color/space/hex.d.mts +15 -6
  33. package/dist/color/space/hex.mjs +15 -6
  34. package/dist/color/space/hsl.d.mts +10 -4
  35. package/dist/color/space/hsl.mjs +10 -4
  36. package/dist/color/space/rgb.d.mts +21 -12
  37. package/dist/color/space/rgb.mjs +21 -12
  38. package/dist/function/assert.d.mts +20 -14
  39. package/dist/function/assert.mjs +19 -13
  40. package/dist/function/limit.d.mts +8 -6
  41. package/dist/function/limit.mjs +8 -6
  42. package/dist/function/memoize.d.mts +15 -4
  43. package/dist/function/memoize.mjs +18 -4
  44. package/dist/function/once.d.mts +5 -3
  45. package/dist/function/once.mjs +5 -3
  46. package/dist/function/retry.d.mts +5 -2
  47. package/dist/function/retry.mjs +3 -1
  48. package/dist/function/work.d.mts +146 -98
  49. package/dist/{kalas.d.mts → herald.d.mts} +17 -8
  50. package/dist/{kalas.mjs → herald.mjs} +22 -13
  51. package/dist/index.d.mts +1464 -708
  52. package/dist/index.mjs +677 -324
  53. package/dist/internal/array/index-of.d.mts +4 -4
  54. package/dist/internal/array/insert.mjs +1 -1
  55. package/dist/internal/array/shuffle.d.mts +1 -0
  56. package/dist/internal/array/shuffle.mjs +2 -1
  57. package/dist/internal/is.d.mts +26 -8
  58. package/dist/internal/is.mjs +26 -8
  59. package/dist/internal/math/aggregate.d.mts +9 -9
  60. package/dist/internal/number.d.mts +13 -2
  61. package/dist/internal/number.mjs +13 -2
  62. package/dist/internal/random.d.mts +4 -2
  63. package/dist/internal/random.mjs +7 -5
  64. package/dist/internal/result.d.mts +17 -11
  65. package/dist/internal/result.mjs +10 -14
  66. package/dist/internal/string.d.mts +16 -1
  67. package/dist/internal/string.mjs +24 -1
  68. package/dist/internal/value/compare.d.mts +5 -2
  69. package/dist/internal/value/compare.mjs +5 -2
  70. package/dist/internal/value/equal.d.mts +12 -3
  71. package/dist/internal/value/equal.mjs +7 -4
  72. package/dist/internal/value/get.d.mts +17 -17
  73. package/dist/internal/value/has.d.mts +55 -11
  74. package/dist/internal/value/set.d.mts +24 -0
  75. package/dist/is.d.mts +12 -0
  76. package/dist/is.mjs +16 -1
  77. package/dist/logger.d.mts +7 -6
  78. package/dist/logger.mjs +6 -5
  79. package/dist/math.d.mts +36 -18
  80. package/dist/math.mjs +6 -3
  81. package/dist/models.d.mts +3 -3
  82. package/dist/promise/delay.d.mts +2 -0
  83. package/dist/promise/helpers.d.mts +6 -4
  84. package/dist/promise/helpers.mjs +6 -4
  85. package/dist/promise/index.d.mts +49 -38
  86. package/dist/promise/misc.d.mts +10 -7
  87. package/dist/promise/misc.mjs +4 -3
  88. package/dist/promise/models.d.mts +18 -19
  89. package/dist/promise/models.mjs +4 -3
  90. package/dist/promise/timed.d.mts +8 -6
  91. package/dist/query.d.mts +2 -0
  92. package/dist/query.mjs +2 -0
  93. package/dist/queue.d.mts +15 -4
  94. package/dist/queue.mjs +10 -3
  95. package/dist/random.d.mts +9 -2
  96. package/dist/random.mjs +7 -2
  97. package/dist/result/index.d.mts +14 -8
  98. package/dist/result/match.d.mts +18 -10
  99. package/dist/result/misc.d.mts +14 -7
  100. package/dist/result/misc.mjs +4 -2
  101. package/dist/result/models.d.mts +2 -0
  102. package/dist/result/work/flow.d.mts +86 -62
  103. package/dist/result/work/pipe.d.mts +55 -33
  104. package/dist/sized/map.d.mts +19 -16
  105. package/dist/sized/map.mjs +4 -4
  106. package/dist/sized/set.d.mts +20 -16
  107. package/dist/sized/set.mjs +8 -7
  108. package/dist/string/case.d.mts +8 -0
  109. package/dist/string/case.mjs +8 -0
  110. package/dist/string/fuzzy.d.mts +19 -5
  111. package/dist/string/fuzzy.mjs +7 -0
  112. package/dist/string/index.d.mts +17 -2
  113. package/dist/string/index.mjs +7 -9
  114. package/dist/string/match.d.mts +3 -0
  115. package/dist/string/match.mjs +3 -0
  116. package/dist/string/normalize.d.mts +6 -2
  117. package/dist/string/normalize.mjs +5 -2
  118. package/dist/string/template.d.mts +38 -9
  119. package/dist/string/template.mjs +19 -19
  120. package/dist/value/clone.d.mts +25 -4
  121. package/dist/value/clone.mjs +36 -22
  122. package/dist/value/collection.d.mts +9 -6
  123. package/dist/value/collection.mjs +3 -2
  124. package/dist/value/diff.d.mts +3 -1
  125. package/dist/value/diff.mjs +1 -0
  126. package/dist/value/freeze.d.mts +118 -9
  127. package/dist/value/freeze.mjs +56 -14
  128. package/dist/value/index.d.mts +1 -2
  129. package/dist/value/index.mjs +1 -2
  130. package/dist/value/merge.d.mts +11 -5
  131. package/dist/value/merge.mjs +2 -2
  132. package/dist/value/omit.d.mts +1 -0
  133. package/dist/value/omit.mjs +1 -0
  134. package/dist/value/pick.d.mts +1 -0
  135. package/dist/value/pick.mjs +1 -0
  136. package/dist/value/shake.d.mts +1 -0
  137. package/dist/value/shake.mjs +1 -0
  138. package/dist/value/smush.d.mts +1 -0
  139. package/dist/value/smush.mjs +1 -0
  140. package/dist/value/transform.d.mts +7 -3
  141. package/dist/value/unsmush.d.mts +1 -0
  142. package/dist/value/unsmush.mjs +1 -0
  143. package/package.json +11 -7
  144. package/src/array/filter.ts +4 -4
  145. package/src/array/find.ts +4 -4
  146. package/src/array/first.ts +4 -4
  147. package/src/array/get.ts +40 -5
  148. package/src/array/group-by.ts +6 -6
  149. package/src/array/last.ts +4 -4
  150. package/src/array/match.ts +7 -6
  151. package/src/array/move.ts +7 -7
  152. package/src/array/select.ts +1 -0
  153. package/src/array/slice.ts +3 -3
  154. package/src/array/sort.ts +15 -10
  155. package/src/array/swap.ts +1 -1
  156. package/src/array/to-map.ts +32 -32
  157. package/src/array/to-record.ts +6 -6
  158. package/src/array/to-set.ts +6 -6
  159. package/src/beacon.ts +6 -0
  160. package/src/color/index.ts +6 -2
  161. package/src/color/instance.ts +78 -14
  162. package/src/color/misc/get.ts +39 -11
  163. package/src/color/misc/is.ts +26 -11
  164. package/src/color/misc/state.ts +1 -1
  165. package/src/color/models.ts +7 -4
  166. package/src/color/space/hex.ts +15 -6
  167. package/src/color/space/hsl.ts +10 -4
  168. package/src/color/space/rgb.ts +21 -12
  169. package/src/function/assert.ts +20 -14
  170. package/src/function/limit.ts +8 -6
  171. package/src/function/memoize.ts +24 -5
  172. package/src/function/once.ts +5 -3
  173. package/src/function/retry.ts +7 -3
  174. package/src/function/work.ts +146 -98
  175. package/src/{kalas.ts → herald.ts} +23 -14
  176. package/src/index.ts +3 -2
  177. package/src/internal/array/index-of.ts +4 -4
  178. package/src/internal/array/insert.ts +1 -1
  179. package/src/internal/array/shuffle.ts +2 -1
  180. package/src/internal/is.ts +26 -8
  181. package/src/internal/math/aggregate.ts +9 -9
  182. package/src/internal/number.ts +13 -2
  183. package/src/internal/random.ts +10 -4
  184. package/src/internal/result.ts +30 -29
  185. package/src/internal/string.ts +28 -0
  186. package/src/internal/value/compare.ts +5 -2
  187. package/src/internal/value/equal.ts +13 -4
  188. package/src/internal/value/get.ts +17 -17
  189. package/src/internal/value/has.ts +54 -11
  190. package/src/internal/value/set.ts +24 -0
  191. package/src/is.ts +15 -1
  192. package/src/logger.ts +8 -7
  193. package/src/math.ts +36 -18
  194. package/src/models.ts +3 -3
  195. package/src/promise/delay.ts +2 -0
  196. package/src/promise/helpers.ts +6 -4
  197. package/src/promise/index.ts +49 -38
  198. package/src/promise/misc.ts +10 -7
  199. package/src/promise/models.ts +18 -19
  200. package/src/promise/timed.ts +8 -6
  201. package/src/query.ts +2 -0
  202. package/src/queue.ts +15 -4
  203. package/src/random.ts +8 -1
  204. package/src/result/index.ts +14 -8
  205. package/src/result/match.ts +18 -10
  206. package/src/result/misc.ts +17 -9
  207. package/src/result/models.ts +2 -0
  208. package/src/result/work/flow.ts +86 -62
  209. package/src/result/work/pipe.ts +55 -33
  210. package/src/sized/map.ts +20 -17
  211. package/src/sized/set.ts +21 -17
  212. package/src/string/case.ts +8 -0
  213. package/src/string/fuzzy.ts +19 -5
  214. package/src/string/index.ts +18 -15
  215. package/src/string/match.ts +3 -0
  216. package/src/string/normalize.ts +6 -2
  217. package/src/string/template.ts +69 -18
  218. package/src/value/clone.ts +51 -26
  219. package/src/value/collection.ts +9 -6
  220. package/src/value/diff.ts +3 -1
  221. package/src/value/freeze.ts +239 -25
  222. package/src/value/index.ts +0 -1
  223. package/src/value/merge.ts +11 -5
  224. package/src/value/omit.ts +1 -0
  225. package/src/value/pick.ts +1 -0
  226. package/src/value/shake.ts +1 -0
  227. package/src/value/smush.ts +1 -0
  228. package/src/value/transform.ts +7 -3
  229. package/src/value/unsmush.ts +1 -0
@@ -11,6 +11,7 @@ type KeysOfUnion<ObjectType> = keyof UnionToIntersection<ObjectType extends unkn
11
11
  type Unsmushed<Value extends PlainObject> = Simplify<Omit<{ [UnionKey in KeysOfUnion<Value>]: Value[UnionKey] }, `${string}.${string}`>>;
12
12
  /**
13
13
  * Unsmush a smushed object _(turning dot notation keys into nested keys)_
14
+ *
14
15
  * @param value Object to unsmush
15
16
  * @returns Unsmushed object with nested keys
16
17
  */
@@ -16,6 +16,7 @@ function getKeys(value) {
16
16
  }
17
17
  /**
18
18
  * Unsmush a smushed object _(turning dot notation keys into nested keys)_
19
+ *
19
20
  * @param value Object to unsmush
20
21
  * @returns Unsmushed object with nested keys
21
22
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oscarpalmer/atoms",
3
- "version": "0.186.2",
3
+ "version": "0.187.0",
4
4
  "description": "Atomic utilities for making your JavaScript better.",
5
5
  "keywords": [
6
6
  "helper",
@@ -101,14 +101,14 @@
101
101
  "types": "./dist/function/work.d.mts",
102
102
  "default": "./dist/function/work.mjs"
103
103
  },
104
+ "./herald": {
105
+ "types": "./dist/herald.d.mts",
106
+ "default": "./dist/herald.mjs"
107
+ },
104
108
  "./is": {
105
109
  "types": "./dist/is.d.mts",
106
110
  "default": "./dist/is.mjs"
107
111
  },
108
- "./kalas": {
109
- "types": "./dist/kalas.d.mts",
110
- "default": "./dist/kalas.mjs"
111
- },
112
112
  "./logger": {
113
113
  "types": "./dist/logger.d.mts",
114
114
  "default": "./dist/logger.mjs"
@@ -232,6 +232,10 @@
232
232
  "types": "./dist/value/diff.d.mts",
233
233
  "default": "./dist/value/diff.mjs"
234
234
  },
235
+ "./value/freeze": {
236
+ "types": "./dist/value/freeze.d.mts",
237
+ "default": "./dist/value/freeze.mjs"
238
+ },
235
239
  "./value/equal": {
236
240
  "types": "./dist/internal/value/equal.d.mts",
237
241
  "default": "./dist/internal/value/equal.mjs"
@@ -253,8 +257,8 @@
253
257
  "watch": "npx vite build --watch"
254
258
  },
255
259
  "devDependencies": {
256
- "@oxlint/plugins": "^1.63",
257
- "@types/node": "^25.6",
260
+ "@oxlint/plugins": "^1.64",
261
+ "@types/node": "^25.7",
258
262
  "@vitest/coverage-istanbul": "^4.1",
259
263
  "eslint": "^10.3",
260
264
  "jsdom": "^29.1",
@@ -6,7 +6,7 @@ import type {PlainObject} from '../models';
6
6
  /**
7
7
  * Get a filtered array of items that do not match the value
8
8
  *
9
- * Available as `exclude` and `filter.remove`
9
+ * _Available as `exclude` and `filter.remove`_
10
10
  *
11
11
  * @param array Array to search in
12
12
  * @param callback Callback to get an item's value for matching
@@ -30,7 +30,7 @@ export function exclude<
30
30
  /**
31
31
  * Get a filtered array of items that do not match the value
32
32
  *
33
- * Available as `exclude` and `filter.remove`
33
+ * _Available as `exclude` and `filter.remove`_
34
34
  *
35
35
  * @param array Array to search in
36
36
  * @param key Key to get an item's value for matching
@@ -55,7 +55,7 @@ export function exclude<Item extends PlainObject, ItemKey extends keyof Item>(
55
55
  /**
56
56
  * Get a filtered array of items that do not match the filter
57
57
  *
58
- * Available as `exclude` and `filter.remove`
58
+ * _Available as `exclude` and `filter.remove`_
59
59
  *
60
60
  * @param array Array to search in
61
61
  * @param filter Filter callback to match items
@@ -77,7 +77,7 @@ export function exclude<Item>(
77
77
  /**
78
78
  * Get a filtered array of items that do not match the given item
79
79
  *
80
- * Available as `exclude` and `filter.remove`
80
+ * _Available as `exclude` and `filter.remove`_
81
81
  *
82
82
  * @param array Array to search in
83
83
  * @param item Item to match against
package/src/array/find.ts CHANGED
@@ -92,7 +92,7 @@ find.last = findLast;
92
92
  /**
93
93
  * Get the last item matching the given value
94
94
  *
95
- * Available as `findLast` and `find.last`
95
+ * _Available as `findLast` and `find.last`_
96
96
  *
97
97
  * @param array Array to search in
98
98
  * @param callback Callback to get an item's value for matching
@@ -116,7 +116,7 @@ export function findLast<
116
116
  /**
117
117
  * Get the last item matching the given value by key
118
118
  *
119
- * Available as `findLast` and `find.last`
119
+ * _Available as `findLast` and `find.last`_
120
120
  *
121
121
  * @param array Array to search in
122
122
  * @param key Key to get an item's value for matching
@@ -141,7 +141,7 @@ export function findLast<Item extends PlainObject, ItemKey extends keyof Item>(
141
141
  /**
142
142
  * Get the last item matching the filter
143
143
  *
144
- * Available as `findLast` and `find.last`
144
+ * _Available as `findLast` and `find.last`_
145
145
  *
146
146
  * @param array Array to search in
147
147
  * @param filter Filter callback to match items
@@ -163,7 +163,7 @@ export function findLast<Item>(
163
163
  /**
164
164
  * Get the last item matching the given value
165
165
  *
166
- * Available as `findLast` and `find.last`
166
+ * _Available as `findLast` and `find.last`_
167
167
  *
168
168
  * @param array Array to search in
169
169
  * @param value Value to match against
@@ -93,7 +93,7 @@ first.default = firstOrDefault;
93
93
  /**
94
94
  * Get the first item matching the given value, or a default value if no match is found
95
95
  *
96
- * Available as `firstOrDefault` and `first.default`
96
+ * _Available as `firstOrDefault` and `first.default`_
97
97
  *
98
98
  * @param array Array to search in
99
99
  * @param defaultValue Default value to return if no match is found
@@ -119,7 +119,7 @@ export function firstOrDefault<
119
119
  /**
120
120
  * Get the first item matching the given value by key, or a default value if no match is found
121
121
  *
122
- * Available as `firstOrDefault` and `first.default`
122
+ * _Available as `firstOrDefault` and `first.default`_
123
123
  *
124
124
  * @param array Array to search in
125
125
  * @param defaultValue Default value to return if no match is found
@@ -147,7 +147,7 @@ export function firstOrDefault<Item extends PlainObject, ItemKey extends keyof I
147
147
  /**
148
148
  * Get the first item matching the filter, or a default value if no match is found
149
149
  *
150
- * Available as `firstOrDefault` and `first.default`
150
+ * _Available as `firstOrDefault` and `first.default`_
151
151
  *
152
152
  * @param array Array to search in
153
153
  * @param defaultValue Default value to return if no match is found
@@ -172,7 +172,7 @@ export function firstOrDefault<Item>(
172
172
  /**
173
173
  * Get the first item from an array, or a default value if the array is empty
174
174
  *
175
- * Available as `firstOrDefault` and `first.default`
175
+ * _Available as `firstOrDefault` and `first.default`_
176
176
  *
177
177
  * @param array Array to get from
178
178
  * @param defaultValue Default value to return if the array is empty
package/src/array/get.ts CHANGED
@@ -20,6 +20,21 @@ export function getArray<Value extends PlainObject>(
20
20
  indiced: true,
21
21
  ): Value[NumericalKeys<Value>][];
22
22
 
23
+ /**
24
+ * Get an array from a map
25
+ *
26
+ * @param value Map to convert to an array
27
+ * @returns Array holding the entries of the map
28
+ *
29
+ * @example
30
+ * ```typescript
31
+ * getArray(
32
+ * new Map([['a', 1], ['b', 2], ['c', 3]]),
33
+ * ); // => [['a', 1], ['b', 2], ['c', 3]]
34
+ * ```
35
+ */
36
+ export function getArray<Key, Value>(map: Map<Key, Value>): [Key, Value][];
37
+
23
38
  /**
24
39
  * Get an array from an object
25
40
  *
@@ -32,7 +47,22 @@ export function getArray<Value extends PlainObject>(
32
47
  * getArray({a: 'a', b: 'b', c: 'c', d: 'd'}); // => ['a', 'b', 'c', 'd']
33
48
  * ```
34
49
  */
35
- export function getArray<Value extends PlainObject>(value: Value): Value[keyof Value][];
50
+ export function getArray<Value extends PlainObject>(
51
+ value: Value,
52
+ ): [keyof Value, Value[keyof Value]][];
53
+
54
+ /**
55
+ * Get an array from a set
56
+ *
57
+ * @param value Set to convert to an array
58
+ * @returns Array holding the values of the set
59
+ *
60
+ * @example
61
+ * ```typescript
62
+ * getArray(new Set([123, 456, 789])); // => [123, 456, 789]
63
+ * ```
64
+ */
65
+ export function getArray<Value>(set: Set<Value>): Value[];
36
66
 
37
67
  /**
38
68
  * Get an array from a value
@@ -65,7 +95,11 @@ export function getArray(value: unknown, indiced?: unknown): unknown[] {
65
95
  return value;
66
96
  }
67
97
 
68
- if (value instanceof Map || value instanceof Set) {
98
+ if (value instanceof Map) {
99
+ return [...value.entries()];
100
+ }
101
+
102
+ if (value instanceof Set) {
69
103
  return [...value.values()];
70
104
  }
71
105
 
@@ -74,7 +108,7 @@ export function getArray(value: unknown, indiced?: unknown): unknown[] {
74
108
  }
75
109
 
76
110
  if (indiced !== true) {
77
- return Object.values(value);
111
+ return Object.entries(value);
78
112
  }
79
113
 
80
114
  const keys = Object.keys(value);
@@ -84,9 +118,10 @@ export function getArray(value: unknown, indiced?: unknown): unknown[] {
84
118
 
85
119
  for (let index = 0; index < length; index += 1) {
86
120
  const key = keys[index];
121
+ const asNumber = Number.parseInt(key, 10);
87
122
 
88
- if (!Number.isNaN(Number(key))) {
89
- array.push(value[key]);
123
+ if (!Number.isNaN(asNumber)) {
124
+ array[asNumber] = (value as Record<string, unknown>)[key];
90
125
  }
91
126
  }
92
127
 
@@ -187,7 +187,7 @@ groupBy.arrays = groupArraysBy;
187
187
  /**
188
188
  * Create a record from an array of items using a specific key and value, grouping values into arrays
189
189
  *
190
- * Available as `groupArraysBy` and `groupBy.arrays`
190
+ * _Available as `groupArraysBy` and `groupBy.arrays`_
191
191
  *
192
192
  * @param array Array to group
193
193
  * @param key Callback to get an item's grouping key
@@ -219,7 +219,7 @@ export function groupArraysBy<
219
219
  /**
220
220
  * Create a record from an array of items using a specific key and value, grouping values into arrays
221
221
  *
222
- * Available as `groupArraysBy` and `groupBy.arrays`
222
+ * _Available as `groupArraysBy` and `groupBy.arrays`_
223
223
  *
224
224
  * @param array Array to group
225
225
  * @param key Callback to get an item's grouping key
@@ -251,7 +251,7 @@ export function groupArraysBy<
251
251
  /**
252
252
  * Create a record from an array of items using a specific key and value, grouping values into arrays
253
253
  *
254
- * Available as `groupArraysBy` and `groupBy.arrays`
254
+ * _Available as `groupArraysBy` and `groupBy.arrays`_
255
255
  *
256
256
  * @param array Array to group
257
257
  * @param key Key to use for grouping
@@ -283,7 +283,7 @@ export function groupArraysBy<
283
283
  /**
284
284
  * Create a record from an array of items using a specific key and value, grouping values into arrays
285
285
  *
286
- * Available as `groupArraysBy` and `groupBy.arrays`
286
+ * _Available as `groupArraysBy` and `groupBy.arrays`_
287
287
  *
288
288
  * @param array Array to group
289
289
  * @param key Key to use for grouping
@@ -315,7 +315,7 @@ export function groupArraysBy<
315
315
  /**
316
316
  * Create a record from an array of items using a specific key, grouping items into arrays
317
317
  *
318
- * Available as `groupArraysBy` and `groupBy.arrays`
318
+ * _Available as `groupArraysBy` and `groupBy.arrays`_
319
319
  *
320
320
  * @param array Array to group
321
321
  * @param callback Callback to get an item's grouping key
@@ -340,7 +340,7 @@ export function groupArraysBy<
340
340
  /**
341
341
  * Create a record from an array of items using a specific key, grouping items into arrays
342
342
  *
343
- * Available as `groupArraysBy` and `groupBy.arrays`
343
+ * _Available as `groupArraysBy` and `groupBy.arrays`_
344
344
  *
345
345
  * @param array Array to group
346
346
  * @param key Key to use for grouping
package/src/array/last.ts CHANGED
@@ -91,7 +91,7 @@ last.default = lastOrDefault;
91
91
  /**
92
92
  * Get the last item matching the given value
93
93
  *
94
- * Available as `lastOrDefault` and `last.default`
94
+ * _Available as `lastOrDefault` and `last.default`_
95
95
  *
96
96
  * @param array Array to search in
97
97
  * @param defaultValue Default value to return if no match is found
@@ -117,7 +117,7 @@ export function lastOrDefault<
117
117
  /**
118
118
  * Get the last item matching the given value by key
119
119
  *
120
- * Available as `lastOrDefault` and `last.default`
120
+ * _Available as `lastOrDefault` and `last.default`_
121
121
  *
122
122
  * @param array Array to search in
123
123
  * @param defaultValue Default value to return if no match is found
@@ -145,7 +145,7 @@ export function lastOrDefault<Item extends PlainObject, ItemKey extends keyof It
145
145
  /**
146
146
  * Get the last item matching the filter
147
147
  *
148
- * Available as `lastOrDefault` and `last.default`
148
+ * _Available as `lastOrDefault` and `last.default`_
149
149
  *
150
150
  * @param array Array to search in
151
151
  * @param defaultValue Default value to return if no match is found
@@ -170,7 +170,7 @@ export function lastOrDefault<Item>(
170
170
  /**
171
171
  * Get the last item from an array
172
172
  *
173
- * Available as `lastOrDefault` and `last.default`
173
+ * _Available as `lastOrDefault` and `last.default`_
174
174
  *
175
175
  * @param array Array to get from
176
176
  * @param defaultValue Default value to return if the array is empty
@@ -13,7 +13,8 @@ export type ArrayComparison = 'end' | 'inside' | 'invalid' | 'outside' | 'same'
13
13
  // #region Functions
14
14
 
15
15
  /**
16
- * Does the needle array end the haystack array?
16
+ * Is the needle array at the end of the haystack array?
17
+ *
17
18
  * @param haystack Haystack array
18
19
  * @param needle Needle array
19
20
  * @param callback Callback to get an item's value for matching
@@ -35,7 +36,7 @@ export function endsWithArray<Item>(
35
36
  ): boolean;
36
37
 
37
38
  /**
38
- * Does the needle array end the haystack array?
39
+ * Is the needle array at the end of the haystack array?
39
40
  *
40
41
  * @param haystack Haystack array
41
42
  * @param needle Needle array
@@ -58,7 +59,7 @@ export function endsWithArray<Item extends PlainObject>(
58
59
  ): boolean;
59
60
 
60
61
  /**
61
- * Does the needle array end the haystack array?
62
+ * Is the needle array at the end of the haystack array?
62
63
  *
63
64
  * @param haystack Haystack array
64
65
  * @param needle Needle array
@@ -343,7 +344,7 @@ export function indexOfArray(haystack: unknown[], needle: unknown[], key?: unkno
343
344
  }
344
345
 
345
346
  /**
346
- * Does the needle array start the haystack array?
347
+ * Is the needle array at the start of the haystack array?
347
348
  *
348
349
  * @param haystack Haystack array
349
350
  * @param needle Needle array
@@ -366,7 +367,7 @@ export function startsWithArray<Item>(
366
367
  ): boolean;
367
368
 
368
369
  /**
369
- * Does the needle array start the haystack array?
370
+ * Is the needle array at the start of the haystack array?
370
371
  *
371
372
  * @param haystack Haystack array
372
373
  * @param needle Needle array
@@ -389,7 +390,7 @@ export function startsWithArray<Item extends PlainObject>(
389
390
  ): boolean;
390
391
 
391
392
  /**
392
- * Does the needle array start the haystack array?
393
+ * Is the needle array at the start of the haystack array?
393
394
  *
394
395
  * @param haystack Haystack array
395
396
  * @param needle Needle array
package/src/array/move.ts CHANGED
@@ -7,7 +7,7 @@ import {indexOfArray} from './match';
7
7
  /**
8
8
  * Move an item _(or array of items)_ to the position of another item _(or array of items)_ within an array
9
9
  *
10
- * When moving to the front of the array, the moved items will be placed __before__ the target item. When moving to the back of the array, the moved items will be placed __after__ the target item.
10
+ * When moving to the front of the array, the moved items will be placed __before__ the target item. When moving to the back of the array, the moved items will be placed __after__ the target item
11
11
  *
12
12
  * If either of values are not present in the array, or if they overlap, the array will be returned unchanged
13
13
  *
@@ -36,7 +36,7 @@ export function move<Item>(
36
36
  /**
37
37
  * Move an item _(or array of items)_ to the position of another item _(or array of items)_ within an array
38
38
  *
39
- * When moving to the front of the array, the moved items will be placed __before__ the target item. When moving to the back of the array, the moved items will be placed __after__ the target item.
39
+ * When moving to the front of the array, the moved items will be placed __before__ the target item. When moving to the back of the array, the moved items will be placed __after__ the target item
40
40
  *
41
41
  * If either of values are not present in the array, or if they overlap, the array will be returned unchanged
42
42
  *
@@ -65,7 +65,7 @@ export function move<Item extends PlainObject, ItemKey extends keyof Item>(
65
65
  /**
66
66
  * Move an item _(or array of items)_ to the position of another item _(or array of items)_ within an array
67
67
  *
68
- * When moving to the front of the array, the moved items will be placed __before__ the target item. When moving to the back of the array, the moved items will be placed __after__ the target item.
68
+ * When moving to the front of the array, the moved items will be placed __before__ the target item. When moving to the back of the array, the moved items will be placed __after__ the target item
69
69
  *
70
70
  * If either of values are not present in the array, or if they overlap, the array will be returned unchanged
71
71
  *
@@ -145,7 +145,7 @@ move.toIndex = moveToIndex;
145
145
  *
146
146
  * If the from index is out of bounds, the array will be returned unchanged
147
147
  *
148
- * Available as `moveIndices` and `move.indices`
148
+ * _Available as `moveIndices` and `move.indices`_
149
149
  *
150
150
  * @param array Array to move within
151
151
  * @param from Index to move from
@@ -195,7 +195,7 @@ export function moveIndices<Item>(array: Item[], from: number, to: number): Item
195
195
  *
196
196
  * If the value is not present in the array, or if the index is out of bounds, the array will be returned unchanged
197
197
  *
198
- * Available as `moveToIndex` and `move.toIndex`
198
+ * _Available as `moveToIndex` and `move.toIndex`_
199
199
  *
200
200
  * @example
201
201
  * ```typescript
@@ -224,7 +224,7 @@ export function moveToIndex<Item>(
224
224
  *
225
225
  * If the value is not present in the array, or if the index is out of bounds, the array will be returned unchanged
226
226
  *
227
- * Available as `moveToIndex` and `move.toIndex`
227
+ * _Available as `moveToIndex` and `move.toIndex`_
228
228
  *
229
229
  * @param array Array to move within
230
230
  * @param value Item or items to move
@@ -253,7 +253,7 @@ export function moveToIndex<Item extends PlainObject, ItemKey extends keyof Item
253
253
  *
254
254
  * If the value is not present in the array, or if the index is out of bounds, the array will be returned unchanged
255
255
  *
256
- * Available as `moveToIndex` and `move.toIndex`
256
+ * _Available as `moveToIndex` and `move.toIndex`_
257
257
  *
258
258
  * @param array Array to move within
259
259
  * @param value Item or items to move
@@ -153,6 +153,7 @@ export function select<
153
153
 
154
154
  /**
155
155
  * Get a filtered and mapped array of items
156
+ *
156
157
  * @param array Array to search in
157
158
  * @param filterCallback Filter callback to match items
158
159
  * @param mapKey Key to get an item's value for mapping
@@ -173,7 +173,7 @@ function extract(
173
173
  }
174
174
 
175
175
  /**
176
- * Slice an array, returning a new array with a specified range of items
176
+ * Slice an array _(returning a new array with a specified range of items)_
177
177
  *
178
178
  * @param array Original array
179
179
  * @param start Start index _(inclusive)_
@@ -188,7 +188,7 @@ function extract(
188
188
  export function slice<Item>(array: Item[], start: number, end: number): Item[];
189
189
 
190
190
  /**
191
- * Slice an array, returning a new array with a specified number of items _(from the start)_
191
+ * Slice an array _(returning a new array with a specified number of items, from the start)_
192
192
  *
193
193
  * @param array Original array
194
194
  * @param count Maximum size of the new array
@@ -202,7 +202,7 @@ export function slice<Item>(array: Item[], start: number, end: number): Item[];
202
202
  export function slice<Item>(array: Item[], count: number): Item[];
203
203
 
204
204
  /**
205
- * Slice an array
205
+ * Slice an array _(returning a new array with all items)_
206
206
  *
207
207
  * @param array Array to slice
208
208
  * @returns Sliced array
package/src/array/sort.ts CHANGED
@@ -149,7 +149,7 @@ function getComparisonSorter(callback: Function, modifier: number): InternalSort
149
149
  simple: callback,
150
150
  },
151
151
  get: false,
152
- identifier: String(callback),
152
+ identifier: callback.toString(),
153
153
  };
154
154
  }
155
155
 
@@ -253,7 +253,7 @@ function getObjectSorter(obj: PlainObject, modifier: number): InternalSorter | u
253
253
  *
254
254
  * _(If the array is not sorted, it will be treated as sorted, and the result may be inaccurate)_
255
255
  *
256
- * Available as `getSortedIndex` and `sort.getIndex`
256
+ * _Available as `getSortedIndex` and `sort.getIndex`_
257
257
  *
258
258
  * @param array Array to get the index from
259
259
  * @param item Item to get the index for
@@ -273,7 +273,7 @@ export function getSortedIndex<Item>(
273
273
  *
274
274
  * _(If the array is not sorted, it will be treated as sorted, and the result may be inaccurate)_
275
275
  *
276
- * Available as `getSortedIndex` and `sort.getIndex`
276
+ * _Available as `getSortedIndex` and `sort.getIndex`_
277
277
  *
278
278
  * @param array Array to get the index from
279
279
  * @param item Item to get the index for
@@ -293,7 +293,7 @@ export function getSortedIndex<Item>(
293
293
  *
294
294
  * _(If the array is not sorted, it will be treated as sorted, and the result may be inaccurate)_
295
295
  *
296
- * Available as `getSortedIndex` and `sort.getIndex`
296
+ * _Available as `getSortedIndex` and `sort.getIndex`_
297
297
  *
298
298
  * @param array Array to get the index from
299
299
  * @param item Item to get the index for
@@ -360,18 +360,20 @@ function getSorters(value: unknown, modifier: number): InternalSorter[] {
360
360
  }
361
361
 
362
362
  function getValueSorter(value: string | Function, modifier: number): InternalSorter {
363
+ const isFunction = typeof value === 'function';
364
+
363
365
  return {
364
366
  modifier,
365
367
  get: true,
366
- identifier: String(value),
367
- value: typeof value === 'function' ? value : (item: unknown) => (item as PlainObject)[value],
368
+ identifier: isFunction ? value.toString() : value,
369
+ value: isFunction ? value : (item: unknown) => (item as PlainObject)[value],
368
370
  };
369
371
  }
370
372
 
371
373
  /**
372
374
  * Initialize a sort handler with sorters _(and an optional default direction)_
373
375
  *
374
- * Available as `initializeSorter` and `sort.initialize`
376
+ * _Available as `initializeSorter` and `sort.initialize`_
375
377
  *
376
378
  * @param sorters Sorters to use for sorting
377
379
  * @param descending Sort in descending order? _(defaults to `false`; overridden by individual sorters)_
@@ -385,7 +387,7 @@ export function initializeSorter<Item>(
385
387
  /**
386
388
  * Initialize a sort handler with a sorter _(and an optional default direction)_
387
389
  *
388
- * Available as `initializeSorter` and `sort.initialize`
390
+ * _Available as `initializeSorter` and `sort.initialize`_
389
391
  *
390
392
  * @param sorter Sorter to use for sorting
391
393
  * @param descending Sort in descending order? _(defaults to `false`; overridden by individual sorters)_
@@ -399,7 +401,7 @@ export function initializeSorter<Item>(
399
401
  /**
400
402
  * Initialize a sort handler _(with an optional default direction)_
401
403
  *
402
- * Available as `initializeSorter` and `sort.initialize`
404
+ * _Available as `initializeSorter` and `sort.initialize`_
403
405
  *
404
406
  * @param descending Sort in descending order? _(defaults to `false`)_
405
407
  * @returns Sort handler
@@ -448,7 +450,7 @@ export function isSorted<Item>(
448
450
  /**
449
451
  * Is the array sorted?
450
452
  *
451
- * Available as `isSorted` and `sort.is`
453
+ * _Available as `isSorted` and `sort.is`_
452
454
  *
453
455
  * @param array Array to check
454
456
  * @param descending Sorted in descending order? _(defaults to `false`)_
@@ -534,6 +536,7 @@ export function sort<Item>(
534
536
 
535
537
  /**
536
538
  * Sort an array of items, using multiple sorters to sort by specific values
539
+ *
537
540
  * @param array Array to sort
538
541
  * @param sorters Sorters to use for sorting
539
542
  * @param descending Sort in descending order? _(defaults to `false`; overridden by individual sorters)_
@@ -547,6 +550,7 @@ export function sort<Item>(
547
550
 
548
551
  /**
549
552
  * Sort an array of items, using a single sorter to sort by a specific value
553
+ *
550
554
  * @param array Array to sort
551
555
  * @param sorter Sorter to use for sorting
552
556
  * @param descending Sort in descending order? _(defaults to `false`; overridden by individual sorters)_
@@ -556,6 +560,7 @@ export function sort<Item>(array: Item[], sorter: ArraySorter<Item>, descending?
556
560
 
557
561
  /**
558
562
  * Sort an array of items
563
+ *
559
564
  * @param array Array to sort
560
565
  * @param descending Sort in descending order? _(defaults to `false`)_
561
566
  * @returns Sorted array
package/src/array/swap.ts CHANGED
@@ -270,7 +270,7 @@ function swapArrays(array: unknown[], from: unknown[], to: unknown[], key: unkno
270
270
  *
271
271
  * If either index is out of bounds, the array will be returned unchanged
272
272
  *
273
- * Available as `swapIndices` and `swap.indices`
273
+ * _Available as `swapIndices` and `swap.indices`_
274
274
  *
275
275
  * @param array Array of items to swap
276
276
  * @param first First index _(can be negative to count from the end)_