toolbox-x 2.2.4 → 2.3.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/CHANGELOG.md +23 -4
- package/dist/{guards-Dc9MB9on.mjs → basics-B7Sqf33u.mjs} +233 -233
- package/dist/{guards-BSwFQX1M.cjs → basics-Cif013VV.cjs} +233 -233
- package/dist/{colors.cjs → colors/index.cjs} +6 -6
- package/dist/{colors.d.mts → colors/index.d.cts} +2 -2
- package/dist/{colors.d.cts → colors/index.d.mts} +2 -2
- package/dist/{colors.mjs → colors/index.mjs} +6 -6
- package/dist/constants.cjs +13 -13
- package/dist/constants.mjs +3 -3
- package/dist/{converter.cjs → converter/index.cjs} +1 -1
- package/dist/{converter.d.cts → converter/index.d.cts} +2 -2
- package/dist/{converter.d.mts → converter/index.d.mts} +2 -2
- package/dist/{converter.mjs → converter/index.mjs} +1 -1
- package/dist/{date.cjs → date/index.cjs} +7 -7
- package/dist/{date.d.cts → date/index.d.cts} +1 -1
- package/dist/{date.d.mts → date/index.d.mts} +1 -1
- package/dist/{date.mjs → date/index.mjs} +7 -7
- package/dist/{dom.cjs → dom/index.cjs} +8 -8
- package/dist/{dom.d.cts → dom/index.d.cts} +3 -3
- package/dist/{dom.d.mts → dom/index.d.mts} +3 -3
- package/dist/{dom.mjs → dom/index.mjs} +5 -5
- package/dist/{guards.cjs → guards/index.cjs} +38 -38
- package/dist/{guards.d.mts → guards/index.d.cts} +4 -4
- package/dist/{guards.d.cts → guards/index.d.mts} +4 -4
- package/dist/{guards.mjs → guards/index.mjs} +6 -6
- package/dist/{guards-CqbVT4L5.cjs → guards-BD2Fkugj.cjs} +2 -2
- package/dist/{guards-DKGBsd6x.mjs → guards-DBunDnng.mjs} +2 -2
- package/dist/{hash.cjs → hash/index.cjs} +69 -66
- package/dist/{hash.d.cts → hash/index.d.cts} +77 -5
- package/dist/{hash.d.mts → hash/index.d.mts} +77 -5
- package/dist/{hash.mjs → hash/index.mjs} +5 -5
- package/dist/{http-status.cjs → http-status/index.cjs} +1 -1
- package/dist/{http-status.d.mts → http-status/index.d.cts} +2 -2
- package/dist/{http-status.d.cts → http-status/index.d.mts} +2 -2
- package/dist/{http-status.mjs → http-status/index.mjs} +1 -1
- package/dist/index.cjs +84 -84
- package/dist/index.mjs +5 -5
- package/dist/{parse-TuFyLeVH.mjs → parse-CILDG7TG.mjs} +3 -3
- package/dist/{parse-jh637S25.cjs → parse-CffWYCuy.cjs} +3 -3
- package/dist/{query-sWSi-d7u.cjs → query-Blm7AiEZ.cjs} +9 -9
- package/dist/{query-BomnyWh3.mjs → query-PGFEup3p.mjs} +2 -2
- package/dist/{stylog.cjs → stylog/index.cjs} +5 -5
- package/dist/{stylog.d.cts → stylog/index.d.cts} +2 -2
- package/dist/{stylog.d.mts → stylog/index.d.mts} +2 -2
- package/dist/{stylog.mjs → stylog/index.mjs} +5 -5
- package/dist/types/pluralizer.d.cts +25 -1
- package/dist/types/pluralizer.d.mts +25 -1
- package/dist/{utilities-BSv8VbnM.mjs → utilities-CmPwOkdy.mjs} +1 -1
- package/dist/{utilities-BVpk3LKy.cjs → utilities-_COSGq1U.cjs} +1 -1
- package/dist/{basics-20lm69yy.mjs → utils-BO5CcsjK.mjs} +631 -548
- package/dist/{basics-byj0VH1c.cjs → utils-DR9g0Sef.cjs} +580 -479
- package/dist/{verbalizer.cjs → verbalizer/index.cjs} +1 -1
- package/dist/{verbalizer.mjs → verbalizer/index.mjs} +1 -1
- package/package.json +22 -25
- package/dist/pluralizer-DXMuPUAK.d.mts +0 -42
- package/dist/pluralizer-DYsDqq9c.d.cts +0 -42
- package/dist/pluralizer.cjs +0 -678
- package/dist/pluralizer.d.cts +0 -152
- package/dist/pluralizer.d.mts +0 -152
- package/dist/pluralizer.mjs +0 -676
- /package/dist/{verbalizer.d.cts → verbalizer/index.d.cts} +0 -0
- /package/dist/{verbalizer.d.mts → verbalizer/index.d.mts} +0 -0
|
@@ -15,10 +15,240 @@
|
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
17
|
const require_primitives = require('./primitives-CBGICrDR.cjs');
|
|
18
|
+
const require_utils = require('./utils-DR9g0Sef.cjs');
|
|
18
19
|
const require_specials = require('./specials-DU8u108m.cjs');
|
|
19
|
-
const require_utilities = require('./utilities-
|
|
20
|
-
const require_basics = require('./basics-byj0VH1c.cjs');
|
|
20
|
+
const require_utilities = require('./utilities-_COSGq1U.cjs');
|
|
21
21
|
|
|
22
|
+
//#region src/string/convert.ts
|
|
23
|
+
/**
|
|
24
|
+
* * Replaces all occurrences of a string or pattern in the given input string.
|
|
25
|
+
*
|
|
26
|
+
* - If `find` is a string, it is converted into a global regular expression (`/find/g`).
|
|
27
|
+
* - If `find` is a `RegExp`, the global (`g`) flag is ensured.
|
|
28
|
+
* - Trims the input before performing replacements.
|
|
29
|
+
*
|
|
30
|
+
* @param input - The string in which replacements should be performed.
|
|
31
|
+
* @param find - The substring or regex pattern to search for.
|
|
32
|
+
* @param replace - The string to replace matches with.
|
|
33
|
+
* @returns The modified/refined string with replacements applied.
|
|
34
|
+
*/
|
|
35
|
+
const replaceAllInString = (input, find, replace) => {
|
|
36
|
+
const trimmedString = require_utils.trimString(input);
|
|
37
|
+
const regex = require_primitives.isString(find) ? new RegExp(find, "g") : new RegExp(find, find?.flags.includes("g") ? find?.flags : find?.flags + "g");
|
|
38
|
+
return trimmedString?.replace(regex, replace);
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* * Converts a string into a URL-friendly slug.
|
|
42
|
+
* @param input - The string to be converted.
|
|
43
|
+
* @returns The slugified string.
|
|
44
|
+
*/
|
|
45
|
+
const slugifyString = (input) => {
|
|
46
|
+
return require_utils.trimString(normalizeString(input))?.toLowerCase()?.replace(/[^a-z0-9]+/g, "-")?.replace(/^-+|-+$/g, "");
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* * Masks part of a string for privacy.
|
|
50
|
+
* @param input - The string to mask.
|
|
51
|
+
* @param options - Options for masking a string.
|
|
52
|
+
* @returns The masked string.
|
|
53
|
+
*/
|
|
54
|
+
const maskString = (input, options) => {
|
|
55
|
+
const { start = 1, end = 1, maskCharacter: maskChar = "*" } = options || {};
|
|
56
|
+
const trimmedString = require_utils.trimString(input);
|
|
57
|
+
if (trimmedString?.length <= start + end) return maskChar?.repeat(trimmedString?.length);
|
|
58
|
+
return trimmedString.slice(0, start) + maskChar?.repeat(trimmedString?.length - start - end) + (end > 0 ? trimmedString.slice(-end) : "");
|
|
59
|
+
};
|
|
60
|
+
/**
|
|
61
|
+
* * Reverses a given string.
|
|
62
|
+
* @param input - The string to reverse.
|
|
63
|
+
* @returns The reversed string.
|
|
64
|
+
*
|
|
65
|
+
* @remarks It {@link trimString trims} the whitespace of the input string before reversing it.
|
|
66
|
+
*/
|
|
67
|
+
const reverseString = (input) => {
|
|
68
|
+
return require_utils.trimString(input)?.split("")?.reverse()?.join("");
|
|
69
|
+
};
|
|
70
|
+
/**
|
|
71
|
+
* * Normalizes a string by removing diacritics (accents).
|
|
72
|
+
* @param str The input string.
|
|
73
|
+
* @returns The normalized string.
|
|
74
|
+
*/
|
|
75
|
+
function normalizeString(str) {
|
|
76
|
+
return str?.normalize("NFD")?.replace(/[\u0300-\u036f]/g, "");
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* * Extracts all email addresses from a string.
|
|
80
|
+
* @param str The input string.
|
|
81
|
+
* @returns An array of extracted email addresses.
|
|
82
|
+
*/
|
|
83
|
+
function extractEmails(str) {
|
|
84
|
+
return str?.match(/[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}/g) || [];
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* * Extracts all URLs from a string.
|
|
88
|
+
* @param str The input string.
|
|
89
|
+
* @returns An array of extracted URLs.
|
|
90
|
+
*/
|
|
91
|
+
function extractURLs(str) {
|
|
92
|
+
return str?.match(/https?:\/\/[^\s/$.?#].[^\s]*/g) || [];
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* * Returns a grammatically correct unit string, optionally prefixed with the number.
|
|
96
|
+
*
|
|
97
|
+
* @remarks For complex and versatile pluralization, please refer to {@link https://toolbox-x.nazmul-nhb.dev/docs/utils/string/pluralizer pluralizer} or {@link https://toolbox-x.nazmul-nhb.dev/docs/classes/pluralizer Pluralizer Class} instead.
|
|
98
|
+
*
|
|
99
|
+
* @param count The numeric value to determine singular or plural.
|
|
100
|
+
* @param unit The unit name (e.g., "day", "hour").
|
|
101
|
+
* @param withNumber Whether to prefix the count before the unit. Defaults to `true`.
|
|
102
|
+
* @returns Formatted unit string like `"1 day"`, `"2 months"`, or `"hour"`.
|
|
103
|
+
*/
|
|
104
|
+
function formatUnitWithPlural(count, unit, withNumber = true) {
|
|
105
|
+
const pluralized = Math.abs(count) === 1 ? unit : `${unit}s`;
|
|
106
|
+
return withNumber ? `${count} ${pluralized}` : pluralized;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
//#endregion
|
|
110
|
+
//#region src/number/guards.ts
|
|
111
|
+
/**
|
|
112
|
+
* * Check if a number is even or not.
|
|
113
|
+
*
|
|
114
|
+
* @param input The number or numeric string to check.
|
|
115
|
+
* @returns Boolean: `true` if even and `false` if not even.
|
|
116
|
+
*/
|
|
117
|
+
const isEven = (input) => {
|
|
118
|
+
const parsed = require_utilities.normalizeNumber(input);
|
|
119
|
+
if (require_primitives.isUndefined(parsed)) return false;
|
|
120
|
+
return parsed % 2 === 0;
|
|
121
|
+
};
|
|
122
|
+
/**
|
|
123
|
+
* * Checks if a number is odd or not.
|
|
124
|
+
*
|
|
125
|
+
* @param input The number or numeric string to check.
|
|
126
|
+
* @returns Boolean: `true` if odd and `false` if not odd.
|
|
127
|
+
*/
|
|
128
|
+
const isOdd = (input) => {
|
|
129
|
+
const parsed = require_utilities.normalizeNumber(input);
|
|
130
|
+
if (require_primitives.isUndefined(parsed)) return false;
|
|
131
|
+
return parsed % 2 !== 0;
|
|
132
|
+
};
|
|
133
|
+
/**
|
|
134
|
+
* * Checks if a number is a multiple of another number.
|
|
135
|
+
*
|
|
136
|
+
* @param input - The number to check.
|
|
137
|
+
* @param multipleOf - The number to check against.
|
|
138
|
+
* @returns `true` if `input` is a multiple of `multipleOf`, otherwise `false`.
|
|
139
|
+
*/
|
|
140
|
+
const isMultiple = (input, multipleOf) => {
|
|
141
|
+
return input % multipleOf === 0;
|
|
142
|
+
};
|
|
143
|
+
/**
|
|
144
|
+
* * Checks if a number is a perfect square.
|
|
145
|
+
*
|
|
146
|
+
* @param num The number to check.
|
|
147
|
+
* @returns `true` if the number is a perfect square, otherwise `false`.
|
|
148
|
+
*/
|
|
149
|
+
function isPerfectSquare(num) {
|
|
150
|
+
return Number.isInteger(Math.sqrt(num));
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* * Checks if a number is part of the Fibonacci sequence.
|
|
154
|
+
*
|
|
155
|
+
* @param num The number to check.
|
|
156
|
+
* @returns `true` if the number is a Fibonacci number, otherwise `false`.
|
|
157
|
+
*/
|
|
158
|
+
function isFibonacci(num) {
|
|
159
|
+
return isPerfectSquare(5 * num * num + 4) || isPerfectSquare(5 * num * num - 4);
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* * Checks whether any input is not a finite number.
|
|
163
|
+
*
|
|
164
|
+
* @param numbers - The list of numbers to validate.
|
|
165
|
+
* @returns `true` if any input is not finite.
|
|
166
|
+
*/
|
|
167
|
+
function areInvalidNumbers(...numbers) {
|
|
168
|
+
return numbers?.some((n) => !Number.isFinite(n));
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
//#endregion
|
|
172
|
+
//#region src/number/prime.ts
|
|
173
|
+
/**
|
|
174
|
+
* * Checks if a number is prime.
|
|
175
|
+
*
|
|
176
|
+
* @param number The number to check.
|
|
177
|
+
* @returns Boolean: `true` if the number is prime, otherwise `false`.
|
|
178
|
+
*/
|
|
179
|
+
const isPrime = (number) => {
|
|
180
|
+
if (number < 2) return false;
|
|
181
|
+
if (number === 2 || number === 3) return true;
|
|
182
|
+
if (number % 2 === 0 || number % 3 === 0) return false;
|
|
183
|
+
for (let i = 5; i * i <= number; i += 6) if (number % i === 0 || number % (i + 2) === 0) return false;
|
|
184
|
+
return true;
|
|
185
|
+
};
|
|
186
|
+
/**
|
|
187
|
+
* * Find prime numbers in a given range.
|
|
188
|
+
*
|
|
189
|
+
* @param start The starting number of the range. Default is `1`.
|
|
190
|
+
* @param end The ending number of the range. Default is `1000`.
|
|
191
|
+
* @returns An array of prime numbers within the range (inclusive).
|
|
192
|
+
*/
|
|
193
|
+
const findPrimeNumbers = (start = 1, end = 1e3) => {
|
|
194
|
+
let startNumber = start, endNumber = end;
|
|
195
|
+
if (start > end) [startNumber, endNumber] = [end, start];
|
|
196
|
+
return Array.from({ length: endNumber - startNumber + 1 }, (_, i) => startNumber + i).filter(isPrime);
|
|
197
|
+
};
|
|
198
|
+
|
|
199
|
+
//#endregion
|
|
200
|
+
//#region src/string/guards.ts
|
|
201
|
+
/**
|
|
202
|
+
* * Checks if a string is a palindrome.
|
|
203
|
+
* @param input - The string to check.
|
|
204
|
+
* @returns True if the string is a palindrome, otherwise false.
|
|
205
|
+
*/
|
|
206
|
+
const isPalindrome = (input) => {
|
|
207
|
+
const normalized = input.toLowerCase().replace(/[^a-z0-9]/g, "");
|
|
208
|
+
return normalized === reverseString(normalized);
|
|
209
|
+
};
|
|
210
|
+
/**
|
|
211
|
+
* * Checks if a string is in camelCase format.
|
|
212
|
+
* @param str The string to check.
|
|
213
|
+
* @returns `true` if the string is in camelCase, otherwise `false`.
|
|
214
|
+
*/
|
|
215
|
+
function isCamelCase(str) {
|
|
216
|
+
return /^[a-z]+([A-Z][a-z]*)*$/.test(str);
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* * Checks if a string is in PascalCase format.
|
|
220
|
+
* @param str The string to check.
|
|
221
|
+
* @returns `true` if the string is in PascalCase, otherwise `false`.
|
|
222
|
+
*/
|
|
223
|
+
function isPascalCase(str) {
|
|
224
|
+
return /^[A-Z][a-zA-Z]*$/.test(str);
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* * Checks if a string is in snake_case format.
|
|
228
|
+
* @param str The string to check.
|
|
229
|
+
* @returns `true` if the string is in snake_case, otherwise `false`.
|
|
230
|
+
*/
|
|
231
|
+
function isSnakeCase(str) {
|
|
232
|
+
return /^[a-z]+(_[a-z]+)*$/.test(str);
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* * Checks if a string is in kebab-case format.
|
|
236
|
+
* @param str The string to check.
|
|
237
|
+
* @returns `true` if the string is in kebab-case, otherwise `false`.
|
|
238
|
+
*/
|
|
239
|
+
function isKebabCase(str) {
|
|
240
|
+
return /^[a-z]+(-[a-z]+)*$/.test(str);
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* * Checks if a string contains only emojis.
|
|
244
|
+
* @param str The string to check.
|
|
245
|
+
* @returns `true` if the string contains only emojis, otherwise `false`.
|
|
246
|
+
*/
|
|
247
|
+
function isEmojiOnly(str) {
|
|
248
|
+
return /^[\p{Emoji}]+$/u.test(str);
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
//#endregion
|
|
22
252
|
//#region src/object/basics.ts
|
|
23
253
|
/**
|
|
24
254
|
* * Deep clone an object using `structuredClone` or deterministic *JSON serialization*.
|
|
@@ -66,7 +296,7 @@ const require_basics = require('./basics-byj0VH1c.cjs');
|
|
|
66
296
|
function cloneObject(obj, serialize = false) {
|
|
67
297
|
try {
|
|
68
298
|
if (!serialize && typeof structuredClone === "function") return structuredClone(obj);
|
|
69
|
-
return JSON.parse(
|
|
299
|
+
return JSON.parse(require_utils.stableStringify(obj));
|
|
70
300
|
} catch {
|
|
71
301
|
return { ...obj };
|
|
72
302
|
}
|
|
@@ -191,236 +421,6 @@ const getLastArrayElement = (array) => {
|
|
|
191
421
|
return array?.length > 0 ? array[array?.length - 1] : void 0;
|
|
192
422
|
};
|
|
193
423
|
|
|
194
|
-
//#endregion
|
|
195
|
-
//#region src/number/guards.ts
|
|
196
|
-
/**
|
|
197
|
-
* * Check if a number is even or not.
|
|
198
|
-
*
|
|
199
|
-
* @param input The number or numeric string to check.
|
|
200
|
-
* @returns Boolean: `true` if even and `false` if not even.
|
|
201
|
-
*/
|
|
202
|
-
const isEven = (input) => {
|
|
203
|
-
const parsed = require_utilities.normalizeNumber(input);
|
|
204
|
-
if (require_primitives.isUndefined(parsed)) return false;
|
|
205
|
-
return parsed % 2 === 0;
|
|
206
|
-
};
|
|
207
|
-
/**
|
|
208
|
-
* * Checks if a number is odd or not.
|
|
209
|
-
*
|
|
210
|
-
* @param input The number or numeric string to check.
|
|
211
|
-
* @returns Boolean: `true` if odd and `false` if not odd.
|
|
212
|
-
*/
|
|
213
|
-
const isOdd = (input) => {
|
|
214
|
-
const parsed = require_utilities.normalizeNumber(input);
|
|
215
|
-
if (require_primitives.isUndefined(parsed)) return false;
|
|
216
|
-
return parsed % 2 !== 0;
|
|
217
|
-
};
|
|
218
|
-
/**
|
|
219
|
-
* * Checks if a number is a multiple of another number.
|
|
220
|
-
*
|
|
221
|
-
* @param input - The number to check.
|
|
222
|
-
* @param multipleOf - The number to check against.
|
|
223
|
-
* @returns `true` if `input` is a multiple of `multipleOf`, otherwise `false`.
|
|
224
|
-
*/
|
|
225
|
-
const isMultiple = (input, multipleOf) => {
|
|
226
|
-
return input % multipleOf === 0;
|
|
227
|
-
};
|
|
228
|
-
/**
|
|
229
|
-
* * Checks if a number is a perfect square.
|
|
230
|
-
*
|
|
231
|
-
* @param num The number to check.
|
|
232
|
-
* @returns `true` if the number is a perfect square, otherwise `false`.
|
|
233
|
-
*/
|
|
234
|
-
function isPerfectSquare(num) {
|
|
235
|
-
return Number.isInteger(Math.sqrt(num));
|
|
236
|
-
}
|
|
237
|
-
/**
|
|
238
|
-
* * Checks if a number is part of the Fibonacci sequence.
|
|
239
|
-
*
|
|
240
|
-
* @param num The number to check.
|
|
241
|
-
* @returns `true` if the number is a Fibonacci number, otherwise `false`.
|
|
242
|
-
*/
|
|
243
|
-
function isFibonacci(num) {
|
|
244
|
-
return isPerfectSquare(5 * num * num + 4) || isPerfectSquare(5 * num * num - 4);
|
|
245
|
-
}
|
|
246
|
-
/**
|
|
247
|
-
* * Checks whether any input is not a finite number.
|
|
248
|
-
*
|
|
249
|
-
* @param numbers - The list of numbers to validate.
|
|
250
|
-
* @returns `true` if any input is not finite.
|
|
251
|
-
*/
|
|
252
|
-
function areInvalidNumbers(...numbers) {
|
|
253
|
-
return numbers?.some((n) => !Number.isFinite(n));
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
//#endregion
|
|
257
|
-
//#region src/number/prime.ts
|
|
258
|
-
/**
|
|
259
|
-
* * Checks if a number is prime.
|
|
260
|
-
*
|
|
261
|
-
* @param number The number to check.
|
|
262
|
-
* @returns Boolean: `true` if the number is prime, otherwise `false`.
|
|
263
|
-
*/
|
|
264
|
-
const isPrime = (number) => {
|
|
265
|
-
if (number < 2) return false;
|
|
266
|
-
if (number === 2 || number === 3) return true;
|
|
267
|
-
if (number % 2 === 0 || number % 3 === 0) return false;
|
|
268
|
-
for (let i = 5; i * i <= number; i += 6) if (number % i === 0 || number % (i + 2) === 0) return false;
|
|
269
|
-
return true;
|
|
270
|
-
};
|
|
271
|
-
/**
|
|
272
|
-
* * Find prime numbers in a given range.
|
|
273
|
-
*
|
|
274
|
-
* @param start The starting number of the range. Default is `1`.
|
|
275
|
-
* @param end The ending number of the range. Default is `1000`.
|
|
276
|
-
* @returns An array of prime numbers within the range (inclusive).
|
|
277
|
-
*/
|
|
278
|
-
const findPrimeNumbers = (start = 1, end = 1e3) => {
|
|
279
|
-
let startNumber = start, endNumber = end;
|
|
280
|
-
if (start > end) [startNumber, endNumber] = [end, start];
|
|
281
|
-
return Array.from({ length: endNumber - startNumber + 1 }, (_, i) => startNumber + i).filter(isPrime);
|
|
282
|
-
};
|
|
283
|
-
|
|
284
|
-
//#endregion
|
|
285
|
-
//#region src/string/convert.ts
|
|
286
|
-
/**
|
|
287
|
-
* * Replaces all occurrences of a string or pattern in the given input string.
|
|
288
|
-
*
|
|
289
|
-
* - If `find` is a string, it is converted into a global regular expression (`/find/g`).
|
|
290
|
-
* - If `find` is a `RegExp`, the global (`g`) flag is ensured.
|
|
291
|
-
* - Trims the input before performing replacements.
|
|
292
|
-
*
|
|
293
|
-
* @param input - The string in which replacements should be performed.
|
|
294
|
-
* @param find - The substring or regex pattern to search for.
|
|
295
|
-
* @param replace - The string to replace matches with.
|
|
296
|
-
* @returns The modified/refined string with replacements applied.
|
|
297
|
-
*/
|
|
298
|
-
const replaceAllInString = (input, find, replace) => {
|
|
299
|
-
const trimmedString = require_basics.trimString(input);
|
|
300
|
-
const regex = require_primitives.isString(find) ? new RegExp(find, "g") : new RegExp(find, find?.flags.includes("g") ? find?.flags : find?.flags + "g");
|
|
301
|
-
return trimmedString?.replace(regex, replace);
|
|
302
|
-
};
|
|
303
|
-
/**
|
|
304
|
-
* * Converts a string into a URL-friendly slug.
|
|
305
|
-
* @param input - The string to be converted.
|
|
306
|
-
* @returns The slugified string.
|
|
307
|
-
*/
|
|
308
|
-
const slugifyString = (input) => {
|
|
309
|
-
return require_basics.trimString(normalizeString(input))?.toLowerCase()?.replace(/[^a-z0-9]+/g, "-")?.replace(/^-+|-+$/g, "");
|
|
310
|
-
};
|
|
311
|
-
/**
|
|
312
|
-
* * Masks part of a string for privacy.
|
|
313
|
-
* @param input - The string to mask.
|
|
314
|
-
* @param options - Options for masking a string.
|
|
315
|
-
* @returns The masked string.
|
|
316
|
-
*/
|
|
317
|
-
const maskString = (input, options) => {
|
|
318
|
-
const { start = 1, end = 1, maskCharacter: maskChar = "*" } = options || {};
|
|
319
|
-
const trimmedString = require_basics.trimString(input);
|
|
320
|
-
if (trimmedString?.length <= start + end) return maskChar?.repeat(trimmedString?.length);
|
|
321
|
-
return trimmedString.slice(0, start) + maskChar?.repeat(trimmedString?.length - start - end) + (end > 0 ? trimmedString.slice(-end) : "");
|
|
322
|
-
};
|
|
323
|
-
/**
|
|
324
|
-
* * Reverses a given string.
|
|
325
|
-
* @param input - The string to reverse.
|
|
326
|
-
* @returns The reversed string.
|
|
327
|
-
*
|
|
328
|
-
* @remarks It {@link trimString trims} the whitespace of the input string before reversing it.
|
|
329
|
-
*/
|
|
330
|
-
const reverseString = (input) => {
|
|
331
|
-
return require_basics.trimString(input)?.split("")?.reverse()?.join("");
|
|
332
|
-
};
|
|
333
|
-
/**
|
|
334
|
-
* * Normalizes a string by removing diacritics (accents).
|
|
335
|
-
* @param str The input string.
|
|
336
|
-
* @returns The normalized string.
|
|
337
|
-
*/
|
|
338
|
-
function normalizeString(str) {
|
|
339
|
-
return str?.normalize("NFD")?.replace(/[\u0300-\u036f]/g, "");
|
|
340
|
-
}
|
|
341
|
-
/**
|
|
342
|
-
* * Extracts all email addresses from a string.
|
|
343
|
-
* @param str The input string.
|
|
344
|
-
* @returns An array of extracted email addresses.
|
|
345
|
-
*/
|
|
346
|
-
function extractEmails(str) {
|
|
347
|
-
return str?.match(/[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}/g) || [];
|
|
348
|
-
}
|
|
349
|
-
/**
|
|
350
|
-
* * Extracts all URLs from a string.
|
|
351
|
-
* @param str The input string.
|
|
352
|
-
* @returns An array of extracted URLs.
|
|
353
|
-
*/
|
|
354
|
-
function extractURLs(str) {
|
|
355
|
-
return str?.match(/https?:\/\/[^\s/$.?#].[^\s]*/g) || [];
|
|
356
|
-
}
|
|
357
|
-
/**
|
|
358
|
-
* * Returns a grammatically correct unit string, optionally prefixed with the number.
|
|
359
|
-
*
|
|
360
|
-
* @remarks For complex and versatile pluralization, please refer to {@link https://toolbox-x.nazmul-nhb.dev/docs/utils/string/pluralizer pluralizer} or {@link https://toolbox-x.nazmul-nhb.dev/docs/classes/pluralizer Pluralizer Class} instead.
|
|
361
|
-
*
|
|
362
|
-
* @param count The numeric value to determine singular or plural.
|
|
363
|
-
* @param unit The unit name (e.g., "day", "hour").
|
|
364
|
-
* @param withNumber Whether to prefix the count before the unit. Defaults to `true`.
|
|
365
|
-
* @returns Formatted unit string like `"1 day"`, `"2 months"`, or `"hour"`.
|
|
366
|
-
*/
|
|
367
|
-
function formatUnitWithPlural(count, unit, withNumber = true) {
|
|
368
|
-
const pluralized = Math.abs(count) === 1 ? unit : `${unit}s`;
|
|
369
|
-
return withNumber ? `${count} ${pluralized}` : pluralized;
|
|
370
|
-
}
|
|
371
|
-
|
|
372
|
-
//#endregion
|
|
373
|
-
//#region src/string/guards.ts
|
|
374
|
-
/**
|
|
375
|
-
* * Checks if a string is a palindrome.
|
|
376
|
-
* @param input - The string to check.
|
|
377
|
-
* @returns True if the string is a palindrome, otherwise false.
|
|
378
|
-
*/
|
|
379
|
-
const isPalindrome = (input) => {
|
|
380
|
-
const normalized = input.toLowerCase().replace(/[^a-z0-9]/g, "");
|
|
381
|
-
return normalized === reverseString(normalized);
|
|
382
|
-
};
|
|
383
|
-
/**
|
|
384
|
-
* * Checks if a string is in camelCase format.
|
|
385
|
-
* @param str The string to check.
|
|
386
|
-
* @returns `true` if the string is in camelCase, otherwise `false`.
|
|
387
|
-
*/
|
|
388
|
-
function isCamelCase(str) {
|
|
389
|
-
return /^[a-z]+([A-Z][a-z]*)*$/.test(str);
|
|
390
|
-
}
|
|
391
|
-
/**
|
|
392
|
-
* * Checks if a string is in PascalCase format.
|
|
393
|
-
* @param str The string to check.
|
|
394
|
-
* @returns `true` if the string is in PascalCase, otherwise `false`.
|
|
395
|
-
*/
|
|
396
|
-
function isPascalCase(str) {
|
|
397
|
-
return /^[A-Z][a-zA-Z]*$/.test(str);
|
|
398
|
-
}
|
|
399
|
-
/**
|
|
400
|
-
* * Checks if a string is in snake_case format.
|
|
401
|
-
* @param str The string to check.
|
|
402
|
-
* @returns `true` if the string is in snake_case, otherwise `false`.
|
|
403
|
-
*/
|
|
404
|
-
function isSnakeCase(str) {
|
|
405
|
-
return /^[a-z]+(_[a-z]+)*$/.test(str);
|
|
406
|
-
}
|
|
407
|
-
/**
|
|
408
|
-
* * Checks if a string is in kebab-case format.
|
|
409
|
-
* @param str The string to check.
|
|
410
|
-
* @returns `true` if the string is in kebab-case, otherwise `false`.
|
|
411
|
-
*/
|
|
412
|
-
function isKebabCase(str) {
|
|
413
|
-
return /^[a-z]+(-[a-z]+)*$/.test(str);
|
|
414
|
-
}
|
|
415
|
-
/**
|
|
416
|
-
* * Checks if a string contains only emojis.
|
|
417
|
-
* @param str The string to check.
|
|
418
|
-
* @returns `true` if the string contains only emojis, otherwise `false`.
|
|
419
|
-
*/
|
|
420
|
-
function isEmojiOnly(str) {
|
|
421
|
-
return /^[\p{Emoji}]+$/u.test(str);
|
|
422
|
-
}
|
|
423
|
-
|
|
424
424
|
//#endregion
|
|
425
425
|
Object.defineProperty(exports, 'areInvalidNumbers', {
|
|
426
426
|
enumerable: true,
|
|
@@ -15,12 +15,12 @@
|
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
17
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
18
|
-
const require_primitives = require('
|
|
19
|
-
const
|
|
20
|
-
const
|
|
21
|
-
const
|
|
22
|
-
const
|
|
23
|
-
const
|
|
18
|
+
const require_primitives = require('../primitives-CBGICrDR.cjs');
|
|
19
|
+
const require_constants = require('../constants-BOs8tjzp.cjs');
|
|
20
|
+
const require_css_colors = require('../css-colors-DC7oZ46Y.cjs');
|
|
21
|
+
const require_utilities = require('../utilities-_COSGq1U.cjs');
|
|
22
|
+
const require_guards = require('../guards-CrfVwk0-.cjs');
|
|
23
|
+
const require_convert = require('../convert-BjKz_hhr.cjs');
|
|
24
24
|
|
|
25
25
|
//#region src/colors/random.ts
|
|
26
26
|
/** Track previously generated colors. */
|
|
@@ -14,8 +14,8 @@
|
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
|
-
import { er as Percent } from "
|
|
18
|
-
import { C as RandomColorOptions, S as RandomColor, T as SolidValues, _ as Hex, a as AlphaValues, b as RGB, g as HSLA, h as HSL, l as ColorInputArray, n as $ColorType, t as Color, v as Hex6, x as RGBA, y as Hex8 } from "
|
|
17
|
+
import { er as Percent } from "../object-DyVg8BFt.cjs";
|
|
18
|
+
import { C as RandomColorOptions, S as RandomColor, T as SolidValues, _ as Hex, a as AlphaValues, b as RGB, g as HSLA, h as HSL, l as ColorInputArray, n as $ColorType, t as Color, v as Hex6, x as RGBA, y as Hex8 } from "../Color-SUPeP6fO.cjs";
|
|
19
19
|
|
|
20
20
|
//#region src/colors/convert.d.ts
|
|
21
21
|
/**
|
|
@@ -14,8 +14,8 @@
|
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
|
-
import { er as Percent } from "
|
|
18
|
-
import { C as RandomColorOptions, S as RandomColor, T as SolidValues, _ as Hex, a as AlphaValues, b as RGB, g as HSLA, h as HSL, l as ColorInputArray, n as $ColorType, t as Color, v as Hex6, x as RGBA, y as Hex8 } from "
|
|
17
|
+
import { er as Percent } from "../object-DyVg8BFt.mjs";
|
|
18
|
+
import { C as RandomColorOptions, S as RandomColor, T as SolidValues, _ as Hex, a as AlphaValues, b as RGB, g as HSLA, h as HSL, l as ColorInputArray, n as $ColorType, t as Color, v as Hex6, x as RGBA, y as Hex8 } from "../Color-D6qMZgDm.mjs";
|
|
19
19
|
|
|
20
20
|
//#region src/colors/convert.d.ts
|
|
21
21
|
/**
|
|
@@ -14,12 +14,12 @@
|
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
|
-
import { a as isNonEmptyString, c as isNumber, d as isString } from "
|
|
18
|
-
import { t as
|
|
19
|
-
import {
|
|
20
|
-
import {
|
|
21
|
-
import {
|
|
22
|
-
import { n as
|
|
17
|
+
import { a as isNonEmptyString, c as isNumber, d as isString } from "../primitives-Djsevc69.mjs";
|
|
18
|
+
import { n as NUMBER_COLOR_PALETTE, t as ALPHABET_COLOR_PALETTE } from "../constants-DCZL77t-.mjs";
|
|
19
|
+
import { t as CSS_COLORS } from "../css-colors-B-y4TmeC.mjs";
|
|
20
|
+
import { t as clampNumber } from "../utilities-CmPwOkdy.mjs";
|
|
21
|
+
import { c as _applyOpacity, l as _generateRandomHSL, n as isHSL, o as isRGB, r as isHSLA, s as isRGBA, u as _isSimilarToLast } from "../guards-CNG9gnvL.mjs";
|
|
22
|
+
import { _ as extractSolidColorValues, a as convertHexToRgb, c as convertHslaToHex8, d as convertRgbToHsl, f as convertRgbToRgba, g as extractAlphaColorValues, h as applyOpacityToHex, i as convertHexToHsl, l as convertHslaToRgba, m as convertRgbaToHsla, n as convertHex8ToHsla, o as convertHslToHex, p as convertRgbaToHex8, r as convertHex8ToRgba, s as convertHslToRgb, t as convertColorCode, u as convertRgbToHex, v as percentToHex } from "../convert-DRZXcjcS.mjs";
|
|
23
23
|
|
|
24
24
|
//#region src/colors/random.ts
|
|
25
25
|
/** Track previously generated colors. */
|
package/dist/constants.cjs
CHANGED
|
@@ -16,11 +16,11 @@
|
|
|
16
16
|
|
|
17
17
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
18
18
|
const require_constants = require('./constants-D_HkIg02.cjs');
|
|
19
|
-
const
|
|
20
|
-
const require_constants$1 = require('./constants-B3nc8psr.cjs');
|
|
21
|
-
const require_constants$2 = require('./constants-BOs8tjzp.cjs');
|
|
22
|
-
const require_constants$3 = require('./constants-CgFaV72Z.cjs');
|
|
19
|
+
const require_constants$1 = require('./constants-CgFaV72Z.cjs');
|
|
23
20
|
const require_timezone = require('./timezone-CSz7R0L6.cjs');
|
|
21
|
+
const require_constants$2 = require('./constants-BOs8tjzp.cjs');
|
|
22
|
+
const require_css_colors = require('./css-colors-DC7oZ46Y.cjs');
|
|
23
|
+
const require_constants$3 = require('./constants-B3nc8psr.cjs');
|
|
24
24
|
const require_constants$4 = require('./constants-DIBRCBIP.cjs');
|
|
25
25
|
const require_countries = require('./countries-C0x58zVg.cjs');
|
|
26
26
|
const require_constants$5 = require('./constants-ZnFGKd7G.cjs');
|
|
@@ -382,11 +382,11 @@ exports.BANGLADESH_SEASONS = BANGLADESH_SEASONS;
|
|
|
382
382
|
exports.CATEGORIZED_UNITS = require_constants$4.UNITS;
|
|
383
383
|
exports.COUNTRIES = require_countries.COUNTRIES;
|
|
384
384
|
exports.CSS_COLORS = require_css_colors.CSS_COLORS;
|
|
385
|
-
exports.CURRENCY_CODES = require_constants$
|
|
386
|
-
exports.CURRENCY_LOCALES = require_constants$
|
|
385
|
+
exports.CURRENCY_CODES = require_constants$3.CURRENCY_CODES;
|
|
386
|
+
exports.CURRENCY_LOCALES = require_constants$3.CURRENCY_LOCALES;
|
|
387
387
|
exports.ETHIOPIA_SEASONS = ETHIOPIA_SEASONS;
|
|
388
|
-
exports.FRANKFURTER_CURRENCIES = require_constants$
|
|
389
|
-
exports.GENERAL_UNITS = require_constants$
|
|
388
|
+
exports.FRANKFURTER_CURRENCIES = require_constants$3.FRANKFURTER_CURRENCIES;
|
|
389
|
+
exports.GENERAL_UNITS = require_constants$3.UNITS;
|
|
390
390
|
exports.HTTP_CODES = require_constants$5.HTTP_STATUS_CODES;
|
|
391
391
|
exports.HTTP_STATUS = require_constants$5.HTTP_STATUS_CODES;
|
|
392
392
|
exports.HTTP_STATUS_CODES = require_constants$5.HTTP_STATUS_CODES;
|
|
@@ -395,9 +395,9 @@ exports.INDIA_IMD_SEASONS = INDIA_IMD_SEASONS;
|
|
|
395
395
|
exports.INDIA_TAMIL_SEASONS = INDIA_TAMIL_SEASONS;
|
|
396
396
|
exports.INDIA_VEDIC_SEASONS = INDIA_VEDIC_SEASONS;
|
|
397
397
|
exports.JAPAN_SEASONS = JAPAN_SEASONS;
|
|
398
|
-
exports.LOCALE_CODES = require_constants$
|
|
398
|
+
exports.LOCALE_CODES = require_constants$3.LOCALE_CODES;
|
|
399
399
|
exports.LOWERCASED_WORDS = require_constants.LOWERCASE;
|
|
400
|
-
exports.MONTHS = require_constants$
|
|
400
|
+
exports.MONTHS = require_constants$1.MONTHS;
|
|
401
401
|
exports.NATIVE_TZ_IDS = require_timezone.NATIVE_TZ_IDS;
|
|
402
402
|
exports.NUMBER_COLOR_PALETTE = require_constants$2.NUMBER_COLOR_PALETTE;
|
|
403
403
|
exports.PHILIPPINES_SEASONS = PHILIPPINES_SEASONS;
|
|
@@ -409,7 +409,7 @@ exports.TIME_ZONE_IDS = require_timezone.TIME_ZONE_IDS;
|
|
|
409
409
|
exports.TIME_ZONE_LABELS = require_timezone.TIME_ZONE_LABELS;
|
|
410
410
|
exports.TZ_ABBREVIATIONS = require_timezone.TIME_ZONES;
|
|
411
411
|
exports.US_ACADEMIC_SEASONS = US_ACADEMIC_SEASONS;
|
|
412
|
-
exports.VEDIC_ZODIAC_SIGNS = require_constants$
|
|
413
|
-
exports.WEEK_DAYS = require_constants$
|
|
412
|
+
exports.VEDIC_ZODIAC_SIGNS = require_constants$1.VEDIC_ZODIAC_SIGNS;
|
|
413
|
+
exports.WEEK_DAYS = require_constants$1.DAYS;
|
|
414
414
|
exports.WESTERN_SEASONS = DEFAULT_SEASONS;
|
|
415
|
-
exports.WESTERN_ZODIAC_SIGNS = require_constants$
|
|
415
|
+
exports.WESTERN_ZODIAC_SIGNS = require_constants$1.WESTERN_ZODIAC_SIGNS;
|
package/dist/constants.mjs
CHANGED
|
@@ -15,11 +15,11 @@
|
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
17
|
import { t as LOWERCASE } from "./constants-B0zJiNqH.mjs";
|
|
18
|
-
import { t as CSS_COLORS } from "./css-colors-B-y4TmeC.mjs";
|
|
19
|
-
import { a as LOCALE_CODES, i as FRANKFURTER_CURRENCIES, n as CURRENCY_CODES, p as UNITS$1, r as CURRENCY_LOCALES } from "./constants-ZyfpysiQ.mjs";
|
|
20
|
-
import { n as NUMBER_COLOR_PALETTE, t as ALPHABET_COLOR_PALETTE } from "./constants-DCZL77t-.mjs";
|
|
21
18
|
import { c as WESTERN_ZODIAC_SIGNS, n as DAYS, r as MONTHS, s as VEDIC_ZODIAC_SIGNS } from "./constants-GZL_CT1W.mjs";
|
|
22
19
|
import { a as TIME_ZONE_IDS, i as TIME_ZONES_NATIVE, n as NATIVE_TZ_IDS, o as TIME_ZONE_LABELS, r as TIME_ZONES, t as IANA_TZ_IDS } from "./timezone-avZ4TvDx.mjs";
|
|
20
|
+
import { n as NUMBER_COLOR_PALETTE, t as ALPHABET_COLOR_PALETTE } from "./constants-DCZL77t-.mjs";
|
|
21
|
+
import { t as CSS_COLORS } from "./css-colors-B-y4TmeC.mjs";
|
|
22
|
+
import { a as LOCALE_CODES, i as FRANKFURTER_CURRENCIES, n as CURRENCY_CODES, p as UNITS$1, r as CURRENCY_LOCALES } from "./constants-ZyfpysiQ.mjs";
|
|
23
23
|
import { r as UNITS } from "./constants-ByLTHWQm.mjs";
|
|
24
24
|
import { t as COUNTRIES } from "./countries-CMxHxKiK.mjs";
|
|
25
25
|
import { t as HTTP_STATUS_CODES } from "./constants-BLAcLxOu.mjs";
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
17
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
18
|
-
const require_constants = require('
|
|
18
|
+
const require_constants = require('../constants-DIBRCBIP.cjs');
|
|
19
19
|
|
|
20
20
|
//#region src/converter/base.ts
|
|
21
21
|
/**
|
|
@@ -14,8 +14,8 @@
|
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
|
-
import { ct as Numeric } from "
|
|
18
|
-
import { C as $Length, S as $Mass, b as $Time, c as $Unit, f as Converted, t as $Area, w as $Data, x as $Temperature, y as $Volume } from "
|
|
17
|
+
import { ct as Numeric } from "../object-DyVg8BFt.cjs";
|
|
18
|
+
import { C as $Length, S as $Mass, b as $Time, c as $Unit, f as Converted, t as $Area, w as $Data, x as $Temperature, y as $Volume } from "../area-kW5kJaQq.cjs";
|
|
19
19
|
|
|
20
20
|
//#region src/converter/Converter.d.ts
|
|
21
21
|
/**
|
|
@@ -14,8 +14,8 @@
|
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
|
-
import { ct as Numeric } from "
|
|
18
|
-
import { C as $Length, S as $Mass, b as $Time, c as $Unit, f as Converted, t as $Area, w as $Data, x as $Temperature, y as $Volume } from "
|
|
17
|
+
import { ct as Numeric } from "../object-DyVg8BFt.mjs";
|
|
18
|
+
import { C as $Length, S as $Mass, b as $Time, c as $Unit, f as Converted, t as $Area, w as $Data, x as $Temperature, y as $Volume } from "../area-CaK6hFzW.mjs";
|
|
19
19
|
|
|
20
20
|
//#region src/converter/Converter.d.ts
|
|
21
21
|
/**
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
|
-
import { i as Y_TO_IES, n as IRREGULAR_PLURALS, r as UNITS, t as INVARIANT_UNITS } from "
|
|
17
|
+
import { i as Y_TO_IES, n as IRREGULAR_PLURALS, r as UNITS, t as INVARIANT_UNITS } from "../constants-ByLTHWQm.mjs";
|
|
18
18
|
|
|
19
19
|
//#region src/converter/base.ts
|
|
20
20
|
/**
|