@oscarpalmer/atoms 0.192.0 → 0.193.1

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 (130) hide show
  1. package/dist/index.d.mts +25 -23
  2. package/dist/index.mjs +30 -31
  3. package/dist/queue.d.mts +25 -23
  4. package/dist/queue.mjs +27 -28
  5. package/package.json +3 -4
  6. package/src/array/difference.ts +0 -73
  7. package/src/array/exists.ts +0 -93
  8. package/src/array/filter.ts +0 -182
  9. package/src/array/find.ts +0 -183
  10. package/src/array/first.ts +0 -196
  11. package/src/array/flatten.ts +0 -20
  12. package/src/array/from.ts +0 -129
  13. package/src/array/get.ts +0 -131
  14. package/src/array/group-by.ts +0 -369
  15. package/src/array/index.ts +0 -26
  16. package/src/array/insert.ts +0 -52
  17. package/src/array/intersection.ts +0 -72
  18. package/src/array/last.ts +0 -194
  19. package/src/array/match.ts +0 -436
  20. package/src/array/move.ts +0 -315
  21. package/src/array/partition.ts +0 -91
  22. package/src/array/push.ts +0 -23
  23. package/src/array/reverse.ts +0 -33
  24. package/src/array/select.ts +0 -260
  25. package/src/array/single.ts +0 -93
  26. package/src/array/slice.ts +0 -335
  27. package/src/array/sort.ts +0 -607
  28. package/src/array/splice.ts +0 -106
  29. package/src/array/swap.ts +0 -322
  30. package/src/array/to-map.ts +0 -371
  31. package/src/array/to-record.ts +0 -351
  32. package/src/array/to-set.ts +0 -80
  33. package/src/array/toggle.ts +0 -79
  34. package/src/array/union.ts +0 -72
  35. package/src/array/unique.ts +0 -67
  36. package/src/array/update.ts +0 -75
  37. package/src/beacon.ts +0 -378
  38. package/src/color/constants.ts +0 -137
  39. package/src/color/index.ts +0 -83
  40. package/src/color/instance.ts +0 -162
  41. package/src/color/misc/alpha.ts +0 -56
  42. package/src/color/misc/format.ts +0 -29
  43. package/src/color/misc/get.ts +0 -210
  44. package/src/color/misc/is.ts +0 -221
  45. package/src/color/misc/state.ts +0 -243
  46. package/src/color/models.ts +0 -389
  47. package/src/color/space/hex.ts +0 -184
  48. package/src/color/space/hsl.ts +0 -174
  49. package/src/color/space/hwb.ts +0 -153
  50. package/src/color/space/rgb.ts +0 -240
  51. package/src/function/assert.ts +0 -174
  52. package/src/function/index.ts +0 -2
  53. package/src/function/limit.ts +0 -83
  54. package/src/function/memoize.ts +0 -202
  55. package/src/function/once.ts +0 -200
  56. package/src/function/retry.ts +0 -175
  57. package/src/function/work.ts +0 -1007
  58. package/src/herald.ts +0 -216
  59. package/src/index.ts +0 -68
  60. package/src/internal/array/callbacks.ts +0 -46
  61. package/src/internal/array/chunk.ts +0 -51
  62. package/src/internal/array/compact.ts +0 -56
  63. package/src/internal/array/find.ts +0 -200
  64. package/src/internal/array/group.ts +0 -42
  65. package/src/internal/array/index-of.ts +0 -182
  66. package/src/internal/array/insert.ts +0 -80
  67. package/src/internal/array/overlap.ts +0 -35
  68. package/src/internal/array/sets.ts +0 -74
  69. package/src/internal/array/shuffle.ts +0 -33
  70. package/src/internal/array/update.ts +0 -52
  71. package/src/internal/function/misc.ts +0 -8
  72. package/src/internal/function/timer.ts +0 -168
  73. package/src/internal/is.ts +0 -244
  74. package/src/internal/math/aggregate.ts +0 -164
  75. package/src/internal/math/misc.ts +0 -28
  76. package/src/internal/number.ts +0 -129
  77. package/src/internal/random.ts +0 -49
  78. package/src/internal/result.ts +0 -92
  79. package/src/internal/sized.ts +0 -25
  80. package/src/internal/string.ts +0 -128
  81. package/src/internal/subscription.ts +0 -264
  82. package/src/internal/value/compare.ts +0 -170
  83. package/src/internal/value/equal.ts +0 -465
  84. package/src/internal/value/get.ts +0 -57
  85. package/src/internal/value/handlers.ts +0 -95
  86. package/src/internal/value/has.ts +0 -118
  87. package/src/internal/value/misc.ts +0 -125
  88. package/src/internal/value/partial.ts +0 -46
  89. package/src/internal/value/set.ts +0 -132
  90. package/src/is.ts +0 -182
  91. package/src/logger.ts +0 -230
  92. package/src/math.ts +0 -281
  93. package/src/models.ts +0 -286
  94. package/src/number.ts +0 -1
  95. package/src/promise/delay.ts +0 -62
  96. package/src/promise/helpers.ts +0 -96
  97. package/src/promise/index.ts +0 -300
  98. package/src/promise/misc.ts +0 -96
  99. package/src/promise/models.ts +0 -195
  100. package/src/promise/timed.ts +0 -91
  101. package/src/query.ts +0 -147
  102. package/src/queue.ts +0 -814
  103. package/src/random.ts +0 -125
  104. package/src/result/index.ts +0 -105
  105. package/src/result/match.ts +0 -124
  106. package/src/result/misc.ts +0 -129
  107. package/src/result/models.ts +0 -83
  108. package/src/result/work/flow.ts +0 -488
  109. package/src/result/work/pipe.ts +0 -496
  110. package/src/sized/map.ts +0 -110
  111. package/src/sized/set.ts +0 -107
  112. package/src/string/case.ts +0 -236
  113. package/src/string/fuzzy.ts +0 -444
  114. package/src/string/index.ts +0 -199
  115. package/src/string/match.ts +0 -80
  116. package/src/string/normalize.ts +0 -205
  117. package/src/string/template.ts +0 -161
  118. package/src/value/clone.ts +0 -319
  119. package/src/value/collection.ts +0 -63
  120. package/src/value/diff.ts +0 -232
  121. package/src/value/freeze.ts +0 -322
  122. package/src/value/handle.ts +0 -3
  123. package/src/value/index.ts +0 -5
  124. package/src/value/merge.ts +0 -278
  125. package/src/value/omit.ts +0 -20
  126. package/src/value/pick.ts +0 -20
  127. package/src/value/shake.ts +0 -45
  128. package/src/value/smush.ts +0 -89
  129. package/src/value/transform.ts +0 -153
  130. package/src/value/unsmush.ts +0 -84
