@omnific/utils 0.0.5 → 0.1.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/debounce.js +5 -4
- package/dist/main.d.ts +2 -1
- package/dist/main.js +2 -1
- package/dist/uniqueId.d.ts +17 -0
- package/dist/uniqueId.js +20 -0
- package/package.json +1 -1
package/dist/debounce.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { isUndefined } from "./isUndefined.js";
|
|
2
|
+
import hasValue from "./hasValue.js";
|
|
2
3
|
//#region debounce.ts
|
|
3
4
|
/**
|
|
4
5
|
* Creates a debounced function that delays invoking the provided function until after `debounceMs` milliseconds
|
|
@@ -37,10 +38,10 @@ import { isUndefined } from "./isUndefined.js";
|
|
|
37
38
|
*/
|
|
38
39
|
function debounce(func, debounceMs, { signal, edges } = {}) {
|
|
39
40
|
let pendingInvoke;
|
|
40
|
-
const leading =
|
|
41
|
+
const leading = hasValue(edges) && edges.includes("leading");
|
|
41
42
|
const trailing = isUndefined(edges) || edges.includes("trailing");
|
|
42
43
|
const invoke = () => {
|
|
43
|
-
if (
|
|
44
|
+
if (hasValue(pendingInvoke)) {
|
|
44
45
|
pendingInvoke();
|
|
45
46
|
pendingInvoke = void 0;
|
|
46
47
|
}
|
|
@@ -51,14 +52,14 @@ function debounce(func, debounceMs, { signal, edges } = {}) {
|
|
|
51
52
|
};
|
|
52
53
|
let timeoutId;
|
|
53
54
|
const schedule = () => {
|
|
54
|
-
if (
|
|
55
|
+
if (hasValue(timeoutId)) clearTimeout(timeoutId);
|
|
55
56
|
timeoutId = setTimeout(() => {
|
|
56
57
|
timeoutId = void 0;
|
|
57
58
|
onTimerEnd();
|
|
58
59
|
}, debounceMs);
|
|
59
60
|
};
|
|
60
61
|
const cancelTimer = () => {
|
|
61
|
-
if (
|
|
62
|
+
if (hasValue(timeoutId)) {
|
|
62
63
|
clearTimeout(timeoutId);
|
|
63
64
|
timeoutId = void 0;
|
|
64
65
|
}
|
package/dist/main.d.ts
CHANGED
|
@@ -21,4 +21,5 @@ import { isUndefined } from "./isUndefined.js";
|
|
|
21
21
|
import { parseJson } from "./parseJson.js";
|
|
22
22
|
import { ThrottleOptions, ThrottledFunction, throttle } from "./throttle.js";
|
|
23
23
|
import resolveValue from "./resolveValue.js";
|
|
24
|
-
|
|
24
|
+
import { uniqueId } from "./uniqueId.js";
|
|
25
|
+
export { type ChainedFunction, type DebounceOptions, type DebouncedFunction, type ThrottleOptions, type ThrottledFunction, createChainedFunction, debounce, get, hasValue, isArray, isArrayBuffer, isBlob, isBoolean, isFormData, isFunction, isNil, isNull, isNumber, isObject, isPlainObject, isPromise, isString, isSymbol, isURLSearchParams, isUndefined, parseJson, resolveValue, throttle, uniqueId };
|
package/dist/main.js
CHANGED
|
@@ -21,4 +21,5 @@ import { isSymbol } from "./isSymbol.js";
|
|
|
21
21
|
import { get } from "./get.js";
|
|
22
22
|
import { throttle } from "./throttle.js";
|
|
23
23
|
import resolveValue from "./resolveValue.js";
|
|
24
|
-
|
|
24
|
+
import { uniqueId } from "./uniqueId.js";
|
|
25
|
+
export { createChainedFunction, debounce, get, hasValue, isArray, isArrayBuffer, isBlob, isBoolean, isFormData, isFunction, isNil, isNull, isNumber, isObject, isPlainObject, isPromise, isString, isSymbol, isURLSearchParams, isUndefined, parseJson, resolveValue, throttle, uniqueId };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
//#region uniqueId.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Generates a unique ID.
|
|
4
|
+
*
|
|
5
|
+
* If `prefix` is provided, the generated ID is appended to it.
|
|
6
|
+
*
|
|
7
|
+
* @param {string} prefix - The value to prefix the generated ID with.
|
|
8
|
+
* @returns {string} Returns the unique ID.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* uniqueId(); // '1'
|
|
12
|
+
* uniqueId('contact_'); // 'contact_2'
|
|
13
|
+
* uniqueId('contact_'); // 'contact_3'
|
|
14
|
+
*/
|
|
15
|
+
declare function uniqueId(prefix?: string): string;
|
|
16
|
+
//#endregion
|
|
17
|
+
export { uniqueId };
|
package/dist/uniqueId.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
//#region uniqueId.ts
|
|
2
|
+
let idCounter = 0;
|
|
3
|
+
/**
|
|
4
|
+
* Generates a unique ID.
|
|
5
|
+
*
|
|
6
|
+
* If `prefix` is provided, the generated ID is appended to it.
|
|
7
|
+
*
|
|
8
|
+
* @param {string} prefix - The value to prefix the generated ID with.
|
|
9
|
+
* @returns {string} Returns the unique ID.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* uniqueId(); // '1'
|
|
13
|
+
* uniqueId('contact_'); // 'contact_2'
|
|
14
|
+
* uniqueId('contact_'); // 'contact_3'
|
|
15
|
+
*/
|
|
16
|
+
function uniqueId(prefix = "") {
|
|
17
|
+
return `${prefix}${++idCounter}`;
|
|
18
|
+
}
|
|
19
|
+
//#endregion
|
|
20
|
+
export { uniqueId };
|