@oscarpalmer/atoms 0.184.2 → 0.186.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 (156) hide show
  1. package/dist/array/difference.d.mts +29 -0
  2. package/dist/array/exists.d.mts +35 -0
  3. package/dist/array/filter.d.mts +72 -2
  4. package/dist/array/find.d.mts +70 -0
  5. package/dist/array/first.d.mts +77 -2
  6. package/dist/array/flatten.d.mts +6 -0
  7. package/dist/array/flatten.mjs +6 -0
  8. package/dist/array/from.d.mts +36 -0
  9. package/dist/array/get.d.mts +21 -13
  10. package/dist/array/group-by.d.mts +142 -0
  11. package/dist/array/index.d.mts +2 -2
  12. package/dist/array/index.mjs +2 -2
  13. package/dist/array/insert.d.mts +16 -0
  14. package/dist/array/intersection.d.mts +29 -0
  15. package/dist/array/last.d.mts +75 -2
  16. package/dist/array/{position.d.mts → match.d.mts} +168 -36
  17. package/dist/array/{position.mjs → match.mjs} +16 -16
  18. package/dist/array/move.d.mts +78 -8
  19. package/dist/array/move.mjs +11 -1
  20. package/dist/array/partition.d.mts +35 -0
  21. package/dist/array/push.d.mts +8 -0
  22. package/dist/array/push.mjs +8 -0
  23. package/dist/array/reverse.d.mts +1 -0
  24. package/dist/array/reverse.mjs +1 -0
  25. package/dist/array/select.d.mts +94 -8
  26. package/dist/array/single.d.mts +29 -0
  27. package/dist/array/slice.d.mts +106 -16
  28. package/dist/array/sort.d.mts +30 -4
  29. package/dist/array/sort.mjs +1 -1
  30. package/dist/array/splice.d.mts +48 -0
  31. package/dist/array/splice.mjs +2 -1
  32. package/dist/array/swap.d.mts +113 -8
  33. package/dist/array/swap.mjs +2 -1
  34. package/dist/array/to-map.d.mts +124 -0
  35. package/dist/array/to-record.d.mts +124 -0
  36. package/dist/array/to-set.d.mts +24 -0
  37. package/dist/array/toggle.d.mts +38 -3
  38. package/dist/array/union.d.mts +29 -0
  39. package/dist/array/unique.d.mts +24 -0
  40. package/dist/array/update.d.mts +38 -3
  41. package/dist/beacon.d.mts +12 -0
  42. package/dist/beacon.mjs +9 -0
  43. package/dist/color/instance.d.mts +8 -0
  44. package/dist/color/instance.mjs +3 -0
  45. package/dist/color/models.d.mts +30 -0
  46. package/dist/function/assert.d.mts +29 -8
  47. package/dist/function/assert.mjs +29 -8
  48. package/dist/function/memoize.d.mts +3 -0
  49. package/dist/function/memoize.mjs +3 -0
  50. package/dist/function/retry.d.mts +3 -0
  51. package/dist/function/retry.mjs +3 -0
  52. package/dist/function/work.mjs +1 -1
  53. package/dist/index.d.mts +2158 -288
  54. package/dist/index.mjs +294 -181
  55. package/dist/internal/array/chunk.d.mts +6 -0
  56. package/dist/internal/array/chunk.mjs +6 -0
  57. package/dist/internal/array/compact.d.mts +12 -0
  58. package/dist/internal/array/index-of.d.mts +70 -0
  59. package/dist/internal/math/aggregate.d.mts +29 -0
  60. package/dist/internal/value/compare.d.mts +2 -1
  61. package/dist/internal/value/equal.d.mts +5 -0
  62. package/dist/internal/value/get.d.mts +27 -5
  63. package/dist/internal/value/has.d.mts +7 -7
  64. package/dist/internal/value/has.mjs +1 -1
  65. package/dist/internal/value/misc.d.mts +2 -2
  66. package/dist/internal/value/misc.mjs +10 -4
  67. package/dist/logger.d.mts +11 -0
  68. package/dist/logger.mjs +11 -0
  69. package/dist/models.d.mts +14 -1
  70. package/dist/promise/helpers.mjs +1 -1
  71. package/dist/promise/index.d.mts +0 -6
  72. package/dist/promise/models.d.mts +36 -0
  73. package/dist/promise/models.mjs +6 -0
  74. package/dist/queue.d.mts +13 -1
  75. package/dist/queue.mjs +9 -0
  76. package/dist/result/index.d.mts +0 -8
  77. package/dist/result/index.mjs +0 -8
  78. package/dist/result/match.d.mts +4 -4
  79. package/dist/result/work/flow.d.mts +12 -36
  80. package/dist/result/work/pipe.d.mts +11 -33
  81. package/dist/sized/set.d.mts +3 -2
  82. package/dist/sized/set.mjs +3 -2
  83. package/dist/value/collection.d.mts +1 -1
  84. package/dist/value/handle.mjs +1 -1
  85. package/dist/value/merge.d.mts +28 -25
  86. package/dist/value/merge.mjs +29 -18
  87. package/dist/value/shake.d.mts +3 -0
  88. package/dist/value/smush.d.mts +3 -0
  89. package/dist/value/transform.d.mts +10 -1
  90. package/dist/value/unsmush.d.mts +2 -3
  91. package/package.json +5 -5
  92. package/src/array/difference.ts +33 -0
  93. package/src/array/exists.ts +35 -0
  94. package/src/array/filter.ts +72 -2
  95. package/src/array/find.ts +70 -0
  96. package/src/array/first.ts +77 -3
  97. package/src/array/flatten.ts +6 -0
  98. package/src/array/from.ts +40 -0
  99. package/src/array/get.ts +21 -15
  100. package/src/array/group-by.ts +142 -0
  101. package/src/array/index.ts +1 -1
  102. package/src/array/insert.ts +16 -2
  103. package/src/array/intersection.ts +33 -0
  104. package/src/array/last.ts +75 -2
  105. package/src/array/{position.ts → match.ts} +197 -65
  106. package/src/array/move.ts +87 -13
  107. package/src/array/partition.ts +35 -0
  108. package/src/array/push.ts +8 -2
  109. package/src/array/reverse.ts +5 -0
  110. package/src/array/select.ts +96 -13
  111. package/src/array/single.ts +29 -0
  112. package/src/array/slice.ts +114 -24
  113. package/src/array/sort.ts +30 -4
  114. package/src/array/splice.ts +52 -4
  115. package/src/array/swap.ts +122 -13
  116. package/src/array/to-map.ts +124 -0
  117. package/src/array/to-record.ts +124 -0
  118. package/src/array/to-set.ts +24 -0
  119. package/src/array/toggle.ts +42 -3
  120. package/src/array/union.ts +33 -0
  121. package/src/array/unique.ts +24 -0
  122. package/src/array/update.ts +38 -3
  123. package/src/beacon.ts +12 -0
  124. package/src/color/index.ts +0 -3
  125. package/src/color/instance.ts +9 -1
  126. package/src/color/models.ts +30 -0
  127. package/src/function/assert.ts +66 -7
  128. package/src/function/memoize.ts +3 -0
  129. package/src/function/once.ts +5 -1
  130. package/src/function/retry.ts +3 -0
  131. package/src/internal/array/chunk.ts +6 -0
  132. package/src/internal/array/compact.ts +12 -0
  133. package/src/internal/array/index-of.ts +70 -0
  134. package/src/internal/math/aggregate.ts +29 -0
  135. package/src/internal/string.ts +0 -2
  136. package/src/internal/value/compare.ts +2 -1
  137. package/src/internal/value/equal.ts +5 -0
  138. package/src/internal/value/get.ts +27 -5
  139. package/src/internal/value/has.ts +10 -10
  140. package/src/internal/value/misc.ts +24 -13
  141. package/src/logger.ts +11 -0
  142. package/src/models.ts +18 -0
  143. package/src/promise/index.ts +0 -6
  144. package/src/promise/models.ts +36 -0
  145. package/src/queue.ts +13 -1
  146. package/src/result/index.ts +0 -8
  147. package/src/result/match.ts +4 -4
  148. package/src/result/work/flow.ts +12 -36
  149. package/src/result/work/pipe.ts +11 -33
  150. package/src/sized/set.ts +4 -3
  151. package/src/value/collection.ts +1 -1
  152. package/src/value/merge.ts +88 -66
  153. package/src/value/shake.ts +3 -0
  154. package/src/value/smush.ts +3 -0
  155. package/src/value/transform.ts +10 -1
  156. package/src/value/unsmush.ts +2 -8