@@ -1,182 +0,0 @@
1
- import {FIND_VALUES_ALL, findValues} from '../internal/array/find';
2
- import type {PlainObject} from '../models';
3
-
4
- // #region Functions
5
-
6
- /**
7
- * Get a filtered array of items that do not match the value
8
- *
9
- * _Available as `exclude` and `filter.remove`_
10
- *
11
- * @param array Array to search in
12
- * @param callback Callback to get an item's value for matching
13
- * @param value Value to match against
14
- * @returns Filtered array of items that do not match the filter
15
- *
16
- * @example
17
- * ```typescript
18
- * exclude(
19
- * [{id: 1}, {id: 2}, {id: 3}],
20
- * item => item.id,
21
- * 2,
22
- * ); // => [{id: 1}, {id: 3}]
23
- * ```
24
- */
25
- export function exclude<
26
- Item,
27
- Callback extends (item: Item, index: number, array: Item[]) => unknown,
28
- >(array: Item[], callback: Callback, value: ReturnType<Callback>): unknown[];
29
-
30
- /**
31
- * Get a filtered array of items that do not match the value
32
- *
33
- * _Available as `exclude` and `filter.remove`_
34
- *
35
- * @param array Array to search in
36
- * @param key Key to get an item's value for matching
37
- * @param value Value to match against
38
- * @returns Filtered array of items that do not match the filter
39
- *
40
- * @example
41
- * ```typescript
42
- * exclude(
43
- * [{id: 1}, {id: 2}, {id: 3}],
44
- * 'id',
45
- * 2,
46
- * ); // => [{id: 1}, {id: 3}]
47
- * ```
48
- */
49
- export function exclude<Item extends PlainObject, ItemKey extends keyof Item>(
50
- array: Item[],
51
- key: ItemKey,
52
- value: Item[ItemKey],
53
- ): unknown[];
54
-
55
- /**
56
- * Get a filtered array of items that do not match the filter
57
- *
58
- * _Available as `exclude` and `filter.remove`_
59
- *
60
- * @param array Array to search in
61
- * @param filter Filter callback to match items
62
- * @returns Filtered array of items that do not match the filter
63
- *
64
- * @example
65
- * ```typescript
66
- * exclude(
67
- * [{id: 1}, {id: 2}, {id: 3}],
68
- * item => item.id === 2,
69
- * ); // => [{id: 1}, {id: 3}]
70
- * ```
71
- */
72
- export function exclude<Item>(
73
- array: Item[],
74
- filter: (item: Item, index: number, array: Item[]) => boolean,
75
- ): unknown[];
76
-
77
- /**
78
- * Get a filtered array of items that do not match the given item
79
- *
80
- * _Available as `exclude` and `filter.remove`_
81
- *
82
- * @param array Array to search in
83
- * @param item Item to match against
84
- * @returns Filtered array of items that do not match the given item
85
- *
86
- * @example
87
- * ```typescript
88
- * exclude([1, 2, 3], 2); // => [1, 3]
89
- * ```
90
- */
91
- export function exclude<Item>(array: Item[], item: Item): unknown[];
92
-
93
- export function exclude(array: unknown[], ...parameters: unknown[]): unknown[] {
94
- return findValues(FIND_VALUES_ALL, array, parameters).notMatched;
95
- }
96
-
97
- /**
98
- * Get a filtered array of items
99
- *
100
- * @param array Array to search in
101
- * @param callback Callback to get an item's value for matching
102
- * @param value Value to match against
103
- * @returns Filtered array of items
104
- *
105
- * @example
106
- * ```typescript
107
- * filter(
108
- * [{id: 1}, {id: 2}, {id: 3}],
109
- * item => item.id,
110
- * 2,
111
- * ); // => [{id: 2}]
112
- * ```
113
- */
114
- export function filter<
115
- Item,
116
- Callback extends (item: Item, index: number, array: Item[]) => unknown,
117
- >(array: Item[], callback: Callback, value: ReturnType<Callback>): Item[];
118
-
119
- /**
120
- * Get a filtered array of items
121
- *
122
- * @param array Array to search in
123
- * @param key Key to get an item's value for matching
124
- * @param value Value to match against
125
- * @returns Filtered array of items
126
- *
127
- * @example
128
- * ```typescript
129
- * filter(
130
- * [{id: 1}, {id: 2}, {id: 3}],
131
- * 'id',
132
- * 2,
133
- * ); // => [{id: 2}]
134
- * ```
135
- */
136
- export function filter<Item extends PlainObject, ItemKey extends keyof Item>(
137
- array: Item[],
138
- key: ItemKey,
139
- value: Item[ItemKey],
140
- ): Item[];
141
-
142
- /**
143
- * Get a filtered array of items matching the filter
144
- *
145
- * @param array Array to search in
146
- * @param filter Filter callback to match items
147
- * @returns Filtered array of items
148
- *
149
- * @example
150
- * ```typescript
151
- * filter(
152
- * [{id: 1}, {id: 2}, {id: 3}],
153
- * item => item.id === 2,
154
- * ); // => [{id: 2}]
155
- * ```
156
- */
157
- export function filter<Item>(
158
- array: Item[],
159
- filter: (item: Item, index: number, array: Item[]) => boolean,
160
- ): Item[];
161
-
162
- /**
163
- * Get a filtered array of items matching the given item
164
- *
165
- * @param array Array to search in
166
- * @param item Item to match against
167
- * @returns Filtered array of items
168
- *
169
- * @example
170
- * ```typescript
171
- * filter([1, 2, 3], 2); // => [2]
172
- * ```
173
- */
174
- export function filter<Item>(array: Item[], item: Item): Item[];
175
-
176
- export function filter(array: unknown[], ...parameters: unknown[]): unknown[] {
177
- return findValues(FIND_VALUES_ALL, array, parameters).matched;
178
- }
179
-
180
- filter.remove = exclude;
181
-
182
- // #endregion
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