nhb-toolbox 0.9.3 → 0.9.4

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.
@@ -0,0 +1,10 @@
1
+ import type { Flatten } from './types';
2
+ /**
3
+ * Flattens a nested array recursively or wraps any non-array data type in an array.
4
+ *
5
+ * @typeParam T : The type of the input, which can be a nested array or a non-array value.
6
+ * @param input - The input value, which can be a nested array or a non-array value.
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
+ */
9
+ export declare const flattenArray: <T>(input: T | T[]) => Flatten<T>[];
10
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +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;AAEvC;;;;;;GAMG;AACH,eAAO,MAAM,YAAY,GAAI,CAAC,SAAS,CAAC,GAAG,CAAC,EAAE,KAAG,OAAO,CAAC,CAAC,CAAC,EAO1D,CAAC"}
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.flattenArray = void 0;
4
+ /**
5
+ * Flattens a nested array recursively or wraps any non-array data type in an array.
6
+ *
7
+ * @typeParam T : The type of the input, which can be a nested array or a non-array value.
8
+ * @param input - The input value, which can be a nested array or a non-array value.
9
+ * @returns A fully flattened array of type `Flatten<T>`. If the input is not an array, it wraps it in a single-element array.
10
+ */
11
+ const flattenArray = (input) => {
12
+ if (!Array.isArray(input))
13
+ return [input];
14
+ return input.reduce((acc, item) => {
15
+ // If item is an array, recursively flatten it; otherwise, add it directly.
16
+ return acc.concat(Array.isArray(item) ? (0, exports.flattenArray)(item) : [item]);
17
+ }, []);
18
+ };
19
+ exports.flattenArray = flattenArray;
@@ -0,0 +1,3 @@
1
+ /** - Flatten Array */
2
+ export type Flatten<T> = T extends (infer U)[] ? Flatten<U> : T;
3
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +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"}
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/dist/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  export { capitalizeString, truncateString, generateRandomID } from './string';
2
2
  export { getColorForFirstCharacter } from './colors';
3
+ export { flattenArray } from './array';
3
4
  //# sourceMappingURL=index.d.ts.map
@@ -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"}
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"}
package/dist/index.js CHANGED
@@ -1,9 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getColorForFirstCharacter = exports.generateRandomID = exports.truncateString = exports.capitalizeString = void 0;
3
+ 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; } });
7
7
  Object.defineProperty(exports, "generateRandomID", { enumerable: true, get: function () { return string_1.generateRandomID; } });
8
8
  var colors_1 = require("./colors");
9
9
  Object.defineProperty(exports, "getColorForFirstCharacter", { enumerable: true, get: function () { return colors_1.getColorForFirstCharacter; } });
10
+ var array_1 = require("./array");
11
+ Object.defineProperty(exports, "flattenArray", { enumerable: true, get: function () { return array_1.flattenArray; } });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nhb-toolbox",
3
- "version": "0.9.3",
3
+ "version": "0.9.4",
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",