nhb-toolbox 1.0.4 → 1.0.5
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/index.d.ts +10 -0
- package/dist/array/index.d.ts.map +1 -1
- package/dist/array/index.js +25 -1
- package/dist/array/types.d.ts +2 -2
- package/dist/array/types.d.ts.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/string/index.d.ts +2 -2
- package/dist/string/index.js +2 -2
- package/dist/string/types.d.ts +1 -1
- package/dist/string/types.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/array/index.d.ts
CHANGED
|
@@ -51,4 +51,14 @@ export declare function sortAnArray(array: boolean[], options?: OrderOption): bo
|
|
|
51
51
|
* @returns The sorted array.
|
|
52
52
|
*/
|
|
53
53
|
export declare function sortAnArray<T extends InputObject>(array: T[], options: SortOptions<T>): T[];
|
|
54
|
+
/**
|
|
55
|
+
* * Filters an array of objects based on multiple conditions for specified keys.
|
|
56
|
+
*
|
|
57
|
+
* @template T - The type of objects in the array.
|
|
58
|
+
* @param array - The array of objects to filter.
|
|
59
|
+
* @param conditions - An object where keys represent the property names and values represent the filter conditions.
|
|
60
|
+
* The conditions can be a value, a range, or a function.
|
|
61
|
+
* @returns The filtered array of objects.
|
|
62
|
+
*/
|
|
63
|
+
export declare const filterArrayOfObjects: <T extends Record<string, unknown>>(array: T[], conditions: { [K in keyof T]?: (value: T[K]) => boolean; }) => T[];
|
|
54
64
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/array/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACX,SAAS,EACT,aAAa,EACb,WAAW,EACX,WAAW,EACX,WAAW,EACX,WAAW,EACX,MAAM,SAAS,CAAC;AAEjB;;;;;;GAMG;AACH,eAAO,MAAM,YAAY,GAAI,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B,CAAC,SAAS,WAAW,EACrB,EAAE,SAAS,MAAM,YACjB,EAAE,SAAS,MAAM,kBAEX,CAAC,EAAE,UACD,aAAa,CAAC,CAAC,EAAE,EAAE,EAAE,EAAE,CAAC,KAC9B,GAAG,CAAC,IAAI,EAAE,GAAG,EAAE,GAAG,MAAM,GAAE,EAe5B,CAAC;AAEF;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,OAAO,CAAC,EAAE,WAAW,GAAG,MAAM,EAAE,CAAC;AAE9E;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,OAAO,CAAC,EAAE,WAAW,GAAG,MAAM,EAAE,CAAC;AAE9E;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,OAAO,EAAE,EAAE,OAAO,CAAC,EAAE,WAAW,GAAG,OAAO,EAAE,CAAC;AAEhF;;;;;;;;;GASG;AACH,wBAAgB,WAAW,CAAC,CAAC,SAAS,WAAW,EAChD,KAAK,EAAE,CAAC,EAAE,EACV,OAAO,EAAE,WAAW,CAAC,CAAC,CAAC,GACrB,CAAC,EAAE,CAAC;AA+EP;;;;;;;;GAQG;AACH,eAAO,MAAM,oBAAoB,GAAI,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,SAC9D,CAAC,EAAE,cACE,GAAG,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC,KAAK,OAAO,GAAE,KACvD,CAAC,EAgBH,CAAC"}
|
package/dist/array/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createOptionsArray = exports.flattenArray = void 0;
|
|
3
|
+
exports.filterArrayOfObjects = exports.createOptionsArray = exports.flattenArray = void 0;
|
|
4
4
|
exports.sortAnArray = sortAnArray;
|
|
5
5
|
/**
|
|
6
6
|
* * Flattens a nested array recursively or wraps any non-array data type in an array.
|
|
@@ -98,3 +98,27 @@ function sortAnArray(array, options) {
|
|
|
98
98
|
}
|
|
99
99
|
throw new Error('Invalid array or missing "sortByField" for objects.');
|
|
100
100
|
}
|
|
101
|
+
/**
|
|
102
|
+
* * Filters an array of objects based on multiple conditions for specified keys.
|
|
103
|
+
*
|
|
104
|
+
* @template T - The type of objects in the array.
|
|
105
|
+
* @param array - The array of objects to filter.
|
|
106
|
+
* @param conditions - An object where keys represent the property names and values represent the filter conditions.
|
|
107
|
+
* The conditions can be a value, a range, or a function.
|
|
108
|
+
* @returns The filtered array of objects.
|
|
109
|
+
*/
|
|
110
|
+
const filterArrayOfObjects = (array, conditions) => {
|
|
111
|
+
if (!Array.isArray(array)) {
|
|
112
|
+
throw new Error('The provided input is not an array!');
|
|
113
|
+
}
|
|
114
|
+
return array.filter((item) => Object.entries(conditions).every(([key, conditionFn]) => {
|
|
115
|
+
// Ensure we only check the key in the object if the condition function is provided
|
|
116
|
+
if (conditionFn) {
|
|
117
|
+
// Type assertion for the value since it's unknown
|
|
118
|
+
return conditionFn(item[key]);
|
|
119
|
+
}
|
|
120
|
+
// If no condition function, include all values for the key
|
|
121
|
+
return true;
|
|
122
|
+
}));
|
|
123
|
+
};
|
|
124
|
+
exports.filterArrayOfObjects = filterArrayOfObjects;
|
package/dist/array/types.d.ts
CHANGED
|
@@ -38,7 +38,7 @@ export interface ConfigOptions<T extends Record<string, string | number | null |
|
|
|
38
38
|
*/
|
|
39
39
|
secondFieldName?: K2;
|
|
40
40
|
}
|
|
41
|
-
/** - Object type with string or number as value for each key. */
|
|
41
|
+
/** - Object type with string or number or boolean as value for each key. */
|
|
42
42
|
export type InputObject = Record<string, string | number | boolean>;
|
|
43
43
|
/** - Option for sorting order. */
|
|
44
44
|
export interface OrderOption {
|
|
@@ -53,7 +53,7 @@ export interface OrderOption {
|
|
|
53
53
|
* * Options for sorting an array of objects.
|
|
54
54
|
* @template T - The type of objects in the array.
|
|
55
55
|
*/
|
|
56
|
-
export interface SortOptions<T extends
|
|
56
|
+
export interface SortOptions<T extends Record<string, unknown>> extends OrderOption {
|
|
57
57
|
/** The field by which to sort the objects in the array. */
|
|
58
58
|
sortByField?: keyof T;
|
|
59
59
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/array/types.ts"],"names":[],"mappings":"AAAA;;;;MAIM;AACN,MAAM,MAAM,SAAS,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,EAAE,GAAG,SAAS,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;AAEpE,wCAAwC;AACxC,MAAM,MAAM,WAAW,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC,CAAC;AAE7E;;;;;;;GAOG;AACH,MAAM,WAAW,aAAa,CAC7B,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC,EAC5D,EAAE,SAAS,MAAM,GAAG,OAAO,EAC3B,EAAE,SAAS,MAAM,GAAG,OAAO;IAE3B;;;OAGG;IACH,aAAa,EAAE,MAAM,CAAC,CAAC;IAEvB;;;OAGG;IACH,cAAc,EAAE,MAAM,CAAC,CAAC;IAExB;;;;OAIG;IACH,cAAc,CAAC,EAAE,EAAE,CAAC;IAEpB;;;;OAIG;IACH,eAAe,CAAC,EAAE,EAAE,CAAC;CACrB;AAED,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/array/types.ts"],"names":[],"mappings":"AAAA;;;;MAIM;AACN,MAAM,MAAM,SAAS,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,EAAE,GAAG,SAAS,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;AAEpE,wCAAwC;AACxC,MAAM,MAAM,WAAW,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC,CAAC;AAE7E;;;;;;;GAOG;AACH,MAAM,WAAW,aAAa,CAC7B,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC,EAC5D,EAAE,SAAS,MAAM,GAAG,OAAO,EAC3B,EAAE,SAAS,MAAM,GAAG,OAAO;IAE3B;;;OAGG;IACH,aAAa,EAAE,MAAM,CAAC,CAAC;IAEvB;;;OAGG;IACH,cAAc,EAAE,MAAM,CAAC,CAAC;IAExB;;;;OAIG;IACH,cAAc,CAAC,EAAE,EAAE,CAAC;IAEpB;;;;OAIG;IACH,eAAe,CAAC,EAAE,EAAE,CAAC;CACrB;AAED,4EAA4E;AAC5E,MAAM,MAAM,WAAW,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,CAAC;AAEpE,kCAAkC;AAClC,MAAM,WAAW,WAAW;IAC3B;;;;OAIG;IACH,SAAS,CAAC,EAAE,KAAK,GAAG,MAAM,CAAC;CAC3B;AAED;;;GAGG;AACH,MAAM,WAAW,WAAW,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAC7D,SAAQ,WAAW;IACnB,2DAA2D;IAC3D,WAAW,CAAC,EAAE,MAAM,CAAC,CAAC;CACtB"}
|
package/dist/index.d.ts
CHANGED
|
@@ -3,6 +3,6 @@ export { getRandomNumber, convertToDecimal } from './number';
|
|
|
3
3
|
export { getColorForInitial } from './colors';
|
|
4
4
|
export { generateRandomColor } from './colors/random';
|
|
5
5
|
export { convertHexToHsl, convertHexToRgb, convertHslToHex, convertHslToRgb, convertRgbToHex, convertRgbToHsl, } from './colors/convert';
|
|
6
|
-
export { flattenArray, createOptionsArray, sortAnArray } from './array';
|
|
6
|
+
export { flattenArray, createOptionsArray, sortAnArray, filterArrayOfObjects, } from './array';
|
|
7
7
|
export { generateQueryParams, cloneObject, isDeepEqual, mergeObjects, flattenObject, mergeAndFlattenObjects, isEmptyObject, countObjectFields, } from './object';
|
|
8
8
|
//# 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,EAAE,gBAAgB,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAE9E,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAE7D,OAAO,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAE9C,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAEtD,OAAO,EACN,eAAe,EACf,eAAe,EACf,eAAe,EACf,eAAe,EACf,eAAe,EACf,eAAe,GACf,MAAM,kBAAkB,CAAC;AAE1B,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAE9E,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAE7D,OAAO,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAE9C,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAEtD,OAAO,EACN,eAAe,EACf,eAAe,EACf,eAAe,EACf,eAAe,EACf,eAAe,EACf,eAAe,GACf,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EACN,YAAY,EACZ,kBAAkB,EAClB,WAAW,EACX,oBAAoB,GACpB,MAAM,SAAS,CAAC;AAEjB,OAAO,EACN,mBAAmB,EACnB,WAAW,EACX,WAAW,EACX,YAAY,EACZ,aAAa,EACb,sBAAsB,EACtB,aAAa,EACb,iBAAiB,GACjB,MAAM,UAAU,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.countObjectFields = exports.isEmptyObject = exports.mergeAndFlattenObjects = exports.flattenObject = exports.mergeObjects = exports.isDeepEqual = exports.cloneObject = exports.generateQueryParams = exports.sortAnArray = exports.createOptionsArray = exports.flattenArray = exports.convertRgbToHsl = exports.convertRgbToHex = exports.convertHslToRgb = exports.convertHslToHex = exports.convertHexToRgb = exports.convertHexToHsl = exports.generateRandomColor = exports.getColorForInitial = exports.convertToDecimal = exports.getRandomNumber = exports.generateRandomID = exports.truncateString = exports.capitalizeString = void 0;
|
|
3
|
+
exports.countObjectFields = exports.isEmptyObject = exports.mergeAndFlattenObjects = exports.flattenObject = exports.mergeObjects = exports.isDeepEqual = exports.cloneObject = exports.generateQueryParams = exports.filterArrayOfObjects = exports.sortAnArray = exports.createOptionsArray = exports.flattenArray = exports.convertRgbToHsl = exports.convertRgbToHex = exports.convertHslToRgb = exports.convertHslToHex = exports.convertHexToRgb = exports.convertHexToHsl = exports.generateRandomColor = exports.getColorForInitial = exports.convertToDecimal = exports.getRandomNumber = exports.generateRandomID = exports.truncateString = exports.capitalizeString = void 0;
|
|
4
4
|
var string_1 = require("./string");
|
|
5
5
|
Object.defineProperty(exports, "capitalizeString", { enumerable: true, get: function () { return string_1.capitalizeString; } });
|
|
6
6
|
Object.defineProperty(exports, "truncateString", { enumerable: true, get: function () { return string_1.truncateString; } });
|
|
@@ -23,6 +23,7 @@ var array_1 = require("./array");
|
|
|
23
23
|
Object.defineProperty(exports, "flattenArray", { enumerable: true, get: function () { return array_1.flattenArray; } });
|
|
24
24
|
Object.defineProperty(exports, "createOptionsArray", { enumerable: true, get: function () { return array_1.createOptionsArray; } });
|
|
25
25
|
Object.defineProperty(exports, "sortAnArray", { enumerable: true, get: function () { return array_1.sortAnArray; } });
|
|
26
|
+
Object.defineProperty(exports, "filterArrayOfObjects", { enumerable: true, get: function () { return array_1.filterArrayOfObjects; } });
|
|
26
27
|
var object_1 = require("./object");
|
|
27
28
|
Object.defineProperty(exports, "generateQueryParams", { enumerable: true, get: function () { return object_1.generateQueryParams; } });
|
|
28
29
|
Object.defineProperty(exports, "cloneObject", { enumerable: true, get: function () { return object_1.cloneObject; } });
|
package/dist/string/index.d.ts
CHANGED
|
@@ -17,10 +17,10 @@ export declare const capitalizeString: (string: string, options?: CapitalizeOpti
|
|
|
17
17
|
*/
|
|
18
18
|
export declare const truncateString: (string: string, maxLength: number) => string;
|
|
19
19
|
/**
|
|
20
|
-
* * Generates a
|
|
20
|
+
* * Generates a random alphanumeric (16 characters long, this length is customizable in the options) ID string composed of an optional `prefix`, `suffix`, a `timestamp`, and a customizable separator.
|
|
21
21
|
*
|
|
22
22
|
* @param options Configuration options for random ID generation.
|
|
23
|
-
* @returns The generated ID string composed of the random alphanumeric string
|
|
23
|
+
* @returns The generated ID string composed of the random alphanumeric string of specified length with optional `timeStamp`, `prefix`, and `suffix`, `caseOption` and `separator`.
|
|
24
24
|
*/
|
|
25
25
|
export declare const generateRandomID: (options?: RandomIdOptions) => string;
|
|
26
26
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/string/index.js
CHANGED
|
@@ -61,10 +61,10 @@ const truncateString = (string, maxLength) => {
|
|
|
61
61
|
};
|
|
62
62
|
exports.truncateString = truncateString;
|
|
63
63
|
/**
|
|
64
|
-
* * Generates a
|
|
64
|
+
* * Generates a random alphanumeric (16 characters long, this length is customizable in the options) ID string composed of an optional `prefix`, `suffix`, a `timestamp`, and a customizable separator.
|
|
65
65
|
*
|
|
66
66
|
* @param options Configuration options for random ID generation.
|
|
67
|
-
* @returns The generated ID string composed of the random alphanumeric string
|
|
67
|
+
* @returns The generated ID string composed of the random alphanumeric string of specified length with optional `timeStamp`, `prefix`, and `suffix`, `caseOption` and `separator`.
|
|
68
68
|
*/
|
|
69
69
|
const generateRandomID = (options) => {
|
|
70
70
|
const { prefix = '', suffix = '', timeStamp = false, length = 16, separator = '', caseOption = null, } = options || {};
|
package/dist/string/types.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/string/types.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/string/types.ts"],"names":[],"mappings":"AAAA,iDAAiD;AACjD,MAAM,WAAW,iBAAiB;IACjC,iGAAiG;IACjG,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAC9B,kFAAkF;IAClF,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,qFAAqF;IACrF,aAAa,CAAC,EAAE,OAAO,CAAC;CACxB;AAED,iDAAiD;AACjD,MAAM,WAAW,eAAe;IAC/B,iEAAiE;IACjE,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB,+DAA+D;IAC/D,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB,8EAA8E;IAC9E,SAAS,CAAC,EAAE,OAAO,CAAC;IAEpB,qEAAqE;IACrE,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB,gFAAgF;IAChF,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB,6DAA6D;IAC7D,UAAU,CAAC,EAAE,OAAO,GAAG,OAAO,GAAG,IAAI,CAAC;CACtC"}
|
package/package.json
CHANGED