nhb-toolbox 2.1.9 → 2.2.2
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 +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/types/index.d.ts +6 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/utils/index.d.ts +31 -0
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +52 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -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
|
package/dist/index.d.ts.map
CHANGED
|
@@ -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,EAAE,gBAAgB,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;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BAAiB,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
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;
|
|
4
|
+
exports.throttleAction = exports.isDeepEqual = exports.debounceAction = exports.convertArrayToString = exports.convertObjectValues = exports.sanitizeData = exports.mergeObjects = exports.mergeAndFlattenObjects = exports.flattenObjectKeyValue = 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; } });
|
|
@@ -79,4 +79,6 @@ var convert_5 = require("./object/convert");
|
|
|
79
79
|
Object.defineProperty(exports, "convertObjectValues", { enumerable: true, get: function () { return convert_5.convertObjectValues; } });
|
|
80
80
|
var utils_1 = require("./utils");
|
|
81
81
|
Object.defineProperty(exports, "convertArrayToString", { enumerable: true, get: function () { return utils_1.convertArrayToString; } });
|
|
82
|
+
Object.defineProperty(exports, "debounceAction", { enumerable: true, get: function () { return utils_1.debounceAction; } });
|
|
82
83
|
Object.defineProperty(exports, "isDeepEqual", { enumerable: true, get: function () { return utils_1.isDeepEqual; } });
|
|
84
|
+
Object.defineProperty(exports, "throttleAction", { enumerable: true, get: function () { return utils_1.throttleAction; } });
|
package/dist/types/index.d.ts
CHANGED
|
@@ -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"}
|
package/dist/utils/index.d.ts
CHANGED
|
@@ -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":"
|
|
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"}
|
package/dist/utils/index.js
CHANGED
|
@@ -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