nhb-toolbox 0.9.4 → 0.9.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 +12 -2
- package/dist/array/index.d.ts.map +1 -1
- package/dist/array/index.js +23 -2
- package/dist/array/types.d.ts +6 -0
- package/dist/array/types.d.ts.map +1 -1
- package/dist/array/types.js +2 -0
- package/dist/colors/types.d.ts +2 -1
- package/dist/colors/types.d.ts.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -1
- package/dist/object/index.d.ts +13 -0
- package/dist/object/index.d.ts.map +1 -0
- package/dist/object/index.js +24 -0
- package/package.json +1 -1
package/dist/array/index.d.ts
CHANGED
|
@@ -1,10 +1,20 @@
|
|
|
1
|
-
import type { Flatten } from './types';
|
|
1
|
+
import type { Flatten, SelectOptions } from './types';
|
|
2
2
|
/**
|
|
3
|
-
* Flattens a nested array recursively or wraps any non-array data type in an array.
|
|
3
|
+
* * Flattens a nested array recursively or wraps any non-array data type in an array.
|
|
4
4
|
*
|
|
5
5
|
* @typeParam T : The type of the input, which can be a nested array or a non-array value.
|
|
6
6
|
* @param input - The input value, which can be a nested array or a non-array value.
|
|
7
7
|
* @returns A fully flattened array of type `Flatten<T>`. If the input is not an array, it wraps it in a single-element array.
|
|
8
8
|
*/
|
|
9
9
|
export declare const flattenArray: <T>(input: T | T[]) => Flatten<T>[];
|
|
10
|
+
/**
|
|
11
|
+
* * Converts an array of objects into a formatted array of select options.
|
|
12
|
+
*
|
|
13
|
+
* @typeParam T - The type of each object in the `data` array.
|
|
14
|
+
* @param data - An array of objects to convert into select options.
|
|
15
|
+
* @param valueKey - The key in each object to use as the `value` field in the select options.
|
|
16
|
+
* @param labelKey - The key in each object to use as the `label` field in the select options.
|
|
17
|
+
* @returns An array of select options, where each option has a `value` and `label` field.
|
|
18
|
+
*/
|
|
19
|
+
export declare const createSelectOptions: <T extends Record<string, string | number | null | undefined>>(data: T[], valueKey: keyof T, labelKey: keyof T) => SelectOptions[];
|
|
10
20
|
//# 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,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/array/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAEtD;;;;;;GAMG;AACH,eAAO,MAAM,YAAY,GAAI,CAAC,SAAS,CAAC,GAAG,CAAC,EAAE,KAAG,OAAO,CAAC,CAAC,CAAC,EAO1D,CAAC;AAEF;;;;;;;;GAQG;AACH,eAAO,MAAM,mBAAmB,GAC/B,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC,QAEtD,CAAC,EAAE,YACC,MAAM,CAAC,YACP,MAAM,CAAC,KACf,aAAa,EASf,CAAC"}
|
package/dist/array/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.flattenArray = void 0;
|
|
3
|
+
exports.createSelectOptions = exports.flattenArray = void 0;
|
|
4
4
|
/**
|
|
5
|
-
* Flattens a nested array recursively or wraps any non-array data type in an array.
|
|
5
|
+
* * Flattens a nested array recursively or wraps any non-array data type in an array.
|
|
6
6
|
*
|
|
7
7
|
* @typeParam T : The type of the input, which can be a nested array or a non-array value.
|
|
8
8
|
* @param input - The input value, which can be a nested array or a non-array value.
|
|
@@ -17,3 +17,24 @@ const flattenArray = (input) => {
|
|
|
17
17
|
}, []);
|
|
18
18
|
};
|
|
19
19
|
exports.flattenArray = flattenArray;
|
|
20
|
+
/**
|
|
21
|
+
* * Converts an array of objects into a formatted array of select options.
|
|
22
|
+
*
|
|
23
|
+
* @typeParam T - The type of each object in the `data` array.
|
|
24
|
+
* @param data - An array of objects to convert into select options.
|
|
25
|
+
* @param valueKey - The key in each object to use as the `value` field in the select options.
|
|
26
|
+
* @param labelKey - The key in each object to use as the `label` field in the select options.
|
|
27
|
+
* @returns An array of select options, where each option has a `value` and `label` field.
|
|
28
|
+
*/
|
|
29
|
+
const createSelectOptions = (data, valueKey, labelKey) => {
|
|
30
|
+
if (data && data.length) {
|
|
31
|
+
return data.map((datum) => ({
|
|
32
|
+
value: String(datum[valueKey] ?? ''),
|
|
33
|
+
label: String(datum[labelKey] ?? ''),
|
|
34
|
+
}));
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
return [];
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
exports.createSelectOptions = createSelectOptions;
|
package/dist/array/types.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/array/types.ts"],"names":[],"mappings":"AAAA,sBAAsB;AACtB,MAAM,MAAM,OAAO,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,EAAE,GAAG,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC"}
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/array/types.ts"],"names":[],"mappings":"AAAA,sBAAsB;AACtB,MAAM,MAAM,OAAO,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,EAAE,GAAG,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;AAEhE,uBAAuB;AACvB,MAAM,WAAW,aAAa;IAC7B,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;CACd;AAED,OAAO"}
|
package/dist/array/types.js
CHANGED
package/dist/colors/types.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
/** - A string, number for generating color. */
|
|
2
2
|
export type ColorInput = string | number;
|
|
3
3
|
/** - An array of strings/numbers or nested arrays of strings/numbers for generating colors. */
|
|
4
|
-
export
|
|
4
|
+
export interface ColorInputArray extends Array<ColorInput | ColorInputArray> {
|
|
5
|
+
}
|
|
5
6
|
/** - Opacity options */
|
|
6
7
|
export type OpacityValue = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100;
|
|
7
8
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/colors/types.ts"],"names":[],"mappings":"AAAA,+CAA+C;AAC/C,MAAM,MAAM,UAAU,GAAG,MAAM,GAAG,MAAM,CAAC;AAEzC,+FAA+F;AAC/F,MAAM,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/colors/types.ts"],"names":[],"mappings":"AAAA,+CAA+C;AAC/C,MAAM,MAAM,UAAU,GAAG,MAAM,GAAG,MAAM,CAAC;AAEzC,+FAA+F;AAC/F,MAAM,WAAW,eAAgB,SAAQ,KAAK,CAAC,UAAU,GAAG,eAAe,CAAC;CAAG;AAE/E,wBAAwB;AACxB,MAAM,MAAM,YAAY,GACrB,CAAC,GACD,CAAC,GACD,CAAC,GACD,CAAC,GACD,CAAC,GACD,CAAC,GACD,CAAC,GACD,CAAC,GACD,CAAC,GACD,CAAC,GACD,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,GAAG,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { capitalizeString, truncateString, generateRandomID } from './string';
|
|
2
2
|
export { getColorForFirstCharacter } from './colors';
|
|
3
|
-
export { flattenArray } from './array';
|
|
3
|
+
export { flattenArray, createSelectOptions } from './array';
|
|
4
|
+
export { generateQueryParams } from './object';
|
|
4
5
|
//# 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,yBAAyB,EAAE,MAAM,UAAU,CAAC;AAErD,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC"}
|
|
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,yBAAyB,EAAE,MAAM,UAAU,CAAC;AAErD,OAAO,EAAE,YAAY,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAE5D,OAAO,EAAE,mBAAmB,EAAE,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.flattenArray = exports.getColorForFirstCharacter = exports.generateRandomID = exports.truncateString = exports.capitalizeString = void 0;
|
|
3
|
+
exports.generateQueryParams = exports.createSelectOptions = exports.flattenArray = exports.getColorForFirstCharacter = 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; } });
|
|
@@ -9,3 +9,6 @@ var colors_1 = require("./colors");
|
|
|
9
9
|
Object.defineProperty(exports, "getColorForFirstCharacter", { enumerable: true, get: function () { return colors_1.getColorForFirstCharacter; } });
|
|
10
10
|
var array_1 = require("./array");
|
|
11
11
|
Object.defineProperty(exports, "flattenArray", { enumerable: true, get: function () { return array_1.flattenArray; } });
|
|
12
|
+
Object.defineProperty(exports, "createSelectOptions", { enumerable: true, get: function () { return array_1.createSelectOptions; } });
|
|
13
|
+
var object_1 = require("./object");
|
|
14
|
+
Object.defineProperty(exports, "generateQueryParams", { enumerable: true, get: function () { return object_1.generateQueryParams; } });
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* * Utility function to generate query parameters from an object.
|
|
3
|
+
*
|
|
4
|
+
* @template T - A generic type extending `Record<string, string | number | string[] | number[]>`.
|
|
5
|
+
* @param params - Object containing query parameters.
|
|
6
|
+
* @returns A query string as a URL-encoded string, e.g., `?key1=value1&key2=value2`.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* generateQueryParams({ key1: 'value1', key2: 42 }); // "?key1=value1&key2=42"
|
|
10
|
+
* generateQueryParams({ key1: ['value1', 'value2'], key2: 42 }); // "?key1=value1&key1=value2&key2=42"
|
|
11
|
+
*/
|
|
12
|
+
export declare const generateQueryParams: <T extends Record<string, string | number | string[] | number[]>>(params?: T) => string;
|
|
13
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/object/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,eAAO,MAAM,mBAAmB,GAC/B,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,EAAE,GAAG,MAAM,EAAE,CAAC,WAEvD,CAAC,KACP,MAkBF,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.generateQueryParams = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* * Utility function to generate query parameters from an object.
|
|
6
|
+
*
|
|
7
|
+
* @template T - A generic type extending `Record<string, string | number | string[] | number[]>`.
|
|
8
|
+
* @param params - Object containing query parameters.
|
|
9
|
+
* @returns A query string as a URL-encoded string, e.g., `?key1=value1&key2=value2`.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* generateQueryParams({ key1: 'value1', key2: 42 }); // "?key1=value1&key2=42"
|
|
13
|
+
* generateQueryParams({ key1: ['value1', 'value2'], key2: 42 }); // "?key1=value1&key1=value2&key2=42"
|
|
14
|
+
*/
|
|
15
|
+
const generateQueryParams = (params = {}) => {
|
|
16
|
+
const queryParams = Object.entries(params)
|
|
17
|
+
.filter(([_, value]) => value !== undefined && value !== null)
|
|
18
|
+
.flatMap(([key, value]) => Array.isArray(value)
|
|
19
|
+
? value.map((v) => `${encodeURIComponent(key)}=${encodeURIComponent(String(v))}`)
|
|
20
|
+
: `${encodeURIComponent(key)}=${encodeURIComponent(String(value))}`)
|
|
21
|
+
.join('&');
|
|
22
|
+
return queryParams ? `?${queryParams}` : '';
|
|
23
|
+
};
|
|
24
|
+
exports.generateQueryParams = generateQueryParams;
|
package/package.json
CHANGED