nhb-toolbox 0.9.8 → 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 +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/number/index.d.ts +11 -1
- package/dist/number/index.d.ts.map +1 -1
- package/dist/number/index.js +18 -1
- package/dist/number/types.d.ts +7 -0
- package/dist/number/types.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { capitalizeString, truncateString, generateRandomID } from './string';
|
|
2
|
-
export { getRandomNumber } from './number';
|
|
2
|
+
export { getRandomNumber, convertToDecimal } from './number';
|
|
3
3
|
export { getColorForFirstCharacter } from './colors';
|
|
4
4
|
export { generateRandomColor } from './colors/random';
|
|
5
5
|
export { convertHexToHsl, convertHexToRgb, convertHslToHex, convertHslToRgb, convertRgbToHex, convertRgbToHsl, } from './colors/convert';
|
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,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,12 +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.getRandomNumber = 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
8
|
var number_1 = require("./number");
|
|
9
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; } });
|
|
10
11
|
var colors_1 = require("./colors");
|
|
11
12
|
Object.defineProperty(exports, "getColorForFirstCharacter", { enumerable: true, get: function () { return colors_1.getColorForFirstCharacter; } });
|
|
12
13
|
var random_1 = require("./colors/random");
|
package/dist/number/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { RandomNumberOptions } from './types';
|
|
1
|
+
import type { DecimalOptions, RandomNumberOptions } from './types';
|
|
2
2
|
/**
|
|
3
3
|
* * Utility to generate a random number between a given range.
|
|
4
4
|
* * If no options are provided, it will generate a random number between `0` and `100` (inclusive).
|
|
@@ -8,4 +8,14 @@ import type { RandomNumberOptions } from './types';
|
|
|
8
8
|
* @returns Random number.
|
|
9
9
|
*/
|
|
10
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;
|
|
11
21
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/number/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;
|
|
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"}
|
package/dist/number/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getRandomNumber = void 0;
|
|
3
|
+
exports.convertToDecimal = exports.getRandomNumber = void 0;
|
|
4
4
|
/**
|
|
5
5
|
* * Utility to generate a random number between a given range.
|
|
6
6
|
* * If no options are provided, it will generate a random number between `0` and `100` (inclusive).
|
|
@@ -43,3 +43,20 @@ const getRandomNumber = (options) => {
|
|
|
43
43
|
return 0;
|
|
44
44
|
};
|
|
45
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;
|
package/dist/number/types.d.ts
CHANGED
|
@@ -9,4 +9,11 @@ export interface RandomNumberOptions {
|
|
|
9
9
|
/** Whether to include the maximum number. */
|
|
10
10
|
includeMax?: boolean;
|
|
11
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
|
+
}
|
|
12
19
|
//# 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"}
|
|
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"}
|
package/package.json
CHANGED