@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
|
@@ -1,18 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const is = require("./is.cjs");
|
|
4
|
+
const string_index = require("./string/index.cjs");
|
|
5
|
+
const value_set = require("./value/set.cjs");
|
|
5
6
|
function fromQuery(query) {
|
|
6
7
|
const parts = query.split("&");
|
|
7
8
|
const { length } = parts;
|
|
8
9
|
const parameters = {};
|
|
9
|
-
for (let index = 0;index < length; index += 1) {
|
|
10
|
+
for (let index = 0; index < length; index += 1) {
|
|
10
11
|
const [key, value] = parts[index].split("=").map(decodeURIComponent);
|
|
11
|
-
if (isNullableOrWhitespace(key)) {
|
|
12
|
-
continue;
|
|
13
|
-
}
|
|
14
12
|
if (key.includes(".")) {
|
|
15
|
-
setValue(parameters, key, getValue(value));
|
|
13
|
+
value_set.setValue(parameters, key, getValue(value));
|
|
16
14
|
} else {
|
|
17
15
|
if (key in parameters) {
|
|
18
16
|
if (!Array.isArray(parameters[key])) {
|
|
@@ -30,15 +28,19 @@ function getParts(value, fromArray, prefix) {
|
|
|
30
28
|
const keys = Object.keys(value);
|
|
31
29
|
const { length } = keys;
|
|
32
30
|
const parts = [];
|
|
33
|
-
for (let index = 0;index < length; index += 1) {
|
|
31
|
+
for (let index = 0; index < length; index += 1) {
|
|
34
32
|
const key = keys[index];
|
|
35
33
|
const val = value[key];
|
|
36
34
|
if (Array.isArray(val)) {
|
|
37
|
-
parts.push(
|
|
38
|
-
|
|
39
|
-
|
|
35
|
+
parts.push(
|
|
36
|
+
...getParts(val, true, string_index.join([prefix, fromArray ? null : key], "."))
|
|
37
|
+
);
|
|
38
|
+
} else if (is.isPlainObject(val)) {
|
|
39
|
+
parts.push(...getParts(val, false, string_index.join([prefix, key], ".")));
|
|
40
40
|
} else if (isDecodable(val)) {
|
|
41
|
-
parts.push(
|
|
41
|
+
parts.push(
|
|
42
|
+
`${encodeURIComponent(string_index.join([prefix, fromArray ? null : key], "."))}=${encodeURIComponent(val)}`
|
|
43
|
+
);
|
|
42
44
|
}
|
|
43
45
|
}
|
|
44
46
|
return parts;
|
|
@@ -59,7 +61,5 @@ function isDecodable(value) {
|
|
|
59
61
|
function toQuery(parameters) {
|
|
60
62
|
return getParts(parameters, false).filter((part) => part.length > 0).join("&");
|
|
61
63
|
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
fromQuery
|
|
65
|
-
};
|
|
64
|
+
exports.fromQuery = fromQuery;
|
|
65
|
+
exports.toQuery = toQuery;
|
package/dist/js/query.js
CHANGED
|
@@ -1,95 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
}
|
|
5
|
-
// src/js/string/index.ts
|
|
6
|
-
function getString(value) {
|
|
7
|
-
if (typeof value === "string") {
|
|
8
|
-
return value;
|
|
9
|
-
}
|
|
10
|
-
if (typeof value !== "object" || value == null) {
|
|
11
|
-
return String(value);
|
|
12
|
-
}
|
|
13
|
-
const valueOff = value.valueOf?.() ?? value;
|
|
14
|
-
const asString = valueOff?.toString?.() ?? String(valueOff);
|
|
15
|
-
return asString.startsWith("[object ") ? JSON.stringify(value) : asString;
|
|
16
|
-
}
|
|
17
|
-
function join(value, delimiter) {
|
|
18
|
-
return compact(value).map(getString).filter((value2) => value2.trim().length > 0).join(typeof delimiter === "string" ? delimiter : "");
|
|
19
|
-
}
|
|
20
|
-
// src/js/internal/value-handle.ts
|
|
21
|
-
function findKey(needle, haystack, ignoreCase) {
|
|
22
|
-
if (!ignoreCase) {
|
|
23
|
-
return needle;
|
|
24
|
-
}
|
|
25
|
-
const keys = Object.keys(haystack);
|
|
26
|
-
const normalised = keys.map((key) => key.toLowerCase());
|
|
27
|
-
const index = normalised.indexOf(needle.toLowerCase());
|
|
28
|
-
return index > -1 ? keys[index] : needle;
|
|
29
|
-
}
|
|
30
|
-
function handleValue(data, path, value, get, ignoreCase) {
|
|
31
|
-
if (typeof data === "object" && data !== null && !/^(__proto__|constructor|prototype)$/i.test(path)) {
|
|
32
|
-
const key = findKey(path, data, ignoreCase);
|
|
33
|
-
if (get) {
|
|
34
|
-
return data[key];
|
|
35
|
-
}
|
|
36
|
-
data[key] = value;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
// src/js/value/set.ts
|
|
40
|
-
function setValue(data, path, value, ignoreCase) {
|
|
41
|
-
const shouldIgnoreCase = ignoreCase === true;
|
|
42
|
-
const parts = (shouldIgnoreCase ? path.toLowerCase() : path).split(".");
|
|
43
|
-
const { length } = parts;
|
|
44
|
-
const lastIndex = length - 1;
|
|
45
|
-
let target = typeof data === "object" && data !== null ? data : {};
|
|
46
|
-
for (let index = 0;index < length; index += 1) {
|
|
47
|
-
const part = parts[index];
|
|
48
|
-
if (index === lastIndex) {
|
|
49
|
-
handleValue(target, part, value, false, shouldIgnoreCase);
|
|
50
|
-
break;
|
|
51
|
-
}
|
|
52
|
-
let next = handleValue(target, part, null, true, shouldIgnoreCase);
|
|
53
|
-
if (typeof next !== "object" || next === null) {
|
|
54
|
-
next = {};
|
|
55
|
-
target[part] = next;
|
|
56
|
-
}
|
|
57
|
-
target = next;
|
|
58
|
-
}
|
|
59
|
-
return data;
|
|
60
|
-
}
|
|
61
|
-
// src/js/is.ts
|
|
62
|
-
function isNullableOrWhitespace(value) {
|
|
63
|
-
return value == null || /^\s*$/.test(getString(value));
|
|
64
|
-
}
|
|
65
|
-
function isPlainObject(value) {
|
|
66
|
-
if (typeof value !== "object" || value === null) {
|
|
67
|
-
return false;
|
|
68
|
-
}
|
|
69
|
-
const prototype = Object.getPrototypeOf(value);
|
|
70
|
-
return (prototype === null || prototype === Object.prototype || Object.getPrototypeOf(prototype) === null) && !(Symbol.toStringTag in value) && !(Symbol.iterator in value);
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
// src/js/query.ts
|
|
1
|
+
import { isPlainObject } from "./is.js";
|
|
2
|
+
import { join } from "./string/index.js";
|
|
3
|
+
import { setValue } from "./value/set.js";
|
|
74
4
|
function fromQuery(query) {
|
|
75
5
|
const parts = query.split("&");
|
|
76
6
|
const { length } = parts;
|
|
77
7
|
const parameters = {};
|
|
78
|
-
for (let index = 0;index < length; index += 1) {
|
|
8
|
+
for (let index = 0; index < length; index += 1) {
|
|
79
9
|
const [key, value] = parts[index].split("=").map(decodeURIComponent);
|
|
80
|
-
if (isNullableOrWhitespace(key)) {
|
|
81
|
-
continue;
|
|
82
|
-
}
|
|
83
10
|
if (key.includes(".")) {
|
|
84
|
-
setValue(parameters, key,
|
|
11
|
+
setValue(parameters, key, getValue(value));
|
|
85
12
|
} else {
|
|
86
13
|
if (key in parameters) {
|
|
87
14
|
if (!Array.isArray(parameters[key])) {
|
|
88
15
|
parameters[key] = [parameters[key]];
|
|
89
16
|
}
|
|
90
|
-
parameters[key].push(
|
|
17
|
+
parameters[key].push(getValue(value));
|
|
91
18
|
} else {
|
|
92
|
-
parameters[key] =
|
|
19
|
+
parameters[key] = getValue(value);
|
|
93
20
|
}
|
|
94
21
|
}
|
|
95
22
|
}
|
|
@@ -99,20 +26,24 @@ function getParts(value, fromArray, prefix) {
|
|
|
99
26
|
const keys = Object.keys(value);
|
|
100
27
|
const { length } = keys;
|
|
101
28
|
const parts = [];
|
|
102
|
-
for (let index = 0;index < length; index += 1) {
|
|
29
|
+
for (let index = 0; index < length; index += 1) {
|
|
103
30
|
const key = keys[index];
|
|
104
31
|
const val = value[key];
|
|
105
32
|
if (Array.isArray(val)) {
|
|
106
|
-
parts.push(
|
|
33
|
+
parts.push(
|
|
34
|
+
...getParts(val, true, join([prefix, fromArray ? null : key], "."))
|
|
35
|
+
);
|
|
107
36
|
} else if (isPlainObject(val)) {
|
|
108
37
|
parts.push(...getParts(val, false, join([prefix, key], ".")));
|
|
109
38
|
} else if (isDecodable(val)) {
|
|
110
|
-
parts.push(
|
|
39
|
+
parts.push(
|
|
40
|
+
`${encodeURIComponent(join([prefix, fromArray ? null : key], "."))}=${encodeURIComponent(val)}`
|
|
41
|
+
);
|
|
111
42
|
}
|
|
112
43
|
}
|
|
113
44
|
return parts;
|
|
114
45
|
}
|
|
115
|
-
function
|
|
46
|
+
function getValue(value) {
|
|
116
47
|
if (/^(false|true)$/.test(value)) {
|
|
117
48
|
return value === "true";
|
|
118
49
|
}
|
|
@@ -129,6 +60,6 @@ function toQuery(parameters) {
|
|
|
129
60
|
return getParts(parameters, false).filter((part) => part.length > 0).join("&");
|
|
130
61
|
}
|
|
131
62
|
export {
|
|
132
|
-
|
|
133
|
-
|
|
63
|
+
fromQuery,
|
|
64
|
+
toQuery
|
|
134
65
|
};
|
|
@@ -1,4 +1,13 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
if (globalThis._atomic_queued == null) {
|
|
4
|
+
const queued = /* @__PURE__ */ new Set();
|
|
5
|
+
Object.defineProperty(globalThis, "_atomic_queued", {
|
|
6
|
+
get() {
|
|
7
|
+
return queued;
|
|
8
|
+
}
|
|
9
|
+
});
|
|
10
|
+
}
|
|
2
11
|
function queue(callback) {
|
|
3
12
|
_atomic_queued.add(callback);
|
|
4
13
|
if (_atomic_queued.size > 0) {
|
|
@@ -6,20 +15,10 @@ function queue(callback) {
|
|
|
6
15
|
const callbacks = [..._atomic_queued];
|
|
7
16
|
const { length } = callbacks;
|
|
8
17
|
_atomic_queued.clear();
|
|
9
|
-
for (let index = 0;index < length; index += 1) {
|
|
18
|
+
for (let index = 0; index < length; index += 1) {
|
|
10
19
|
callbacks[index]();
|
|
11
20
|
}
|
|
12
21
|
});
|
|
13
22
|
}
|
|
14
23
|
}
|
|
15
|
-
|
|
16
|
-
const queued = new Set;
|
|
17
|
-
Object.defineProperty(globalThis, "_atomic_queued", {
|
|
18
|
-
get() {
|
|
19
|
-
return queued;
|
|
20
|
-
}
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
|
-
export {
|
|
24
|
-
queue
|
|
25
|
-
};
|
|
24
|
+
exports.queue = queue;
|
package/dist/js/queue.js
CHANGED
|
@@ -1,4 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
if (globalThis._atomic_queued == null) {
|
|
2
|
+
const queued = /* @__PURE__ */ new Set();
|
|
3
|
+
Object.defineProperty(globalThis, "_atomic_queued", {
|
|
4
|
+
get() {
|
|
5
|
+
return queued;
|
|
6
|
+
}
|
|
7
|
+
});
|
|
8
|
+
}
|
|
2
9
|
function queue(callback) {
|
|
3
10
|
_atomic_queued.add(callback);
|
|
4
11
|
if (_atomic_queued.size > 0) {
|
|
@@ -6,20 +13,12 @@ function queue(callback) {
|
|
|
6
13
|
const callbacks = [..._atomic_queued];
|
|
7
14
|
const { length } = callbacks;
|
|
8
15
|
_atomic_queued.clear();
|
|
9
|
-
for (let index = 0;index < length; index += 1) {
|
|
16
|
+
for (let index = 0; index < length; index += 1) {
|
|
10
17
|
callbacks[index]();
|
|
11
18
|
}
|
|
12
19
|
});
|
|
13
20
|
}
|
|
14
21
|
}
|
|
15
|
-
if (globalThis._atomic_queued == null) {
|
|
16
|
-
const queued = new Set;
|
|
17
|
-
Object.defineProperty(globalThis, "_atomic_queued", {
|
|
18
|
-
get() {
|
|
19
|
-
return queued;
|
|
20
|
-
}
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
22
|
export {
|
|
24
23
|
queue
|
|
25
24
|
};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const array_shuffle = require("./array/shuffle.cjs");
|
|
3
4
|
function getRandomBoolean() {
|
|
4
5
|
return Math.random() > 0.5;
|
|
5
6
|
}
|
|
@@ -9,7 +10,7 @@ function getRandomCharacters(length, selection) {
|
|
|
9
10
|
}
|
|
10
11
|
const actual = typeof selection === "string" && selection.length > 0 ? selection : "abcdefghijklmnopqrstuvwxyz";
|
|
11
12
|
let characters = "";
|
|
12
|
-
for (let index = 0;index < length; index += 1) {
|
|
13
|
+
for (let index = 0; index < length; index += 1) {
|
|
13
14
|
characters += actual.charAt(getRandomInteger(0, actual.length));
|
|
14
15
|
}
|
|
15
16
|
return characters;
|
|
@@ -17,11 +18,6 @@ function getRandomCharacters(length, selection) {
|
|
|
17
18
|
function getRandomColour() {
|
|
18
19
|
return `#${Array.from({ length: 6 }, getRandomHex).join("")}`;
|
|
19
20
|
}
|
|
20
|
-
function getRandomDate(earliest, latest) {
|
|
21
|
-
const earliestTime = earliest?.getTime() ?? -8640000000000000;
|
|
22
|
-
const latestTime = latest?.getTime() ?? 8640000000000000;
|
|
23
|
-
return new Date(getRandomInteger(earliestTime, latestTime));
|
|
24
|
-
}
|
|
25
21
|
function getRandomFloat(min, max) {
|
|
26
22
|
const minimum = min ?? Number.MIN_SAFE_INTEGER;
|
|
27
23
|
return Math.random() * ((max ?? Number.MAX_SAFE_INTEGER) - minimum) + minimum;
|
|
@@ -39,16 +35,13 @@ function getRandomItems(array, amount) {
|
|
|
39
35
|
if (amount === 1) {
|
|
40
36
|
return array.length === 0 ? [] : [array[getRandomInteger(0, array.length)]];
|
|
41
37
|
}
|
|
42
|
-
return amount == null || amount >= array.length ? shuffle(array) : shuffle(array).slice(0, amount);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
getRandomCharacters,
|
|
53
|
-
getRandomBoolean
|
|
54
|
-
};
|
|
38
|
+
return amount == null || amount >= array.length ? array_shuffle.shuffle(array) : array_shuffle.shuffle(array).slice(0, amount);
|
|
39
|
+
}
|
|
40
|
+
exports.getRandomBoolean = getRandomBoolean;
|
|
41
|
+
exports.getRandomCharacters = getRandomCharacters;
|
|
42
|
+
exports.getRandomColour = getRandomColour;
|
|
43
|
+
exports.getRandomFloat = getRandomFloat;
|
|
44
|
+
exports.getRandomHex = getRandomHex;
|
|
45
|
+
exports.getRandomInteger = getRandomInteger;
|
|
46
|
+
exports.getRandomItem = getRandomItem;
|
|
47
|
+
exports.getRandomItems = getRandomItems;
|
package/dist/js/random.js
CHANGED
|
@@ -1,15 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
function shuffle(array) {
|
|
3
|
-
const shuffled = array.slice();
|
|
4
|
-
const { length } = shuffled;
|
|
5
|
-
for (let index = 0;index < length; index += 1) {
|
|
6
|
-
const random = getRandomInteger(0, length);
|
|
7
|
-
[shuffled[index], shuffled[random]] = [shuffled[random], shuffled[index]];
|
|
8
|
-
}
|
|
9
|
-
return shuffled;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
// src/js/random.ts
|
|
1
|
+
import { shuffle } from "./array/shuffle.js";
|
|
13
2
|
function getRandomBoolean() {
|
|
14
3
|
return Math.random() > 0.5;
|
|
15
4
|
}
|
|
@@ -19,7 +8,7 @@ function getRandomCharacters(length, selection) {
|
|
|
19
8
|
}
|
|
20
9
|
const actual = typeof selection === "string" && selection.length > 0 ? selection : "abcdefghijklmnopqrstuvwxyz";
|
|
21
10
|
let characters = "";
|
|
22
|
-
for (let index = 0;index < length; index += 1) {
|
|
11
|
+
for (let index = 0; index < length; index += 1) {
|
|
23
12
|
characters += actual.charAt(getRandomInteger(0, actual.length));
|
|
24
13
|
}
|
|
25
14
|
return characters;
|
|
@@ -27,11 +16,6 @@ function getRandomCharacters(length, selection) {
|
|
|
27
16
|
function getRandomColour() {
|
|
28
17
|
return `#${Array.from({ length: 6 }, getRandomHex).join("")}`;
|
|
29
18
|
}
|
|
30
|
-
function getRandomDate(earliest, latest) {
|
|
31
|
-
const earliestTime = earliest?.getTime() ?? -8640000000000000;
|
|
32
|
-
const latestTime = latest?.getTime() ?? 8640000000000000;
|
|
33
|
-
return new Date(getRandomInteger(earliestTime, latestTime));
|
|
34
|
-
}
|
|
35
19
|
function getRandomFloat(min, max) {
|
|
36
20
|
const minimum = min ?? Number.MIN_SAFE_INTEGER;
|
|
37
21
|
return Math.random() * ((max ?? Number.MAX_SAFE_INTEGER) - minimum) + minimum;
|
|
@@ -52,13 +36,12 @@ function getRandomItems(array, amount) {
|
|
|
52
36
|
return amount == null || amount >= array.length ? shuffle(array) : shuffle(array).slice(0, amount);
|
|
53
37
|
}
|
|
54
38
|
export {
|
|
55
|
-
|
|
56
|
-
getRandomItem,
|
|
57
|
-
getRandomInteger,
|
|
58
|
-
getRandomHex,
|
|
59
|
-
getRandomFloat,
|
|
60
|
-
getRandomDate,
|
|
61
|
-
getRandomColour,
|
|
39
|
+
getRandomBoolean,
|
|
62
40
|
getRandomCharacters,
|
|
63
|
-
|
|
41
|
+
getRandomColour,
|
|
42
|
+
getRandomFloat,
|
|
43
|
+
getRandomHex,
|
|
44
|
+
getRandomInteger,
|
|
45
|
+
getRandomItem,
|
|
46
|
+
getRandomItems
|
|
64
47
|
};
|
|
@@ -1,36 +1,49 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
4
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
5
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
6
|
+
const number = require("./number.cjs");
|
|
8
7
|
class SizedMap extends Map {
|
|
9
|
-
maximumSize;
|
|
10
|
-
get full() {
|
|
11
|
-
return this.size >= this.maximumSize;
|
|
12
|
-
}
|
|
13
|
-
get maximum() {
|
|
14
|
-
return this.maximumSize;
|
|
15
|
-
}
|
|
16
8
|
constructor(entries, maximum) {
|
|
17
|
-
const maximumSize = getMaximum(
|
|
18
|
-
|
|
9
|
+
const maximumSize = getMaximum(
|
|
10
|
+
typeof entries === "number" ? entries : typeof maximum === "number" ? maximum : void 0
|
|
11
|
+
);
|
|
12
|
+
super(Array.isArray(entries) ? entries.slice(0, maximumSize) : void 0);
|
|
13
|
+
__publicField(this, "maximumSize");
|
|
19
14
|
this.maximumSize = maximumSize;
|
|
20
15
|
if (Array.isArray(entries) && entries.length > maximumSize) {
|
|
21
|
-
for (let index = 0;index < maximumSize; index += 1) {
|
|
16
|
+
for (let index = 0; index < maximumSize; index += 1) {
|
|
22
17
|
this.set(...entries[entries.length - maximumSize + index]);
|
|
23
18
|
}
|
|
24
19
|
}
|
|
25
20
|
}
|
|
21
|
+
/**
|
|
22
|
+
* Is the Map full?
|
|
23
|
+
*/
|
|
24
|
+
get full() {
|
|
25
|
+
return this.size >= this.maximumSize;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* The maximum size of the Map
|
|
29
|
+
*/
|
|
30
|
+
get maximum() {
|
|
31
|
+
return this.maximumSize;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* @inheritdoc
|
|
35
|
+
*/
|
|
26
36
|
get(key) {
|
|
27
37
|
const value = super.get(key);
|
|
28
|
-
if (value
|
|
38
|
+
if (value == null && !this.has(key)) {
|
|
29
39
|
return;
|
|
30
40
|
}
|
|
31
41
|
this.set(key, value);
|
|
32
42
|
return value;
|
|
33
43
|
}
|
|
44
|
+
/**
|
|
45
|
+
* @inheritdoc
|
|
46
|
+
*/
|
|
34
47
|
set(key, value) {
|
|
35
48
|
if (this.has(key)) {
|
|
36
49
|
this.delete(key);
|
|
@@ -40,25 +53,37 @@ class SizedMap extends Map {
|
|
|
40
53
|
return super.set(key, value);
|
|
41
54
|
}
|
|
42
55
|
}
|
|
43
|
-
|
|
44
56
|
class SizedSet extends Set {
|
|
45
|
-
maximumSize;
|
|
46
|
-
get full() {
|
|
47
|
-
return this.size >= this.maximumSize;
|
|
48
|
-
}
|
|
49
|
-
get maximum() {
|
|
50
|
-
return this.maximumSize;
|
|
51
|
-
}
|
|
52
57
|
constructor(values, maximum) {
|
|
53
|
-
const maximumSize = getMaximum(
|
|
54
|
-
|
|
58
|
+
const maximumSize = getMaximum(
|
|
59
|
+
typeof values === "number" ? values : typeof maximum === "number" ? maximum : void 0
|
|
60
|
+
);
|
|
61
|
+
super(
|
|
62
|
+
Array.isArray(values) && values.length <= maximumSize ? values : void 0
|
|
63
|
+
);
|
|
64
|
+
__publicField(this, "maximumSize");
|
|
55
65
|
this.maximumSize = maximumSize;
|
|
56
66
|
if (Array.isArray(values) && values.length > maximumSize) {
|
|
57
|
-
for (let index = 0;index < maximumSize; index += 1) {
|
|
67
|
+
for (let index = 0; index < maximumSize; index += 1) {
|
|
58
68
|
this.add(values[values.length - maximumSize + index]);
|
|
59
69
|
}
|
|
60
70
|
}
|
|
61
71
|
}
|
|
72
|
+
/**
|
|
73
|
+
* Is the Set full?
|
|
74
|
+
*/
|
|
75
|
+
get full() {
|
|
76
|
+
return this.size >= this.maximumSize;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* The maximum size of the Set
|
|
80
|
+
*/
|
|
81
|
+
get maximum() {
|
|
82
|
+
return this.maximumSize;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* @inheritdoc
|
|
86
|
+
*/
|
|
62
87
|
add(value) {
|
|
63
88
|
if (this.has(value)) {
|
|
64
89
|
this.delete(value);
|
|
@@ -67,6 +92,11 @@ class SizedSet extends Set {
|
|
|
67
92
|
}
|
|
68
93
|
return super.add(value);
|
|
69
94
|
}
|
|
95
|
+
/**
|
|
96
|
+
* Get a value from an index in the Set, if it exists
|
|
97
|
+
* - Negative indices are counted from the end
|
|
98
|
+
* - Optionally move the value to the end with `update`
|
|
99
|
+
*/
|
|
70
100
|
at(index, update) {
|
|
71
101
|
const value = [...this.values()][index < 0 ? this.size + index : index];
|
|
72
102
|
if ((update ?? false) && this.has(value)) {
|
|
@@ -75,6 +105,9 @@ class SizedSet extends Set {
|
|
|
75
105
|
}
|
|
76
106
|
return value;
|
|
77
107
|
}
|
|
108
|
+
/**
|
|
109
|
+
* Get a value from the Set, if it exists _(and move it to the end)_
|
|
110
|
+
*/
|
|
78
111
|
get(value, update) {
|
|
79
112
|
if (this.has(value)) {
|
|
80
113
|
if (update ?? false) {
|
|
@@ -85,7 +118,9 @@ class SizedSet extends Set {
|
|
|
85
118
|
}
|
|
86
119
|
}
|
|
87
120
|
}
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
}
|
|
121
|
+
function getMaximum(first, second) {
|
|
122
|
+
const actual = (typeof first === "number" ? first : void 0) ?? 2 ** 20;
|
|
123
|
+
return number.clamp(actual, 1, 2 ** 24);
|
|
124
|
+
}
|
|
125
|
+
exports.SizedMap = SizedMap;
|
|
126
|
+
exports.SizedSet = SizedSet;
|