@catbee/utils 1.0.5 → 2.0.0-next.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 +1 -1
- package/README.md +27 -27
- package/array/array.utils.d.ts +191 -0
- package/array/index.cjs +246 -0
- package/array/index.d.ts +25 -0
- package/array/index.mjs +228 -0
- package/async/async.utils.d.ts +296 -0
- package/async/index.cjs +428 -0
- package/async/index.d.ts +25 -0
- package/async/index.mjs +407 -0
- package/cache/cache.utils.d.ts +176 -0
- package/cache/index.cjs +292 -0
- package/cache/index.d.ts +25 -0
- package/cache/index.mjs +290 -0
- package/config/config.d.ts +57 -0
- package/config/index.cjs +136 -0
- package/config/index.d.ts +26 -0
- package/config/index.mjs +131 -0
- package/context-store/context-store.utils.d.ts +212 -0
- package/context-store/index.cjs +267 -0
- package/context-store/index.d.ts +25 -0
- package/context-store/index.mjs +261 -0
- package/crypto/crypto.utils.d.ts +183 -0
- package/crypto/index.cjs +182 -0
- package/crypto/index.d.ts +25 -0
- package/crypto/index.mjs +166 -0
- package/date/date.utils.d.ts +190 -0
- package/date/index.cjs +295 -0
- package/date/index.d.ts +25 -0
- package/date/index.mjs +283 -0
- package/decorators/decorators.utils.d.ts +705 -0
- package/decorators/index.cjs +913 -0
- package/decorators/index.d.ts +25 -0
- package/decorators/index.mjs +872 -0
- package/dir/dir.utils.d.ts +216 -0
- package/dir/index.cjs +416 -0
- package/dir/index.d.ts +25 -0
- package/dir/index.mjs +389 -0
- package/env/env.utils.d.ts +400 -0
- package/env/index.cjs +761 -0
- package/env/index.d.ts +25 -0
- package/env/index.mjs +758 -0
- package/exception/exception.utils.d.ts +253 -0
- package/exception/index.cjs +362 -0
- package/exception/index.d.ts +25 -0
- package/exception/index.mjs +338 -0
- package/fs/fs.utils.d.ts +196 -0
- package/fs/index.cjs +253 -0
- package/fs/index.d.ts +25 -0
- package/fs/index.mjs +228 -0
- package/http-status-codes/http-status-codes.d.ts +289 -0
- package/http-status-codes/index.cjs +96 -0
- package/http-status-codes/index.d.ts +25 -0
- package/http-status-codes/index.mjs +94 -0
- package/id/id.utils.d.ts +59 -0
- package/id/index.cjs +62 -0
- package/id/index.d.ts +25 -0
- package/id/index.mjs +56 -0
- package/index.cjs +218 -0
- package/index.d.ts +51 -0
- package/index.mjs +51 -0
- package/logger/index.cjs +334 -0
- package/logger/index.d.ts +25 -0
- package/logger/index.mjs +313 -0
- package/logger/logger.utils.d.ts +210 -0
- package/middleware/index.cjs +177 -0
- package/middleware/index.d.ts +25 -0
- package/middleware/index.mjs +170 -0
- package/middleware/middleware.utils.d.ts +123 -0
- package/obj/index.cjs +317 -0
- package/obj/index.d.ts +25 -0
- package/obj/index.mjs +301 -0
- package/obj/obj.utils.d.ts +156 -0
- package/package.json +172 -20
- package/performance/index.cjs +231 -0
- package/performance/index.d.ts +25 -0
- package/performance/index.mjs +225 -0
- package/performance/performance.utils.d.ts +159 -0
- package/request/index.cjs +202 -0
- package/request/index.d.ts +26 -0
- package/request/index.mjs +194 -0
- package/request/request.utils.d.ts +109 -0
- package/response/index.cjs +234 -0
- package/response/index.d.ts +26 -0
- package/response/index.mjs +222 -0
- package/response/response.utils.d.ts +186 -0
- package/server/index.cjs +1627 -0
- package/server/index.d.ts +28 -0
- package/server/index.mjs +1617 -0
- package/server/server.builder.d.ts +531 -0
- package/server/server.d.ts +303 -0
- package/stream/index.cjs +151 -0
- package/stream/index.d.ts +25 -0
- package/stream/index.mjs +144 -0
- package/stream/stream.utils.d.ts +111 -0
- package/string/index.cjs +109 -0
- package/string/index.d.ts +25 -0
- package/string/index.mjs +95 -0
- package/string/string.utils.d.ts +124 -0
- package/type/index.cjs +129 -0
- package/type/index.d.ts +25 -0
- package/type/index.mjs +119 -0
- package/type/type.utils.d.ts +129 -0
- package/types/api-response.d.ts +175 -0
- package/types/common.d.ts +148 -0
- package/types/config.d.ts +88 -0
- package/types/index.cjs +34 -0
- package/types/index.d.ts +28 -0
- package/types/index.mjs +32 -0
- package/types/server.d.ts +291 -0
- package/url/index.cjs +201 -0
- package/url/index.d.ts +25 -0
- package/url/index.mjs +189 -0
- package/url/url.utils.d.ts +164 -0
- package/validate/index.cjs +212 -0
- package/validate/index.d.ts +25 -0
- package/validate/index.mjs +188 -0
- package/validate/validate.utils.d.ts +200 -0
- package/build/index.cjs +0 -7579
- package/build/index.d.ts +0 -5774
- package/build/index.mjs +0 -7274
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* The MIT License
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2025 Catbee Technologies. https://catbee.in/license
|
|
5
|
+
*
|
|
6
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
* in the Software without restriction, including without limitation the rights
|
|
9
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
* furnished to do so, subject to the following conditions:
|
|
12
|
+
*
|
|
13
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
* copies or substantial portions of the Software.
|
|
15
|
+
*
|
|
16
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
* SOFTWARE.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
var __defProp = Object.defineProperty;
|
|
26
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
27
|
+
|
|
28
|
+
// src/validate/validate.utils.ts
|
|
29
|
+
function isPort(value) {
|
|
30
|
+
const port = typeof value === "string" ? Number(value.trim()) : value;
|
|
31
|
+
return Number.isInteger(port) && port > 0 && port <= 65535;
|
|
32
|
+
}
|
|
33
|
+
__name(isPort, "isPort");
|
|
34
|
+
function isEmail(str) {
|
|
35
|
+
if (typeof str !== "string" || str.length > 254) return false;
|
|
36
|
+
const atIndex = str.indexOf("@");
|
|
37
|
+
if (atIndex === -1 || atIndex !== str.lastIndexOf("@")) return false;
|
|
38
|
+
const local = str.slice(0, atIndex);
|
|
39
|
+
const domain = str.slice(atIndex + 1);
|
|
40
|
+
if (!local || !domain) return false;
|
|
41
|
+
const dotAtom = /^[A-Za-z0-9!#$%&'*+/=?^_`{|}~-]+(\.[A-Za-z0-9!#$%&'*+/=?^_`{|}~-]+)*$/;
|
|
42
|
+
const quotedLocal = /^"([\s\x21\x23-\x5B\x5D-\x7E]|\\[\x20-\x7E])*"$/;
|
|
43
|
+
if (!dotAtom.test(local) && !quotedLocal.test(local)) return false;
|
|
44
|
+
if (domain.includes("..")) return false;
|
|
45
|
+
const labels = domain.split(".");
|
|
46
|
+
if (labels.some((l) => !l.length)) return false;
|
|
47
|
+
if (labels.length < 2) return false;
|
|
48
|
+
const labelRegex = /^[A-Za-z0-9-]{1,63}$/;
|
|
49
|
+
for (const label of labels) {
|
|
50
|
+
if (!labelRegex.test(label)) return false;
|
|
51
|
+
if (label.startsWith("-") || label.endsWith("-")) return false;
|
|
52
|
+
}
|
|
53
|
+
const tld = labels[labels.length - 1];
|
|
54
|
+
if (!/^[A-Za-z]{2,63}$/.test(tld)) return false;
|
|
55
|
+
return true;
|
|
56
|
+
}
|
|
57
|
+
__name(isEmail, "isEmail");
|
|
58
|
+
function isUUID(str) {
|
|
59
|
+
return /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(str);
|
|
60
|
+
}
|
|
61
|
+
__name(isUUID, "isUUID");
|
|
62
|
+
function isURL(str) {
|
|
63
|
+
try {
|
|
64
|
+
new URL(str);
|
|
65
|
+
return true;
|
|
66
|
+
} catch {
|
|
67
|
+
return false;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
__name(isURL, "isURL");
|
|
71
|
+
function isPhone(str) {
|
|
72
|
+
if (typeof str !== "string") return false;
|
|
73
|
+
const digitsOnly = str.replace(/\D/g, "");
|
|
74
|
+
if (digitsOnly.length < 6 || digitsOnly.length > 15) return false;
|
|
75
|
+
return /^[+]?[\d\s().-]+$/.test(str);
|
|
76
|
+
}
|
|
77
|
+
__name(isPhone, "isPhone");
|
|
78
|
+
function isAlphanumeric(str) {
|
|
79
|
+
return /^[a-z0-9]+$/i.test(str);
|
|
80
|
+
}
|
|
81
|
+
__name(isAlphanumeric, "isAlphanumeric");
|
|
82
|
+
function isNumeric(value) {
|
|
83
|
+
if (typeof value === "string" && value.trim() === "") return false;
|
|
84
|
+
const num = typeof value === "number" ? value : Number(value);
|
|
85
|
+
return typeof num === "number" && isFinite(num);
|
|
86
|
+
}
|
|
87
|
+
__name(isNumeric, "isNumeric");
|
|
88
|
+
function isHexColor(str) {
|
|
89
|
+
return /^#([a-f0-9]{6}|[a-f0-9]{3})$/i.test(str);
|
|
90
|
+
}
|
|
91
|
+
__name(isHexColor, "isHexColor");
|
|
92
|
+
function isISODate(str) {
|
|
93
|
+
const isoRegex = /^\d{4}-\d{2}-\d{2}(T\d{2}:\d{2}:\d{2}(\.\d+)?(Z|[+-]\d{2}:\d{2})?)?$/;
|
|
94
|
+
if (!isoRegex.test(str)) return false;
|
|
95
|
+
const date = new Date(str);
|
|
96
|
+
return !isNaN(date.getTime()) && date.toISOString().startsWith(str.slice(0, 10));
|
|
97
|
+
}
|
|
98
|
+
__name(isISODate, "isISODate");
|
|
99
|
+
function isLengthBetween(str, min, max) {
|
|
100
|
+
return str.length >= min && str.length <= max;
|
|
101
|
+
}
|
|
102
|
+
__name(isLengthBetween, "isLengthBetween");
|
|
103
|
+
function isNumberBetween(value, min, max) {
|
|
104
|
+
return value >= min && value <= max;
|
|
105
|
+
}
|
|
106
|
+
__name(isNumberBetween, "isNumberBetween");
|
|
107
|
+
function isAlpha(str) {
|
|
108
|
+
return /^[a-zA-Z]+$/.test(str);
|
|
109
|
+
}
|
|
110
|
+
__name(isAlpha, "isAlpha");
|
|
111
|
+
function isStrongPassword(str) {
|
|
112
|
+
if (str.length < 8) return false;
|
|
113
|
+
const hasUpperCase = /[A-Z]/.test(str);
|
|
114
|
+
const hasLowerCase = /[a-z]/.test(str);
|
|
115
|
+
const hasNumbers = /[0-9]/.test(str);
|
|
116
|
+
const hasSpecialChar = /[!@#$%^&*()_+\-=[\]{};':"\\|,.<>?]/.test(str);
|
|
117
|
+
return hasUpperCase && hasLowerCase && hasNumbers && hasSpecialChar;
|
|
118
|
+
}
|
|
119
|
+
__name(isStrongPassword, "isStrongPassword");
|
|
120
|
+
function isIPv4(str) {
|
|
121
|
+
const parts = str.split(".");
|
|
122
|
+
if (parts.length !== 4) return false;
|
|
123
|
+
return parts.every((part) => {
|
|
124
|
+
const num = parseInt(part, 10);
|
|
125
|
+
return part === num.toString() && num >= 0 && num <= 255;
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
__name(isIPv4, "isIPv4");
|
|
129
|
+
function isIPv6(str) {
|
|
130
|
+
return /^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]+|::(ffff(:0{1,4})?:)?((25[0-5]|(2[0-4]|1?[0-9])?[0-9])\.){3}(25[0-5]|(2[0-4]|1?[0-9])?[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1?[0-9])?[0-9])\.){3}(25[0-5]|(2[0-4]|1?[0-9])?[0-9]))$/.test(str);
|
|
131
|
+
}
|
|
132
|
+
__name(isIPv6, "isIPv6");
|
|
133
|
+
function isCreditCard(str) {
|
|
134
|
+
const cardNumber = str.replace(/\D/g, "");
|
|
135
|
+
if (cardNumber.length < 13 || cardNumber.length > 19) return false;
|
|
136
|
+
let sum = 0;
|
|
137
|
+
let shouldDouble = false;
|
|
138
|
+
for (let i = cardNumber.length - 1; i >= 0; i--) {
|
|
139
|
+
let digit = parseInt(cardNumber.charAt(i), 10);
|
|
140
|
+
if (shouldDouble) {
|
|
141
|
+
digit *= 2;
|
|
142
|
+
if (digit > 9) digit -= 9;
|
|
143
|
+
}
|
|
144
|
+
sum += digit;
|
|
145
|
+
shouldDouble = !shouldDouble;
|
|
146
|
+
}
|
|
147
|
+
return sum % 10 === 0;
|
|
148
|
+
}
|
|
149
|
+
__name(isCreditCard, "isCreditCard");
|
|
150
|
+
function isValidJSON(str) {
|
|
151
|
+
try {
|
|
152
|
+
JSON.parse(str);
|
|
153
|
+
return true;
|
|
154
|
+
} catch {
|
|
155
|
+
return false;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
__name(isValidJSON, "isValidJSON");
|
|
159
|
+
function isArray(value, itemGuard) {
|
|
160
|
+
if (!Array.isArray(value)) return false;
|
|
161
|
+
return !itemGuard || value.every((item) => itemGuard(item));
|
|
162
|
+
}
|
|
163
|
+
__name(isArray, "isArray");
|
|
164
|
+
function isBase64(str) {
|
|
165
|
+
return /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(str);
|
|
166
|
+
}
|
|
167
|
+
__name(isBase64, "isBase64");
|
|
168
|
+
function hasRequiredProps(obj, requiredProps) {
|
|
169
|
+
return requiredProps.every((prop) => Object.prototype.hasOwnProperty.call(obj, prop) && obj[prop] !== void 0 && obj[prop] !== null);
|
|
170
|
+
}
|
|
171
|
+
__name(hasRequiredProps, "hasRequiredProps");
|
|
172
|
+
function isDateInRange(date, minDate, maxDate) {
|
|
173
|
+
if (!(date instanceof Date) || isNaN(date.getTime())) return false;
|
|
174
|
+
if (minDate && date < minDate) return false;
|
|
175
|
+
if (maxDate && date > maxDate) return false;
|
|
176
|
+
return true;
|
|
177
|
+
}
|
|
178
|
+
__name(isDateInRange, "isDateInRange");
|
|
179
|
+
function matchesPattern(str, pattern) {
|
|
180
|
+
return pattern.test(str);
|
|
181
|
+
}
|
|
182
|
+
__name(matchesPattern, "matchesPattern");
|
|
183
|
+
function validateAll(value, validators) {
|
|
184
|
+
return validators.every((validator) => validator(value));
|
|
185
|
+
}
|
|
186
|
+
__name(validateAll, "validateAll");
|
|
187
|
+
|
|
188
|
+
export { hasRequiredProps, isAlpha, isAlphanumeric, isArray, isBase64, isCreditCard, isDateInRange, isEmail, isHexColor, isIPv4, isIPv6, isISODate, isLengthBetween, isNumberBetween, isNumeric, isPhone, isPort, isStrongPassword, isURL, isUUID, isValidJSON, matchesPattern, validateAll };
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* The MIT License
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2025 Catbee Technologies. https://catbee.in/license
|
|
5
|
+
*
|
|
6
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
* in the Software without restriction, including without limitation the rights
|
|
9
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
* furnished to do so, subject to the following conditions:
|
|
12
|
+
*
|
|
13
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
* copies or substantial portions of the Software.
|
|
15
|
+
*
|
|
16
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
* SOFTWARE.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Collection of common validation helpers for strings, numbers, email, UUID, etc.
|
|
27
|
+
*/
|
|
28
|
+
/**
|
|
29
|
+
* Checks if a string is a valid port number.
|
|
30
|
+
*
|
|
31
|
+
* @param str - The input string or number.
|
|
32
|
+
* @returns True if valid port number, else false.
|
|
33
|
+
*/
|
|
34
|
+
export declare function isPort(value: string | number): boolean;
|
|
35
|
+
/**
|
|
36
|
+
* Checks if a string is a valid email address.
|
|
37
|
+
*
|
|
38
|
+
* @param {string} str - The input string.
|
|
39
|
+
* @returns {boolean} True if valid email, else false.
|
|
40
|
+
*/
|
|
41
|
+
export declare function isEmail(str: string): boolean;
|
|
42
|
+
/**
|
|
43
|
+
* Checks if a string is a valid UUID (versions 1-5).
|
|
44
|
+
*
|
|
45
|
+
* @param {string} str - The input string.
|
|
46
|
+
* @returns {boolean} True if valid UUID, else false.
|
|
47
|
+
*/
|
|
48
|
+
export declare function isUUID(str: string): boolean;
|
|
49
|
+
/**
|
|
50
|
+
* Checks if a string is a valid URL.
|
|
51
|
+
*
|
|
52
|
+
* @param {string} str - The input string.
|
|
53
|
+
* @returns {boolean} True if valid URL, else false.
|
|
54
|
+
*/
|
|
55
|
+
export declare function isURL(str: string): boolean;
|
|
56
|
+
/**
|
|
57
|
+
* Checks if a string is a valid international phone number (E.164 or common patterns).
|
|
58
|
+
*
|
|
59
|
+
* @param {string} str - The input string.
|
|
60
|
+
* @returns {boolean} True if looks like a phone number.
|
|
61
|
+
*/
|
|
62
|
+
export declare function isPhone(str: string): boolean;
|
|
63
|
+
/**
|
|
64
|
+
* Checks if a string is strictly alphanumeric (letters/numbers only).
|
|
65
|
+
*
|
|
66
|
+
* @param {string} str - The input string.
|
|
67
|
+
* @returns {boolean} True if alphanumeric.
|
|
68
|
+
*/
|
|
69
|
+
export declare function isAlphanumeric(str: string): boolean;
|
|
70
|
+
/**
|
|
71
|
+
* Checks if a string or number can be safely parsed to a number.
|
|
72
|
+
*
|
|
73
|
+
* @param {string | number} value - The value to check.
|
|
74
|
+
* @returns {boolean} True if the value is numeric.
|
|
75
|
+
*/
|
|
76
|
+
export declare function isNumeric(value: string | number): boolean;
|
|
77
|
+
/**
|
|
78
|
+
* Checks if a string is a valid hex color code (e.g. #FFF or #FFFFFF).
|
|
79
|
+
*
|
|
80
|
+
* @param {string} str - Input string.
|
|
81
|
+
* @returns {boolean}
|
|
82
|
+
*/
|
|
83
|
+
export declare function isHexColor(str: string): boolean;
|
|
84
|
+
/**
|
|
85
|
+
* Checks if a string is a valid date string.
|
|
86
|
+
*
|
|
87
|
+
* @param {string} str - Input string.
|
|
88
|
+
* @returns {boolean}
|
|
89
|
+
*/
|
|
90
|
+
export declare function isISODate(str: string): boolean;
|
|
91
|
+
/**
|
|
92
|
+
* Checks if a string matches a specified length range.
|
|
93
|
+
*
|
|
94
|
+
* @param {string} str - The input string.
|
|
95
|
+
* @param {number} min - Minimum length (inclusive).
|
|
96
|
+
* @param {number} max - Maximum length (inclusive).
|
|
97
|
+
* @returns {boolean} True if string length is within range.
|
|
98
|
+
*/
|
|
99
|
+
export declare function isLengthBetween(str: string, min: number, max: number): boolean;
|
|
100
|
+
/**
|
|
101
|
+
* Validates that a number is between specified min and max values (inclusive).
|
|
102
|
+
*
|
|
103
|
+
* @param {number} value - The number to validate.
|
|
104
|
+
* @param {number} min - Minimum value.
|
|
105
|
+
* @param {number} max - Maximum value.
|
|
106
|
+
* @returns {boolean} True if number is within range.
|
|
107
|
+
*/
|
|
108
|
+
export declare function isNumberBetween(value: number, min: number, max: number): boolean;
|
|
109
|
+
/**
|
|
110
|
+
* Checks if a string contains only alphabetic characters.
|
|
111
|
+
*
|
|
112
|
+
* @param {string} str - The input string.
|
|
113
|
+
* @returns {boolean} True if alphabetic only.
|
|
114
|
+
*/
|
|
115
|
+
export declare function isAlpha(str: string): boolean;
|
|
116
|
+
/**
|
|
117
|
+
* Validates that a string contains at least one uppercase letter,
|
|
118
|
+
* one lowercase letter, one number, and one special character.
|
|
119
|
+
*
|
|
120
|
+
* @param {string} str - The input string.
|
|
121
|
+
* @returns {boolean} True if string meets password complexity requirements.
|
|
122
|
+
*/
|
|
123
|
+
export declare function isStrongPassword(str: string): boolean;
|
|
124
|
+
/**
|
|
125
|
+
* Checks if a string is a valid IPv4 address.
|
|
126
|
+
*
|
|
127
|
+
* @param {string} str - The input string.
|
|
128
|
+
* @returns {boolean} True if valid IPv4 address.
|
|
129
|
+
*/
|
|
130
|
+
export declare function isIPv4(str: string): boolean;
|
|
131
|
+
/**
|
|
132
|
+
* Checks if a string is a valid IPv6 address.
|
|
133
|
+
*
|
|
134
|
+
* @param {string} str - The input string.
|
|
135
|
+
* @returns {boolean} True if valid IPv6 address.
|
|
136
|
+
*/
|
|
137
|
+
export declare function isIPv6(str: string): boolean;
|
|
138
|
+
/**
|
|
139
|
+
* Validates a credit card number using the Luhn algorithm.
|
|
140
|
+
*
|
|
141
|
+
* @param {string} str - The credit card number string.
|
|
142
|
+
* @returns {boolean} True if valid credit card number.
|
|
143
|
+
*/
|
|
144
|
+
export declare function isCreditCard(str: string): boolean;
|
|
145
|
+
/**
|
|
146
|
+
* Checks if a string is a valid JSON.
|
|
147
|
+
*
|
|
148
|
+
* @param {string} str - The input string.
|
|
149
|
+
* @returns {boolean} True if valid JSON.
|
|
150
|
+
*/
|
|
151
|
+
export declare function isValidJSON(str: string): boolean;
|
|
152
|
+
/**
|
|
153
|
+
* Type guard that checks if a value is an array.
|
|
154
|
+
*
|
|
155
|
+
* @template T Optional expected element type
|
|
156
|
+
* @param {unknown} value - The value to check.
|
|
157
|
+
* @param {(item: unknown) => boolean} [itemGuard] - Optional function to validate each item.
|
|
158
|
+
* @returns {boolean} True if value is an array (with optional item validation).
|
|
159
|
+
*/
|
|
160
|
+
export declare function isArray<T = unknown>(value: unknown, itemGuard?: (item: unknown) => item is T): value is T[];
|
|
161
|
+
/**
|
|
162
|
+
* Checks if a string is a valid base64 encoded string.
|
|
163
|
+
*
|
|
164
|
+
* @param {string} str - The input string.
|
|
165
|
+
* @returns {boolean} True if valid base64.
|
|
166
|
+
*/
|
|
167
|
+
export declare function isBase64(str: string): boolean;
|
|
168
|
+
/**
|
|
169
|
+
* Validates that an object has all required properties.
|
|
170
|
+
*
|
|
171
|
+
* @param {object} obj - The object to validate.
|
|
172
|
+
* @param {string[]} requiredProps - Array of required property names.
|
|
173
|
+
* @returns {boolean} True if all required properties exist.
|
|
174
|
+
*/
|
|
175
|
+
export declare function hasRequiredProps(obj: Record<string, unknown>, requiredProps: string[]): boolean;
|
|
176
|
+
/**
|
|
177
|
+
* Validates a date is within a specified range.
|
|
178
|
+
*
|
|
179
|
+
* @param {Date} date - The date to validate.
|
|
180
|
+
* @param {Date} [minDate] - Optional minimum date (inclusive).
|
|
181
|
+
* @param {Date} [maxDate] - Optional maximum date (inclusive).
|
|
182
|
+
* @returns {boolean} True if date is within range.
|
|
183
|
+
*/
|
|
184
|
+
export declare function isDateInRange(date: Date, minDate?: Date, maxDate?: Date): boolean;
|
|
185
|
+
/**
|
|
186
|
+
* Validates a string matches a specific regular expression pattern.
|
|
187
|
+
*
|
|
188
|
+
* @param {string} str - The input string.
|
|
189
|
+
* @param {RegExp} pattern - Regular expression to test against.
|
|
190
|
+
* @returns {boolean} True if string matches pattern.
|
|
191
|
+
*/
|
|
192
|
+
export declare function matchesPattern(str: string, pattern: RegExp): boolean;
|
|
193
|
+
/**
|
|
194
|
+
* Validates data against multiple constraints.
|
|
195
|
+
*
|
|
196
|
+
* @param {unknown} value - The value to validate.
|
|
197
|
+
* @param {Array<(value: unknown) => boolean>} validators - Array of validation functions.
|
|
198
|
+
* @returns {boolean} True if value passes all validations.
|
|
199
|
+
*/
|
|
200
|
+
export declare function validateAll(value: unknown, validators: Array<(value: unknown) => boolean>): boolean;
|