@omnific/utils 0.0.5 → 0.1.1

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 CHANGED
@@ -1,4 +1,6 @@
1
+ import hasValue from "./hasValue.js";
1
2
  import { isUndefined } from "./isUndefined.js";
3
+ import { isNil } from "./isNil.js";
2
4
  //#region debounce.ts
3
5
  /**
4
6
  * Creates a debounced function that delays invoking the provided function until after `debounceMs` milliseconds
@@ -37,13 +39,12 @@ import { isUndefined } from "./isUndefined.js";
37
39
  */
38
40
  function debounce(func, debounceMs, { signal, edges } = {}) {
39
41
  let pendingInvoke;
40
- const leading = !isUndefined(edges) && edges.includes("leading");
42
+ const leading = hasValue(edges) && edges.includes("leading");
41
43
  const trailing = isUndefined(edges) || edges.includes("trailing");
42
44
  const invoke = () => {
43
- if (!isUndefined(pendingInvoke)) {
44
- pendingInvoke();
45
- pendingInvoke = void 0;
46
- }
45
+ if (isNil(pendingInvoke)) return;
46
+ pendingInvoke();
47
+ pendingInvoke = void 0;
47
48
  };
48
49
  const onTimerEnd = () => {
49
50
  if (trailing) invoke();
@@ -51,17 +52,16 @@ function debounce(func, debounceMs, { signal, edges } = {}) {
51
52
  };
52
53
  let timeoutId;
53
54
  const schedule = () => {
54
- if (!isUndefined(timeoutId)) clearTimeout(timeoutId);
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 (!isUndefined(timeoutId)) {
62
- clearTimeout(timeoutId);
63
- timeoutId = void 0;
64
- }
62
+ if (isNil(timeoutId)) return;
63
+ clearTimeout(timeoutId);
64
+ timeoutId = void 0;
65
65
  };
66
66
  const cancel = () => {
67
67
  cancelTimer();
package/dist/hasValue.js CHANGED
@@ -1,4 +1,3 @@
1
- import { isNil } from "./isNil.js";
2
1
  //#region hasValue.ts
3
2
  /**
4
3
  * Checks whether a value is neither `null` nor `undefined`.
@@ -17,7 +16,7 @@ import { isNil } from "./isNil.js";
17
16
  * }
18
17
  */
19
18
  function hasValue(value) {
20
- return !isNil(value);
19
+ return value !== null && value !== void 0;
21
20
  }
22
21
  //#endregion
23
22
  export { hasValue as default, hasValue };
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
- 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 };
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
@@ -1,12 +1,12 @@
1
1
  import { isArray } from "./isArray.js";
2
2
  import { isBoolean } from "./isBoolean.js";
3
- import { isUndefined } from "./isUndefined.js";
4
- import { isNull } from "./isNull.js";
5
- import { isNil } from "./isNil.js";
6
3
  import hasValue from "./hasValue.js";
7
4
  import { isBlob } from "./isBlob.js";
8
5
  import { isFunction } from "./isFunction.js";
9
6
  import { createChainedFunction } from "./createChainedFunction.js";
7
+ import { isUndefined } from "./isUndefined.js";
8
+ import { isNull } from "./isNull.js";
9
+ import { isNil } from "./isNil.js";
10
10
  import { debounce } from "./debounce.js";
11
11
  import { isFormData } from "./isFormData.js";
12
12
  import { isNumber } from "./isNumber.js";
@@ -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
- export { createChainedFunction, debounce, get, hasValue, isArray, isArrayBuffer, isBlob, isBoolean, isFormData, isFunction, isNil, isNull, isNumber, isObject, isPlainObject, isPromise, isString, isSymbol, isURLSearchParams, isUndefined, parseJson, resolveValue, throttle };
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 };
@@ -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 };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@omnific/utils",
3
- "version": "0.0.5",
3
+ "version": "0.1.1",
4
4
  "description": "Shared utility predicates for Omnific packages",
5
5
  "license": "MIT",
6
6
  "type": "module",