nhb-toolbox 2.1.9 → 2.2.9

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/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  export { capitalizeString, generateRandomID, trimString, truncateString, } from './string/basics';
2
2
  export { generateAnagrams } from './string/anagram';
3
3
  export { convertStringCase, replaceAllInString } from './string/convert';
4
- export { convertToDecimal, getRandomNumber } from './number/basics';
4
+ export { calculateHCF as calculateGCD, calculateHCF, calculateLCM as calculateLCD, calculateLCM, convertToDecimal, getRandomNumber, } from './number/basics';
5
5
  export { numberToWords } from './number/convert';
6
6
  export { findPrimeNumbers, isPrime } from './number/prime';
7
7
  export { getNumbersInRange } from './number/range';
@@ -18,5 +18,5 @@ export { cloneObject, countObjectFields, generateQueryParams, isEmptyObject, isO
18
18
  export { extractNewFields, extractUpdatedAndNewFields, extractUpdatedFields, flattenObjectDotNotation, flattenObjectKeyValue, mergeAndFlattenObjects, mergeObjects, } from './object/objectify';
19
19
  export { sanitizeData } from './object/sanitize';
20
20
  export { convertObjectValues } from './object/convert';
21
- export { convertArrayToString, isDeepEqual } from './utils';
21
+ export { convertArrayToString, debounceAction, isDeepEqual, throttleAction, } from './utils';
22
22
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,gBAAgB,EAChB,gBAAgB,EAChB,UAAU,EACV,cAAc,GACd,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAEpD,OAAO,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAEzE,OAAO,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAEpE,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAEjD,OAAO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e,EAAE,MAAM,gBAAgB,CAAC;AAEtE,OAAO,EAAE,wBAAwB,EAAE,MAAM,kBAAkB,CAAC;AAE5D,OAAO,EACN,WAAW,EACX,iBAAiB,EACjB,mBAAmB,EACnB,aAAa,EACb,QAAQ,GACR,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EACN,gBAAgB,EAChB,0BAA0B,EAC1B,oBAAoB,EACpB,wBAAwB,EACxB,qBAAqB,EACrB,sBAAsB,EACtB,YAAY,GACZ,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEjD,OAAO,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAEvD,OAAO,EACN,oBAAoB,EACpB,cAAc,EACd,WAAW,EACX,cAAc,GACd,MAAM,SAAS,CAAC"}
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.flattenObjectDotNotation = exports.extractUpdatedFields = exports.extractUpdatedAndNewFields = exports.extractNewFields = exports.isObject = exports.isEmptyObject = exports.generateQueryParams = exports.countObjectFields = exports.cloneObject = exports.createControlledFormData = exports.isEmptyFormData = exports.convertIntoFormData = exports.removeDuplicatesFromArray = exports.createOptionsArray = exports.sortAnArray = exports.shuffleArray = exports.isValidEmptyArray = exports.flattenArray = exports.filterArrayOfObjects = exports.Color = exports.convertRgbToRgba = exports.convertRgbToHsl = exports.convertRgbToHex = exports.convertRgbaToHsla = exports.convertRgbaToHex8 = exports.convertHslToRgb = exports.convertHslToHex = exports.convertHslaToRgba = exports.convertHslaToHex8 = exports.convertHexToRgb = exports.convertHexToHsl = exports.convertHex8ToRgba = exports.convertHex8ToHsla = exports.convertColorCode = exports.generateRandomHSLColor = exports.generateRandomColorInHexRGB = exports.getColorForInitial = exports.getNumbersInRange = exports.isPrime = exports.findPrimeNumbers = exports.numberToWords = exports.getRandomNumber = exports.convertToDecimal = exports.replaceAllInString = exports.convertStringCase = exports.generateAnagrams = exports.truncateString = exports.trimString = exports.generateRandomID = exports.capitalizeString = void 0;
4
- exports.isDeepEqual = exports.convertArrayToString = exports.convertObjectValues = exports.sanitizeData = exports.mergeObjects = exports.mergeAndFlattenObjects = exports.flattenObjectKeyValue = void 0;
3
+ exports.isObject = exports.isEmptyObject = exports.generateQueryParams = exports.countObjectFields = exports.cloneObject = exports.createControlledFormData = exports.isEmptyFormData = exports.convertIntoFormData = exports.removeDuplicatesFromArray = exports.createOptionsArray = exports.sortAnArray = exports.shuffleArray = exports.isValidEmptyArray = exports.flattenArray = exports.filterArrayOfObjects = exports.Color = exports.convertRgbToRgba = exports.convertRgbToHsl = exports.convertRgbToHex = exports.convertRgbaToHsla = exports.convertRgbaToHex8 = exports.convertHslToRgb = exports.convertHslToHex = exports.convertHslaToRgba = exports.convertHslaToHex8 = exports.convertHexToRgb = exports.convertHexToHsl = exports.convertHex8ToRgba = exports.convertHex8ToHsla = exports.convertColorCode = exports.generateRandomHSLColor = exports.generateRandomColorInHexRGB = exports.getColorForInitial = exports.getNumbersInRange = exports.isPrime = exports.findPrimeNumbers = exports.numberToWords = exports.getRandomNumber = exports.convertToDecimal = exports.calculateLCM = exports.calculateLCD = exports.calculateHCF = exports.calculateGCD = exports.replaceAllInString = exports.convertStringCase = exports.generateAnagrams = exports.truncateString = exports.trimString = exports.generateRandomID = exports.capitalizeString = void 0;
4
+ exports.throttleAction = exports.isDeepEqual = exports.debounceAction = exports.convertArrayToString = exports.convertObjectValues = exports.sanitizeData = exports.mergeObjects = exports.mergeAndFlattenObjects = exports.flattenObjectKeyValue = exports.flattenObjectDotNotation = exports.extractUpdatedFields = exports.extractUpdatedAndNewFields = exports.extractNewFields = void 0;
5
5
  var basics_1 = require("./string/basics");
6
6
  Object.defineProperty(exports, "capitalizeString", { enumerable: true, get: function () { return basics_1.capitalizeString; } });
7
7
  Object.defineProperty(exports, "generateRandomID", { enumerable: true, get: function () { return basics_1.generateRandomID; } });
@@ -13,6 +13,10 @@ var convert_1 = require("./string/convert");
13
13
  Object.defineProperty(exports, "convertStringCase", { enumerable: true, get: function () { return convert_1.convertStringCase; } });
14
14
  Object.defineProperty(exports, "replaceAllInString", { enumerable: true, get: function () { return convert_1.replaceAllInString; } });
15
15
  var basics_2 = require("./number/basics");
16
+ Object.defineProperty(exports, "calculateGCD", { enumerable: true, get: function () { return basics_2.calculateHCF; } });
17
+ Object.defineProperty(exports, "calculateHCF", { enumerable: true, get: function () { return basics_2.calculateHCF; } });
18
+ Object.defineProperty(exports, "calculateLCD", { enumerable: true, get: function () { return basics_2.calculateLCM; } });
19
+ Object.defineProperty(exports, "calculateLCM", { enumerable: true, get: function () { return basics_2.calculateLCM; } });
16
20
  Object.defineProperty(exports, "convertToDecimal", { enumerable: true, get: function () { return basics_2.convertToDecimal; } });
17
21
  Object.defineProperty(exports, "getRandomNumber", { enumerable: true, get: function () { return basics_2.getRandomNumber; } });
18
22
  var convert_2 = require("./number/convert");
@@ -79,4 +83,6 @@ var convert_5 = require("./object/convert");
79
83
  Object.defineProperty(exports, "convertObjectValues", { enumerable: true, get: function () { return convert_5.convertObjectValues; } });
80
84
  var utils_1 = require("./utils");
81
85
  Object.defineProperty(exports, "convertArrayToString", { enumerable: true, get: function () { return utils_1.convertArrayToString; } });
86
+ Object.defineProperty(exports, "debounceAction", { enumerable: true, get: function () { return utils_1.debounceAction; } });
82
87
  Object.defineProperty(exports, "isDeepEqual", { enumerable: true, get: function () { return utils_1.isDeepEqual; } });
88
+ Object.defineProperty(exports, "throttleAction", { enumerable: true, get: function () { return utils_1.throttleAction; } });
@@ -16,4 +16,18 @@ export declare const getRandomNumber: (options?: RandomNumberOptions) => number;
16
16
  * @returns Converted number (as a `number`) or string (if `isString` is `true`).
17
17
  */
18
18
  export declare const convertToDecimal: (num: number, options?: DecimalOptions) => number | string;
19
+ /**
20
+ * * Calculate the HCF/GCD of multiple numbers.
21
+ *
22
+ * @param numbers - List of numbers to find the HCF/GCD for.
23
+ * @returns The HCF/GCD of all the provided numbers.
24
+ */
25
+ export declare const calculateHCF: (...numbers: number[]) => number;
26
+ /**
27
+ * * Calculate the LCM/LCD of multiple numbers.
28
+ *
29
+ * @param numbers - List of numbers to find the LCM/LCD for.
30
+ * @returns The LCM/LCD of all the provided numbers.
31
+ */
32
+ export declare const calculateLCM: (...numbers: number[]) => number;
19
33
  //# sourceMappingURL=basics.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"basics.d.ts","sourceRoot":"","sources":["../../src/number/basics.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAEnE;;;;;;;GAOG;AACH,eAAO,MAAM,eAAe,aAAc,mBAAmB,KAAG,MA+C/D,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,gBAAgB,QACvB,MAAM,YACD,cAAc,KACtB,MAAM,GAAG,MAQX,CAAC"}
1
+ {"version":3,"file":"basics.d.ts","sourceRoot":"","sources":["../../src/number/basics.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAEnE;;;;;;;GAOG;AACH,eAAO,MAAM,eAAe,aAAc,mBAAmB,KAAG,MA+C/D,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,gBAAgB,QACvB,MAAM,YACD,cAAc,KACtB,MAAM,GAAG,MAQX,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,YAAY,eAAgB,MAAM,EAAE,KAAG,MAQnD,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,YAAY,eAAgB,MAAM,EAAE,KAAG,MAQnD,CAAC"}
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.convertToDecimal = exports.getRandomNumber = void 0;
3
+ exports.calculateLCM = exports.calculateHCF = exports.convertToDecimal = exports.getRandomNumber = void 0;
4
+ const helpers_1 = require("./helpers");
4
5
  /**
5
6
  * * Utility to generate a random number between a given range.
6
7
  * * If no options are provided, it will generate a random number between `0` and `100` (inclusive).
@@ -58,3 +59,31 @@ const convertToDecimal = (num, options) => {
58
59
  return parseFloat(num.toFixed(decimalPlaces));
59
60
  };
60
61
  exports.convertToDecimal = convertToDecimal;
62
+ /**
63
+ * * Calculate the HCF/GCD of multiple numbers.
64
+ *
65
+ * @param numbers - List of numbers to find the HCF/GCD for.
66
+ * @returns The HCF/GCD of all the provided numbers.
67
+ */
68
+ const calculateHCF = (...numbers) => {
69
+ let hcf = numbers[0];
70
+ for (let i = 1; i < numbers.length; i++) {
71
+ hcf = (0, helpers_1._find2NumbersHCF)(hcf, numbers[i]);
72
+ }
73
+ return hcf;
74
+ };
75
+ exports.calculateHCF = calculateHCF;
76
+ /**
77
+ * * Calculate the LCM/LCD of multiple numbers.
78
+ *
79
+ * @param numbers - List of numbers to find the LCM/LCD for.
80
+ * @returns The LCM/LCD of all the provided numbers.
81
+ */
82
+ const calculateLCM = (...numbers) => {
83
+ let lcm = numbers[0];
84
+ for (let i = 1; i < numbers.length; i++) {
85
+ lcm = (0, helpers_1._find2NumbersLCM)(lcm, numbers[i]);
86
+ }
87
+ return lcm;
88
+ };
89
+ exports.calculateLCM = calculateLCM;
@@ -0,0 +1,17 @@
1
+ /**
2
+ * * Calculate the HCF (Highest Common Factor) of two numbers using the Euclidean algorithm.
3
+ *
4
+ * @param a - First number.
5
+ * @param b - Second number.
6
+ * @returns The HCF of the two numbers.
7
+ */
8
+ export declare const _find2NumbersHCF: (a: number, b: number) => number;
9
+ /**
10
+ * * Calculate the LCM (Least Common Multiple) of two numbers using the Euclidean algorithm.
11
+ *
12
+ * @param a - First number.
13
+ * @param b - Second number.
14
+ * @returns The LCM of the two numbers.
15
+ */
16
+ export declare const _find2NumbersLCM: (a: number, b: number) => number;
17
+ //# sourceMappingURL=helpers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../src/number/helpers.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,eAAO,MAAM,gBAAgB,MAAO,MAAM,KAAK,MAAM,KAAG,MAYvD,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,gBAAgB,MAAO,MAAM,KAAK,MAAM,KAAG,MAKvD,CAAC"}
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports._find2NumbersLCM = exports._find2NumbersHCF = void 0;
4
+ /**
5
+ * * Calculate the HCF (Highest Common Factor) of two numbers using the Euclidean algorithm.
6
+ *
7
+ * @param a - First number.
8
+ * @param b - Second number.
9
+ * @returns The HCF of the two numbers.
10
+ */
11
+ const _find2NumbersHCF = (a, b) => {
12
+ let x = Math.abs(a);
13
+ let y = Math.abs(b);
14
+ while (y !== 0) {
15
+ const temp = y;
16
+ y = x % y;
17
+ x = temp;
18
+ }
19
+ return x;
20
+ };
21
+ exports._find2NumbersHCF = _find2NumbersHCF;
22
+ /**
23
+ * * Calculate the LCM (Least Common Multiple) of two numbers using the Euclidean algorithm.
24
+ *
25
+ * @param a - First number.
26
+ * @param b - Second number.
27
+ * @returns The LCM of the two numbers.
28
+ */
29
+ const _find2NumbersLCM = (a, b) => {
30
+ const x = Math.abs(a);
31
+ const y = Math.abs(b);
32
+ return (x * y) / (0, exports._find2NumbersHCF)(x, y);
33
+ };
34
+ exports._find2NumbersLCM = _find2NumbersLCM;
@@ -8,5 +8,11 @@ type Brand<B> = {
8
8
  export type Branded<T, B> = T & Brand<B>;
9
9
  /** Union of Primitive Types */
10
10
  export type Primitive = string | number | boolean | null | undefined;
11
+ /** Generic function type */
12
+ export type GenericFn = (...args: any[]) => void;
13
+ /** Debounced function type after certain delay */
14
+ export type DelayedFn<T extends GenericFn> = (...args: Parameters<T>) => void;
15
+ /** Throttled function type after specific delay */
16
+ export type ThrottledFn<T extends GenericFn> = (...args: Parameters<T>) => void;
11
17
  export {};
12
18
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,6CAA6C;AAC7C,MAAM,MAAM,eAAe,GAAG,GAAG,CAAC;AAElC,OAAO,CAAC,MAAM,OAAO,EAAE,OAAO,MAAM,CAAC;AACrC,KAAK,KAAK,CAAC,CAAC,IAAI;IAAE,CAAC,OAAO,CAAC,EAAE,CAAC,CAAA;CAAE,CAAC;AAEjC,6BAA6B;AAC7B,MAAM,MAAM,OAAO,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;AAEzC,+BAA+B;AAC/B,MAAM,MAAM,SAAS,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,GAAG,SAAS,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,6CAA6C;AAC7C,MAAM,MAAM,eAAe,GAAG,GAAG,CAAC;AAElC,OAAO,CAAC,MAAM,OAAO,EAAE,OAAO,MAAM,CAAC;AACrC,KAAK,KAAK,CAAC,CAAC,IAAI;IAAE,CAAC,OAAO,CAAC,EAAE,CAAC,CAAA;CAAE,CAAC;AAEjC,6BAA6B;AAC7B,MAAM,MAAM,OAAO,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;AAEzC,+BAA+B;AAC/B,MAAM,MAAM,SAAS,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,GAAG,SAAS,CAAC;AAErE,4BAA4B;AAC5B,MAAM,MAAM,SAAS,GAAG,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,CAAC;AAEjD,kDAAkD;AAClD,MAAM,MAAM,SAAS,CAAC,CAAC,SAAS,SAAS,IAAI,CAAC,GAAG,IAAI,EAAE,UAAU,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC;AAE9E,mDAAmD;AACnD,MAAM,MAAM,WAAW,CAAC,CAAC,SAAS,SAAS,IAAI,CAAC,GAAG,IAAI,EAAE,UAAU,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC"}
@@ -1,3 +1,4 @@
1
+ import type { DelayedFn, GenericFn, ThrottledFn } from '../types';
1
2
  /**
2
3
  * * Deeply compare two values (arrays, objects, or primitive values).
3
4
  *
@@ -14,4 +15,34 @@ export declare const isDeepEqual: <T>(a: T, b: T) => boolean;
14
15
  * @returns Converted array in string format with the separator.
15
16
  */
16
17
  export declare const convertArrayToString: <T>(array: T[], separator?: string) => string;
18
+ /**
19
+ * * A generic debounce function that delays the execution of a callback.
20
+ *
21
+ * @param callback - The function to debounce.
22
+ * @param delay - The delay in milliseconds. Default is `300ms`.
23
+ * @returns A debounced version of the callback function.
24
+ *
25
+ * @example
26
+ * const debouncedSearch = debounceAction((query: string) => {
27
+ * console.log(`Searching for: ${query}`);
28
+ * }, 300);
29
+ *
30
+ * debouncedSearch('laptop'); // Executes after 300ms of inactivity.
31
+ */
32
+ export declare const debounceAction: <T extends GenericFn>(callback: T, delay?: number) => DelayedFn<T>;
33
+ /**
34
+ * * A generic throttle function that ensures a callback is executed at most once per specified interval.
35
+ *
36
+ * @param callback - The function to throttle.
37
+ * @param delay - The delay in milliseconds. Default is `150ms`.
38
+ * @returns A throttled version of the callback function.
39
+ *
40
+ * @example
41
+ * const throttledResize = throttleAction(() => {
42
+ * console.log('Resized');
43
+ * }, 300);
44
+ *
45
+ * window.addEventListener('resize', throttledResize);
46
+ */
47
+ export declare const throttleAction: <T extends GenericFn>(callback: T, delay?: number) => ThrottledFn<T>;
17
48
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAGA;;;;;;GAMG;AACH,eAAO,MAAM,WAAW,GAAI,CAAC,KAAK,CAAC,KAAK,CAAC,KAAG,OA6B3C,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,oBAAoB,GAAI,CAAC,SAC9B,CAAC,EAAE,cACC,MAAM,KACf,MAKF,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAElE;;;;;;GAMG;AACH,eAAO,MAAM,WAAW,GAAI,CAAC,KAAK,CAAC,KAAK,CAAC,KAAG,OA6B3C,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,oBAAoB,GAAI,CAAC,SAC9B,CAAC,EAAE,cACC,MAAM,KACf,MAKF,CAAC;AAEF;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,cAAc,GAAI,CAAC,SAAS,SAAS,YACvC,CAAC,qBAET,SAAS,CAAC,CAAC,CAYb,CAAC;AAEF;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,cAAc,GAAI,CAAC,SAAS,SAAS,YACvC,CAAC,qBAET,WAAW,CAAC,CAAC,CAWf,CAAC"}
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.convertArrayToString = exports.isDeepEqual = void 0;
3
+ exports.throttleAction = exports.debounceAction = exports.convertArrayToString = exports.isDeepEqual = void 0;
4
4
  const basics_1 = require("../array/basics");
5
5
  /**
6
6
  * * Deeply compare two values (arrays, objects, or primitive values).
@@ -50,3 +50,54 @@ const convertArrayToString = (array, separator = ',') => {
50
50
  return array.join(separator);
51
51
  };
52
52
  exports.convertArrayToString = convertArrayToString;
53
+ /**
54
+ * * A generic debounce function that delays the execution of a callback.
55
+ *
56
+ * @param callback - The function to debounce.
57
+ * @param delay - The delay in milliseconds. Default is `300ms`.
58
+ * @returns A debounced version of the callback function.
59
+ *
60
+ * @example
61
+ * const debouncedSearch = debounceAction((query: string) => {
62
+ * console.log(`Searching for: ${query}`);
63
+ * }, 300);
64
+ *
65
+ * debouncedSearch('laptop'); // Executes after 300ms of inactivity.
66
+ */
67
+ const debounceAction = (callback, delay = 300) => {
68
+ let timeoutId = undefined;
69
+ return (...args) => {
70
+ // Clear the previous timeout
71
+ clearTimeout(timeoutId);
72
+ // Set a new timeout
73
+ timeoutId = setTimeout(() => {
74
+ callback(...args);
75
+ }, delay);
76
+ };
77
+ };
78
+ exports.debounceAction = debounceAction;
79
+ /**
80
+ * * A generic throttle function that ensures a callback is executed at most once per specified interval.
81
+ *
82
+ * @param callback - The function to throttle.
83
+ * @param delay - The delay in milliseconds. Default is `150ms`.
84
+ * @returns A throttled version of the callback function.
85
+ *
86
+ * @example
87
+ * const throttledResize = throttleAction(() => {
88
+ * console.log('Resized');
89
+ * }, 300);
90
+ *
91
+ * window.addEventListener('resize', throttledResize);
92
+ */
93
+ const throttleAction = (callback, delay = 150) => {
94
+ let lastCall = 0;
95
+ return (...args) => {
96
+ const now = Date.now();
97
+ if (now - lastCall >= delay) {
98
+ lastCall = now;
99
+ callback(...args);
100
+ }
101
+ };
102
+ };
103
+ exports.throttleAction = throttleAction;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nhb-toolbox",
3
- "version": "2.1.9",
3
+ "version": "2.2.9",
4
4
  "description": "A versatile collection of smart, efficient, and reusable utility functions for everyday development needs.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",