nhb-toolbox 0.9.7 → 0.9.9

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/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export { capitalizeString, truncateString, generateRandomID } from './string';
2
+ export { getRandomNumber, convertToDecimal } from './number';
2
3
  export { getColorForFirstCharacter } from './colors';
3
4
  export { generateRandomColor } from './colors/random';
4
5
  export { convertHexToHsl, convertHexToRgb, convertHslToHex, convertHslToRgb, convertRgbToHex, convertRgbToHsl, } from './colors/convert';
@@ -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,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,EAAE,YAAY,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAE5D,OAAO,EAAE,mBAAmB,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,eAAe,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAE7D,OAAO,EAAE,yBAAyB,EAAE,MAAM,UAAU,CAAC;AAErD,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,EAAE,YAAY,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAE5D,OAAO,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC"}
package/dist/index.js CHANGED
@@ -1,10 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.generateQueryParams = exports.createSelectOptions = exports.flattenArray = exports.convertRgbToHsl = exports.convertRgbToHex = exports.convertHslToRgb = exports.convertHslToHex = exports.convertHexToRgb = exports.convertHexToHsl = exports.generateRandomColor = exports.getColorForFirstCharacter = exports.generateRandomID = exports.truncateString = exports.capitalizeString = void 0;
3
+ exports.generateQueryParams = exports.createSelectOptions = exports.flattenArray = exports.convertRgbToHsl = exports.convertRgbToHex = exports.convertHslToRgb = exports.convertHslToHex = exports.convertHexToRgb = exports.convertHexToHsl = exports.generateRandomColor = exports.getColorForFirstCharacter = 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; } });
7
7
  Object.defineProperty(exports, "generateRandomID", { enumerable: true, get: function () { return string_1.generateRandomID; } });
8
+ var number_1 = require("./number");
9
+ Object.defineProperty(exports, "getRandomNumber", { enumerable: true, get: function () { return number_1.getRandomNumber; } });
10
+ Object.defineProperty(exports, "convertToDecimal", { enumerable: true, get: function () { return number_1.convertToDecimal; } });
8
11
  var colors_1 = require("./colors");
9
12
  Object.defineProperty(exports, "getColorForFirstCharacter", { enumerable: true, get: function () { return colors_1.getColorForFirstCharacter; } });
10
13
  var random_1 = require("./colors/random");
@@ -0,0 +1,21 @@
1
+ import type { DecimalOptions, RandomNumberOptions } from './types';
2
+ /**
3
+ * * Utility to generate a random number between a given range.
4
+ * * If no options are provided, it will generate a random number between `0` and `100` (inclusive).
5
+ * * If `min` is greater than `max`, it will swap the values and generate a random number.
6
+ *
7
+ * @param options - Options for configuring random number generator.
8
+ * @returns Random number.
9
+ */
10
+ export declare const getRandomNumber: (options?: RandomNumberOptions) => number;
11
+ /**
12
+ * * Utility to round a number to a given decimal places.
13
+ *
14
+ * @param num - Number to round.
15
+ * @param options - Options for rounding behavior, including decimal places and return type.
16
+ * @param options.decimalPlaces - Number of decimal places to round to.
17
+ * @param options.isString - Flag to determine if the result should be returned as a string (default: `false`).
18
+ * @returns - Rounded number (as a `number`) or string (if `isString` is `true`).
19
+ */
20
+ export declare const convertToDecimal: (num: number, options?: DecimalOptions) => number | string;
21
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/number/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAEnE;;;;;;;GAOG;AACH,eAAO,MAAM,eAAe,aAAc,mBAAmB,KAAG,MA+C/D,CAAC;AAEF;;;;;;;;GAQG;AACH,eAAO,MAAM,gBAAgB,QACvB,MAAM,YACD,cAAc,KACtB,MAAM,GAAG,MAQX,CAAC"}
@@ -0,0 +1,62 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.convertToDecimal = exports.getRandomNumber = void 0;
4
+ /**
5
+ * * Utility to generate a random number between a given range.
6
+ * * If no options are provided, it will generate a random number between `0` and `100` (inclusive).
7
+ * * If `min` is greater than `max`, it will swap the values and generate a random number.
8
+ *
9
+ * @param options - Options for configuring random number generator.
10
+ * @returns Random number.
11
+ */
12
+ const getRandomNumber = (options) => {
13
+ const { min = 0, max = 100, includeMin = true, includeMax = true, } = options || {};
14
+ let minimum = min, maximum = max;
15
+ if (min > max) {
16
+ [minimum, maximum] = [max, min];
17
+ return (0, exports.getRandomNumber)({
18
+ min: minimum,
19
+ max: maximum,
20
+ includeMin,
21
+ includeMax,
22
+ });
23
+ }
24
+ if (min === max) {
25
+ return min;
26
+ }
27
+ if (includeMin && includeMax) {
28
+ // Generate random number between min and max, inclusive
29
+ return Math.floor(Math.random() * (max - min + 1)) + min;
30
+ }
31
+ if (!includeMin && !includeMax) {
32
+ // Generate random number between min and max, exclusive
33
+ return Math.floor(Math.random() * (max - min - 1)) + min + 1;
34
+ }
35
+ if (includeMin && !includeMax) {
36
+ // Generate random number between min and max, inclusive of min but exclusive of max
37
+ return Math.floor(Math.random() * (max - min)) + min;
38
+ }
39
+ if (!includeMin && includeMax) {
40
+ // Generate random number between min and max, exclusive of min but inclusive of max
41
+ return Math.floor(Math.random() * (max - min)) + min + 1;
42
+ }
43
+ return 0;
44
+ };
45
+ exports.getRandomNumber = getRandomNumber;
46
+ /**
47
+ * * Utility to round a number to a given decimal places.
48
+ *
49
+ * @param num - Number to round.
50
+ * @param options - Options for rounding behavior, including decimal places and return type.
51
+ * @param options.decimalPlaces - Number of decimal places to round to.
52
+ * @param options.isString - Flag to determine if the result should be returned as a string (default: `false`).
53
+ * @returns - Rounded number (as a `number`) or string (if `isString` is `true`).
54
+ */
55
+ const convertToDecimal = (num, options) => {
56
+ const { decimalPlaces = 2, isString = false } = options || {};
57
+ if (isString) {
58
+ return num.toFixed(decimalPlaces); // Return as string
59
+ }
60
+ return parseFloat(num.toFixed(decimalPlaces)); // Return as number
61
+ };
62
+ exports.convertToDecimal = convertToDecimal;
@@ -0,0 +1,19 @@
1
+ /** - Options for random number generator */
2
+ export interface RandomNumberOptions {
3
+ /** Minimum number to start with. */
4
+ min?: number;
5
+ /** Maximum number to end with. */
6
+ max?: number;
7
+ /** Whether to include the minimum number. */
8
+ includeMin?: boolean;
9
+ /** Whether to include the maximum number. */
10
+ includeMax?: boolean;
11
+ }
12
+ /** Decimal options for converting to decimal */
13
+ export interface DecimalOptions {
14
+ /** Number of decimal places to round to. Defaults to `2`. */
15
+ decimalPlaces?: number;
16
+ /** If the return value is in `string` or `number`. Defaults to `false`. */
17
+ isString?: boolean;
18
+ }
19
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +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,gDAAgD;AAChD,MAAM,WAAW,cAAc;IAC9B,6DAA6D;IAC7D,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,2EAA2E;IAC3E,QAAQ,CAAC,EAAE,OAAO,CAAC;CACnB"}
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nhb-toolbox",
3
- "version": "0.9.7",
3
+ "version": "0.9.9",
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",