@omnific/utils 0.1.1 → 0.3.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.
@@ -8,6 +8,9 @@ type GetFieldTypeOfNarrowedByLKR<T, L, K, R> = '' extends L ? '' extends R ? Get
8
8
  type GetFieldTypeOfNarrowed<T, X, XT extends 'DotPath' | 'Key' | 'Path'> = XT extends 'Key' ? GetFieldTypeOfNarrowedByKey<T, X> : XT extends 'DotPath' ? GetFieldTypeOfNarrowedByDotPath<T, X> : X extends `${infer L}['${infer K}']${infer R}` ? GetFieldTypeOfNarrowedByLKR<T, L, K, R> : X extends `${infer L}["${infer K}"]${infer R}` ? GetFieldTypeOfNarrowedByLKR<T, L, K, R> : X extends `${infer L}[${infer K}]${infer R}` ? GetFieldTypeOfNarrowedByLKR<T, L, K, R> : GetFieldTypeOfNarrowedByDotPath<T, X>;
9
9
  type GetFieldTypeOfObject<T, X, XT extends 'DotPath' | 'Key' | 'Path'> = Extract<T, unknown[]> extends never ? GetFieldTypeOfNarrowed<T, X, XT> : GetFieldTypeOfNarrowed<Exclude<T, unknown[]>, X, XT> | GetFieldTypeOfNarrowed<Extract<T, unknown[]>, X, XT>;
10
10
  type GetFieldTypeOfPrimitive<T, X, XT extends 'DotPath' | 'Key' | 'Path'> = Extract<T, string> extends never ? T extends never ? never : undefined : (Exclude<T, string> extends never ? never : undefined) | GetFieldTypeOfNarrowed<Extract<T, string>, X, XT>;
11
+ /**
12
+ * 解析指定键、点路径或括号路径对应的值类型。
13
+ */
11
14
  type GetFieldType<T, X, XT extends 'DotPath' | 'Key' | 'Path' = 'Path'> = Extract<T, object> extends never ? GetFieldTypeOfPrimitive<T, X, XT> : GetFieldTypeOfPrimitive<Exclude<T, object>, X, XT> | GetFieldTypeOfObject<Extract<T, object>, X, XT>;
12
15
  //#endregion
13
16
  export { GetFieldType };
@@ -1,4 +1,7 @@
1
1
  //#region @types/Many.d.ts
2
+ /**
3
+ * 表示单个值或只读值列表。
4
+ */
2
5
  type Many<T> = T | readonly T[];
3
6
  //#endregion
4
7
  export { Many };
@@ -1,6 +1,9 @@
1
1
  import { Many } from "./Many.js";
2
2
 
3
3
  //#region @types/PropertyPath.d.ts
4
+ /**
5
+ * 用于对象路径访问的单个属性键或只读属性键列表。
6
+ */
4
7
  type PropertyPath = Many<PropertyKey>;
5
8
  //#endregion
6
9
  export { PropertyPath };
@@ -1,6 +1,9 @@
1
1
  import { isString } from "../isString.js";
2
2
  import { isSymbol } from "../isSymbol.js";
3
3
  //#region _internal/toKey.ts
4
+ /**
5
+ * 将属性路径片段规范化为字符串键。
6
+ */
4
7
  function normalizeKey(path) {
5
8
  return Object.is(path?.valueOf?.(), -0) ? "-0" : String(path);
6
9
  }
@@ -2,7 +2,7 @@
2
2
  /**
3
3
  * A function with a bound `this` context and variadic arguments.
4
4
  */
5
- type ChainedFunction<TArgs extends any[], TThis> = (this: TThis, ...args: TArgs) => void;
5
+ type ChainedFunction<TArguments extends any[], TThis> = (this: TThis, ...arguments_: TArguments) => void;
6
6
  /**
7
7
  * Composes multiple callbacks into a single callback while preserving `this`.
8
8
  *
@@ -14,6 +14,6 @@ type ChainedFunction<TArgs extends any[], TThis> = (this: TThis, ...args: TArgs)
14
14
  * @param {...(ChainedFunction<TArgs, TThis> | null | undefined)[]} funcs - The callbacks to chain.
15
15
  * @returns {ChainedFunction<TArgs, TThis>} A single chained callback.
16
16
  */
