toolbox-x 1.0.0
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/LICENSE +201 -0
- package/dist/Color-B3mgF9Dh.d.cts +486 -0
- package/dist/Color-D38Xrw65.d.mts +486 -0
- package/dist/Stylog-Df7eq3-j.d.cts +519 -0
- package/dist/Stylog-jvlLcMQq.d.mts +519 -0
- package/dist/array-DvW0zIu6.d.mts +130 -0
- package/dist/array-rUnEVisO.d.cts +130 -0
- package/dist/basics-D_eSv0cu.cjs +132 -0
- package/dist/basics-Dp_aEK81.mjs +115 -0
- package/dist/basics-WEYWlnRO.d.cts +95 -0
- package/dist/basics-uBSfkBEI.d.mts +95 -0
- package/dist/case-BWIt8Ash.mjs +449 -0
- package/dist/case-C-S-b5YP.d.cts +327 -0
- package/dist/case-CS8Ii3A7.cjs +526 -0
- package/dist/case-CybASFPD.d.mts +327 -0
- package/dist/change-case.cjs +32 -0
- package/dist/change-case.d.cts +18 -0
- package/dist/change-case.d.mts +18 -0
- package/dist/change-case.mjs +19 -0
- package/dist/colors.cjs +574 -0
- package/dist/colors.d.cts +355 -0
- package/dist/colors.d.mts +355 -0
- package/dist/colors.mjs +547 -0
- package/dist/constants-2gAw23_7.mjs +144 -0
- package/dist/constants-B34K0QPi.d.cts +21 -0
- package/dist/constants-BIBDKY1u.cjs +924 -0
- package/dist/constants-BWT-810U.cjs +158 -0
- package/dist/constants-BwbHnXlM.mjs +662 -0
- package/dist/constants-BxN9l5el.cjs +74 -0
- package/dist/constants-CLS_bgKD.d.mts +847 -0
- package/dist/constants-D73iFu8g.mjs +171 -0
- package/dist/constants-DAfRxaa8.mjs +62 -0
- package/dist/constants-DQYeCjlx.cjs +207 -0
- package/dist/constants-Deeie-iH.d.mts +21 -0
- package/dist/constants-DpTG9RP6.d.mts +29 -0
- package/dist/constants-DqwnkJ_d.cjs +740 -0
- package/dist/constants-DvRUY_FY.cjs +150 -0
- package/dist/constants-VcRtQu0K.d.cts +29 -0
- package/dist/constants-X5hm1UtB.mjs +912 -0
- package/dist/constants-eNd-iYsV.mjs +134 -0
- package/dist/constants-qm8FafmD.d.cts +847 -0
- package/dist/constants.cjs +415 -0
- package/dist/constants.d.cts +184 -0
- package/dist/constants.d.mts +184 -0
- package/dist/constants.mjs +378 -0
- package/dist/convert-BOCgUv2D.cjs +252 -0
- package/dist/convert-Bn4jFomQ.mjs +169 -0
- package/dist/convert-BrzlG-m_.cjs +475 -0
- package/dist/convert-DhaUoPVU.mjs +368 -0
- package/dist/converter-1P90_RcP.d.mts +402 -0
- package/dist/converter-CmkcAppi.d.cts +402 -0
- package/dist/converter.cjs +780 -0
- package/dist/converter.d.cts +29 -0
- package/dist/converter.d.mts +29 -0
- package/dist/converter.mjs +771 -0
- package/dist/countries-CIpmtEzV.cjs +1469 -0
- package/dist/countries-Cy0xiqS3.mjs +1463 -0
- package/dist/css-colors-Bx947Ng3.d.cts +179 -0
- package/dist/css-colors-CXCDqQbG.cjs +186 -0
- package/dist/css-colors-CXTp1vvy.d.mts +179 -0
- package/dist/css-colors-DfUW3nTR.mjs +180 -0
- package/dist/date.cjs +332 -0
- package/dist/date.d.cts +213 -0
- package/dist/date.d.mts +213 -0
- package/dist/date.mjs +298 -0
- package/dist/dom.cjs +461 -0
- package/dist/dom.d.cts +228 -0
- package/dist/dom.d.mts +228 -0
- package/dist/dom.mjs +429 -0
- package/dist/form-BMFVGUrN.d.mts +118 -0
- package/dist/form-DRFbryvK.d.cts +118 -0
- package/dist/guards-3kaUX66g.mjs +157 -0
- package/dist/guards-C8gkvIHb.cjs +240 -0
- package/dist/guards-DdyU4h4o.mjs +110 -0
- package/dist/guards-Efhp1mNy.cjs +151 -0
- package/dist/guards.cjs +172 -0
- package/dist/guards.d.cts +399 -0
- package/dist/guards.d.mts +399 -0
- package/dist/guards.mjs +75 -0
- package/dist/hash-B6JPEyAz.d.mts +131 -0
- package/dist/hash-NTpeKYB_.d.cts +131 -0
- package/dist/hash.cjs +2126 -0
- package/dist/hash.d.cts +1239 -0
- package/dist/hash.d.mts +1239 -0
- package/dist/hash.mjs +2095 -0
- package/dist/http-status-BAZdtr7-.d.mts +65 -0
- package/dist/http-status-U_3MtoGb.d.cts +65 -0
- package/dist/http-status.cjs +173 -0
- package/dist/http-status.d.cts +142 -0
- package/dist/http-status.d.mts +142 -0
- package/dist/http-status.mjs +171 -0
- package/dist/index.cjs +2551 -0
- package/dist/index.d.cts +1493 -0
- package/dist/index.d.mts +1493 -0
- package/dist/index.mjs +2357 -0
- package/dist/object-B0TV3eHx.d.mts +8052 -0
- package/dist/object-Blq0Amdv.d.cts +8052 -0
- package/dist/objectify-CDs0Fbr1.mjs +417 -0
- package/dist/objectify-DIJ-OBmo.cjs +524 -0
- package/dist/paginator.cjs +245 -0
- package/dist/paginator.d.cts +144 -0
- package/dist/paginator.d.mts +144 -0
- package/dist/paginator.mjs +243 -0
- package/dist/parse-2ubxXZRp.cjs +211 -0
- package/dist/parse-N7g942uy.mjs +164 -0
- package/dist/pluralizer-BjMIc6uT.d.mts +42 -0
- package/dist/pluralizer-Cb6ZmrDl.d.cts +42 -0
- package/dist/pluralizer.cjs +678 -0
- package/dist/pluralizer.d.cts +152 -0
- package/dist/pluralizer.d.mts +152 -0
- package/dist/pluralizer.mjs +676 -0
- package/dist/primitives-B26uZolQ.cjs +228 -0
- package/dist/primitives-KsFUp3kQ.mjs +144 -0
- package/dist/specials-D48_IZbd.d.mts +108 -0
- package/dist/specials-DzLr1ZgU.cjs +477 -0
- package/dist/specials-LVONlKbQ.d.cts +108 -0
- package/dist/specials-uhDuRg8H.mjs +292 -0
- package/dist/string-CBAbxaG1.d.mts +258 -0
- package/dist/string-CsNsm_65.d.cts +258 -0
- package/dist/stylog.cjs +621 -0
- package/dist/stylog.d.cts +49 -0
- package/dist/stylog.d.mts +49 -0
- package/dist/stylog.mjs +614 -0
- package/dist/timezone-B2OYK6Fh.mjs +5589 -0
- package/dist/timezone-Beh9IGpw.cjs +5625 -0
- package/dist/types/array.cjs +16 -0
- package/dist/types/array.d.cts +18 -0
- package/dist/types/array.d.mts +18 -0
- package/dist/types/array.mjs +17 -0
- package/dist/types/colors.cjs +16 -0
- package/dist/types/colors.d.cts +18 -0
- package/dist/types/colors.d.mts +18 -0
- package/dist/types/colors.mjs +17 -0
- package/dist/types/converter.cjs +16 -0
- package/dist/types/converter.d.cts +18 -0
- package/dist/types/converter.d.mts +18 -0
- package/dist/types/converter.mjs +17 -0
- package/dist/types/form.cjs +16 -0
- package/dist/types/form.d.cts +18 -0
- package/dist/types/form.d.mts +18 -0
- package/dist/types/form.mjs +17 -0
- package/dist/types/hash.cjs +16 -0
- package/dist/types/hash.d.cts +18 -0
- package/dist/types/hash.d.mts +18 -0
- package/dist/types/hash.mjs +17 -0
- package/dist/types/http-status.cjs +16 -0
- package/dist/types/http-status.d.cts +18 -0
- package/dist/types/http-status.d.mts +18 -0
- package/dist/types/http-status.mjs +17 -0
- package/dist/types/index.cjs +16 -0
- package/dist/types/index.d.cts +18 -0
- package/dist/types/index.d.mts +18 -0
- package/dist/types/index.mjs +17 -0
- package/dist/types/number.cjs +16 -0
- package/dist/types/number.d.cts +18 -0
- package/dist/types/number.d.mts +18 -0
- package/dist/types/number.mjs +17 -0
- package/dist/types/object.cjs +16 -0
- package/dist/types/object.d.cts +18 -0
- package/dist/types/object.d.mts +18 -0
- package/dist/types/object.mjs +17 -0
- package/dist/types/pluralizer.cjs +16 -0
- package/dist/types/pluralizer.d.cts +18 -0
- package/dist/types/pluralizer.d.mts +18 -0
- package/dist/types/pluralizer.mjs +17 -0
- package/dist/types/string.cjs +16 -0
- package/dist/types/string.d.cts +18 -0
- package/dist/types/string.d.mts +18 -0
- package/dist/types/string.mjs +17 -0
- package/dist/types/stylog.cjs +16 -0
- package/dist/types/stylog.d.cts +18 -0
- package/dist/types/stylog.d.mts +18 -0
- package/dist/types/stylog.mjs +17 -0
- package/dist/types/utils.cjs +16 -0
- package/dist/types/utils.d.cts +18 -0
- package/dist/types/utils.d.mts +18 -0
- package/dist/types/utils.mjs +17 -0
- package/dist/types/verbalizer.cjs +16 -0
- package/dist/types/verbalizer.d.cts +30 -0
- package/dist/types/verbalizer.d.mts +30 -0
- package/dist/types/verbalizer.mjs +17 -0
- package/dist/utilities-CLUmdQeV.cjs +140 -0
- package/dist/utilities-m5yFKqLd.mjs +105 -0
- package/dist/utils-ClW9LA6f.mjs +449 -0
- package/dist/utils-DLFRgXUC.cjs +568 -0
- package/dist/verbalizer.cjs +998 -0
- package/dist/verbalizer.d.cts +148 -0
- package/dist/verbalizer.d.mts +148 -0
- package/dist/verbalizer.mjs +996 -0
- package/package.json +249 -0
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2026 - present Nazmul Hassan
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import { E as NestedPrimitiveKey, nt as NormalPrimitiveKey, y as GenericObject } from "./object-Blq0Amdv.cjs";
|
|
18
|
+
|
|
19
|
+
//#region src/types/array.d.ts
|
|
20
|
+
/** * Flatten Array or Wrap in Array */
|
|
21
|
+
type Flattened<T> = T extends (infer U)[] ? Flattened<U> : T;
|
|
22
|
+
/**
|
|
23
|
+
* * Configuration for `createOptionsArray`.
|
|
24
|
+
* - Defines the mapping between keys in the input objects and the keys in the output options.
|
|
25
|
+
*
|
|
26
|
+
* @typeParam T - The type of the objects in the input array.
|
|
27
|
+
* @typeParam K1 - The name of the key for the first field in the output (default: `'value'`).
|
|
28
|
+
* @typeParam K2 - The name of the key for the second field in the output (default: `'label'`).
|
|
29
|
+
* @typeParam V - Whether to keep the `value` field as number if it is a number. Defaults to `false`.
|
|
30
|
+
*/
|
|
31
|
+
interface OptionsConfig<T, K1, K2, V extends boolean = false> {
|
|
32
|
+
/**
|
|
33
|
+
* - The key in the input objects to use for the first field of the option. Only primitive values (`string | number | boolean | null | undefined`) are accepted.
|
|
34
|
+
* @example
|
|
35
|
+
* // If the input objects have an `id` field and you want to use it as the `value` field in the output:
|
|
36
|
+
* createOptionsArray(data, {firstFieldKey: 'id'}).
|
|
37
|
+
*/
|
|
38
|
+
firstFieldKey: NormalPrimitiveKey<T>;
|
|
39
|
+
/**
|
|
40
|
+
* - The key in the input objects to use for the second field of the option. Only primitive values (`string | number | boolean | null | undefined`) are accepted.
|
|
41
|
+
* @example
|
|
42
|
+
* // If the input objects have a `name` field and you want to use it as the `label` field in the output:
|
|
43
|
+
* createOptionsArray(data, {firstFieldKey: 'id', secondFieldKey: 'name'}).
|
|
44
|
+
*/
|
|
45
|
+
secondFieldKey: NormalPrimitiveKey<T>;
|
|
46
|
+
/**
|
|
47
|
+
* - The name of the first field in the output object.
|
|
48
|
+
* - Defaults to `'value'`.
|
|
49
|
+
* @example
|
|
50
|
+
* // If you want the output field to be named `'key'` instead of `'value'`:
|
|
51
|
+
* createOptionsArray(data, {firstFieldKey: 'id', secondFieldKey: 'name', firstFieldName: 'key'}).
|
|
52
|
+
*/
|
|
53
|
+
firstFieldName?: K1;
|
|
54
|
+
/**
|
|
55
|
+
* - The name of the second field in the output object.
|
|
56
|
+
* - Defaults to `'label'`.
|
|
57
|
+
* @example
|
|
58
|
+
* // If you want the output field to be named `'title'` instead of `'label'`:
|
|
59
|
+
* createOptionsArray(data, {firstFieldKey: 'id', secondFieldKey: 'name', firstFieldName: 'key', secondFieldName: 'title'}).
|
|
60
|
+
*/
|
|
61
|
+
secondFieldName?: K2;
|
|
62
|
+
/**
|
|
63
|
+
* - If `true`, numeric values from `firstFieldKey` will remain as numbers.
|
|
64
|
+
* - All other values (including booleans, null, undefined) will be converted to strings.
|
|
65
|
+
* - When `false` (default), all values are converted to strings.
|
|
66
|
+
* - Defaults to `false`.
|
|
67
|
+
* @example
|
|
68
|
+
* // Numeric IDs remain as numbers
|
|
69
|
+
* createOptionsArray(data, {
|
|
70
|
+
* firstFieldKey: 'id',
|
|
71
|
+
* secondFieldKey: 'name',
|
|
72
|
+
* retainNumberValue: true
|
|
73
|
+
* });
|
|
74
|
+
*
|
|
75
|
+
* // All values become strings (default behavior)
|
|
76
|
+
* createOptionsArray(data, {
|
|
77
|
+
* firstFieldKey: 'id',
|
|
78
|
+
* secondFieldKey: 'name'
|
|
79
|
+
* });
|
|
80
|
+
*/
|
|
81
|
+
retainNumberValue?: V;
|
|
82
|
+
}
|
|
83
|
+
/** Type for first field key */
|
|
84
|
+
type FirstFieldKey<T extends GenericObject, K1 extends string = 'value', K2 extends string = 'label', V extends boolean = false> = T[OptionsConfig<T, K1, K2, V>['firstFieldKey']];
|
|
85
|
+
/** Type for firs field value */
|
|
86
|
+
type FirstFieldValue<T extends GenericObject, K1 extends string = 'value', K2 extends string = 'label', V extends boolean = false> = V extends true ? FirstFieldKey<T, K1, K2, V> extends Exclude<FirstFieldKey<T, K1, K2, V>, number> ? string : number : string;
|
|
87
|
+
/** Type of values for the option fields */
|
|
88
|
+
type FieldValue<P extends K1 | K2, T extends GenericObject, K1 extends string = 'value', K2 extends string = 'label', V extends boolean = false> = P extends K1 ? FirstFieldValue<T, K1, K2, V> : string;
|
|
89
|
+
/** Type of an option in `OptionsArray` */
|
|
90
|
+
type Option<T extends GenericObject, K1 extends string = 'value', K2 extends string = 'label', V extends boolean = false> = { [P in K1 | K2]: FieldValue<P, T, K1, K2, V> };
|
|
91
|
+
/** * Option for sorting order. */
|
|
92
|
+
interface OrderOption {
|
|
93
|
+
/**
|
|
94
|
+
* * The order in which to sort the array. Defaults to `'asc'`.
|
|
95
|
+
* - `'asc'`: Sort in ascending order.
|
|
96
|
+
* - `'desc'`: Sort in descending order.
|
|
97
|
+
*/
|
|
98
|
+
sortOrder?: 'asc' | 'desc';
|
|
99
|
+
}
|
|
100
|
+
/** * Options for setting sortByField for sorting an array of objects. */
|
|
101
|
+
interface SortByOption<T extends GenericObject> extends OrderOption {
|
|
102
|
+
/** The field by which to sort the objects in the array. */
|
|
103
|
+
sortByField: NestedPrimitiveKey<T>;
|
|
104
|
+
}
|
|
105
|
+
/** * Options for sorting array. */
|
|
106
|
+
type SortOptions<T> = T extends GenericObject ? SortByOption<T> : OrderOption;
|
|
107
|
+
/** Optional settings to configure comparison behavior. */
|
|
108
|
+
interface SortNature {
|
|
109
|
+
/** If true, compares string chunks without case sensitivity. Defaults to `true`. */
|
|
110
|
+
caseInsensitive?: boolean;
|
|
111
|
+
/** If true, uses localeCompare for string chunk comparisons. Defaults to `false`. */
|
|
112
|
+
localeAware?: boolean;
|
|
113
|
+
}
|
|
114
|
+
/** * Options for customizing the search behavior. */
|
|
115
|
+
interface FindOptions<T extends GenericObject = {}> {
|
|
116
|
+
/** * Enables fuzzy matching when exact match fails. Defaults to `false`. */
|
|
117
|
+
fuzzy?: boolean;
|
|
118
|
+
/** * Optional key for caching the result. Defaults to `finder-cache` */
|
|
119
|
+
cacheKey?: string;
|
|
120
|
+
/** * Forces binary search even for small datasets. Defaults to `false`. */
|
|
121
|
+
forceBinary?: boolean;
|
|
122
|
+
/** * If true, matcher and keys will be normalized to lowercase. Defaults to `true`. */
|
|
123
|
+
caseInsensitive?: boolean;
|
|
124
|
+
/** * If true, uses built in `Array.sort()`. Defaults to `true`. Pass `false` if data is already sorted. */
|
|
125
|
+
needSorting?: boolean;
|
|
126
|
+
/** * Optional data source to use instead of constructor items. */
|
|
127
|
+
data?: T[] | (() => T[]);
|
|
128
|
+
}
|
|
129
|
+
//#endregion
|
|
130
|
+
export { Flattened as a, OrderOption as c, SortOptions as d, FirstFieldValue as i, SortByOption as l, FindOptions as n, Option as o, FirstFieldKey as r, OptionsConfig as s, FieldValue as t, SortNature as u };
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2026 - present Nazmul Hassan
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
const require_primitives = require('./primitives-B26uZolQ.cjs');
|
|
18
|
+
|
|
19
|
+
//#region src/string/basics.ts
|
|
20
|
+
/**
|
|
21
|
+
* * Utility to truncate a string to a specified length.
|
|
22
|
+
*
|
|
23
|
+
* @param str The string to truncate.
|
|
24
|
+
* @param maxLength The maximum length of the truncated string.
|
|
25
|
+
* @returns Truncated string with ellipsis (`...`) (only if it has more length than `maxLength`).
|
|
26
|
+
*/
|
|
27
|
+
function truncateString(str, maxLength) {
|
|
28
|
+
if (!require_primitives.isNonEmptyString(str)) return "";
|
|
29
|
+
const trimmedString = str.trim();
|
|
30
|
+
if (!trimmedString) return "";
|
|
31
|
+
if (trimmedString.length <= maxLength) return trimmedString;
|
|
32
|
+
return trimmedString.slice(0, maxLength).concat("...");
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* * Generates a random alphanumeric (16 characters long, this length is customizable in the options) ID string composed of an optional `prefix`, `suffix`, a `timestamp`, `caseOption` and a customizable `separator`.
|
|
36
|
+
*
|
|
37
|
+
* @param options Configuration options for random ID generation.
|
|
38
|
+
* @returns The generated ID string composed of the random alphanumeric string of specified length with optional `timeStamp`, `prefix`, and `suffix`, `caseOption` and `separator`.
|
|
39
|
+
*
|
|
40
|
+
* @see {@link https://toolbox.nazmul-nhb.dev/docs/utilities/hash/uuid uuid} for `uuid` generation
|
|
41
|
+
* @see {@link https://toolbox.nazmul-nhb.dev/docs/utilities/hash/randomHex randomHex} for random hexadecimal string generation
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* // Generate an ID with all default options
|
|
45
|
+
* const id = generateRandomID();
|
|
46
|
+
* // Example output: "swo8ckxwsc13w7xw"
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* // Generate an ID with a custom prefix and separator
|
|
50
|
+
* const id = generateRandomID({ prefix: 'ID', separator: '-' });
|
|
51
|
+
* // Example output: "ID-eh1ymwfxzwas9jte"
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* // Generate an ID with a timestamp
|
|
55
|
+
* const id = generateRandomID({ timeStamp: false });
|
|
56
|
+
* // Example output: "1764610287501pd3r4w85qwkuulgf"
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* // Generate an ID with a custom length for the random string
|
|
60
|
+
* const id = generateRandomID({ length: 8 });
|
|
61
|
+
* // Example output: "i623uiev"
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* // Generate an ID with a custom suffix
|
|
65
|
+
* const id = generateRandomID({ suffix: 'END' });
|
|
66
|
+
* // Example output: "3csf27a4800rbli9END"
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* // Generate an ID with a uppercase random string
|
|
70
|
+
* const id = generateRandomID({ caseOption: "upper" });
|
|
71
|
+
* // Example output: "H0VNU6O8XV1Y30HG"
|
|
72
|
+
*
|
|
73
|
+
* @example
|
|
74
|
+
* // Generate an ID with all options customized
|
|
75
|
+
* const id = generateRandomID({
|
|
76
|
+
* prefix: 'ID',
|
|
77
|
+
* suffix: 'END',
|
|
78
|
+
* timeStamp: true,
|
|
79
|
+
* length: 10,
|
|
80
|
+
* separator: '-',
|
|
81
|
+
* caseOption: "upper"
|
|
82
|
+
* });
|
|
83
|
+
* // Example output: "ID-1764610471474-4KSL51IB91-END"
|
|
84
|
+
*/
|
|
85
|
+
function generateRandomID(options) {
|
|
86
|
+
const { prefix = "", suffix = "", timeStamp = false, length = 16, separator = "", caseOption = null } = options || {};
|
|
87
|
+
const date = timeStamp ? Date.now() : "";
|
|
88
|
+
const randomString = Array.from({ length }, () => Math.random().toString(36).slice(2, 3)).join("");
|
|
89
|
+
const ID = [
|
|
90
|
+
prefix && prefix.trim(),
|
|
91
|
+
date,
|
|
92
|
+
randomString,
|
|
93
|
+
suffix && suffix.trim()
|
|
94
|
+
].filter(Boolean).join(separator);
|
|
95
|
+
switch (caseOption) {
|
|
96
|
+
case "upper": return ID.toUpperCase();
|
|
97
|
+
case "lower": return ID.toLowerCase();
|
|
98
|
+
default: return ID;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* * Trims all the words in a string or an array of strings.
|
|
103
|
+
*
|
|
104
|
+
* @param input String or array of strings.
|
|
105
|
+
* @returns Trimmed string or array of strings.
|
|
106
|
+
*/
|
|
107
|
+
function trimString(input) {
|
|
108
|
+
if (!input) return "";
|
|
109
|
+
if (require_primitives.isNonEmptyString(input)) return input.trim().replace(/\s+/g, " ");
|
|
110
|
+
if (Array.isArray(input)) return input.map((str) => require_primitives.isNonEmptyString(str) ? str.trim().replace(/\s+/g, " ") : str);
|
|
111
|
+
throw new TypeError("Expected string or array of strings!", { cause: "Invalid Input Type" });
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
//#endregion
|
|
115
|
+
Object.defineProperty(exports, 'generateRandomID', {
|
|
116
|
+
enumerable: true,
|
|
117
|
+
get: function () {
|
|
118
|
+
return generateRandomID;
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
Object.defineProperty(exports, 'trimString', {
|
|
122
|
+
enumerable: true,
|
|
123
|
+
get: function () {
|
|
124
|
+
return trimString;
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
Object.defineProperty(exports, 'truncateString', {
|
|
128
|
+
enumerable: true,
|
|
129
|
+
get: function () {
|
|
130
|
+
return truncateString;
|
|
131
|
+
}
|
|
132
|
+
});
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2026 - present Nazmul Hassan
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import { a as isNonEmptyString } from "./primitives-KsFUp3kQ.mjs";
|
|
18
|
+
|
|
19
|
+
//#region src/string/basics.ts
|
|
20
|
+
/**
|
|
21
|
+
* * Utility to truncate a string to a specified length.
|
|
22
|
+
*
|
|
23
|
+
* @param str The string to truncate.
|
|
24
|
+
* @param maxLength The maximum length of the truncated string.
|
|
25
|
+
* @returns Truncated string with ellipsis (`...`) (only if it has more length than `maxLength`).
|
|
26
|
+
*/
|
|
27
|
+
function truncateString(str, maxLength) {
|
|
28
|
+
if (!isNonEmptyString(str)) return "";
|
|
29
|
+
const trimmedString = str.trim();
|
|
30
|
+
if (!trimmedString) return "";
|
|
31
|
+
if (trimmedString.length <= maxLength) return trimmedString;
|
|
32
|
+
return trimmedString.slice(0, maxLength).concat("...");
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* * Generates a random alphanumeric (16 characters long, this length is customizable in the options) ID string composed of an optional `prefix`, `suffix`, a `timestamp`, `caseOption` and a customizable `separator`.
|
|
36
|
+
*
|
|
37
|
+
* @param options Configuration options for random ID generation.
|
|
38
|
+
* @returns The generated ID string composed of the random alphanumeric string of specified length with optional `timeStamp`, `prefix`, and `suffix`, `caseOption` and `separator`.
|
|
39
|
+
*
|
|
40
|
+
* @see {@link https://toolbox.nazmul-nhb.dev/docs/utilities/hash/uuid uuid} for `uuid` generation
|
|
41
|
+
* @see {@link https://toolbox.nazmul-nhb.dev/docs/utilities/hash/randomHex randomHex} for random hexadecimal string generation
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* // Generate an ID with all default options
|
|
45
|
+
* const id = generateRandomID();
|
|
46
|
+
* // Example output: "swo8ckxwsc13w7xw"
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* // Generate an ID with a custom prefix and separator
|
|
50
|
+
* const id = generateRandomID({ prefix: 'ID', separator: '-' });
|
|
51
|
+
* // Example output: "ID-eh1ymwfxzwas9jte"
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* // Generate an ID with a timestamp
|
|
55
|
+
* const id = generateRandomID({ timeStamp: false });
|
|
56
|
+
* // Example output: "1764610287501pd3r4w85qwkuulgf"
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* // Generate an ID with a custom length for the random string
|
|
60
|
+
* const id = generateRandomID({ length: 8 });
|
|
61
|
+
* // Example output: "i623uiev"
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* // Generate an ID with a custom suffix
|
|
65
|
+
* const id = generateRandomID({ suffix: 'END' });
|
|
66
|
+
* // Example output: "3csf27a4800rbli9END"
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* // Generate an ID with a uppercase random string
|
|
70
|
+
* const id = generateRandomID({ caseOption: "upper" });
|
|
71
|
+
* // Example output: "H0VNU6O8XV1Y30HG"
|
|
72
|
+
*
|
|
73
|
+
* @example
|
|
74
|
+
* // Generate an ID with all options customized
|
|
75
|
+
* const id = generateRandomID({
|
|
76
|
+
* prefix: 'ID',
|
|
77
|
+
* suffix: 'END',
|
|
78
|
+
* timeStamp: true,
|
|
79
|
+
* length: 10,
|
|
80
|
+
* separator: '-',
|
|
81
|
+
* caseOption: "upper"
|
|
82
|
+
* });
|
|
83
|
+
* // Example output: "ID-1764610471474-4KSL51IB91-END"
|
|
84
|
+
*/
|
|
85
|
+
function generateRandomID(options) {
|
|
86
|
+
const { prefix = "", suffix = "", timeStamp = false, length = 16, separator = "", caseOption = null } = options || {};
|
|
87
|
+
const date = timeStamp ? Date.now() : "";
|
|
88
|
+
const randomString = Array.from({ length }, () => Math.random().toString(36).slice(2, 3)).join("");
|
|
89
|
+
const ID = [
|
|
90
|
+
prefix && prefix.trim(),
|
|
91
|
+
date,
|
|
92
|
+
randomString,
|
|
93
|
+
suffix && suffix.trim()
|
|
94
|
+
].filter(Boolean).join(separator);
|
|
95
|
+
switch (caseOption) {
|
|
96
|
+
case "upper": return ID.toUpperCase();
|
|
97
|
+
case "lower": return ID.toLowerCase();
|
|
98
|
+
default: return ID;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* * Trims all the words in a string or an array of strings.
|
|
103
|
+
*
|
|
104
|
+
* @param input String or array of strings.
|
|
105
|
+
* @returns Trimmed string or array of strings.
|
|
106
|
+
*/
|
|
107
|
+
function trimString(input) {
|
|
108
|
+
if (!input) return "";
|
|
109
|
+
if (isNonEmptyString(input)) return input.trim().replace(/\s+/g, " ");
|
|
110
|
+
if (Array.isArray(input)) return input.map((str) => isNonEmptyString(str) ? str.trim().replace(/\s+/g, " ") : str);
|
|
111
|
+
throw new TypeError("Expected string or array of strings!", { cause: "Invalid Input Type" });
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
//#endregion
|
|
115
|
+
export { trimString as n, truncateString as r, generateRandomID as t };
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2026 - present Nazmul Hassan
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import { F as RandomIdOptions } from "./string-CsNsm_65.cjs";
|
|
18
|
+
|
|
19
|
+
//#region src/string/basics.d.ts
|
|
20
|
+
/**
|
|
21
|
+
* * Utility to truncate a string to a specified length.
|
|
22
|
+
*
|
|
23
|
+
* @param str The string to truncate.
|
|
24
|
+
* @param maxLength The maximum length of the truncated string.
|
|
25
|
+
* @returns Truncated string with ellipsis (`...`) (only if it has more length than `maxLength`).
|
|
26
|
+
*/
|
|
27
|
+
declare function truncateString(str: string, maxLength: number): string;
|
|
28
|
+
/**
|
|
29
|
+
* * Generates a random alphanumeric (16 characters long, this length is customizable in the options) ID string composed of an optional `prefix`, `suffix`, a `timestamp`, `caseOption` and a customizable `separator`.
|
|
30
|
+
*
|
|
31
|
+
* @param options Configuration options for random ID generation.
|
|
32
|
+
* @returns The generated ID string composed of the random alphanumeric string of specified length with optional `timeStamp`, `prefix`, and `suffix`, `caseOption` and `separator`.
|
|
33
|
+
*
|
|
34
|
+
* @see {@link https://toolbox.nazmul-nhb.dev/docs/utilities/hash/uuid uuid} for `uuid` generation
|
|
35
|
+
* @see {@link https://toolbox.nazmul-nhb.dev/docs/utilities/hash/randomHex randomHex} for random hexadecimal string generation
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* // Generate an ID with all default options
|
|
39
|
+
* const id = generateRandomID();
|
|
40
|
+
* // Example output: "swo8ckxwsc13w7xw"
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* // Generate an ID with a custom prefix and separator
|
|
44
|
+
* const id = generateRandomID({ prefix: 'ID', separator: '-' });
|
|
45
|
+
* // Example output: "ID-eh1ymwfxzwas9jte"
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* // Generate an ID with a timestamp
|
|
49
|
+
* const id = generateRandomID({ timeStamp: false });
|
|
50
|
+
* // Example output: "1764610287501pd3r4w85qwkuulgf"
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* // Generate an ID with a custom length for the random string
|
|
54
|
+
* const id = generateRandomID({ length: 8 });
|
|
55
|
+
* // Example output: "i623uiev"
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* // Generate an ID with a custom suffix
|
|
59
|
+
* const id = generateRandomID({ suffix: 'END' });
|
|
60
|
+
* // Example output: "3csf27a4800rbli9END"
|
|
61
|
+
*
|
|
62
|
+
* @example
|
|
63
|
+
* // Generate an ID with a uppercase random string
|
|
64
|
+
* const id = generateRandomID({ caseOption: "upper" });
|
|
65
|
+
* // Example output: "H0VNU6O8XV1Y30HG"
|
|
66
|
+
*
|
|
67
|
+
* @example
|
|
68
|
+
* // Generate an ID with all options customized
|
|
69
|
+
* const id = generateRandomID({
|
|
70
|
+
* prefix: 'ID',
|
|
71
|
+
* suffix: 'END',
|
|
72
|
+
* timeStamp: true,
|
|
73
|
+
* length: 10,
|
|
74
|
+
* separator: '-',
|
|
75
|
+
* caseOption: "upper"
|
|
76
|
+
* });
|
|
77
|
+
* // Example output: "ID-1764610471474-4KSL51IB91-END"
|
|
78
|
+
*/
|
|
79
|
+
declare function generateRandomID(options?: RandomIdOptions): string;
|
|
80
|
+
/**
|
|
81
|
+
* * Trims all the words in a string.
|
|
82
|
+
*
|
|
83
|
+
* @param input The string to trim.
|
|
84
|
+
* @returns Trimmed string.
|
|
85
|
+
*/
|
|
86
|
+
declare function trimString(input: string): string;
|
|
87
|
+
/**
|
|
88
|
+
* * Trims all the words in an array of strings.
|
|
89
|
+
*
|
|
90
|
+
* @param input The array of strings to trim.
|
|
91
|
+
* @returns Trimmed array of strings.
|
|
92
|
+
*/
|
|
93
|
+
declare function trimString(input: string[]): string[];
|
|
94
|
+
//#endregion
|
|
95
|
+
export { trimString as n, truncateString as r, generateRandomID as t };
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2026 - present Nazmul Hassan
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import { F as RandomIdOptions } from "./string-CBAbxaG1.mjs";
|
|
18
|
+
|
|
19
|
+
//#region src/string/basics.d.ts
|
|
20
|
+
/**
|
|
21
|
+
* * Utility to truncate a string to a specified length.
|
|
22
|
+
*
|
|
23
|
+
* @param str The string to truncate.
|
|
24
|
+
* @param maxLength The maximum length of the truncated string.
|
|
25
|
+
* @returns Truncated string with ellipsis (`...`) (only if it has more length than `maxLength`).
|
|
26
|
+
*/
|
|
27
|
+
declare function truncateString(str: string, maxLength: number): string;
|
|
28
|
+
/**
|
|
29
|
+
* * Generates a random alphanumeric (16 characters long, this length is customizable in the options) ID string composed of an optional `prefix`, `suffix`, a `timestamp`, `caseOption` and a customizable `separator`.
|
|
30
|
+
*
|
|
31
|
+
* @param options Configuration options for random ID generation.
|
|
32
|
+
* @returns The generated ID string composed of the random alphanumeric string of specified length with optional `timeStamp`, `prefix`, and `suffix`, `caseOption` and `separator`.
|
|
33
|
+
*
|
|
34
|
+
* @see {@link https://toolbox.nazmul-nhb.dev/docs/utilities/hash/uuid uuid} for `uuid` generation
|
|
35
|
+
* @see {@link https://toolbox.nazmul-nhb.dev/docs/utilities/hash/randomHex randomHex} for random hexadecimal string generation
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* // Generate an ID with all default options
|
|
39
|
+
* const id = generateRandomID();
|
|
40
|
+
* // Example output: "swo8ckxwsc13w7xw"
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* // Generate an ID with a custom prefix and separator
|
|
44
|
+
* const id = generateRandomID({ prefix: 'ID', separator: '-' });
|
|
45
|
+
* // Example output: "ID-eh1ymwfxzwas9jte"
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* // Generate an ID with a timestamp
|
|
49
|
+
* const id = generateRandomID({ timeStamp: false });
|
|
50
|
+
* // Example output: "1764610287501pd3r4w85qwkuulgf"
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* // Generate an ID with a custom length for the random string
|
|
54
|
+
* const id = generateRandomID({ length: 8 });
|
|
55
|
+
* // Example output: "i623uiev"
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* // Generate an ID with a custom suffix
|
|
59
|
+
* const id = generateRandomID({ suffix: 'END' });
|
|
60
|
+
* // Example output: "3csf27a4800rbli9END"
|
|
61
|
+
*
|
|
62
|
+
* @example
|
|
63
|
+
* // Generate an ID with a uppercase random string
|
|
64
|
+
* const id = generateRandomID({ caseOption: "upper" });
|
|
65
|
+
* // Example output: "H0VNU6O8XV1Y30HG"
|
|
66
|
+
*
|
|
67
|
+
* @example
|
|
68
|
+
* // Generate an ID with all options customized
|
|
69
|
+
* const id = generateRandomID({
|
|
70
|
+
* prefix: 'ID',
|
|
71
|
+
* suffix: 'END',
|
|
72
|
+
* timeStamp: true,
|
|
73
|
+
* length: 10,
|
|
74
|
+
* separator: '-',
|
|
75
|
+
* caseOption: "upper"
|
|
76
|
+
* });
|
|
77
|
+
* // Example output: "ID-1764610471474-4KSL51IB91-END"
|
|
78
|
+
*/
|
|
79
|
+
declare function generateRandomID(options?: RandomIdOptions): string;
|
|
80
|
+
/**
|
|
81
|
+
* * Trims all the words in a string.
|
|
82
|
+
*
|
|
83
|
+
* @param input The string to trim.
|
|
84
|
+
* @returns Trimmed string.
|
|
85
|
+
*/
|
|
86
|
+
declare function trimString(input: string): string;
|
|
87
|
+
/**
|
|
88
|
+
* * Trims all the words in an array of strings.
|
|
89
|
+
*
|
|
90
|
+
* @param input The array of strings to trim.
|
|
91
|
+
* @returns Trimmed array of strings.
|
|
92
|
+
*/
|
|
93
|
+
declare function trimString(input: string[]): string[];
|
|
94
|
+
//#endregion
|
|
95
|
+
export { trimString as n, truncateString as r, generateRandomID as t };
|