@oscarpalmer/atoms 0.12.0 → 0.13.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/element/focusable.js +1 -5
- package/dist/js/element/focusable.mjs +1 -5
- package/dist/js/index.js +116 -123
- package/dist/js/timer.js +2 -1
- package/dist/js/timer.mjs +2 -1
- package/dist/js/value.js +11 -17
- package/dist/js/value.mjs +11 -14
- package/package.json +4 -5
- package/src/js/element/focusable.ts +1 -8
- package/src/js/number.ts +4 -1
- package/src/js/timer.ts +1 -1
- package/src/js/value.ts +11 -15
- package/types/number.d.ts +1 -0
- package/types/timer.d.ts +1 -1
|
@@ -18,11 +18,7 @@ var _getValidElements = function(type, parent, filters) {
|
|
|
18
18
|
}
|
|
19
19
|
const indiced = [];
|
|
20
20
|
const zeroed = [];
|
|
21
|
-
const
|
|
22
|
-
let position = Number(length);
|
|
23
|
-
while (position--) {
|
|
24
|
-
const index = length - position - 1;
|
|
25
|
-
const item = items[index];
|
|
21
|
+
for (const item of items) {
|
|
26
22
|
if (item.tabIndex === 0) {
|
|
27
23
|
zeroed.push(item.element);
|
|
28
24
|
} else {
|
|
@@ -18,11 +18,7 @@ var _getValidElements = function(type, parent, filters) {
|
|
|
18
18
|
}
|
|
19
19
|
const indiced = [];
|
|
20
20
|
const zeroed = [];
|
|
21
|
-
const
|
|
22
|
-
let position = Number(length);
|
|
23
|
-
while (position--) {
|
|
24
|
-
const index = length - position - 1;
|
|
25
|
-
const item = items[index];
|
|
21
|
+
for (const item of items) {
|
|
26
22
|
if (item.tabIndex === 0) {
|
|
27
23
|
zeroed.push(item.element);
|
|
28
24
|
} else {
|
package/dist/js/index.js
CHANGED
|
@@ -1,81 +1,70 @@
|
|
|
1
|
-
// src/js/
|
|
2
|
-
function
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
// src/js/value.ts
|
|
13
|
-
var _getValue = function(data, key) {
|
|
14
|
-
if (typeof data !== "object" || data === null || /^(__proto__|constructor|prototype)$/i.test(key)) {
|
|
15
|
-
return;
|
|
1
|
+
// src/js/element/index.ts
|
|
2
|
+
function findElements(selector, context) {
|
|
3
|
+
const contexts = context === undefined ? [document] : findElements(context);
|
|
4
|
+
const elements = [];
|
|
5
|
+
if (typeof selector === "string") {
|
|
6
|
+
for (const context2 of contexts) {
|
|
7
|
+
elements.push(...Array.from(context2.querySelectorAll(selector) ?? []));
|
|
8
|
+
}
|
|
9
|
+
return elements;
|
|
16
10
|
}
|
|
17
|
-
|
|
18
|
-
|
|
11
|
+
const nodes = Array.isArray(selector) || selector instanceof NodeList ? selector : [selector];
|
|
12
|
+
for (const node of nodes) {
|
|
13
|
+
if (node instanceof Element && contexts.some((context2) => context2.contains(node))) {
|
|
14
|
+
elements.push(node);
|
|
15
|
+
}
|
|
19
16
|
}
|
|
20
|
-
return
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
if (
|
|
17
|
+
return elements;
|
|
18
|
+
}
|
|
19
|
+
function findParentElement(origin, selector) {
|
|
20
|
+
if (origin == null || selector == null) {
|
|
24
21
|
return;
|
|
25
22
|
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
} else {
|
|
29
|
-
data[key] = value;
|
|
23
|
+
function matches(element) {
|
|
24
|
+
return typeof selector === "string" ? element.matches?.(selector) ?? false : typeof selector === "function" ? selector(element) : false;
|
|
30
25
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
if (typeof data !== "object" || data === null || isNullableOrWhitespace(key)) {
|
|
34
|
-
return;
|
|
26
|
+
if (matches(origin)) {
|
|
27
|
+
return origin;
|
|
35
28
|
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
value = _getValue(value, parts[position]);
|
|
41
|
-
if (value == null) {
|
|
42
|
-
break;
|
|
29
|
+
let parent = origin.parentElement;
|
|
30
|
+
while (parent != null && !matches(parent)) {
|
|
31
|
+
if (parent === document.body) {
|
|
32
|
+
return;
|
|
43
33
|
}
|
|
34
|
+
parent = parent.parentElement;
|
|
44
35
|
}
|
|
45
|
-
return
|
|
46
|
-
}
|
|
47
|
-
function isArrayOrObject(value) {
|
|
48
|
-
return /^(array|object)$/i.test(value?.constructor?.name);
|
|
49
|
-
}
|
|
50
|
-
function isNullable(value) {
|
|
51
|
-
return value == null;
|
|
36
|
+
return parent ?? undefined;
|
|
52
37
|
}
|
|
53
|
-
function
|
|
54
|
-
|
|
38
|
+
function getElementUnderPointer(skipIgnore) {
|
|
39
|
+
const elements = Array.from(document.querySelectorAll(":hover")).filter((element) => {
|
|
40
|
+
if (/^head$/i.test(element.tagName)) {
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
const style = getComputedStyle(element);
|
|
44
|
+
return typeof skipIgnore === "boolean" && skipIgnore || style.pointerEvents !== "none" && style.visibility !== "hidden";
|
|
45
|
+
});
|
|
46
|
+
return elements[elements.length - 1];
|
|
55
47
|
}
|
|
56
|
-
function
|
|
57
|
-
|
|
58
|
-
|
|
48
|
+
function getTextDirection(element) {
|
|
49
|
+
const direction = element.getAttribute("dir");
|
|
50
|
+
if (direction !== null && /^(ltr|rtl)$/i.test(direction)) {
|
|
51
|
+
return direction.toLowerCase();
|
|
59
52
|
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
target[key2] = next;
|
|
73
|
-
}
|
|
74
|
-
target = next;
|
|
53
|
+
return getComputedStyle?.(element)?.direction === "rtl" ? "rtl" : "ltr";
|
|
54
|
+
}
|
|
55
|
+
// src/js/event.ts
|
|
56
|
+
function getEventPosition(event) {
|
|
57
|
+
let x;
|
|
58
|
+
let y;
|
|
59
|
+
if (event instanceof MouseEvent) {
|
|
60
|
+
x = event.clientX;
|
|
61
|
+
y = event.clientY;
|
|
62
|
+
} else if (event instanceof TouchEvent) {
|
|
63
|
+
x = event.touches[0]?.clientX;
|
|
64
|
+
y = event.touches[0]?.clientY;
|
|
75
65
|
}
|
|
76
|
-
return
|
|
66
|
+
return typeof x === "number" && typeof y === "number" ? { x, y } : undefined;
|
|
77
67
|
}
|
|
78
|
-
|
|
79
68
|
// src/js/number.ts
|
|
80
69
|
function clampNumber(value, min, max) {
|
|
81
70
|
return Math.min(Math.max(getNumber(value), getNumber(min)), getNumber(max));
|
|
@@ -107,7 +96,16 @@ function getNumber(value) {
|
|
|
107
96
|
}
|
|
108
97
|
return +(/^0x[0-9a-f]+$/i.test(trimmed) ? trimmed : trimmed.replace(/_/g, ""));
|
|
109
98
|
}
|
|
110
|
-
|
|
99
|
+
// src/js/string.ts
|
|
100
|
+
function createUuid() {
|
|
101
|
+
return "10000000-1000-4000-8000-100000000000".replace(/[018]/g, (substring) => (substring ^ crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> substring / 4).toString(16));
|
|
102
|
+
}
|
|
103
|
+
function getString(value) {
|
|
104
|
+
return typeof value === "string" ? value : typeof value?.toString === "function" ? value.toString() : String(value);
|
|
105
|
+
}
|
|
106
|
+
function isNullableOrWhitespace(value) {
|
|
107
|
+
return value == null || getString(value).trim().length === 0;
|
|
108
|
+
}
|
|
111
109
|
// src/js/timer.ts
|
|
112
110
|
function repeat(callback, options) {
|
|
113
111
|
const count = typeof options?.count === "number" ? options.count : Infinity;
|
|
@@ -191,74 +189,68 @@ class Timer {
|
|
|
191
189
|
return work("stop", this, this.state, this.options);
|
|
192
190
|
}
|
|
193
191
|
}
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
const elements = [];
|
|
199
|
-
if (typeof selector === "string") {
|
|
200
|
-
for (const context2 of contexts) {
|
|
201
|
-
elements.push(...Array.from(context2.querySelectorAll(selector) ?? []));
|
|
202
|
-
}
|
|
203
|
-
return elements;
|
|
192
|
+
// src/js/value.ts
|
|
193
|
+
var _getValue = function(data, key) {
|
|
194
|
+
if (typeof data !== "object" || data === null || /^(__proto__|constructor|prototype)$/i.test(key)) {
|
|
195
|
+
return;
|
|
204
196
|
}
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
if (node instanceof Element && contexts.some((context2) => context2.contains(node))) {
|
|
208
|
-
elements.push(node);
|
|
209
|
-
}
|
|
197
|
+
if (data instanceof Map) {
|
|
198
|
+
return data.get(key);
|
|
210
199
|
}
|
|
211
|
-
return
|
|
212
|
-
}
|
|
213
|
-
function
|
|
214
|
-
if (
|
|
200
|
+
return data[key];
|
|
201
|
+
};
|
|
202
|
+
var _setValue = function(data, key, value) {
|
|
203
|
+
if (typeof data !== "object" || data === null || /^(__proto__|constructor|prototype)$/i.test(key)) {
|
|
215
204
|
return;
|
|
216
205
|
}
|
|
217
|
-
|
|
218
|
-
|
|
206
|
+
if (data instanceof Map) {
|
|
207
|
+
data.set(key, value);
|
|
208
|
+
} else {
|
|
209
|
+
data[key] = value;
|
|
219
210
|
}
|
|
220
|
-
|
|
221
|
-
|
|
211
|
+
};
|
|
212
|
+
function getValue(data, key) {
|
|
213
|
+
if (typeof data !== "object" || data === null || isNullableOrWhitespace(key)) {
|
|
214
|
+
return;
|
|
222
215
|
}
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
216
|
+
const parts = getString(key).split(".");
|
|
217
|
+
let value = data;
|
|
218
|
+
for (const part of parts) {
|
|
219
|
+
value = _getValue(value, part);
|
|
220
|
+
if (value == null) {
|
|
221
|
+
break;
|
|
227
222
|
}
|
|
228
|
-
parent = parent.parentElement;
|
|
229
223
|
}
|
|
230
|
-
return
|
|
224
|
+
return value;
|
|
231
225
|
}
|
|
232
|
-
function
|
|
233
|
-
|
|
234
|
-
if (/^head$/i.test(element.tagName)) {
|
|
235
|
-
return false;
|
|
236
|
-
}
|
|
237
|
-
const style = getComputedStyle(element);
|
|
238
|
-
return typeof skipIgnore === "boolean" && skipIgnore || style.pointerEvents !== "none" && style.visibility !== "hidden";
|
|
239
|
-
});
|
|
240
|
-
return elements[elements.length - 1];
|
|
226
|
+
function isArrayOrObject(value) {
|
|
227
|
+
return /^(array|object)$/i.test(value?.constructor?.name);
|
|
241
228
|
}
|
|
242
|
-
function
|
|
243
|
-
|
|
244
|
-
if (direction !== null && /^(ltr|rtl)$/i.test(direction)) {
|
|
245
|
-
return direction.toLowerCase();
|
|
246
|
-
}
|
|
247
|
-
return getComputedStyle?.(element)?.direction === "rtl" ? "rtl" : "ltr";
|
|
229
|
+
function isNullable(value) {
|
|
230
|
+
return value == null;
|
|
248
231
|
}
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
x = event.clientX;
|
|
256
|
-
y = event.clientY;
|
|
257
|
-
} else if (event instanceof TouchEvent) {
|
|
258
|
-
x = event.touches[0]?.clientX;
|
|
259
|
-
y = event.touches[0]?.clientY;
|
|
232
|
+
function isObject(value) {
|
|
233
|
+
return /^object$/i.test(value?.constructor?.name);
|
|
234
|
+
}
|
|
235
|
+
function setValue(data, key, value) {
|
|
236
|
+
if (typeof data !== "object" || data === null || isNullableOrWhitespace(key)) {
|
|
237
|
+
return data;
|
|
260
238
|
}
|
|
261
|
-
|
|
239
|
+
const parts = getString(key).split(".");
|
|
240
|
+
let target = data;
|
|
241
|
+
for (const part of parts) {
|
|
242
|
+
if (parts.indexOf(part) === parts.length - 1) {
|
|
243
|
+
_setValue(target, part, value);
|
|
244
|
+
break;
|
|
245
|
+
}
|
|
246
|
+
let next = _getValue(target, part);
|
|
247
|
+
if (typeof next !== "object" || next === null) {
|
|
248
|
+
next = /^\d+$/.test(part) ? [] : {};
|
|
249
|
+
target[part] = next;
|
|
250
|
+
}
|
|
251
|
+
target = next;
|
|
252
|
+
}
|
|
253
|
+
return data;
|
|
262
254
|
}
|
|
263
255
|
export {
|
|
264
256
|
wait,
|
|
@@ -277,5 +269,6 @@ export {
|
|
|
277
269
|
findParentElement,
|
|
278
270
|
findElements,
|
|
279
271
|
createUuid,
|
|
280
|
-
clampNumber
|
|
272
|
+
clampNumber,
|
|
273
|
+
Timer
|
|
281
274
|
};
|
package/dist/js/timer.js
CHANGED
package/dist/js/timer.mjs
CHANGED
package/dist/js/value.js
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
1
|
// src/js/string.ts
|
|
2
|
-
function createUuid() {
|
|
3
|
-
return "10000000-1000-4000-8000-100000000000".replace(/[018]/g, (substring) => (substring ^ crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> substring / 4).toString(16));
|
|
4
|
-
}
|
|
5
2
|
function getString(value) {
|
|
6
3
|
return typeof value === "string" ? value : typeof value?.toString === "function" ? value.toString() : String(value);
|
|
7
4
|
}
|
|
@@ -33,11 +30,10 @@ function getValue(data, key) {
|
|
|
33
30
|
if (typeof data !== "object" || data === null || isNullableOrWhitespace(key)) {
|
|
34
31
|
return;
|
|
35
32
|
}
|
|
36
|
-
const parts = getString(key).split(".")
|
|
37
|
-
let position = parts.length;
|
|
33
|
+
const parts = getString(key).split(".");
|
|
38
34
|
let value = data;
|
|
39
|
-
|
|
40
|
-
value = _getValue(value,
|
|
35
|
+
for (const part of parts) {
|
|
36
|
+
value = _getValue(value, part);
|
|
41
37
|
if (value == null) {
|
|
42
38
|
break;
|
|
43
39
|
}
|
|
@@ -51,25 +47,23 @@ function isNullable(value) {
|
|
|
51
47
|
return value == null;
|
|
52
48
|
}
|
|
53
49
|
function isObject(value) {
|
|
54
|
-
return value?.constructor?.name
|
|
50
|
+
return /^object$/i.test(value?.constructor?.name);
|
|
55
51
|
}
|
|
56
52
|
function setValue(data, key, value) {
|
|
57
53
|
if (typeof data !== "object" || data === null || isNullableOrWhitespace(key)) {
|
|
58
54
|
return data;
|
|
59
55
|
}
|
|
60
|
-
const parts = getString(key).split(".")
|
|
61
|
-
let position = parts.length;
|
|
56
|
+
const parts = getString(key).split(".");
|
|
62
57
|
let target = data;
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
_setValue(target, key2, value);
|
|
58
|
+
for (const part of parts) {
|
|
59
|
+
if (parts.indexOf(part) === parts.length - 1) {
|
|
60
|
+
_setValue(target, part, value);
|
|
67
61
|
break;
|
|
68
62
|
}
|
|
69
|
-
let next = _getValue(target,
|
|
63
|
+
let next = _getValue(target, part);
|
|
70
64
|
if (typeof next !== "object" || next === null) {
|
|
71
|
-
next = /^\d+$/.test(
|
|
72
|
-
target[
|
|
65
|
+
next = /^\d+$/.test(part) ? [] : {};
|
|
66
|
+
target[part] = next;
|
|
73
67
|
}
|
|
74
68
|
target = next;
|
|
75
69
|
}
|
package/dist/js/value.mjs
CHANGED
|
@@ -23,11 +23,10 @@ function getValue(data, key) {
|
|
|
23
23
|
if (typeof data !== "object" || data === null || isNullableOrWhitespace(key)) {
|
|
24
24
|
return;
|
|
25
25
|
}
|
|
26
|
-
const parts = getString(key).split(".")
|
|
27
|
-
let position = parts.length;
|
|
26
|
+
const parts = getString(key).split(".");
|
|
28
27
|
let value = data;
|
|
29
|
-
|
|
30
|
-
value = _getValue(value,
|
|
28
|
+
for (const part of parts) {
|
|
29
|
+
value = _getValue(value, part);
|
|
31
30
|
if (value == null) {
|
|
32
31
|
break;
|
|
33
32
|
}
|
|
@@ -41,25 +40,23 @@ function isNullable(value) {
|
|
|
41
40
|
return value == null;
|
|
42
41
|
}
|
|
43
42
|
function isObject(value) {
|
|
44
|
-
return value?.constructor?.name
|
|
43
|
+
return /^object$/i.test(value?.constructor?.name);
|
|
45
44
|
}
|
|
46
45
|
function setValue(data, key, value) {
|
|
47
46
|
if (typeof data !== "object" || data === null || isNullableOrWhitespace(key)) {
|
|
48
47
|
return data;
|
|
49
48
|
}
|
|
50
|
-
const parts = getString(key).split(".")
|
|
51
|
-
let position = parts.length;
|
|
49
|
+
const parts = getString(key).split(".");
|
|
52
50
|
let target = data;
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
_setValue(target, key2, value);
|
|
51
|
+
for (const part of parts) {
|
|
52
|
+
if (parts.indexOf(part) === parts.length - 1) {
|
|
53
|
+
_setValue(target, part, value);
|
|
57
54
|
break;
|
|
58
55
|
}
|
|
59
|
-
let next = _getValue(target,
|
|
56
|
+
let next = _getValue(target, part);
|
|
60
57
|
if (typeof next !== "object" || next === null) {
|
|
61
|
-
next = /^\d+$/.test(
|
|
62
|
-
target[
|
|
58
|
+
next = /^\d+$/.test(part) ? [] : {};
|
|
59
|
+
target[part] = next;
|
|
63
60
|
}
|
|
64
61
|
target = next;
|
|
65
62
|
}
|
package/package.json
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
"@biomejs/biome": "^1.5",
|
|
9
9
|
"@happy-dom/global-registrator": "^13.3",
|
|
10
10
|
"bun": "^1.0",
|
|
11
|
-
"sass": "^1.
|
|
11
|
+
"sass": "^1.71",
|
|
12
12
|
"typescript": "^5.3"
|
|
13
13
|
},
|
|
14
14
|
"exports": {
|
|
@@ -83,10 +83,9 @@
|
|
|
83
83
|
"url": "git+https://github.com/oscarpalmer/atoms.git"
|
|
84
84
|
},
|
|
85
85
|
"scripts": {
|
|
86
|
-
"build": "bun run build:css && bun run build:js && bun run
|
|
86
|
+
"build": "bun run build:css && bun run build:js && bun run types",
|
|
87
87
|
"build:css": "bunx sass ./src/css:./dist/css --no-source-map",
|
|
88
|
-
"build:js": "bunx bun ./.bun.ts",
|
|
89
|
-
"build:mjs": "bunx bun ./.bun.ts --mjs",
|
|
88
|
+
"build:js": "bunx bun ./.bun.ts && bunx bun ./.bun.ts --mjs",
|
|
90
89
|
"test": "bun test --preload ./test/_preload.ts --coverage",
|
|
91
90
|
"types": "bunx tsc -p ./tsconfig.json",
|
|
92
91
|
"watch:css": "bunx sass ./src/css:./dist/css --no-source-map --watch",
|
|
@@ -94,5 +93,5 @@
|
|
|
94
93
|
},
|
|
95
94
|
"type": "module",
|
|
96
95
|
"types": "./types/index.d.ts",
|
|
97
|
-
"version": "0.
|
|
96
|
+
"version": "0.13.0"
|
|
98
97
|
}
|
|
@@ -87,14 +87,7 @@ function _getValidElements(
|
|
|
87
87
|
const indiced: Array<Array<FocusableElement>> = [];
|
|
88
88
|
const zeroed: Array<FocusableElement> = [];
|
|
89
89
|
|
|
90
|
-
const
|
|
91
|
-
|
|
92
|
-
let position = Number(length);
|
|
93
|
-
|
|
94
|
-
while (position--) {
|
|
95
|
-
const index = length - position - 1;
|
|
96
|
-
const item = items[index];
|
|
97
|
-
|
|
90
|
+
for (const item of items) {
|
|
98
91
|
if (item.tabIndex === 0) {
|
|
99
92
|
zeroed.push(item.element);
|
|
100
93
|
} else {
|
package/src/js/number.ts
CHANGED
|
@@ -9,6 +9,7 @@ export function clampNumber(value: number, min: number, max: number): number {
|
|
|
9
9
|
/**
|
|
10
10
|
* - Gets the number value from an unknown value
|
|
11
11
|
* - Returns `NaN` if the value is `undefined`, `null`, or cannot be parsed
|
|
12
|
+
* - Based on Lodash :-)
|
|
12
13
|
*/
|
|
13
14
|
export function getNumber(value: unknown): number {
|
|
14
15
|
if (typeof value === 'number') {
|
|
@@ -45,5 +46,7 @@ export function getNumber(value: unknown): number {
|
|
|
45
46
|
return parseInt(trimmed.slice(2), isBinary ? 2 : 8);
|
|
46
47
|
}
|
|
47
48
|
|
|
48
|
-
return +(/^0x[0-9a-f]+$/i.test(trimmed)
|
|
49
|
+
return +(/^0x[0-9a-f]+$/i.test(trimmed)
|
|
50
|
+
? trimmed
|
|
51
|
+
: trimmed.replace(/_/g, ''));
|
|
49
52
|
}
|
package/src/js/timer.ts
CHANGED
|
@@ -42,7 +42,7 @@ type WorkType = 'restart' | 'start' | 'stop';
|
|
|
42
42
|
/**
|
|
43
43
|
* A timer that can be started, stopped, and restarted as neeeded
|
|
44
44
|
*/
|
|
45
|
-
class Timer {
|
|
45
|
+
export class Timer {
|
|
46
46
|
private declare readonly state: TimerState;
|
|
47
47
|
private declare readonly options: TimerOptions;
|
|
48
48
|
|
package/src/js/value.ts
CHANGED
|
@@ -57,13 +57,12 @@ export function getValue(data: ValueObject, key: Key): unknown {
|
|
|
57
57
|
return undefined;
|
|
58
58
|
}
|
|
59
59
|
|
|
60
|
-
const parts = getString(key).split('.')
|
|
60
|
+
const parts = getString(key).split('.');
|
|
61
61
|
|
|
62
|
-
let position = parts.length;
|
|
63
62
|
let value = data;
|
|
64
63
|
|
|
65
|
-
|
|
66
|
-
value = _getValue(value,
|
|
64
|
+
for (const part of parts) {
|
|
65
|
+
value = _getValue(value, part) as ValueObject;
|
|
67
66
|
|
|
68
67
|
if (value == null) {
|
|
69
68
|
break;
|
|
@@ -91,7 +90,7 @@ export function isNullable(value: unknown): value is undefined | null {
|
|
|
91
90
|
* Is the value a generic object?
|
|
92
91
|
*/
|
|
93
92
|
export function isObject(value: unknown): value is GenericObject {
|
|
94
|
-
return (value as GenericObject)?.constructor?.name
|
|
93
|
+
return /^object$/i.test((value as GenericObject)?.constructor?.name);
|
|
95
94
|
}
|
|
96
95
|
|
|
97
96
|
/**
|
|
@@ -113,26 +112,23 @@ export function setValue<Model extends ValueObject>(
|
|
|
113
112
|
return data;
|
|
114
113
|
}
|
|
115
114
|
|
|
116
|
-
const parts = getString(key).split('.')
|
|
115
|
+
const parts = getString(key).split('.');
|
|
117
116
|
|
|
118
|
-
let position = parts.length;
|
|
119
117
|
let target: ValueObject = data;
|
|
120
118
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
if (position === 0) {
|
|
125
|
-
_setValue(target, key, value);
|
|
119
|
+
for (const part of parts) {
|
|
120
|
+
if (parts.indexOf(part) === parts.length - 1) {
|
|
121
|
+
_setValue(target, part, value);
|
|
126
122
|
|
|
127
123
|
break;
|
|
128
124
|
}
|
|
129
125
|
|
|
130
|
-
let next = _getValue(target,
|
|
126
|
+
let next = _getValue(target, part);
|
|
131
127
|
|
|
132
128
|
if (typeof next !== 'object' || next === null) {
|
|
133
|
-
next = /^\d+$/.test(
|
|
129
|
+
next = /^\d+$/.test(part) ? [] : {};
|
|
134
130
|
|
|
135
|
-
target[
|
|
131
|
+
target[part as never] = next as never;
|
|
136
132
|
}
|
|
137
133
|
|
|
138
134
|
target = next as ValueObject;
|
package/types/number.d.ts
CHANGED
|
@@ -5,5 +5,6 @@ export declare function clampNumber(value: number, min: number, max: number): nu
|
|
|
5
5
|
/**
|
|
6
6
|
* - Gets the number value from an unknown value
|
|
7
7
|
* - Returns `NaN` if the value is `undefined`, `null`, or cannot be parsed
|
|
8
|
+
* - Based on Lodash :-)
|
|
8
9
|
*/
|
|
9
10
|
export declare function getNumber(value: unknown): number;
|