17
- declare function createChainedFunction<TArgs extends any[], TThis>(...funcs: Array<ChainedFunction<TArgs, TThis> | null | undefined>): ChainedFunction<TArgs, TThis>;
17
+ declare function createChainedFunction<TArguments extends any[], TThis>(...funcs: Array<ChainedFunction<TArguments, TThis> | null | undefined>): ChainedFunction<TArguments, TThis>;
18
18
  //#endregion
19
19
  export { ChainedFunction, createChainedFunction, createChainedFunction as default };
@@ -1,3 +1,4 @@
1
+ import { isArrayEmpty } from "./isArrayEmpty.js";
1
2
  import { isFunction } from "./isFunction.js";
2
3
  //#region createChainedFunction.ts
3
4
  /**
@@ -12,11 +13,11 @@ import { isFunction } from "./isFunction.js";
12
13
  * @returns {ChainedFunction<TArgs, TThis>} A single chained callback.
13
14
  */
14
15
  function createChainedFunction(...funcs) {
15
- const validFuncs = funcs.filter((fn) => isFunction(fn));
16
- if (validFuncs.length === 0) return function() {};
16
+ const validFuncs = funcs.filter((function_) => isFunction(function_));
17
+ if (isArrayEmpty(validFuncs)) return function() {};
17
18
  if (validFuncs.length === 1) return validFuncs[0];
18
- return function(...args) {
19
- for (const fn of validFuncs) fn.apply(this, args);
19
+ return function(...arguments_) {
20
+ for (const function_ of validFuncs) function_.apply(this, arguments_);
20
21
  };
21
22
  }
22
23
  //#endregion
@@ -1,4 +1,7 @@
1
1
  //#region debounce.d.ts
2
+ /**
3
+ * 控制防抖函数何时调用或取消的选项。
4
+ */
2
5
  interface DebounceOptions {
3
6
  /**
4
7
  * An optional AbortSignal to cancel the debounced function.
@@ -13,8 +16,11 @@ interface DebounceOptions {
13
16
  */
14
17
  edges?: Array<'leading' | 'trailing'>;
15
18
  }
16
- interface DebouncedFunction<F extends (...args: any[]) => void> {
17
- (...args: Parameters<F>): void;
19
+ /**
20
+ * 带有调度、取消和立即执行控制能力的防抖函数。
21
+ */
22
+ interface DebouncedFunction<F extends (...arguments_: any[]) => void> {
23
+ (...arguments_: Parameters<F>): void;
18
24
  /**
19
25
  * Schedules the execution of the debounced function after the specified debounce delay.
20
26
  * This method resets any existing timer, ensuring that the function is only invoked
@@ -41,7 +47,7 @@ interface DebouncedFunction<F extends (...args: any[]) => void> {
41
47
  * method to cancel any pending execution.
42
48
  *
43
49
  * @template F - The type of function.
44
- * @param {F} func - The function to debounce.
50
+ * @param {F} function_ - The function to debounce.
45
51
  * @param {number} debounceMs - The number of milliseconds to delay.
46
52
  * @param {DebounceOptions} options - The options object
47
53
  * @param {AbortSignal} options.signal - An optional AbortSignal to cancel the debounced function.
@@ -70,7 +76,7 @@ interface DebouncedFunction<F extends (...args: any[]) => void> {
70
76
  * // Will cancel the debounced function call
71
77
  * controller.abort();
72
78
  */
73
- declare function debounce<F extends (...args: any[]) => void>(func: F, debounceMs: number, {
79
+ declare function debounce<F extends (...arguments_: any[]) => void>(function_: F, debounceMs: number, {
74
80
  signal,
75
81
  edges
76
82
  }?: DebounceOptions): DebouncedFunction<F>;
package/dist/debounce.js CHANGED
@@ -1,6 +1,6 @@
1
- import hasValue from "./hasValue.js";
2
1
  import { isUndefined } from "./isUndefined.js";
3
2
  import { isNil } from "./isNil.js";
3
+ import hasValue from "./hasValue.js";
4
4
  //#region debounce.ts
5
5
  /**
6
6
  * Creates a debounced function that delays invoking the provided function until after `debounceMs` milliseconds
@@ -8,7 +8,7 @@ import { isNil } from "./isNil.js";
8
8
  * method to cancel any pending execution.
9
9
  *
10
10
  * @template F - The type of function.
11
- * @param {F} func - The function to debounce.
11
+ * @param {F} function_ - The function to debounce.
12
12
  * @param {number} debounceMs - The number of milliseconds to delay.
13
13
  * @param {DebounceOptions} options - The options object
14
14
  * @param {AbortSignal} options.signal - An optional AbortSignal to cancel the debounced function.
@@ -37,7 +37,7 @@ import { isNil } from "./isNil.js";
37
37
  * // Will cancel the debounced function call
38
38
  * controller.abort();
39
39
  */
40
- function debounce(func, debounceMs, { signal, edges } = {}) {
40
+ function debounce(function_, debounceMs, { signal, edges } = {}) {
41
41
  let pendingInvoke;
42
42
  const leading = hasValue(edges) && edges.includes("leading");
43
43
  const trailing = isUndefined(edges) || edges.includes("trailing");
@@ -71,10 +71,10 @@ function debounce(func, debounceMs, { signal, edges } = {}) {
71
71
  cancelTimer();
72
72
  invoke();
73
73
  };
74
- const debounced = function(...args) {
74
+ const debounced = function(...arguments_) {
75
75
  if (signal?.aborted) return;
76
76
  pendingInvoke = () => {
77
- func.apply(this, args);
77
+ function_.apply(this, arguments_);
78
78
  };
79
79
  const isFirstCall = isUndefined(timeoutId);
80
80
  schedule();
package/dist/get.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import { isUndefined } from "./isUndefined.js";
2
2
  import { isNil } from "./isNil.js";
3
+ import { isArrayEmpty } from "./isArrayEmpty.js";
3
4
  import { isNumber } from "./isNumber.js";
4
5
  import { isString } from "./isString.js";
5
6
  import { isUnsafeProperty } from "./_internal/isUnsafeProperty.js";
@@ -41,7 +42,7 @@ function get(object, path, defaultValue) {
41
42
  return getDirect(object, normalizeKey(path), defaultValue);
42
43
  }
43
44
  function getWithPath(object, path, defaultValue) {
44
- if (path.length === 0) return defaultValue;
45
+ if (isArrayEmpty(path)) return defaultValue;
45
46
  let current = object;
46
47
  for (const element of path) {
47
48
  if (isNil(current) || isUnsafeProperty(element)) return defaultValue;
@@ -0,0 +1,9 @@
1
+ //#region isArrayEmpty.d.ts
2
+ /**
3
+ * Checks whether a value is nullish or an empty array.
4
+ *
5
+ * `null`, `undefined`, and arrays without elements are considered empty.
6
+ */
7
+ declare function isArrayEmpty<T>(value: readonly T[] | null | undefined): value is null | undefined | readonly [];
8
+ //#endregion
9
+ export { isArrayEmpty };
@@ -0,0 +1,13 @@
1
+ import { isNil } from "./isNil.js";
2
+ //#region isArrayEmpty.ts
3
+ /**
4
+ * Checks whether a value is nullish or an empty array.
5
+ *
6
+ * `null`, `undefined`, and arrays without elements are considered empty.
7
+ */
8
+ function isArrayEmpty(value) {
9
+ if (isNil(value)) return true;
10
+ return value.length === 0;
11
+ }
12
+ //#endregion
13
+ export { isArrayEmpty };
@@ -12,6 +12,6 @@
12
12
  * isFunction(Proxy); // true
13
13
  * isFunction(Int8Array); // true
14
14
  */
15
- declare function isFunction(value: any): value is (...args: any[]) => any;
15
+ declare function isFunction(value: any): value is (...arguments_: any[]) => any;
16
16
  //#endregion
17
17
  export { isFunction };
package/dist/isNumber.js CHANGED
@@ -22,7 +22,8 @@
22
22
  *
23
23
  */
24
24
  function isNumber(value) {
25
- return typeof value === "number" && !Number.isNaN(value);
25
+ if (Number.isNaN(value)) return false;
26
+ return typeof value === "number";
26
27
  }
27
28
  //#endregion
28
29
  export { isNumber };
@@ -45,8 +45,8 @@ import { isObject } from "./isObject.js";
45
45
  */
46
46
  function isPlainObject(value) {
47
47
  if (!isObject(value)) return false;
48
- const proto = Object.getPrototypeOf(value);
49
- if (!(isNull(proto) || proto === Object.prototype || isNull(Object.getPrototypeOf(proto)))) return false;
48
+ const prototype = Object.getPrototypeOf(value);
49
+ if (!(isNull(prototype) || prototype === Object.prototype || isNull(Object.getPrototypeOf(prototype)))) return false;
50
50
  return Object.prototype.toString.call(value) === "[object Object]";
51
51
  }
52
52
  //#endregion
package/dist/isPromise.js CHANGED
@@ -1,3 +1,4 @@
1
+ import hasValue from "./hasValue.js";
1
2
  import { isFunction } from "./isFunction.js";
2
3
  import { isObject } from "./isObject.js";
3
4
  //#region isPromise.ts
@@ -19,7 +20,7 @@ import { isObject } from "./isObject.js";
19
20
  * console.log(isPromise(value3)); // false
20
21
  */
21
22
  function isPromise(value) {
22
- return value !== null && (isObject(value) || isFunction(value)) && typeof value.then === "function";
23
+ return hasValue(value) && (isObject(value) || isFunction(value)) && isFunction(value.then);
23
24
  }
24
25
  //#endregion
25
26
  export { isPromise };
@@ -0,0 +1,9 @@
1
+ //#region isStringEmpty.d.ts
2
+ /**
3
+ * Checks whether a value is nullish or an empty string.
4
+ *
5
+ * `null`, `undefined`, and whitespace-only strings are considered empty.
6
+ */
7
+ declare function isStringEmpty(value: string | null | undefined): value is null | undefined;
8
+ //#endregion
9
+ export { isStringEmpty };
@@ -0,0 +1,13 @@
1
+ import { isNil } from "./isNil.js";
2
+ //#region isStringEmpty.ts
3
+ /**
4
+ * Checks whether a value is nullish or an empty string.
5
+ *
6
+ * `null`, `undefined`, and whitespace-only strings are considered empty.
7
+ */
8
+ function isStringEmpty(value) {
9
+ if (isNil(value)) return true;
10
+ return value.trim().length === 0;
11
+ }
12
+ //#endregion
13
+ export { isStringEmpty };
@@ -1,4 +1,4 @@
1
- //#region isURLSearchParams.d.ts
1
+ //#region isURLSearchParameters.d.ts
2
2
  /**
3
3
  * Checks if a given value is `URLSearchParams`.
4
4
  *
@@ -12,10 +12,10 @@
12
12
  * const value2 = new FormData();
13
13
  * const value3 = 'a=1';
14
14
  *
15
- * console.log(isURLSearchParams(value1)); // true
16
- * console.log(isURLSearchParams(value2)); // false
17
- * console.log(isURLSearchParams(value3)); // false
15
+ * console.log(isURLSearchParameters(value1)); // true
16
+ * console.log(isURLSearchParameters(value2)); // false
17
+ * console.log(isURLSearchParameters(value3)); // false
18
18
  */
19
- declare function isURLSearchParams(value: unknown): value is URLSearchParams;
19
+ declare function isURLSearchParameters(value: unknown): value is URLSearchParams;
20
20
  //#endregion
21
- export { isURLSearchParams };
21
+ export { isURLSearchParameters };
@@ -1,5 +1,5 @@
1
1
  import hasValue from "./hasValue.js";
2
- //#region isURLSearchParams.ts
2
+ //#region isURLSearchParameters.ts
3
3
  /**
4
4
  * Checks if a given value is `URLSearchParams`.
5
5
  *
@@ -13,12 +13,12 @@ import hasValue from "./hasValue.js";
13
13
  * const value2 = new FormData();
14
14
  * const value3 = 'a=1';
15
15
  *
16
- * console.log(isURLSearchParams(value1)); // true
17
- * console.log(isURLSearchParams(value2)); // false
18
- * console.log(isURLSearchParams(value3)); // false
16
+ * console.log(isURLSearchParameters(value1)); // true
17
+ * console.log(isURLSearchParameters(value2)); // false
18
+ * console.log(isURLSearchParameters(value3)); // false
19
19
  */
20
- function isURLSearchParams(value) {
20
+ function isURLSearchParameters(value) {
21
21
  return hasValue(value) && value instanceof URLSearchParams;
22
22
  }
23
23
  //#endregion
24
- export { isURLSearchParams };
24
+ export { isURLSearchParameters };
package/dist/main.d.ts CHANGED
@@ -4,6 +4,7 @@ import { get } from "./get.js";
4
4
  import hasValue from "./hasValue.js";
5
5
  import { isArray } from "./isArray.js";
6
6
  import { isArrayBuffer } from "./isArrayBuffer.js";
7
+ import { isArrayEmpty } from "./isArrayEmpty.js";
7
8
  import { isBlob } from "./isBlob.js";
8
9
  import { isBoolean } from "./isBoolean.js";
9
10
  import { isFormData } from "./isFormData.js";
@@ -15,11 +16,12 @@ import { isObject } from "./isObject.js";
15
16
  import { isPlainObject } from "./isPlainObject.js";
16
17
  import { isPromise } from "./isPromise.js";
17
18
  import { isString } from "./isString.js";
19
+ import { isStringEmpty } from "./isStringEmpty.js";
18
20
  import { isSymbol } from "./isSymbol.js";
19
- import { isURLSearchParams } from "./isURLSearchParams.js";
21
+ import { isURLSearchParameters } from "./isURLSearchParameters.js";
20
22
  import { isUndefined } from "./isUndefined.js";
21
23
  import { parseJson } from "./parseJson.js";
22
24
  import { ThrottleOptions, ThrottledFunction, throttle } from "./throttle.js";
23
25
  import resolveValue from "./resolveValue.js";
24
26
  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 };
27
+ export { type ChainedFunction, type DebounceOptions, type DebouncedFunction, type ThrottleOptions, type ThrottledFunction, createChainedFunction, debounce, get, hasValue, isArray, isArrayBuffer, isArrayEmpty, isBlob, isBoolean, isFormData, isFunction, isNil, isNull, isNumber, isObject, isPlainObject, isPromise, isString, isStringEmpty, isSymbol, isURLSearchParameters, isUndefined, parseJson, resolveValue, throttle, uniqueId };
package/dist/main.js CHANGED
@@ -1,25 +1,27 @@
1
1
  import { isArray } from "./isArray.js";
2
+ import { isUndefined } from "./isUndefined.js";
3
+ import { isNull } from "./isNull.js";
4
+ import { isNil } from "./isNil.js";
5
+ import { isArrayEmpty } from "./isArrayEmpty.js";
2
6
  import { isBoolean } from "./isBoolean.js";
3
7
  import hasValue from "./hasValue.js";
4
8
  import { isBlob } from "./isBlob.js";
5
9
  import { isFunction } from "./isFunction.js";
6
10
  import { createChainedFunction } from "./createChainedFunction.js";
7
- import { isUndefined } from "./isUndefined.js";
8
- import { isNull } from "./isNull.js";
9
- import { isNil } from "./isNil.js";
10
11
  import { debounce } from "./debounce.js";
11
12
  import { isFormData } from "./isFormData.js";
12
13
  import { isNumber } from "./isNumber.js";
13
14
  import { isObject } from "./isObject.js";
14
15
  import { isPlainObject } from "./isPlainObject.js";
15
16
  import { isString } from "./isString.js";
17
+ import { isStringEmpty } from "./isStringEmpty.js";
16
18
  import { isPromise } from "./isPromise.js";
17
19
  import { isArrayBuffer } from "./isArrayBuffer.js";
18
- import { isURLSearchParams } from "./isURLSearchParams.js";
20
+ import { isURLSearchParameters } from "./isURLSearchParameters.js";
19
21
  import { parseJson } from "./parseJson.js";
20
22
  import { isSymbol } from "./isSymbol.js";
21
23
  import { get } from "./get.js";
22
24
  import { throttle } from "./throttle.js";
23
25
  import resolveValue from "./resolveValue.js";
24
26
  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 };
27
+ export { createChainedFunction, debounce, get, hasValue, isArray, isArrayBuffer, isArrayEmpty, isBlob, isBoolean, isFormData, isFunction, isNil, isNull, isNumber, isObject, isPlainObject, isPromise, isString, isStringEmpty, isSymbol, isURLSearchParameters, isUndefined, parseJson, resolveValue, throttle, uniqueId };
package/dist/parseJson.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { isStringEmpty } from "./isStringEmpty.js";
1
2
  //#region parseJson.ts
2
3
  /**
3
4
  * Parses JSON text into a value.
@@ -6,7 +7,7 @@
6
7
  * returns the fallback instead of throwing.
7
8
  */
8
9
  function parseJson(text, fallback) {
9
- if (!text.trim()) return;
10
+ if (isStringEmpty(text)) return;
10
11
  try {
11
12
  return JSON.parse(text);
12
13
  } catch (error) {
@@ -12,6 +12,6 @@
12
12
  * resolveValue('ready');
13
13
  * resolveValue(status => status === 'error' ? 'retry' : 'ok', 'error');
14
14
  */
15
- declare function resolveValue<TValue, TArgs extends any[]>(value: TValue | ((...args: TArgs) => TValue), ...args: TArgs): TValue;
15
+ declare function resolveValue<TValue, TArguments extends any[]>(value: TValue | ((...arguments_: TArguments) => TValue), ...arguments_: TArguments): TValue;
16
16
  //#endregion
17
17
  export { resolveValue as default, resolveValue };
@@ -13,8 +13,8 @@ import { isFunction } from "./isFunction.js";
13
13
  * resolveValue('ready');
14
14
  * resolveValue(status => status === 'error' ? 'retry' : 'ok', 'error');
15
15
  */
16
- function resolveValue(value, ...args) {
17
- if (isFunction(value)) return value(...args);
16
+ function resolveValue(value, ...arguments_) {
17
+ if (isFunction(value)) return value(...arguments_);
18
18
  return value;
19
19
  }
20
20
  //#endregion
@@ -1,4 +1,7 @@
1
1
  //#region throttle.d.ts
2
+ /**
3
+ * 控制节流函数何时调用或取消的选项。
4
+ */
2
5
  interface ThrottleOptions {
3
6
  /**
4
7
  * An optional AbortSignal to cancel the throttled function.
@@ -13,8 +16,11 @@ interface ThrottleOptions {
13
16
  */
14
17
  edges?: Array<'leading' | 'trailing'>;
15
18
  }
16
- interface ThrottledFunction<F extends (...args: any[]) => void> {
17
- (...args: Parameters<F>): void;
19
+ /**
20
+ * 带有取消和立即执行控制能力的节流函数。
21
+ */
22
+ interface ThrottledFunction<F extends (...arguments_: any[]) => void> {
23
+ (...arguments_: Parameters<F>): void;
18
24
  cancel: () => void;
19
25
  flush: () => void;
20
26
  }
@@ -24,7 +30,7 @@ interface ThrottledFunction<F extends (...args: any[]) => void> {
24
30
  * within the wait time will not trigger the execution of the original function.
25
31
  *
26
32
  * @template F - The type of function.
27
- * @param {F} func - The function to throttle.
33
+ * @param {F} function_ - The function to throttle.
28
34
  * @param {number} throttleMs - The number of milliseconds to throttle executions to.
29
35
  * @returns {(...args: Parameters<F>) => void} A new throttled function that accepts the same parameters as the original function.
30
36
  *
@@ -44,7 +50,7 @@ interface ThrottledFunction<F extends (...args: any[]) => void> {
44
50
  * throttledFunction(); // Will log 'Function executed'
45
51
  * }, 1000);
46
52
  */
47
- declare function throttle<F extends (...args: any[]) => void>(func: F, throttleMs: number, {
53
+ declare function throttle<F extends (...arguments_: any[]) => void>(function_: F, throttleMs: number, {
48
54
  signal,
49
55
  edges
50
56
  }?: ThrottleOptions): ThrottledFunction<F>;
package/dist/throttle.js CHANGED
@@ -7,7 +7,7 @@ import { debounce } from "./debounce.js";
7
7
  * within the wait time will not trigger the execution of the original function.
8
8
  *
9
9
  * @template F - The type of function.
10
- * @param {F} func - The function to throttle.
10
+ * @param {F} function_ - The function to throttle.
11
11
  * @param {number} throttleMs - The number of milliseconds to throttle executions to.
12
12
  * @returns {(...args: Parameters<F>) => void} A new throttled function that accepts the same parameters as the original function.
13
13
  *
@@ -27,25 +27,25 @@ import { debounce } from "./debounce.js";
27
27
  * throttledFunction(); // Will log 'Function executed'
28
28
  * }, 1000);
29
29
  */
30
- function throttle(func, throttleMs, { signal, edges = ["leading", "trailing"] } = {}) {
30
+ function throttle(function_, throttleMs, { signal, edges = ["leading", "trailing"] } = {}) {
31
31
  let pendingAt;
32
- const debounced = debounce(function(...args) {
32
+ const debounced = debounce(function(...arguments_) {
33
33
  pendingAt = Date.now();
34
- func.apply(this, args);
34
+ function_.apply(this, arguments_);
35
35
  }, throttleMs, {
36
36
  signal,
37
37
  edges
38
38
  });
39
- const throttled = function(...args) {
39
+ const throttled = function(...arguments_) {
40
40
  if (isUndefined(pendingAt)) pendingAt = Date.now();
41
41
  if (Date.now() - pendingAt >= throttleMs) {
42
42
  pendingAt = Date.now();
43
- func.apply(this, args);
43
+ function_.apply(this, arguments_);
44
44
  debounced.cancel();
45
45
  debounced.schedule();
46
46
  return;
47
47
  }
48
- debounced.apply(this, args);
48
+ debounced.apply(this, arguments_);
49
49
  };
50
50
  throttled.cancel = () => {
51
51
  pendingAt = void 0;
package/dist/uniqueId.js CHANGED
@@ -1,5 +1,5 @@
1
1
  //#region uniqueId.ts
2
- let idCounter = 0;
2
+ const uniqueIdCounter = { value: 0 };
3
3
  /**
4
4
  * Generates a unique ID.
5
5
  *
@@ -14,7 +14,7 @@ let idCounter = 0;
14
14
  * uniqueId('contact_'); // 'contact_3'
15
15
  */
16
16
  function uniqueId(prefix = "") {
17
- return `${prefix}${++idCounter}`;
17
+ return `${prefix}${++uniqueIdCounter.value}`;
18
18
  }
19
19
  //#endregion
20
20
  export { uniqueId };
@@ -1,3 +1,4 @@
1
+ import { isSymbol } from "../isSymbol.js";
1
2
  import { toKey } from "../_internal/toKey.js";
2
3
  import { toString } from "./toString.js";
3
4
  //#region utils/toPath.ts
@@ -20,7 +21,7 @@ import { toString } from "./toString.js";
20
21
  */
21
22
  function toPath(deepKey) {
22
23
  if (Array.isArray(deepKey)) return deepKey.map((item) => toKey(item));
23
- if (typeof deepKey === "symbol") return [deepKey];
24
+ if (isSymbol(deepKey)) return [deepKey];
24
25
  deepKey = toString(deepKey);
25
26
  const result = [];
26
27
  const length = deepKey.length;
@@ -28,7 +29,7 @@ function toPath(deepKey) {
28
29
  let index = 0;
29
30
  let key = "";
30
31
  let quoteChar = "";
31
- let bracket = false;
32
+ let isBracket = false;
32
33
  if (deepKey.codePointAt(0) === 46) {
33
34
  result.push("");
34
35
  index++;
@@ -40,14 +41,14 @@ function toPath(deepKey) {
40
41
  key += deepKey[index];
41
42
  } else if (char === quoteChar) quoteChar = "";
42
43
  else key += char;
43
- else if (bracket) if (char === "\"" || char === "'") quoteChar = char;
44
+ else if (isBracket) if (char === "\"" || char === "'") quoteChar = char;
44
45
  else if (char === "]") {
45
- bracket = false;
46
+ isBracket = false;
46
47
  result.push(key);
47
48
  key = "";
48
49
  } else key += char;
49
50
  else if (char === "[") {
50
- bracket = true;
51
+ isBracket = true;
51
52
  if (key) {
52
53
  result.push(key);
53
54
  key = "";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@omnific/utils",
3
- "version": "0.1.1",
3
+ "version": "0.3.0",
4
4
  "description": "Shared utility predicates for Omnific packages",
5
5
  "license": "MIT",
6
6
  "type": "module",