@oscarpalmer/atoms 0.193.0 → 0.194.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 (204) hide show
  1. package/dist/array/difference.mjs +2 -2
  2. package/dist/array/intersection.mjs +2 -2
  3. package/dist/array/match.mjs +13 -13
  4. package/dist/array/slice.mjs +5 -5
  5. package/dist/array/sort.d.mts +5 -1
  6. package/dist/array/sort.mjs +4 -2
  7. package/dist/array/union.mjs +2 -2
  8. package/dist/beacon.d.mts +8 -1
  9. package/dist/beacon.mjs +52 -60
  10. package/dist/color/constants.d.mts +1 -1
  11. package/dist/color/constants.mjs +3 -5
  12. package/dist/color/instance.mjs +34 -41
  13. package/dist/color/misc/format.d.mts +3 -2
  14. package/dist/color/misc/format.mjs +4 -1
  15. package/dist/color/misc/is.d.mts +9 -1
  16. package/dist/color/misc/is.mjs +11 -1
  17. package/dist/color/misc/state.d.mts +6 -6
  18. package/dist/color/misc/state.mjs +11 -14
  19. package/dist/color/models.d.mts +23 -68
  20. package/dist/function/assert.mjs +2 -2
  21. package/dist/function/limit.d.mts +0 -6
  22. package/dist/function/limit.mjs +2 -2
  23. package/dist/function/memoize.mjs +19 -32
  24. package/dist/function/once.d.mts +0 -3
  25. package/dist/function/once.mjs +16 -13
  26. package/dist/function/retry.d.mts +1 -24
  27. package/dist/function/retry.mjs +1 -1
  28. package/dist/function/work.mjs +13 -11
  29. package/dist/herald.d.mts +30 -31
  30. package/dist/herald.mjs +74 -56
  31. package/dist/index.d.mts +100 -185
  32. package/dist/index.mjs +680 -702
  33. package/dist/internal/abort.d.mts +10 -0
  34. package/dist/internal/abort.mjs +14 -0
  35. package/dist/internal/array/chunk.mjs +2 -2
  36. package/dist/internal/array/find.mjs +2 -2
  37. package/dist/internal/array/sets.d.mts +4 -4
  38. package/dist/internal/array/sets.mjs +7 -7
  39. package/dist/internal/function/timer.mjs +19 -15
  40. package/dist/internal/number.mjs +7 -7
  41. package/dist/internal/result.mjs +3 -3
  42. package/dist/internal/sized.mjs +4 -4
  43. package/dist/internal/string.mjs +4 -4
  44. package/dist/internal/subscription.d.mts +24 -8
  45. package/dist/internal/subscription.mjs +49 -36
  46. package/dist/internal/value/equal.mjs +6 -6
  47. package/dist/internal/value/misc.mjs +14 -14
  48. package/dist/internal/value/set.mjs +2 -2
  49. package/dist/logger.mjs +15 -39
  50. package/dist/promise/constants.d.mts +17 -0
  51. package/dist/promise/constants.mjs +14 -0
  52. package/dist/promise/delay.mjs +7 -10
  53. package/dist/promise/helpers.mjs +1 -1
  54. package/dist/promise/index.mjs +14 -17
  55. package/dist/promise/misc.d.mts +2 -1
  56. package/dist/promise/misc.mjs +8 -7
  57. package/dist/promise/models.d.mts +4 -16
  58. package/dist/promise/models.mjs +4 -13
  59. package/dist/promise/timed.mjs +9 -10
  60. package/dist/query.mjs +15 -15
  61. package/dist/queue.mjs +103 -116
  62. package/dist/random.mjs +7 -7
  63. package/dist/result/index.d.mts +0 -3
  64. package/dist/result/index.mjs +1 -1
  65. package/dist/result/match.d.mts +0 -3
  66. package/dist/result/match.mjs +4 -4
  67. package/dist/result/misc.mjs +2 -2
  68. package/dist/result/work/flow.d.mts +0 -3
  69. package/dist/result/work/flow.mjs +5 -5
  70. package/dist/result/work/pipe.d.mts +0 -3
  71. package/dist/result/work/pipe.mjs +3 -3
  72. package/dist/string/case.mjs +20 -20
  73. package/dist/string/fuzzy.mjs +23 -18
  74. package/dist/string/index.mjs +7 -7
  75. package/dist/string/normalize.mjs +14 -14
  76. package/dist/string/template.mjs +2 -2
  77. package/dist/value/clone.mjs +10 -10
  78. package/dist/value/smush.mjs +2 -2
  79. package/package.json +13 -5
  80. package/src/array/difference.ts +0 -73
  81. package/src/array/exists.ts +0 -93
  82. package/src/array/filter.ts +0 -182
  83. package/src/array/find.ts +0 -183
  84. package/src/array/first.ts +0 -196
  85. package/src/array/flatten.ts +0 -20
  86. package/src/array/from.ts +0 -129
  87. package/src/array/get.ts +0 -131
  88. package/src/array/group-by.ts +0 -369
  89. package/src/array/index.ts +0 -26
  90. package/src/array/insert.ts +0 -52
  91. package/src/array/intersection.ts +0 -72
  92. package/src/array/last.ts +0 -194
  93. package/src/array/match.ts +0 -436
  94. package/src/array/move.ts +0 -315
  95. package/src/array/partition.ts +0 -91
  96. package/src/array/push.ts +0 -23
  97. package/src/array/reverse.ts +0 -33
  98. package/src/array/select.ts +0 -260
  99. package/src/array/single.ts +0 -93
  100. package/src/array/slice.ts +0 -335
  101. package/src/array/sort.ts +0 -607
  102. package/src/array/splice.ts +0 -106
  103. package/src/array/swap.ts +0 -322
  104. package/src/array/to-map.ts +0 -371
  105. package/src/array/to-record.ts +0 -351
  106. package/src/array/to-set.ts +0 -80
  107. package/src/array/toggle.ts +0 -79
  108. package/src/array/union.ts +0 -72
  109. package/src/array/unique.ts +0 -67
  110. package/src/array/update.ts +0 -75
  111. package/src/beacon.ts +0 -378
  112. package/src/color/constants.ts +0 -137
  113. package/src/color/index.ts +0 -83
  114. package/src/color/instance.ts +0 -162
  115. package/src/color/misc/alpha.ts +0 -56
  116. package/src/color/misc/format.ts +0 -29
  117. package/src/color/misc/get.ts +0 -210
  118. package/src/color/misc/is.ts +0 -221
  119. package/src/color/misc/state.ts +0 -243
  120. package/src/color/models.ts +0 -389
  121. package/src/color/space/hex.ts +0 -184
  122. package/src/color/space/hsl.ts +0 -174
  123. package/src/color/space/hwb.ts +0 -153
  124. package/src/color/space/rgb.ts +0 -240
  125. package/src/function/assert.ts +0 -174
  126. package/src/function/index.ts +0 -2
  127. package/src/function/limit.ts +0 -83
  128. package/src/function/memoize.ts +0 -202
  129. package/src/function/once.ts +0 -200
  130. package/src/function/retry.ts +0 -175
  131. package/src/function/work.ts +0 -1007
  132. package/src/herald.ts +0 -216
  133. package/src/index.ts +0 -68
  134. package/src/internal/array/callbacks.ts +0 -46
  135. package/src/internal/array/chunk.ts +0 -51
  136. package/src/internal/array/compact.ts +0 -56
  137. package/src/internal/array/find.ts +0 -200
  138. package/src/internal/array/group.ts +0 -42
  139. package/src/internal/array/index-of.ts +0 -182
  140. package/src/internal/array/insert.ts +0 -80
  141. package/src/internal/array/overlap.ts +0 -35
  142. package/src/internal/array/sets.ts +0 -74
  143. package/src/internal/array/shuffle.ts +0 -33
  144. package/src/internal/array/update.ts +0 -52
  145. package/src/internal/function/misc.ts +0 -8
  146. package/src/internal/function/timer.ts +0 -168
  147. package/src/internal/is.ts +0 -244
  148. package/src/internal/math/aggregate.ts +0 -164
  149. package/src/internal/math/misc.ts +0 -28
  150. package/src/internal/number.ts +0 -129
  151. package/src/internal/random.ts +0 -49
  152. package/src/internal/result.ts +0 -92
  153. package/src/internal/sized.ts +0 -25
  154. package/src/internal/string.ts +0 -128
  155. package/src/internal/subscription.ts +0 -264
  156. package/src/internal/value/compare.ts +0 -170
  157. package/src/internal/value/equal.ts +0 -465
  158. package/src/internal/value/get.ts +0 -57
  159. package/src/internal/value/handlers.ts +0 -95
  160. package/src/internal/value/has.ts +0 -118
  161. package/src/internal/value/misc.ts +0 -125
  162. package/src/internal/value/partial.ts +0 -46
  163. package/src/internal/value/set.ts +0 -132
  164. package/src/is.ts +0 -182
  165. package/src/logger.ts +0 -230
  166. package/src/math.ts +0 -281
  167. package/src/models.ts +0 -286
  168. package/src/number.ts +0 -1
  169. package/src/promise/delay.ts +0 -62
  170. package/src/promise/helpers.ts +0 -96
  171. package/src/promise/index.ts +0 -300
  172. package/src/promise/misc.ts +0 -96
  173. package/src/promise/models.ts +0 -195
  174. package/src/promise/timed.ts +0 -91
  175. package/src/query.ts +0 -147
  176. package/src/queue.ts +0 -814
  177. package/src/random.ts +0 -125
  178. package/src/result/index.ts +0 -105
  179. package/src/result/match.ts +0 -124
  180. package/src/result/misc.ts +0 -129
  181. package/src/result/models.ts +0 -83
  182. package/src/result/work/flow.ts +0 -488
  183. package/src/result/work/pipe.ts +0 -496
  184. package/src/sized/map.ts +0 -110
  185. package/src/sized/set.ts +0 -107
  186. package/src/string/case.ts +0 -236
  187. package/src/string/fuzzy.ts +0 -444
  188. package/src/string/index.ts +0 -199
  189. package/src/string/match.ts +0 -80
  190. package/src/string/normalize.ts +0 -205
  191. package/src/string/template.ts +0 -161
  192. package/src/value/clone.ts +0 -319
  193. package/src/value/collection.ts +0 -63
  194. package/src/value/diff.ts +0 -232
  195. package/src/value/freeze.ts +0 -322
  196. package/src/value/handle.ts +0 -3
  197. package/src/value/index.ts +0 -5
  198. package/src/value/merge.ts +0 -278
  199. package/src/value/omit.ts +0 -20
  200. package/src/value/pick.ts +0 -20
  201. package/src/value/shake.ts +0 -45
  202. package/src/value/smush.ts +0 -89
  203. package/src/value/transform.ts +0 -153
  204. package/src/value/unsmush.ts +0 -84
