@oscarpalmer/atoms 0.98.0 → 0.99.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/group-by.cjs +27 -2
- package/dist/array/group-by.js +26 -2
- package/dist/array/index.cjs +19 -13
- package/dist/array/index.js +17 -6
- package/dist/array/insert.cjs +28 -2
- package/dist/array/insert.js +27 -2
- package/dist/{internal/array → array}/shuffle.cjs +3 -3
- package/dist/array/sort.cjs +24 -24
- package/dist/array/sort.js +22 -22
- package/dist/array/splice.cjs +2 -2
- package/dist/array/splice.js +1 -1
- package/dist/array/to-map.cjs +1 -1
- package/dist/array/to-map.js +1 -1
- package/dist/array/to-record.cjs +2 -2
- package/dist/array/to-record.js +1 -1
- package/dist/atoms.full.js +2745 -0
- package/dist/attoms.full.js +2840 -0
- package/dist/color.cjs +276 -0
- package/dist/color.js +263 -0
- package/dist/emitter.cjs +8 -8
- package/dist/emitter.js +1 -1
- package/dist/function.cjs +10 -9
- package/dist/function.js +6 -5
- package/dist/i18n.cjs +4 -6
- package/dist/i18n.js +4 -6
- package/dist/index.cjs +70 -77
- package/dist/index.js +27 -34
- package/dist/internal/array/callbacks.cjs +4 -1
- package/dist/internal/array/callbacks.js +4 -1
- package/dist/internal/array/find.cjs +4 -4
- package/dist/internal/array/find.js +4 -4
- package/dist/internal/math/aggregate.cjs +0 -4
- package/dist/internal/math/aggregate.js +1 -4
- package/dist/internal/string/key.cjs +10 -0
- package/dist/internal/string/key.js +6 -0
- package/dist/internal/value/{misc.cjs → handle.cjs} +2 -8
- package/dist/internal/value/{misc.js → handle.js} +2 -7
- package/dist/internal/value/paths.cjs +11 -0
- package/dist/internal/value/paths.js +7 -0
- package/dist/is.cjs +26 -8
- package/dist/is.js +21 -3
- package/dist/logger.cjs +9 -9
- package/dist/logger.js +1 -1
- package/dist/math.cjs +4 -1
- package/dist/math.js +4 -2
- package/dist/number.cjs +49 -6
- package/dist/number.js +48 -1
- package/dist/query.cjs +33 -32
- package/dist/query.js +30 -29
- package/dist/random.cjs +22 -9
- package/dist/random.js +16 -4
- package/dist/sized.cjs +2 -2
- package/dist/sized.js +1 -1
- package/dist/string/case.cjs +5 -5
- package/dist/string/case.js +1 -1
- package/dist/string/index.cjs +3 -4
- package/dist/string/index.js +1 -2
- package/dist/string/misc.cjs +26 -2
- package/dist/string/misc.js +24 -3
- package/dist/string/template.cjs +4 -4
- package/dist/string/template.js +2 -2
- package/dist/value/clone.cjs +2 -12
- package/dist/value/clone.js +1 -11
- package/dist/{internal/value → value}/compare.cjs +8 -8
- package/dist/{internal/value → value}/compare.js +3 -3
- package/dist/value/diff.cjs +10 -13
- package/dist/value/diff.js +4 -7
- package/dist/{internal/value → value}/equal.cjs +3 -3
- package/dist/{internal/value → value}/get.cjs +4 -3
- package/dist/{internal/value → value}/get.js +2 -1
- package/dist/value/index.cjs +21 -11
- package/dist/value/index.js +19 -5
- package/dist/value/merge.cjs +7 -24
- package/dist/value/merge.js +7 -24
- package/dist/{internal/value → value}/set.cjs +5 -4
- package/dist/{internal/value → value}/set.js +2 -1
- package/dist/value/smush.cjs +6 -6
- package/dist/value/smush.js +2 -2
- package/dist/value/unsmush.cjs +4 -4
- package/dist/value/unsmush.js +2 -2
- package/package.json +4 -3
- package/src/array/flatten.ts +3 -5
- package/src/array/index.ts +0 -1
- package/src/array/sort.ts +2 -2
- package/src/array/unique.ts +3 -5
- package/src/color/index.ts +0 -1
- package/src/color/is.ts +7 -7
- package/src/emitter.ts +0 -1
- package/src/function.ts +66 -45
- package/src/internal/is.ts +7 -0
- package/src/internal/number.ts +23 -1
- package/src/internal/random.ts +16 -14
- package/src/internal/value/get.ts +5 -0
- package/src/internal/value/misc.ts +11 -12
- package/src/internal/value/set.ts +7 -0
- package/src/is.ts +1 -7
- package/src/sized.ts +24 -32
- package/types/array/count.d.cts +0 -6
- package/types/array/exists.d.cts +0 -6
- package/types/array/filter.d.cts +0 -6
- package/types/array/find.d.cts +0 -6
- package/types/array/group-by.d.cts +2 -7
- package/types/array/group-by.d.ts +1 -0
- package/types/array/index-of.d.cts +0 -6
- package/types/array/index.d.cts +24 -40
- package/types/array/index.d.ts +17 -9
- package/types/array/insert.d.cts +2 -0
- package/types/array/insert.d.ts +2 -0
- package/types/array/models.d.cts +15 -15
- package/types/array/models.d.ts +15 -13
- package/types/array/sort.d.cts +9 -25
- package/types/array/sort.d.ts +8 -8
- package/types/array/to-map.d.cts +0 -6
- package/types/array/to-record.d.cts +1 -7
- package/types/array/unique.d.cts +0 -6
- package/types/{color/index.d.ts → color.d.ts} +26 -3
- package/types/function.d.cts +5 -5
- package/types/function.d.ts +6 -2
- package/types/index.d.cts +127 -157
- package/types/index.d.ts +1 -1
- package/types/internal/array/callbacks.d.cts +1 -1
- package/types/internal/array/callbacks.d.ts +1 -6
- package/types/internal/array/find.d.ts +1 -3
- package/types/internal/math/aggregate.d.cts +0 -19
- package/types/internal/math/aggregate.d.ts +0 -16
- package/types/internal/string/key.d.cts +5 -0
- package/types/internal/string/key.d.ts +1 -0
- package/types/internal/value/{misc.d.cts → handle.d.cts} +0 -4
- package/types/internal/value/{misc.d.ts → handle.d.ts} +0 -1
- package/types/internal/value/paths.d.cts +5 -0
- package/types/internal/value/paths.d.ts +1 -0
- package/types/is.d.cts +9 -21
- package/types/is.d.ts +14 -2
- package/types/math.d.cts +12 -15
- package/types/math.d.ts +16 -2
- package/types/models.d.cts +2 -14
- package/types/models.d.ts +2 -14
- package/types/number.d.ts +15 -1
- package/types/query.d.cts +0 -3
- package/types/random.d.cts +8 -8
- package/types/random.d.ts +8 -1
- package/types/string/index.d.cts +12 -15
- package/types/string/index.d.ts +0 -1
- package/types/string/misc.d.cts +12 -0
- package/types/string/misc.d.ts +12 -0
- package/types/string/template.d.cts +0 -3
- package/types/{internal/value → value}/get.d.cts +0 -3
- package/types/{internal/value → value}/get.d.ts +1 -1
- package/types/value/index.d.cts +39 -53
- package/types/value/index.d.ts +9 -5
- package/types/value/merge.d.cts +2 -13
- package/types/value/merge.d.ts +3 -8
- package/types/{internal/value → value}/set.d.cts +0 -3
- package/types/{internal/value → value}/set.d.ts +1 -1
- package/types/value/smush.d.cts +0 -3
- package/types/value/unsmush.d.cts +0 -3
- package/dist/array/flatten.cjs +0 -12
- package/dist/array/flatten.js +0 -8
- package/dist/array/push.cjs +0 -11
- package/dist/array/push.js +0 -7
- package/dist/color/constants.cjs +0 -33
- package/dist/color/constants.js +0 -22
- package/dist/color/get.cjs +0 -50
- package/dist/color/get.js +0 -46
- package/dist/color/index.cjs +0 -98
- package/dist/color/index.js +0 -85
- package/dist/color/is.cjs +0 -58
- package/dist/color/is.js +0 -51
- package/dist/color/misc.cjs +0 -16
- package/dist/color/misc.js +0 -12
- package/dist/color/models.cjs +0 -2
- package/dist/color/models.js +0 -1
- package/dist/color/value.cjs +0 -90
- package/dist/color/value.js +0 -83
- package/dist/internal/array/group.cjs +0 -32
- package/dist/internal/array/group.js +0 -28
- package/dist/internal/array/insert.cjs +0 -33
- package/dist/internal/array/insert.js +0 -29
- package/dist/internal/function.cjs +0 -8
- package/dist/internal/function.js +0 -4
- package/dist/internal/is.cjs +0 -41
- package/dist/internal/is.js +0 -34
- package/dist/internal/number.cjs +0 -54
- package/dist/internal/number.js +0 -48
- package/dist/internal/random.cjs +0 -21
- package/dist/internal/random.js +0 -16
- package/dist/internal/string.cjs +0 -50
- package/dist/internal/string.js +0 -41
- package/dist/value/partial.cjs +0 -18
- package/dist/value/partial.js +0 -14
- package/types/array/flatten.d.cts +0 -9
- package/types/array/flatten.d.ts +0 -5
- package/types/array/push.d.cts +0 -10
- package/types/array/push.d.ts +0 -6
- package/types/color/constants.d.cts +0 -23
- package/types/color/constants.d.ts +0 -9
- package/types/color/get.d.cts +0 -23
- package/types/color/get.d.ts +0 -5
- package/types/color/is.d.cts +0 -53
- package/types/color/is.d.ts +0 -18
- package/types/color/misc.d.cts +0 -8
- package/types/color/misc.d.ts +0 -4
- package/types/color/models.d.cts +0 -20
- package/types/color/models.d.ts +0 -16
- package/types/color/value.d.cts +0 -32
- package/types/color/value.d.ts +0 -19
- package/types/internal/array/group.d.cts +0 -9
- package/types/internal/array/group.d.ts +0 -2
- package/types/internal/array/insert.d.cts +0 -5
- package/types/internal/array/insert.d.ts +0 -1
- package/types/internal/function.d.cts +0 -8
- package/types/internal/function.d.ts +0 -4
- package/types/internal/is.d.cts +0 -33
- package/types/internal/is.d.ts +0 -17
- package/types/internal/number.d.cts +0 -19
- package/types/internal/number.d.ts +0 -15
- package/types/internal/random.d.cts +0 -12
- package/types/internal/random.d.ts +0 -8
- package/types/internal/string.d.cts +0 -19
- package/types/internal/string.d.ts +0 -15
- package/types/value/partial.d.cts +0 -12
- package/types/value/partial.d.ts +0 -5
- package/dist/{internal/array → array}/chunk.cjs +0 -0
- package/dist/{internal/array → array}/chunk.js +0 -0
- package/dist/{internal/array → array}/compact.cjs +0 -0
- package/dist/{internal/array → array}/compact.js +0 -0
- package/dist/{internal/array → array}/shuffle.js +0 -0
- package/dist/{internal/value → value}/equal.js +0 -0
- package/types/{internal/array → array}/chunk.d.cts +0 -0
- package/types/{internal/array → array}/chunk.d.ts +0 -0
- package/types/{internal/array → array}/compact.d.cts +0 -0
- package/types/{internal/array → array}/compact.d.ts +0 -0
- package/types/{internal/array → array}/shuffle.d.cts +0 -0
- package/types/{internal/array → array}/shuffle.d.ts +0 -0
- package/types/{color/index.d.cts → color.d.cts} +16 -16
- /package/types/{internal/value → value}/compare.d.cts +0 -0
- /package/types/{internal/value → value}/compare.d.ts +0 -0
- /package/types/{internal/value → value}/equal.d.cts +0 -0
- /package/types/{internal/value → value}/equal.d.ts +0 -0
package/dist/array/group-by.cjs
CHANGED
|
@@ -2,15 +2,40 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
4
|
|
|
5
|
-
const
|
|
5
|
+
const internal_array_callbacks = require('../internal/array/callbacks.cjs');
|
|
6
6
|
|
|
7
7
|
function groupBy(array, key, valueOrArrays, arrays) {
|
|
8
|
-
return
|
|
8
|
+
return groupValues(
|
|
9
9
|
array,
|
|
10
10
|
key,
|
|
11
11
|
valueOrArrays,
|
|
12
12
|
key === true || valueOrArrays === true || arrays === true
|
|
13
13
|
);
|
|
14
14
|
}
|
|
15
|
+
function groupValues(array, key, value, arrays) {
|
|
16
|
+
if (!Array.isArray(array) || array.length === 0) {
|
|
17
|
+
return {};
|
|
18
|
+
}
|
|
19
|
+
const callbacks = internal_array_callbacks.getCallbacks(void 0, key, value);
|
|
20
|
+
const record = {};
|
|
21
|
+
const { length } = array;
|
|
22
|
+
for (let index = 0; index < length; index += 1) {
|
|
23
|
+
const item = array[index];
|
|
24
|
+
const keyed = callbacks?.key?.(item, index, array) ?? index;
|
|
25
|
+
const valued = callbacks?.value?.(item, index, array) ?? item;
|
|
26
|
+
if (arrays) {
|
|
27
|
+
const existing = record[keyed];
|
|
28
|
+
if (existing == null) {
|
|
29
|
+
record[keyed] = [valued];
|
|
30
|
+
} else {
|
|
31
|
+
existing.push(valued);
|
|
32
|
+
}
|
|
33
|
+
} else {
|
|
34
|
+
record[keyed] = valued;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return record;
|
|
38
|
+
}
|
|
15
39
|
|
|
16
40
|
exports.groupBy = groupBy;
|
|
41
|
+
exports.groupValues = groupValues;
|
package/dist/array/group-by.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getCallbacks } from '../internal/array/callbacks.js';
|
|
2
2
|
|
|
3
3
|
function groupBy(array, key, valueOrArrays, arrays) {
|
|
4
4
|
return groupValues(
|
|
@@ -8,5 +8,29 @@ function groupBy(array, key, valueOrArrays, arrays) {
|
|
|
8
8
|
key === true || valueOrArrays === true || arrays === true
|
|
9
9
|
);
|
|
10
10
|
}
|
|
11
|
+
function groupValues(array, key, value, arrays) {
|
|
12
|
+
if (!Array.isArray(array) || array.length === 0) {
|
|
13
|
+
return {};
|
|
14
|
+
}
|
|
15
|
+
const callbacks = getCallbacks(void 0, key, value);
|
|
16
|
+
const record = {};
|
|
17
|
+
const { length } = array;
|
|
18
|
+
for (let index = 0; index < length; index += 1) {
|
|
19
|
+
const item = array[index];
|
|
20
|
+
const keyed = callbacks?.key?.(item, index, array) ?? index;
|
|
21
|
+
const valued = callbacks?.value?.(item, index, array) ?? item;
|
|
22
|
+
if (arrays) {
|
|
23
|
+
const existing = record[keyed];
|
|
24
|
+
if (existing == null) {
|
|
25
|
+
record[keyed] = [valued];
|
|
26
|
+
} else {
|
|
27
|
+
existing.push(valued);
|
|
28
|
+
}
|
|
29
|
+
} else {
|
|
30
|
+
record[keyed] = valued;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return record;
|
|
34
|
+
}
|
|
11
35
|
|
|
12
|
-
export { groupBy };
|
|
36
|
+
export { groupBy, groupValues };
|
package/dist/array/index.cjs
CHANGED
|
@@ -2,40 +2,46 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
4
|
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const
|
|
5
|
+
const array_insert = require('./insert.cjs');
|
|
6
|
+
const array_chunk = require('./chunk.cjs');
|
|
7
|
+
const array_compact = require('./compact.cjs');
|
|
8
8
|
const array_count = require('./count.cjs');
|
|
9
9
|
const array_exists = require('./exists.cjs');
|
|
10
10
|
const array_filter = require('./filter.cjs');
|
|
11
11
|
const array_find = require('./find.cjs');
|
|
12
|
-
const array_flatten = require('./flatten.cjs');
|
|
13
12
|
const array_groupBy = require('./group-by.cjs');
|
|
14
13
|
const array_indexOf = require('./index-of.cjs');
|
|
15
|
-
const
|
|
16
|
-
const array_push = require('./push.cjs');
|
|
14
|
+
const array_shuffle = require('./shuffle.cjs');
|
|
17
15
|
const array_sort = require('./sort.cjs');
|
|
18
16
|
const array_splice = require('./splice.cjs');
|
|
19
17
|
const array_toMap = require('./to-map.cjs');
|
|
20
18
|
const array_toRecord = require('./to-record.cjs');
|
|
21
19
|
const array_unique = require('./unique.cjs');
|
|
22
20
|
|
|
21
|
+
function flatten(array) {
|
|
22
|
+
if (!Array.isArray(array)) {
|
|
23
|
+
return [];
|
|
24
|
+
}
|
|
25
|
+
return array.flat(Number.POSITIVE_INFINITY);
|
|
26
|
+
}
|
|
27
|
+
function push(array, pushed) {
|
|
28
|
+
return array_insert.insertValues("push", array, pushed, array.length, 0);
|
|
29
|
+
}
|
|
23
30
|
|
|
24
|
-
|
|
25
|
-
exports.chunk =
|
|
26
|
-
exports.compact =
|
|
27
|
-
exports.shuffle = internal_array_shuffle.shuffle;
|
|
31
|
+
exports.insert = array_insert.insert;
|
|
32
|
+
exports.chunk = array_chunk.chunk;
|
|
33
|
+
exports.compact = array_compact.compact;
|
|
28
34
|
exports.count = array_count.count;
|
|
29
35
|
exports.exists = array_exists.exists;
|
|
30
36
|
exports.filter = array_filter.filter;
|
|
31
37
|
exports.find = array_find.find;
|
|
32
|
-
exports.flatten = array_flatten.flatten;
|
|
33
38
|
exports.groupBy = array_groupBy.groupBy;
|
|
34
39
|
exports.indexOf = array_indexOf.indexOf;
|
|
35
|
-
exports.
|
|
36
|
-
exports.push = array_push.push;
|
|
40
|
+
exports.shuffle = array_shuffle.shuffle;
|
|
37
41
|
exports.sort = array_sort.sort;
|
|
38
42
|
exports.splice = array_splice.splice;
|
|
39
43
|
exports.toMap = array_toMap.toMap;
|
|
40
44
|
exports.toRecord = array_toRecord.toRecord;
|
|
41
45
|
exports.unique = array_unique.unique;
|
|
46
|
+
exports.flatten = flatten;
|
|
47
|
+
exports.push = push;
|
package/dist/array/index.js
CHANGED
|
@@ -1,17 +1,28 @@
|
|
|
1
|
-
|
|
2
|
-
export {
|
|
3
|
-
export {
|
|
1
|
+
import { insertValues } from './insert.js';
|
|
2
|
+
export { insert } from './insert.js';
|
|
3
|
+
export { chunk } from './chunk.js';
|
|
4
|
+
export { compact } from './compact.js';
|
|
4
5
|
export { count } from './count.js';
|
|
5
6
|
export { exists } from './exists.js';
|
|
6
7
|
export { filter } from './filter.js';
|
|
7
8
|
export { find } from './find.js';
|
|
8
|
-
export { flatten } from './flatten.js';
|
|
9
9
|
export { groupBy } from './group-by.js';
|
|
10
10
|
export { indexOf } from './index-of.js';
|
|
11
|
-
export {
|
|
12
|
-
export { push } from './push.js';
|
|
11
|
+
export { shuffle } from './shuffle.js';
|
|
13
12
|
export { sort } from './sort.js';
|
|
14
13
|
export { splice } from './splice.js';
|
|
15
14
|
export { toMap } from './to-map.js';
|
|
16
15
|
export { toRecord } from './to-record.js';
|
|
17
16
|
export { unique } from './unique.js';
|
|
17
|
+
|
|
18
|
+
function flatten(array) {
|
|
19
|
+
if (!Array.isArray(array)) {
|
|
20
|
+
return [];
|
|
21
|
+
}
|
|
22
|
+
return array.flat(Number.POSITIVE_INFINITY);
|
|
23
|
+
}
|
|
24
|
+
function push(array, pushed) {
|
|
25
|
+
return insertValues("push", array, pushed, array.length, 0);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export { flatten, push };
|
package/dist/array/insert.cjs
CHANGED
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
4
|
|
|
5
|
-
const
|
|
5
|
+
const array_chunk = require('./chunk.cjs');
|
|
6
6
|
|
|
7
7
|
function insert(array, indexOrItems, items) {
|
|
8
|
-
return
|
|
8
|
+
return insertValues(
|
|
9
9
|
"insert",
|
|
10
10
|
array,
|
|
11
11
|
items == null ? indexOrItems : items,
|
|
@@ -13,5 +13,31 @@ function insert(array, indexOrItems, items) {
|
|
|
13
13
|
0
|
|
14
14
|
);
|
|
15
15
|
}
|
|
16
|
+
function insertValues(type, array, items, start, deleteCount) {
|
|
17
|
+
const splice = type === "insert" || type === "splice";
|
|
18
|
+
if (!Array.isArray(array) || typeof start !== "number") {
|
|
19
|
+
return splice ? [] : 0;
|
|
20
|
+
}
|
|
21
|
+
if (!Array.isArray(items) || items.length === 0) {
|
|
22
|
+
return splice ? [] : 0;
|
|
23
|
+
}
|
|
24
|
+
const actualStart = Math.min(Math.max(0, start), array.length);
|
|
25
|
+
const chunked = array_chunk.chunk(items);
|
|
26
|
+
const lastIndex = chunked.length - 1;
|
|
27
|
+
let index = Number(chunked.length);
|
|
28
|
+
let returned;
|
|
29
|
+
while (--index >= 0) {
|
|
30
|
+
const result = array.splice(
|
|
31
|
+
actualStart,
|
|
32
|
+
index === lastIndex ? deleteCount < 0 ? 0 : deleteCount : 0,
|
|
33
|
+
...chunked[index]
|
|
34
|
+
);
|
|
35
|
+
if (returned == null) {
|
|
36
|
+
returned = result;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return type === "insert" ? array : type === "splice" ? returned : array.length;
|
|
40
|
+
}
|
|
16
41
|
|
|
17
42
|
exports.insert = insert;
|
|
43
|
+
exports.insertValues = insertValues;
|
package/dist/array/insert.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { chunk } from './chunk.js';
|
|
2
2
|
|
|
3
3
|
function insert(array, indexOrItems, items) {
|
|
4
4
|
return insertValues(
|
|
@@ -9,5 +9,30 @@ function insert(array, indexOrItems, items) {
|
|
|
9
9
|
0
|
|
10
10
|
);
|
|
11
11
|
}
|
|
12
|
+
function insertValues(type, array, items, start, deleteCount) {
|
|
13
|
+
const splice = type === "insert" || type === "splice";
|
|
14
|
+
if (!Array.isArray(array) || typeof start !== "number") {
|
|
15
|
+
return splice ? [] : 0;
|
|
16
|
+
}
|
|
17
|
+
if (!Array.isArray(items) || items.length === 0) {
|
|
18
|
+
return splice ? [] : 0;
|
|
19
|
+
}
|
|
20
|
+
const actualStart = Math.min(Math.max(0, start), array.length);
|
|
21
|
+
const chunked = chunk(items);
|
|
22
|
+
const lastIndex = chunked.length - 1;
|
|
23
|
+
let index = Number(chunked.length);
|
|
24
|
+
let returned;
|
|
25
|
+
while (--index >= 0) {
|
|
26
|
+
const result = array.splice(
|
|
27
|
+
actualStart,
|
|
28
|
+
index === lastIndex ? deleteCount < 0 ? 0 : deleteCount : 0,
|
|
29
|
+
...chunked[index]
|
|
30
|
+
);
|
|
31
|
+
if (returned == null) {
|
|
32
|
+
returned = result;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return type === "insert" ? array : type === "splice" ? returned : array.length;
|
|
36
|
+
}
|
|
12
37
|
|
|
13
|
-
export { insert };
|
|
38
|
+
export { insert, insertValues };
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
4
|
|
|
5
|
-
const
|
|
5
|
+
const random = require('../random.cjs');
|
|
6
6
|
|
|
7
7
|
function shuffle(array) {
|
|
8
8
|
if (!Array.isArray(array)) {
|
|
@@ -14,8 +14,8 @@ function shuffle(array) {
|
|
|
14
14
|
const shuffled = array.slice();
|
|
15
15
|
let index = Number(shuffled.length);
|
|
16
16
|
while (--index >= 0) {
|
|
17
|
-
const random =
|
|
18
|
-
[shuffled[index], shuffled[random]] = [shuffled[random], shuffled[index]];
|
|
17
|
+
const random$1 = random.getRandomInteger(0, index);
|
|
18
|
+
[shuffled[index], shuffled[random$1]] = [shuffled[random$1], shuffled[index]];
|
|
19
19
|
}
|
|
20
20
|
return shuffled;
|
|
21
21
|
}
|
package/dist/array/sort.cjs
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
4
|
|
|
5
|
-
const
|
|
6
|
-
const
|
|
5
|
+
const is = require('../is.cjs');
|
|
6
|
+
const value_compare = require('../value/compare.cjs');
|
|
7
7
|
|
|
8
8
|
function sort(array, first, second) {
|
|
9
9
|
if (!Array.isArray(array)) {
|
|
@@ -13,48 +13,48 @@ function sort(array, first, second) {
|
|
|
13
13
|
return array;
|
|
14
14
|
}
|
|
15
15
|
const direction = first === true || second === true ? "desc" : "asc";
|
|
16
|
-
const
|
|
17
|
-
let { length } =
|
|
18
|
-
const
|
|
16
|
+
const unknownKeys = Array.isArray(first) ? first : [first];
|
|
17
|
+
let { length } = unknownKeys;
|
|
18
|
+
const keys = [];
|
|
19
19
|
for (let index = 0; index < length; index += 1) {
|
|
20
|
-
const
|
|
21
|
-
const
|
|
20
|
+
const key = unknownKeys[index];
|
|
21
|
+
const keyWithCallback = {
|
|
22
22
|
direction,
|
|
23
23
|
callback: void 0
|
|
24
24
|
};
|
|
25
|
-
if (
|
|
26
|
-
|
|
27
|
-
} else if (typeof
|
|
28
|
-
|
|
29
|
-
} else if (typeof
|
|
30
|
-
|
|
31
|
-
|
|
25
|
+
if (is.isKey(key)) {
|
|
26
|
+
keyWithCallback.callback = (value) => value[key];
|
|
27
|
+
} else if (typeof key === "function") {
|
|
28
|
+
keyWithCallback.callback = key;
|
|
29
|
+
} else if (typeof key?.value === "function" || is.isKey(key?.value)) {
|
|
30
|
+
keyWithCallback.direction = key?.direction ?? direction;
|
|
31
|
+
keyWithCallback.callback = typeof key.value === "function" ? key.value : (value) => value[key.value];
|
|
32
32
|
}
|
|
33
|
-
if (typeof
|
|
34
|
-
const existing =
|
|
35
|
-
(existing2) => existing2.callback.toString() ===
|
|
33
|
+
if (typeof keyWithCallback.callback === "function") {
|
|
34
|
+
const existing = keys.findIndex(
|
|
35
|
+
(existing2) => existing2.callback.toString() === keyWithCallback.callback.toString()
|
|
36
36
|
);
|
|
37
37
|
if (existing > -1) {
|
|
38
|
-
|
|
38
|
+
keys.splice(existing, 1);
|
|
39
39
|
}
|
|
40
|
-
|
|
40
|
+
keys.push(keyWithCallback);
|
|
41
41
|
}
|
|
42
42
|
}
|
|
43
|
-
length =
|
|
43
|
+
length = keys.length;
|
|
44
44
|
if (length === 0) {
|
|
45
45
|
return array.sort(
|
|
46
|
-
(first2, second2) =>
|
|
46
|
+
(first2, second2) => value_compare.compare(first2, second2) * (direction === "asc" ? 1 : -1)
|
|
47
47
|
);
|
|
48
48
|
}
|
|
49
49
|
if (length === 1) {
|
|
50
50
|
return array.sort(
|
|
51
|
-
(first2, second2) =>
|
|
51
|
+
(first2, second2) => value_compare.compare(keys[0].callback(first2), keys[0].callback(second2)) * (keys[0].direction === "asc" ? 1 : -1)
|
|
52
52
|
);
|
|
53
53
|
}
|
|
54
54
|
const sorted = array.sort((first2, second2) => {
|
|
55
55
|
for (let index = 0; index < length; index += 1) {
|
|
56
|
-
const { callback, direction: direction2 } =
|
|
57
|
-
const compared =
|
|
56
|
+
const { callback, direction: direction2 } = keys[index];
|
|
57
|
+
const compared = value_compare.compare(callback(first2), callback(second2)) * (direction2 === "asc" ? 1 : -1);
|
|
58
58
|
if (compared !== 0) {
|
|
59
59
|
return compared;
|
|
60
60
|
}
|
package/dist/array/sort.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { isKey } from '../
|
|
2
|
-
import { compare } from '../
|
|
1
|
+
import { isKey } from '../is.js';
|
|
2
|
+
import { compare } from '../value/compare.js';
|
|
3
3
|
|
|
4
4
|
function sort(array, first, second) {
|
|
5
5
|
if (!Array.isArray(array)) {
|
|
@@ -9,34 +9,34 @@ function sort(array, first, second) {
|
|
|
9
9
|
return array;
|
|
10
10
|
}
|
|
11
11
|
const direction = first === true || second === true ? "desc" : "asc";
|
|
12
|
-
const
|
|
13
|
-
let { length } =
|
|
14
|
-
const
|
|
12
|
+
const unknownKeys = Array.isArray(first) ? first : [first];
|
|
13
|
+
let { length } = unknownKeys;
|
|
14
|
+
const keys = [];
|
|
15
15
|
for (let index = 0; index < length; index += 1) {
|
|
16
|
-
const
|
|
17
|
-
const
|
|
16
|
+
const key = unknownKeys[index];
|
|
17
|
+
const keyWithCallback = {
|
|
18
18
|
direction,
|
|
19
19
|
callback: void 0
|
|
20
20
|
};
|
|
21
|
-
if (isKey(
|
|
22
|
-
|
|
23
|
-
} else if (typeof
|
|
24
|
-
|
|
25
|
-
} else if (typeof
|
|
26
|
-
|
|
27
|
-
|
|
21
|
+
if (isKey(key)) {
|
|
22
|
+
keyWithCallback.callback = (value) => value[key];
|
|
23
|
+
} else if (typeof key === "function") {
|
|
24
|
+
keyWithCallback.callback = key;
|
|
25
|
+
} else if (typeof key?.value === "function" || isKey(key?.value)) {
|
|
26
|
+
keyWithCallback.direction = key?.direction ?? direction;
|
|
27
|
+
keyWithCallback.callback = typeof key.value === "function" ? key.value : (value) => value[key.value];
|
|
28
28
|
}
|
|
29
|
-
if (typeof
|
|
30
|
-
const existing =
|
|
31
|
-
(existing2) => existing2.callback.toString() ===
|
|
29
|
+
if (typeof keyWithCallback.callback === "function") {
|
|
30
|
+
const existing = keys.findIndex(
|
|
31
|
+
(existing2) => existing2.callback.toString() === keyWithCallback.callback.toString()
|
|
32
32
|
);
|
|
33
33
|
if (existing > -1) {
|
|
34
|
-
|
|
34
|
+
keys.splice(existing, 1);
|
|
35
35
|
}
|
|
36
|
-
|
|
36
|
+
keys.push(keyWithCallback);
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
|
-
length =
|
|
39
|
+
length = keys.length;
|
|
40
40
|
if (length === 0) {
|
|
41
41
|
return array.sort(
|
|
42
42
|
(first2, second2) => compare(first2, second2) * (direction === "asc" ? 1 : -1)
|
|
@@ -44,12 +44,12 @@ function sort(array, first, second) {
|
|
|
44
44
|
}
|
|
45
45
|
if (length === 1) {
|
|
46
46
|
return array.sort(
|
|
47
|
-
(first2, second2) => compare(
|
|
47
|
+
(first2, second2) => compare(keys[0].callback(first2), keys[0].callback(second2)) * (keys[0].direction === "asc" ? 1 : -1)
|
|
48
48
|
);
|
|
49
49
|
}
|
|
50
50
|
const sorted = array.sort((first2, second2) => {
|
|
51
51
|
for (let index = 0; index < length; index += 1) {
|
|
52
|
-
const { callback, direction: direction2 } =
|
|
52
|
+
const { callback, direction: direction2 } = keys[index];
|
|
53
53
|
const compared = compare(callback(first2), callback(second2)) * (direction2 === "asc" ? 1 : -1);
|
|
54
54
|
if (compared !== 0) {
|
|
55
55
|
return compared;
|
package/dist/array/splice.cjs
CHANGED
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
4
|
|
|
5
|
-
const
|
|
5
|
+
const array_insert = require('./insert.cjs');
|
|
6
6
|
|
|
7
7
|
function splice(array, start, deleteCountOrItems, items) {
|
|
8
|
-
return
|
|
8
|
+
return array_insert.insertValues(
|
|
9
9
|
"splice",
|
|
10
10
|
array,
|
|
11
11
|
typeof deleteCountOrItems === "number" ? items : deleteCountOrItems,
|
package/dist/array/splice.js
CHANGED
package/dist/array/to-map.cjs
CHANGED
|
@@ -14,7 +14,7 @@ function toMap(array, keyOrArrays, valueOrArrays, arrays) {
|
|
|
14
14
|
const { length } = array;
|
|
15
15
|
for (let index = 0; index < length; index += 1) {
|
|
16
16
|
const item = array[index];
|
|
17
|
-
const key = callbacks?.
|
|
17
|
+
const key = callbacks?.key?.(item, index, array) ?? index;
|
|
18
18
|
const value = callbacks?.value?.(item, index, array) ?? item;
|
|
19
19
|
if (asArrays) {
|
|
20
20
|
const existing = map.get(key);
|
package/dist/array/to-map.js
CHANGED
|
@@ -10,7 +10,7 @@ function toMap(array, keyOrArrays, valueOrArrays, arrays) {
|
|
|
10
10
|
const { length } = array;
|
|
11
11
|
for (let index = 0; index < length; index += 1) {
|
|
12
12
|
const item = array[index];
|
|
13
|
-
const key = callbacks?.
|
|
13
|
+
const key = callbacks?.key?.(item, index, array) ?? index;
|
|
14
14
|
const value = callbacks?.value?.(item, index, array) ?? item;
|
|
15
15
|
if (asArrays) {
|
|
16
16
|
const existing = map.get(key);
|
package/dist/array/to-record.cjs
CHANGED
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
4
|
|
|
5
|
-
const
|
|
5
|
+
const array_groupBy = require('./group-by.cjs');
|
|
6
6
|
|
|
7
7
|
function toRecord(array, key, valueOrArrays, arrays) {
|
|
8
|
-
return
|
|
8
|
+
return array_groupBy.groupValues(
|
|
9
9
|
array,
|
|
10
10
|
key,
|
|
11
11
|
valueOrArrays,
|
package/dist/array/to-record.js
CHANGED