nhb-toolbox 2.8.1 → 2.8.3
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/array/basics.js +7 -15
- package/dist/array/sort.js +1 -4
- package/dist/array/transform.js +4 -9
- package/dist/array/types.js +1 -2
- package/dist/colors/Color.js +17 -21
- package/dist/colors/constants.js +2 -5
- package/dist/colors/convert.js +56 -73
- package/dist/colors/helpers.js +13 -29
- package/dist/colors/initials.d.ts +2 -2
- package/dist/colors/initials.d.ts.map +1 -1
- package/dist/colors/initials.js +13 -16
- package/dist/colors/random.js +7 -12
- package/dist/colors/types.js +1 -2
- package/dist/form/convert.js +4 -9
- package/dist/form/guards.js +4 -10
- package/dist/form/transform.js +9 -13
- package/dist/form/types.js +1 -2
- package/dist/guards/non-primitives.d.ts +10 -10
- package/dist/guards/non-primitives.js +27 -44
- package/dist/guards/primitives.d.ts +12 -12
- package/dist/guards/primitives.js +24 -38
- package/dist/guards/specials.d.ts +12 -12
- package/dist/guards/specials.js +35 -49
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +25 -156
- package/dist/number/basics.js +11 -21
- package/dist/number/constants.js +4 -7
- package/dist/number/convert.js +5 -8
- package/dist/number/helpers.js +11 -18
- package/dist/number/prime.js +3 -8
- package/dist/number/range.js +12 -15
- package/dist/number/types.js +1 -2
- package/dist/object/basics.js +8 -16
- package/dist/object/convert.js +1 -4
- package/dist/object/objectify.js +22 -32
- package/dist/object/sanitize.js +8 -11
- package/dist/object/types.js +1 -2
- package/dist/string/anagram.js +1 -4
- package/dist/string/basics.js +4 -11
- package/dist/string/constants.js +1 -4
- package/dist/string/convert.js +4 -9
- package/dist/string/types.js +1 -2
- package/dist/types/index.js +1 -2
- package/dist/utils/index.js +8 -15
- package/package.json +2 -1
package/dist/object/convert.js
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.convertObjectValues = convertObjectValues;
|
|
4
1
|
/**
|
|
5
2
|
* * Converts the values of specified keys in an object or array of objects to either string or number.
|
|
6
3
|
* * Supports nested objects using dot-notation keys.
|
|
@@ -11,7 +8,7 @@ exports.convertObjectValues = convertObjectValues;
|
|
|
11
8
|
* - `convertTo`: The target type, either "string" or "number".
|
|
12
9
|
* @returns The modified object or array of objects with the converted values, with updated types.
|
|
13
10
|
*/
|
|
14
|
-
function convertObjectValues(data, options) {
|
|
11
|
+
export function convertObjectValues(data, options) {
|
|
15
12
|
const { keys, convertTo } = options;
|
|
16
13
|
/** * Helper function to determine if value should be preserved. */
|
|
17
14
|
const _shouldPreserveValue = (value) => convertTo === 'number' &&
|
package/dist/object/objectify.js
CHANGED
|
@@ -1,15 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.extractUpdatedAndNewFields = exports.extractNewFields = exports.extractUpdatedFields = exports.flattenObjectDotNotation = exports.flattenObjectKeyValue = exports.mergeAndFlattenObjects = exports.mergeObjects = void 0;
|
|
4
|
-
const utils_1 = require("../utils");
|
|
5
|
-
const basics_1 = require("./basics");
|
|
1
|
+
import { isDeepEqual } from '../utils';
|
|
2
|
+
import { isEmptyObject, isObject } from './basics';
|
|
6
3
|
/**
|
|
7
4
|
* * Deeply merge two or more objects using `Map`.
|
|
8
5
|
*
|
|
9
6
|
* @param objects Objects to merge.
|
|
10
7
|
* @returns Merged object.
|
|
11
8
|
*/
|
|
12
|
-
const mergeObjects = (...objects) => {
|
|
9
|
+
export const mergeObjects = (...objects) => {
|
|
13
10
|
const map = new Map();
|
|
14
11
|
objects.forEach((obj) => {
|
|
15
12
|
for (const key in obj) {
|
|
@@ -19,7 +16,7 @@ const mergeObjects = (...objects) => {
|
|
|
19
16
|
if (existingValue &&
|
|
20
17
|
existingValue instanceof Object &&
|
|
21
18
|
!Array.isArray(existingValue)) {
|
|
22
|
-
map.set(key,
|
|
19
|
+
map.set(key, mergeObjects(existingValue, obj[key]));
|
|
23
20
|
}
|
|
24
21
|
else {
|
|
25
22
|
// Otherwise, just set the value
|
|
@@ -38,7 +35,6 @@ const mergeObjects = (...objects) => {
|
|
|
38
35
|
});
|
|
39
36
|
return result;
|
|
40
37
|
};
|
|
41
|
-
exports.mergeObjects = mergeObjects;
|
|
42
38
|
/**
|
|
43
39
|
* * Deeply merge objects and flatten nested objects.
|
|
44
40
|
* * Useful for flattening a single object or merging multiple objects with duplicate key(s).
|
|
@@ -47,7 +43,7 @@ exports.mergeObjects = mergeObjects;
|
|
|
47
43
|
* @param objects Objects to merge.
|
|
48
44
|
* @returns Merged object with flattened structure.
|
|
49
45
|
*/
|
|
50
|
-
const mergeAndFlattenObjects = (...objects) => {
|
|
46
|
+
export const mergeAndFlattenObjects = (...objects) => {
|
|
51
47
|
const map = new Map();
|
|
52
48
|
const _flattenObject = (obj, parentKey = '') => {
|
|
53
49
|
for (const key in obj) {
|
|
@@ -69,21 +65,20 @@ const mergeAndFlattenObjects = (...objects) => {
|
|
|
69
65
|
});
|
|
70
66
|
return result;
|
|
71
67
|
};
|
|
72
|
-
exports.mergeAndFlattenObjects = mergeAndFlattenObjects;
|
|
73
68
|
/**
|
|
74
69
|
* * Flattens a nested object into key-value format.
|
|
75
70
|
*
|
|
76
71
|
* @param object - The `object` to flatten.
|
|
77
72
|
* @returns A `flattened object` in key-value format.
|
|
78
73
|
*/
|
|
79
|
-
const flattenObjectKeyValue = (object) => {
|
|
74
|
+
export const flattenObjectKeyValue = (object) => {
|
|
80
75
|
const flattened = {};
|
|
81
76
|
for (const [key, value] of Object.entries(object)) {
|
|
82
77
|
if (typeof value === 'object' &&
|
|
83
78
|
value !== null &&
|
|
84
79
|
!Array.isArray(value)) {
|
|
85
80
|
// Recursively flatten nested objects
|
|
86
|
-
const nestedFlattened =
|
|
81
|
+
const nestedFlattened = flattenObjectKeyValue(value);
|
|
87
82
|
Object.assign(flattened, nestedFlattened);
|
|
88
83
|
}
|
|
89
84
|
else {
|
|
@@ -93,14 +88,13 @@ const flattenObjectKeyValue = (object) => {
|
|
|
93
88
|
}
|
|
94
89
|
return flattened;
|
|
95
90
|
};
|
|
96
|
-
exports.flattenObjectKeyValue = flattenObjectKeyValue;
|
|
97
91
|
/**
|
|
98
92
|
* * Flattens a nested object into a dot notation format.
|
|
99
93
|
*
|
|
100
94
|
* @param object - The `object` to flatten.
|
|
101
95
|
* @returns A `flattened object` with dot notation keys.
|
|
102
96
|
*/
|
|
103
|
-
const flattenObjectDotNotation = (object) => {
|
|
97
|
+
export const flattenObjectDotNotation = (object) => {
|
|
104
98
|
/**
|
|
105
99
|
* * Recursively flattens an object, transforming nested structures into dot-notation keys.
|
|
106
100
|
*
|
|
@@ -130,7 +124,6 @@ const flattenObjectDotNotation = (object) => {
|
|
|
130
124
|
// Call the recursive function with an empty prefix initially
|
|
131
125
|
return _flattenObject(object);
|
|
132
126
|
};
|
|
133
|
-
exports.flattenObjectDotNotation = flattenObjectDotNotation;
|
|
134
127
|
/**
|
|
135
128
|
* * Extracts only the fields that have changed between the original and updated object.
|
|
136
129
|
*
|
|
@@ -138,14 +131,14 @@ exports.flattenObjectDotNotation = flattenObjectDotNotation;
|
|
|
138
131
|
* @param updatedObject The modified object containing potential updates.
|
|
139
132
|
* @returns A new object containing only the changed fields.
|
|
140
133
|
*/
|
|
141
|
-
const extractUpdatedFields = (baseObject, updatedObject) => {
|
|
134
|
+
export const extractUpdatedFields = (baseObject, updatedObject) => {
|
|
142
135
|
const updatedFields = {};
|
|
143
136
|
for (const key in updatedObject) {
|
|
144
137
|
if (key in baseObject &&
|
|
145
|
-
!
|
|
146
|
-
if (updatedObject[key] &&
|
|
147
|
-
updatedFields[key] =
|
|
148
|
-
if (updatedFields[key] &&
|
|
138
|
+
!isDeepEqual(updatedObject[key], baseObject[key])) {
|
|
139
|
+
if (updatedObject[key] && isObject(updatedObject[key])) {
|
|
140
|
+
updatedFields[key] = extractUpdatedFields(baseObject[key], updatedObject[key]);
|
|
141
|
+
if (updatedFields[key] && isEmptyObject(updatedFields[key])) {
|
|
149
142
|
delete updatedFields[key];
|
|
150
143
|
}
|
|
151
144
|
}
|
|
@@ -156,7 +149,6 @@ const extractUpdatedFields = (baseObject, updatedObject) => {
|
|
|
156
149
|
}
|
|
157
150
|
return updatedFields;
|
|
158
151
|
};
|
|
159
|
-
exports.extractUpdatedFields = extractUpdatedFields;
|
|
160
152
|
/**
|
|
161
153
|
* * Extracts only new fields that exist in updatedObject but not in baseObject.
|
|
162
154
|
*
|
|
@@ -164,17 +156,17 @@ exports.extractUpdatedFields = extractUpdatedFields;
|
|
|
164
156
|
* @param updatedObject The modified object containing potential new fields.
|
|
165
157
|
* @returns A new object containing only the new fields.
|
|
166
158
|
*/
|
|
167
|
-
const extractNewFields = (baseObject, updatedObject) => {
|
|
159
|
+
export const extractNewFields = (baseObject, updatedObject) => {
|
|
168
160
|
const newFields = {};
|
|
169
161
|
for (const key in updatedObject) {
|
|
170
162
|
if (!(key in baseObject)) {
|
|
171
163
|
// Directly assign new fields
|
|
172
164
|
newFields[key] = updatedObject[key];
|
|
173
165
|
}
|
|
174
|
-
else if (
|
|
166
|
+
else if (isObject(updatedObject[key]) && isObject(baseObject[key])) {
|
|
175
167
|
// Recursively extract new fields inside nested objects
|
|
176
|
-
const nestedNewFields =
|
|
177
|
-
if (!
|
|
168
|
+
const nestedNewFields = extractNewFields(baseObject[key], updatedObject[key]);
|
|
169
|
+
if (!isEmptyObject(nestedNewFields)) {
|
|
178
170
|
newFields[key] =
|
|
179
171
|
nestedNewFields;
|
|
180
172
|
}
|
|
@@ -182,7 +174,6 @@ const extractNewFields = (baseObject, updatedObject) => {
|
|
|
182
174
|
}
|
|
183
175
|
return newFields;
|
|
184
176
|
};
|
|
185
|
-
exports.extractNewFields = extractNewFields;
|
|
186
177
|
/**
|
|
187
178
|
* * Extracts changed fields from the updated object while also identifying newly added keys.
|
|
188
179
|
*
|
|
@@ -190,17 +181,17 @@ exports.extractNewFields = extractNewFields;
|
|
|
190
181
|
* @param updatedObject The modified object containing potential updates.
|
|
191
182
|
* @returns An object containing modified fields and new fields separately.
|
|
192
183
|
*/
|
|
193
|
-
const extractUpdatedAndNewFields = (baseObject, updatedObject) => {
|
|
184
|
+
export const extractUpdatedAndNewFields = (baseObject, updatedObject) => {
|
|
194
185
|
const updatedFields = {};
|
|
195
186
|
const newFields = {};
|
|
196
187
|
for (const key in updatedObject) {
|
|
197
188
|
if (!(key in baseObject)) {
|
|
198
189
|
newFields[key] = updatedObject[key];
|
|
199
190
|
}
|
|
200
|
-
else if (!
|
|
201
|
-
if (updatedObject[key] &&
|
|
202
|
-
updatedFields[key] =
|
|
203
|
-
if (updatedFields[key] &&
|
|
191
|
+
else if (!isDeepEqual(updatedObject[key], baseObject[key])) {
|
|
192
|
+
if (updatedObject[key] && isObject(updatedObject[key])) {
|
|
193
|
+
updatedFields[key] = extractUpdatedAndNewFields(baseObject[key], updatedObject[key]);
|
|
194
|
+
if (updatedFields[key] && isEmptyObject(updatedFields[key])) {
|
|
204
195
|
delete updatedFields[key];
|
|
205
196
|
}
|
|
206
197
|
}
|
|
@@ -211,4 +202,3 @@ const extractUpdatedAndNewFields = (baseObject, updatedObject) => {
|
|
|
211
202
|
}
|
|
212
203
|
return { ...updatedFields, ...newFields };
|
|
213
204
|
};
|
|
214
|
-
exports.extractUpdatedAndNewFields = extractUpdatedAndNewFields;
|
package/dist/object/sanitize.js
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.sanitizeData = sanitizeData;
|
|
4
|
-
const basics_1 = require("../string/basics");
|
|
5
|
-
const basics_2 = require("./basics");
|
|
1
|
+
import { trimString } from '../string/basics';
|
|
2
|
+
import { isEmptyObject } from './basics';
|
|
6
3
|
/**
|
|
7
4
|
* * Sanitizes a string, array of strings, an object or array of objects by ignoring specified keys and trimming string values.
|
|
8
5
|
* * Also excludes nullish values (null, undefined) if specified. Always ignores empty nested object(s).
|
|
@@ -11,7 +8,7 @@ const basics_2 = require("./basics");
|
|
|
11
8
|
* @param options - Options for processing.
|
|
12
9
|
* @returns A new string, object or array of strings or objects with the specified modifications.
|
|
13
10
|
*/
|
|
14
|
-
function sanitizeData(input, options) {
|
|
11
|
+
export function sanitizeData(input, options) {
|
|
15
12
|
const { keysToIgnore: ignoreKeys = [], trimStrings = true, ignoreNullish = false, } = options || {};
|
|
16
13
|
// Flatten the object keys and use the keys for comparison
|
|
17
14
|
const ignoreKeySet = new Set(ignoreKeys);
|
|
@@ -34,7 +31,7 @@ function sanitizeData(input, options) {
|
|
|
34
31
|
}
|
|
35
32
|
// Trim string values if enabled
|
|
36
33
|
if (typeof value === 'string' && trimStrings) {
|
|
37
|
-
acc[key] =
|
|
34
|
+
acc[key] = trimString(value);
|
|
38
35
|
}
|
|
39
36
|
else if (value &&
|
|
40
37
|
typeof value === 'object' &&
|
|
@@ -42,7 +39,7 @@ function sanitizeData(input, options) {
|
|
|
42
39
|
// Recursively process nested objects
|
|
43
40
|
const processedValue = _processObject(value, fullKeyPath);
|
|
44
41
|
// Only add the property if it's not an empty object
|
|
45
|
-
if (!
|
|
42
|
+
if (!isEmptyObject(processedValue)) {
|
|
46
43
|
acc[key] = processedValue;
|
|
47
44
|
}
|
|
48
45
|
}
|
|
@@ -54,18 +51,18 @@ function sanitizeData(input, options) {
|
|
|
54
51
|
}, {});
|
|
55
52
|
// Process strings
|
|
56
53
|
if (typeof input === 'string') {
|
|
57
|
-
return
|
|
54
|
+
return trimString(input);
|
|
58
55
|
}
|
|
59
56
|
// Process array of strings and objects
|
|
60
57
|
if (Array.isArray(input)) {
|
|
61
58
|
// Process array of strings
|
|
62
59
|
if (typeof input[0] === 'string') {
|
|
63
|
-
return
|
|
60
|
+
return trimString(input);
|
|
64
61
|
}
|
|
65
62
|
// Process array of objects
|
|
66
63
|
return input
|
|
67
64
|
.map((obj) => _processObject(obj))
|
|
68
|
-
.filter((obj) => !
|
|
65
|
+
.filter((obj) => !isEmptyObject(obj));
|
|
69
66
|
}
|
|
70
67
|
// Process object
|
|
71
68
|
if (typeof input === 'object' && input !== null) {
|
package/dist/object/types.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|
package/dist/string/anagram.js
CHANGED
|
@@ -1,13 +1,10 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.generateAnagrams = generateAnagrams;
|
|
4
1
|
/**
|
|
5
2
|
* * Utility to generate unique anagrams of a word.
|
|
6
3
|
* @param word The word for generating anagrams.
|
|
7
4
|
* @param limit The maximum number of anagrams to return ('all' for unlimited). Default is `100`.
|
|
8
5
|
* @returns An array of generated anagrams. The first element is always the given word.
|
|
9
6
|
*/
|
|
10
|
-
function generateAnagrams(word, limit = 100) {
|
|
7
|
+
export function generateAnagrams(word, limit = 100) {
|
|
11
8
|
if (word.length <= 1)
|
|
12
9
|
return [word];
|
|
13
10
|
const uniqueAnagrams = new Set();
|
package/dist/string/basics.js
CHANGED
|
@@ -1,8 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.generateRandomID = exports.truncateString = void 0;
|
|
4
|
-
exports.capitalizeString = capitalizeString;
|
|
5
|
-
exports.trimString = trimString;
|
|
6
1
|
/**
|
|
7
2
|
* * Utility to convert the first letter of any string to uppercase and the rest lowercase (unless specified).
|
|
8
3
|
* * Handles surrounding symbols like quotes or parentheses.
|
|
@@ -11,7 +6,7 @@ exports.trimString = trimString;
|
|
|
11
6
|
* @param options Options to customize the capitalization.
|
|
12
7
|
* @returns Capitalized string or fully uppercased string depending on `capitalizeAll` option.
|
|
13
8
|
*/
|
|
14
|
-
function capitalizeString(string, options) {
|
|
9
|
+
export function capitalizeString(string, options) {
|
|
15
10
|
if (typeof string !== 'string' || !string)
|
|
16
11
|
return '';
|
|
17
12
|
const trimmedString = string.trim();
|
|
@@ -48,7 +43,7 @@ function capitalizeString(string, options) {
|
|
|
48
43
|
* @param maxLength The maximum length of the truncated string.
|
|
49
44
|
* @returns Truncated string with ellipsis (`...`) (only if it has more length than `maxLength`).
|
|
50
45
|
*/
|
|
51
|
-
const truncateString = (string, maxLength) => {
|
|
46
|
+
export const truncateString = (string, maxLength) => {
|
|
52
47
|
if (typeof string !== 'string' || !string)
|
|
53
48
|
return '';
|
|
54
49
|
const trimmedString = string.trim();
|
|
@@ -58,14 +53,13 @@ const truncateString = (string, maxLength) => {
|
|
|
58
53
|
return trimmedString;
|
|
59
54
|
return trimmedString.slice(0, maxLength).concat('...');
|
|
60
55
|
};
|
|
61
|
-
exports.truncateString = truncateString;
|
|
62
56
|
/**
|
|
63
57
|
* * Generates a random alphanumeric (16 characters long, this length is customizable in the options) ID string composed of an optional `prefix`, `suffix`, a `timestamp`, `caseOption` and a customizable `separator`.
|
|
64
58
|
*
|
|
65
59
|
* @param options Configuration options for random ID generation.
|
|
66
60
|
* @returns The generated ID string composed of the random alphanumeric string of specified length with optional `timeStamp`, `prefix`, and `suffix`, `caseOption` and `separator`.
|
|
67
61
|
*/
|
|
68
|
-
const generateRandomID = (options) => {
|
|
62
|
+
export const generateRandomID = (options) => {
|
|
69
63
|
const { prefix = '', suffix = '', timeStamp = false, length = 16, separator = '', caseOption = null, } = options || {};
|
|
70
64
|
// generate timestamp
|
|
71
65
|
const date = timeStamp ? Date.now() : '';
|
|
@@ -88,14 +82,13 @@ const generateRandomID = (options) => {
|
|
|
88
82
|
return ID;
|
|
89
83
|
}
|
|
90
84
|
};
|
|
91
|
-
exports.generateRandomID = generateRandomID;
|
|
92
85
|
/**
|
|
93
86
|
* * Trims all the words in a string or an array of strings.
|
|
94
87
|
*
|
|
95
88
|
* @param input String or array of strings.
|
|
96
89
|
* @returns Trimmed string or array of strings.
|
|
97
90
|
*/
|
|
98
|
-
function trimString(input) {
|
|
91
|
+
export function trimString(input) {
|
|
99
92
|
if (!input)
|
|
100
93
|
return '';
|
|
101
94
|
// If the input is a string, trim each word
|
package/dist/string/constants.js
CHANGED
package/dist/string/convert.js
CHANGED
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.replaceAllInString = void 0;
|
|
4
|
-
exports.convertStringCase = convertStringCase;
|
|
5
|
-
const constants_1 = require("./constants");
|
|
1
|
+
import { LOWERCASE } from './constants';
|
|
6
2
|
/**
|
|
7
3
|
* Converts a string to a specified case format such as `camelCase`, `snake_case`, `kebab-case`, `PascalCase`, `Title Case`, `lowercase`, or `UPPERCASE`.
|
|
8
4
|
*
|
|
@@ -27,7 +23,7 @@ const constants_1 = require("./constants");
|
|
|
27
23
|
* convertStringCase('my example string', 'lowercase'); // returns 'my example string'
|
|
28
24
|
* convertStringCase('my example string', 'UPPERCASE'); // returns 'MY EXAMPLE STRING'
|
|
29
25
|
*/
|
|
30
|
-
function convertStringCase(string, format) {
|
|
26
|
+
export function convertStringCase(string, format) {
|
|
31
27
|
if (!string || typeof string !== 'string')
|
|
32
28
|
return '';
|
|
33
29
|
const start = string.match(/^[^\d\w\s]+/)?.[0] || '';
|
|
@@ -39,7 +35,7 @@ function convertStringCase(string, format) {
|
|
|
39
35
|
const startSymbol = part.match(/^[^\d\w\s]+/)?.[0] || ''; // Capture leading symbols
|
|
40
36
|
const endSymbol = part.match(/[^\d\w\s]+$/)?.[0] || ''; // Capture trailing symbols
|
|
41
37
|
const coreWord = part.replace(/^[^\d\w\s]+|[^\d\w\s]+$/g, ''); // Remove them for processing
|
|
42
|
-
if (
|
|
38
|
+
if (LOWERCASE.includes(coreWord.toLowerCase())) {
|
|
43
39
|
return startSymbol + coreWord.toLowerCase() + endSymbol;
|
|
44
40
|
}
|
|
45
41
|
return (startSymbol +
|
|
@@ -98,7 +94,7 @@ function convertStringCase(string, format) {
|
|
|
98
94
|
* @param replace - The string to replace matches with.
|
|
99
95
|
* @returns The modified/refined string with replacements applied.
|
|
100
96
|
*/
|
|
101
|
-
const replaceAllInString = (input, find, replace) => {
|
|
97
|
+
export const replaceAllInString = (input, find, replace) => {
|
|
102
98
|
if (!input)
|
|
103
99
|
return '';
|
|
104
100
|
const trimmedString = input?.trim();
|
|
@@ -109,4 +105,3 @@ const replaceAllInString = (input, find, replace) => {
|
|
|
109
105
|
: new RegExp(find, find.flags.includes('g') ? find.flags : find.flags + 'g');
|
|
110
106
|
return trimmedString?.replace(regex, replace);
|
|
111
107
|
};
|
|
112
|
-
exports.replaceAllInString = replaceAllInString;
|
package/dist/string/types.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|
package/dist/types/index.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|
package/dist/utils/index.js
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.throttleAction = exports.debounceAction = exports.convertArrayToString = exports.isDeepEqual = void 0;
|
|
4
|
-
const basics_1 = require("../array/basics");
|
|
1
|
+
import { isInvalidOrEmptyArray } from '../array/basics';
|
|
5
2
|
/**
|
|
6
3
|
* * Deeply compare two values (arrays, objects, or primitive values).
|
|
7
4
|
*
|
|
@@ -9,7 +6,7 @@ const basics_1 = require("../array/basics");
|
|
|
9
6
|
* @param b Second value to compare.
|
|
10
7
|
* @returns Whether the values are deeply equal.
|
|
11
8
|
*/
|
|
12
|
-
const isDeepEqual = (a, b) => {
|
|
9
|
+
export const isDeepEqual = (a, b) => {
|
|
13
10
|
// If both values are strictly equal (handles primitive types and same references)
|
|
14
11
|
if (a === b)
|
|
15
12
|
return true;
|
|
@@ -23,7 +20,7 @@ const isDeepEqual = (a, b) => {
|
|
|
23
20
|
if (Array.isArray(a) && Array.isArray(b)) {
|
|
24
21
|
if (a.length !== b.length)
|
|
25
22
|
return false;
|
|
26
|
-
return a.every((element, index) =>
|
|
23
|
+
return a.every((element, index) => isDeepEqual(element, b[index]));
|
|
27
24
|
}
|
|
28
25
|
// Check for object equality
|
|
29
26
|
if (typeof a === 'object' && typeof b === 'object') {
|
|
@@ -31,11 +28,10 @@ const isDeepEqual = (a, b) => {
|
|
|
31
28
|
const bKeys = Object.keys(b);
|
|
32
29
|
if (aKeys.length !== bKeys.length)
|
|
33
30
|
return false;
|
|
34
|
-
return aKeys.every((key) =>
|
|
31
|
+
return aKeys.every((key) => isDeepEqual(a[key], b[key]));
|
|
35
32
|
}
|
|
36
33
|
return false;
|
|
37
34
|
};
|
|
38
|
-
exports.isDeepEqual = isDeepEqual;
|
|
39
35
|
/**
|
|
40
36
|
* * Utility to convert an array to string with custom separator.
|
|
41
37
|
*
|
|
@@ -43,13 +39,12 @@ exports.isDeepEqual = isDeepEqual;
|
|
|
43
39
|
* @param separator Separate each element of the array. Can be `,`, `-`, `|` etc. Default is `,`.
|
|
44
40
|
* @returns Converted array in string format with the separator.
|
|
45
41
|
*/
|
|
46
|
-
const convertArrayToString = (array, separator = ',') => {
|
|
47
|
-
if (!
|
|
42
|
+
export const convertArrayToString = (array, separator = ',') => {
|
|
43
|
+
if (!isInvalidOrEmptyArray) {
|
|
48
44
|
throw new Error('Please, provide a valid array!');
|
|
49
45
|
}
|
|
50
46
|
return array.join(separator);
|
|
51
47
|
};
|
|
52
|
-
exports.convertArrayToString = convertArrayToString;
|
|
53
48
|
/**
|
|
54
49
|
* * A generic debounce function that delays the execution of a callback.
|
|
55
50
|
*
|
|
@@ -64,7 +59,7 @@ exports.convertArrayToString = convertArrayToString;
|
|
|
64
59
|
*
|
|
65
60
|
* debouncedSearch('laptop'); // Executes after 300ms of inactivity.
|
|
66
61
|
*/
|
|
67
|
-
const debounceAction = (callback, delay = 300) => {
|
|
62
|
+
export const debounceAction = (callback, delay = 300) => {
|
|
68
63
|
let timeoutId = undefined;
|
|
69
64
|
return (...args) => {
|
|
70
65
|
// Clear the previous timeout
|
|
@@ -75,7 +70,6 @@ const debounceAction = (callback, delay = 300) => {
|
|
|
75
70
|
}, delay);
|
|
76
71
|
};
|
|
77
72
|
};
|
|
78
|
-
exports.debounceAction = debounceAction;
|
|
79
73
|
/**
|
|
80
74
|
* * A generic throttle function that ensures a callback is executed at most once per specified interval.
|
|
81
75
|
*
|
|
@@ -90,7 +84,7 @@ exports.debounceAction = debounceAction;
|
|
|
90
84
|
*
|
|
91
85
|
* window.addEventListener('resize', throttledResize);
|
|
92
86
|
*/
|
|
93
|
-
const throttleAction = (callback, delay = 150) => {
|
|
87
|
+
export const throttleAction = (callback, delay = 150) => {
|
|
94
88
|
let lastCall = 0;
|
|
95
89
|
return (...args) => {
|
|
96
90
|
const now = Date.now();
|
|
@@ -100,4 +94,3 @@ const throttleAction = (callback, delay = 150) => {
|
|
|
100
94
|
}
|
|
101
95
|
};
|
|
102
96
|
};
|
|
103
|
-
exports.throttleAction = throttleAction;
|
package/package.json
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nhb-toolbox",
|
|
3
|
-
"version": "2.8.
|
|
3
|
+
"version": "2.8.3",
|
|
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",
|
|
7
|
+
"sideEffects": false,
|
|
7
8
|
"publishConfig": {
|
|
8
9
|
"access": "public"
|
|
9
10
|
},
|