nhb-toolbox 0.9.2 → 0.9.3
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/colors/constants.d.ts +5 -0
- package/dist/colors/constants.d.ts.map +1 -0
- package/dist/colors/constants.js +45 -0
- package/dist/colors/helpers.d.ts +16 -0
- package/dist/colors/helpers.d.ts.map +1 -0
- package/dist/colors/helpers.js +28 -0
- package/dist/colors/index.d.ts +25 -0
- package/dist/colors/index.d.ts.map +1 -0
- package/dist/colors/index.js +61 -0
- package/dist/colors/types.d.ts +7 -0
- package/dist/colors/types.d.ts.map +1 -0
- package/dist/colors/types.js +2 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -1
- package/dist/string/index.d.ts +6 -6
- package/dist/string/index.js +5 -5
- package/dist/string/types.d.ts +6 -6
- package/dist/string/types.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/colors/constants.ts"],"names":[],"mappings":"AAAA,qDAAqD;AACrD,eAAO,MAAM,oBAAoB,UA2BhC,CAAC;AAEF,4CAA4C;AAC5C,eAAO,MAAM,kBAAkB,UAW9B,CAAC"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.numberColorPalette = exports.alphabetColorPalette = void 0;
|
|
4
|
+
/** Colors based on the ASCII value of the letter. */
|
|
5
|
+
exports.alphabetColorPalette = [
|
|
6
|
+
'#00094C',
|
|
7
|
+
'#00376E',
|
|
8
|
+
'#005600',
|
|
9
|
+
'#024647',
|
|
10
|
+
'#423067',
|
|
11
|
+
'#55188E',
|
|
12
|
+
'#00453E',
|
|
13
|
+
'#00516C',
|
|
14
|
+
'#263E0D',
|
|
15
|
+
'#0F6F3F',
|
|
16
|
+
'#730073',
|
|
17
|
+
'#053636',
|
|
18
|
+
'#253654',
|
|
19
|
+
'#4682B4',
|
|
20
|
+
'#3253B6',
|
|
21
|
+
'#43616C',
|
|
22
|
+
'#036C44',
|
|
23
|
+
'#30784F',
|
|
24
|
+
'#601C1C',
|
|
25
|
+
'#690000',
|
|
26
|
+
'#005B00',
|
|
27
|
+
'#BF0E6C',
|
|
28
|
+
'#008080',
|
|
29
|
+
'#475F47',
|
|
30
|
+
'#546F1C',
|
|
31
|
+
'#824809',
|
|
32
|
+
];
|
|
33
|
+
/** Colors based on the index of numbers. */
|
|
34
|
+
exports.numberColorPalette = [
|
|
35
|
+
'#893213',
|
|
36
|
+
'#A44C15',
|
|
37
|
+
'#8B4513',
|
|
38
|
+
'#8A1D33',
|
|
39
|
+
'#3B543B',
|
|
40
|
+
'#342656',
|
|
41
|
+
'#A43522',
|
|
42
|
+
'#04605F',
|
|
43
|
+
'#B5680A',
|
|
44
|
+
'#6437B3',
|
|
45
|
+
];
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { OpacityValue } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* * Converts opacity percentage (0-100) to a 2-digit hex string.
|
|
4
|
+
*
|
|
5
|
+
* @param opacity - The opacity value as a percentage (0-100).
|
|
6
|
+
* @returns A 2-digit hex string representing the alpha value.
|
|
7
|
+
*/
|
|
8
|
+
export declare const convertOpacityToHex: (opacity: OpacityValue) => string;
|
|
9
|
+
/**
|
|
10
|
+
* * Applies an opacity value to a color string.
|
|
11
|
+
* @param color The color string to apply opacity to.
|
|
12
|
+
* @param opacity The opacity value as a percentage (0-100).
|
|
13
|
+
* @returns The color string with the opacity value applied.
|
|
14
|
+
*/
|
|
15
|
+
export declare const applyOpacity: (color: string, opacity: string) => string;
|
|
16
|
+
//# sourceMappingURL=helpers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../src/colors/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAE5C;;;;;GAKG;AACH,eAAO,MAAM,mBAAmB,YAAa,YAAY,KAAG,MAO3D,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,YAAY,UAAW,MAAM,WAAW,MAAM,KAAG,MAE7D,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.applyOpacity = exports.convertOpacityToHex = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* * Converts opacity percentage (0-100) to a 2-digit hex string.
|
|
6
|
+
*
|
|
7
|
+
* @param opacity - The opacity value as a percentage (0-100).
|
|
8
|
+
* @returns A 2-digit hex string representing the alpha value.
|
|
9
|
+
*/
|
|
10
|
+
const convertOpacityToHex = (opacity) => {
|
|
11
|
+
// Ensure opacity is between 0 and 100
|
|
12
|
+
const validOpacity = Math.min(100, Math.max(0, opacity));
|
|
13
|
+
// Convert to a value between 0 and 255, then to a hex string
|
|
14
|
+
const alpha = Math.round((validOpacity / 100) * 255);
|
|
15
|
+
// Ensure it's 2 digits (e.g., 0x0A instead of 0xA)
|
|
16
|
+
return alpha.toString(16).padStart(2, '0').toUpperCase();
|
|
17
|
+
};
|
|
18
|
+
exports.convertOpacityToHex = convertOpacityToHex;
|
|
19
|
+
/**
|
|
20
|
+
* * Applies an opacity value to a color string.
|
|
21
|
+
* @param color The color string to apply opacity to.
|
|
22
|
+
* @param opacity The opacity value as a percentage (0-100).
|
|
23
|
+
* @returns The color string with the opacity value applied.
|
|
24
|
+
*/
|
|
25
|
+
const applyOpacity = (color, opacity) => {
|
|
26
|
+
return color.concat(opacity);
|
|
27
|
+
};
|
|
28
|
+
exports.applyOpacity = applyOpacity;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { ColorInput, ColorInputArray, OpacityValue } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* * Generates a hex color based on the first character of a string or number.
|
|
4
|
+
*
|
|
5
|
+
* - For numbers, it uses 10 predefined colors (0-9).
|
|
6
|
+
* - For letters, it uses 26 predefined colors (A-Z).
|
|
7
|
+
* - Invalid characters handled with a fallback color.
|
|
8
|
+
* @param input - A string or number.
|
|
9
|
+
* @param opacity - A value from 0 to 100 representing the opacity percentage.
|
|
10
|
+
* @returns A hex color for the first character of the provided string/number.
|
|
11
|
+
*/
|
|
12
|
+
export declare function getColorForFirstCharacter(input?: ColorInput, opacity?: OpacityValue): string;
|
|
13
|
+
/**
|
|
14
|
+
* * Generates an array of hex colors based on the first character of an array of strings/numbers or even nested arrays of strings/numbers.
|
|
15
|
+
*
|
|
16
|
+
* - For numbers, it uses 10 predefined colors (0-9).
|
|
17
|
+
* - For letters, it uses 26 predefined colors (A-Z).
|
|
18
|
+
* - For empty array it returns all 36 colors.
|
|
19
|
+
* - Invalid characters and inputs are handled with a fallback color.
|
|
20
|
+
* @param input - A string, number, or an array of strings/numbers or even nested arrays of strings/numbers.
|
|
21
|
+
* @param opacity - A value from 0 to 100 representing the opacity percentage.
|
|
22
|
+
* @returns A hex color for a string/number, or an array of hex colors for each element of the provided array.
|
|
23
|
+
*/
|
|
24
|
+
export declare function getColorForFirstCharacter(input: ColorInputArray, opacity?: OpacityValue): string[];
|
|
25
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/colors/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAGzE;;;;;;;;;GASG;AACH,wBAAgB,yBAAyB,CACxC,KAAK,CAAC,EAAE,UAAU,EAClB,OAAO,CAAC,EAAE,YAAY,GACpB,MAAM,CAAC;AAEV;;;;;;;;;;GAUG;AACH,wBAAgB,yBAAyB,CACxC,KAAK,EAAE,eAAe,EACtB,OAAO,CAAC,EAAE,YAAY,GACpB,MAAM,EAAE,CAAC"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getColorForFirstCharacter = getColorForFirstCharacter;
|
|
4
|
+
const helpers_1 = require("./helpers");
|
|
5
|
+
const constants_1 = require("./constants");
|
|
6
|
+
/**
|
|
7
|
+
* * Generates an array of hex colors based on the first character of an array of strings/numbers or even nested arrays of strings/numbers.
|
|
8
|
+
*
|
|
9
|
+
* - For numbers, it uses 10 predefined colors (0-9).
|
|
10
|
+
* - For letters, it uses 26 predefined colors (A-Z).
|
|
11
|
+
* - For empty array it returns all 36 colors.
|
|
12
|
+
* - Invalid characters and inputs are handled with a fallback color.
|
|
13
|
+
* @param input - A string, number, or an array of strings/numbers or even nested arrays of strings/numbers.
|
|
14
|
+
* @param opacity - A value from 0 to 100 representing the opacity percentage.
|
|
15
|
+
* @returns A hex color for a string/number, or an array of hex colors for each element of the provided array.
|
|
16
|
+
*/
|
|
17
|
+
function getColorForFirstCharacter(input = '', opacity = 100) {
|
|
18
|
+
let initial;
|
|
19
|
+
const hexOpacity = (0, helpers_1.convertOpacityToHex)(opacity);
|
|
20
|
+
const numbers = '0123456789';
|
|
21
|
+
// Handle empty string case
|
|
22
|
+
if (!input)
|
|
23
|
+
return (0, helpers_1.applyOpacity)('#010514', hexOpacity);
|
|
24
|
+
// Handle string input
|
|
25
|
+
if (typeof input === 'string') {
|
|
26
|
+
initial = input[0];
|
|
27
|
+
// Handle number as string
|
|
28
|
+
if (numbers.includes(initial)) {
|
|
29
|
+
return (0, helpers_1.applyOpacity)(constants_1.numberColorPalette[parseInt(initial, 10)], hexOpacity);
|
|
30
|
+
}
|
|
31
|
+
const upperInitial = initial.toUpperCase();
|
|
32
|
+
const index = upperInitial.charCodeAt(0) - 'A'.charCodeAt(0);
|
|
33
|
+
// Validate alphabet
|
|
34
|
+
if (index >= 0 && index < constants_1.alphabetColorPalette.length) {
|
|
35
|
+
return (0, helpers_1.applyOpacity)(constants_1.alphabetColorPalette[index], hexOpacity);
|
|
36
|
+
}
|
|
37
|
+
return (0, helpers_1.applyOpacity)('#010514', hexOpacity);
|
|
38
|
+
// Handle number input
|
|
39
|
+
}
|
|
40
|
+
else if (typeof input === 'number' && !isNaN(input)) {
|
|
41
|
+
initial = input.toString()[0];
|
|
42
|
+
if (numbers.includes(initial)) {
|
|
43
|
+
return (0, helpers_1.applyOpacity)(constants_1.numberColorPalette[parseInt(initial, 10)], hexOpacity);
|
|
44
|
+
}
|
|
45
|
+
return (0, helpers_1.applyOpacity)('#010514', hexOpacity);
|
|
46
|
+
// Handle array of strings/numbers
|
|
47
|
+
}
|
|
48
|
+
else if (Array.isArray(input)) {
|
|
49
|
+
if (input.length < 1)
|
|
50
|
+
return [...constants_1.alphabetColorPalette, ...constants_1.numberColorPalette].map((color) => (0, helpers_1.applyOpacity)(color, hexOpacity));
|
|
51
|
+
return input
|
|
52
|
+
.map((el) => {
|
|
53
|
+
if (Array.isArray(el)) {
|
|
54
|
+
return getColorForFirstCharacter(el, opacity);
|
|
55
|
+
}
|
|
56
|
+
return getColorForFirstCharacter(el, opacity);
|
|
57
|
+
})
|
|
58
|
+
.flat();
|
|
59
|
+
}
|
|
60
|
+
return (0, helpers_1.applyOpacity)('#010514', hexOpacity);
|
|
61
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/** - A string, number for generating color. */
|
|
2
|
+
export type ColorInput = string | number;
|
|
3
|
+
/** - An array of strings/numbers or nested arrays of strings/numbers for generating colors. */
|
|
4
|
+
export type ColorInputArray = (ColorInput | ColorInputArray)[];
|
|
5
|
+
/** - Opacity options */
|
|
6
|
+
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
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +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,MAAM,eAAe,GAAG,CAAC,UAAU,GAAG,eAAe,CAAC,EAAE,CAAC;AAE/D,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
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,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"}
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.capitalizeString = void 0;
|
|
3
|
+
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
|
+
Object.defineProperty(exports, "truncateString", { enumerable: true, get: function () { return string_1.truncateString; } });
|
|
7
|
+
Object.defineProperty(exports, "generateRandomID", { enumerable: true, get: function () { return string_1.generateRandomID; } });
|
|
8
|
+
var colors_1 = require("./colors");
|
|
9
|
+
Object.defineProperty(exports, "getColorForFirstCharacter", { enumerable: true, get: function () { return colors_1.getColorForFirstCharacter; } });
|
package/dist/string/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { CapitalizeOptions,
|
|
1
|
+
import type { CapitalizeOptions, RandomIdOptions } from './types';
|
|
2
2
|
/**
|
|
3
|
-
* Utility to convert the first letter of any string to uppercase and the rest lowercase (unless specified).
|
|
3
|
+
* * Utility to convert the first letter of any string to uppercase and the rest lowercase (unless specified).
|
|
4
4
|
* Handles surrounding symbols like quotes or parentheses.
|
|
5
5
|
*
|
|
6
6
|
* @param string String to be capitalized.
|
|
@@ -9,7 +9,7 @@ import type { CapitalizeOptions, RandomIDOptions } from './types';
|
|
|
9
9
|
*/
|
|
10
10
|
export declare const capitalizeString: (string: string, options?: CapitalizeOptions) => string;
|
|
11
11
|
/**
|
|
12
|
-
* Utility to truncate a string to a specified length.
|
|
12
|
+
* * Utility to truncate a string to a specified length.
|
|
13
13
|
*
|
|
14
14
|
* @param string The string to truncate.
|
|
15
15
|
* @param maxLength The maximum length of the truncated string.
|
|
@@ -17,10 +17,10 @@ export declare const capitalizeString: (string: string, options?: CapitalizeOpti
|
|
|
17
17
|
*/
|
|
18
18
|
export declare const truncateString: (string: string, maxLength: number) => string;
|
|
19
19
|
/**
|
|
20
|
-
* Generates a unique ID string composed of an optional `prefix`, `suffix`, a `timestamp`, `separator`, and a random alphanumeric string, separated by a customizable separator.
|
|
20
|
+
* * Generates a unique ID string composed of an optional `prefix`, `suffix`, a `timestamp`, `separator`, and a random alphanumeric string, separated by a customizable separator.
|
|
21
21
|
*
|
|
22
22
|
* @param options Configuration options for random ID generation.
|
|
23
|
-
* @returns The generated ID string composed of the
|
|
23
|
+
* @returns The generated ID string composed of the random alphanumeric string, timestamp, prefix, and suffix, separated by the specified separator.
|
|
24
24
|
*/
|
|
25
|
-
export declare const generateRandomID: (options?:
|
|
25
|
+
export declare const generateRandomID: (options?: RandomIdOptions) => string;
|
|
26
26
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/string/index.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.generateRandomID = exports.truncateString = exports.capitalizeString = void 0;
|
|
4
4
|
/**
|
|
5
|
-
* Utility to convert the first letter of any string to uppercase and the rest lowercase (unless specified).
|
|
5
|
+
* * Utility to convert the first letter of any string to uppercase and the rest lowercase (unless specified).
|
|
6
6
|
* Handles surrounding symbols like quotes or parentheses.
|
|
7
7
|
*
|
|
8
8
|
* @param string String to be capitalized.
|
|
@@ -41,7 +41,7 @@ const capitalizeString = (string, options) => {
|
|
|
41
41
|
};
|
|
42
42
|
exports.capitalizeString = capitalizeString;
|
|
43
43
|
/**
|
|
44
|
-
* Utility to truncate a string to a specified length.
|
|
44
|
+
* * Utility to truncate a string to a specified length.
|
|
45
45
|
*
|
|
46
46
|
* @param string The string to truncate.
|
|
47
47
|
* @param maxLength The maximum length of the truncated string.
|
|
@@ -61,13 +61,13 @@ const truncateString = (string, maxLength) => {
|
|
|
61
61
|
};
|
|
62
62
|
exports.truncateString = truncateString;
|
|
63
63
|
/**
|
|
64
|
-
* Generates a unique ID string composed of an optional `prefix`, `suffix`, a `timestamp`, `separator`, and a random alphanumeric string, separated by a customizable separator.
|
|
64
|
+
* * Generates a unique ID string composed of an optional `prefix`, `suffix`, a `timestamp`, `separator`, and a random alphanumeric string, separated by a customizable separator.
|
|
65
65
|
*
|
|
66
66
|
* @param options Configuration options for random ID generation.
|
|
67
|
-
* @returns The generated ID string composed of the
|
|
67
|
+
* @returns The generated ID string composed of the random alphanumeric string, timestamp, prefix, and suffix, separated by the specified separator.
|
|
68
68
|
*/
|
|
69
69
|
const generateRandomID = (options) => {
|
|
70
|
-
const { prefix = '', suffix = '', timeStamp =
|
|
70
|
+
const { prefix = '', suffix = '', timeStamp = false, length = 16, separator = '', caseOption = null, } = options || {};
|
|
71
71
|
// generate timestamp
|
|
72
72
|
const date = timeStamp ? Date.now() : '';
|
|
73
73
|
// Generate a random string of alphanumeric characters
|
package/dist/string/types.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/** Options for capitalizeString function. */
|
|
1
|
+
/** - Options for capitalizeString function. */
|
|
2
2
|
export interface CapitalizeOptions {
|
|
3
3
|
/** If true, capitalizes the first letter of each word (space separated). Defaults to `false`. */
|
|
4
4
|
capitalizeEachFirst?: boolean;
|
|
@@ -7,17 +7,17 @@ export interface CapitalizeOptions {
|
|
|
7
7
|
/** If true, ensures that the rest of the string is lowercase. Defaults to `true`. */
|
|
8
8
|
lowerCaseRest?: boolean;
|
|
9
9
|
}
|
|
10
|
-
/** Configuration options for ID generation. */
|
|
11
|
-
export interface
|
|
10
|
+
/** - Configuration options for ID generation. */
|
|
11
|
+
export interface RandomIdOptions {
|
|
12
12
|
/** A string to prepend to the ID. Default is an empty string. */
|
|
13
13
|
prefix?: string;
|
|
14
14
|
/** A string to append to the ID. Default is an empty string.*/
|
|
15
15
|
suffix?: string;
|
|
16
|
-
/** Whether to include the current timestamp in the ID. Default is `
|
|
16
|
+
/** Whether to include the current timestamp in the ID. Default is `false`. */
|
|
17
17
|
timeStamp?: boolean;
|
|
18
|
-
/** The length of the random alphanumeric string. Default is `
|
|
18
|
+
/** The length of the random alphanumeric string. Default is `16`. */
|
|
19
19
|
length?: number;
|
|
20
|
-
/** The separator to use between parts of the ID. Default is
|
|
20
|
+
/** The separator to use between parts of the ID. Default is an empty string. */
|
|
21
21
|
separator?: string;
|
|
22
22
|
/** Specifies the case for the random alphanumeric string. */
|
|
23
23
|
caseOption?: 'upper' | 'lower' | null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/string/types.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/string/types.ts"],"names":[],"mappings":"AAAA,+CAA+C;AAC/C,MAAM,WAAW,iBAAiB;IACjC,iGAAiG;IACjG,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAC9B,kFAAkF;IAClF,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,qFAAqF;IACrF,aAAa,CAAC,EAAE,OAAO,CAAC;CACxB;AAED,iDAAiD;AACjD,MAAM,WAAW,eAAe;IAC/B,iEAAiE;IACjE,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB,+DAA+D;IAC/D,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB,8EAA8E;IAC9E,SAAS,CAAC,EAAE,OAAO,CAAC;IAEpB,qEAAqE;IACrE,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB,gFAAgF;IAChF,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB,6DAA6D;IAC7D,UAAU,CAAC,EAAE,OAAO,GAAG,OAAO,GAAG,IAAI,CAAC;CACtC"}
|
package/package.json
CHANGED