@oscarpalmer/atoms 0.145.0 → 0.146.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.
- package/dist/array/misc.js +20 -0
- package/dist/atoms.full.js +196 -196
- package/dist/index.js +7 -6
- package/dist/random.js +1 -1
- package/package.json +6 -74
- package/src/array/misc.ts +20 -0
- package/src/index.ts +1 -19
- package/types/array/misc.d.ts +19 -0
- package/types/index.d.ts +1 -19
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { exists } from "./exists.js";
|
|
2
|
+
import { filter } from "./filter.js";
|
|
3
|
+
import { find } from "./find.js";
|
|
4
|
+
import { flatten } from "./flatten.js";
|
|
5
|
+
import { getArray } from "./get.js";
|
|
6
|
+
import { indexOf } from "./index-of.js";
|
|
7
|
+
import { chunk } from "../internal/array/chunk.js";
|
|
8
|
+
import { insert } from "./insert.js";
|
|
9
|
+
import { compact } from "../internal/array/compact.js";
|
|
10
|
+
import { shuffle } from "../internal/array/shuffle.js";
|
|
11
|
+
import { partition } from "./partition.js";
|
|
12
|
+
import { push } from "./push.js";
|
|
13
|
+
import { range } from "./range.js";
|
|
14
|
+
import { select } from "./select.js";
|
|
15
|
+
import { sort } from "./sort.js";
|
|
16
|
+
import { splice } from "./splice.js";
|
|
17
|
+
import { toSet } from "./to-set.js";
|
|
18
|
+
import { toggle } from "./toggle.js";
|
|
19
|
+
import { update } from "./update.js";
|
|
20
|
+
export { chunk, compact, exists, filter, find, flatten, getArray, indexOf, insert, partition, push, range, select, shuffle, sort, splice, toSet, toggle, update };
|
package/dist/atoms.full.js
CHANGED
|
@@ -37,6 +37,168 @@ function getArrayCallbacks(bool, key, value) {
|
|
|
37
37
|
value: getArrayCallback(value)
|
|
38
38
|
};
|
|
39
39
|
}
|
|
40
|
+
function groupValues(array, key, value, arrays) {
|
|
41
|
+
if (!Array.isArray(array) || array.length === 0) return {};
|
|
42
|
+
const { length } = array;
|
|
43
|
+
const callbacks = getArrayCallbacks(void 0, key, value);
|
|
44
|
+
const record = {};
|
|
45
|
+
for (let index = 0; index < length; index += 1) {
|
|
46
|
+
const item = array[index];
|
|
47
|
+
const keyed = callbacks?.keyed?.(item, index, array) ?? index;
|
|
48
|
+
const valued = callbacks?.value?.(item, index, array) ?? item;
|
|
49
|
+
if (arrays) {
|
|
50
|
+
const existing = record[keyed];
|
|
51
|
+
if (existing == null) record[keyed] = [valued];
|
|
52
|
+
else existing.push(valued);
|
|
53
|
+
} else record[keyed] = valued;
|
|
54
|
+
}
|
|
55
|
+
return record;
|
|
56
|
+
}
|
|
57
|
+
function groupBy(array, first, second) {
|
|
58
|
+
return groupValues(array, first, second, false);
|
|
59
|
+
}
|
|
60
|
+
groupBy.arrays = groupArraysBy;
|
|
61
|
+
function groupArraysBy(array, first, second) {
|
|
62
|
+
return groupValues(array, first, second, true);
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Chunk an array into smaller arrays
|
|
66
|
+
* @param array Array to chunk
|
|
67
|
+
* @param size Size of each chunk _(minimum is `1`, maximum is `5000`; defaults to `5000`)_
|
|
68
|
+
* @returns Array of arrays
|
|
69
|
+
*/
|
|
70
|
+
function chunk(array, size) {
|
|
71
|
+
if (!Array.isArray(array)) return [];
|
|
72
|
+
if (array.length === 0) return [];
|
|
73
|
+
const { length } = array;
|
|
74
|
+
const actualSize = typeof size === "number" && size > 0 && size <= MAX_SIZE ? size : MAX_SIZE;
|
|
75
|
+
if (length <= actualSize) return [array];
|
|
76
|
+
const chunks = [];
|
|
77
|
+
let index = 0;
|
|
78
|
+
while (index < length) {
|
|
79
|
+
chunks.push(array.slice(index, index + actualSize));
|
|
80
|
+
index += actualSize;
|
|
81
|
+
}
|
|
82
|
+
return chunks;
|
|
83
|
+
}
|
|
84
|
+
const MAX_SIZE = 5e3;
|
|
85
|
+
function compact(array, strict) {
|
|
86
|
+
if (!Array.isArray(array)) return [];
|
|
87
|
+
if (strict === true) return array.filter(Boolean);
|
|
88
|
+
const { length } = array;
|
|
89
|
+
const compacted = [];
|
|
90
|
+
for (let index = 0; index < length; index += 1) {
|
|
91
|
+
const item = array[index];
|
|
92
|
+
if (item != null) compacted.push(item);
|
|
93
|
+
}
|
|
94
|
+
return compacted;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Is the value an array or a record?
|
|
98
|
+
* @param value Value to check
|
|
99
|
+
* @returns `true` if the value is an array or a record, otherwise `false`
|
|
100
|
+
*/
|
|
101
|
+
function isArrayOrPlainObject(value) {
|
|
102
|
+
return Array.isArray(value) || isPlainObject(value);
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Is the value a constructor function?
|
|
106
|
+
* @param value Value to check
|
|
107
|
+
* @returns `true` if the value is a constructor function, otherwise `false`
|
|
108
|
+
*/
|
|
109
|
+
function isConstructor(value) {
|
|
110
|
+
return typeof value === "function" && value.prototype?.constructor === value;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Is the value a key?
|
|
114
|
+
* @param value Value to check
|
|
115
|
+
* @returns `true` if the value is a `Key` _(`number` or `string`)_, otherwise `false`
|
|
116
|
+
*/
|
|
117
|
+
function isKey(value) {
|
|
118
|
+
return typeof value === "number" || typeof value === "string";
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Is the value a number?
|
|
122
|
+
* @param value Value to check
|
|
123
|
+
* @returns `true` if the value is a `number`, otherwise `false`
|
|
124
|
+
*/
|
|
125
|
+
function isNumber(value) {
|
|
126
|
+
return typeof value === "number" && !Number.isNaN(value);
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Is the value a plain object?
|
|
130
|
+
* @param value Value to check
|
|
131
|
+
* @returns `true` if the value is a plain object, otherwise `false`
|
|
132
|
+
*/
|
|
133
|
+
function isPlainObject(value) {
|
|
134
|
+
if (value === null || typeof value !== "object") return false;
|
|
135
|
+
if (Symbol.toStringTag in value || Symbol.iterator in value) return false;
|
|
136
|
+
const prototype = Object.getPrototypeOf(value);
|
|
137
|
+
return prototype === null || prototype === Object.prototype || Object.getPrototypeOf(prototype) === null;
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Is the value a typed array?
|
|
141
|
+
* @param value Value to check
|
|
142
|
+
* @returns `true` if the value is a typed array, otherwise `false`
|
|
143
|
+
*/
|
|
144
|
+
function isTypedArray(value) {
|
|
145
|
+
TYPED_ARRAYS ??= new Set([
|
|
146
|
+
Int8Array,
|
|
147
|
+
Uint8Array,
|
|
148
|
+
Uint8ClampedArray,
|
|
149
|
+
Int16Array,
|
|
150
|
+
Uint16Array,
|
|
151
|
+
Int32Array,
|
|
152
|
+
Uint32Array,
|
|
153
|
+
Float32Array,
|
|
154
|
+
Float64Array,
|
|
155
|
+
BigInt64Array,
|
|
156
|
+
BigUint64Array
|
|
157
|
+
]);
|
|
158
|
+
return TYPED_ARRAYS.has(value?.constructor);
|
|
159
|
+
}
|
|
160
|
+
let TYPED_ARRAYS;
|
|
161
|
+
function _getRandomFloat(inclusive, minimum, maximum) {
|
|
162
|
+
let maxFloat = isNumber(maximum) && maximum <= Number.MAX_SAFE_INTEGER ? maximum : Number.MAX_SAFE_INTEGER;
|
|
163
|
+
let minFloat = isNumber(minimum) && minimum >= Number.MIN_SAFE_INTEGER ? minimum : Number.MIN_SAFE_INTEGER;
|
|
164
|
+
if (minFloat === maxFloat) return minFloat;
|
|
165
|
+
if (minFloat > maxFloat) [minFloat, maxFloat] = [maxFloat, minFloat];
|
|
166
|
+
return Math.random() * (maxFloat + (inclusive ? 1 : 0) - minFloat) + minFloat;
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Get a random floating-point number
|
|
170
|
+
* @param minimum Minimum value
|
|
171
|
+
* @param maximum Maximum value
|
|
172
|
+
* @returns Random floating-point number
|
|
173
|
+
*/
|
|
174
|
+
function getRandomFloat(minimum, maximum) {
|
|
175
|
+
return _getRandomFloat(false, minimum, maximum);
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Get a random integer
|
|
179
|
+
* @param minimum Minimum value
|
|
180
|
+
* @param maximum Maximum value
|
|
181
|
+
* @returns Random integer
|
|
182
|
+
*/
|
|
183
|
+
function getRandomInteger(minimum, maximum) {
|
|
184
|
+
return Math.floor(_getRandomFloat(true, minimum, maximum));
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Shuffle items in array
|
|
188
|
+
* @param array Original array
|
|
189
|
+
* @returns Shuffled array
|
|
190
|
+
*/
|
|
191
|
+
function shuffle(array) {
|
|
192
|
+
if (!Array.isArray(array)) return [];
|
|
193
|
+
const shuffled = [...array];
|
|
194
|
+
if (shuffled.length < 2) return shuffled;
|
|
195
|
+
let index = Number(shuffled.length);
|
|
196
|
+
while (--index >= 0) {
|
|
197
|
+
const random = getRandomInteger(0, index);
|
|
198
|
+
[shuffled[index], shuffled[random]] = [shuffled[random], shuffled[index]];
|
|
199
|
+
}
|
|
200
|
+
return shuffled;
|
|
201
|
+
}
|
|
40
202
|
function findValue(type, array, parameters) {
|
|
41
203
|
const findIndex = type === "index";
|
|
42
204
|
if (!Array.isArray(array) || array.length === 0) return findIndex ? -1 : void 0;
|
|
@@ -122,71 +284,6 @@ function find(array, ...parameters) {
|
|
|
122
284
|
function flatten(array) {
|
|
123
285
|
return Array.isArray(array) ? array.flat(Number.POSITIVE_INFINITY) : [];
|
|
124
286
|
}
|
|
125
|
-
/**
|
|
126
|
-
* Is the value an array or a record?
|
|
127
|
-
* @param value Value to check
|
|
128
|
-
* @returns `true` if the value is an array or a record, otherwise `false`
|
|
129
|
-
*/
|
|
130
|
-
function isArrayOrPlainObject(value) {
|
|
131
|
-
return Array.isArray(value) || isPlainObject(value);
|
|
132
|
-
}
|
|
133
|
-
/**
|
|
134
|
-
* Is the value a constructor function?
|
|
135
|
-
* @param value Value to check
|
|
136
|
-
* @returns `true` if the value is a constructor function, otherwise `false`
|
|
137
|
-
*/
|
|
138
|
-
function isConstructor(value) {
|
|
139
|
-
return typeof value === "function" && value.prototype?.constructor === value;
|
|
140
|
-
}
|
|
141
|
-
/**
|
|
142
|
-
* Is the value a key?
|
|
143
|
-
* @param value Value to check
|
|
144
|
-
* @returns `true` if the value is a `Key` _(`number` or `string`)_, otherwise `false`
|
|
145
|
-
*/
|
|
146
|
-
function isKey(value) {
|
|
147
|
-
return typeof value === "number" || typeof value === "string";
|
|
148
|
-
}
|
|
149
|
-
/**
|
|
150
|
-
* Is the value a number?
|
|
151
|
-
* @param value Value to check
|
|
152
|
-
* @returns `true` if the value is a `number`, otherwise `false`
|
|
153
|
-
*/
|
|
154
|
-
function isNumber(value) {
|
|
155
|
-
return typeof value === "number" && !Number.isNaN(value);
|
|
156
|
-
}
|
|
157
|
-
/**
|
|
158
|
-
* Is the value a plain object?
|
|
159
|
-
* @param value Value to check
|
|
160
|
-
* @returns `true` if the value is a plain object, otherwise `false`
|
|
161
|
-
*/
|
|
162
|
-
function isPlainObject(value) {
|
|
163
|
-
if (value === null || typeof value !== "object") return false;
|
|
164
|
-
if (Symbol.toStringTag in value || Symbol.iterator in value) return false;
|
|
165
|
-
const prototype = Object.getPrototypeOf(value);
|
|
166
|
-
return prototype === null || prototype === Object.prototype || Object.getPrototypeOf(prototype) === null;
|
|
167
|
-
}
|
|
168
|
-
/**
|
|
169
|
-
* Is the value a typed array?
|
|
170
|
-
* @param value Value to check
|
|
171
|
-
* @returns `true` if the value is a typed array, otherwise `false`
|
|
172
|
-
*/
|
|
173
|
-
function isTypedArray(value) {
|
|
174
|
-
TYPED_ARRAYS ??= new Set([
|
|
175
|
-
Int8Array,
|
|
176
|
-
Uint8Array,
|
|
177
|
-
Uint8ClampedArray,
|
|
178
|
-
Int16Array,
|
|
179
|
-
Uint16Array,
|
|
180
|
-
Int32Array,
|
|
181
|
-
Uint32Array,
|
|
182
|
-
Float32Array,
|
|
183
|
-
Float64Array,
|
|
184
|
-
BigInt64Array,
|
|
185
|
-
BigUint64Array
|
|
186
|
-
]);
|
|
187
|
-
return TYPED_ARRAYS.has(value?.constructor);
|
|
188
|
-
}
|
|
189
|
-
let TYPED_ARRAYS;
|
|
190
287
|
function getArray(value, indiced) {
|
|
191
288
|
if (Array.isArray(value)) return value;
|
|
192
289
|
if (value instanceof Map || value instanceof Set) return [...value.values()];
|
|
@@ -201,54 +298,9 @@ function getArray(value, indiced) {
|
|
|
201
298
|
}
|
|
202
299
|
return array;
|
|
203
300
|
}
|
|
204
|
-
function groupValues(array, key, value, arrays) {
|
|
205
|
-
if (!Array.isArray(array) || array.length === 0) return {};
|
|
206
|
-
const { length } = array;
|
|
207
|
-
const callbacks = getArrayCallbacks(void 0, key, value);
|
|
208
|
-
const record = {};
|
|
209
|
-
for (let index = 0; index < length; index += 1) {
|
|
210
|
-
const item = array[index];
|
|
211
|
-
const keyed = callbacks?.keyed?.(item, index, array) ?? index;
|
|
212
|
-
const valued = callbacks?.value?.(item, index, array) ?? item;
|
|
213
|
-
if (arrays) {
|
|
214
|
-
const existing = record[keyed];
|
|
215
|
-
if (existing == null) record[keyed] = [valued];
|
|
216
|
-
else existing.push(valued);
|
|
217
|
-
} else record[keyed] = valued;
|
|
218
|
-
}
|
|
219
|
-
return record;
|
|
220
|
-
}
|
|
221
|
-
function groupBy(array, first, second) {
|
|
222
|
-
return groupValues(array, first, second, false);
|
|
223
|
-
}
|
|
224
|
-
groupBy.arrays = groupArraysBy;
|
|
225
|
-
function groupArraysBy(array, first, second) {
|
|
226
|
-
return groupValues(array, first, second, true);
|
|
227
|
-
}
|
|
228
301
|
function indexOf(array, ...parameters) {
|
|
229
302
|
return findValue("index", array, parameters);
|
|
230
303
|
}
|
|
231
|
-
/**
|
|
232
|
-
* Chunk an array into smaller arrays
|
|
233
|
-
* @param array Array to chunk
|
|
234
|
-
* @param size Size of each chunk _(minimum is `1`, maximum is `5000`; defaults to `5000`)_
|
|
235
|
-
* @returns Array of arrays
|
|
236
|
-
*/
|
|
237
|
-
function chunk(array, size) {
|
|
238
|
-
if (!Array.isArray(array)) return [];
|
|
239
|
-
if (array.length === 0) return [];
|
|
240
|
-
const { length } = array;
|
|
241
|
-
const actualSize = typeof size === "number" && size > 0 && size <= MAX_SIZE ? size : MAX_SIZE;
|
|
242
|
-
if (length <= actualSize) return [array];
|
|
243
|
-
const chunks = [];
|
|
244
|
-
let index = 0;
|
|
245
|
-
while (index < length) {
|
|
246
|
-
chunks.push(array.slice(index, index + actualSize));
|
|
247
|
-
index += actualSize;
|
|
248
|
-
}
|
|
249
|
-
return chunks;
|
|
250
|
-
}
|
|
251
|
-
const MAX_SIZE = 5e3;
|
|
252
304
|
function insertChunkedValues(type, array, items, start, deleteCount) {
|
|
253
305
|
const actualDeleteCount = deleteCount < 0 ? 0 : deleteCount;
|
|
254
306
|
const actualStart = Math.min(Math.max(0, start), array.length);
|
|
@@ -338,17 +390,6 @@ const aggregators = {
|
|
|
338
390
|
min: (current, value, notNumber) => notNumber || value < current ? value : current,
|
|
339
391
|
sum: calculateSum
|
|
340
392
|
};
|
|
341
|
-
function compact(array, strict) {
|
|
342
|
-
if (!Array.isArray(array)) return [];
|
|
343
|
-
if (strict === true) return array.filter(Boolean);
|
|
344
|
-
const { length } = array;
|
|
345
|
-
const compacted = [];
|
|
346
|
-
for (let index = 0; index < length; index += 1) {
|
|
347
|
-
const item = array[index];
|
|
348
|
-
if (item != null) compacted.push(item);
|
|
349
|
-
}
|
|
350
|
-
return compacted;
|
|
351
|
-
}
|
|
352
393
|
/**
|
|
353
394
|
* Get the string value from any value
|
|
354
395
|
* @param value Original value
|
|
@@ -578,37 +619,6 @@ function sort(array, first, second) {
|
|
|
578
619
|
function splice(array, start, deleteCountOrItems, items) {
|
|
579
620
|
return insertValues("splice", array, typeof deleteCountOrItems === "number" ? items : deleteCountOrItems, start, typeof deleteCountOrItems === "number" ? deleteCountOrItems : 0);
|
|
580
621
|
}
|
|
581
|
-
function getMapValues(array, first, second, arrays) {
|
|
582
|
-
if (!Array.isArray(array)) return /* @__PURE__ */ new Map();
|
|
583
|
-
const { length } = array;
|
|
584
|
-
const callbacks = getArrayCallbacks(void 0, first, second);
|
|
585
|
-
const map = /* @__PURE__ */ new Map();
|
|
586
|
-
for (let index = 0; index < length; index += 1) {
|
|
587
|
-
const item = array[index];
|
|
588
|
-
const key = callbacks?.keyed?.(item, index, array) ?? index;
|
|
589
|
-
const value = callbacks?.value?.(item, index, array) ?? item;
|
|
590
|
-
if (arrays) {
|
|
591
|
-
const existing = map.get(key);
|
|
592
|
-
if (existing == null) map.set(key, [value]);
|
|
593
|
-
else existing.push(value);
|
|
594
|
-
} else map.set(key, value);
|
|
595
|
-
}
|
|
596
|
-
return map;
|
|
597
|
-
}
|
|
598
|
-
function toMap(array, first, second) {
|
|
599
|
-
return getMapValues(array, first, second, false);
|
|
600
|
-
}
|
|
601
|
-
toMap.arrays = toMapArrays;
|
|
602
|
-
function toMapArrays(array, first, second) {
|
|
603
|
-
return getMapValues(array, first, second, true);
|
|
604
|
-
}
|
|
605
|
-
function toRecord(array, first, second) {
|
|
606
|
-
return groupValues(array, first, second, false);
|
|
607
|
-
}
|
|
608
|
-
toRecord.arrays = toRecordArrays;
|
|
609
|
-
function toRecordArrays(array, first, second) {
|
|
610
|
-
return groupValues(array, first, second, true);
|
|
611
|
-
}
|
|
612
622
|
function toSet(array, value) {
|
|
613
623
|
if (!Array.isArray(array)) return /* @__PURE__ */ new Set();
|
|
614
624
|
const callbacks = getArrayCallbacks(void 0, void 0, value);
|
|
@@ -641,13 +651,44 @@ function updateInArray(array, items, key, replace) {
|
|
|
641
651
|
function toggle(array, values, key) {
|
|
642
652
|
return updateInArray(array, values, key, false);
|
|
643
653
|
}
|
|
654
|
+
function update(array, values, key) {
|
|
655
|
+
return updateInArray(array, values, key, true);
|
|
656
|
+
}
|
|
657
|
+
function getMapValues(array, first, second, arrays) {
|
|
658
|
+
if (!Array.isArray(array)) return /* @__PURE__ */ new Map();
|
|
659
|
+
const { length } = array;
|
|
660
|
+
const callbacks = getArrayCallbacks(void 0, first, second);
|
|
661
|
+
const map = /* @__PURE__ */ new Map();
|
|
662
|
+
for (let index = 0; index < length; index += 1) {
|
|
663
|
+
const item = array[index];
|
|
664
|
+
const key = callbacks?.keyed?.(item, index, array) ?? index;
|
|
665
|
+
const value = callbacks?.value?.(item, index, array) ?? item;
|
|
666
|
+
if (arrays) {
|
|
667
|
+
const existing = map.get(key);
|
|
668
|
+
if (existing == null) map.set(key, [value]);
|
|
669
|
+
else existing.push(value);
|
|
670
|
+
} else map.set(key, value);
|
|
671
|
+
}
|
|
672
|
+
return map;
|
|
673
|
+
}
|
|
674
|
+
function toMap(array, first, second) {
|
|
675
|
+
return getMapValues(array, first, second, false);
|
|
676
|
+
}
|
|
677
|
+
toMap.arrays = toMapArrays;
|
|
678
|
+
function toMapArrays(array, first, second) {
|
|
679
|
+
return getMapValues(array, first, second, true);
|
|
680
|
+
}
|
|
681
|
+
function toRecord(array, first, second) {
|
|
682
|
+
return groupValues(array, first, second, false);
|
|
683
|
+
}
|
|
684
|
+
toRecord.arrays = toRecordArrays;
|
|
685
|
+
function toRecordArrays(array, first, second) {
|
|
686
|
+
return groupValues(array, first, second, true);
|
|
687
|
+
}
|
|
644
688
|
function unique(array, key) {
|
|
645
689
|
if (!Array.isArray(array)) return [];
|
|
646
690
|
return array.length > 1 ? findValues("unique", array, [key, void 0]).matched : array;
|
|
647
691
|
}
|
|
648
|
-
function update(array, values, key) {
|
|
649
|
-
return updateInArray(array, values, key, true);
|
|
650
|
-
}
|
|
651
692
|
function getLimiter(callback, throttler, time) {
|
|
652
693
|
const interval = typeof time === "number" && time >= frame_rate_default ? time : frame_rate_default;
|
|
653
694
|
function step(now, parameters) {
|
|
@@ -959,47 +1000,6 @@ const MESSAGE_FLOW = "Flow expected to receive an array of functions";
|
|
|
959
1000
|
const MESSAGE_PIPE = "Pipe expected to receive an array of functions";
|
|
960
1001
|
const assertFlowFunctions = assert.condition((value) => Array.isArray(value) && value.every((item) => typeof item === "function"), MESSAGE_FLOW, TypeError);
|
|
961
1002
|
const assertPipeFunctions = assert.condition((value) => Array.isArray(value) && value.every((item) => typeof item === "function"), MESSAGE_PIPE, TypeError);
|
|
962
|
-
function _getRandomFloat(inclusive, minimum, maximum) {
|
|
963
|
-
let maxFloat = isNumber(maximum) && maximum <= Number.MAX_SAFE_INTEGER ? maximum : Number.MAX_SAFE_INTEGER;
|
|
964
|
-
let minFloat = isNumber(minimum) && minimum >= Number.MIN_SAFE_INTEGER ? minimum : Number.MIN_SAFE_INTEGER;
|
|
965
|
-
if (minFloat === maxFloat) return minFloat;
|
|
966
|
-
if (minFloat > maxFloat) [minFloat, maxFloat] = [maxFloat, minFloat];
|
|
967
|
-
return Math.random() * (maxFloat + (inclusive ? 1 : 0) - minFloat) + minFloat;
|
|
968
|
-
}
|
|
969
|
-
/**
|
|
970
|
-
* Get a random floating-point number
|
|
971
|
-
* @param minimum Minimum value
|
|
972
|
-
* @param maximum Maximum value
|
|
973
|
-
* @returns Random floating-point number
|
|
974
|
-
*/
|
|
975
|
-
function getRandomFloat(minimum, maximum) {
|
|
976
|
-
return _getRandomFloat(false, minimum, maximum);
|
|
977
|
-
}
|
|
978
|
-
/**
|
|
979
|
-
* Get a random integer
|
|
980
|
-
* @param minimum Minimum value
|
|
981
|
-
* @param maximum Maximum value
|
|
982
|
-
* @returns Random integer
|
|
983
|
-
*/
|
|
984
|
-
function getRandomInteger(minimum, maximum) {
|
|
985
|
-
return Math.floor(_getRandomFloat(true, minimum, maximum));
|
|
986
|
-
}
|
|
987
|
-
/**
|
|
988
|
-
* Shuffle items in array
|
|
989
|
-
* @param array Original array
|
|
990
|
-
* @returns Shuffled array
|
|
991
|
-
*/
|
|
992
|
-
function shuffle(array) {
|
|
993
|
-
if (!Array.isArray(array)) return [];
|
|
994
|
-
const shuffled = [...array];
|
|
995
|
-
if (shuffled.length < 2) return shuffled;
|
|
996
|
-
let index = Number(shuffled.length);
|
|
997
|
-
while (--index >= 0) {
|
|
998
|
-
const random = getRandomInteger(0, index);
|
|
999
|
-
[shuffled[index], shuffled[random]] = [shuffled[random], shuffled[index]];
|
|
1000
|
-
}
|
|
1001
|
-
return shuffled;
|
|
1002
|
-
}
|
|
1003
1003
|
/**
|
|
1004
1004
|
* A function that does nothing, which can be useful, I guess…
|
|
1005
1005
|
*/
|
package/dist/index.js
CHANGED
|
@@ -8,22 +8,25 @@ import { groupBy } from "./array/group-by.js";
|
|
|
8
8
|
import { indexOf } from "./array/index-of.js";
|
|
9
9
|
import { chunk } from "./internal/array/chunk.js";
|
|
10
10
|
import { insert } from "./array/insert.js";
|
|
11
|
+
import { compact } from "./internal/array/compact.js";
|
|
12
|
+
import { getRandomFloat, getRandomInteger } from "./internal/random.js";
|
|
13
|
+
import { shuffle } from "./internal/array/shuffle.js";
|
|
11
14
|
import { partition } from "./array/partition.js";
|
|
12
15
|
import { push } from "./array/push.js";
|
|
13
16
|
import { range } from "./array/range.js";
|
|
14
17
|
import { select } from "./array/select.js";
|
|
15
18
|
import { max } from "./internal/math/aggregate.js";
|
|
16
|
-
import { compact } from "./internal/array/compact.js";
|
|
17
19
|
import { getString, ignoreKey, join, tryDecode, tryEncode, words } from "./internal/string.js";
|
|
18
20
|
import { compare } from "./internal/value/compare.js";
|
|
19
21
|
import { sort } from "./array/sort.js";
|
|
20
22
|
import { splice } from "./array/splice.js";
|
|
21
|
-
import { toMap } from "./array/to-map.js";
|
|
22
|
-
import { toRecord } from "./array/to-record.js";
|
|
23
23
|
import { toSet } from "./array/to-set.js";
|
|
24
24
|
import { toggle } from "./array/toggle.js";
|
|
25
|
-
import { unique } from "./array/unique.js";
|
|
26
25
|
import { update } from "./array/update.js";
|
|
26
|
+
import "./array/misc.js";
|
|
27
|
+
import { toMap } from "./array/to-map.js";
|
|
28
|
+
import { toRecord } from "./array/to-record.js";
|
|
29
|
+
import { unique } from "./array/unique.js";
|
|
27
30
|
import { noop } from "./internal/function/misc.js";
|
|
28
31
|
import { beacon } from "./beacon.js";
|
|
29
32
|
import { between, clamp, getNumber } from "./internal/number.js";
|
|
@@ -39,8 +42,6 @@ import { SizedMap } from "./sized/map.js";
|
|
|
39
42
|
import { memoize } from "./function/memoize.js";
|
|
40
43
|
import { throttle } from "./function/throttle.js";
|
|
41
44
|
import { flow, pipe } from "./function/work.js";
|
|
42
|
-
import { getRandomFloat, getRandomInteger } from "./internal/random.js";
|
|
43
|
-
import { shuffle } from "./internal/array/shuffle.js";
|
|
44
45
|
import { equal } from "./internal/value/equal.js";
|
|
45
46
|
import { getValue } from "./internal/value/get.js";
|
|
46
47
|
import { setValue } from "./internal/value/set.js";
|
package/dist/random.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { join } from "./internal/string.js";
|
|
2
1
|
import { getRandomFloat, getRandomInteger } from "./internal/random.js";
|
|
3
2
|
import { shuffle } from "./internal/array/shuffle.js";
|
|
3
|
+
import { join } from "./internal/string.js";
|
|
4
4
|
/**
|
|
5
5
|
* Get a random boolean
|
|
6
6
|
* @return Random boolean
|
package/package.json
CHANGED
|
@@ -8,8 +8,8 @@
|
|
|
8
8
|
"@types/node": "^25.3",
|
|
9
9
|
"@vitest/coverage-istanbul": "^4",
|
|
10
10
|
"jsdom": "^28.1",
|
|
11
|
-
"oxfmt": "^0.
|
|
12
|
-
"oxlint": "^1.
|
|
11
|
+
"oxfmt": "^0.36",
|
|
12
|
+
"oxlint": "^1.51",
|
|
13
13
|
"rolldown": "1.0.0-rc.6",
|
|
14
14
|
"tslib": "^2.8",
|
|
15
15
|
"typescript": "^5.9",
|
|
@@ -22,69 +22,13 @@
|
|
|
22
22
|
"types": "./types/index.d.ts",
|
|
23
23
|
"default": "./dist/index.js"
|
|
24
24
|
},
|
|
25
|
-
"./array/chunk": {
|
|
26
|
-
"types": "./types/internal/array/chunk.d.ts",
|
|
27
|
-
"default": "./dist/internal/array/chunk.js"
|
|
28
|
-
},
|
|
29
|
-
"./array/compact": {
|
|
30
|
-
"types": "./types/internal/array/compact.d.ts",
|
|
31
|
-
"default": "./dist/internal/array/compact.js"
|
|
32
|
-
},
|
|
33
|
-
"./array/exists": {
|
|
34
|
-
"types": "./types/array/exists.d.ts",
|
|
35
|
-
"default": "./dist/array/exists.js"
|
|
36
|
-
},
|
|
37
|
-
"./array/filter": {
|
|
38
|
-
"types": "./types/array/filter.d.ts",
|
|
39
|
-
"default": "./dist/array/filter.js"
|
|
40
|
-
},
|
|
41
|
-
"./array/find": {
|
|
42
|
-
"types": "./types/array/find.d.ts",
|
|
43
|
-
"default": "./dist/array/find.js"
|
|
44
|
-
},
|
|
45
|
-
"./array/flatten": {
|
|
46
|
-
"types": "./types/array/flatten.d.ts",
|
|
47
|
-
"default": "./dist/array/flatten.js"
|
|
48
|
-
},
|
|
49
|
-
"./array/get": {
|
|
50
|
-
"types": "./types/array/get.d.ts",
|
|
51
|
-
"default": "./dist/array/get.js"
|
|
52
|
-
},
|
|
53
25
|
"./array/group-by": {
|
|
54
26
|
"types": "./types/array/group-by.d.ts",
|
|
55
27
|
"default": "./dist/array/group-by.js"
|
|
56
28
|
},
|
|
57
|
-
"./array/
|
|
58
|
-
"types": "./types/array/
|
|
59
|
-
"default": "./dist/array/
|
|
60
|
-
},
|
|
61
|
-
"./array/insert": {
|
|
62
|
-
"types": "./types/array/insert.d.ts",
|
|
63
|
-
"default": "./dist/array/insert.js"
|
|
64
|
-
},
|
|
65
|
-
"./array/partition": {
|
|
66
|
-
"types": "./types/array/partition.d.ts",
|
|
67
|
-
"default": "./dist/array/partition.js"
|
|
68
|
-
},
|
|
69
|
-
"./array/push": {
|
|
70
|
-
"types": "./types/array/push.d.ts",
|
|
71
|
-
"default": "./dist/array/push.js"
|
|
72
|
-
},
|
|
73
|
-
"./array/range": {
|
|
74
|
-
"types": "./types/array/range.d.ts",
|
|
75
|
-
"default": "./dist/array/range.js"
|
|
76
|
-
},
|
|
77
|
-
"./array/select": {
|
|
78
|
-
"types": "./types/array/select.d.ts",
|
|
79
|
-
"default": "./dist/array/select.js"
|
|
80
|
-
},
|
|
81
|
-
"./array/sort": {
|
|
82
|
-
"types": "./types/array/sort.d.ts",
|
|
83
|
-
"default": "./dist/array/sort.js"
|
|
84
|
-
},
|
|
85
|
-
"./array/splice": {
|
|
86
|
-
"types": "./types/array/splice.d.ts",
|
|
87
|
-
"default": "./dist/array/splice.js"
|
|
29
|
+
"./array/misc": {
|
|
30
|
+
"types": "./types/array/misc.d.ts",
|
|
31
|
+
"default": "./dist/array/misc.js"
|
|
88
32
|
},
|
|
89
33
|
"./array/to-map": {
|
|
90
34
|
"types": "./types/array/to-map.d.ts",
|
|
@@ -94,22 +38,10 @@
|
|
|
94
38
|
"types": "./types/array/to-record.d.ts",
|
|
95
39
|
"default": "./dist/array/to-record.js"
|
|
96
40
|
},
|
|
97
|
-
"./array/to-set": {
|
|
98
|
-
"types": "./types/array/to-set.d.ts",
|
|
99
|
-
"default": "./dist/array/to-set.js"
|
|
100
|
-
},
|
|
101
|
-
"./array/toggle": {
|
|
102
|
-
"types": "./types/array/toggle.d.ts",
|
|
103
|
-
"default": "./dist/array/toggle.js"
|
|
104
|
-
},
|
|
105
41
|
"./array/unique": {
|
|
106
42
|
"types": "./types/array/unique.d.ts",
|
|
107
43
|
"default": "./dist/array/unique.js"
|
|
108
44
|
},
|
|
109
|
-
"./array/update": {
|
|
110
|
-
"types": "./types/array/update.d.ts",
|
|
111
|
-
"default": "./dist/array/update.js"
|
|
112
|
-
},
|
|
113
45
|
"./beacon": {
|
|
114
46
|
"types": "./types/beacon.d.ts",
|
|
115
47
|
"default": "./dist/beacon.js"
|
|
@@ -260,5 +192,5 @@
|
|
|
260
192
|
},
|
|
261
193
|
"type": "module",
|
|
262
194
|
"types": "./types/index.d.ts",
|
|
263
|
-
"version": "0.
|
|
195
|
+
"version": "0.146.0"
|
|
264
196
|
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export * from '../internal/array/chunk';
|
|
2
|
+
export * from '../internal/array/compact';
|
|
3
|
+
export * from '../internal/array/shuffle';
|
|
4
|
+
|
|
5
|
+
export * from './exists';
|
|
6
|
+
export * from './filter';
|
|
7
|
+
export * from './find';
|
|
8
|
+
export * from './flatten';
|
|
9
|
+
export * from './get';
|
|
10
|
+
export * from './index-of';
|
|
11
|
+
export * from './insert';
|
|
12
|
+
export * from './partition';
|
|
13
|
+
export * from './push';
|
|
14
|
+
export * from './range';
|
|
15
|
+
export * from './select';
|
|
16
|
+
export * from './sort';
|
|
17
|
+
export * from './splice';
|
|
18
|
+
export * from './to-set';
|
|
19
|
+
export * from './toggle';
|
|
20
|
+
export * from './update';
|
package/src/index.ts
CHANGED
|
@@ -1,34 +1,16 @@
|
|
|
1
1
|
import FRAME_RATE_MS from './internal/frame-rate';
|
|
2
2
|
|
|
3
|
-
export * from './array/exists';
|
|
4
|
-
export * from './array/filter';
|
|
5
|
-
export * from './array/find';
|
|
6
|
-
export * from './array/flatten';
|
|
7
|
-
export * from './array/get';
|
|
8
3
|
export * from './array/group-by';
|
|
9
|
-
export * from './array/
|
|
10
|
-
export * from './array/insert';
|
|
11
|
-
export * from './array/partition';
|
|
12
|
-
export * from './array/push';
|
|
13
|
-
export * from './array/range';
|
|
14
|
-
export * from './array/select';
|
|
15
|
-
export * from './array/sort';
|
|
16
|
-
export * from './array/splice';
|
|
4
|
+
export * from './array/misc';
|
|
17
5
|
export * from './array/to-map';
|
|
18
6
|
export * from './array/to-record';
|
|
19
|
-
export * from './array/to-set';
|
|
20
|
-
export * from './array/toggle';
|
|
21
7
|
export * from './array/unique';
|
|
22
|
-
export * from './array/update';
|
|
23
8
|
|
|
24
9
|
export * from './function/debounce';
|
|
25
10
|
export * from './function/memoize';
|
|
26
11
|
export * from './function/throttle';
|
|
27
12
|
export * from './function/work';
|
|
28
13
|
|
|
29
|
-
export * from './internal/array/chunk';
|
|
30
|
-
export * from './internal/array/compact';
|
|
31
|
-
export * from './internal/array/shuffle';
|
|
32
14
|
export * from './internal/function/misc';
|
|
33
15
|
export * from './internal/string';
|
|
34
16
|
export * from './internal/value/compare';
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export * from '../internal/array/chunk';
|
|
2
|
+
export * from '../internal/array/compact';
|
|
3
|
+
export * from '../internal/array/shuffle';
|
|
4
|
+
export * from './exists';
|
|
5
|
+
export * from './filter';
|
|
6
|
+
export * from './find';
|
|
7
|
+
export * from './flatten';
|
|
8
|
+
export * from './get';
|
|
9
|
+
export * from './index-of';
|
|
10
|
+
export * from './insert';
|
|
11
|
+
export * from './partition';
|
|
12
|
+
export * from './push';
|
|
13
|
+
export * from './range';
|
|
14
|
+
export * from './select';
|
|
15
|
+
export * from './sort';
|
|
16
|
+
export * from './splice';
|
|
17
|
+
export * from './to-set';
|
|
18
|
+
export * from './toggle';
|
|
19
|
+
export * from './update';
|
package/types/index.d.ts
CHANGED
|
@@ -1,31 +1,13 @@
|
|
|
1
1
|
import FRAME_RATE_MS from './internal/frame-rate';
|
|
2
|
-
export * from './array/exists';
|
|
3
|
-
export * from './array/filter';
|
|
4
|
-
export * from './array/find';
|
|
5
|
-
export * from './array/flatten';
|
|
6
|
-
export * from './array/get';
|
|
7
2
|
export * from './array/group-by';
|
|
8
|
-
export * from './array/
|
|
9
|
-
export * from './array/insert';
|
|
10
|
-
export * from './array/partition';
|
|
11
|
-
export * from './array/push';
|
|
12
|
-
export * from './array/range';
|
|
13
|
-
export * from './array/select';
|
|
14
|
-
export * from './array/sort';
|
|
15
|
-
export * from './array/splice';
|
|
3
|
+
export * from './array/misc';
|
|
16
4
|
export * from './array/to-map';
|
|
17
5
|
export * from './array/to-record';
|
|
18
|
-
export * from './array/to-set';
|
|
19
|
-
export * from './array/toggle';
|
|
20
6
|
export * from './array/unique';
|
|
21
|
-
export * from './array/update';
|
|
22
7
|
export * from './function/debounce';
|
|
23
8
|
export * from './function/memoize';
|
|
24
9
|
export * from './function/throttle';
|
|
25
10
|
export * from './function/work';
|
|
26
|
-
export * from './internal/array/chunk';
|
|
27
|
-
export * from './internal/array/compact';
|
|
28
|
-
export * from './internal/array/shuffle';
|
|
29
11
|
export * from './internal/function/misc';
|
|
30
12
|
export * from './internal/string';
|
|
31
13
|
export * from './internal/value/compare';
|