@oscarpalmer/atoms 0.74.1 → 0.76.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/js/array/chunk.cjs +18 -0
- package/dist/js/array/{chunk.mjs → chunk.js} +2 -2
- package/dist/js/array/compact.cjs +6 -0
- package/dist/js/array/{compact.mjs → compact.js} +0 -1
- package/dist/js/array/count.cjs +14 -0
- package/dist/js/array/count.js +14 -0
- package/dist/js/array/exists.cjs +14 -0
- package/dist/js/array/exists.js +14 -0
- package/dist/js/array/filter.cjs +14 -0
- package/dist/js/array/filter.js +14 -0
- package/dist/js/array/find.cjs +14 -0
- package/dist/js/array/find.js +14 -0
- package/dist/js/array/group-by.cjs +35 -0
- package/dist/js/array/group-by.js +35 -0
- package/dist/js/array/index-of.cjs +14 -0
- package/dist/js/array/index-of.js +14 -0
- package/dist/js/array/index.cjs +40 -0
- package/dist/js/array/index.js +34 -381
- package/dist/js/array/insert.cjs +31 -0
- package/dist/js/array/insert.js +31 -0
- package/dist/js/array/models.cjs +1 -0
- package/dist/js/array/models.js +1 -0
- package/dist/js/array/shuffle.cjs +13 -0
- package/dist/js/array/{shuffle.mjs → shuffle.js} +2 -3
- package/dist/js/array/sort.cjs +53 -0
- package/dist/js/array/{sort.mjs → sort.js} +13 -9
- package/dist/js/array/splice.cjs +14 -0
- package/dist/js/array/splice.js +14 -0
- package/dist/js/array/to-map.cjs +27 -0
- package/dist/js/array/to-map.js +27 -0
- package/dist/js/array/to-record.cjs +12 -0
- package/dist/js/array/to-record.js +12 -0
- package/dist/js/array/unique.cjs +7 -0
- package/dist/js/array/unique.js +7 -0
- package/dist/js/colour/base.cjs +18 -0
- package/dist/js/colour/{base.mjs → base.js} +4 -3
- package/dist/js/colour/functions.cjs +96 -0
- package/dist/js/colour/{functions.mjs → functions.js} +18 -19
- package/dist/js/colour/hex.cjs +56 -0
- package/dist/js/colour/{hex.mjs → hex.js} +34 -15
- package/dist/js/colour/hsl.cjs +85 -0
- package/dist/js/colour/{hsl.mjs → hsl.js} +40 -12
- package/dist/js/colour/index.cjs +29 -0
- package/dist/js/colour/index.js +14 -272
- package/dist/js/colour/is.cjs +27 -0
- package/dist/js/colour/{is.mjs → is.js} +7 -6
- package/dist/js/colour/rgb.cjs +87 -0
- package/dist/js/colour/{rgb.mjs → rgb.js} +43 -12
- package/dist/js/{emitter.mjs → emitter.cjs} +88 -56
- package/dist/js/emitter.js +85 -56
- package/dist/js/{function.mjs → function.cjs} +66 -46
- package/dist/js/function.js +61 -48
- package/dist/js/index.cjs +136 -0
- package/dist/js/index.js +133 -1724
- package/dist/js/internal/array/callbacks.cjs +23 -0
- package/dist/js/internal/array/callbacks.js +23 -0
- package/dist/js/internal/array/find.cjs +51 -0
- package/dist/js/internal/array/find.js +51 -0
- package/dist/js/internal/value/handle.cjs +21 -0
- package/dist/js/internal/{value-handle.mjs → value/handle.js} +0 -1
- package/dist/js/{is.mjs → is.cjs} +17 -18
- package/dist/js/is.js +15 -27
- package/dist/js/logger.cjs +108 -0
- package/dist/js/logger.js +44 -8
- package/dist/js/{math.mjs → math.cjs} +7 -8
- package/dist/js/math.js +4 -5
- package/dist/js/models.cjs +1 -0
- package/dist/js/models.js +1 -0
- package/dist/js/{number.mjs → number.cjs} +8 -8
- package/dist/js/number.js +5 -5
- package/dist/js/{query.mjs → query.cjs} +18 -18
- package/dist/js/query.js +17 -86
- package/dist/js/{queue.mjs → queue.cjs} +12 -13
- package/dist/js/queue.js +9 -10
- package/dist/js/{random.mjs → random.cjs} +14 -21
- package/dist/js/random.js +9 -26
- package/dist/js/{sized.mjs → sized.cjs} +68 -33
- package/dist/js/sized.js +66 -38
- package/dist/js/string/case.cjs +41 -0
- package/dist/js/string/{case.mjs → case.js} +13 -9
- package/dist/js/string/index.cjs +59 -0
- package/dist/js/string/index.js +30 -100
- package/dist/js/string/template.cjs +21 -0
- package/dist/js/string/{template.mjs → template.js} +4 -5
- package/dist/js/{touch.mjs → touch.cjs} +4 -7
- package/dist/js/touch.js +3 -5
- package/dist/js/value/clone.cjs +76 -0
- package/dist/js/value/{clone.mjs → clone.js} +5 -6
- package/dist/js/value/compare.cjs +59 -0
- package/dist/js/value/{compare.mjs → compare.js} +4 -6
- package/dist/js/value/diff.cjs +75 -0
- package/dist/js/value/{diff.mjs → diff.js} +13 -11
- package/dist/js/value/equal.cjs +106 -0
- package/dist/js/value/{equal.mjs → equal.js} +13 -8
- package/dist/js/value/get.cjs +21 -0
- package/dist/js/value/{get.mjs → get.js} +9 -4
- package/dist/js/value/index.cjs +30 -0
- package/dist/js/value/index.js +19 -510
- package/dist/js/value/merge.cjs +35 -0
- package/dist/js/value/{merge.mjs → merge.js} +7 -6
- package/dist/js/value/set.cjs +25 -0
- package/dist/js/value/{set.mjs → set.js} +3 -4
- package/dist/js/value/smush.cjs +26 -0
- package/dist/js/value/{smush.mjs → smush.js} +3 -4
- package/dist/js/value/unsmush.cjs +39 -0
- package/dist/js/value/{unsmush.mjs → unsmush.js} +10 -7
- package/package.json +50 -47
- package/src/js/array/chunk.ts +6 -5
- package/src/js/array/compact.ts +8 -10
- package/src/js/array/count.ts +39 -19
- package/src/js/array/exists.ts +39 -15
- package/src/js/array/filter.ts +42 -20
- package/src/js/array/find.ts +45 -20
- package/src/js/array/group-by.ts +158 -27
- package/src/js/array/index-of.ts +40 -18
- package/src/js/array/index.ts +10 -9
- package/src/js/array/insert.ts +28 -14
- package/src/js/array/models.ts +18 -15
- package/src/js/array/shuffle.ts +3 -3
- package/src/js/array/sort.ts +32 -34
- package/src/js/array/splice.ts +22 -26
- package/src/js/array/to-map.ts +133 -45
- package/src/js/array/to-record.ts +137 -39
- package/src/js/array/unique.ts +20 -15
- package/src/js/colour/base.ts +3 -3
- package/src/js/colour/functions.ts +4 -6
- package/src/js/colour/hex.ts +5 -5
- package/src/js/colour/hsl.ts +18 -12
- package/src/js/colour/index.ts +1 -1
- package/src/js/colour/is.ts +3 -3
- package/src/js/colour/rgb.ts +17 -11
- package/src/js/emitter.ts +12 -9
- package/src/js/function.ts +17 -17
- package/src/js/index.ts +16 -16
- package/src/js/internal/array/callbacks.ts +33 -0
- package/src/js/internal/{array-find.ts → array/find.ts} +23 -24
- package/src/js/internal/{value-handle.ts → value/handle.ts} +1 -1
- package/src/js/is.ts +2 -2
- package/src/js/logger.ts +14 -14
- package/src/js/math.ts +1 -1
- package/src/js/models.ts +5 -5
- package/src/js/number.ts +2 -2
- package/src/js/query.ts +6 -10
- package/src/js/queue.ts +1 -1
- package/src/js/random.ts +9 -19
- package/src/js/sized.ts +145 -145
- package/src/js/string/case.ts +1 -1
- package/src/js/string/index.ts +13 -7
- package/src/js/string/template.ts +6 -3
- package/src/js/value/clone.ts +3 -7
- package/src/js/value/compare.ts +3 -5
- package/src/js/value/diff.ts +4 -4
- package/src/js/value/equal.ts +2 -2
- package/src/js/value/get.ts +3 -3
- package/src/js/value/index.ts +2 -2
- package/src/js/value/merge.ts +3 -3
- package/src/js/value/set.ts +3 -4
- package/src/js/value/smush.ts +4 -4
- package/src/js/value/unsmush.ts +4 -4
- package/types/array/chunk.d.cts +8 -0
- package/types/array/chunk.d.ts +2 -2
- package/types/array/compact.d.cts +12 -0
- package/types/array/compact.d.ts +4 -4
- package/types/array/count.d.cts +24 -0
- package/types/array/count.d.ts +13 -7
- package/types/array/exists.d.cts +26 -0
- package/types/array/exists.d.ts +11 -3
- package/types/array/filter.d.cts +26 -0
- package/types/array/filter.d.ts +14 -6
- package/types/array/find.d.cts +26 -0
- package/types/array/find.d.ts +14 -6
- package/types/array/group-by.d.cts +58 -0
- package/types/array/group-by.d.ts +49 -5
- package/types/array/index-of.d.cts +26 -0
- package/types/array/index-of.d.ts +14 -6
- package/types/array/index.d.cts +239 -95
- package/types/array/index.d.ts +7 -6
- package/types/array/insert.d.cts +16 -0
- package/types/array/insert.d.ts +10 -5
- package/types/array/models.d.cts +14 -11
- package/types/array/models.d.ts +14 -12
- package/types/array/shuffle.d.cts +8 -0
- package/types/array/shuffle.d.ts +2 -2
- package/types/array/sort.d.cts +24 -0
- package/types/array/sort.d.ts +10 -10
- package/types/array/splice.d.cts +22 -0
- package/types/array/splice.d.ts +4 -4
- package/types/array/to-map.d.cts +61 -0
- package/types/array/to-map.d.ts +42 -20
- package/types/array/to-record.d.cts +61 -0
- package/types/array/to-record.d.ts +42 -20
- package/types/array/unique.d.cts +21 -0
- package/types/array/unique.d.ts +10 -6
- package/types/colour/base.d.cts +153 -0
- package/types/colour/base.d.ts +2 -2
- package/types/colour/functions.d.cts +173 -0
- package/types/colour/functions.d.ts +3 -3
- package/types/colour/hex.d.cts +157 -0
- package/types/colour/hex.d.ts +4 -4
- package/types/colour/hsl.d.cts +157 -0
- package/types/colour/hsl.d.ts +16 -10
- package/types/colour/index.d.cts +28 -16
- package/types/colour/index.d.ts +1 -1
- package/types/colour/is.d.cts +170 -0
- package/types/colour/is.d.ts +3 -3
- package/types/colour/rgb.d.cts +157 -0
- package/types/colour/rgb.d.ts +15 -9
- package/types/emitter.d.cts +11 -8
- package/types/emitter.d.ts +11 -8
- package/types/function.d.cts +10 -10
- package/types/function.d.ts +11 -11
- package/types/index.d.cts +1120 -736
- package/types/index.d.ts +16 -16
- package/types/internal/array/callbacks.d.cts +11 -0
- package/types/internal/array/callbacks.d.ts +2 -0
- package/types/internal/array/find.d.cts +7 -0
- package/types/internal/array/find.d.ts +3 -0
- package/types/internal/value/handle.d.cts +37 -0
- package/types/internal/{value-handle.d.ts → value/handle.d.ts} +1 -1
- package/types/is.d.ts +1 -1
- package/types/logger.d.cts +13 -21
- package/types/logger.d.ts +13 -21
- package/types/math.d.cts +1 -1
- package/types/math.d.ts +1 -1
- package/types/models.d.cts +4 -4
- package/types/models.d.ts +1 -4
- package/types/number.d.cts +2 -2
- package/types/number.d.ts +2 -2
- package/types/query.d.cts +2 -2
- package/types/query.d.ts +3 -3
- package/types/queue.d.cts +1 -1
- package/types/queue.d.ts +1 -1
- package/types/random.d.cts +8 -12
- package/types/random.d.ts +8 -12
- package/types/sized.d.cts +6 -6
- package/types/sized.d.ts +6 -6
- package/types/string/case.d.cts +28 -0
- package/types/string/index.d.cts +30 -27
- package/types/string/index.d.ts +3 -3
- package/types/string/template.d.cts +50 -0
- package/types/string/template.d.ts +4 -1
- package/types/value/clone.d.cts +8 -0
- package/types/value/clone.d.ts +4 -2
- package/types/value/compare.d.cts +8 -0
- package/types/value/diff.d.cts +25 -0
- package/types/value/equal.d.cts +12 -0
- package/types/value/get.d.cts +1319 -0
- package/types/value/get.d.ts +1 -1
- package/types/value/index.d.cts +8 -6
- package/types/value/index.d.ts +2 -2
- package/types/value/merge.d.cts +72 -0
- package/types/value/merge.d.ts +2 -2
- package/types/value/set.d.cts +1011 -0
- package/types/value/set.d.ts +1 -1
- package/types/value/smush.d.cts +1368 -0
- package/types/value/smush.d.ts +2 -2
- package/types/value/unsmush.d.cts +141 -0
- package/types/value/unsmush.d.ts +2 -2
- package/dist/js/array/count.mjs +0 -8
- package/dist/js/array/exists.mjs +0 -8
- package/dist/js/array/filter.mjs +0 -8
- package/dist/js/array/find.mjs +0 -8
- package/dist/js/array/group-by.mjs +0 -33
- package/dist/js/array/index-of.mjs +0 -8
- package/dist/js/array/index.mjs +0 -34
- package/dist/js/array/insert.mjs +0 -22
- package/dist/js/array/models.mjs +0 -0
- package/dist/js/array/splice.mjs +0 -9
- package/dist/js/array/to-map.mjs +0 -27
- package/dist/js/array/to-record.mjs +0 -8
- package/dist/js/array/unique.mjs +0 -8
- package/dist/js/colour/index.mjs +0 -30
- package/dist/js/index.mjs +0 -17
- package/dist/js/internal/array-callbacks.mjs +0 -19
- package/dist/js/internal/array-find.mjs +0 -51
- package/dist/js/logger.mjs +0 -69
- package/dist/js/models.mjs +0 -0
- package/dist/js/string/index.mjs +0 -44
- package/dist/js/value/index.mjs +0 -23
- package/src/js/internal/array-callbacks.ts +0 -28
- package/types/internal/array-callbacks.d.ts +0 -2
- package/types/internal/array-find.d.ts +0 -4
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const is = require("../is.cjs");
|
|
4
|
+
const value_set = require("./set.cjs");
|
|
5
|
+
function getKeyGroups(value) {
|
|
6
|
+
const keys = Object.keys(value);
|
|
7
|
+
const { length } = keys;
|
|
8
|
+
const grouped = [];
|
|
9
|
+
for (let index = 0; index < length; index += 1) {
|
|
10
|
+
const key = keys[index];
|
|
11
|
+
const dots = key.split(".");
|
|
12
|
+
if (grouped[dots.length] == null) {
|
|
13
|
+
grouped[dots.length] = [key];
|
|
14
|
+
} else {
|
|
15
|
+
grouped[dots.length].push(key);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
return grouped;
|
|
19
|
+
}
|
|
20
|
+
function unsmush(value) {
|
|
21
|
+
const groups = getKeyGroups(value);
|
|
22
|
+
const { length } = groups;
|
|
23
|
+
const unsmushed = {};
|
|
24
|
+
for (let groupIndex = 1; groupIndex < length; groupIndex += 1) {
|
|
25
|
+
const group = groups[groupIndex];
|
|
26
|
+
const groupLength = group.length;
|
|
27
|
+
for (let keyIndex = 0; keyIndex < groupLength; keyIndex += 1) {
|
|
28
|
+
const key = group[keyIndex];
|
|
29
|
+
const val = value[key];
|
|
30
|
+
value_set.setValue(
|
|
31
|
+
unsmushed,
|
|
32
|
+
key,
|
|
33
|
+
is.isArrayOrPlainObject(val) ? Array.isArray(val) ? [...val] : { ...val } : val
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return unsmushed;
|
|
38
|
+
}
|
|
39
|
+
exports.unsmush = unsmush;
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
import { setValue } from "./set";
|
|
1
|
+
import { isArrayOrPlainObject } from "../is.js";
|
|
2
|
+
import { setValue } from "./set.js";
|
|
4
3
|
function getKeyGroups(value) {
|
|
5
4
|
const keys = Object.keys(value);
|
|
6
5
|
const { length } = keys;
|
|
7
6
|
const grouped = [];
|
|
8
|
-
for (let index = 0;index < length; index += 1) {
|
|
7
|
+
for (let index = 0; index < length; index += 1) {
|
|
9
8
|
const key = keys[index];
|
|
10
9
|
const dots = key.split(".");
|
|
11
10
|
if (grouped[dots.length] == null) {
|
|
@@ -20,13 +19,17 @@ function unsmush(value) {
|
|
|
20
19
|
const groups = getKeyGroups(value);
|
|
21
20
|
const { length } = groups;
|
|
22
21
|
const unsmushed = {};
|
|
23
|
-
for (let groupIndex = 1;groupIndex < length; groupIndex += 1) {
|
|
22
|
+
for (let groupIndex = 1; groupIndex < length; groupIndex += 1) {
|
|
24
23
|
const group = groups[groupIndex];
|
|
25
24
|
const groupLength = group.length;
|
|
26
|
-
for (let keyIndex = 0;keyIndex < groupLength; keyIndex += 1) {
|
|
25
|
+
for (let keyIndex = 0; keyIndex < groupLength; keyIndex += 1) {
|
|
27
26
|
const key = group[keyIndex];
|
|
28
27
|
const val = value[key];
|
|
29
|
-
setValue(
|
|
28
|
+
setValue(
|
|
29
|
+
unsmushed,
|
|
30
|
+
key,
|
|
31
|
+
isArrayOrPlainObject(val) ? Array.isArray(val) ? [...val] : { ...val } : val
|
|
32
|
+
);
|
|
30
33
|
}
|
|
31
34
|
}
|
|
32
35
|
return unsmushed;
|
package/package.json
CHANGED
|
@@ -8,14 +8,16 @@
|
|
|
8
8
|
},
|
|
9
9
|
"description": "Sweet little atomic goodies…",
|
|
10
10
|
"devDependencies": {
|
|
11
|
-
"@biomejs/biome": "^1.9
|
|
12
|
-
"@
|
|
13
|
-
"@
|
|
14
|
-
"
|
|
15
|
-
"
|
|
16
|
-
"
|
|
17
|
-
"sass": "^1.79
|
|
18
|
-
"typescript": "^5.6
|
|
11
|
+
"@biomejs/biome": "^1.9",
|
|
12
|
+
"@types/node": "^22.7",
|
|
13
|
+
"@vitest/coverage-istanbul": "^2.1",
|
|
14
|
+
"dts-bundle-generator": "^9.5",
|
|
15
|
+
"glob": "^11",
|
|
16
|
+
"happy-dom": "^15.7",
|
|
17
|
+
"sass": "^1.79",
|
|
18
|
+
"typescript": "^5.6",
|
|
19
|
+
"vite": "^5.4",
|
|
20
|
+
"vitest": "^2.1"
|
|
19
21
|
},
|
|
20
22
|
"exports": {
|
|
21
23
|
"./package.json": "./package.json",
|
|
@@ -23,33 +25,33 @@
|
|
|
23
25
|
"bun": "./src/js/index.ts",
|
|
24
26
|
"import": {
|
|
25
27
|
"types": "./types/index.d.ts",
|
|
26
|
-
"default": "./dist/js/index.
|
|
28
|
+
"default": "./dist/js/index.js"
|
|
27
29
|
},
|
|
28
30
|
"require": {
|
|
29
31
|
"types": "./types/index.d.cts",
|
|
30
|
-
"default": "./dist/js/index.
|
|
32
|
+
"default": "./dist/js/index.cjs"
|
|
31
33
|
}
|
|
32
34
|
},
|
|
33
35
|
"./array": {
|
|
34
36
|
"bun": "./src/js/array/index.ts",
|
|
35
37
|
"import": {
|
|
36
38
|
"types": "./types/array/index.d.ts",
|
|
37
|
-
"default": "./dist/js/array/index.
|
|
39
|
+
"default": "./dist/js/array/index.js"
|
|
38
40
|
},
|
|
39
41
|
"require": {
|
|
40
42
|
"types": "./types/array/index.d.cts",
|
|
41
|
-
"default": "./dist/js/array/index.
|
|
43
|
+
"default": "./dist/js/array/index.cjs"
|
|
42
44
|
}
|
|
43
45
|
},
|
|
44
46
|
"./colour": {
|
|
45
47
|
"bun": "./src/js/colour/index.ts",
|
|
46
48
|
"import": {
|
|
47
49
|
"types": "./types/colour/index.d.ts",
|
|
48
|
-
"default": "./dist/js/colour/index.
|
|
50
|
+
"default": "./dist/js/colour/index.js"
|
|
49
51
|
},
|
|
50
52
|
"require": {
|
|
51
53
|
"types": "./types/colour/index.d.cts",
|
|
52
|
-
"default": "./dist/js/colour/index.
|
|
54
|
+
"default": "./dist/js/colour/index.cjs"
|
|
53
55
|
}
|
|
54
56
|
},
|
|
55
57
|
"./css/a11y": {
|
|
@@ -68,55 +70,55 @@
|
|
|
68
70
|
"bun": "./src/js/emitter.ts",
|
|
69
71
|
"import": {
|
|
70
72
|
"types": "./types/emitter.d.ts",
|
|
71
|
-
"default": "./dist/js/emitter.
|
|
73
|
+
"default": "./dist/js/emitter.js"
|
|
72
74
|
},
|
|
73
75
|
"require": {
|
|
74
76
|
"types": "./types/emitter.d.cts",
|
|
75
|
-
"default": "./dist/js/emitter.
|
|
77
|
+
"default": "./dist/js/emitter.cjs"
|
|
76
78
|
}
|
|
77
79
|
},
|
|
78
80
|
"./function": {
|
|
79
81
|
"bun": "./src/js/function.ts",
|
|
80
82
|
"import": {
|
|
81
83
|
"types": "./types/function.d.ts",
|
|
82
|
-
"default": "./dist/js/function.
|
|
84
|
+
"default": "./dist/js/function.js"
|
|
83
85
|
},
|
|
84
86
|
"require": {
|
|
85
87
|
"types": "./types/function.d.cts",
|
|
86
|
-
"default": "./dist/js/function.
|
|
88
|
+
"default": "./dist/js/function.cjs"
|
|
87
89
|
}
|
|
88
90
|
},
|
|
89
91
|
"./is": {
|
|
90
92
|
"bun": "./src/js/is.ts",
|
|
91
93
|
"import": {
|
|
92
94
|
"types": "./types/is.d.ts",
|
|
93
|
-
"default": "./dist/js/is.
|
|
95
|
+
"default": "./dist/js/is.js"
|
|
94
96
|
},
|
|
95
97
|
"require": {
|
|
96
98
|
"types": "./types/is.d.cts",
|
|
97
|
-
"default": "./dist/js/is.
|
|
99
|
+
"default": "./dist/js/is.cjs"
|
|
98
100
|
}
|
|
99
101
|
},
|
|
100
102
|
"./logger": {
|
|
101
103
|
"bun": "./src/js/logger.ts",
|
|
102
104
|
"import": {
|
|
103
105
|
"types": "./types/logger.d.ts",
|
|
104
|
-
"default": "./dist/js/logger.
|
|
106
|
+
"default": "./dist/js/logger.js"
|
|
105
107
|
},
|
|
106
108
|
"require": {
|
|
107
109
|
"types": "./types/logger.d.cts",
|
|
108
|
-
"default": "./dist/js/logger.
|
|
110
|
+
"default": "./dist/js/logger.cjs"
|
|
109
111
|
}
|
|
110
112
|
},
|
|
111
113
|
"./math": {
|
|
112
114
|
"bun": "./src/js/math.ts",
|
|
113
115
|
"import": {
|
|
114
116
|
"types": "./types/math.d.ts",
|
|
115
|
-
"default": "./dist/js/math.
|
|
117
|
+
"default": "./dist/js/math.js"
|
|
116
118
|
},
|
|
117
119
|
"require": {
|
|
118
120
|
"types": "./types/math.d.cts",
|
|
119
|
-
"default": "./dist/js/math.
|
|
121
|
+
"default": "./dist/js/math.cjs"
|
|
120
122
|
}
|
|
121
123
|
},
|
|
122
124
|
"./models": {
|
|
@@ -132,100 +134,101 @@
|
|
|
132
134
|
"bun": "./src/js/number.ts",
|
|
133
135
|
"import": {
|
|
134
136
|
"types": "./types/number.d.ts",
|
|
135
|
-
"default": "./dist/js/number.
|
|
137
|
+
"default": "./dist/js/number.js"
|
|
136
138
|
},
|
|
137
139
|
"require": {
|
|
138
140
|
"types": "./types/number.d.cts",
|
|
139
|
-
"default": "./dist/js/number.
|
|
141
|
+
"default": "./dist/js/number.cjs"
|
|
140
142
|
}
|
|
141
143
|
},
|
|
142
144
|
"./query": {
|
|
143
145
|
"bun": "./src/js/query.ts",
|
|
144
146
|
"import": {
|
|
145
147
|
"types": "./types/query.d.ts",
|
|
146
|
-
"default": "./dist/js/query.
|
|
148
|
+
"default": "./dist/js/query.js"
|
|
147
149
|
},
|
|
148
150
|
"require": {
|
|
149
151
|
"types": "./types/query.d.cts",
|
|
150
|
-
"default": "./dist/js/query.
|
|
152
|
+
"default": "./dist/js/query.cjs"
|
|
151
153
|
}
|
|
152
154
|
},
|
|
153
155
|
"./queue": {
|
|
154
156
|
"bun": "./src/js/queue.ts",
|
|
155
157
|
"import": {
|
|
156
158
|
"types": "./types/queue.d.ts",
|
|
157
|
-
"default": "./dist/js/queue.
|
|
159
|
+
"default": "./dist/js/queue.js"
|
|
158
160
|
},
|
|
159
161
|
"require": {
|
|
160
162
|
"types": "./types/queue.d.cts",
|
|
161
|
-
"default": "./dist/js/queue.
|
|
163
|
+
"default": "./dist/js/queue.cjs"
|
|
162
164
|
}
|
|
163
165
|
},
|
|
164
166
|
"./random": {
|
|
165
167
|
"bun": "./src/js/random.ts",
|
|
166
168
|
"import": {
|
|
167
169
|
"types": "./types/random.d.ts",
|
|
168
|
-
"default": "./dist/js/random.
|
|
170
|
+
"default": "./dist/js/random.js"
|
|
169
171
|
},
|
|
170
172
|
"require": {
|
|
171
173
|
"types": "./types/random.d.cts",
|
|
172
|
-
"default": "./dist/js/random.
|
|
174
|
+
"default": "./dist/js/random.cjs"
|
|
173
175
|
}
|
|
174
176
|
},
|
|
175
177
|
"./string": {
|
|
176
178
|
"bun": "./src/js/string/index.ts",
|
|
177
179
|
"import": {
|
|
178
180
|
"types": "./types/string/index.d.ts",
|
|
179
|
-
"default": "./dist/js/string/index.
|
|
181
|
+
"default": "./dist/js/string/index.js"
|
|
180
182
|
},
|
|
181
183
|
"require": {
|
|
182
184
|
"types": "./types/string/index.d.cts",
|
|
183
|
-
"default": "./dist/js/string/index.
|
|
185
|
+
"default": "./dist/js/string/index.cjs"
|
|
184
186
|
}
|
|
185
187
|
},
|
|
186
188
|
"./supports-touch": {
|
|
187
189
|
"bun": "./src/js/touch.ts",
|
|
188
190
|
"import": {
|
|
189
191
|
"types": "./types/touch.d.ts",
|
|
190
|
-
"default": "./dist/js/touch.
|
|
192
|
+
"default": "./dist/js/touch.js"
|
|
191
193
|
},
|
|
192
194
|
"require": {
|
|
193
195
|
"types": "./types/touch.d.cts",
|
|
194
|
-
"default": "./dist/js/touch.
|
|
196
|
+
"default": "./dist/js/touch.cjs"
|
|
195
197
|
}
|
|
196
198
|
},
|
|
197
199
|
"./value": {
|
|
198
200
|
"bun": "./src/js/value/index.ts",
|
|
199
201
|
"import": {
|
|
200
202
|
"types": "./types/value/index.d.ts",
|
|
201
|
-
"default": "./dist/js/value/index.
|
|
203
|
+
"default": "./dist/js/value/index.js"
|
|
202
204
|
},
|
|
203
205
|
"require": {
|
|
204
206
|
"types": "./types/value/index.d.cts",
|
|
205
|
-
"default": "./dist/js/value/index.
|
|
207
|
+
"default": "./dist/js/value/index.cjs"
|
|
206
208
|
}
|
|
207
209
|
}
|
|
208
210
|
},
|
|
209
211
|
"files": ["dist", "src", "types"],
|
|
210
212
|
"keywords": ["helper", "utility"],
|
|
211
213
|
"license": "MIT",
|
|
212
|
-
"main": "./dist/js/index.
|
|
213
|
-
"module": "./dist/js/index.
|
|
214
|
+
"main": "./dist/js/index.cjs",
|
|
215
|
+
"module": "./dist/js/index.js",
|
|
214
216
|
"name": "@oscarpalmer/atoms",
|
|
215
217
|
"repository": {
|
|
216
218
|
"type": "git",
|
|
217
219
|
"url": "git+https://github.com/oscarpalmer/atoms.git"
|
|
218
220
|
},
|
|
219
221
|
"scripts": {
|
|
220
|
-
"build": "
|
|
221
|
-
"build:css": "
|
|
222
|
-
"build:js": "
|
|
222
|
+
"build": "npm run clean && npm run build:css && npm run build:js",
|
|
223
|
+
"build:css": "npx sass ./src/css:./dist/css --no-source-map",
|
|
224
|
+
"build:js": "npx vite build && npm run types",
|
|
223
225
|
"clean": "rm -rf ./dist && rm -rf ./types && rm -f ./tsconfig.tsbuildinfo",
|
|
224
|
-
"test": "
|
|
225
|
-
"
|
|
226
|
-
"watch:
|
|
226
|
+
"test": "npx vitest --coverage",
|
|
227
|
+
"types": "npx tsc && npx dts-bundle-generator --config ./dts.config.ts --silent",
|
|
228
|
+
"watch:css": "npx sass ./src/css:./dist/css --no-source-map --watch",
|
|
229
|
+
"watch:js": "npx vite build --watch"
|
|
227
230
|
},
|
|
228
231
|
"type": "module",
|
|
229
232
|
"types": "./types/index.d.cts",
|
|
230
|
-
"version": "0.
|
|
233
|
+
"version": "0.76.0"
|
|
231
234
|
}
|
package/src/js/array/chunk.ts
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
|
+
import {clamp} from '~/number';
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
|
-
*
|
|
4
|
+
* Chunk an array _(into smaller arrays of a specified size)_
|
|
3
5
|
*/
|
|
4
|
-
export function chunk<
|
|
6
|
+
export function chunk<Item>(array: Item[], size?: number): Item[][] {
|
|
7
|
+
const chunkSize = clamp(size ?? 64_000, 1, 64_000);
|
|
5
8
|
const {length} = array;
|
|
6
9
|
|
|
7
|
-
const chunkSize = typeof size === 'number' && size > 0 ? size : 64_000;
|
|
8
|
-
|
|
9
10
|
if (length <= chunkSize) {
|
|
10
11
|
return [array];
|
|
11
12
|
}
|
|
12
13
|
|
|
13
|
-
const chunks:
|
|
14
|
+
const chunks: Item[][] = [];
|
|
14
15
|
|
|
15
16
|
let remaining = Number(length);
|
|
16
17
|
|
package/src/js/array/compact.ts
CHANGED
|
@@ -1,19 +1,17 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Compact an array _(removing all `null` and `undefined` values)_
|
|
3
3
|
*/
|
|
4
|
-
export function compact<
|
|
5
|
-
array: Value[],
|
|
6
|
-
strict: true,
|
|
7
|
-
): Exclude<Value, 0 | '' | false | null | undefined>[];
|
|
4
|
+
export function compact<Item>(array: Item[]): Exclude<Item, null | undefined>[];
|
|
8
5
|
|
|
9
6
|
/**
|
|
10
|
-
*
|
|
7
|
+
* Compact an array _(removing all falsey values)_
|
|
11
8
|
*/
|
|
12
|
-
export function compact<
|
|
13
|
-
array:
|
|
14
|
-
|
|
9
|
+
export function compact<Item>(
|
|
10
|
+
array: Item[],
|
|
11
|
+
strict: true,
|
|
12
|
+
): Exclude<Item, 0 | '' | false | null | undefined>[];
|
|
15
13
|
|
|
16
|
-
export function compact<
|
|
14
|
+
export function compact<Item>(array: Item[], strict?: boolean): Item[] {
|
|
17
15
|
return strict === true
|
|
18
16
|
? array.filter(item => !!item)
|
|
19
17
|
: array.filter(item => item != null);
|
package/src/js/array/count.ts
CHANGED
|
@@ -1,29 +1,49 @@
|
|
|
1
|
-
import {findValues} from '
|
|
2
|
-
import type {
|
|
3
|
-
import type {BooleanCallback, KeyCallback} from './models';
|
|
1
|
+
import {findValues} from '~/internal/array/find';
|
|
2
|
+
import type {BooleanCallback, KeyCallback} from '~/array/models';
|
|
4
3
|
|
|
5
4
|
/**
|
|
6
|
-
*
|
|
5
|
+
* Get the number of items _(count)_ that match the given value
|
|
7
6
|
*/
|
|
8
|
-
export function count<
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
export function count<Item>(array: Item[], value: Item): number;
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Get the number of items _(count)_ that match the given value
|
|
11
|
+
*/
|
|
12
|
+
export function count<Item>(
|
|
13
|
+
array: Item[],
|
|
14
|
+
matches: BooleanCallback<Item>,
|
|
15
|
+
): number;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Get the number of items _(count)_ that match the given value
|
|
19
|
+
*/
|
|
20
|
+
export function count<Item, Key extends keyof Item>(
|
|
21
|
+
array: Item[],
|
|
22
|
+
key: Key,
|
|
23
|
+
value: Item[Key],
|
|
11
24
|
): number;
|
|
12
25
|
|
|
13
26
|
/**
|
|
14
|
-
*
|
|
15
|
-
* - Use `key` to find a comparison value to match with `value`
|
|
27
|
+
* Get the number of items _(count)_ that match the given value
|
|
16
28
|
*/
|
|
17
|
-
export function count<
|
|
18
|
-
array:
|
|
19
|
-
|
|
20
|
-
|
|
29
|
+
export function count<Item, Key extends KeyCallback<Item>>(
|
|
30
|
+
array: Item[],
|
|
31
|
+
key: Key,
|
|
32
|
+
value: ReturnType<Key>,
|
|
21
33
|
): number;
|
|
22
34
|
|
|
23
|
-
export function count
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
35
|
+
export function count(array: unknown[], ...parameters: unknown[]): number {
|
|
36
|
+
const {length} = parameters;
|
|
37
|
+
|
|
38
|
+
return findValues(
|
|
39
|
+
'all',
|
|
40
|
+
array,
|
|
41
|
+
length === 1 && typeof parameters[0] === 'function'
|
|
42
|
+
? parameters[0]
|
|
43
|
+
: undefined,
|
|
44
|
+
length === 2 ? parameters[0] : undefined,
|
|
45
|
+
length === 1 && typeof parameters[0] !== 'function'
|
|
46
|
+
? parameters[0]
|
|
47
|
+
: parameters[1],
|
|
48
|
+
).length;
|
|
29
49
|
}
|
package/src/js/array/exists.ts
CHANGED
|
@@ -1,29 +1,53 @@
|
|
|
1
|
-
import {findValue} from '
|
|
2
|
-
import type {Key} from '../models';
|
|
1
|
+
import {findValue} from '~/internal/array/find';
|
|
3
2
|
import type {BooleanCallback, KeyCallback} from './models';
|
|
4
3
|
|
|
5
4
|
/**
|
|
6
5
|
* Does the value exist in array?
|
|
7
6
|
*/
|
|
8
|
-
export function exists<
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
export function exists<Item>(array: Item[], value: Item): boolean;
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Does the value exist in array?
|
|
11
|
+
*/
|
|
12
|
+
export function exists<Item>(
|
|
13
|
+
array: Item[],
|
|
14
|
+
matches: BooleanCallback<Item>,
|
|
11
15
|
): boolean;
|
|
12
16
|
|
|
13
17
|
/**
|
|
14
18
|
* - Does the value exist in array?
|
|
15
19
|
* - Use `key` to find a comparison value to match with `value`
|
|
16
20
|
*/
|
|
17
|
-
export function exists<
|
|
18
|
-
array:
|
|
19
|
-
|
|
20
|
-
|
|
21
|
+
export function exists<Item, Key extends keyof Item>(
|
|
22
|
+
array: Item[],
|
|
23
|
+
key: Key,
|
|
24
|
+
value: Item[Key],
|
|
21
25
|
): boolean;
|
|
22
26
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
27
|
+
/**
|
|
28
|
+
* - Does the value exist in array?
|
|
29
|
+
* - Use `key` to find a comparison value to match with `value`
|
|
30
|
+
*/
|
|
31
|
+
export function exists<Item, Key extends KeyCallback<Item>>(
|
|
32
|
+
array: Item[],
|
|
33
|
+
key: Key,
|
|
34
|
+
value: ReturnType<Key>,
|
|
35
|
+
): boolean;
|
|
36
|
+
|
|
37
|
+
export function exists(array: unknown[], ...parameters: unknown[]): boolean {
|
|
38
|
+
const {length} = parameters;
|
|
39
|
+
|
|
40
|
+
return (
|
|
41
|
+
(findValue(
|
|
42
|
+
'index',
|
|
43
|
+
array,
|
|
44
|
+
length === 1 && typeof parameters[0] === 'function'
|
|
45
|
+
? parameters[0]
|
|
46
|
+
: undefined,
|
|
47
|
+
length === 2 ? parameters[0] : undefined,
|
|
48
|
+
length === 1 && typeof parameters[0] !== 'function'
|
|
49
|
+
? parameters[0]
|
|
50
|
+
: parameters[1],
|
|
51
|
+
) as number) > -1
|
|
52
|
+
);
|
|
29
53
|
}
|
package/src/js/array/filter.ts
CHANGED
|
@@ -1,29 +1,51 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
import type {BooleanCallback, KeyCallback} from './models';
|
|
1
|
+
import type {BooleanCallback, KeyCallback} from '~/array/models';
|
|
2
|
+
import {findValues} from '~/internal/array/find';
|
|
4
3
|
|
|
5
4
|
/**
|
|
6
|
-
*
|
|
5
|
+
* Get a filtered array of items matching `value`
|
|
7
6
|
*/
|
|
8
|
-
export function filter<
|
|
9
|
-
array: Model[],
|
|
10
|
-
value: Value | BooleanCallback<Model>,
|
|
11
|
-
): Model[];
|
|
7
|
+
export function filter<Item>(array: Item[], value: Item): Item[];
|
|
12
8
|
|
|
13
9
|
/**
|
|
14
|
-
*
|
|
10
|
+
* Get a filtered array of items matching `value`
|
|
11
|
+
*/
|
|
12
|
+
export function filter<Item>(
|
|
13
|
+
array: Item[],
|
|
14
|
+
matches: BooleanCallback<Item>,
|
|
15
|
+
): Item[];
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* - Get a filtered array of items
|
|
19
|
+
* - Use `key` to find a comparison value to match with `value`
|
|
20
|
+
*/
|
|
21
|
+
export function filter<Item, Key extends keyof Item>(
|
|
22
|
+
array: Item[],
|
|
23
|
+
key: Key,
|
|
24
|
+
value: Item[Key],
|
|
25
|
+
): Item[];
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* - Get a filtered array of items
|
|
15
29
|
* - Use `key` to find a comparison value to match with `value`
|
|
16
30
|
*/
|
|
17
|
-
export function filter<
|
|
18
|
-
array:
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
):
|
|
31
|
+
export function filter<Item, Key extends KeyCallback<Item>>(
|
|
32
|
+
array: Item[],
|
|
33
|
+
key: Key,
|
|
34
|
+
value: ReturnType<Key>,
|
|
35
|
+
): Item[];
|
|
36
|
+
|
|
37
|
+
export function filter(array: unknown[], ...parameters: unknown[]): unknown[] {
|
|
38
|
+
const {length} = parameters;
|
|
22
39
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
40
|
+
return findValues(
|
|
41
|
+
'all',
|
|
42
|
+
array,
|
|
43
|
+
length === 1 && typeof parameters[0] === 'function'
|
|
44
|
+
? parameters[0]
|
|
45
|
+
: undefined,
|
|
46
|
+
length === 2 ? parameters[0] : undefined,
|
|
47
|
+
length === 1 && typeof parameters[0] !== 'function'
|
|
48
|
+
? parameters[0]
|
|
49
|
+
: parameters[1],
|
|
50
|
+
);
|
|
29
51
|
}
|