package/src/array/find.ts CHANGED
@@ -5,10 +5,20 @@ import type {PlainObject} from '../models';
5
5
 
6
6
  /**
7
7
  * Get the first item matching the given value
8
+ *
8
9
  * @param array Array to search in
9
10
  * @param callback Callback to get an item's value for matching
10
11
  * @param value Value to match against
11
12
  * @returns First item that matches the value, or `undefined` if no match is found
13
+ *
14
+ * @example
15
+ * ```typescript
16
+ * find(
17
+ * [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
18
+ * item => item.value,
19
+ * 10,
20
+ * ); // => {id: 1, value: 10}
21
+ * ```
12
22
  */
13
23
  export function find<Item, Callback extends (item: Item, index: number, array: Item[]) => unknown>(
14
24
  array: Item[],
@@ -18,10 +28,20 @@ export function find<Item, Callback extends (item: Item, index: number, array: I
18
28
 
19
29
  /**
20
30
  * Get the first item matching the given value by key
31
+ *
21
32
  * @param array Array to search in
22
33
  * @param key Key to get an item's value for matching
23
34
  * @param value Value to match against
24
35
  * @returns First item that matches the value, or `undefined` if no match is found
36
+ *
37
+ * @example
38
+ * ```typescript
39
+ * find(
40
+ * [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
41
+ * 'value',
42
+ * 10,
43
+ * ); // => {id: 1, value: 10}
44
+ * ```
25
45
  */
26
46
  export function find<Item extends PlainObject, ItemKey extends keyof Item>(
27
47
  array: Item[],
@@ -31,9 +51,18 @@ export function find<Item extends PlainObject, ItemKey extends keyof Item>(
31
51
 
32
52
  /**
33
53
  * Get the first item matching the filter
54
+ *
34
55
  * @param array Array to search in
35
56
  * @param filter Filter callback to match items
36
57
  * @returns First item that matches the filter, or `undefined` if no match is found
58
+ *
59
+ * @example
60
+ * ```typescript
61
+ * find(
62
+ * [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
63
+ * item => item.value === 10,
64
+ * ); // => {id: 1, value: 10}
65
+ * ```
37
66
  */
38
67
  export function find<Item>(
39
68
  array: Item[],
@@ -42,9 +71,15 @@ export function find<Item>(
42
71
 
43
72
  /**
44
73
  * Get the first item matching the given value
74
+ *
45
75
  * @param array Array to search in
46
76
  * @param value Value to match against
47
77
  * @returns First item that matches the value, or `undefined` if no match is found
78
+ *
79
+ * @example
80
+ * ```typescript
81
+ * find([1, 2, 3, 2, 1], 1); // => 1
82
+ * ```
48
83
  */
49
84
  export function find<Item>(array: Item[], value: Item): Item | undefined;
50
85
 
@@ -58,10 +93,20 @@ find.last = findLast;
58
93
  * Get the last item matching the given value
59
94
  *
60
95
  * Available as `findLast` and `find.last`
96
+ *
61
97
  * @param array Array to search in
62
98
  * @param callback Callback to get an item's value for matching
63
99
  * @param value Value to match against
64
100
  * @returns Last item that matches the value, or `undefined` if no match is found
101
+ *
102
+ * @example
103
+ * ```typescript
104
+ * findLast(
105
+ * [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
106
+ * item => item.value,
107
+ * 10,
108
+ * ); // => {id: 3, value: 10}
109
+ * ```
65
110
  */
66
111
  export function findLast<
67
112
  Item,
@@ -72,10 +117,20 @@ export function findLast<
72
117
  * Get the last item matching the given value by key
73
118
  *
74
119
  * Available as `findLast` and `find.last`
120
+ *
75
121
  * @param array Array to search in
76
122
  * @param key Key to get an item's value for matching
77
123
  * @param value Value to match against
78
124
  * @returns Last item that matches the value, or `undefined` if no match is found
125
+ *
126
+ * @example
127
+ * ```typescript
128
+ * findLast(
129
+ * [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
130
+ * 'value',
131
+ * 10,
132
+ * ); // => {id: 3, value: 10}
133
+ * ```
79
134
  */
80
135
  export function findLast<Item extends PlainObject, ItemKey extends keyof Item>(
81
136
  array: Item[],
@@ -87,9 +142,18 @@ export function findLast<Item extends PlainObject, ItemKey extends keyof Item>(
87
142
  * Get the last item matching the filter
88
143
  *
89
144
  * Available as `findLast` and `find.last`
145
+ *
90
146
  * @param array Array to search in
91
147
  * @param filter Filter callback to match items
92
148
  * @returns Last item that matches the filter, or `undefined` if no match is found
149
+ *
150
+ * @example
151
+ * ```typescript
152
+ * findLast(
153
+ * [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
154
+ * item => item.value === 10,
155
+ * ); // => {id: 3, value: 10}
156
+ * ```
93
157
  */
94
158
  export function findLast<Item>(
95
159
  array: Item[],
@@ -100,9 +164,15 @@ export function findLast<Item>(
100
164
  * Get the last item matching the given value
101
165
  *
102
166
  * Available as `findLast` and `find.last`
167
+ *
103
168
  * @param array Array to search in
104
169
  * @param value Value to match against
105
170
  * @returns Last item that matches the value, or `undefined` if no match is found
171
+ *
172
+ * @example
173
+ * ```typescript
174
+ * findLast([1, 2, 3, 2, 1], 1); // => 1
175
+ * ```
106
176
  */
107
177
  export function findLast<Item>(array: Item[], value: Item): Item | undefined;
108
178
 
@@ -5,10 +5,20 @@ import type {PlainObject} from '../models';
5
5
 
6
6
  /**
7
7
  * Get the first item matching the given value
8
+ *
8
9
  * @param array Array to search in
9
10
  * @param callback Callback to get an item's value for matching
10
11
  * @param value Value to match against
11
12
  * @returns First item that matches the value, or `undefined` if no match is found
13
+ *
14
+ * @example
15
+ * ```typescript
16
+ * first(
17
+ * [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
18
+ * item => item.value,
19
+ * 10,
20
+ * ); // => {id: 1, value: 10}
21
+ * ```
12
22
  */
13
23
  export function first<Item, Callback extends (item: Item, index: number, array: Item[]) => unknown>(
14
24
  array: Item[],
@@ -18,10 +28,20 @@ export function first<Item, Callback extends (item: Item, index: number, array:
18
28
 
19
29
  /**
20
30
  * Get the first item matching the given value by key
31
+ *
21
32
  * @param array Array to search in
22
33
  * @param key Key to get an item's value for matching
23
34
  * @param value Value to match against
24
35
  * @returns First item that matches the value, or `undefined` if no match is found
36
+ *
37
+ * @example
38
+ * ```typescript
39
+ * first(
40
+ * [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
41
+ * 'value',
42
+ * 10,
43
+ * ); // => {id: 1, value: 10}
44
+ * ```
25
45
  */
26
46
  export function first<Item extends PlainObject, ItemKey extends keyof Item>(
27
47
  array: Item[],
@@ -31,9 +51,18 @@ export function first<Item extends PlainObject, ItemKey extends keyof Item>(
31
51
 
32
52
  /**
33
53
  * Get the first item matching the filter
54
+ *
34
55
  * @param array Array to search in
35
56
  * @param filter Filter callback to match items
36
57
  * @returns First item that matches the filter, or `undefined` if no match is found
58
+ *
59
+ * @example
60
+ * ```typescript
61
+ * first(
62
+ * [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
63
+ * item => item.value === 10,
64
+ * ); // => {id: 1, value: 10}
65
+ * ```
37
66
  */
38
67
  export function first<Item>(
39
68
  array: Item[],
@@ -42,8 +71,16 @@ export function first<Item>(
42
71
 
43
72
  /**
44
73
  * Get the first item from an array
74
+ *
45
75
  * @param array Array to get from
46
- * @return First item from the array, or `undefined` if the array is empty
76
+ * @returns First item from the array, or `undefined` if the array is empty
77
+ *
78
+ * @example
79
+ * ```typescript
80
+ * first(
81
+ * [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
82
+ * ); // => {id: 1, value: 10}
83
+ * ```
47
84
  */
48
85
  export function first<Item>(array: Item[]): Item | undefined;
49
86
 
@@ -57,11 +94,22 @@ first.default = firstOrDefault;
57
94
  * Get the first item matching the given value, or a default value if no match is found
58
95
  *
59
96
  * Available as `firstOrDefault` and `first.default`
97
+ *
60
98
  * @param array Array to search in
61
99
  * @param defaultValue Default value to return if no match is found
62
100
  * @param callback Callback to get an item's value for matching
63
101
  * @param value Value to match against
64
102
  * @returns First item that matches the value, or the default value if no match is found
103
+ *
104
+ * @example
105
+ * ```typescript
106
+ * firstOrDefault(
107
+ * [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
108
+ * {id: -1, value: 30},
109
+ * item => item.value,
110
+ * 30,
111
+ * ); // => {id: -1, value: 30}
112
+ * ```
65
113
  */
66
114
  export function firstOrDefault<
67
115
  Item,
@@ -72,13 +120,23 @@ export function firstOrDefault<
72
120
  * Get the first item matching the given value by key, or a default value if no match is found
73
121
  *
74
122
  * Available as `firstOrDefault` and `first.default`
123
+ *
75
124
  * @param array Array to search in
76
125
  * @param defaultValue Default value to return if no match is found
77
126
  * @param key Key to get an item's value for matching
78
127
  * @param value Value to match against
79
128
  * @returns First item that matches the value, or the default value if no match is found
129
+ *
130
+ * @example
131
+ * ```typescript
132
+ * firstOrDefault(
133
+ * [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
134
+ * {id: -1, value: 30},
135
+ * 'value',
136
+ * 30,
137
+ * ); // => {id: -1, value: 30}
138
+ * ```
80
139
  */
81
-
82
140
  export function firstOrDefault<Item extends PlainObject, ItemKey extends keyof Item>(
83
141
  array: Item[],
84
142
  defaultValue: Item,
@@ -90,10 +148,20 @@ export function firstOrDefault<Item extends PlainObject, ItemKey extends keyof I
90
148
  * Get the first item matching the filter, or a default value if no match is found
91
149
  *
92
150
  * Available as `firstOrDefault` and `first.default`
151
+ *
93
152
  * @param array Array to search in
94
153
  * @param defaultValue Default value to return if no match is found
95
154
  * @param filter Filter callback to match items
96
155
  * @returns First item that matches the filter, or the default value if no match is found
156
+ *
157
+ * @example
158
+ * ```typescript
159
+ * firstOrDefault(
160
+ * [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
161
+ * {id: -1, value: 30},
162
+ * item => item.value === 30,
163
+ * ); // => {id: -1, value: 30}
164
+ * ```
97
165
  */
98
166
  export function firstOrDefault<Item>(
99
167
  array: Item[],
@@ -105,9 +173,15 @@ export function firstOrDefault<Item>(
105
173
  * Get the first item from an array, or a default value if the array is empty
106
174
  *
107
175
  * Available as `firstOrDefault` and `first.default`
176
+ *
108
177
  * @param array Array to get from
109
178
  * @param defaultValue Default value to return if the array is empty
110
- * @return First item from the array, or the default value if the array is empty
179
+ * @returns First item from the array, or the default value if the array is empty
180
+ *
181
+ * @example
182
+ * ```typescript
183
+ * firstOrDefault([], {id: -1, value: 30}); // => {id: -1, value: 30}
184
+ * ```
111
185
  */
112
186
  export function firstOrDefault<Item>(array: Item[], defaultValue: Item): Item;
113
187
 
@@ -4,8 +4,14 @@ import type {NestedArray} from '../models';
4
4
 
5
5
  /**
6
6
  * Flatten an array _(using native `flat` and maximum depth)_
7
+ *
7
8
  * @param array Array to flatten
8
9
  * @returns Flattened array
10
+ *
11
+ * @example
12
+ * ```typescript
13
+ * flatten([1, [2, [3, 4], 5], 6]); // => [1, 2, 3, 4, 5, 6]
14
+ * ```
9
15
  */
10
16
  export function flatten<Item>(array: Item[]): NestedArray<Item>[] {
11
17
  return (Array.isArray(array) ? array.flat(Number.POSITIVE_INFINITY) : []) as NestedArray<Item>[];
package/src/array/from.ts CHANGED
@@ -1,24 +1,44 @@
1
+ // #region Functions
2
+
1
3
  /**
2
4
  * Get an array with a specified length, filled with indices
5
+ *
3
6
  * @param length Length of the array
4
7
  * @returns Array of indices
8
+ *
9
+ * @example
10
+ * ```typescript
11
+ * range(5); // => [0, 1, 2, 3, 4]
12
+ * ```
5
13
  */
6
14
  export function range(length: number): number[];
7
15
 
8
16
  /**
9
17
  * Get an array of numbers in a specified range
18
+ *
10
19
  * @param start Starting number _(inclusive)_
11
20
  * @param end Ending number _(exclusive)_
12
21
  * @returns Array of numbers in range
22
+ *
23
+ * @example
24
+ * ```typescript
25
+ * range(2, 5); // => [2, 3, 4]
26
+ * ```
13
27
  */
14
28
  export function range(start: number, end: number): number[];
15
29
 
16
30
  /**
17
31
  * Get an array of numbers in a specified range with a specified step
32
+ *
18
33
  * @param start Starting number _(inclusive)_
19
34
  * @param end Ending number _(exclusive)_
20
35
  * @param step Step between numbers
21
36
  * @returns Array of numbers in range
37
+ *
38
+ * @example
39
+ * ```typescript
40
+ * range(0, 10, 2); // => [0, 2, 4, 6, 8]
41
+ * ```
22
42
  */
23
43
  export function range(start: number, end: number, step: number): number[];
24
44
 
@@ -48,16 +68,28 @@ export function range(first: number, second?: number, third?: number): number[]
48
68
 
49
69
  /**
50
70
  * Get an array with a specified length, filled with indices
71
+ *
51
72
  * @param length Length of the array
52
73
  * @returns Array of indices
74
+ *
75
+ * @example
76
+ * ```typescript
77
+ * times(5); // => [0, 1, 2, 3, 4]
78
+ * ```
53
79
  */
54
80
  export function times(length: number): number[];
55
81
 
56
82
  /**
57
83
  * Get an array with a specified length, filled by values from a callback
84
+ *
58
85
  * @param length Length of the array
59
86
  * @param callback Callback function to generate values
60
87
  * @returns Array of values generated by the callback
88
+ *
89
+ * @example
90
+ * ```typescript
91
+ * times(5, index => index * 2); // => [0, 2, 4, 6, 8]
92
+ * ```
61
93
  */
62
94
  export function times<Callback extends (index: number) => unknown>(
63
95
  length: number,
@@ -66,9 +98,15 @@ export function times<Callback extends (index: number) => unknown>(
66
98
 
67
99
  /**
68
100
  * Get an array with a specified length, filled with a specified value
101
+ *
69
102
  * @param length Length of the array
70
103
  * @param value Value to fill the array with
71
104
  * @returns Array filled with the specified value
105
+ *
106
+ * @example
107
+ * ```typescript
108
+ * times(5, 'a'); // => ['a', 'a', 'a', 'a', 'a']
109
+ * ```
72
110
  */
73
111
  export function times<Value>(length: number, value: Value): Value[];
74
112
 
@@ -87,3 +125,5 @@ export function times(length: number, value?: unknown): unknown[] {
87
125
 
88
126
  return values;
89
127
  }
128
+
129
+ // #endregion
package/src/array/get.ts CHANGED
@@ -5,8 +5,15 @@ import type {NumericalKeys, PlainObject} from '../models';
5
5
 
6
6
  /**
7
7
  * Get an array from an object, where only values with numerical keys will be included
8
+ *
8
9
  * @param value Object to convert to an array
9
10
  * @returns Array holding the values of the object's numerical keys
11
+ *
12
+ * @example
13
+ * ```typescript
14
+ * getArray({0: 'a', 1: 'b', 2: 'c', d: 'd'}, true); // => ['a', 'b', 'c']
15
+ * getArray({a: 'a', b: 'b', c: 'c', d: 'd'}, true); // => []
16
+ * ```
10
17
  */
11
18
  export function getArray<Value extends PlainObject>(
12
19
  value: Value,
@@ -15,32 +22,31 @@ export function getArray<Value extends PlainObject>(
15
22
 
16
23
  /**
17
24
  * Get an array from an object
25
+ *
18
26
  * @param value Object to convert to an array
19
27
  * @returns Array holding the values of the object
28
+ *
29
+ * @example
30
+ * ```typescript
31
+ * getArray({0: 'a', 1: 'b', 2: 'c', d: 'd'}); // => ['a', 'b', 'c', 'd']
32
+ * getArray({a: 'a', b: 'b', c: 'c', d: 'd'}); // => ['a', 'b', 'c', 'd']
33
+ * ```
20
34
  */
21
35
  export function getArray<Value extends PlainObject>(value: Value): Value[keyof Value][];
22
36
 
23
37
  /**
24
- * Get an array
38
+ * Get an array from a value
39
+ *
25
40
  * @param value Original array
26
41
  * @returns Original array
42
+ *
43
+ * @example
44
+ * ```typescript
45
+ * getArray(123); // => [123]
46
+ * ```
27
47
  */
28
48
  export function getArray<Item>(value: Item[]): Item[];
29
49
 
30
- /**
31
- * Get an array from a value
32
- * @param value Value to convert to an array
33
- * @returns Array holding the value
34
- */
35
- export function getArray<Item>(value: Item): Item[];
36
-
37
- /**
38
- * Get an array from an unknown value
39
- * @param value Value to convert to an array
40
- * @returns Array of value
41
- */
42
- export function getArray(value: unknown): unknown[];
43
-
44
50
  export function getArray(value: unknown, indiced?: unknown): unknown[] {
45
51
  if (Array.isArray(value)) {
46
52
  return value;