nhb-toolbox 1.7.5 → 1.8.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.
@@ -25,4 +25,11 @@ export declare const filterArrayOfObjects: <T extends GenericObject>(array: T[],
25
25
  * @returns Whether the array is empty.
26
26
  */
27
27
  export declare const isValidButEmptyArray: <T>(array: T[] | unknown) => boolean;
28
+ /**
29
+ * * Shuffle the elements of an array.
30
+ *
31
+ * @param array Array to shuffle.
32
+ * @returns Shuffled array.
33
+ */
34
+ export declare const shuffleArray: <T>(array: T[]) => T[];
28
35
  //# sourceMappingURL=basics.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"basics.d.ts","sourceRoot":"","sources":["../../src/array/basics.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AACrD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAEzC;;;;;;GAMG;AACH,eAAO,MAAM,YAAY,GAAI,CAAC,SAAS,CAAC,GAAG,CAAC,EAAE,KAAG,SAAS,CAAC,CAAC,CAAC,EAO5D,CAAC;AAEF;;;;;;;;GAQG;AACH,eAAO,MAAM,oBAAoB,GAAI,CAAC,SAAS,aAAa,SACpD,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;AAEF;;;;;GAKG;AACH,eAAO,MAAM,oBAAoB,GAAI,CAAC,SAAS,CAAC,EAAE,GAAG,OAAO,KAAG,OAE9D,CAAC"}
1
+ {"version":3,"file":"basics.d.ts","sourceRoot":"","sources":["../../src/array/basics.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AACrD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAEzC;;;;;;GAMG;AACH,eAAO,MAAM,YAAY,GAAI,CAAC,SAAS,CAAC,GAAG,CAAC,EAAE,KAAG,SAAS,CAAC,CAAC,CAAC,EAO5D,CAAC;AAEF;;;;;;;;GAQG;AACH,eAAO,MAAM,oBAAoB,GAAI,CAAC,SAAS,aAAa,SACpD,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;AAEF;;;;;GAKG;AACH,eAAO,MAAM,oBAAoB,GAAI,CAAC,SAAS,CAAC,EAAE,GAAG,OAAO,KAAG,OAE9D,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,YAAY,GAAI,CAAC,SAAS,CAAC,EAAE,KAAG,CAAC,EAW7C,CAAC"}
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isValidButEmptyArray = exports.filterArrayOfObjects = exports.flattenArray = void 0;
3
+ exports.shuffleArray = exports.isValidButEmptyArray = exports.filterArrayOfObjects = exports.flattenArray = void 0;
4
4
  /**
5
5
  * * Flattens a nested array recursively or wraps any non-array data type in an array.
6
6
  *
@@ -51,3 +51,20 @@ const isValidButEmptyArray = (array) => {
51
51
  return Array.isArray(array) && array.length === 0;
52
52
  };
53
53
  exports.isValidButEmptyArray = isValidButEmptyArray;
54
+ /**
55
+ * * Shuffle the elements of an array.
56
+ *
57
+ * @param array Array to shuffle.
58
+ * @returns Shuffled array.
59
+ */
60
+ const shuffleArray = (array) => {
61
+ if ((0, exports.isValidButEmptyArray)(array))
62
+ return array;
63
+ const shuffled = structuredClone(array);
64
+ for (let i = shuffled.length - 1; i > 0; i--) {
65
+ const j = Math.floor(Math.random() * (i + 1));
66
+ [shuffled[i], shuffled[j]] = [shuffled[j], shuffled[i]];
67
+ }
68
+ return shuffled;
69
+ };
70
+ exports.shuffleArray = shuffleArray;
@@ -1,4 +1,4 @@
1
- import type { InputObject, OrderOption, SortOptions } from "./types";
1
+ import type { InputObject, OrderOption, SortOptions } from './types';
2
2
  /**
3
3
  * * Sorts an array of strings.
4
4
  *
package/dist/index.d.ts CHANGED
@@ -1,14 +1,16 @@
1
1
  export { capitalizeString, generateRandomID, trimString, truncateString, } from './string/basics';
2
2
  export { generateAnagrams } from './string/anagram';
3
+ export { convertStringCase } from './string/convert';
3
4
  export { convertToDecimal, getRandomNumber } from './number/basics';
4
5
  export { numberToWords } from './number/convert';
5
6
  export { findPrimeNumbers, isPrime } from './number/prime';
7
+ export { getNumbersInRange } from './number/range';
6
8
  export { getColorForInitial } from './colors/initials';
7
9
  export { generateRandomColorInHexRGB, generateRandomHSLColor, } from './colors/random';
8
10
  export { convertColorCode, convertHexToHsl, convertHexToRgb, convertHslToHex, convertHslToRgb, convertRgbToHex, convertRgbToHsl, } from './colors/convert';
9
11
  export { Color } from './colors/Color';
10
12
  export { extractNumbersFromColor } from './colors/helpers';
11
- export { filterArrayOfObjects, flattenArray, isValidButEmptyArray, } from './array/basics';
13
+ export { filterArrayOfObjects, flattenArray, isValidButEmptyArray, shuffleArray, } from './array/basics';
12
14
  export { sortAnArray } from './array/sort';
13
15
  export { createOptionsArray } from './array/transform';
14
16
  export { convertIntoFormData, isEmptyFormData } from './form/convert';
@@ -17,5 +19,5 @@ export { cloneObject, countObjectFields, generateQueryParams, isEmptyObject, isO
17
19
  export { extractNewFields, extractUpdatedAndNewFields, extractUpdatedFields, flattenObject, mergeAndFlattenObjects, mergeObjects, } from './object/objectify';
18
20
  export { sanitizeData } from './object/sanitize';
19
21
  export { convertObjectValues } from './object/convert';
20
- export { isDeepEqual } from './utils';
22
+ export { convertArrayToString, isDeepEqual } from './utils';
21
23
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,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,EAAE,wBAAwB,EAAE,MAAM,kBAAkB,CAAC;AAE5D,OAAO,EACN,WAAW,EACX,iBAAiB,EACjB,mBAAmB,EACnB,aAAa,EACb,QAAQ,GACR,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EACN,gBAAgB,EAChB,0BAA0B,EAC1B,oBAAoB,EACpB,aAAa,EACb,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,EAAE,oBAAoB,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC"}
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isDeepEqual = exports.convertObjectValues = exports.sanitizeData = exports.mergeObjects = exports.mergeAndFlattenObjects = exports.flattenObject = exports.extractUpdatedFields = exports.extractUpdatedAndNewFields = exports.extractNewFields = exports.isObject = exports.isEmptyObject = exports.generateQueryParams = exports.countObjectFields = exports.cloneObject = exports.createControlledFormData = exports.isEmptyFormData = exports.convertIntoFormData = exports.createOptionsArray = exports.sortAnArray = exports.isValidButEmptyArray = exports.flattenArray = exports.filterArrayOfObjects = exports.extractNumbersFromColor = exports.Color = exports.convertRgbToHsl = exports.convertRgbToHex = exports.convertHslToRgb = exports.convertHslToHex = exports.convertHexToRgb = exports.convertHexToHsl = exports.convertColorCode = exports.generateRandomHSLColor = exports.generateRandomColorInHexRGB = exports.getColorForInitial = exports.isPrime = exports.findPrimeNumbers = exports.numberToWords = exports.getRandomNumber = exports.convertToDecimal = exports.generateAnagrams = exports.truncateString = exports.trimString = exports.generateRandomID = exports.capitalizeString = void 0;
3
+ exports.isDeepEqual = exports.convertArrayToString = exports.convertObjectValues = exports.sanitizeData = exports.mergeObjects = exports.mergeAndFlattenObjects = exports.flattenObject = exports.extractUpdatedFields = exports.extractUpdatedAndNewFields = exports.extractNewFields = exports.isObject = exports.isEmptyObject = exports.generateQueryParams = exports.countObjectFields = exports.cloneObject = exports.createControlledFormData = exports.isEmptyFormData = exports.convertIntoFormData = exports.createOptionsArray = exports.sortAnArray = exports.shuffleArray = exports.isValidButEmptyArray = exports.flattenArray = exports.filterArrayOfObjects = exports.extractNumbersFromColor = exports.Color = exports.convertRgbToHsl = exports.convertRgbToHex = exports.convertHslToRgb = exports.convertHslToHex = exports.convertHexToRgb = exports.convertHexToHsl = exports.convertColorCode = exports.generateRandomHSLColor = exports.generateRandomColorInHexRGB = exports.getColorForInitial = exports.getNumbersInRange = exports.isPrime = exports.findPrimeNumbers = exports.numberToWords = exports.getRandomNumber = exports.convertToDecimal = exports.convertStringCase = exports.generateAnagrams = exports.truncateString = exports.trimString = exports.generateRandomID = exports.capitalizeString = void 0;
4
4
  var basics_1 = require("./string/basics");
5
5
  Object.defineProperty(exports, "capitalizeString", { enumerable: true, get: function () { return basics_1.capitalizeString; } });
6
6
  Object.defineProperty(exports, "generateRandomID", { enumerable: true, get: function () { return basics_1.generateRandomID; } });
@@ -8,27 +8,31 @@ Object.defineProperty(exports, "trimString", { enumerable: true, get: function (
8
8
  Object.defineProperty(exports, "truncateString", { enumerable: true, get: function () { return basics_1.truncateString; } });
9
9
  var anagram_1 = require("./string/anagram");
10
10
  Object.defineProperty(exports, "generateAnagrams", { enumerable: true, get: function () { return anagram_1.generateAnagrams; } });
11
+ var convert_1 = require("./string/convert");
12
+ Object.defineProperty(exports, "convertStringCase", { enumerable: true, get: function () { return convert_1.convertStringCase; } });
11
13
  var basics_2 = require("./number/basics");
12
14
  Object.defineProperty(exports, "convertToDecimal", { enumerable: true, get: function () { return basics_2.convertToDecimal; } });
13
15
  Object.defineProperty(exports, "getRandomNumber", { enumerable: true, get: function () { return basics_2.getRandomNumber; } });
14
- var convert_1 = require("./number/convert");
15
- Object.defineProperty(exports, "numberToWords", { enumerable: true, get: function () { return convert_1.numberToWords; } });
16
+ var convert_2 = require("./number/convert");
17
+ Object.defineProperty(exports, "numberToWords", { enumerable: true, get: function () { return convert_2.numberToWords; } });
16
18
  var prime_1 = require("./number/prime");
17
19
  Object.defineProperty(exports, "findPrimeNumbers", { enumerable: true, get: function () { return prime_1.findPrimeNumbers; } });
18
20
  Object.defineProperty(exports, "isPrime", { enumerable: true, get: function () { return prime_1.isPrime; } });
21
+ var range_1 = require("./number/range");
22
+ Object.defineProperty(exports, "getNumbersInRange", { enumerable: true, get: function () { return range_1.getNumbersInRange; } });
19
23
  var initials_1 = require("./colors/initials");
20
24
  Object.defineProperty(exports, "getColorForInitial", { enumerable: true, get: function () { return initials_1.getColorForInitial; } });
21
25
  var random_1 = require("./colors/random");
22
26
  Object.defineProperty(exports, "generateRandomColorInHexRGB", { enumerable: true, get: function () { return random_1.generateRandomColorInHexRGB; } });
23
27
  Object.defineProperty(exports, "generateRandomHSLColor", { enumerable: true, get: function () { return random_1.generateRandomHSLColor; } });
24
- var convert_2 = require("./colors/convert");
25
- Object.defineProperty(exports, "convertColorCode", { enumerable: true, get: function () { return convert_2.convertColorCode; } });
26
- Object.defineProperty(exports, "convertHexToHsl", { enumerable: true, get: function () { return convert_2.convertHexToHsl; } });
27
- Object.defineProperty(exports, "convertHexToRgb", { enumerable: true, get: function () { return convert_2.convertHexToRgb; } });
28
- Object.defineProperty(exports, "convertHslToHex", { enumerable: true, get: function () { return convert_2.convertHslToHex; } });
29
- Object.defineProperty(exports, "convertHslToRgb", { enumerable: true, get: function () { return convert_2.convertHslToRgb; } });
30
- Object.defineProperty(exports, "convertRgbToHex", { enumerable: true, get: function () { return convert_2.convertRgbToHex; } });
31
- Object.defineProperty(exports, "convertRgbToHsl", { enumerable: true, get: function () { return convert_2.convertRgbToHsl; } });
28
+ var convert_3 = require("./colors/convert");
29
+ Object.defineProperty(exports, "convertColorCode", { enumerable: true, get: function () { return convert_3.convertColorCode; } });
30
+ Object.defineProperty(exports, "convertHexToHsl", { enumerable: true, get: function () { return convert_3.convertHexToHsl; } });
31
+ Object.defineProperty(exports, "convertHexToRgb", { enumerable: true, get: function () { return convert_3.convertHexToRgb; } });
32
+ Object.defineProperty(exports, "convertHslToHex", { enumerable: true, get: function () { return convert_3.convertHslToHex; } });
33
+ Object.defineProperty(exports, "convertHslToRgb", { enumerable: true, get: function () { return convert_3.convertHslToRgb; } });
34
+ Object.defineProperty(exports, "convertRgbToHex", { enumerable: true, get: function () { return convert_3.convertRgbToHex; } });
35
+ Object.defineProperty(exports, "convertRgbToHsl", { enumerable: true, get: function () { return convert_3.convertRgbToHsl; } });
32
36
  var Color_1 = require("./colors/Color");
33
37
  Object.defineProperty(exports, "Color", { enumerable: true, get: function () { return Color_1.Color; } });
34
38
  var helpers_1 = require("./colors/helpers");
@@ -37,13 +41,14 @@ var basics_3 = require("./array/basics");
37
41
  Object.defineProperty(exports, "filterArrayOfObjects", { enumerable: true, get: function () { return basics_3.filterArrayOfObjects; } });
38
42
  Object.defineProperty(exports, "flattenArray", { enumerable: true, get: function () { return basics_3.flattenArray; } });
39
43
  Object.defineProperty(exports, "isValidButEmptyArray", { enumerable: true, get: function () { return basics_3.isValidButEmptyArray; } });
44
+ Object.defineProperty(exports, "shuffleArray", { enumerable: true, get: function () { return basics_3.shuffleArray; } });
40
45
  var sort_1 = require("./array/sort");
41
46
  Object.defineProperty(exports, "sortAnArray", { enumerable: true, get: function () { return sort_1.sortAnArray; } });
42
47
  var transform_1 = require("./array/transform");
43
48
  Object.defineProperty(exports, "createOptionsArray", { enumerable: true, get: function () { return transform_1.createOptionsArray; } });
44
- var convert_3 = require("./form/convert");
45
- Object.defineProperty(exports, "convertIntoFormData", { enumerable: true, get: function () { return convert_3.convertIntoFormData; } });
46
- Object.defineProperty(exports, "isEmptyFormData", { enumerable: true, get: function () { return convert_3.isEmptyFormData; } });
49
+ var convert_4 = require("./form/convert");
50
+ Object.defineProperty(exports, "convertIntoFormData", { enumerable: true, get: function () { return convert_4.convertIntoFormData; } });
51
+ Object.defineProperty(exports, "isEmptyFormData", { enumerable: true, get: function () { return convert_4.isEmptyFormData; } });
47
52
  var transform_2 = require("./form/transform");
48
53
  Object.defineProperty(exports, "createControlledFormData", { enumerable: true, get: function () { return transform_2.createControlledFormData; } });
49
54
  var basics_4 = require("./object/basics");
@@ -61,7 +66,8 @@ Object.defineProperty(exports, "mergeAndFlattenObjects", { enumerable: true, get
61
66
  Object.defineProperty(exports, "mergeObjects", { enumerable: true, get: function () { return objectify_1.mergeObjects; } });
62
67
  var sanitize_1 = require("./object/sanitize");
63
68
  Object.defineProperty(exports, "sanitizeData", { enumerable: true, get: function () { return sanitize_1.sanitizeData; } });
64
- var convert_4 = require("./object/convert");
65
- Object.defineProperty(exports, "convertObjectValues", { enumerable: true, get: function () { return convert_4.convertObjectValues; } });
69
+ var convert_5 = require("./object/convert");
70
+ Object.defineProperty(exports, "convertObjectValues", { enumerable: true, get: function () { return convert_5.convertObjectValues; } });
66
71
  var utils_1 = require("./utils");
72
+ Object.defineProperty(exports, "convertArrayToString", { enumerable: true, get: function () { return utils_1.convertArrayToString; } });
67
73
  Object.defineProperty(exports, "isDeepEqual", { enumerable: true, get: function () { return utils_1.isDeepEqual; } });
@@ -9,7 +9,7 @@ import type { DecimalOptions, RandomNumberOptions } from './types';
9
9
  */
10
10
  export declare const getRandomNumber: (options?: RandomNumberOptions) => number;
11
11
  /**
12
- * * Utility to round a number to a given decimal places.
12
+ * * Utility to round a number to given decimal places.
13
13
  *
14
14
  * @param num - Number to round.
15
15
  * @param options - Options for rounding behavior, including decimal places and return type.
@@ -44,7 +44,7 @@ const getRandomNumber = (options) => {
44
44
  };
45
45
  exports.getRandomNumber = getRandomNumber;
46
46
  /**
47
- * * Utility to round a number to a given decimal places.
47
+ * * Utility to round a number to given decimal places.
48
48
  *
49
49
  * @param num - Number to round.
50
50
  * @param options - Options for rounding behavior, including decimal places and return type.
@@ -0,0 +1,11 @@
1
+ import type { GetAs, NumberType, RangedNumbers, RangeOptions } from './types';
2
+ /**
3
+ * * Function to get numbers within a range based on the provided `NumberType` and options.
4
+ * * Returns either a string or an array of numbers based on the `getAs` property in options.
5
+ *
6
+ * @param type - The type of numbers to generate ('random', 'prime', etc.).
7
+ * @param options - Options to configure number generation, including range and formatting.
8
+ * @returns Either a string or an array of numbers.
9
+ */
10
+ export declare function getNumbersInRange<T extends GetAs>(type?: NumberType, options?: RangeOptions<T>): RangedNumbers<T>;
11
+ //# sourceMappingURL=range.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"range.d.ts","sourceRoot":"","sources":["../../src/number/range.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,KAAK,EAAE,UAAU,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAE9E;;;;;;;GAOG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,SAAS,KAAK,EAChD,IAAI,GAAE,UAAkB,EACxB,OAAO,CAAC,EAAE,YAAY,CAAC,CAAC,CAAC,GACvB,aAAa,CAAC,CAAC,CAAC,CAsGlB"}
@@ -0,0 +1,88 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getNumbersInRange = getNumbersInRange;
4
+ const basics_1 = require("../array/basics");
5
+ const utils_1 = require("../utils");
6
+ const basics_2 = require("./basics");
7
+ const prime_1 = require("./prime");
8
+ /**
9
+ * * Function to get numbers within a range based on the provided `NumberType` and options.
10
+ * * Returns either a string or an array of numbers based on the `getAs` property in options.
11
+ *
12
+ * @param type - The type of numbers to generate ('random', 'prime', etc.).
13
+ * @param options - Options to configure number generation, including range and formatting.
14
+ * @returns Either a string or an array of numbers.
15
+ */
16
+ function getNumbersInRange(type = 'any', options) {
17
+ const { getAs = 'array', min = 0, max = 100, includeMin = true, includeMax = true, separator = ',', multiples, } = options || {};
18
+ let output = [];
19
+ /**
20
+ * Apply multiples of a number if there is any.
21
+ * @param array Array of numbers to apply the condition on.
22
+ * @param multiples The multiples of which number.
23
+ * @returns Array of multiples of the desired number
24
+ */
25
+ const _applyMultiples = (array, multiples) => {
26
+ if (!multiples)
27
+ return array;
28
+ return array.filter((n) => n % multiples === 0);
29
+ };
30
+ /**
31
+ * Helper function to apply range and get array of numbers in that range.
32
+ *
33
+ * @param start The start of the range.
34
+ * @param end The end of the range.
35
+ * @returns The array of numbers in the range.
36
+ */
37
+ const _applyRangeOptions = (start, end) => {
38
+ let startNumber = start;
39
+ let endNumber = end;
40
+ if (start > end) {
41
+ [startNumber, endNumber] = [end, start];
42
+ }
43
+ const numbers = [];
44
+ for (let i = startNumber; i <= endNumber; i++) {
45
+ if (i >= min &&
46
+ i <= max &&
47
+ (includeMin || i > min) &&
48
+ (includeMax || i < max)) {
49
+ numbers.push(i);
50
+ }
51
+ }
52
+ return numbers;
53
+ };
54
+ if (type === 'prime' && multiples !== undefined) {
55
+ console.warn('Warning: The "multiples" option is ignored when the type is "prime"!');
56
+ }
57
+ switch (type) {
58
+ case 'random':
59
+ output = (0, basics_1.shuffleArray)(_applyRangeOptions(min, max).map((n) => (0, basics_2.getRandomNumber)({
60
+ min: n,
61
+ max: n,
62
+ includeMin,
63
+ includeMax,
64
+ })));
65
+ break;
66
+ case 'prime':
67
+ output = _applyRangeOptions(min, max).filter(prime_1.isPrime);
68
+ break;
69
+ case 'odd':
70
+ output = _applyRangeOptions(min, max).filter((i) => i % 2 !== 0);
71
+ break;
72
+ case 'even':
73
+ output = _applyRangeOptions(min, max).filter((i) => i % 2 === 0);
74
+ break;
75
+ case 'natural':
76
+ output = _applyRangeOptions(Math.max(min, 1), max);
77
+ break;
78
+ default:
79
+ output = _applyRangeOptions(min, max);
80
+ break;
81
+ }
82
+ if (type !== 'prime') {
83
+ output = _applyMultiples(output, multiples);
84
+ }
85
+ return getAs === 'string' ?
86
+ (0, utils_1.convertArrayToString)(output, separator)
87
+ : output;
88
+ }
@@ -16,4 +16,19 @@ export interface DecimalOptions {
16
16
  /** If the return value is in `string` or `number`. Defaults to `false`. */
17
17
  isString?: boolean;
18
18
  }
19
+ /** - Type of numbers to generate */
20
+ export type NumberType = 'any' | 'natural' | 'odd' | 'even' | 'prime' | 'random';
21
+ /** - Output format for the generated numbers */
22
+ export type GetAs = 'array' | 'string';
23
+ /** - Options for generating numbers in a range */
24
+ export interface RangeOptions<T extends GetAs> extends RandomNumberOptions {
25
+ /** Separator for the string format if `getAs` is `'string'`. Defaults to `,`. */
26
+ separator?: string;
27
+ /** The multiples of which number to consider in the result. */
28
+ multiples?: number;
29
+ /** The format for the result - either `'array'` or `'string'`. Default is `array` */
30
+ getAs?: T;
31
+ }
32
+ /** - The return type of the `getNumbersInRange` function */
33
+ export type RangedNumbers<T extends GetAs> = T extends 'array' ? number[] : string;
19
34
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/number/types.ts"],"names":[],"mappings":"AAAA,4CAA4C;AAC5C,MAAM,WAAW,mBAAmB;IACnC,oCAAoC;IACpC,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,kCAAkC;IAClC,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,6CAA6C;IAC7C,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,6CAA6C;IAC7C,UAAU,CAAC,EAAE,OAAO,CAAC;CACrB;AAED,kDAAkD;AAClD,MAAM,WAAW,cAAc;IAC9B,6DAA6D;IAC7D,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,2EAA2E;IAC3E,QAAQ,CAAC,EAAE,OAAO,CAAC;CACnB"}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/number/types.ts"],"names":[],"mappings":"AAAA,4CAA4C;AAC5C,MAAM,WAAW,mBAAmB;IACnC,oCAAoC;IACpC,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,kCAAkC;IAClC,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,6CAA6C;IAC7C,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,6CAA6C;IAC7C,UAAU,CAAC,EAAE,OAAO,CAAC;CACrB;AAED,kDAAkD;AAClD,MAAM,WAAW,cAAc;IAC9B,6DAA6D;IAC7D,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,2EAA2E;IAC3E,QAAQ,CAAC,EAAE,OAAO,CAAC;CACnB;AAED,oCAAoC;AACpC,MAAM,MAAM,UAAU,GACnB,KAAK,GACL,SAAS,GACT,KAAK,GACL,MAAM,GACN,OAAO,GACP,QAAQ,CAAC;AAEZ,gDAAgD;AAChD,MAAM,MAAM,KAAK,GAAG,OAAO,GAAG,QAAQ,CAAC;AAEvC,kDAAkD;AAClD,MAAM,WAAW,YAAY,CAAC,CAAC,SAAS,KAAK,CAAE,SAAQ,mBAAmB;IACzE,iFAAiF;IACjF,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,+DAA+D;IAC/D,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,qFAAqF;IACrF,KAAK,CAAC,EAAE,CAAC,CAAC;CACV;AAED,4DAA4D;AAC5D,MAAM,MAAM,aAAa,CAAC,CAAC,SAAS,KAAK,IACxC,CAAC,SAAS,OAAO,GAAG,MAAM,EAAE,GAAG,MAAM,CAAC"}
@@ -0,0 +1,9 @@
1
+ /**
2
+ * * Converts a string to `camelCase`, `snake_case`, or `kebab-case`.
3
+ *
4
+ * @param string - The input string to be converted. Words should be separated by **non-alphanumeric characters** (e.g., spaces, hyphens, underscores, dots, slashes, etc.).
5
+ * @param format - The format to convert the string to (`'camelCase'`, `'snake_case'`, or `'kebab-case'`).
6
+ * @returns The formatted string in the specified case format.
7
+ */
8
+ export declare function convertStringCase(string: string, format: 'camelCase' | 'snake_case' | 'kebab-case'): string;
9
+ //# sourceMappingURL=convert.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"convert.d.ts","sourceRoot":"","sources":["../../src/string/convert.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,wBAAgB,iBAAiB,CAChC,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,WAAW,GAAG,YAAY,GAAG,YAAY,GAC/C,MAAM,CA8BR"}
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ /**
3
+ * * Converts a string to `camelCase`, `snake_case`, or `kebab-case`.
4
+ *
5
+ * @param string - The input string to be converted. Words should be separated by **non-alphanumeric characters** (e.g., spaces, hyphens, underscores, dots, slashes, etc.).
6
+ * @param format - The format to convert the string to (`'camelCase'`, `'snake_case'`, or `'kebab-case'`).
7
+ * @returns The formatted string in the specified case format.
8
+ */
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.convertStringCase = convertStringCase;
11
+ function convertStringCase(string, format) {
12
+ if (!string || typeof string !== 'string')
13
+ return '';
14
+ const formattedString = string.replace(/[^a-zA-Z0-9]+(.)?/g, (_, chr) => (chr ? chr.toUpperCase() : ''));
15
+ if (!formattedString)
16
+ return '';
17
+ switch (format) {
18
+ case 'camelCase':
19
+ return (formattedString.charAt(0).toLowerCase() +
20
+ formattedString.slice(1));
21
+ case 'snake_case':
22
+ return formattedString.replace(/[A-Z]/g, (letter, index) => index === 0 ? letter.toLowerCase() : `_${letter.toLowerCase()}`);
23
+ case 'kebab-case':
24
+ return formattedString.replace(/[A-Z]/g, (letter, index) => index === 0 ? letter.toLowerCase() : `-${letter.toLowerCase()}`);
25
+ default:
26
+ return formattedString;
27
+ }
28
+ }
@@ -6,4 +6,12 @@
6
6
  * @returns Whether the values are deeply equal.
