@ls-stack/utils 3.57.0 → 3.59.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/arrayUtils.cjs +5 -0
- package/dist/arrayUtils.d.cts +4 -3
- package/dist/arrayUtils.d.ts +4 -3
- package/dist/arrayUtils.js +3 -1
- package/dist/asyncQueue.js +2 -2
- package/dist/cache.js +3 -3
- package/dist/{chunk-LBBC55GE.js → chunk-2LO5FYP5.js} +1 -1
- package/dist/{chunk-5MNYPLZI.js → chunk-6FBIEPWU.js} +1 -1
- package/dist/{chunk-NW5H5EW7.js → chunk-CCUPDGSZ.js} +44 -12
- package/dist/chunk-DBOWTYR4.js +49 -0
- package/dist/{chunk-AULH7VMS.js → chunk-DX2524CZ.js} +1 -1
- package/dist/{chunk-BT3UMATU.js → chunk-GVIDV772.js} +4 -0
- package/dist/{chunk-WNFRB7P6.js → chunk-SGRS4OEE.js} +31 -4
- package/dist/concurrentCalls.js +1 -1
- package/dist/createThrottleController.js +2 -2
- package/dist/debounce.cjs +44 -12
- package/dist/debounce.d.cts +9 -0
- package/dist/debounce.d.ts +9 -0
- package/dist/debounce.js +1 -1
- package/dist/filterObjectOrArrayKeys.js +2 -2
- package/dist/interpolate.js +1 -1
- package/dist/matchPath.js +3 -3
- package/dist/mathUtils.cjs +28 -2
- package/dist/mathUtils.d.cts +48 -1
- package/dist/mathUtils.d.ts +48 -1
- package/dist/mathUtils.js +11 -3
- package/dist/objUtils.cjs +34 -2
- package/dist/objUtils.d.cts +14 -3
- package/dist/objUtils.d.ts +14 -3
- package/dist/objUtils.js +12 -2
- package/dist/serializeXML.js +1 -1
- package/dist/testUtils.js +4 -4
- package/dist/throttle.cjs +43 -11
- package/dist/throttle.js +1 -1
- package/dist/time.js +2 -2
- package/package.json +1 -1
- package/dist/chunk-HTCYUMDR.js +0 -27
package/dist/arrayUtils.cjs
CHANGED
|
@@ -31,6 +31,7 @@ __export(arrayUtils_exports, {
|
|
|
31
31
|
hasDuplicates: () => hasDuplicates,
|
|
32
32
|
intersperse: () => intersperse,
|
|
33
33
|
isInArray: () => isInArray,
|
|
34
|
+
looseIsInArray: () => looseIsInArray,
|
|
34
35
|
rejectArrayUndefinedValues: () => rejectArrayUndefinedValues,
|
|
35
36
|
rejectDuplicates: () => rejectDuplicates,
|
|
36
37
|
repeat: () => repeat,
|
|
@@ -105,6 +106,9 @@ function isInArray(value, oneOf) {
|
|
|
105
106
|
}
|
|
106
107
|
return false;
|
|
107
108
|
}
|
|
109
|
+
function looseIsInArray(value, array) {
|
|
110
|
+
return array.includes(value);
|
|
111
|
+
}
|
|
108
112
|
function findAfterIndex(array, index, predicate) {
|
|
109
113
|
for (let i = index + 1; i < array.length; i++) {
|
|
110
114
|
if (predicate(array[i])) {
|
|
@@ -211,6 +215,7 @@ function repeat(value, count, separator) {
|
|
|
211
215
|
hasDuplicates,
|
|
212
216
|
intersperse,
|
|
213
217
|
isInArray,
|
|
218
|
+
looseIsInArray,
|
|
214
219
|
rejectArrayUndefinedValues,
|
|
215
220
|
rejectDuplicates,
|
|
216
221
|
repeat,
|
package/dist/arrayUtils.d.cts
CHANGED
|
@@ -76,6 +76,7 @@ declare function arrayWithPrevAndIndex<T>(array: T[]): {
|
|
|
76
76
|
index: number;
|
|
77
77
|
}[];
|
|
78
78
|
declare function isInArray<T, const U extends T>(value: T, oneOf: readonly U[]): value is U;
|
|
79
|
+
declare function looseIsInArray(value: unknown, array: readonly unknown[]): boolean;
|
|
79
80
|
declare function findAfterIndex<T>(array: T[], index: number, predicate: (item: T) => boolean): T | undefined;
|
|
80
81
|
declare function findBeforeIndex<T>(array: T[], index: number, predicate: (item: T) => boolean): T | undefined;
|
|
81
82
|
declare function rejectArrayUndefinedValues<T extends unknown[]>(array: T): T;
|
|
@@ -152,8 +153,8 @@ declare function arrayOps<T>(array: T[]): ArrayOps<T>;
|
|
|
152
153
|
*/
|
|
153
154
|
declare function intersperse<T, I>(array: T[], separator: I): (T | I)[];
|
|
154
155
|
/**
|
|
155
|
-
* Creates an array by repeating a value a specified number of times,
|
|
156
|
-
*
|
|
156
|
+
* Creates an array by repeating a value a specified number of times, optionally
|
|
157
|
+
* with a separator between each repetition.
|
|
157
158
|
*
|
|
158
159
|
* @example
|
|
159
160
|
* repeat('x', 3); // ['x', 'x', 'x']
|
|
@@ -166,4 +167,4 @@ declare function intersperse<T, I>(array: T[], separator: I): (T | I)[];
|
|
|
166
167
|
*/
|
|
167
168
|
declare function repeat<T>(value: T, count: number, separator?: T): T[];
|
|
168
169
|
|
|
169
|
-
export { type FilterAndMapReturn, type SortByProps, type SortByValueFn, arrayOps, arrayWithPrev, arrayWithPrevAndIndex, filterAndMap, findAfterIndex, findAndMap, findBeforeIndex, getAscIndexOrder, hasDuplicates, intersperse, isInArray, rejectArrayUndefinedValues, rejectDuplicates, repeat, sortBy, truncateArray };
|
|
170
|
+
export { type FilterAndMapReturn, type SortByProps, type SortByValueFn, arrayOps, arrayWithPrev, arrayWithPrevAndIndex, filterAndMap, findAfterIndex, findAndMap, findBeforeIndex, getAscIndexOrder, hasDuplicates, intersperse, isInArray, looseIsInArray, rejectArrayUndefinedValues, rejectDuplicates, repeat, sortBy, truncateArray };
|
package/dist/arrayUtils.d.ts
CHANGED
|
@@ -76,6 +76,7 @@ declare function arrayWithPrevAndIndex<T>(array: T[]): {
|
|
|
76
76
|
index: number;
|
|
77
77
|
}[];
|
|
78
78
|
declare function isInArray<T, const U extends T>(value: T, oneOf: readonly U[]): value is U;
|
|
79
|
+
declare function looseIsInArray(value: unknown, array: readonly unknown[]): boolean;
|
|
79
80
|
declare function findAfterIndex<T>(array: T[], index: number, predicate: (item: T) => boolean): T | undefined;
|
|
80
81
|
declare function findBeforeIndex<T>(array: T[], index: number, predicate: (item: T) => boolean): T | undefined;
|
|
81
82
|
declare function rejectArrayUndefinedValues<T extends unknown[]>(array: T): T;
|
|
@@ -152,8 +153,8 @@ declare function arrayOps<T>(array: T[]): ArrayOps<T>;
|
|
|
152
153
|
*/
|
|
153
154
|
declare function intersperse<T, I>(array: T[], separator: I): (T | I)[];
|
|
154
155
|
/**
|
|
155
|
-
* Creates an array by repeating a value a specified number of times,
|
|
156
|
-
*
|
|
156
|
+
* Creates an array by repeating a value a specified number of times, optionally
|
|
157
|
+
* with a separator between each repetition.
|
|
157
158
|
*
|
|
158
159
|
* @example
|
|
159
160
|
* repeat('x', 3); // ['x', 'x', 'x']
|
|
@@ -166,4 +167,4 @@ declare function intersperse<T, I>(array: T[], separator: I): (T | I)[];
|
|
|
166
167
|
*/
|
|
167
168
|
declare function repeat<T>(value: T, count: number, separator?: T): T[];
|
|
168
169
|
|
|
169
|
-
export { type FilterAndMapReturn, type SortByProps, type SortByValueFn, arrayOps, arrayWithPrev, arrayWithPrevAndIndex, filterAndMap, findAfterIndex, findAndMap, findBeforeIndex, getAscIndexOrder, hasDuplicates, intersperse, isInArray, rejectArrayUndefinedValues, rejectDuplicates, repeat, sortBy, truncateArray };
|
|
170
|
+
export { type FilterAndMapReturn, type SortByProps, type SortByValueFn, arrayOps, arrayWithPrev, arrayWithPrevAndIndex, filterAndMap, findAfterIndex, findAndMap, findBeforeIndex, getAscIndexOrder, hasDuplicates, intersperse, isInArray, looseIsInArray, rejectArrayUndefinedValues, rejectDuplicates, repeat, sortBy, truncateArray };
|
package/dist/arrayUtils.js
CHANGED
|
@@ -10,12 +10,13 @@ import {
|
|
|
10
10
|
hasDuplicates,
|
|
11
11
|
intersperse,
|
|
12
12
|
isInArray,
|
|
13
|
+
looseIsInArray,
|
|
13
14
|
rejectArrayUndefinedValues,
|
|
14
15
|
rejectDuplicates,
|
|
15
16
|
repeat,
|
|
16
17
|
sortBy,
|
|
17
18
|
truncateArray
|
|
18
|
-
} from "./chunk-
|
|
19
|
+
} from "./chunk-GVIDV772.js";
|
|
19
20
|
import "./chunk-C2SVCIWE.js";
|
|
20
21
|
import "./chunk-JF2MDHOJ.js";
|
|
21
22
|
export {
|
|
@@ -30,6 +31,7 @@ export {
|
|
|
30
31
|
hasDuplicates,
|
|
31
32
|
intersperse,
|
|
32
33
|
isInArray,
|
|
34
|
+
looseIsInArray,
|
|
33
35
|
rejectArrayUndefinedValues,
|
|
34
36
|
rejectDuplicates,
|
|
35
37
|
repeat,
|
package/dist/asyncQueue.js
CHANGED
package/dist/cache.js
CHANGED
|
@@ -4,9 +4,9 @@ import {
|
|
|
4
4
|
cachedGetter,
|
|
5
5
|
createCache,
|
|
6
6
|
fastCache
|
|
7
|
-
} from "./chunk-
|
|
8
|
-
import "./chunk-
|
|
9
|
-
import "./chunk-
|
|
7
|
+
} from "./chunk-DX2524CZ.js";
|
|
8
|
+
import "./chunk-6FBIEPWU.js";
|
|
9
|
+
import "./chunk-DBOWTYR4.js";
|
|
10
10
|
import "./chunk-II4R3VVX.js";
|
|
11
11
|
import "./chunk-C2SVCIWE.js";
|
|
12
12
|
import "./chunk-JF2MDHOJ.js";
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
// src/debounce.ts
|
|
2
2
|
function debounce(func, wait, options) {
|
|
3
|
+
let currentCallback = func;
|
|
4
|
+
let waitMs = wait;
|
|
5
|
+
let currentOptions = options;
|
|
3
6
|
let lastArgs;
|
|
4
7
|
let lastThis;
|
|
5
8
|
let maxWait;
|
|
@@ -10,35 +13,37 @@ function debounce(func, wait, options) {
|
|
|
10
13
|
let leading = false;
|
|
11
14
|
let maxing = false;
|
|
12
15
|
let trailing = true;
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
function applyOptions() {
|
|
17
|
+
const opts = currentOptions;
|
|
18
|
+
leading = !!opts?.leading;
|
|
19
|
+
trailing = opts && "trailing" in opts ? !!opts.trailing : true;
|
|
20
|
+
maxing = !!(opts && "maxWait" in opts);
|
|
21
|
+
maxWait = maxing ? Math.max(opts?.maxWait ?? 0, waitMs) : void 0;
|
|
18
22
|
}
|
|
23
|
+
applyOptions();
|
|
19
24
|
function invokeFunc(time) {
|
|
20
25
|
const args = lastArgs;
|
|
21
26
|
const thisArg = lastThis;
|
|
22
27
|
lastArgs = lastThis = void 0;
|
|
23
28
|
lastInvokeTime = time;
|
|
24
|
-
result =
|
|
29
|
+
result = currentCallback.apply(thisArg, args);
|
|
25
30
|
return result;
|
|
26
31
|
}
|
|
27
32
|
function leadingEdge(time) {
|
|
28
33
|
lastInvokeTime = time;
|
|
29
|
-
timerId = setTimeout(timerExpired,
|
|
34
|
+
timerId = setTimeout(timerExpired, waitMs);
|
|
30
35
|
return leading ? invokeFunc(time) : result;
|
|
31
36
|
}
|
|
32
37
|
function remainingWait(time) {
|
|
33
38
|
const timeSinceLastCall = time - (lastCallTime ?? 0);
|
|
34
39
|
const timeSinceLastInvoke = time - lastInvokeTime;
|
|
35
|
-
const timeWaiting =
|
|
40
|
+
const timeWaiting = waitMs - timeSinceLastCall;
|
|
36
41
|
return maxing ? Math.min(timeWaiting, (maxWait ?? 0) - timeSinceLastInvoke) : timeWaiting;
|
|
37
42
|
}
|
|
38
43
|
function shouldInvoke(time) {
|
|
39
44
|
const timeSinceLastCall = time - (lastCallTime ?? 0);
|
|
40
45
|
const timeSinceLastInvoke = time - lastInvokeTime;
|
|
41
|
-
return lastCallTime === void 0 || timeSinceLastCall >=
|
|
46
|
+
return lastCallTime === void 0 || timeSinceLastCall >= waitMs || timeSinceLastCall < 0 || maxing && timeSinceLastInvoke >= (maxWait ?? 0);
|
|
42
47
|
}
|
|
43
48
|
function timerExpired() {
|
|
44
49
|
const time = Date.now();
|
|
@@ -65,6 +70,30 @@ function debounce(func, wait, options) {
|
|
|
65
70
|
function flush() {
|
|
66
71
|
return timerId === void 0 ? result : trailingEdge(Date.now());
|
|
67
72
|
}
|
|
73
|
+
function pending() {
|
|
74
|
+
return timerId !== void 0;
|
|
75
|
+
}
|
|
76
|
+
function updateCb(callback) {
|
|
77
|
+
currentCallback = callback;
|
|
78
|
+
}
|
|
79
|
+
function updateParams(newWait, newOptions) {
|
|
80
|
+
waitMs = newWait;
|
|
81
|
+
if (newOptions !== void 0) {
|
|
82
|
+
currentOptions = newOptions;
|
|
83
|
+
}
|
|
84
|
+
applyOptions();
|
|
85
|
+
if (timerId !== void 0) {
|
|
86
|
+
const time = Date.now();
|
|
87
|
+
const shouldRun = shouldInvoke(time);
|
|
88
|
+
clearTimeout(timerId);
|
|
89
|
+
if (shouldRun) {
|
|
90
|
+
timerId = setTimeout(timerExpired, 0);
|
|
91
|
+
} else {
|
|
92
|
+
const delay = remainingWait(time);
|
|
93
|
+
timerId = setTimeout(timerExpired, delay > 0 ? delay : 0);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
68
97
|
function debounced() {
|
|
69
98
|
const time = Date.now();
|
|
70
99
|
const isInvoking = shouldInvoke(time);
|
|
@@ -77,21 +106,24 @@ function debounce(func, wait, options) {
|
|
|
77
106
|
}
|
|
78
107
|
if (maxing) {
|
|
79
108
|
clearTimeout(timerId);
|
|
80
|
-
timerId = setTimeout(timerExpired,
|
|
109
|
+
timerId = setTimeout(timerExpired, waitMs);
|
|
81
110
|
return invokeFunc(lastCallTime);
|
|
82
111
|
}
|
|
83
112
|
}
|
|
84
113
|
if (timerId === void 0) {
|
|
85
|
-
timerId = setTimeout(timerExpired,
|
|
114
|
+
timerId = setTimeout(timerExpired, waitMs);
|
|
86
115
|
}
|
|
87
116
|
return result;
|
|
88
117
|
}
|
|
89
118
|
debounced.cancel = cancel;
|
|
90
119
|
debounced.flush = flush;
|
|
120
|
+
debounced.pending = pending;
|
|
121
|
+
debounced.updateCb = updateCb;
|
|
122
|
+
debounced.updateParams = updateParams;
|
|
91
123
|
return debounced;
|
|
92
124
|
}
|
|
93
125
|
function isDebouncedFn(fn) {
|
|
94
|
-
return typeof fn === "function" && "cancel" in fn && "flush" in fn;
|
|
126
|
+
return typeof fn === "function" && "cancel" in fn && typeof fn.cancel === "function" && "flush" in fn && typeof fn.flush === "function" && "pending" in fn && typeof fn.pending === "function" && "updateCb" in fn && typeof fn.updateCb === "function" && "updateParams" in fn && typeof fn.updateParams === "function";
|
|
95
127
|
}
|
|
96
128
|
|
|
97
129
|
export {
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
// src/mathUtils.ts
|
|
2
|
+
function clampMax(value, max) {
|
|
3
|
+
return value > max ? max : value;
|
|
4
|
+
}
|
|
5
|
+
function clampMin(value, min) {
|
|
6
|
+
return value < min ? min : value;
|
|
7
|
+
}
|
|
8
|
+
function clampRange(num, v1, v2) {
|
|
9
|
+
if (v2 > v1) {
|
|
10
|
+
return clamp(num, v1, v2);
|
|
11
|
+
}
|
|
12
|
+
return clamp(num, v2, v1);
|
|
13
|
+
}
|
|
14
|
+
function clamp(num, min, max) {
|
|
15
|
+
return num > max ? max : num < min ? min : num;
|
|
16
|
+
}
|
|
17
|
+
function fixFloatingPointNumber(value) {
|
|
18
|
+
return Number(value.toPrecision(15));
|
|
19
|
+
}
|
|
20
|
+
function roundToStep(value, step, offset = 0) {
|
|
21
|
+
const inv = 1 / step;
|
|
22
|
+
const snapped = Math.round((value - offset) * inv) / inv + offset;
|
|
23
|
+
return Number(snapped.toFixed(12));
|
|
24
|
+
}
|
|
25
|
+
function floorToStep(value, step, offset = 0) {
|
|
26
|
+
const inv = 1 / step;
|
|
27
|
+
const snapped = Math.floor((value - offset) * inv) / inv + offset;
|
|
28
|
+
return Number(snapped.toFixed(12));
|
|
29
|
+
}
|
|
30
|
+
function ceilToStep(value, step, offset = 0) {
|
|
31
|
+
const inv = 1 / step;
|
|
32
|
+
const snapped = Math.ceil((value - offset) * inv) / inv + offset;
|
|
33
|
+
return Number(snapped.toFixed(12));
|
|
34
|
+
}
|
|
35
|
+
function round(num, precision) {
|
|
36
|
+
return Math.round(num * 10 ** precision) / 10 ** precision;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export {
|
|
40
|
+
clampMax,
|
|
41
|
+
clampMin,
|
|
42
|
+
clampRange,
|
|
43
|
+
clamp,
|
|
44
|
+
fixFloatingPointNumber,
|
|
45
|
+
roundToStep,
|
|
46
|
+
floorToStep,
|
|
47
|
+
ceilToStep,
|
|
48
|
+
round
|
|
49
|
+
};
|
|
@@ -60,6 +60,9 @@ function isInArray(value, oneOf) {
|
|
|
60
60
|
}
|
|
61
61
|
return false;
|
|
62
62
|
}
|
|
63
|
+
function looseIsInArray(value, array) {
|
|
64
|
+
return array.includes(value);
|
|
65
|
+
}
|
|
63
66
|
function findAfterIndex(array, index, predicate) {
|
|
64
67
|
for (let i = index + 1; i < array.length; i++) {
|
|
65
68
|
if (predicate(array[i])) {
|
|
@@ -161,6 +164,7 @@ export {
|
|
|
161
164
|
arrayWithPrev,
|
|
162
165
|
arrayWithPrevAndIndex,
|
|
163
166
|
isInArray,
|
|
167
|
+
looseIsInArray,
|
|
164
168
|
findAfterIndex,
|
|
165
169
|
findBeforeIndex,
|
|
166
170
|
rejectArrayUndefinedValues,
|
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
} from "./chunk-GMJTLFM6.js";
|
|
4
4
|
import {
|
|
5
5
|
sortBy
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-GVIDV772.js";
|
|
7
7
|
|
|
8
8
|
// src/objUtils.ts
|
|
9
9
|
import { Result } from "t-result";
|
|
@@ -17,14 +17,16 @@ function pick(obj, keys) {
|
|
|
17
17
|
}
|
|
18
18
|
return result;
|
|
19
19
|
}
|
|
20
|
-
function
|
|
20
|
+
function mapArrToObj(array, mapper) {
|
|
21
21
|
return Object.fromEntries(array.map(mapper));
|
|
22
22
|
}
|
|
23
|
-
|
|
23
|
+
var mapArrayToObject = mapArrToObj;
|
|
24
|
+
function mapObjToObj(obj, mapper) {
|
|
24
25
|
return Object.fromEntries(
|
|
25
26
|
objectTypedEntries(obj).map(([key, value]) => mapper(key, value))
|
|
26
27
|
);
|
|
27
28
|
}
|
|
29
|
+
var mapObjectToObject = mapObjToObj;
|
|
28
30
|
function omit(obj, keys) {
|
|
29
31
|
const result = {};
|
|
30
32
|
for (const key of Object.keys(obj)) {
|
|
@@ -136,16 +138,41 @@ function parsePath(path) {
|
|
|
136
138
|
function isNumericString(str) {
|
|
137
139
|
return /^\d+$/.test(str);
|
|
138
140
|
}
|
|
141
|
+
function getObjPropertyOrInsert(obj, prop, insertValue) {
|
|
142
|
+
if (obj[prop] === void 0) {
|
|
143
|
+
obj[prop] = insertValue();
|
|
144
|
+
}
|
|
145
|
+
return obj[prop];
|
|
146
|
+
}
|
|
147
|
+
function addPrefixToObjKeys(obj, prefix) {
|
|
148
|
+
const newObj = {};
|
|
149
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
150
|
+
newObj[`${prefix}${key}`] = value;
|
|
151
|
+
}
|
|
152
|
+
return newObj;
|
|
153
|
+
}
|
|
154
|
+
function addSuffixToObjKeys(obj, suffix) {
|
|
155
|
+
const newObj = {};
|
|
156
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
157
|
+
newObj[`${key}${suffix}`] = value;
|
|
158
|
+
}
|
|
159
|
+
return newObj;
|
|
160
|
+
}
|
|
139
161
|
|
|
140
162
|
export {
|
|
141
163
|
objectTypedEntries,
|
|
142
164
|
pick,
|
|
165
|
+
mapArrToObj,
|
|
143
166
|
mapArrayToObject,
|
|
167
|
+
mapObjToObj,
|
|
144
168
|
mapObjectToObject,
|
|
145
169
|
omit,
|
|
146
170
|
looseGetObjectProperty,
|
|
147
171
|
rejectObjUndefinedValues,
|
|
148
172
|
filterObjectKeys,
|
|
149
173
|
sortObjectKeys,
|
|
150
|
-
getValueFromPath
|
|
174
|
+
getValueFromPath,
|
|
175
|
+
getObjPropertyOrInsert,
|
|
176
|
+
addPrefixToObjKeys,
|
|
177
|
+
addSuffixToObjKeys
|
|
151
178
|
};
|
package/dist/concurrentCalls.js
CHANGED
|
@@ -3,8 +3,8 @@ import {
|
|
|
3
3
|
} from "./chunk-7CQPOM5I.js";
|
|
4
4
|
import {
|
|
5
5
|
durationObjToMs
|
|
6
|
-
} from "./chunk-
|
|
7
|
-
import "./chunk-
|
|
6
|
+
} from "./chunk-6FBIEPWU.js";
|
|
7
|
+
import "./chunk-DBOWTYR4.js";
|
|
8
8
|
import "./chunk-II4R3VVX.js";
|
|
9
9
|
import "./chunk-C2SVCIWE.js";
|
|
10
10
|
import "./chunk-JF2MDHOJ.js";
|
package/dist/debounce.cjs
CHANGED
|
@@ -25,6 +25,9 @@ __export(debounce_exports, {
|
|
|
25
25
|
});
|
|
26
26
|
module.exports = __toCommonJS(debounce_exports);
|
|
27
27
|
function debounce(func, wait, options) {
|
|
28
|
+
let currentCallback = func;
|
|
29
|
+
let waitMs = wait;
|
|
30
|
+
let currentOptions = options;
|
|
28
31
|
let lastArgs;
|
|
29
32
|
let lastThis;
|
|
30
33
|
let maxWait;
|
|
@@ -35,35 +38,37 @@ function debounce(func, wait, options) {
|
|
|
35
38
|
let leading = false;
|
|
36
39
|
let maxing = false;
|
|
37
40
|
let trailing = true;
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
41
|
+
function applyOptions() {
|
|
42
|
+
const opts = currentOptions;
|
|
43
|
+
leading = !!opts?.leading;
|
|
44
|
+
trailing = opts && "trailing" in opts ? !!opts.trailing : true;
|
|
45
|
+
maxing = !!(opts && "maxWait" in opts);
|
|
46
|
+
maxWait = maxing ? Math.max(opts?.maxWait ?? 0, waitMs) : void 0;
|
|
43
47
|
}
|
|
48
|
+
applyOptions();
|
|
44
49
|
function invokeFunc(time) {
|
|
45
50
|
const args = lastArgs;
|
|
46
51
|
const thisArg = lastThis;
|
|
47
52
|
lastArgs = lastThis = void 0;
|
|
48
53
|
lastInvokeTime = time;
|
|
49
|
-
result =
|
|
54
|
+
result = currentCallback.apply(thisArg, args);
|
|
50
55
|
return result;
|
|
51
56
|
}
|
|
52
57
|
function leadingEdge(time) {
|
|
53
58
|
lastInvokeTime = time;
|
|
54
|
-
timerId = setTimeout(timerExpired,
|
|
59
|
+
timerId = setTimeout(timerExpired, waitMs);
|
|
55
60
|
return leading ? invokeFunc(time) : result;
|
|
56
61
|
}
|
|
57
62
|
function remainingWait(time) {
|
|
58
63
|
const timeSinceLastCall = time - (lastCallTime ?? 0);
|
|
59
64
|
const timeSinceLastInvoke = time - lastInvokeTime;
|
|
60
|
-
const timeWaiting =
|
|
65
|
+
const timeWaiting = waitMs - timeSinceLastCall;
|
|
61
66
|
return maxing ? Math.min(timeWaiting, (maxWait ?? 0) - timeSinceLastInvoke) : timeWaiting;
|
|
62
67
|
}
|
|
63
68
|
function shouldInvoke(time) {
|
|
64
69
|
const timeSinceLastCall = time - (lastCallTime ?? 0);
|
|
65
70
|
const timeSinceLastInvoke = time - lastInvokeTime;
|
|
66
|
-
return lastCallTime === void 0 || timeSinceLastCall >=
|
|
71
|
+
return lastCallTime === void 0 || timeSinceLastCall >= waitMs || timeSinceLastCall < 0 || maxing && timeSinceLastInvoke >= (maxWait ?? 0);
|
|
67
72
|
}
|
|
68
73
|
function timerExpired() {
|
|
69
74
|
const time = Date.now();
|
|
@@ -90,6 +95,30 @@ function debounce(func, wait, options) {
|
|
|
90
95
|
function flush() {
|
|
91
96
|
return timerId === void 0 ? result : trailingEdge(Date.now());
|
|
92
97
|
}
|
|
98
|
+
function pending() {
|
|
99
|
+
return timerId !== void 0;
|
|
100
|
+
}
|
|
101
|
+
function updateCb(callback) {
|
|
102
|
+
currentCallback = callback;
|
|
103
|
+
}
|
|
104
|
+
function updateParams(newWait, newOptions) {
|
|
105
|
+
waitMs = newWait;
|
|
106
|
+
if (newOptions !== void 0) {
|
|
107
|
+
currentOptions = newOptions;
|
|
108
|
+
}
|
|
109
|
+
applyOptions();
|
|
110
|
+
if (timerId !== void 0) {
|
|
111
|
+
const time = Date.now();
|
|
112
|
+
const shouldRun = shouldInvoke(time);
|
|
113
|
+
clearTimeout(timerId);
|
|
114
|
+
if (shouldRun) {
|
|
115
|
+
timerId = setTimeout(timerExpired, 0);
|
|
116
|
+
} else {
|
|
117
|
+
const delay = remainingWait(time);
|
|
118
|
+
timerId = setTimeout(timerExpired, delay > 0 ? delay : 0);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
93
122
|
function debounced() {
|
|
94
123
|
const time = Date.now();
|
|
95
124
|
const isInvoking = shouldInvoke(time);
|
|
@@ -102,21 +131,24 @@ function debounce(func, wait, options) {
|
|
|
102
131
|
}
|
|
103
132
|
if (maxing) {
|
|
104
133
|
clearTimeout(timerId);
|
|
105
|
-
timerId = setTimeout(timerExpired,
|
|
134
|
+
timerId = setTimeout(timerExpired, waitMs);
|
|
106
135
|
return invokeFunc(lastCallTime);
|
|
107
136
|
}
|
|
108
137
|
}
|
|
109
138
|
if (timerId === void 0) {
|
|
110
|
-
timerId = setTimeout(timerExpired,
|
|
139
|
+
timerId = setTimeout(timerExpired, waitMs);
|
|
111
140
|
}
|
|
112
141
|
return result;
|
|
113
142
|
}
|
|
114
143
|
debounced.cancel = cancel;
|
|
115
144
|
debounced.flush = flush;
|
|
145
|
+
debounced.pending = pending;
|
|
146
|
+
debounced.updateCb = updateCb;
|
|
147
|
+
debounced.updateParams = updateParams;
|
|
116
148
|
return debounced;
|
|
117
149
|
}
|
|
118
150
|
function isDebouncedFn(fn) {
|
|
119
|
-
return typeof fn === "function" && "cancel" in fn && "flush" in fn;
|
|
151
|
+
return typeof fn === "function" && "cancel" in fn && typeof fn.cancel === "function" && "flush" in fn && typeof fn.flush === "function" && "pending" in fn && typeof fn.pending === "function" && "updateCb" in fn && typeof fn.updateCb === "function" && "updateParams" in fn && typeof fn.updateParams === "function";
|
|
120
152
|
}
|
|
121
153
|
// Annotate the CommonJS export names for ESM import in node:
|
|
122
154
|
0 && (module.exports = {
|
package/dist/debounce.d.cts
CHANGED
|
@@ -27,11 +27,20 @@ interface DebouncedFunc<T extends (...args: any[]) => void> {
|
|
|
27
27
|
* debounced function was never invoked.
|
|
28
28
|
*/
|
|
29
29
|
flush: () => ReturnType<T> | undefined;
|
|
30
|
+
/** Return true if the debounced function still has a scheduled run. */
|
|
31
|
+
pending: () => boolean;
|
|
32
|
+
/** Update the debounced function with a new callback. */
|
|
33
|
+
updateCb: (callback: T) => void;
|
|
34
|
+
/** Update the debounce wait and options while keeping scheduled runs. */
|
|
35
|
+
updateParams: (wait: number, options?: DebounceOptions) => void;
|
|
30
36
|
}
|
|
31
37
|
declare function debounce<T extends (...args: any[]) => void>(func: T, wait: number, options?: DebounceOptions): DebouncedFunc<T>;
|
|
32
38
|
declare function isDebouncedFn<T extends (...args: any[]) => void>(fn: T): fn is T & {
|
|
33
39
|
cancel: () => void;
|
|
34
40
|
flush: () => ReturnType<T> | undefined;
|
|
41
|
+
pending: () => boolean;
|
|
42
|
+
updateCb: (callback: T) => void;
|
|
43
|
+
updateParams: (wait: number, options?: DebounceOptions) => void;
|
|
35
44
|
};
|
|
36
45
|
|
|
37
46
|
export { type DebounceOptions, type DebouncedFunc, debounce, isDebouncedFn };
|
package/dist/debounce.d.ts
CHANGED
|
@@ -27,11 +27,20 @@ interface DebouncedFunc<T extends (...args: any[]) => void> {
|
|
|
27
27
|
* debounced function was never invoked.
|
|
28
28
|
*/
|
|
29
29
|
flush: () => ReturnType<T> | undefined;
|
|
30
|
+
/** Return true if the debounced function still has a scheduled run. */
|
|
31
|
+
pending: () => boolean;
|
|
32
|
+
/** Update the debounced function with a new callback. */
|
|
33
|
+
updateCb: (callback: T) => void;
|
|
34
|
+
/** Update the debounce wait and options while keeping scheduled runs. */
|
|
35
|
+
updateParams: (wait: number, options?: DebounceOptions) => void;
|
|
30
36
|
}
|
|
31
37
|
declare function debounce<T extends (...args: any[]) => void>(func: T, wait: number, options?: DebounceOptions): DebouncedFunc<T>;
|
|
32
38
|
declare function isDebouncedFn<T extends (...args: any[]) => void>(fn: T): fn is T & {
|
|
33
39
|
cancel: () => void;
|
|
34
40
|
flush: () => ReturnType<T> | undefined;
|
|
41
|
+
pending: () => boolean;
|
|
42
|
+
updateCb: (callback: T) => void;
|
|
43
|
+
updateParams: (wait: number, options?: DebounceOptions) => void;
|
|
35
44
|
};
|
|
36
45
|
|
|
37
46
|
export { type DebounceOptions, type DebouncedFunc, debounce, isDebouncedFn };
|
package/dist/debounce.js
CHANGED
package/dist/interpolate.js
CHANGED
package/dist/matchPath.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import {
|
|
2
2
|
fastCache
|
|
3
|
-
} from "./chunk-
|
|
4
|
-
import "./chunk-
|
|
5
|
-
import "./chunk-
|
|
3
|
+
} from "./chunk-DX2524CZ.js";
|
|
4
|
+
import "./chunk-6FBIEPWU.js";
|
|
5
|
+
import "./chunk-DBOWTYR4.js";
|
|
6
6
|
import "./chunk-II4R3VVX.js";
|
|
7
7
|
import "./chunk-C2SVCIWE.js";
|
|
8
8
|
import "./chunk-JF2MDHOJ.js";
|
package/dist/mathUtils.cjs
CHANGED
|
@@ -20,11 +20,15 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/mathUtils.ts
|
|
21
21
|
var mathUtils_exports = {};
|
|
22
22
|
__export(mathUtils_exports, {
|
|
23
|
+
ceilToStep: () => ceilToStep,
|
|
23
24
|
clamp: () => clamp,
|
|
24
25
|
clampMax: () => clampMax,
|
|
25
26
|
clampMin: () => clampMin,
|
|
26
27
|
clampRange: () => clampRange,
|
|
27
|
-
fixFloatingPointNumber: () => fixFloatingPointNumber
|
|
28
|
+
fixFloatingPointNumber: () => fixFloatingPointNumber,
|
|
29
|
+
floorToStep: () => floorToStep,
|
|
30
|
+
round: () => round,
|
|
31
|
+
roundToStep: () => roundToStep
|
|
28
32
|
});
|
|
29
33
|
module.exports = __toCommonJS(mathUtils_exports);
|
|
30
34
|
function clampMax(value, max) {
|
|
@@ -45,11 +49,33 @@ function clamp(num, min, max) {
|
|
|
45
49
|
function fixFloatingPointNumber(value) {
|
|
46
50
|
return Number(value.toPrecision(15));
|
|
47
51
|
}
|
|
52
|
+
function roundToStep(value, step, offset = 0) {
|
|
53
|
+
const inv = 1 / step;
|
|
54
|
+
const snapped = Math.round((value - offset) * inv) / inv + offset;
|
|
55
|
+
return Number(snapped.toFixed(12));
|
|
56
|
+
}
|
|
57
|
+
function floorToStep(value, step, offset = 0) {
|
|
58
|
+
const inv = 1 / step;
|
|
59
|
+
const snapped = Math.floor((value - offset) * inv) / inv + offset;
|
|
60
|
+
return Number(snapped.toFixed(12));
|
|
61
|
+
}
|
|
62
|
+
function ceilToStep(value, step, offset = 0) {
|
|
63
|
+
const inv = 1 / step;
|
|
64
|
+
const snapped = Math.ceil((value - offset) * inv) / inv + offset;
|
|
65
|
+
return Number(snapped.toFixed(12));
|
|
66
|
+
}
|
|
67
|
+
function round(num, precision) {
|
|
68
|
+
return Math.round(num * 10 ** precision) / 10 ** precision;
|
|
69
|
+
}
|
|
48
70
|
// Annotate the CommonJS export names for ESM import in node:
|
|
49
71
|
0 && (module.exports = {
|
|
72
|
+
ceilToStep,
|
|
50
73
|
clamp,
|
|
51
74
|
clampMax,
|
|
52
75
|
clampMin,
|
|
53
76
|
clampRange,
|
|
54
|
-
fixFloatingPointNumber
|
|
77
|
+
fixFloatingPointNumber,
|
|
78
|
+
floorToStep,
|
|
79
|
+
round,
|
|
80
|
+
roundToStep
|
|
55
81
|
});
|
package/dist/mathUtils.d.cts
CHANGED
|
@@ -3,5 +3,52 @@ declare function clampMin(value: number, min: number): number;
|
|
|
3
3
|
declare function clampRange(num: number, v1: number, v2: number): number;
|
|
4
4
|
declare function clamp(num: number, min: number, max: number): number;
|
|
5
5
|
declare function fixFloatingPointNumber(value: number): number;
|
|
6
|
+
/**
|
|
7
|
+
* Rounds a number to the nearest multiple of the specified step value.
|
|
8
|
+
*
|
|
9
|
+
* @param value - The number to round
|
|
10
|
+
* @param step - The step size to round to
|
|
11
|
+
* @param offset - Optional offset to shift the rounding grid
|
|
12
|
+
* @returns The rounded value
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* roundToStep(23, 5) // 25 (nearest multiple of 5)
|
|
16
|
+
*/
|
|
17
|
+
declare function roundToStep(value: number, step: number, offset?: number): number;
|
|
18
|
+
/**
|
|
19
|
+
* Floors a number down to the nearest multiple of the specified step value.
|
|
20
|
+
*
|
|
21
|
+
* @param value - The number to floor
|
|
22
|
+
* @param step - The step size to floor to
|
|
23
|
+
* @param offset - Optional offset to shift the flooring grid
|
|
24
|
+
* @returns The floored value
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* floorToStep(23, 5) // 20 (largest multiple of 5 ≤ 23)
|
|
28
|
+
*/
|
|
29
|
+
declare function floorToStep(value: number, step: number, offset?: number): number;
|
|
30
|
+
/**
|
|
31
|
+
* Ceils a number up to the nearest multiple of the specified step value.
|
|
32
|
+
*
|
|
33
|
+
* @param value - The number to ceil
|
|
34
|
+
* @param step - The step size to ceil to
|
|
35
|
+
* @param offset - Optional offset to shift the ceiling grid
|
|
36
|
+
* @returns The ceiled value
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* ceilToStep(23, 5) // 25 (smallest multiple of 5 ≥ 23)
|
|
40
|
+
*/
|
|
41
|
+
declare function ceilToStep(value: number, step: number, offset?: number): number;
|
|
42
|
+
/**
|
|
43
|
+
* Rounds a number to the specified number of decimal places.
|
|
44
|
+
*
|
|
45
|
+
* @param num - The number to round
|
|
46
|
+
* @param precision - Number of decimal places
|
|
47
|
+
* @returns The rounded number
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* round(3.14159, 2) // 3.14
|
|
51
|
+
*/
|
|
52
|
+
declare function round(num: number, precision: number): number;
|
|
6
53
|
|
|
7
|
-
export { clamp, clampMax, clampMin, clampRange, fixFloatingPointNumber };
|
|
54
|
+
export { ceilToStep, clamp, clampMax, clampMin, clampRange, fixFloatingPointNumber, floorToStep, round, roundToStep };
|
package/dist/mathUtils.d.ts
CHANGED
|
@@ -3,5 +3,52 @@ declare function clampMin(value: number, min: number): number;
|
|
|
3
3
|
declare function clampRange(num: number, v1: number, v2: number): number;
|
|
4
4
|
declare function clamp(num: number, min: number, max: number): number;
|
|
5
5
|
declare function fixFloatingPointNumber(value: number): number;
|
|
6
|
+
/**
|
|
7
|
+
* Rounds a number to the nearest multiple of the specified step value.
|
|
8
|
+
*
|
|
9
|
+
* @param value - The number to round
|
|
10
|
+
* @param step - The step size to round to
|
|
11
|
+
* @param offset - Optional offset to shift the rounding grid
|
|
12
|
+
* @returns The rounded value
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* roundToStep(23, 5) // 25 (nearest multiple of 5)
|
|
16
|
+
*/
|
|
17
|
+
declare function roundToStep(value: number, step: number, offset?: number): number;
|
|
18
|
+
/**
|
|
19
|
+
* Floors a number down to the nearest multiple of the specified step value.
|
|
20
|
+
*
|
|
21
|
+
* @param value - The number to floor
|
|
22
|
+
* @param step - The step size to floor to
|
|
23
|
+
* @param offset - Optional offset to shift the flooring grid
|
|
24
|
+
* @returns The floored value
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* floorToStep(23, 5) // 20 (largest multiple of 5 ≤ 23)
|
|
28
|
+
*/
|
|
29
|
+
declare function floorToStep(value: number, step: number, offset?: number): number;
|
|
30
|
+
/**
|
|
31
|
+
* Ceils a number up to the nearest multiple of the specified step value.
|
|
32
|
+
*
|
|
33
|
+
* @param value - The number to ceil
|
|
34
|
+
* @param step - The step size to ceil to
|
|
35
|
+
* @param offset - Optional offset to shift the ceiling grid
|
|
36
|
+
* @returns The ceiled value
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* ceilToStep(23, 5) // 25 (smallest multiple of 5 ≥ 23)
|
|
40
|
+
*/
|
|
41
|
+
declare function ceilToStep(value: number, step: number, offset?: number): number;
|
|
42
|
+
/**
|
|
43
|
+
* Rounds a number to the specified number of decimal places.
|
|
44
|
+
*
|
|
45
|
+
* @param num - The number to round
|
|
46
|
+
* @param precision - Number of decimal places
|
|
47
|
+
* @returns The rounded number
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* round(3.14159, 2) // 3.14
|
|
51
|
+
*/
|
|
52
|
+
declare function round(num: number, precision: number): number;
|
|
6
53
|
|
|
7
|
-
export { clamp, clampMax, clampMin, clampRange, fixFloatingPointNumber };
|
|
54
|
+
export { ceilToStep, clamp, clampMax, clampMin, clampRange, fixFloatingPointNumber, floorToStep, round, roundToStep };
|
package/dist/mathUtils.js
CHANGED
|
@@ -1,14 +1,22 @@
|
|
|
1
1
|
import {
|
|
2
|
+
ceilToStep,
|
|
2
3
|
clamp,
|
|
3
4
|
clampMax,
|
|
4
5
|
clampMin,
|
|
5
6
|
clampRange,
|
|
6
|
-
fixFloatingPointNumber
|
|
7
|
-
|
|
7
|
+
fixFloatingPointNumber,
|
|
8
|
+
floorToStep,
|
|
9
|
+
round,
|
|
10
|
+
roundToStep
|
|
11
|
+
} from "./chunk-DBOWTYR4.js";
|
|
8
12
|
export {
|
|
13
|
+
ceilToStep,
|
|
9
14
|
clamp,
|
|
10
15
|
clampMax,
|
|
11
16
|
clampMin,
|
|
12
17
|
clampRange,
|
|
13
|
-
fixFloatingPointNumber
|
|
18
|
+
fixFloatingPointNumber,
|
|
19
|
+
floorToStep,
|
|
20
|
+
round,
|
|
21
|
+
roundToStep
|
|
14
22
|
};
|
package/dist/objUtils.cjs
CHANGED
|
@@ -20,10 +20,15 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/objUtils.ts
|
|
21
21
|
var objUtils_exports = {};
|
|
22
22
|
__export(objUtils_exports, {
|
|
23
|
+
addPrefixToObjKeys: () => addPrefixToObjKeys,
|
|
24
|
+
addSuffixToObjKeys: () => addSuffixToObjKeys,
|
|
23
25
|
filterObjectKeys: () => filterObjectKeys,
|
|
26
|
+
getObjPropertyOrInsert: () => getObjPropertyOrInsert,
|
|
24
27
|
getValueFromPath: () => getValueFromPath,
|
|
25
28
|
looseGetObjectProperty: () => looseGetObjectProperty,
|
|
29
|
+
mapArrToObj: () => mapArrToObj,
|
|
26
30
|
mapArrayToObject: () => mapArrayToObject,
|
|
31
|
+
mapObjToObj: () => mapObjToObj,
|
|
27
32
|
mapObjectToObject: () => mapObjectToObject,
|
|
28
33
|
objectTypedEntries: () => objectTypedEntries,
|
|
29
34
|
omit: () => omit,
|
|
@@ -76,14 +81,16 @@ function pick(obj, keys) {
|
|
|
76
81
|
}
|
|
77
82
|
return result;
|
|
78
83
|
}
|
|
79
|
-
function
|
|
84
|
+
function mapArrToObj(array, mapper) {
|
|
80
85
|
return Object.fromEntries(array.map(mapper));
|
|
81
86
|
}
|
|
82
|
-
|
|
87
|
+
var mapArrayToObject = mapArrToObj;
|
|
88
|
+
function mapObjToObj(obj, mapper) {
|
|
83
89
|
return Object.fromEntries(
|
|
84
90
|
objectTypedEntries(obj).map(([key, value]) => mapper(key, value))
|
|
85
91
|
);
|
|
86
92
|
}
|
|
93
|
+
var mapObjectToObject = mapObjToObj;
|
|
87
94
|
function omit(obj, keys) {
|
|
88
95
|
const result = {};
|
|
89
96
|
for (const key of Object.keys(obj)) {
|
|
@@ -195,12 +202,37 @@ function parsePath(path) {
|
|
|
195
202
|
function isNumericString(str) {
|
|
196
203
|
return /^\d+$/.test(str);
|
|
197
204
|
}
|
|
205
|
+
function getObjPropertyOrInsert(obj, prop, insertValue) {
|
|
206
|
+
if (obj[prop] === void 0) {
|
|
207
|
+
obj[prop] = insertValue();
|
|
208
|
+
}
|
|
209
|
+
return obj[prop];
|
|
210
|
+
}
|
|
211
|
+
function addPrefixToObjKeys(obj, prefix) {
|
|
212
|
+
const newObj = {};
|
|
213
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
214
|
+
newObj[`${prefix}${key}`] = value;
|
|
215
|
+
}
|
|
216
|
+
return newObj;
|
|
217
|
+
}
|
|
218
|
+
function addSuffixToObjKeys(obj, suffix) {
|
|
219
|
+
const newObj = {};
|
|
220
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
221
|
+
newObj[`${key}${suffix}`] = value;
|
|
222
|
+
}
|
|
223
|
+
return newObj;
|
|
224
|
+
}
|
|
198
225
|
// Annotate the CommonJS export names for ESM import in node:
|
|
199
226
|
0 && (module.exports = {
|
|
227
|
+
addPrefixToObjKeys,
|
|
228
|
+
addSuffixToObjKeys,
|
|
200
229
|
filterObjectKeys,
|
|
230
|
+
getObjPropertyOrInsert,
|
|
201
231
|
getValueFromPath,
|
|
202
232
|
looseGetObjectProperty,
|
|
233
|
+
mapArrToObj,
|
|
203
234
|
mapArrayToObject,
|
|
235
|
+
mapObjToObj,
|
|
204
236
|
mapObjectToObject,
|
|
205
237
|
objectTypedEntries,
|
|
206
238
|
omit,
|
package/dist/objUtils.d.cts
CHANGED
|
@@ -8,13 +8,24 @@ import { MakeUndefinedKeysOptional } from './typeUtils.cjs';
|
|
|
8
8
|
*/
|
|
9
9
|
declare function objectTypedEntries<T extends Record<string, unknown>>(obj: T): [Extract<keyof T, string>, T[keyof T]][];
|
|
10
10
|
declare function pick<T extends Record<string, unknown>, K extends keyof T>(obj: T, keys: K[]): Pick<T, K>;
|
|
11
|
-
declare function
|
|
12
|
-
|
|
11
|
+
declare function mapArrToObj<T, K extends string, O>(array: T[], mapper: (item: T, index: number) => [K, O]): Record<K, O>;
|
|
12
|
+
/** @deprecated Use mapArrToObj instead */
|
|
13
|
+
declare const mapArrayToObject: typeof mapArrToObj;
|
|
14
|
+
declare function mapObjToObj<I extends Record<string | number | symbol, unknown>, K extends string | number | symbol, O>(obj: I, mapper: (key: keyof I, value: I[keyof I]) => [K, O]): Record<K, O>;
|
|
15
|
+
/** @deprecated Use mapObjToObj instead */
|
|
16
|
+
declare const mapObjectToObject: typeof mapObjToObj;
|
|
13
17
|
declare function omit<T extends Record<string, unknown>, K extends keyof T>(obj: T, keys: K[]): Omit<T, K>;
|
|
14
18
|
declare function looseGetObjectProperty<T extends Record<string, unknown>>(obj: T, key: string): T[keyof T] | undefined;
|
|
15
19
|
declare function rejectObjUndefinedValues<T extends Record<string, unknown>>(obj: T): MakeUndefinedKeysOptional<T>;
|
|
16
20
|
declare function filterObjectKeys<T extends Record<string, unknown>>(obj: T, predicate: (key: keyof T, value: T[keyof T]) => boolean): Partial<T>;
|
|
17
21
|
declare function sortObjectKeys<T extends Record<string, unknown>>(obj: T, sortByFn: SortByValueFn<[key: keyof T, value: T[keyof T]]>, options?: SortByProps): T;
|
|
18
22
|
declare function getValueFromPath(obj: Record<string, unknown>, path: string): Result<unknown, Error>;
|
|
23
|
+
declare function getObjPropertyOrInsert<T extends Record<string, any>, K extends keyof T>(obj: T, prop: K, insertValue: () => Exclude<T[K], undefined>): Exclude<T[K], undefined>;
|
|
24
|
+
declare function addPrefixToObjKeys<T extends Record<string, unknown>, P extends string>(obj: T, prefix: P): {
|
|
25
|
+
[K in keyof T & string as `${P}${K}`]: T[K];
|
|
26
|
+
};
|
|
27
|
+
declare function addSuffixToObjKeys<T extends Record<string, unknown>, S extends string>(obj: T, suffix: S): {
|
|
28
|
+
[K in keyof T & string as `${K}${S}`]: T[K];
|
|
29
|
+
};
|
|
19
30
|
|
|
20
|
-
export { filterObjectKeys, getValueFromPath, looseGetObjectProperty, mapArrayToObject, mapObjectToObject, objectTypedEntries, omit, pick, rejectObjUndefinedValues, sortObjectKeys };
|
|
31
|
+
export { addPrefixToObjKeys, addSuffixToObjKeys, filterObjectKeys, getObjPropertyOrInsert, getValueFromPath, looseGetObjectProperty, mapArrToObj, mapArrayToObject, mapObjToObj, mapObjectToObject, objectTypedEntries, omit, pick, rejectObjUndefinedValues, sortObjectKeys };
|
package/dist/objUtils.d.ts
CHANGED
|
@@ -8,13 +8,24 @@ import { MakeUndefinedKeysOptional } from './typeUtils.js';
|
|
|
8
8
|
*/
|
|
9
9
|
declare function objectTypedEntries<T extends Record<string, unknown>>(obj: T): [Extract<keyof T, string>, T[keyof T]][];
|
|
10
10
|
declare function pick<T extends Record<string, unknown>, K extends keyof T>(obj: T, keys: K[]): Pick<T, K>;
|
|
11
|
-
declare function
|
|
12
|
-
|
|
11
|
+
declare function mapArrToObj<T, K extends string, O>(array: T[], mapper: (item: T, index: number) => [K, O]): Record<K, O>;
|
|
12
|
+
/** @deprecated Use mapArrToObj instead */
|
|
13
|
+
declare const mapArrayToObject: typeof mapArrToObj;
|
|
14
|
+
declare function mapObjToObj<I extends Record<string | number | symbol, unknown>, K extends string | number | symbol, O>(obj: I, mapper: (key: keyof I, value: I[keyof I]) => [K, O]): Record<K, O>;
|
|
15
|
+
/** @deprecated Use mapObjToObj instead */
|
|
16
|
+
declare const mapObjectToObject: typeof mapObjToObj;
|
|
13
17
|
declare function omit<T extends Record<string, unknown>, K extends keyof T>(obj: T, keys: K[]): Omit<T, K>;
|
|
14
18
|
declare function looseGetObjectProperty<T extends Record<string, unknown>>(obj: T, key: string): T[keyof T] | undefined;
|
|
15
19
|
declare function rejectObjUndefinedValues<T extends Record<string, unknown>>(obj: T): MakeUndefinedKeysOptional<T>;
|
|
16
20
|
declare function filterObjectKeys<T extends Record<string, unknown>>(obj: T, predicate: (key: keyof T, value: T[keyof T]) => boolean): Partial<T>;
|
|
17
21
|
declare function sortObjectKeys<T extends Record<string, unknown>>(obj: T, sortByFn: SortByValueFn<[key: keyof T, value: T[keyof T]]>, options?: SortByProps): T;
|
|
18
22
|
declare function getValueFromPath(obj: Record<string, unknown>, path: string): Result<unknown, Error>;
|
|
23
|
+
declare function getObjPropertyOrInsert<T extends Record<string, any>, K extends keyof T>(obj: T, prop: K, insertValue: () => Exclude<T[K], undefined>): Exclude<T[K], undefined>;
|
|
24
|
+
declare function addPrefixToObjKeys<T extends Record<string, unknown>, P extends string>(obj: T, prefix: P): {
|
|
25
|
+
[K in keyof T & string as `${P}${K}`]: T[K];
|
|
26
|
+
};
|
|
27
|
+
declare function addSuffixToObjKeys<T extends Record<string, unknown>, S extends string>(obj: T, suffix: S): {
|
|
28
|
+
[K in keyof T & string as `${K}${S}`]: T[K];
|
|
29
|
+
};
|
|
19
30
|
|
|
20
|
-
export { filterObjectKeys, getValueFromPath, looseGetObjectProperty, mapArrayToObject, mapObjectToObject, objectTypedEntries, omit, pick, rejectObjUndefinedValues, sortObjectKeys };
|
|
31
|
+
export { addPrefixToObjKeys, addSuffixToObjKeys, filterObjectKeys, getObjPropertyOrInsert, getValueFromPath, looseGetObjectProperty, mapArrToObj, mapArrayToObject, mapObjToObj, mapObjectToObject, objectTypedEntries, omit, pick, rejectObjUndefinedValues, sortObjectKeys };
|
package/dist/objUtils.js
CHANGED
|
@@ -1,24 +1,34 @@
|
|
|
1
1
|
import {
|
|
2
|
+
addPrefixToObjKeys,
|
|
3
|
+
addSuffixToObjKeys,
|
|
2
4
|
filterObjectKeys,
|
|
5
|
+
getObjPropertyOrInsert,
|
|
3
6
|
getValueFromPath,
|
|
4
7
|
looseGetObjectProperty,
|
|
8
|
+
mapArrToObj,
|
|
5
9
|
mapArrayToObject,
|
|
10
|
+
mapObjToObj,
|
|
6
11
|
mapObjectToObject,
|
|
7
12
|
objectTypedEntries,
|
|
8
13
|
omit,
|
|
9
14
|
pick,
|
|
10
15
|
rejectObjUndefinedValues,
|
|
11
16
|
sortObjectKeys
|
|
12
|
-
} from "./chunk-
|
|
17
|
+
} from "./chunk-SGRS4OEE.js";
|
|
13
18
|
import "./chunk-GMJTLFM6.js";
|
|
14
|
-
import "./chunk-
|
|
19
|
+
import "./chunk-GVIDV772.js";
|
|
15
20
|
import "./chunk-C2SVCIWE.js";
|
|
16
21
|
import "./chunk-JF2MDHOJ.js";
|
|
17
22
|
export {
|
|
23
|
+
addPrefixToObjKeys,
|
|
24
|
+
addSuffixToObjKeys,
|
|
18
25
|
filterObjectKeys,
|
|
26
|
+
getObjPropertyOrInsert,
|
|
19
27
|
getValueFromPath,
|
|
20
28
|
looseGetObjectProperty,
|
|
29
|
+
mapArrToObj,
|
|
21
30
|
mapArrayToObject,
|
|
31
|
+
mapObjToObj,
|
|
22
32
|
mapObjectToObject,
|
|
23
33
|
objectTypedEntries,
|
|
24
34
|
omit,
|
package/dist/serializeXML.js
CHANGED
package/dist/testUtils.js
CHANGED
|
@@ -4,11 +4,11 @@ import {
|
|
|
4
4
|
import {
|
|
5
5
|
omit,
|
|
6
6
|
pick
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-SGRS4OEE.js";
|
|
8
8
|
import "./chunk-GMJTLFM6.js";
|
|
9
9
|
import {
|
|
10
10
|
filterObjectOrArrayKeys
|
|
11
|
-
} from "./chunk-
|
|
11
|
+
} from "./chunk-2LO5FYP5.js";
|
|
12
12
|
import "./chunk-IATIXMCE.js";
|
|
13
13
|
import {
|
|
14
14
|
deepEqual
|
|
@@ -21,12 +21,12 @@ import {
|
|
|
21
21
|
} from "./chunk-DFXNVEH6.js";
|
|
22
22
|
import {
|
|
23
23
|
clampMin
|
|
24
|
-
} from "./chunk-
|
|
24
|
+
} from "./chunk-DBOWTYR4.js";
|
|
25
25
|
import "./chunk-BM4PYVOX.js";
|
|
26
26
|
import {
|
|
27
27
|
arrayWithPrevAndIndex,
|
|
28
28
|
filterAndMap
|
|
29
|
-
} from "./chunk-
|
|
29
|
+
} from "./chunk-GVIDV772.js";
|
|
30
30
|
import {
|
|
31
31
|
isObject
|
|
32
32
|
} from "./chunk-C2SVCIWE.js";
|
package/dist/throttle.cjs
CHANGED
|
@@ -27,6 +27,9 @@ module.exports = __toCommonJS(throttle_exports);
|
|
|
27
27
|
|
|
28
28
|
// src/debounce.ts
|
|
29
29
|
function debounce(func, wait, options) {
|
|
30
|
+
let currentCallback = func;
|
|
31
|
+
let waitMs = wait;
|
|
32
|
+
let currentOptions = options;
|
|
30
33
|
let lastArgs;
|
|
31
34
|
let lastThis;
|
|
32
35
|
let maxWait;
|
|
@@ -37,35 +40,37 @@ function debounce(func, wait, options) {
|
|
|
37
40
|
let leading = false;
|
|
38
41
|
let maxing = false;
|
|
39
42
|
let trailing = true;
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
43
|
+
function applyOptions() {
|
|
44
|
+
const opts = currentOptions;
|
|
45
|
+
leading = !!opts?.leading;
|
|
46
|
+
trailing = opts && "trailing" in opts ? !!opts.trailing : true;
|
|
47
|
+
maxing = !!(opts && "maxWait" in opts);
|
|
48
|
+
maxWait = maxing ? Math.max(opts?.maxWait ?? 0, waitMs) : void 0;
|
|
45
49
|
}
|
|
50
|
+
applyOptions();
|
|
46
51
|
function invokeFunc(time) {
|
|
47
52
|
const args = lastArgs;
|
|
48
53
|
const thisArg = lastThis;
|
|
49
54
|
lastArgs = lastThis = void 0;
|
|
50
55
|
lastInvokeTime = time;
|
|
51
|
-
result =
|
|
56
|
+
result = currentCallback.apply(thisArg, args);
|
|
52
57
|
return result;
|
|
53
58
|
}
|
|
54
59
|
function leadingEdge(time) {
|
|
55
60
|
lastInvokeTime = time;
|
|
56
|
-
timerId = setTimeout(timerExpired,
|
|
61
|
+
timerId = setTimeout(timerExpired, waitMs);
|
|
57
62
|
return leading ? invokeFunc(time) : result;
|
|
58
63
|
}
|
|
59
64
|
function remainingWait(time) {
|
|
60
65
|
const timeSinceLastCall = time - (lastCallTime ?? 0);
|
|
61
66
|
const timeSinceLastInvoke = time - lastInvokeTime;
|
|
62
|
-
const timeWaiting =
|
|
67
|
+
const timeWaiting = waitMs - timeSinceLastCall;
|
|
63
68
|
return maxing ? Math.min(timeWaiting, (maxWait ?? 0) - timeSinceLastInvoke) : timeWaiting;
|
|
64
69
|
}
|
|
65
70
|
function shouldInvoke(time) {
|
|
66
71
|
const timeSinceLastCall = time - (lastCallTime ?? 0);
|
|
67
72
|
const timeSinceLastInvoke = time - lastInvokeTime;
|
|
68
|
-
return lastCallTime === void 0 || timeSinceLastCall >=
|
|
73
|
+
return lastCallTime === void 0 || timeSinceLastCall >= waitMs || timeSinceLastCall < 0 || maxing && timeSinceLastInvoke >= (maxWait ?? 0);
|
|
69
74
|
}
|
|
70
75
|
function timerExpired() {
|
|
71
76
|
const time = Date.now();
|
|
@@ -92,6 +97,30 @@ function debounce(func, wait, options) {
|
|
|
92
97
|
function flush() {
|
|
93
98
|
return timerId === void 0 ? result : trailingEdge(Date.now());
|
|
94
99
|
}
|
|
100
|
+
function pending() {
|
|
101
|
+
return timerId !== void 0;
|
|
102
|
+
}
|
|
103
|
+
function updateCb(callback) {
|
|
104
|
+
currentCallback = callback;
|
|
105
|
+
}
|
|
106
|
+
function updateParams(newWait, newOptions) {
|
|
107
|
+
waitMs = newWait;
|
|
108
|
+
if (newOptions !== void 0) {
|
|
109
|
+
currentOptions = newOptions;
|
|
110
|
+
}
|
|
111
|
+
applyOptions();
|
|
112
|
+
if (timerId !== void 0) {
|
|
113
|
+
const time = Date.now();
|
|
114
|
+
const shouldRun = shouldInvoke(time);
|
|
115
|
+
clearTimeout(timerId);
|
|
116
|
+
if (shouldRun) {
|
|
117
|
+
timerId = setTimeout(timerExpired, 0);
|
|
118
|
+
} else {
|
|
119
|
+
const delay = remainingWait(time);
|
|
120
|
+
timerId = setTimeout(timerExpired, delay > 0 ? delay : 0);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
95
124
|
function debounced() {
|
|
96
125
|
const time = Date.now();
|
|
97
126
|
const isInvoking = shouldInvoke(time);
|
|
@@ -104,17 +133,20 @@ function debounce(func, wait, options) {
|
|
|
104
133
|
}
|
|
105
134
|
if (maxing) {
|
|
106
135
|
clearTimeout(timerId);
|
|
107
|
-
timerId = setTimeout(timerExpired,
|
|
136
|
+
timerId = setTimeout(timerExpired, waitMs);
|
|
108
137
|
return invokeFunc(lastCallTime);
|
|
109
138
|
}
|
|
110
139
|
}
|
|
111
140
|
if (timerId === void 0) {
|
|
112
|
-
timerId = setTimeout(timerExpired,
|
|
141
|
+
timerId = setTimeout(timerExpired, waitMs);
|
|
113
142
|
}
|
|
114
143
|
return result;
|
|
115
144
|
}
|
|
116
145
|
debounced.cancel = cancel;
|
|
117
146
|
debounced.flush = flush;
|
|
147
|
+
debounced.pending = pending;
|
|
148
|
+
debounced.updateCb = updateCb;
|
|
149
|
+
debounced.updateParams = updateParams;
|
|
118
150
|
return debounced;
|
|
119
151
|
}
|
|
120
152
|
|
package/dist/throttle.js
CHANGED
package/dist/time.js
CHANGED
|
@@ -15,8 +15,8 @@ import {
|
|
|
15
15
|
getUnixSeconds,
|
|
16
16
|
msToTimeString,
|
|
17
17
|
parseTimeStringToMs
|
|
18
|
-
} from "./chunk-
|
|
19
|
-
import "./chunk-
|
|
18
|
+
} from "./chunk-6FBIEPWU.js";
|
|
19
|
+
import "./chunk-DBOWTYR4.js";
|
|
20
20
|
import "./chunk-II4R3VVX.js";
|
|
21
21
|
export {
|
|
22
22
|
DAY_AS_MS,
|
package/package.json
CHANGED
package/dist/chunk-HTCYUMDR.js
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
// src/mathUtils.ts
|
|
2
|
-
function clampMax(value, max) {
|
|
3
|
-
return value > max ? max : value;
|
|
4
|
-
}
|
|
5
|
-
function clampMin(value, min) {
|
|
6
|
-
return value < min ? min : value;
|
|
7
|
-
}
|
|
8
|
-
function clampRange(num, v1, v2) {
|
|
9
|
-
if (v2 > v1) {
|
|
10
|
-
return clamp(num, v1, v2);
|
|
11
|
-
}
|
|
12
|
-
return clamp(num, v2, v1);
|
|
13
|
-
}
|
|
14
|
-
function clamp(num, min, max) {
|
|
15
|
-
return num > max ? max : num < min ? min : num;
|
|
16
|
-
}
|
|
17
|
-
function fixFloatingPointNumber(value) {
|
|
18
|
-
return Number(value.toPrecision(15));
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export {
|
|
22
|
-
clampMax,
|
|
23
|
-
clampMin,
|
|
24
|
-
clampRange,
|
|
25
|
-
clamp,
|
|
26
|
-
fixFloatingPointNumber
|
|
27
|
-
};
|