toolbox-x 1.2.0 → 2.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/dist/{Color-Dsut0Bex.d.cts → Color-B8MR8Vp0.d.cts} +1 -1
- package/dist/{Color-DCfoQk_-.d.mts → Color-D2MfZx7L.d.mts} +1 -1
- package/dist/{Stylog-DXZtHAbp.d.mts → Stylog-CSbLtqrZ.d.mts} +5 -5
- package/dist/{Stylog-TyLCTRtT.d.cts → Stylog-DF0CWtZb.d.cts} +5 -5
- package/dist/{area-CvSC96va.d.mts → area-C4tDXnGC.d.mts} +3 -3
- package/dist/{area-CcRQ6TfR.d.cts → area-CMJZ0gVm.d.cts} +3 -3
- package/dist/{array-B6jWzJ4F.d.mts → array-26Vs2HCs.d.mts} +1 -1
- package/dist/{array-CqDu610k.d.cts → array-DJAq9Qj8.d.cts} +1 -1
- package/dist/{basics-K8BDSYD6.cjs → basics-CJmdhXoo.cjs} +567 -14
- package/dist/{basics-1_M7UvCn.mjs → basics-CebgkY-n.mjs} +449 -16
- package/dist/{basics-KobRNhV-.d.cts → basics-Cis9Ej6c.d.mts} +5 -5
- package/dist/{basics-V5M2oltn.d.mts → basics-D4yU0NQ_.d.cts} +5 -5
- package/dist/{case-uKFzt5TY.cjs → case-Bd7QLHYw.cjs} +3 -3
- package/dist/{case-KdrBKjjK.d.mts → case-ChRzRBnY.d.mts} +12 -12
- package/dist/{case-BQwn5N-k.mjs → case-DBC4Rj0h.mjs} +3 -3
- package/dist/{case--Vjea9DS.d.cts → case-DkYSKSeV.d.cts} +12 -12
- package/dist/change-case.cjs +1 -1
- package/dist/change-case.d.cts +1 -1
- package/dist/change-case.d.mts +1 -1
- package/dist/change-case.mjs +1 -1
- package/dist/colors.d.cts +2 -2
- package/dist/colors.d.mts +2 -2
- package/dist/constants.d.cts +1 -1
- package/dist/constants.d.mts +1 -1
- package/dist/converter.cjs +2 -2
- package/dist/converter.d.cts +2 -2
- package/dist/converter.d.mts +2 -2
- package/dist/converter.mjs +2 -2
- package/dist/date.cjs +10 -10
- package/dist/date.d.cts +4 -4
- package/dist/date.d.mts +4 -4
- package/dist/date.mjs +10 -10
- package/dist/dom.cjs +5 -6
- package/dist/dom.d.cts +3 -3
- package/dist/dom.d.mts +3 -3
- package/dist/dom.mjs +4 -5
- package/dist/{form-DoQGMTOc.d.mts → form-Cp1OyCRI.d.cts} +2 -2
- package/dist/{form-mP-nl8EC.d.cts → form-DPdS2AhM.d.mts} +2 -2
- package/dist/guards-B2s2wlVN.mjs +425 -0
- package/dist/{guards-Cp6KAkVI.mjs → guards-BK1QuvFZ.mjs} +3 -3
- package/dist/{guards-DP5k4_Mm.cjs → guards-Bsh6Bfdq.cjs} +3 -3
- package/dist/{guards-0VjySrPM.cjs → guards-DMJcjPDt.cjs} +279 -3
- package/dist/guards.cjs +9 -9
- package/dist/guards.d.cts +6 -5
- package/dist/guards.d.mts +6 -5
- package/dist/guards.mjs +5 -5
- package/dist/{hash-BcoFHSu1.d.cts → hash-DfhOK0Fi.d.mts} +1 -1
- package/dist/{hash-GYRx2ee_.d.mts → hash-IdZN0mIe.d.cts} +1 -1
- package/dist/hash.cjs +8 -8
- package/dist/hash.d.cts +8 -8
- package/dist/hash.d.mts +8 -8
- package/dist/hash.mjs +4 -5
- package/dist/{http-status-xrlR-LlB.d.mts → http-status-B-yBZr-J.d.mts} +1 -1
- package/dist/{http-status-C0DOpCDf.d.cts → http-status-Dq_hoSG6.d.cts} +1 -1
- package/dist/http-status.cjs +4 -4
- package/dist/http-status.d.cts +6 -6
- package/dist/http-status.d.mts +6 -6
- package/dist/http-status.mjs +4 -4
- package/dist/index-C5FoCCbF.d.cts +292 -0
- package/dist/index-CIJWxnDS.d.mts +292 -0
- package/dist/index.cjs +67 -248
- package/dist/index.d.cts +25 -280
- package/dist/index.d.mts +25 -280
- package/dist/index.mjs +11 -194
- package/dist/{object-ChFVh95z.d.cts → object-X5fSMx-I.d.cts} +13 -1
- package/dist/{object-ChFVh95z.d.mts → object-X5fSMx-I.d.mts} +13 -1
- package/dist/{objectify-CfXtS_E0.mjs → objectify-CQa8gQib.mjs} +3 -4
- package/dist/{objectify-CZJr9hwg.cjs → objectify-xQvZS3UI.cjs} +5 -6
- package/dist/paginator.d.cts +1 -1
- package/dist/paginator.d.mts +1 -1
- package/dist/{parse-BpUlILVi.cjs → parse-DT7jbWx7.cjs} +5 -5
- package/dist/{parse-rcJRAOJl.mjs → parse-erxBG2hd.mjs} +5 -5
- package/dist/{pluralizer-CdG-VJ6t.d.cts → pluralizer-B8vuljyy.d.cts} +1 -1
- package/dist/{pluralizer-D2Lh8CdU.d.mts → pluralizer-DOdDskzF.d.mts} +1 -1
- package/dist/pluralizer.cjs +6 -6
- package/dist/pluralizer.d.cts +6 -6
- package/dist/pluralizer.d.mts +6 -6
- package/dist/pluralizer.mjs +6 -6
- package/dist/{specials-Cye93-uo.mjs → specials-Hq5Ncd6y.mjs} +2 -2
- package/dist/{specials-BM6cx43o.cjs → specials-dkYP1Nh2.cjs} +2 -2
- package/dist/{string-CkwTVFeL.d.mts → string-C51m7T6d.d.mts} +4 -2
- package/dist/{string-Dq2b8rcN.d.cts → string-CO7HP50i.d.cts} +4 -2
- package/dist/stylog.cjs +5 -5
- package/dist/stylog.d.cts +2 -2
- package/dist/stylog.d.mts +2 -2
- package/dist/stylog.mjs +5 -5
- package/dist/types/array.d.cts +1 -1
- package/dist/types/array.d.mts +1 -1
- package/dist/types/colors.d.cts +1 -1
- package/dist/types/colors.d.mts +1 -1
- package/dist/types/converter.d.cts +1 -1
- package/dist/types/converter.d.mts +1 -1
- package/dist/types/date.d.cts +1 -1
- package/dist/types/date.d.mts +1 -1
- package/dist/types/form.d.cts +1 -1
- package/dist/types/form.d.mts +1 -1
- package/dist/types/hash.d.cts +1 -1
- package/dist/types/hash.d.mts +1 -1
- package/dist/types/http-status.d.cts +1 -1
- package/dist/types/http-status.d.mts +1 -1
- package/dist/types/index.d.cts +2 -2
- package/dist/types/index.d.mts +2 -2
- package/dist/types/number.d.cts +1 -1
- package/dist/types/number.d.mts +1 -1
- package/dist/types/object.d.cts +2 -2
- package/dist/types/object.d.mts +2 -2
- package/dist/types/pluralizer.d.cts +1 -1
- package/dist/types/pluralizer.d.mts +1 -1
- package/dist/types/string.d.cts +2 -2
- package/dist/types/string.d.mts +2 -2
- package/dist/types/stylog.d.cts +1 -1
- package/dist/types/stylog.d.mts +1 -1
- package/dist/types/utils.d.cts +1 -1
- package/dist/types/utils.d.mts +1 -1
- package/dist/{utilities-CzyXCRHM.cjs → utilities-CWV1GPGY.cjs} +1 -1
- package/dist/{utilities-B9axOvOX.mjs → utilities-DPscNbS1.mjs} +1 -1
- package/dist/{uuid-DgTBxcVu.d.cts → uuid-BUI3Jt8n.d.cts} +3 -3
- package/dist/{uuid-Yc3Uu8qr.d.mts → uuid-mEiy14sf.d.mts} +3 -3
- package/dist/verbalizer.cjs +3 -3
- package/dist/verbalizer.d.cts +3 -3
- package/dist/verbalizer.d.mts +3 -3
- package/dist/verbalizer.mjs +3 -3
- package/package.json +7 -6
- package/dist/guards-DeO4ukiK.mjs +0 -221
- package/dist/utils-CFyEFj2Y.cjs +0 -568
- package/dist/utils-CN3ocK98.mjs +0 -449
package/dist/guards-DeO4ukiK.mjs
DELETED
|
@@ -1,221 +0,0 @@
|
|
|
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 { d as isString, m as isUndefined } from "./primitives-Djsevc69.mjs";
|
|
18
|
-
import { a as normalizeNumber } from "./utilities-B9axOvOX.mjs";
|
|
19
|
-
import { n as trimString } from "./basics-1_M7UvCn.mjs";
|
|
20
|
-
|
|
21
|
-
//#region src/number/guards.ts
|
|
22
|
-
/**
|
|
23
|
-
* * Check if a number is even or not.
|
|
24
|
-
*
|
|
25
|
-
* @param input The number or numeric string to check.
|
|
26
|
-
* @returns Boolean: `true` if even and `false` if not even.
|
|
27
|
-
*/
|
|
28
|
-
const isEven = (input) => {
|
|
29
|
-
const parsed = normalizeNumber(input);
|
|
30
|
-
if (isUndefined(parsed)) return false;
|
|
31
|
-
return parsed % 2 === 0;
|
|
32
|
-
};
|
|
33
|
-
/**
|
|
34
|
-
* * Checks if a number is odd or not.
|
|
35
|
-
*
|
|
36
|
-
* @param input The number or numeric string to check.
|
|
37
|
-
* @returns Boolean: `true` if odd and `false` if not odd.
|
|
38
|
-
*/
|
|
39
|
-
const isOdd = (input) => {
|
|
40
|
-
const parsed = normalizeNumber(input);
|
|
41
|
-
if (isUndefined(parsed)) return false;
|
|
42
|
-
return parsed % 2 !== 0;
|
|
43
|
-
};
|
|
44
|
-
/**
|
|
45
|
-
* * Checks if a number is a multiple of another number.
|
|
46
|
-
*
|
|
47
|
-
* @param input - The number to check.
|
|
48
|
-
* @param multipleOf - The number to check against.
|
|
49
|
-
* @returns `true` if `input` is a multiple of `multipleOf`, otherwise `false`.
|
|
50
|
-
*/
|
|
51
|
-
const isMultiple = (input, multipleOf) => {
|
|
52
|
-
return input % multipleOf === 0;
|
|
53
|
-
};
|
|
54
|
-
/**
|
|
55
|
-
* * Checks if a number is a perfect square.
|
|
56
|
-
*
|
|
57
|
-
* @param num The number to check.
|
|
58
|
-
* @returns `true` if the number is a perfect square, otherwise `false`.
|
|
59
|
-
*/
|
|
60
|
-
function isPerfectSquare(num) {
|
|
61
|
-
return Number.isInteger(Math.sqrt(num));
|
|
62
|
-
}
|
|
63
|
-
/**
|
|
64
|
-
* * Checks if a number is part of the Fibonacci sequence.
|
|
65
|
-
*
|
|
66
|
-
* @param num The number to check.
|
|
67
|
-
* @returns `true` if the number is a Fibonacci number, otherwise `false`.
|
|
68
|
-
*/
|
|
69
|
-
function isFibonacci(num) {
|
|
70
|
-
return isPerfectSquare(5 * num * num + 4) || isPerfectSquare(5 * num * num - 4);
|
|
71
|
-
}
|
|
72
|
-
/**
|
|
73
|
-
* * Checks whether any input is not a finite number.
|
|
74
|
-
*
|
|
75
|
-
* @param numbers - The list of numbers to validate.
|
|
76
|
-
* @returns `true` if any input is not finite.
|
|
77
|
-
*/
|
|
78
|
-
function areInvalidNumbers(...numbers) {
|
|
79
|
-
return numbers?.some((n) => !Number.isFinite(n));
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
//#endregion
|
|
83
|
-
//#region src/string/convert.ts
|
|
84
|
-
/**
|
|
85
|
-
* * Replaces all occurrences of a string or pattern in the given input string.
|
|
86
|
-
*
|
|
87
|
-
* - If `find` is a string, it is converted into a global regular expression (`/find/g`).
|
|
88
|
-
* - If `find` is a `RegExp`, the global (`g`) flag is ensured.
|
|
89
|
-
* - Trims the input before performing replacements.
|
|
90
|
-
*
|
|
91
|
-
* @param input - The string in which replacements should be performed.
|
|
92
|
-
* @param find - The substring or regex pattern to search for.
|
|
93
|
-
* @param replace - The string to replace matches with.
|
|
94
|
-
* @returns The modified/refined string with replacements applied.
|
|
95
|
-
*/
|
|
96
|
-
const replaceAllInString = (input, find, replace) => {
|
|
97
|
-
const trimmedString = trimString(input);
|
|
98
|
-
const regex = isString(find) ? new RegExp(find, "g") : new RegExp(find, find?.flags.includes("g") ? find?.flags : find?.flags + "g");
|
|
99
|
-
return trimmedString?.replace(regex, replace);
|
|
100
|
-
};
|
|
101
|
-
/**
|
|
102
|
-
* * Converts a string into a URL-friendly slug.
|
|
103
|
-
* @param input - The string to be converted.
|
|
104
|
-
* @returns The slugified string.
|
|
105
|
-
*/
|
|
106
|
-
const slugifyString = (input) => {
|
|
107
|
-
return trimString(normalizeString(input))?.toLowerCase()?.replace(/[^a-z0-9]+/g, "-")?.replace(/^-+|-+$/g, "");
|
|
108
|
-
};
|
|
109
|
-
/**
|
|
110
|
-
* * Masks part of a string for privacy.
|
|
111
|
-
* @param input - The string to mask.
|
|
112
|
-
* @param options - Options for masking a string.
|
|
113
|
-
* @returns The masked string.
|
|
114
|
-
*/
|
|
115
|
-
const maskString = (input, options) => {
|
|
116
|
-
const { start = 1, end = 1, maskCharacter: maskChar = "*" } = options || {};
|
|
117
|
-
const trimmedString = trimString(input);
|
|
118
|
-
if (trimmedString?.length <= start + end) return maskChar?.repeat(trimmedString?.length);
|
|
119
|
-
return trimmedString.slice(0, start) + maskChar?.repeat(trimmedString?.length - start - end) + (end > 0 ? trimmedString.slice(-end) : "");
|
|
120
|
-
};
|
|
121
|
-
/**
|
|
122
|
-
* * Reverses a given string.
|
|
123
|
-
* @param input - The string to reverse.
|
|
124
|
-
* @returns The reversed string.
|
|
125
|
-
*/
|
|
126
|
-
const reverseString = (input) => {
|
|
127
|
-
return trimString(input)?.split("")?.reverse()?.join("");
|
|
128
|
-
};
|
|
129
|
-
/**
|
|
130
|
-
* * Normalizes a string by removing diacritics (accents).
|
|
131
|
-
* @param str The input string.
|
|
132
|
-
* @returns The normalized string.
|
|
133
|
-
*/
|
|
134
|
-
function normalizeString(str) {
|
|
135
|
-
return str?.normalize("NFD")?.replace(/[\u0300-\u036f]/g, "");
|
|
136
|
-
}
|
|
137
|
-
/**
|
|
138
|
-
* * Extracts all email addresses from a string.
|
|
139
|
-
* @param str The input string.
|
|
140
|
-
* @returns An array of extracted email addresses.
|
|
141
|
-
*/
|
|
142
|
-
function extractEmails(str) {
|
|
143
|
-
return str?.match(/[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}/g) || [];
|
|
144
|
-
}
|
|
145
|
-
/**
|
|
146
|
-
* * Extracts all URLs from a string.
|
|
147
|
-
* @param str The input string.
|
|
148
|
-
* @returns An array of extracted URLs.
|
|
149
|
-
*/
|
|
150
|
-
function extractURLs(str) {
|
|
151
|
-
return str?.match(/https?:\/\/[^\s/$.?#].[^\s]*/g) || [];
|
|
152
|
-
}
|
|
153
|
-
/**
|
|
154
|
-
* * Returns a grammatically correct unit string, optionally prefixed with the number.
|
|
155
|
-
*
|
|
156
|
-
* @remarks For complex and versatile pluralization, please refer to {@link https://toolbox-x.nazmul-nhb.dev/docs/utilities/string/pluralizer pluralizer} or {@link https://toolbox-x.nazmul-nhb.dev/docs/classes/Pluralizer Pluralizer Class} instead.
|
|
157
|
-
*
|
|
158
|
-
* @param count The numeric value to determine singular or plural.
|
|
159
|
-
* @param unit The unit name (e.g., "day", "hour").
|
|
160
|
-
* @param withNumber Whether to prefix the count before the unit. Defaults to `true`.
|
|
161
|
-
* @returns Formatted unit string like `"1 day"`, `"2 months"`, or `"hour"`.
|
|
162
|
-
*/
|
|
163
|
-
function formatUnitWithPlural(count, unit, withNumber = true) {
|
|
164
|
-
const pluralized = Math.abs(count) === 1 ? unit : `${unit}s`;
|
|
165
|
-
return withNumber ? `${count} ${pluralized}` : pluralized;
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
//#endregion
|
|
169
|
-
//#region src/string/guards.ts
|
|
170
|
-
/**
|
|
171
|
-
* * Checks if a string is a palindrome.
|
|
172
|
-
* @param input - The string to check.
|
|
173
|
-
* @returns True if the string is a palindrome, otherwise false.
|
|
174
|
-
*/
|
|
175
|
-
const isPalindrome = (input) => {
|
|
176
|
-
const normalized = input.toLowerCase().replace(/[^a-z0-9]/g, "");
|
|
177
|
-
return normalized === reverseString(normalized);
|
|
178
|
-
};
|
|
179
|
-
/**
|
|
180
|
-
* * Checks if a string is in camelCase format.
|
|
181
|
-
* @param str The string to check.
|
|
182
|
-
* @returns `true` if the string is in camelCase, otherwise `false`.
|
|
183
|
-
*/
|
|
184
|
-
function isCamelCase(str) {
|
|
185
|
-
return /^[a-z]+([A-Z][a-z]*)*$/.test(str);
|
|
186
|
-
}
|
|
187
|
-
/**
|
|
188
|
-
* * Checks if a string is in PascalCase format.
|
|
189
|
-
* @param str The string to check.
|
|
190
|
-
* @returns `true` if the string is in PascalCase, otherwise `false`.
|
|
191
|
-
*/
|
|
192
|
-
function isPascalCase(str) {
|
|
193
|
-
return /^[A-Z][a-zA-Z]*$/.test(str);
|
|
194
|
-
}
|
|
195
|
-
/**
|
|
196
|
-
* * Checks if a string is in snake_case format.
|
|
197
|
-
* @param str The string to check.
|
|
198
|
-
* @returns `true` if the string is in snake_case, otherwise `false`.
|
|
199
|
-
*/
|
|
200
|
-
function isSnakeCase(str) {
|
|
201
|
-
return /^[a-z]+(_[a-z]+)*$/.test(str);
|
|
202
|
-
}
|
|
203
|
-
/**
|
|
204
|
-
* * Checks if a string is in kebab-case format.
|
|
205
|
-
* @param str The string to check.
|
|
206
|
-
* @returns `true` if the string is in kebab-case, otherwise `false`.
|
|
207
|
-
*/
|
|
208
|
-
function isKebabCase(str) {
|
|
209
|
-
return /^[a-z]+(-[a-z]+)*$/.test(str);
|
|
210
|
-
}
|
|
211
|
-
/**
|
|
212
|
-
* * Checks if a string contains only emojis.
|
|
213
|
-
* @param str The string to check.
|
|
214
|
-
* @returns `true` if the string contains only emojis, otherwise `false`.
|
|
215
|
-
*/
|
|
216
|
-
function isEmojiOnly(str) {
|
|
217
|
-
return /^[\p{Emoji}]+$/u.test(str);
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
//#endregion
|
|
221
|
-
export { isFibonacci as _, isPascalCase as a, isPerfectSquare as b, extractURLs as c, normalizeString as d, replaceAllInString as f, isEven as g, areInvalidNumbers as h, isPalindrome as i, formatUnitWithPlural as l, slugifyString as m, isEmojiOnly as n, isSnakeCase as o, reverseString as p, isKebabCase as r, extractEmails as s, isCamelCase as t, maskString as u, isMultiple as v, isOdd as y };
|