@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
package/dist/js/sized.js
CHANGED
|
@@ -1,43 +1,47 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
}
|
|
6
|
-
return value > max ? loop === true ? min : max : value;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
// src/js/sized.ts
|
|
10
|
-
function getMaximum(first, second) {
|
|
11
|
-
const actual = (typeof first === "number" ? first : typeof second === "number" ? second : undefined) ?? 2 ** 20;
|
|
12
|
-
return clamp(actual, 1, 2 ** 24);
|
|
13
|
-
}
|
|
14
|
-
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
4
|
+
import { clamp } from "./number.js";
|
|
15
5
|
class SizedMap extends Map {
|
|
16
|
-
maximumSize;
|
|
17
|
-
get full() {
|
|
18
|
-
return this.size >= this.maximumSize;
|
|
19
|
-
}
|
|
20
|
-
get maximum() {
|
|
21
|
-
return this.maximumSize;
|
|
22
|
-
}
|
|
23
6
|
constructor(entries, maximum) {
|
|
24
|
-
const maximumSize = getMaximum(
|
|
25
|
-
|
|
7
|
+
const maximumSize = getMaximum(
|
|
8
|
+
typeof entries === "number" ? entries : typeof maximum === "number" ? maximum : void 0
|
|
9
|
+
);
|
|
10
|
+
super(Array.isArray(entries) ? entries.slice(0, maximumSize) : void 0);
|
|
11
|
+
__publicField(this, "maximumSize");
|
|
26
12
|
this.maximumSize = maximumSize;
|
|
27
13
|
if (Array.isArray(entries) && entries.length > maximumSize) {
|
|
28
|
-
for (let index = 0;index < maximumSize; index += 1) {
|
|
14
|
+
for (let index = 0; index < maximumSize; index += 1) {
|
|
29
15
|
this.set(...entries[entries.length - maximumSize + index]);
|
|
30
16
|
}
|
|
31
17
|
}
|
|
32
18
|
}
|
|
19
|
+
/**
|
|
20
|
+
* Is the Map full?
|
|
21
|
+
*/
|
|
22
|
+
get full() {
|
|
23
|
+
return this.size >= this.maximumSize;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* The maximum size of the Map
|
|
27
|
+
*/
|
|
28
|
+
get maximum() {
|
|
29
|
+
return this.maximumSize;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* @inheritdoc
|
|
33
|
+
*/
|
|
33
34
|
get(key) {
|
|
34
35
|
const value = super.get(key);
|
|
35
|
-
if (value
|
|
36
|
+
if (value == null && !this.has(key)) {
|
|
36
37
|
return;
|
|
37
38
|
}
|
|
38
39
|
this.set(key, value);
|
|
39
40
|
return value;
|
|
40
41
|
}
|
|
42
|
+
/**
|
|
43
|
+
* @inheritdoc
|
|
44
|
+
*/
|
|
41
45
|
set(key, value) {
|
|
42
46
|
if (this.has(key)) {
|
|
43
47
|
this.delete(key);
|
|
@@ -47,25 +51,37 @@ class SizedMap extends Map {
|
|
|
47
51
|
return super.set(key, value);
|
|
48
52
|
}
|
|
49
53
|
}
|
|
50
|
-
|
|
51
54
|
class SizedSet extends Set {
|
|
52
|
-
maximumSize;
|
|
53
|
-
get full() {
|
|
54
|
-
return this.size >= this.maximumSize;
|
|
55
|
-
}
|
|
56
|
-
get maximum() {
|
|
57
|
-
return this.maximumSize;
|
|
58
|
-
}
|
|
59
55
|
constructor(values, maximum) {
|
|
60
|
-
const maximumSize = getMaximum(
|
|
61
|
-
|
|
56
|
+
const maximumSize = getMaximum(
|
|
57
|
+
typeof values === "number" ? values : typeof maximum === "number" ? maximum : void 0
|
|
58
|
+
);
|
|
59
|
+
super(
|
|
60
|
+
Array.isArray(values) && values.length <= maximumSize ? values : void 0
|
|
61
|
+
);
|
|
62
|
+
__publicField(this, "maximumSize");
|
|
62
63
|
this.maximumSize = maximumSize;
|
|
63
64
|
if (Array.isArray(values) && values.length > maximumSize) {
|
|
64
|
-
for (let index = 0;index < maximumSize; index += 1) {
|
|
65
|
+
for (let index = 0; index < maximumSize; index += 1) {
|
|
65
66
|
this.add(values[values.length - maximumSize + index]);
|
|
66
67
|
}
|
|
67
68
|
}
|
|
68
69
|
}
|
|
70
|
+
/**
|
|
71
|
+
* Is the Set full?
|
|
72
|
+
*/
|
|
73
|
+
get full() {
|
|
74
|
+
return this.size >= this.maximumSize;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* The maximum size of the Set
|
|
78
|
+
*/
|
|
79
|
+
get maximum() {
|
|
80
|
+
return this.maximumSize;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* @inheritdoc
|
|
84
|
+
*/
|
|
69
85
|
add(value) {
|
|
70
86
|
if (this.has(value)) {
|
|
71
87
|
this.delete(value);
|
|
@@ -74,6 +90,11 @@ class SizedSet extends Set {
|
|
|
74
90
|
}
|
|
75
91
|
return super.add(value);
|
|
76
92
|
}
|
|
93
|
+
/**
|
|
94
|
+
* Get a value from an index in the Set, if it exists
|
|
95
|
+
* - Negative indices are counted from the end
|
|
96
|
+
* - Optionally move the value to the end with `update`
|
|
97
|
+
*/
|
|
77
98
|
at(index, update) {
|
|
78
99
|
const value = [...this.values()][index < 0 ? this.size + index : index];
|
|
79
100
|
if ((update ?? false) && this.has(value)) {
|
|
@@ -82,6 +103,9 @@ class SizedSet extends Set {
|
|
|
82
103
|
}
|
|
83
104
|
return value;
|
|
84
105
|
}
|
|
106
|
+
/**
|
|
107
|
+
* Get a value from the Set, if it exists _(and move it to the end)_
|
|
108
|
+
*/
|
|
85
109
|
get(value, update) {
|
|
86
110
|
if (this.has(value)) {
|
|
87
111
|
if (update ?? false) {
|
|
@@ -92,7 +116,11 @@ class SizedSet extends Set {
|
|
|
92
116
|
}
|
|
93
117
|
}
|
|
94
118
|
}
|
|
119
|
+
function getMaximum(first, second) {
|
|
120
|
+
const actual = (typeof first === "number" ? first : void 0) ?? 2 ** 20;
|
|
121
|
+
return clamp(actual, 1, 2 ** 24);
|
|
122
|
+
}
|
|
95
123
|
export {
|
|
96
|
-
|
|
97
|
-
|
|
124
|
+
SizedMap,
|
|
125
|
+
SizedSet
|
|
98
126
|
};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const string_index = require("./index.cjs");
|
|
4
|
+
function camelCase(value) {
|
|
5
|
+
return toCase(value, "", true, false);
|
|
6
|
+
}
|
|
7
|
+
function capitalise(value) {
|
|
8
|
+
if (value.length === 0) {
|
|
9
|
+
return value;
|
|
10
|
+
}
|
|
11
|
+
return value.length === 1 ? value.toLocaleUpperCase() : `${value.charAt(0).toLocaleUpperCase()}${value.slice(1).toLocaleLowerCase()}`;
|
|
12
|
+
}
|
|
13
|
+
function kebabCase(value) {
|
|
14
|
+
return toCase(value, "-", false, false);
|
|
15
|
+
}
|
|
16
|
+
function pascalCase(value) {
|
|
17
|
+
return toCase(value, "", true, true);
|
|
18
|
+
}
|
|
19
|
+
function snakeCase(value) {
|
|
20
|
+
return toCase(value, "_", false, false);
|
|
21
|
+
}
|
|
22
|
+
function titleCase(value) {
|
|
23
|
+
return string_index.words(value).map(capitalise).join(" ");
|
|
24
|
+
}
|
|
25
|
+
function toCase(value, delimiter, capitaliseAny, capitaliseFirst) {
|
|
26
|
+
return string_index.words(value).map((word, index) => {
|
|
27
|
+
const parts = word.replace(
|
|
28
|
+
new RegExp("(\\p{Lu}*)(\\p{Lu})(\\p{Ll}+)", "gu"),
|
|
29
|
+
(full, one, two, three) => three === "s" ? full : `${one}-${two}${three}`
|
|
30
|
+
).replace(new RegExp("(\\p{Ll})(\\p{Lu})", "gu"), "$1-$2").split("-");
|
|
31
|
+
return parts.filter((part) => part.length > 0).map(
|
|
32
|
+
(part, partIndex) => !capitaliseAny || partIndex === 0 && index === 0 && !capitaliseFirst ? part.toLocaleLowerCase() : capitalise(part)
|
|
33
|
+
).join(delimiter);
|
|
34
|
+
}).join(delimiter);
|
|
35
|
+
}
|
|
36
|
+
exports.camelCase = camelCase;
|
|
37
|
+
exports.capitalise = capitalise;
|
|
38
|
+
exports.kebabCase = kebabCase;
|
|
39
|
+
exports.pascalCase = pascalCase;
|
|
40
|
+
exports.snakeCase = snakeCase;
|
|
41
|
+
exports.titleCase = titleCase;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
import { words } from "./index";
|
|
1
|
+
import { words } from "./index.js";
|
|
3
2
|
function camelCase(value) {
|
|
4
3
|
return toCase(value, "", true, false);
|
|
5
4
|
}
|
|
@@ -23,15 +22,20 @@ function titleCase(value) {
|
|
|
23
22
|
}
|
|
24
23
|
function toCase(value, delimiter, capitaliseAny, capitaliseFirst) {
|
|
25
24
|
return words(value).map((word, index) => {
|
|
26
|
-
const parts = word.replace(
|
|
27
|
-
|
|
25
|
+
const parts = word.replace(
|
|
26
|
+
new RegExp("(\\p{Lu}*)(\\p{Lu})(\\p{Ll}+)", "gu"),
|
|
27
|
+
(full, one, two, three) => three === "s" ? full : `${one}-${two}${three}`
|
|
28
|
+
).replace(new RegExp("(\\p{Ll})(\\p{Lu})", "gu"), "$1-$2").split("-");
|
|
29
|
+
return parts.filter((part) => part.length > 0).map(
|
|
30
|
+
(part, partIndex) => !capitaliseAny || partIndex === 0 && index === 0 && !capitaliseFirst ? part.toLocaleLowerCase() : capitalise(part)
|
|
31
|
+
).join(delimiter);
|
|
28
32
|
}).join(delimiter);
|
|
29
33
|
}
|
|
30
34
|
export {
|
|
31
|
-
|
|
32
|
-
snakeCase,
|
|
33
|
-
pascalCase,
|
|
34
|
-
kebabCase,
|
|
35
|
+
camelCase,
|
|
35
36
|
capitalise,
|
|
36
|
-
|
|
37
|
+
kebabCase,
|
|
38
|
+
pascalCase,
|
|
39
|
+
snakeCase,
|
|
40
|
+
titleCase
|
|
37
41
|
};
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const array_compact = require("../array/compact.cjs");
|
|
4
|
+
const string_case = require("./case.cjs");
|
|
5
|
+
const string_template = require("./template.cjs");
|
|
6
|
+
function createUuid() {
|
|
7
|
+
return "10000000-1000-4000-8000-100000000000".replace(
|
|
8
|
+
/[018]/g,
|
|
9
|
+
(substring) => (substring ^ crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> substring / 4).toString(16)
|
|
10
|
+
);
|
|
11
|
+
}
|
|
12
|
+
function getString(value) {
|
|
13
|
+
var _a, _b;
|
|
14
|
+
if (typeof value === "string") {
|
|
15
|
+
return value;
|
|
16
|
+
}
|
|
17
|
+
if (typeof value !== "object" || value == null) {
|
|
18
|
+
return String(value);
|
|
19
|
+
}
|
|
20
|
+
const valueOff = ((_a = value.valueOf) == null ? void 0 : _a.call(value)) ?? value;
|
|
21
|
+
const asString = ((_b = valueOff == null ? void 0 : valueOff.toString) == null ? void 0 : _b.call(valueOff)) ?? String(valueOff);
|
|
22
|
+
return asString.startsWith("[object ") ? JSON.stringify(value) : asString;
|
|
23
|
+
}
|
|
24
|
+
function join(value, delimiter) {
|
|
25
|
+
return array_compact.compact(value).map(getString).filter((value2) => value2.trim().length > 0).join(typeof delimiter === "string" ? delimiter : "");
|
|
26
|
+
}
|
|
27
|
+
function parse(value, reviver) {
|
|
28
|
+
try {
|
|
29
|
+
return JSON.parse(value, reviver);
|
|
30
|
+
} catch {
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
function truncate(value, length, suffix) {
|
|
34
|
+
if (length <= 0) {
|
|
35
|
+
return "";
|
|
36
|
+
}
|
|
37
|
+
if (length >= value.length) {
|
|
38
|
+
return value;
|
|
39
|
+
}
|
|
40
|
+
const suffixLength = (suffix == null ? void 0 : suffix.length) ?? 0;
|
|
41
|
+
const truncatedLength = length - suffixLength;
|
|
42
|
+
return `${value.slice(0, truncatedLength)}${suffix ?? ""}`;
|
|
43
|
+
}
|
|
44
|
+
function words(value) {
|
|
45
|
+
return value.match(/[^\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\x7f]+/g) ?? [];
|
|
46
|
+
}
|
|
47
|
+
exports.camelCase = string_case.camelCase;
|
|
48
|
+
exports.capitalise = string_case.capitalise;
|
|
49
|
+
exports.kebabCase = string_case.kebabCase;
|
|
50
|
+
exports.pascalCase = string_case.pascalCase;
|
|
51
|
+
exports.snakeCase = string_case.snakeCase;
|
|
52
|
+
exports.titleCase = string_case.titleCase;
|
|
53
|
+
exports.template = string_template.template;
|
|
54
|
+
exports.createUuid = createUuid;
|
|
55
|
+
exports.getString = getString;
|
|
56
|
+
exports.join = join;
|
|
57
|
+
exports.parse = parse;
|
|
58
|
+
exports.truncate = truncate;
|
|
59
|
+
exports.words = words;
|
package/dist/js/string/index.js
CHANGED
|
@@ -1,20 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
}
|
|
5
|
-
// src/js/string/index.ts
|
|
1
|
+
import { compact } from "../array/compact.js";
|
|
2
|
+
import { camelCase, capitalise, kebabCase, pascalCase, snakeCase, titleCase } from "./case.js";
|
|
3
|
+
import { template } from "./template.js";
|
|
6
4
|
function createUuid() {
|
|
7
|
-
return "10000000-1000-4000-8000-100000000000".replace(
|
|
5
|
+
return "10000000-1000-4000-8000-100000000000".replace(
|
|
6
|
+
/[018]/g,
|
|
7
|
+
(substring) => (substring ^ crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> substring / 4).toString(16)
|
|
8
|
+
);
|
|
8
9
|
}
|
|
9
10
|
function getString(value) {
|
|
11
|
+
var _a, _b;
|
|
10
12
|
if (typeof value === "string") {
|
|
11
13
|
return value;
|
|
12
14
|
}
|
|
13
15
|
if (typeof value !== "object" || value == null) {
|
|
14
16
|
return String(value);
|
|
15
17
|
}
|
|
16
|
-
const valueOff = value.valueOf
|
|
17
|
-
const asString = valueOff
|
|
18
|
+
const valueOff = ((_a = value.valueOf) == null ? void 0 : _a.call(value)) ?? value;
|
|
19
|
+
const asString = ((_b = valueOff == null ? void 0 : valueOff.toString) == null ? void 0 : _b.call(valueOff)) ?? String(valueOff);
|
|
18
20
|
return asString.startsWith("[object ") ? JSON.stringify(value) : asString;
|
|
19
21
|
}
|
|
20
22
|
function join(value, delimiter) {
|
|
@@ -27,103 +29,31 @@ function parse(value, reviver) {
|
|
|
27
29
|
}
|
|
28
30
|
}
|
|
29
31
|
function truncate(value, length, suffix) {
|
|
30
|
-
|
|
32
|
+
if (length <= 0) {
|
|
33
|
+
return "";
|
|
34
|
+
}
|
|
35
|
+
if (length >= value.length) {
|
|
36
|
+
return value;
|
|
37
|
+
}
|
|
38
|
+
const suffixLength = (suffix == null ? void 0 : suffix.length) ?? 0;
|
|
31
39
|
const truncatedLength = length - suffixLength;
|
|
32
|
-
return
|
|
40
|
+
return `${value.slice(0, truncatedLength)}${suffix ?? ""}`;
|
|
33
41
|
}
|
|
34
42
|
function words(value) {
|
|
35
43
|
return value.match(/[^\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\x7f]+/g) ?? [];
|
|
36
44
|
}
|
|
37
|
-
|
|
38
|
-
// src/js/string/case.ts
|
|
39
|
-
function camelCase(value) {
|
|
40
|
-
return toCase(value, "", true, false);
|
|
41
|
-
}
|
|
42
|
-
function capitalise(value) {
|
|
43
|
-
if (value.length === 0) {
|
|
44
|
-
return value;
|
|
45
|
-
}
|
|
46
|
-
return value.length === 1 ? value.toLocaleUpperCase() : `${value.charAt(0).toLocaleUpperCase()}${value.slice(1).toLocaleLowerCase()}`;
|
|
47
|
-
}
|
|
48
|
-
function kebabCase(value) {
|
|
49
|
-
return toCase(value, "-", false, false);
|
|
50
|
-
}
|
|
51
|
-
function pascalCase(value) {
|
|
52
|
-
return toCase(value, "", true, true);
|
|
53
|
-
}
|
|
54
|
-
function snakeCase(value) {
|
|
55
|
-
return toCase(value, "_", false, false);
|
|
56
|
-
}
|
|
57
|
-
function titleCase(value) {
|
|
58
|
-
return words(value).map(capitalise).join(" ");
|
|
59
|
-
}
|
|
60
|
-
function toCase(value, delimiter, capitaliseAny, capitaliseFirst) {
|
|
61
|
-
return words(value).map((word, index) => {
|
|
62
|
-
const parts = word.replace(/(\p{Lu}*)(\p{Lu})(\p{Ll}+)/gu, (full, one, two, three) => three === "s" ? full : `${one}-${two}${three}`).replace(/(\p{Ll})(\p{Lu})/gu, "$1-$2").split("-");
|
|
63
|
-
return parts.filter((part) => part.length > 0).map((part, partIndex) => !capitaliseAny || partIndex === 0 && index === 0 && !capitaliseFirst ? part.toLocaleLowerCase() : capitalise(part)).join(delimiter);
|
|
64
|
-
}).join(delimiter);
|
|
65
|
-
}
|
|
66
|
-
// src/js/internal/value-handle.ts
|
|
67
|
-
function findKey(needle, haystack, ignoreCase) {
|
|
68
|
-
if (!ignoreCase) {
|
|
69
|
-
return needle;
|
|
70
|
-
}
|
|
71
|
-
const keys = Object.keys(haystack);
|
|
72
|
-
const normalised = keys.map((key) => key.toLowerCase());
|
|
73
|
-
const index = normalised.indexOf(needle.toLowerCase());
|
|
74
|
-
return index > -1 ? keys[index] : needle;
|
|
75
|
-
}
|
|
76
|
-
function handleValue(data, path, value, get, ignoreCase) {
|
|
77
|
-
if (typeof data === "object" && data !== null && !/^(__proto__|constructor|prototype)$/i.test(path)) {
|
|
78
|
-
const key = findKey(path, data, ignoreCase);
|
|
79
|
-
if (get) {
|
|
80
|
-
return data[key];
|
|
81
|
-
}
|
|
82
|
-
data[key] = value;
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
// src/js/value/get.ts
|
|
87
|
-
function getValue(data, path, ignoreCase) {
|
|
88
|
-
const shouldIgnoreCase = ignoreCase === true;
|
|
89
|
-
const parts = (shouldIgnoreCase ? path.toLowerCase() : path).split(".");
|
|
90
|
-
const { length } = parts;
|
|
91
|
-
let index = 0;
|
|
92
|
-
let value = typeof data === "object" ? data ?? {} : {};
|
|
93
|
-
while (index < length && value != null) {
|
|
94
|
-
value = handleValue(value, parts[index++], null, true, shouldIgnoreCase);
|
|
95
|
-
}
|
|
96
|
-
return value;
|
|
97
|
-
}
|
|
98
|
-
// src/js/string/template.ts
|
|
99
|
-
function template(value, variables, options) {
|
|
100
|
-
const ignoreCase = options?.ignoreCase === true;
|
|
101
|
-
const pattern = options?.pattern instanceof RegExp ? options.pattern : /{{([\s\S]+?)}}/g;
|
|
102
|
-
const values = {};
|
|
103
|
-
return value.replace(pattern, (_, key) => {
|
|
104
|
-
if (values[key] != null) {
|
|
105
|
-
return values[key];
|
|
106
|
-
}
|
|
107
|
-
const value2 = getValue(variables, key, ignoreCase);
|
|
108
|
-
if (value2 == null) {
|
|
109
|
-
return "";
|
|
110
|
-
}
|
|
111
|
-
values[key] = getString(value2);
|
|
112
|
-
return values[key];
|
|
113
|
-
});
|
|
114
|
-
}
|
|
115
45
|
export {
|
|
116
|
-
|
|
117
|
-
truncate,
|
|
118
|
-
titleCase,
|
|
119
|
-
template,
|
|
120
|
-
snakeCase,
|
|
121
|
-
pascalCase,
|
|
122
|
-
parse,
|
|
123
|
-
kebabCase,
|
|
124
|
-
join,
|
|
125
|
-
getString,
|
|
126
|
-
createUuid,
|
|
46
|
+
camelCase,
|
|
127
47
|
capitalise,
|
|
128
|
-
|
|
48
|
+
createUuid,
|
|
49
|
+
getString,
|
|
50
|
+
join,
|
|
51
|
+
kebabCase,
|
|
52
|
+
parse,
|
|
53
|
+
pascalCase,
|
|
54
|
+
snakeCase,
|
|
55
|
+
template,
|
|
56
|
+
titleCase,
|
|
57
|
+
truncate,
|
|
58
|
+
words
|
|
129
59
|
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const string_index = require("./index.cjs");
|
|
4
|
+
const value_get = require("../value/get.cjs");
|
|
5
|
+
function template(value, variables, options) {
|
|
6
|
+
const ignoreCase = (options == null ? void 0 : options.ignoreCase) === true;
|
|
7
|
+
const pattern = (options == null ? void 0 : options.pattern) instanceof RegExp ? options.pattern : /{{([\s\S]+?)}}/g;
|
|
8
|
+
const values = {};
|
|
9
|
+
return value.replace(pattern, (_, key) => {
|
|
10
|
+
if (values[key] != null) {
|
|
11
|
+
return values[key];
|
|
12
|
+
}
|
|
13
|
+
const value2 = value_get.getValue(variables, key, ignoreCase);
|
|
14
|
+
if (value2 == null) {
|
|
15
|
+
return "";
|
|
16
|
+
}
|
|
17
|
+
values[key] = string_index.getString(value2);
|
|
18
|
+
return values[key];
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
exports.template = template;
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
import { getValue } from "../value";
|
|
3
|
-
import { getString } from "./index";
|
|
1
|
+
import { getString } from "./index.js";
|
|
2
|
+
import { getValue } from "../value/get.js";
|
|
4
3
|
function template(value, variables, options) {
|
|
5
|
-
const ignoreCase = options
|
|
6
|
-
const pattern = options
|
|
4
|
+
const ignoreCase = (options == null ? void 0 : options.ignoreCase) === true;
|
|
5
|
+
const pattern = (options == null ? void 0 : options.pattern) instanceof RegExp ? options.pattern : /{{([\s\S]+?)}}/g;
|
|
7
6
|
const values = {};
|
|
8
7
|
return value.replace(pattern, (_, key) => {
|
|
9
8
|
if (values[key] != null) {
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
const supportsTouch = (() => {
|
|
3
3
|
let value = false;
|
|
4
4
|
try {
|
|
5
5
|
if ("matchMedia" in window) {
|
|
6
6
|
const media = matchMedia("(pointer: coarse)");
|
|
7
|
-
if (typeof media
|
|
7
|
+
if (typeof (media == null ? void 0 : media.matches) === "boolean") {
|
|
8
8
|
value = media.matches;
|
|
9
9
|
}
|
|
10
10
|
}
|
|
@@ -16,7 +16,4 @@ var supportsTouch = (() => {
|
|
|
16
16
|
}
|
|
17
17
|
return value;
|
|
18
18
|
})();
|
|
19
|
-
|
|
20
|
-
export {
|
|
21
|
-
touch_default as default
|
|
22
|
-
};
|
|
19
|
+
module.exports = supportsTouch;
|
package/dist/js/touch.js
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
var supportsTouch = (() => {
|
|
1
|
+
const supportsTouch = (() => {
|
|
3
2
|
let value = false;
|
|
4
3
|
try {
|
|
5
4
|
if ("matchMedia" in window) {
|
|
6
5
|
const media = matchMedia("(pointer: coarse)");
|
|
7
|
-
if (typeof media
|
|
6
|
+
if (typeof (media == null ? void 0 : media.matches) === "boolean") {
|
|
8
7
|
value = media.matches;
|
|
9
8
|
}
|
|
10
9
|
}
|
|
@@ -16,7 +15,6 @@ var supportsTouch = (() => {
|
|
|
16
15
|
}
|
|
17
16
|
return value;
|
|
18
17
|
})();
|
|
19
|
-
var touch_default = supportsTouch;
|
|
20
18
|
export {
|
|
21
|
-
|
|
19
|
+
supportsTouch as default
|
|
22
20
|
};
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const is = require("../is.cjs");
|
|
4
|
+
function clone(value) {
|
|
5
|
+
switch (true) {
|
|
6
|
+
case value == null:
|
|
7
|
+
return value;
|
|
8
|
+
case typeof value === "bigint":
|
|
9
|
+
return BigInt(value);
|
|
10
|
+
case typeof value === "boolean":
|
|
11
|
+
return Boolean(value);
|
|
12
|
+
case typeof value === "function":
|
|
13
|
+
return void 0;
|
|
14
|
+
case typeof value === "number":
|
|
15
|
+
return Number(value);
|
|
16
|
+
case typeof value === "string":
|
|
17
|
+
return String(value);
|
|
18
|
+
case typeof value === "symbol":
|
|
19
|
+
return Symbol(value.description);
|
|
20
|
+
case value instanceof ArrayBuffer:
|
|
21
|
+
return cloneArrayBuffer(value);
|
|
22
|
+
case value instanceof DataView:
|
|
23
|
+
return cloneDataView(value);
|
|
24
|
+
case value instanceof Map:
|
|
25
|
+
case value instanceof Set:
|
|
26
|
+
return cloneMapOrSet(value);
|
|
27
|
+
case value instanceof Node:
|
|
28
|
+
return value.cloneNode(true);
|
|
29
|
+
case value instanceof RegExp:
|
|
30
|
+
return cloneRegularExpression(value);
|
|
31
|
+
case is.isArrayOrPlainObject(value):
|
|
32
|
+
return cloneObject(value);
|
|
33
|
+
default:
|
|
34
|
+
return structuredClone(value);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
function cloneArrayBuffer(value) {
|
|
38
|
+
const cloned = new ArrayBuffer(value.byteLength);
|
|
39
|
+
new Uint8Array(cloned).set(new Uint8Array(value));
|
|
40
|
+
return cloned;
|
|
41
|
+
}
|
|
42
|
+
function cloneDataView(value) {
|
|
43
|
+
const buffer = cloneArrayBuffer(value.buffer);
|
|
44
|
+
return new DataView(buffer, value.byteOffset, value.byteLength);
|
|
45
|
+
}
|
|
46
|
+
function cloneMapOrSet(value) {
|
|
47
|
+
const isMap = value instanceof Map;
|
|
48
|
+
const cloned = isMap ? /* @__PURE__ */ new Map() : /* @__PURE__ */ new Set();
|
|
49
|
+
const entries = [...value.entries()];
|
|
50
|
+
const { length } = entries;
|
|
51
|
+
for (let index = 0; index < length; index += 1) {
|
|
52
|
+
const entry = entries[index];
|
|
53
|
+
if (isMap) {
|
|
54
|
+
cloned.set(clone(entry[0]), clone(entry[1]));
|
|
55
|
+
} else {
|
|
56
|
+
cloned.add(clone(entry[0]));
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return cloned;
|
|
60
|
+
}
|
|
61
|
+
function cloneObject(value) {
|
|
62
|
+
const cloned = Array.isArray(value) ? [] : {};
|
|
63
|
+
const keys = Object.keys(value);
|
|
64
|
+
const { length } = keys;
|
|
65
|
+
for (let index = 0; index < length; index += 1) {
|
|
66
|
+
const key = keys[index];
|
|
67
|
+
cloned[key] = clone(value[key]);
|
|
68
|
+
}
|
|
69
|
+
return cloned;
|
|
70
|
+
}
|
|
71
|
+
function cloneRegularExpression(value) {
|
|
72
|
+
const cloned = new RegExp(value.source, value.flags);
|
|
73
|
+
cloned.lastIndex = value.lastIndex;
|
|
74
|
+
return cloned;
|
|
75
|
+
}
|
|
76
|
+
exports.clone = clone;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
import { isArrayOrPlainObject } from "../is";
|
|
1
|
+
import { isArrayOrPlainObject } from "../is.js";
|
|
3
2
|
function clone(value) {
|
|
4
3
|
switch (true) {
|
|
5
4
|
case value == null:
|
|
@@ -9,7 +8,7 @@ function clone(value) {
|
|
|
9
8
|
case typeof value === "boolean":
|
|
10
9
|
return Boolean(value);
|
|
11
10
|
case typeof value === "function":
|
|
12
|
-
return;
|
|
11
|
+
return void 0;
|
|
13
12
|
case typeof value === "number":
|
|
14
13
|
return Number(value);
|
|
15
14
|
case typeof value === "string":
|
|
@@ -44,10 +43,10 @@ function cloneDataView(value) {
|
|
|
44
43
|
}
|
|
45
44
|
function cloneMapOrSet(value) {
|
|
46
45
|
const isMap = value instanceof Map;
|
|
47
|
-
const cloned = isMap ? new Map : new Set;
|
|
46
|
+
const cloned = isMap ? /* @__PURE__ */ new Map() : /* @__PURE__ */ new Set();
|
|
48
47
|
const entries = [...value.entries()];
|
|
49
48
|
const { length } = entries;
|
|
50
|
-
for (let index = 0;index < length; index += 1) {
|
|
49
|
+
for (let index = 0; index < length; index += 1) {
|
|
51
50
|
const entry = entries[index];
|
|
52
51
|
if (isMap) {
|
|
53
52
|
cloned.set(clone(entry[0]), clone(entry[1]));
|
|
@@ -61,7 +60,7 @@ function cloneObject(value) {
|
|
|
61
60
|
const cloned = Array.isArray(value) ? [] : {};
|
|
62
61
|
const keys = Object.keys(value);
|
|
63
62
|
const { length } = keys;
|
|
64
|
-
for (let index = 0;index < length; index += 1) {
|
|
63
|
+
for (let index = 0; index < length; index += 1) {
|
|
65
64
|
const key = keys[index];
|
|
66
65
|
cloned[key] = clone(value[key]);
|
|
67
66
|
}
|