package/src/array/find.ts DELETED
@@ -1,183 +0,0 @@
1
- import {FIND_VALUE_ITEM, findValue} from '../internal/array/find';
2
- import type {PlainObject} from '../models';
3
-
4
- // #region Functions
5
-
6
- /**
7
- * Get the first item matching the given value
8
- *
9
- * @param array Array to search in
10
- * @param callback Callback to get an item's value for matching
11
- * @param value Value to match against
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
- * ```
22
- */
23
- export function find<Item, Callback extends (item: Item, index: number, array: Item[]) => unknown>(
24
- array: Item[],
25
- callback: Callback,
26
- value: ReturnType<Callback>,
27
- ): Item | undefined;
28
-
29
- /**
30
- * Get the first item matching the given value by key
31
- *
32
- * @param array Array to search in
33
- * @param key Key to get an item's value for matching
34
- * @param value Value to match against
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
- * ```
45
- */
46
- export function find<Item extends PlainObject, ItemKey extends keyof Item>(
47
- array: Item[],
48
- key: ItemKey,
49
- value: Item[ItemKey],
50
- ): Item | undefined;
51
-
52
- /**
53
- * Get the first item matching the filter
54
- *
55
- * @param array Array to search in
56
- * @param filter Filter callback to match items
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
- * ```
66
- */
67
- export function find<Item>(
68
- array: Item[],
69
- filter: (item: Item, index: number, array: Item[]) => boolean,
70
- ): Item | undefined;
71
-
72
- /**
73
- * Get the first item matching the given value
74
- *
75
- * @param array Array to search in
76
- * @param value Value to match against
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
- * ```
83
- */
84
- export function find<Item>(array: Item[], value: Item): Item | undefined;
85
-
86
- export function find(array: unknown[], ...parameters: unknown[]): unknown {
87
- return findValue(FIND_VALUE_ITEM, array, parameters, false);
88
- }
89
-
90
- find.last = findLast;
91
-
92
- /**
93
- * Get the last item matching the given value
94
- *
95
- * _Available as `findLast` and `find.last`_
96
- *
97
- * @param array Array to search in
98
- * @param callback Callback to get an item's value for matching
99
- * @param value Value to match against
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
- * ```
110
- */
111
- export function findLast<
112
- Item,
113
- Callback extends (item: Item, index: number, array: Item[]) => unknown,
114
- >(array: Item[], callback: Callback, value: ReturnType<Callback>): Item | undefined;
115
-
116
- /**
117
- * Get the last item matching the given value by key
118
- *
119
- * _Available as `findLast` and `find.last`_
120
- *
121
- * @param array Array to search in
122
- * @param key Key to get an item's value for matching
123
- * @param value Value to match against
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
- * ```
134
- */
135
- export function findLast<Item extends PlainObject, ItemKey extends keyof Item>(
136
- array: Item[],
137
- key: ItemKey,
138
- value: Item[ItemKey],
139
- ): Item | undefined;
140
-
141
- /**
142
- * Get the last item matching the filter
143
- *
144
- * _Available as `findLast` and `find.last`_
145
- *
146
- * @param array Array to search in
147
- * @param filter Filter callback to match items
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
- * ```
157
- */
158
- export function findLast<Item>(
159
- array: Item[],
160
- filter: (item: Item, index: number, array: Item[]) => boolean,
161
- ): Item | undefined;
162
-
163
- /**
164
- * Get the last item matching the given value
165
- *
166
- * _Available as `findLast` and `find.last`_
167
- *
168
- * @param array Array to search in
169
- * @param value Value to match against
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
- * ```
176
- */
177
- export function findLast<Item>(array: Item[], value: Item): Item | undefined;
178
-
179
- export function findLast(array: unknown[], ...parameters: unknown[]): unknown {
180
- return findValue(FIND_VALUE_ITEM, array, parameters, true);
181
- }
182
-
183
- // #endregion
@@ -1,196 +0,0 @@
1
- import {findAbsoluteValueOrDefault} from '../internal/array/find';
2
- import type {PlainObject} from '../models';
3
-
4
- // #region Functions
5
-
6
- /**
7
- * Get the first item matching the given value
8
- *
9
- * @param array Array to search in
10
- * @param callback Callback to get an item's value for matching
11
- * @param value Value to match against
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
- * ```
22
- */
23
- export function first<Item, Callback extends (item: Item, index: number, array: Item[]) => unknown>(
24
- array: Item[],
25
- callback: Callback,
26
- value: ReturnType<Callback>,
27
- ): Item | undefined;
28
-
29
- /**
30
- * Get the first item matching the given value by key
31
- *
32
- * @param array Array to search in
33
- * @param key Key to get an item's value for matching
34
- * @param value Value to match against
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
- * ```
45
- */
46
- export function first<Item extends PlainObject, ItemKey extends keyof Item>(
47
- array: Item[],
48
- key: ItemKey,
49
- value: Item[ItemKey],
50
- ): Item | undefined;
51
-
52
- /**
53
- * Get the first item matching the filter
54
- *
55
- * @param array Array to search in
56
- * @param filter Filter callback to match items
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
- * ```
66
- */
67
- export function first<Item>(
68
- array: Item[],
69
- filter: (item: Item, index: number, array: Item[]) => boolean,
70
- ): Item | undefined;
71
-
72
- /**
73
- * Get the first item from an array
74
- *
75
- * @param array Array to get from
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
- * ```
84
- */
85
- export function first<Item>(array: Item[]): Item | undefined;
86
-
87
- export function first(array: unknown[], ...parameters: unknown[]): unknown {
88
- return findAbsoluteValueOrDefault(array, parameters, undefined, false, false);
89
- }
90
-
91
- first.default = firstOrDefault;
92
-
93
- /**
94
- * Get the first item matching the given value, or a default value if no match is found
95
- *
96
- * _Available as `firstOrDefault` and `first.default`_
97
- *
98
- * @param array Array to search in
99
- * @param defaultValue Default value to return if no match is found
100
- * @param callback Callback to get an item's value for matching
101
- * @param value Value to match against
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
- * ```
113
- */
114
- export function firstOrDefault<
115
- Item,
116
- Callback extends (item: Item, index: number, array: Item[]) => unknown,
117
- >(array: Item[], defaultValue: Item, callback: Callback, value: ReturnType<Callback>): Item;
118
-
119
- /**
120
- * Get the first item matching the given value by key, or a default value if no match is found
121
- *
122
- * _Available as `firstOrDefault` and `first.default`_
123
- *
124
- * @param array Array to search in
125
- * @param defaultValue Default value to return if no match is found
126
- * @param key Key to get an item's value for matching
127
- * @param value Value to match against
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
- * ```
139
- */
140
- export function firstOrDefault<Item extends PlainObject, ItemKey extends keyof Item>(
141
- array: Item[],
142
- defaultValue: Item,
143
- key: ItemKey,
144
- value: Item[ItemKey],
145
- ): Item;
146
-
147
- /**
148
- * Get the first item matching the filter, or a default value if no match is found
149
- *
150
- * _Available as `firstOrDefault` and `first.default`_
151
- *
152
- * @param array Array to search in
153
- * @param defaultValue Default value to return if no match is found
154
- * @param filter Filter callback to match items
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
- * ```
165
- */
166
- export function firstOrDefault<Item>(
167
- array: Item[],
168
- defaultValue: Item,
169
- filter: (item: Item, index: number, array: Item[]) => boolean,
170
- ): Item;
171
-
172
- /**
173
- * Get the first item from an array, or a default value if the array is empty
174
- *
175
- * _Available as `firstOrDefault` and `first.default`_
176
- *
177
- * @param array Array to get from
178
- * @param defaultValue Default value to return 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
- * ```
185
- */
186
- export function firstOrDefault<Item>(array: Item[], defaultValue: Item): Item;
187
-
188
- export function firstOrDefault(
189
- array: unknown[],
190
- defaultValue: unknown,
191
- ...parameters: unknown[]
192
- ): unknown {
193
- return findAbsoluteValueOrDefault(array, parameters, defaultValue, true, false);
194
- }
195
-
196
- // #endregion
@@ -1,20 +0,0 @@
1
- import type {NestedArray} from '../models';
2
-
3
- // #region Functions
4
-
5
- /**
6
- * Flatten an array _(using native `flat` and maximum depth)_
7
- *
8
- * @param array Array to flatten
9
- * @returns Flattened array
10
- *
11
- * @example
12
- * ```typescript
13
- * flatten([1, [2, [3, 4], 5], 6]); // => [1, 2, 3, 4, 5, 6]
14
- * ```
15
- */
16
- export function flatten<Item>(array: Item[]): NestedArray<Item>[] {
17
- return (Array.isArray(array) ? array.flat(Number.POSITIVE_INFINITY) : []) as NestedArray<Item>[];
18
- }
19
-
20
- // #endregion
package/src/array/from.ts DELETED
@@ -1,129 +0,0 @@
1
- // #region Functions
2
-
3
- /**
4
- * Get an array with a specified length, filled with indices
5
- *
6
- * @param length Length of the array
7
- * @returns Array of indices
8
- *
9
- * @example
10
- * ```typescript
11
- * range(5); // => [0, 1, 2, 3, 4]
12
- * ```
13
- */
14
- export function range(length: number): number[];
15
-
16
- /**
17
- * Get an array of numbers in a specified range
18
- *
19
- * @param start Starting number _(inclusive)_
20
- * @param end Ending number _(exclusive)_
21
- * @returns Array of numbers in range
22
- *
23
- * @example
24
- * ```typescript
25
- * range(2, 5); // => [2, 3, 4]
26
- * ```
27
- */
28
- export function range(start: number, end: number): number[];
29
-
30
- /**
31
- * Get an array of numbers in a specified range with a specified step
32
- *
33
- * @param start Starting number _(inclusive)_
34
- * @param end Ending number _(exclusive)_
35
- * @param step Step between numbers
36
- * @returns Array of numbers in range
37
- *
38
- * @example
39
- * ```typescript
40
- * range(0, 10, 2); // => [0, 2, 4, 6, 8]
41
- * ```
42
- */
43
- export function range(start: number, end: number, step: number): number[];
44
-
45
- export function range(first: number, second?: number, third?: number): number[] {
46
- const start = typeof second === 'number' ? first : 0;
47
- const end = typeof second === 'number' ? second : first;
48
- const step = typeof third === 'number' ? third : 1;
49
-
50
- const values: number[] = [];
51
-
52
- if (step === 0) {
53
- return values;
54
- }
55
-
56
- if (step > 0) {
57
- for (let i = start; i < end; i += step) {
58
- values.push(i);
59
- }
60
- } else {
61
- for (let i = start; i > end; i += step) {
62
- values.push(i);
63
- }
64
- }
65
-
66
- return values;
67
- }
68
-
69
- /**
70
- * Get an array with a specified length, filled with indices
71
- *
72
- * @param length Length of the array
73
- * @returns Array of indices
74
- *
75
- * @example
76
- * ```typescript
77
- * times(5); // => [0, 1, 2, 3, 4]
78
- * ```
79
- */
80
- export function times(length: number): number[];
81
-
82
- /**
83
- * Get an array with a specified length, filled by values from a callback
84
- *
85
- * @param length Length of the array
86
- * @param callback Callback function to generate values
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
- * ```
93
- */
94
- export function times<Callback extends (index: number) => unknown>(
95
- length: number,
96
- callback: Callback,
97
- ): ReturnType<Callback>[];
98
-
99
- /**
100
- * Get an array with a specified length, filled with a specified value
101
- *
102
- * @param length Length of the array
103
- * @param value Value to fill the array with
104
- * @returns Array filled with the specified value
105
- *
106
- * @example
107
- * ```typescript
108
- * times(5, 'a'); // => ['a', 'a', 'a', 'a', 'a']
109
- * ```
110
- */
111
- export function times<Value>(length: number, value: Value): Value[];
112
-
113
- export function times(length: number, value?: unknown): unknown[] {
114
- if (typeof length !== 'number' || length <= 0) {
115
- return [];
116
- }
117
-
118
- const isFunction = typeof value === 'function';
119
-
120
- const values: unknown[] = [];
121
-
122
- for (let index = 0; index < length; index += 1) {
123
- values.push(isFunction ? (value as (index: number) => unknown)(index) : (value ?? index));
124
- }
125
-
126
- return values;
127
- }
128
-
129
- // #endregion
package/src/array/get.ts DELETED
@@ -1,131 +0,0 @@
1
- import {isNonPlainObject} from '../internal/is';
2
- import type {NumericalKeys, PlainObject} from '../models';
3
-
4
- // #region Functions
5
-
6
- /**
7
- * Get an array from an object, where only values with numerical keys will be included
8
- *
9
- * @param value Object to convert to an array
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
- * ```
17
- */
18
- export function getArray<Value extends PlainObject>(
19
- value: Value,
20
- indiced: true,
21
- ): Value[NumericalKeys<Value>][];
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
-
38
- /**
39
- * Get an array from an object
40
- *
41
- * @param value Object to convert to an array
42
- * @returns Array holding the values of the object
43
- *
44
- * @example
45
- * ```typescript
46
- * getArray({0: 'a', 1: 'b', 2: 'c', d: 'd'}); // => ['a', 'b', 'c', 'd']
47
- * getArray({a: 'a', b: 'b', c: 'c', d: 'd'}); // => ['a', 'b', 'c', 'd']
48
- * ```
49
- */
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[];
66
-
67
- /**
68
- * Get an array from a value
69
- *
70
- * @param value Original array
71
- * @returns Original array
72
- *
73
- * @example
74
- * ```typescript
75
- * getArray([123]); // => [123]
76
- * ```
77
- */
78
- export function getArray<Item>(value: Item[]): Item[];
79
-
80
- /**
81
- * Get an array from an unknown value
82
- *
83
- * @param value Value to convert to an array
84
- * @returns Array of value
85
- *
86
- * @example
87
- * ```typescript
88
- * getArray(123); // => [123]
89
- * ```
90
- */
91
- export function getArray<Value>(value: Value): Value[];
92
-
93
- export function getArray(value: unknown, indiced?: unknown): unknown[] {
94
- if (Array.isArray(value)) {
95
- return value;
96
- }
97
-
98
- if (value instanceof Map) {
99
- return [...value.entries()];
100
- }
101
-
102
- if (value instanceof Set) {
103
- return [...value.values()];
104
- }
105
-
106
- if (isNonPlainObject(value)) {
107
- return [value];
108
- }
109
-
110
- if (indiced !== true) {
111
- return Object.entries(value);
112
- }
113
-
114
- const keys = Object.keys(value);
115
- const {length} = keys;
116
-
117
- const array: unknown[] = [];
118
-
119
- for (let index = 0; index < length; index += 1) {
120
- const key = keys[index];
121
- const asNumber = Number.parseInt(key, 10);
122
-
123
- if (!Number.isNaN(asNumber)) {
124
- array[asNumber] = (value as Record<string, unknown>)[key];
125
- }
126
- }
127
-
128
- return array;
129
- }
130
-
131
- // #endregion