@oscarpalmer/atoms 0.75.0 → 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 +2 -1
- package/dist/js/array/chunk.js +2 -1
- package/dist/js/array/count.cjs +10 -3
- package/dist/js/array/count.js +10 -3
- package/dist/js/array/exists.cjs +10 -3
- package/dist/js/array/exists.js +10 -3
- package/dist/js/array/filter.cjs +10 -3
- package/dist/js/array/filter.js +10 -3
- package/dist/js/array/find.cjs +10 -3
- package/dist/js/array/find.js +10 -3
- package/dist/js/array/group-by.cjs +18 -16
- package/dist/js/array/group-by.js +18 -16
- package/dist/js/array/index-of.cjs +10 -3
- package/dist/js/array/index-of.js +10 -3
- package/dist/js/array/index.cjs +2 -2
- package/dist/js/array/index.js +2 -2
- package/dist/js/array/insert.cjs +10 -4
- package/dist/js/array/insert.js +10 -4
- package/dist/js/array/splice.cjs +4 -4
- package/dist/js/array/splice.js +4 -4
- package/dist/js/array/to-map.cjs +11 -11
- package/dist/js/array/to-map.js +11 -11
- package/dist/js/array/to-record.cjs +3 -3
- package/dist/js/array/to-record.js +3 -3
- package/dist/js/array/unique.cjs +2 -2
- package/dist/js/array/unique.js +2 -2
- package/dist/js/colour/base.cjs +1 -1
- package/dist/js/colour/base.js +1 -1
- package/dist/js/colour/hex.cjs +2 -2
- package/dist/js/colour/hex.js +2 -2
- package/dist/js/colour/hsl.cjs +13 -7
- package/dist/js/colour/hsl.js +13 -7
- package/dist/js/colour/rgb.cjs +12 -6
- package/dist/js/colour/rgb.js +12 -6
- package/dist/js/emitter.cjs +8 -5
- package/dist/js/emitter.js +8 -5
- package/dist/js/function.cjs +6 -6
- package/dist/js/function.js +6 -6
- package/dist/js/index.cjs +0 -1
- package/dist/js/index.js +1 -2
- 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 → array/find.cjs} +11 -12
- package/dist/js/internal/{array-find.js → array/find.js} +11 -12
- package/dist/js/logger.cjs +13 -13
- package/dist/js/logger.js +13 -13
- package/dist/js/query.cjs +0 -3
- package/dist/js/query.js +1 -4
- package/dist/js/random.cjs +0 -6
- package/dist/js/random.js +0 -6
- package/dist/js/sized.cjs +1 -1
- package/dist/js/sized.js +1 -1
- package/dist/js/string/index.cjs +7 -1
- package/dist/js/string/index.js +7 -1
- package/dist/js/value/compare.cjs +0 -1
- package/dist/js/value/compare.js +0 -1
- package/dist/js/value/get.cjs +3 -3
- package/dist/js/value/get.js +2 -2
- package/dist/js/value/set.cjs +4 -4
- package/dist/js/value/set.js +2 -2
- package/package.json +3 -2
- 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 +40 -16
- 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 +28 -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 +12 -12
- 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 +2 -2
- package/types/array/chunk.d.ts +2 -2
- package/types/array/compact.d.cts +4 -4
- package/types/array/compact.d.ts +4 -4
- package/types/array/count.d.cts +15 -8
- package/types/array/count.d.ts +13 -7
- package/types/array/exists.d.cts +14 -5
- package/types/array/exists.d.ts +12 -4
- package/types/array/filter.d.cts +16 -7
- package/types/array/filter.d.ts +14 -6
- package/types/array/find.d.cts +16 -7
- package/types/array/find.d.ts +14 -6
- package/types/array/group-by.d.cts +51 -5
- package/types/array/group-by.d.ts +49 -5
- package/types/array/index-of.d.cts +16 -7
- 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 +9 -4
- 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 +2 -2
- package/types/array/shuffle.d.ts +2 -2
- package/types/array/sort.d.cts +11 -11
- package/types/array/sort.d.ts +10 -10
- package/types/array/splice.d.cts +4 -4
- package/types/array/splice.d.ts +4 -4
- package/types/array/to-map.d.cts +44 -20
- package/types/array/to-map.d.ts +42 -20
- package/types/array/to-record.d.cts +44 -20
- package/types/array/to-record.d.ts +42 -20
- package/types/array/unique.d.cts +11 -6
- package/types/array/unique.d.ts +10 -6
- package/types/colour/base.d.cts +28 -16
- package/types/colour/base.d.ts +2 -2
- package/types/colour/functions.d.cts +28 -16
- package/types/colour/functions.d.ts +3 -3
- package/types/colour/hex.d.cts +28 -16
- package/types/colour/hex.d.ts +4 -4
- package/types/colour/hsl.d.cts +28 -16
- 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 +28 -16
- package/types/colour/is.d.ts +3 -3
- package/types/colour/rgb.d.cts +28 -16
- 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 +1061 -669
- 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.ts → value/handle.d.ts} +1 -1
- package/types/is.d.ts +1 -1
- package/types/logger.d.cts +13 -13
- package/types/logger.d.ts +13 -13
- 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/index.d.cts +6 -3
- package/types/string/index.d.ts +3 -3
- package/types/string/template.d.cts +3 -0
- package/types/string/template.d.ts +4 -1
- package/types/value/clone.d.cts +4 -2
- package/types/value/clone.d.ts +4 -2
- 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 +1 -1
- package/types/value/merge.d.ts +2 -2
- package/types/value/set.d.ts +1 -1
- package/types/value/smush.d.cts +1 -1
- package/types/value/smush.d.ts +2 -2
- package/types/value/unsmush.d.cts +1 -1
- package/types/value/unsmush.d.ts +2 -2
- package/dist/js/internal/array-callbacks.cjs +0 -18
- package/dist/js/internal/array-callbacks.js +0 -18
- package/src/js/internal/array-callbacks.ts +0 -28
- package/types/internal/array-callbacks.d.cts +0 -13
- package/types/internal/array-callbacks.d.ts +0 -2
- package/types/internal/array-find.d.cts +0 -11
- package/types/internal/array-find.d.ts +0 -4
- /package/dist/js/internal/{value-handle.cjs → value/handle.cjs} +0 -0
- /package/dist/js/internal/{value-handle.js → value/handle.js} +0 -0
- /package/types/internal/{value-handle.d.cts → value/handle.d.cts} +0 -0
package/dist/js/logger.cjs
CHANGED
|
@@ -6,13 +6,13 @@ if (globalThis._atomic_logging == null) {
|
|
|
6
6
|
}
|
|
7
7
|
class Logger {
|
|
8
8
|
/**
|
|
9
|
-
*
|
|
9
|
+
* Log any number of values at the "debug" log level
|
|
10
10
|
*/
|
|
11
11
|
get debug() {
|
|
12
12
|
return this.enabled ? console.debug : _function.noop;
|
|
13
13
|
}
|
|
14
14
|
/**
|
|
15
|
-
*
|
|
15
|
+
* Log the value and shows all its properties
|
|
16
16
|
*/
|
|
17
17
|
get dir() {
|
|
18
18
|
return this.enabled ? console.dir : _function.noop;
|
|
@@ -30,43 +30,43 @@ class Logger {
|
|
|
30
30
|
globalThis._atomic_logging = value;
|
|
31
31
|
}
|
|
32
32
|
/**
|
|
33
|
-
*
|
|
33
|
+
* Log any number of values at the "error" log level
|
|
34
34
|
*/
|
|
35
35
|
get error() {
|
|
36
36
|
return this.enabled ? console.error : _function.noop;
|
|
37
37
|
}
|
|
38
38
|
/**
|
|
39
|
-
*
|
|
39
|
+
* Log any number of values at the "info" log level
|
|
40
40
|
*/
|
|
41
41
|
get info() {
|
|
42
42
|
return this.enabled ? console.info : _function.noop;
|
|
43
43
|
}
|
|
44
44
|
/**
|
|
45
|
-
*
|
|
45
|
+
* Log any number of values at the "log" log level
|
|
46
46
|
*/
|
|
47
47
|
get log() {
|
|
48
48
|
return this.enabled ? console.log : _function.noop;
|
|
49
49
|
}
|
|
50
50
|
/**
|
|
51
|
-
*
|
|
51
|
+
* Log data as a table, with optional properties to use as columns
|
|
52
52
|
*/
|
|
53
53
|
get table() {
|
|
54
54
|
return this.enabled ? console.table : _function.noop;
|
|
55
55
|
}
|
|
56
56
|
/**
|
|
57
|
-
*
|
|
57
|
+
* Log any number of values together with a trace from where it was called
|
|
58
58
|
*/
|
|
59
59
|
get trace() {
|
|
60
60
|
return this.enabled ? console.trace : _function.noop;
|
|
61
61
|
}
|
|
62
62
|
/**
|
|
63
|
-
*
|
|
63
|
+
* Log any number of values at the "warn" log level
|
|
64
64
|
*/
|
|
65
65
|
get warn() {
|
|
66
66
|
return this.enabled ? console.warn : _function.noop;
|
|
67
67
|
}
|
|
68
68
|
/**
|
|
69
|
-
* -
|
|
69
|
+
* - Start a logged timer with a label
|
|
70
70
|
* - Returns a `Time`-object for logging the current duration of the timer and stopping the timer _(and logging the total duration)_
|
|
71
71
|
*/
|
|
72
72
|
time(label) {
|
|
@@ -85,8 +85,8 @@ class Time {
|
|
|
85
85
|
}
|
|
86
86
|
}
|
|
87
87
|
/**
|
|
88
|
-
* -
|
|
89
|
-
* - Ignored if logging is disabled
|
|
88
|
+
* - Log the current duration of the timer
|
|
89
|
+
* - _(Ignored if logging is disabled)_
|
|
90
90
|
*/
|
|
91
91
|
log() {
|
|
92
92
|
if (this.state.started && !this.state.stopped && logger.enabled) {
|
|
@@ -94,8 +94,8 @@ class Time {
|
|
|
94
94
|
}
|
|
95
95
|
}
|
|
96
96
|
/**
|
|
97
|
-
* -
|
|
98
|
-
* - Will always log the total duration, even if logging is disabled
|
|
97
|
+
* - Stop the timer and logs the total duration
|
|
98
|
+
* - _(Will always log the total duration, even if logging is disabled)_
|
|
99
99
|
*/
|
|
100
100
|
stop() {
|
|
101
101
|
if (this.state.started && !this.state.stopped) {
|
package/dist/js/logger.js
CHANGED
|
@@ -4,13 +4,13 @@ if (globalThis._atomic_logging == null) {
|
|
|
4
4
|
}
|
|
5
5
|
class Logger {
|
|
6
6
|
/**
|
|
7
|
-
*
|
|
7
|
+
* Log any number of values at the "debug" log level
|
|
8
8
|
*/
|
|
9
9
|
get debug() {
|
|
10
10
|
return this.enabled ? console.debug : noop;
|
|
11
11
|
}
|
|
12
12
|
/**
|
|
13
|
-
*
|
|
13
|
+
* Log the value and shows all its properties
|
|
14
14
|
*/
|
|
15
15
|
get dir() {
|
|
16
16
|
return this.enabled ? console.dir : noop;
|
|
@@ -28,43 +28,43 @@ class Logger {
|
|
|
28
28
|
globalThis._atomic_logging = value;
|
|
29
29
|
}
|
|
30
30
|
/**
|
|
31
|
-
*
|
|
31
|
+
* Log any number of values at the "error" log level
|
|
32
32
|
*/
|
|
33
33
|
get error() {
|
|
34
34
|
return this.enabled ? console.error : noop;
|
|
35
35
|
}
|
|
36
36
|
/**
|
|
37
|
-
*
|
|
37
|
+
* Log any number of values at the "info" log level
|
|
38
38
|
*/
|
|
39
39
|
get info() {
|
|
40
40
|
return this.enabled ? console.info : noop;
|
|
41
41
|
}
|
|
42
42
|
/**
|
|
43
|
-
*
|
|
43
|
+
* Log any number of values at the "log" log level
|
|
44
44
|
*/
|
|
45
45
|
get log() {
|
|
46
46
|
return this.enabled ? console.log : noop;
|
|
47
47
|
}
|
|
48
48
|
/**
|
|
49
|
-
*
|
|
49
|
+
* Log data as a table, with optional properties to use as columns
|
|
50
50
|
*/
|
|
51
51
|
get table() {
|
|
52
52
|
return this.enabled ? console.table : noop;
|
|
53
53
|
}
|
|
54
54
|
/**
|
|
55
|
-
*
|
|
55
|
+
* Log any number of values together with a trace from where it was called
|
|
56
56
|
*/
|
|
57
57
|
get trace() {
|
|
58
58
|
return this.enabled ? console.trace : noop;
|
|
59
59
|
}
|
|
60
60
|
/**
|
|
61
|
-
*
|
|
61
|
+
* Log any number of values at the "warn" log level
|
|
62
62
|
*/
|
|
63
63
|
get warn() {
|
|
64
64
|
return this.enabled ? console.warn : noop;
|
|
65
65
|
}
|
|
66
66
|
/**
|
|
67
|
-
* -
|
|
67
|
+
* - Start a logged timer with a label
|
|
68
68
|
* - Returns a `Time`-object for logging the current duration of the timer and stopping the timer _(and logging the total duration)_
|
|
69
69
|
*/
|
|
70
70
|
time(label) {
|
|
@@ -83,8 +83,8 @@ class Time {
|
|
|
83
83
|
}
|
|
84
84
|
}
|
|
85
85
|
/**
|
|
86
|
-
* -
|
|
87
|
-
* - Ignored if logging is disabled
|
|
86
|
+
* - Log the current duration of the timer
|
|
87
|
+
* - _(Ignored if logging is disabled)_
|
|
88
88
|
*/
|
|
89
89
|
log() {
|
|
90
90
|
if (this.state.started && !this.state.stopped && logger.enabled) {
|
|
@@ -92,8 +92,8 @@ class Time {
|
|
|
92
92
|
}
|
|
93
93
|
}
|
|
94
94
|
/**
|
|
95
|
-
* -
|
|
96
|
-
* - Will always log the total duration, even if logging is disabled
|
|
95
|
+
* - Stop the timer and logs the total duration
|
|
96
|
+
* - _(Will always log the total duration, even if logging is disabled)_
|
|
97
97
|
*/
|
|
98
98
|
stop() {
|
|
99
99
|
if (this.state.started && !this.state.stopped) {
|
package/dist/js/query.cjs
CHANGED
|
@@ -9,9 +9,6 @@ function fromQuery(query) {
|
|
|
9
9
|
const parameters = {};
|
|
10
10
|
for (let index = 0; index < length; index += 1) {
|
|
11
11
|
const [key, value] = parts[index].split("=").map(decodeURIComponent);
|
|
12
|
-
if (is.isNullableOrWhitespace(key)) {
|
|
13
|
-
continue;
|
|
14
|
-
}
|
|
15
12
|
if (key.includes(".")) {
|
|
16
13
|
value_set.setValue(parameters, key, getValue(value));
|
|
17
14
|
} else {
|
package/dist/js/query.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { isPlainObject } from "./is.js";
|
|
2
2
|
import { join } from "./string/index.js";
|
|
3
3
|
import { setValue } from "./value/set.js";
|
|
4
4
|
function fromQuery(query) {
|
|
@@ -7,9 +7,6 @@ function fromQuery(query) {
|
|
|
7
7
|
const parameters = {};
|
|
8
8
|
for (let index = 0; index < length; index += 1) {
|
|
9
9
|
const [key, value] = parts[index].split("=").map(decodeURIComponent);
|
|
10
|
-
if (isNullableOrWhitespace(key)) {
|
|
11
|
-
continue;
|
|
12
|
-
}
|
|
13
10
|
if (key.includes(".")) {
|
|
14
11
|
setValue(parameters, key, getValue(value));
|
|
15
12
|
} else {
|
package/dist/js/random.cjs
CHANGED
|
@@ -18,11 +18,6 @@ function getRandomCharacters(length, selection) {
|
|
|
18
18
|
function getRandomColour() {
|
|
19
19
|
return `#${Array.from({ length: 6 }, getRandomHex).join("")}`;
|
|
20
20
|
}
|
|
21
|
-
function getRandomDate(earliest, latest) {
|
|
22
|
-
const earliestTime = (earliest == null ? void 0 : earliest.getTime()) ?? -864e13;
|
|
23
|
-
const latestTime = (latest == null ? void 0 : latest.getTime()) ?? 864e13;
|
|
24
|
-
return new Date(getRandomInteger(earliestTime, latestTime));
|
|
25
|
-
}
|
|
26
21
|
function getRandomFloat(min, max) {
|
|
27
22
|
const minimum = min ?? Number.MIN_SAFE_INTEGER;
|
|
28
23
|
return Math.random() * ((max ?? Number.MAX_SAFE_INTEGER) - minimum) + minimum;
|
|
@@ -45,7 +40,6 @@ function getRandomItems(array, amount) {
|
|
|
45
40
|
exports.getRandomBoolean = getRandomBoolean;
|
|
46
41
|
exports.getRandomCharacters = getRandomCharacters;
|
|
47
42
|
exports.getRandomColour = getRandomColour;
|
|
48
|
-
exports.getRandomDate = getRandomDate;
|
|
49
43
|
exports.getRandomFloat = getRandomFloat;
|
|
50
44
|
exports.getRandomHex = getRandomHex;
|
|
51
45
|
exports.getRandomInteger = getRandomInteger;
|
package/dist/js/random.js
CHANGED
|
@@ -16,11 +16,6 @@ function getRandomCharacters(length, selection) {
|
|
|
16
16
|
function getRandomColour() {
|
|
17
17
|
return `#${Array.from({ length: 6 }, getRandomHex).join("")}`;
|
|
18
18
|
}
|
|
19
|
-
function getRandomDate(earliest, latest) {
|
|
20
|
-
const earliestTime = (earliest == null ? void 0 : earliest.getTime()) ?? -864e13;
|
|
21
|
-
const latestTime = (latest == null ? void 0 : latest.getTime()) ?? 864e13;
|
|
22
|
-
return new Date(getRandomInteger(earliestTime, latestTime));
|
|
23
|
-
}
|
|
24
19
|
function getRandomFloat(min, max) {
|
|
25
20
|
const minimum = min ?? Number.MIN_SAFE_INTEGER;
|
|
26
21
|
return Math.random() * ((max ?? Number.MAX_SAFE_INTEGER) - minimum) + minimum;
|
|
@@ -44,7 +39,6 @@ export {
|
|
|
44
39
|
getRandomBoolean,
|
|
45
40
|
getRandomCharacters,
|
|
46
41
|
getRandomColour,
|
|
47
|
-
getRandomDate,
|
|
48
42
|
getRandomFloat,
|
|
49
43
|
getRandomHex,
|
|
50
44
|
getRandomInteger,
|
package/dist/js/sized.cjs
CHANGED
package/dist/js/sized.js
CHANGED
package/dist/js/string/index.cjs
CHANGED
|
@@ -31,9 +31,15 @@ function parse(value, reviver) {
|
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
33
|
function truncate(value, length, suffix) {
|
|
34
|
+
if (length <= 0) {
|
|
35
|
+
return "";
|
|
36
|
+
}
|
|
37
|
+
if (length >= value.length) {
|
|
38
|
+
return value;
|
|
39
|
+
}
|
|
34
40
|
const suffixLength = (suffix == null ? void 0 : suffix.length) ?? 0;
|
|
35
41
|
const truncatedLength = length - suffixLength;
|
|
36
|
-
return
|
|
42
|
+
return `${value.slice(0, truncatedLength)}${suffix ?? ""}`;
|
|
37
43
|
}
|
|
38
44
|
function words(value) {
|
|
39
45
|
return value.match(/[^\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\x7f]+/g) ?? [];
|
package/dist/js/string/index.js
CHANGED
|
@@ -29,9 +29,15 @@ function parse(value, reviver) {
|
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
31
|
function truncate(value, length, suffix) {
|
|
32
|
+
if (length <= 0) {
|
|
33
|
+
return "";
|
|
34
|
+
}
|
|
35
|
+
if (length >= value.length) {
|
|
36
|
+
return value;
|
|
37
|
+
}
|
|
32
38
|
const suffixLength = (suffix == null ? void 0 : suffix.length) ?? 0;
|
|
33
39
|
const truncatedLength = length - suffixLength;
|
|
34
|
-
return
|
|
40
|
+
return `${value.slice(0, truncatedLength)}${suffix ?? ""}`;
|
|
35
41
|
}
|
|
36
42
|
function words(value) {
|
|
37
43
|
return value.match(/[^\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\x7f]+/g) ?? [];
|
package/dist/js/value/compare.js
CHANGED
package/dist/js/value/get.cjs
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const
|
|
3
|
+
const internal_value_handle = require("../internal/value/handle.cjs");
|
|
4
4
|
function getValue(data, path, ignoreCase) {
|
|
5
5
|
const shouldIgnoreCase = ignoreCase === true;
|
|
6
6
|
const parts = (shouldIgnoreCase ? path.toLowerCase() : path).split(".");
|
|
7
7
|
const { length } = parts;
|
|
8
8
|
let index = 0;
|
|
9
|
-
let value =
|
|
9
|
+
let value = data;
|
|
10
10
|
while (index < length && value != null) {
|
|
11
|
-
value =
|
|
11
|
+
value = internal_value_handle.handleValue(
|
|
12
12
|
value,
|
|
13
13
|
parts[index++],
|
|
14
14
|
null,
|
package/dist/js/value/get.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { handleValue } from "../internal/value
|
|
1
|
+
import { handleValue } from "../internal/value/handle.js";
|
|
2
2
|
function getValue(data, path, ignoreCase) {
|
|
3
3
|
const shouldIgnoreCase = ignoreCase === true;
|
|
4
4
|
const parts = (shouldIgnoreCase ? path.toLowerCase() : path).split(".");
|
|
5
5
|
const { length } = parts;
|
|
6
6
|
let index = 0;
|
|
7
|
-
let value =
|
|
7
|
+
let value = data;
|
|
8
8
|
while (index < length && value != null) {
|
|
9
9
|
value = handleValue(
|
|
10
10
|
value,
|
package/dist/js/value/set.cjs
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const
|
|
3
|
+
const internal_value_handle = require("../internal/value/handle.cjs");
|
|
4
4
|
function setValue(data, path, value, ignoreCase) {
|
|
5
5
|
const shouldIgnoreCase = ignoreCase === true;
|
|
6
6
|
const parts = (shouldIgnoreCase ? path.toLowerCase() : path).split(".");
|
|
7
7
|
const { length } = parts;
|
|
8
8
|
const lastIndex = length - 1;
|
|
9
|
-
let target =
|
|
9
|
+
let target = data;
|
|
10
10
|
for (let index = 0; index < length; index += 1) {
|
|
11
11
|
const part = parts[index];
|
|
12
12
|
if (index === lastIndex) {
|
|
13
|
-
|
|
13
|
+
internal_value_handle.handleValue(target, part, value, false, shouldIgnoreCase);
|
|
14
14
|
break;
|
|
15
15
|
}
|
|
16
|
-
let next =
|
|
16
|
+
let next = internal_value_handle.handleValue(target, part, null, true, shouldIgnoreCase);
|
|
17
17
|
if (typeof next !== "object" || next === null) {
|
|
18
18
|
next = {};
|
|
19
19
|
target[part] = next;
|
package/dist/js/value/set.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { handleValue } from "../internal/value
|
|
1
|
+
import { handleValue } from "../internal/value/handle.js";
|
|
2
2
|
function setValue(data, path, value, ignoreCase) {
|
|
3
3
|
const shouldIgnoreCase = ignoreCase === true;
|
|
4
4
|
const parts = (shouldIgnoreCase ? path.toLowerCase() : path).split(".");
|
|
5
5
|
const { length } = parts;
|
|
6
6
|
const lastIndex = length - 1;
|
|
7
|
-
let target =
|
|
7
|
+
let target = data;
|
|
8
8
|
for (let index = 0; index < length; index += 1) {
|
|
9
9
|
const part = parts[index];
|
|
10
10
|
if (index === lastIndex) {
|
package/package.json
CHANGED
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
"@types/node": "^22.7",
|
|
13
13
|
"@vitest/coverage-istanbul": "^2.1",
|
|
14
14
|
"dts-bundle-generator": "^9.5",
|
|
15
|
+
"glob": "^11",
|
|
15
16
|
"happy-dom": "^15.7",
|
|
16
17
|
"sass": "^1.79",
|
|
17
18
|
"typescript": "^5.6",
|
|
@@ -223,11 +224,11 @@
|
|
|
223
224
|
"build:js": "npx vite build && npm run types",
|
|
224
225
|
"clean": "rm -rf ./dist && rm -rf ./types && rm -f ./tsconfig.tsbuildinfo",
|
|
225
226
|
"test": "npx vitest --coverage",
|
|
226
|
-
"types": "npx tsc && npx dts-bundle-generator --config ./dts.config.ts",
|
|
227
|
+
"types": "npx tsc && npx dts-bundle-generator --config ./dts.config.ts --silent",
|
|
227
228
|
"watch:css": "npx sass ./src/css:./dist/css --no-source-map --watch",
|
|
228
229
|
"watch:js": "npx vite build --watch"
|
|
229
230
|
},
|
|
230
231
|
"type": "module",
|
|
231
232
|
"types": "./types/index.d.cts",
|
|
232
|
-
"version": "0.
|
|
233
|
+
"version": "0.76.0"
|
|
233
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
|
|
2
|
-
import {
|
|
3
|
-
import type {Key} 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
|
|
2
|
-
import {
|
|
3
|
-
import type {Key} from '@/models';
|
|
1
|
+
import {findValue} from '~/internal/array/find';
|
|
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
|
}
|