7
7
  */
8
8
  export declare const isDeepEqual: <T>(a: T, b: T) => boolean;
9
+ /**
10
+ * * Utility to convert an array to string with custom separator.
11
+ *
12
+ * @param array Array to convert.
13
+ * @param separator Separate each element of the array. Can be `,`, `-`, `|` etc. Default is `,`.
14
+ * @returns Converted array in string format with the separator.
15
+ */
16
+ export declare const convertArrayToString: <T>(array: T[], separator?: string) => string;
9
17
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAEA;;;;;;GAMG;AACH,eAAO,MAAM,WAAW,GAAI,CAAC,KAAK,CAAC,KAAK,CAAC,KAAG,OA6B3C,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAGA;;;;;;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"}
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isDeepEqual = void 0;
3
+ exports.convertArrayToString = exports.isDeepEqual = void 0;
4
+ const basics_1 = require("../array/basics");
4
5
  /**
5
6
  * * Deeply compare two values (arrays, objects, or primitive values).
6
7
  *
@@ -35,3 +36,17 @@ const isDeepEqual = (a, b) => {
35
36
  return false;
36
37
  };
37
38
  exports.isDeepEqual = isDeepEqual;
39
+ /**
40
+ * * Utility to convert an array to string with custom separator.
41
+ *
42
+ * @param array Array to convert.
43
+ * @param separator Separate each element of the array. Can be `,`, `-`, `|` etc. Default is `,`.
44
+ * @returns Converted array in string format with the separator.
45
+ */
46
+ const convertArrayToString = (array, separator = ',') => {
47
+ if (!basics_1.isValidButEmptyArray) {
48
+ throw new Error('Please, provide a valid array!');
49
+ }
50
+ return array.join(separator);
51
+ };
52
+ exports.convertArrayToString = convertArrayToString;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nhb-toolbox",
3
- "version": "1.7.5",
3
+ "version": "1.8.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",