@catbee/utils 0.0.8-rc.3 → 1.0.1
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/README.md +3 -2
- package/build/index.cjs +6912 -0
- package/build/index.d.ts +5284 -0
- package/build/index.mjs +6635 -0
- package/package.json +13 -292
- package/build/cjs/config.d.ts +0 -121
- package/build/cjs/config.js +0 -137
- package/build/cjs/index.d.ts +0 -26
- package/build/cjs/index.js +0 -68
- package/build/cjs/servers/server.builder.d.ts +0 -507
- package/build/cjs/servers/server.builder.js +0 -658
- package/build/cjs/servers/server.d.ts +0 -255
- package/build/cjs/servers/server.js +0 -970
- package/build/cjs/types/api-response.d.ts +0 -151
- package/build/cjs/types/api-response.js +0 -36
- package/build/cjs/types/index.d.ts +0 -124
- package/build/cjs/types/index.js +0 -25
- package/build/cjs/types/server.d.ts +0 -267
- package/build/cjs/types/server.js +0 -25
- package/build/cjs/utils/array.utils.d.ts +0 -167
- package/build/cjs/utils/array.utils.js +0 -363
- package/build/cjs/utils/async.utils.d.ts +0 -264
- package/build/cjs/utils/async.utils.js +0 -640
- package/build/cjs/utils/cache.utils.d.ts +0 -152
- package/build/cjs/utils/cache.utils.js +0 -298
- package/build/cjs/utils/context-store.utils.d.ts +0 -188
- package/build/cjs/utils/context-store.utils.js +0 -297
- package/build/cjs/utils/crypto.utils.d.ts +0 -159
- package/build/cjs/utils/crypto.utils.js +0 -295
- package/build/cjs/utils/date.utils.d.ts +0 -158
- package/build/cjs/utils/date.utils.js +0 -395
- package/build/cjs/utils/decorators.utils.d.ts +0 -511
- package/build/cjs/utils/decorators.utils.js +0 -1035
- package/build/cjs/utils/dir.utils.d.ts +0 -195
- package/build/cjs/utils/dir.utils.js +0 -500
- package/build/cjs/utils/env.utils.d.ts +0 -376
- package/build/cjs/utils/env.utils.js +0 -786
- package/build/cjs/utils/exception.utils.d.ts +0 -229
- package/build/cjs/utils/exception.utils.js +0 -408
- package/build/cjs/utils/fs.utils.d.ts +0 -163
- package/build/cjs/utils/fs.utils.js +0 -371
- package/build/cjs/utils/http-status-codes.d.ts +0 -265
- package/build/cjs/utils/http-status-codes.js +0 -297
- package/build/cjs/utils/id.utils.d.ts +0 -35
- package/build/cjs/utils/id.utils.js +0 -90
- package/build/cjs/utils/logger.utils.d.ts +0 -159
- package/build/cjs/utils/logger.utils.js +0 -350
- package/build/cjs/utils/middleware.utils.d.ts +0 -99
- package/build/cjs/utils/middleware.utils.js +0 -243
- package/build/cjs/utils/obj.utils.d.ts +0 -123
- package/build/cjs/utils/obj.utils.js +0 -428
- package/build/cjs/utils/performance.utils.d.ts +0 -135
- package/build/cjs/utils/performance.utils.js +0 -280
- package/build/cjs/utils/request.utils.d.ts +0 -85
- package/build/cjs/utils/request.utils.js +0 -199
- package/build/cjs/utils/response.utils.d.ts +0 -162
- package/build/cjs/utils/response.utils.js +0 -274
- package/build/cjs/utils/stream.utils.d.ts +0 -87
- package/build/cjs/utils/stream.utils.js +0 -217
- package/build/cjs/utils/string.utils.d.ts +0 -92
- package/build/cjs/utils/string.utils.js +0 -178
- package/build/cjs/utils/type.utils.d.ts +0 -89
- package/build/cjs/utils/type.utils.js +0 -195
- package/build/cjs/utils/url.utils.d.ts +0 -140
- package/build/cjs/utils/url.utils.js +0 -316
- package/build/cjs/utils/validate.utils.d.ts +0 -176
- package/build/cjs/utils/validate.utils.js +0 -344
- package/build/esm/config.d.ts +0 -121
- package/build/esm/config.js +0 -132
- package/build/esm/index.d.ts +0 -26
- package/build/esm/index.js +0 -49
- package/build/esm/servers/server.builder.d.ts +0 -507
- package/build/esm/servers/server.builder.js +0 -654
- package/build/esm/servers/server.d.ts +0 -255
- package/build/esm/servers/server.js +0 -963
- package/build/esm/types/api-response.d.ts +0 -151
- package/build/esm/types/api-response.js +0 -33
- package/build/esm/types/index.d.ts +0 -124
- package/build/esm/types/index.js +0 -24
- package/build/esm/types/server.d.ts +0 -267
- package/build/esm/types/server.js +0 -24
- package/build/esm/utils/array.utils.d.ts +0 -167
- package/build/esm/utils/array.utils.js +0 -344
- package/build/esm/utils/async.utils.d.ts +0 -264
- package/build/esm/utils/async.utils.js +0 -619
- package/build/esm/utils/cache.utils.d.ts +0 -152
- package/build/esm/utils/cache.utils.js +0 -294
- package/build/esm/utils/context-store.utils.d.ts +0 -188
- package/build/esm/utils/context-store.utils.js +0 -290
- package/build/esm/utils/crypto.utils.d.ts +0 -159
- package/build/esm/utils/crypto.utils.js +0 -278
- package/build/esm/utils/date.utils.d.ts +0 -158
- package/build/esm/utils/date.utils.js +0 -383
- package/build/esm/utils/decorators.utils.d.ts +0 -511
- package/build/esm/utils/decorators.utils.js +0 -1013
- package/build/esm/utils/dir.utils.d.ts +0 -195
- package/build/esm/utils/dir.utils.js +0 -476
- package/build/esm/utils/env.utils.d.ts +0 -376
- package/build/esm/utils/env.utils.js +0 -782
- package/build/esm/utils/exception.utils.d.ts +0 -229
- package/build/esm/utils/exception.utils.js +0 -382
- package/build/esm/utils/fs.utils.d.ts +0 -163
- package/build/esm/utils/fs.utils.js +0 -348
- package/build/esm/utils/http-status-codes.d.ts +0 -265
- package/build/esm/utils/http-status-codes.js +0 -294
- package/build/esm/utils/id.utils.d.ts +0 -35
- package/build/esm/utils/id.utils.js +0 -83
- package/build/esm/utils/logger.utils.d.ts +0 -159
- package/build/esm/utils/logger.utils.js +0 -304
- package/build/esm/utils/middleware.utils.d.ts +0 -99
- package/build/esm/utils/middleware.utils.js +0 -235
- package/build/esm/utils/obj.utils.d.ts +0 -123
- package/build/esm/utils/obj.utils.js +0 -412
- package/build/esm/utils/performance.utils.d.ts +0 -135
- package/build/esm/utils/performance.utils.js +0 -273
- package/build/esm/utils/request.utils.d.ts +0 -85
- package/build/esm/utils/request.utils.js +0 -190
- package/build/esm/utils/response.utils.d.ts +0 -162
- package/build/esm/utils/response.utils.js +0 -261
- package/build/esm/utils/stream.utils.d.ts +0 -87
- package/build/esm/utils/stream.utils.js +0 -209
- package/build/esm/utils/string.utils.d.ts +0 -92
- package/build/esm/utils/string.utils.js +0 -164
- package/build/esm/utils/type.utils.d.ts +0 -89
- package/build/esm/utils/type.utils.js +0 -186
- package/build/esm/utils/url.utils.d.ts +0 -140
- package/build/esm/utils/url.utils.js +0 -303
- package/build/esm/utils/validate.utils.d.ts +0 -176
- package/build/esm/utils/validate.utils.js +0 -319
|
@@ -1,176 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Collection of common validation helpers for strings, numbers, email, UUID, etc.
|
|
3
|
-
*/
|
|
4
|
-
/**
|
|
5
|
-
* Checks if a string is a valid port number.
|
|
6
|
-
*
|
|
7
|
-
* @param str - The input string or number.
|
|
8
|
-
* @returns True if valid port number, else false.
|
|
9
|
-
*/
|
|
10
|
-
export declare function isPort(value: string | number): boolean;
|
|
11
|
-
/**
|
|
12
|
-
* Checks if a string is a valid email address.
|
|
13
|
-
*
|
|
14
|
-
* @param {string} str - The input string.
|
|
15
|
-
* @returns {boolean} True if valid email, else false.
|
|
16
|
-
*/
|
|
17
|
-
export declare function isEmail(str: string): boolean;
|
|
18
|
-
/**
|
|
19
|
-
* Checks if a string is a valid UUID (versions 1-5).
|
|
20
|
-
*
|
|
21
|
-
* @param {string} str - The input string.
|
|
22
|
-
* @returns {boolean} True if valid UUID, else false.
|
|
23
|
-
*/
|
|
24
|
-
export declare function isUUID(str: string): boolean;
|
|
25
|
-
/**
|
|
26
|
-
* Checks if a string is a valid URL.
|
|
27
|
-
*
|
|
28
|
-
* @param {string} str - The input string.
|
|
29
|
-
* @returns {boolean} True if valid URL, else false.
|
|
30
|
-
*/
|
|
31
|
-
export declare function isURL(str: string): boolean;
|
|
32
|
-
/**
|
|
33
|
-
* Checks if a string is a valid international phone number (E.164 or common patterns).
|
|
34
|
-
*
|
|
35
|
-
* @param {string} str - The input string.
|
|
36
|
-
* @returns {boolean} True if looks like a phone number.
|
|
37
|
-
*/
|
|
38
|
-
export declare function isPhone(str: string): boolean;
|
|
39
|
-
/**
|
|
40
|
-
* Checks if a string is strictly alphanumeric (letters/numbers only).
|
|
41
|
-
*
|
|
42
|
-
* @param {string} str - The input string.
|
|
43
|
-
* @returns {boolean} True if alphanumeric.
|
|
44
|
-
*/
|
|
45
|
-
export declare function isAlphanumeric(str: string): boolean;
|
|
46
|
-
/**
|
|
47
|
-
* Checks if a string or number can be safely parsed to a number.
|
|
48
|
-
*
|
|
49
|
-
* @param {string | number} value - The value to check.
|
|
50
|
-
* @returns {boolean} True if the value is numeric.
|
|
51
|
-
*/
|
|
52
|
-
export declare function isNumeric(value: string | number): boolean;
|
|
53
|
-
/**
|
|
54
|
-
* Checks if a string is a valid hex color code (e.g. #FFF or #FFFFFF).
|
|
55
|
-
*
|
|
56
|
-
* @param {string} str - Input string.
|
|
57
|
-
* @returns {boolean}
|
|
58
|
-
*/
|
|
59
|
-
export declare function isHexColor(str: string): boolean;
|
|
60
|
-
/**
|
|
61
|
-
* Checks if a string is a valid date string.
|
|
62
|
-
*
|
|
63
|
-
* @param {string} str - Input string.
|
|
64
|
-
* @returns {boolean}
|
|
65
|
-
*/
|
|
66
|
-
export declare function isISODate(str: string): boolean;
|
|
67
|
-
/**
|
|
68
|
-
* Checks if a string matches a specified length range.
|
|
69
|
-
*
|
|
70
|
-
* @param {string} str - The input string.
|
|
71
|
-
* @param {number} min - Minimum length (inclusive).
|
|
72
|
-
* @param {number} max - Maximum length (inclusive).
|
|
73
|
-
* @returns {boolean} True if string length is within range.
|
|
74
|
-
*/
|
|
75
|
-
export declare function isLengthBetween(str: string, min: number, max: number): boolean;
|
|
76
|
-
/**
|
|
77
|
-
* Validates that a number is between specified min and max values (inclusive).
|
|
78
|
-
*
|
|
79
|
-
* @param {number} value - The number to validate.
|
|
80
|
-
* @param {number} min - Minimum value.
|
|
81
|
-
* @param {number} max - Maximum value.
|
|
82
|
-
* @returns {boolean} True if number is within range.
|
|
83
|
-
*/
|
|
84
|
-
export declare function isNumberBetween(value: number, min: number, max: number): boolean;
|
|
85
|
-
/**
|
|
86
|
-
* Checks if a string contains only alphabetic characters.
|
|
87
|
-
*
|
|
88
|
-
* @param {string} str - The input string.
|
|
89
|
-
* @returns {boolean} True if alphabetic only.
|
|
90
|
-
*/
|
|
91
|
-
export declare function isAlpha(str: string): boolean;
|
|
92
|
-
/**
|
|
93
|
-
* Validates that a string contains at least one uppercase letter,
|
|
94
|
-
* one lowercase letter, one number, and one special character.
|
|
95
|
-
*
|
|
96
|
-
* @param {string} str - The input string.
|
|
97
|
-
* @returns {boolean} True if string meets password complexity requirements.
|
|
98
|
-
*/
|
|
99
|
-
export declare function isStrongPassword(str: string): boolean;
|
|
100
|
-
/**
|
|
101
|
-
* Checks if a string is a valid IPv4 address.
|
|
102
|
-
*
|
|
103
|
-
* @param {string} str - The input string.
|
|
104
|
-
* @returns {boolean} True if valid IPv4 address.
|
|
105
|
-
*/
|
|
106
|
-
export declare function isIPv4(str: string): boolean;
|
|
107
|
-
/**
|
|
108
|
-
* Checks if a string is a valid IPv6 address.
|
|
109
|
-
*
|
|
110
|
-
* @param {string} str - The input string.
|
|
111
|
-
* @returns {boolean} True if valid IPv6 address.
|
|
112
|
-
*/
|
|
113
|
-
export declare function isIPv6(str: string): boolean;
|
|
114
|
-
/**
|
|
115
|
-
* Validates a credit card number using the Luhn algorithm.
|
|
116
|
-
*
|
|
117
|
-
* @param {string} str - The credit card number string.
|
|
118
|
-
* @returns {boolean} True if valid credit card number.
|
|
119
|
-
*/
|
|
120
|
-
export declare function isCreditCard(str: string): boolean;
|
|
121
|
-
/**
|
|
122
|
-
* Checks if a string is a valid JSON.
|
|
123
|
-
*
|
|
124
|
-
* @param {string} str - The input string.
|
|
125
|
-
* @returns {boolean} True if valid JSON.
|
|
126
|
-
*/
|
|
127
|
-
export declare function isValidJSON(str: string): boolean;
|
|
128
|
-
/**
|
|
129
|
-
* Type guard that checks if a value is an array.
|
|
130
|
-
*
|
|
131
|
-
* @template T Optional expected element type
|
|
132
|
-
* @param {unknown} value - The value to check.
|
|
133
|
-
* @param {(item: unknown) => boolean} [itemGuard] - Optional function to validate each item.
|
|
134
|
-
* @returns {boolean} True if value is an array (with optional item validation).
|
|
135
|
-
*/
|
|
136
|
-
export declare function isArray<T = unknown>(value: unknown, itemGuard?: (item: unknown) => item is T): value is T[];
|
|
137
|
-
/**
|
|
138
|
-
* Checks if a string is a valid base64 encoded string.
|
|
139
|
-
*
|
|
140
|
-
* @param {string} str - The input string.
|
|
141
|
-
* @returns {boolean} True if valid base64.
|
|
142
|
-
*/
|
|
143
|
-
export declare function isBase64(str: string): boolean;
|
|
144
|
-
/**
|
|
145
|
-
* Validates that an object has all required properties.
|
|
146
|
-
*
|
|
147
|
-
* @param {object} obj - The object to validate.
|
|
148
|
-
* @param {string[]} requiredProps - Array of required property names.
|
|
149
|
-
* @returns {boolean} True if all required properties exist.
|
|
150
|
-
*/
|
|
151
|
-
export declare function hasRequiredProps(obj: Record<string, unknown>, requiredProps: string[]): boolean;
|
|
152
|
-
/**
|
|
153
|
-
* Validates a date is within a specified range.
|
|
154
|
-
*
|
|
155
|
-
* @param {Date} date - The date to validate.
|
|
156
|
-
* @param {Date} [minDate] - Optional minimum date (inclusive).
|
|
157
|
-
* @param {Date} [maxDate] - Optional maximum date (inclusive).
|
|
158
|
-
* @returns {boolean} True if date is within range.
|
|
159
|
-
*/
|
|
160
|
-
export declare function isDateInRange(date: Date, minDate?: Date, maxDate?: Date): boolean;
|
|
161
|
-
/**
|
|
162
|
-
* Validates a string matches a specific regular expression pattern.
|
|
163
|
-
*
|
|
164
|
-
* @param {string} str - The input string.
|
|
165
|
-
* @param {RegExp} pattern - Regular expression to test against.
|
|
166
|
-
* @returns {boolean} True if string matches pattern.
|
|
167
|
-
*/
|
|
168
|
-
export declare function matchesPattern(str: string, pattern: RegExp): boolean;
|
|
169
|
-
/**
|
|
170
|
-
* Validates data against multiple constraints.
|
|
171
|
-
*
|
|
172
|
-
* @param {unknown} value - The value to validate.
|
|
173
|
-
* @param {Array<(value: unknown) => boolean>} validators - Array of validation functions.
|
|
174
|
-
* @returns {boolean} True if value passes all validations.
|
|
175
|
-
*/
|
|
176
|
-
export declare function validateAll(value: unknown, validators: Array<(value: unknown) => boolean>): boolean;
|
|
@@ -1,344 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*
|
|
3
|
-
* The MIT License
|
|
4
|
-
*
|
|
5
|
-
* Copyright (c) 2025 Catbee Technologies. https://catbee-utils.npm.hprasath.com/license
|
|
6
|
-
*
|
|
7
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
8
|
-
* of this software and associated documentation files (the "Software"), to deal
|
|
9
|
-
* in the Software without restriction, including without limitation the rights
|
|
10
|
-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
11
|
-
* copies of the Software, and to permit persons to whom the Software is
|
|
12
|
-
* furnished to do so, subject to the following conditions:
|
|
13
|
-
*
|
|
14
|
-
* The above copyright notice and this permission notice shall be included in all
|
|
15
|
-
* copies or substantial portions of the Software.
|
|
16
|
-
*
|
|
17
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
18
|
-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
19
|
-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
20
|
-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
21
|
-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
22
|
-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
23
|
-
* SOFTWARE.
|
|
24
|
-
*/
|
|
25
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.isPort = isPort;
|
|
27
|
-
exports.isEmail = isEmail;
|
|
28
|
-
exports.isUUID = isUUID;
|
|
29
|
-
exports.isURL = isURL;
|
|
30
|
-
exports.isPhone = isPhone;
|
|
31
|
-
exports.isAlphanumeric = isAlphanumeric;
|
|
32
|
-
exports.isNumeric = isNumeric;
|
|
33
|
-
exports.isHexColor = isHexColor;
|
|
34
|
-
exports.isISODate = isISODate;
|
|
35
|
-
exports.isLengthBetween = isLengthBetween;
|
|
36
|
-
exports.isNumberBetween = isNumberBetween;
|
|
37
|
-
exports.isAlpha = isAlpha;
|
|
38
|
-
exports.isStrongPassword = isStrongPassword;
|
|
39
|
-
exports.isIPv4 = isIPv4;
|
|
40
|
-
exports.isIPv6 = isIPv6;
|
|
41
|
-
exports.isCreditCard = isCreditCard;
|
|
42
|
-
exports.isValidJSON = isValidJSON;
|
|
43
|
-
exports.isArray = isArray;
|
|
44
|
-
exports.isBase64 = isBase64;
|
|
45
|
-
exports.hasRequiredProps = hasRequiredProps;
|
|
46
|
-
exports.isDateInRange = isDateInRange;
|
|
47
|
-
exports.matchesPattern = matchesPattern;
|
|
48
|
-
exports.validateAll = validateAll;
|
|
49
|
-
/**
|
|
50
|
-
* Collection of common validation helpers for strings, numbers, email, UUID, etc.
|
|
51
|
-
*/
|
|
52
|
-
/**
|
|
53
|
-
* Checks if a string is a valid port number.
|
|
54
|
-
*
|
|
55
|
-
* @param str - The input string or number.
|
|
56
|
-
* @returns True if valid port number, else false.
|
|
57
|
-
*/
|
|
58
|
-
function isPort(value) {
|
|
59
|
-
const port = typeof value === 'string' ? Number(value.trim()) : value;
|
|
60
|
-
return Number.isInteger(port) && port > 0 && port <= 65535;
|
|
61
|
-
}
|
|
62
|
-
/**
|
|
63
|
-
* Checks if a string is a valid email address.
|
|
64
|
-
*
|
|
65
|
-
* @param {string} str - The input string.
|
|
66
|
-
* @returns {boolean} True if valid email, else false.
|
|
67
|
-
*/
|
|
68
|
-
function isEmail(str) {
|
|
69
|
-
if (!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(str))
|
|
70
|
-
return false;
|
|
71
|
-
// Additional checks
|
|
72
|
-
const [local, domain] = str.split('@');
|
|
73
|
-
if (!local || !domain)
|
|
74
|
-
return false;
|
|
75
|
-
// Disallow consecutive dots in local or domain part
|
|
76
|
-
if (local.includes('..') || domain.includes('..'))
|
|
77
|
-
return false;
|
|
78
|
-
return true;
|
|
79
|
-
}
|
|
80
|
-
/**
|
|
81
|
-
* Checks if a string is a valid UUID (versions 1-5).
|
|
82
|
-
*
|
|
83
|
-
* @param {string} str - The input string.
|
|
84
|
-
* @returns {boolean} True if valid UUID, else false.
|
|
85
|
-
*/
|
|
86
|
-
function isUUID(str) {
|
|
87
|
-
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);
|
|
88
|
-
}
|
|
89
|
-
/**
|
|
90
|
-
* Checks if a string is a valid URL.
|
|
91
|
-
*
|
|
92
|
-
* @param {string} str - The input string.
|
|
93
|
-
* @returns {boolean} True if valid URL, else false.
|
|
94
|
-
*/
|
|
95
|
-
function isURL(str) {
|
|
96
|
-
try {
|
|
97
|
-
new URL(str);
|
|
98
|
-
return true;
|
|
99
|
-
}
|
|
100
|
-
catch {
|
|
101
|
-
return false;
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
/**
|
|
105
|
-
* Checks if a string is a valid international phone number (E.164 or common patterns).
|
|
106
|
-
*
|
|
107
|
-
* @param {string} str - The input string.
|
|
108
|
-
* @returns {boolean} True if looks like a phone number.
|
|
109
|
-
*/
|
|
110
|
-
function isPhone(str) {
|
|
111
|
-
if (typeof str !== 'string')
|
|
112
|
-
return false;
|
|
113
|
-
// Strip non-digit characters to count total digits
|
|
114
|
-
const digitsOnly = str.replace(/\D/g, '');
|
|
115
|
-
if (digitsOnly.length < 6 || digitsOnly.length > 15)
|
|
116
|
-
return false;
|
|
117
|
-
// Accept typical phone characters: +, digits, space, -, (, )
|
|
118
|
-
return /^[+]?[\d\s().-]+$/.test(str);
|
|
119
|
-
}
|
|
120
|
-
/**
|
|
121
|
-
* Checks if a string is strictly alphanumeric (letters/numbers only).
|
|
122
|
-
*
|
|
123
|
-
* @param {string} str - The input string.
|
|
124
|
-
* @returns {boolean} True if alphanumeric.
|
|
125
|
-
*/
|
|
126
|
-
function isAlphanumeric(str) {
|
|
127
|
-
return /^[a-z0-9]+$/i.test(str);
|
|
128
|
-
}
|
|
129
|
-
/**
|
|
130
|
-
* Checks if a string or number can be safely parsed to a number.
|
|
131
|
-
*
|
|
132
|
-
* @param {string | number} value - The value to check.
|
|
133
|
-
* @returns {boolean} True if the value is numeric.
|
|
134
|
-
*/
|
|
135
|
-
function isNumeric(value) {
|
|
136
|
-
if (typeof value === 'string' && value.trim() === '')
|
|
137
|
-
return false;
|
|
138
|
-
const num = typeof value === 'number' ? value : Number(value);
|
|
139
|
-
return typeof num === 'number' && isFinite(num);
|
|
140
|
-
}
|
|
141
|
-
/**
|
|
142
|
-
* Checks if a string is a valid hex color code (e.g. #FFF or #FFFFFF).
|
|
143
|
-
*
|
|
144
|
-
* @param {string} str - Input string.
|
|
145
|
-
* @returns {boolean}
|
|
146
|
-
*/
|
|
147
|
-
function isHexColor(str) {
|
|
148
|
-
return /^#([a-f0-9]{6}|[a-f0-9]{3})$/i.test(str);
|
|
149
|
-
}
|
|
150
|
-
/**
|
|
151
|
-
* Checks if a string is a valid date string.
|
|
152
|
-
*
|
|
153
|
-
* @param {string} str - Input string.
|
|
154
|
-
* @returns {boolean}
|
|
155
|
-
*/
|
|
156
|
-
function isISODate(str) {
|
|
157
|
-
const isoRegex = /^\d{4}-\d{2}-\d{2}(T\d{2}:\d{2}:\d{2}(\.\d+)?(Z|[+-]\d{2}:\d{2})?)?$/;
|
|
158
|
-
if (!isoRegex.test(str))
|
|
159
|
-
return false;
|
|
160
|
-
const date = new Date(str);
|
|
161
|
-
return !isNaN(date.getTime()) && date.toISOString().startsWith(str.slice(0, 10));
|
|
162
|
-
}
|
|
163
|
-
/**
|
|
164
|
-
* Checks if a string matches a specified length range.
|
|
165
|
-
*
|
|
166
|
-
* @param {string} str - The input string.
|
|
167
|
-
* @param {number} min - Minimum length (inclusive).
|
|
168
|
-
* @param {number} max - Maximum length (inclusive).
|
|
169
|
-
* @returns {boolean} True if string length is within range.
|
|
170
|
-
*/
|
|
171
|
-
function isLengthBetween(str, min, max) {
|
|
172
|
-
return str.length >= min && str.length <= max;
|
|
173
|
-
}
|
|
174
|
-
/**
|
|
175
|
-
* Validates that a number is between specified min and max values (inclusive).
|
|
176
|
-
*
|
|
177
|
-
* @param {number} value - The number to validate.
|
|
178
|
-
* @param {number} min - Minimum value.
|
|
179
|
-
* @param {number} max - Maximum value.
|
|
180
|
-
* @returns {boolean} True if number is within range.
|
|
181
|
-
*/
|
|
182
|
-
function isNumberBetween(value, min, max) {
|
|
183
|
-
return value >= min && value <= max;
|
|
184
|
-
}
|
|
185
|
-
/**
|
|
186
|
-
* Checks if a string contains only alphabetic characters.
|
|
187
|
-
*
|
|
188
|
-
* @param {string} str - The input string.
|
|
189
|
-
* @returns {boolean} True if alphabetic only.
|
|
190
|
-
*/
|
|
191
|
-
function isAlpha(str) {
|
|
192
|
-
return /^[a-zA-Z]+$/.test(str);
|
|
193
|
-
}
|
|
194
|
-
/**
|
|
195
|
-
* Validates that a string contains at least one uppercase letter,
|
|
196
|
-
* one lowercase letter, one number, and one special character.
|
|
197
|
-
*
|
|
198
|
-
* @param {string} str - The input string.
|
|
199
|
-
* @returns {boolean} True if string meets password complexity requirements.
|
|
200
|
-
*/
|
|
201
|
-
function isStrongPassword(str) {
|
|
202
|
-
if (str.length < 8)
|
|
203
|
-
return false;
|
|
204
|
-
const hasUpperCase = /[A-Z]/.test(str);
|
|
205
|
-
const hasLowerCase = /[a-z]/.test(str);
|
|
206
|
-
const hasNumbers = /[0-9]/.test(str);
|
|
207
|
-
const hasSpecialChar = /[!@#$%^&*()_+\-=[\]{};':"\\|,.<>?]/.test(str);
|
|
208
|
-
return hasUpperCase && hasLowerCase && hasNumbers && hasSpecialChar;
|
|
209
|
-
}
|
|
210
|
-
/**
|
|
211
|
-
* Checks if a string is a valid IPv4 address.
|
|
212
|
-
*
|
|
213
|
-
* @param {string} str - The input string.
|
|
214
|
-
* @returns {boolean} True if valid IPv4 address.
|
|
215
|
-
*/
|
|
216
|
-
function isIPv4(str) {
|
|
217
|
-
const parts = str.split('.');
|
|
218
|
-
if (parts.length !== 4)
|
|
219
|
-
return false;
|
|
220
|
-
return parts.every(part => {
|
|
221
|
-
const num = parseInt(part, 10);
|
|
222
|
-
return part === num.toString() && num >= 0 && num <= 255;
|
|
223
|
-
});
|
|
224
|
-
}
|
|
225
|
-
/**
|
|
226
|
-
* Checks if a string is a valid IPv6 address.
|
|
227
|
-
*
|
|
228
|
-
* @param {string} str - The input string.
|
|
229
|
-
* @returns {boolean} True if valid IPv6 address.
|
|
230
|
-
*/
|
|
231
|
-
function isIPv6(str) {
|
|
232
|
-
// Simple but effective check for common IPv6 formats
|
|
233
|
-
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);
|
|
234
|
-
}
|
|
235
|
-
/**
|
|
236
|
-
* Validates a credit card number using the Luhn algorithm.
|
|
237
|
-
*
|
|
238
|
-
* @param {string} str - The credit card number string.
|
|
239
|
-
* @returns {boolean} True if valid credit card number.
|
|
240
|
-
*/
|
|
241
|
-
function isCreditCard(str) {
|
|
242
|
-
// Remove non-digit characters
|
|
243
|
-
const cardNumber = str.replace(/\D/g, '');
|
|
244
|
-
if (cardNumber.length < 13 || cardNumber.length > 19)
|
|
245
|
-
return false;
|
|
246
|
-
// Luhn algorithm implementation
|
|
247
|
-
let sum = 0;
|
|
248
|
-
let shouldDouble = false;
|
|
249
|
-
for (let i = cardNumber.length - 1; i >= 0; i--) {
|
|
250
|
-
let digit = parseInt(cardNumber.charAt(i), 10);
|
|
251
|
-
if (shouldDouble) {
|
|
252
|
-
digit *= 2;
|
|
253
|
-
if (digit > 9)
|
|
254
|
-
digit -= 9;
|
|
255
|
-
}
|
|
256
|
-
sum += digit;
|
|
257
|
-
shouldDouble = !shouldDouble;
|
|
258
|
-
}
|
|
259
|
-
return sum % 10 === 0;
|
|
260
|
-
}
|
|
261
|
-
/**
|
|
262
|
-
* Checks if a string is a valid JSON.
|
|
263
|
-
*
|
|
264
|
-
* @param {string} str - The input string.
|
|
265
|
-
* @returns {boolean} True if valid JSON.
|
|
266
|
-
*/
|
|
267
|
-
function isValidJSON(str) {
|
|
268
|
-
try {
|
|
269
|
-
JSON.parse(str);
|
|
270
|
-
return true;
|
|
271
|
-
}
|
|
272
|
-
catch {
|
|
273
|
-
return false;
|
|
274
|
-
}
|
|
275
|
-
}
|
|
276
|
-
/**
|
|
277
|
-
* Type guard that checks if a value is an array.
|
|
278
|
-
*
|
|
279
|
-
* @template T Optional expected element type
|
|
280
|
-
* @param {unknown} value - The value to check.
|
|
281
|
-
* @param {(item: unknown) => boolean} [itemGuard] - Optional function to validate each item.
|
|
282
|
-
* @returns {boolean} True if value is an array (with optional item validation).
|
|
283
|
-
*/
|
|
284
|
-
function isArray(value, itemGuard) {
|
|
285
|
-
if (!Array.isArray(value))
|
|
286
|
-
return false;
|
|
287
|
-
return !itemGuard || value.every(item => itemGuard(item));
|
|
288
|
-
}
|
|
289
|
-
/**
|
|
290
|
-
* Checks if a string is a valid base64 encoded string.
|
|
291
|
-
*
|
|
292
|
-
* @param {string} str - The input string.
|
|
293
|
-
* @returns {boolean} True if valid base64.
|
|
294
|
-
*/
|
|
295
|
-
function isBase64(str) {
|
|
296
|
-
return /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(str);
|
|
297
|
-
}
|
|
298
|
-
/**
|
|
299
|
-
* Validates that an object has all required properties.
|
|
300
|
-
*
|
|
301
|
-
* @param {object} obj - The object to validate.
|
|
302
|
-
* @param {string[]} requiredProps - Array of required property names.
|
|
303
|
-
* @returns {boolean} True if all required properties exist.
|
|
304
|
-
*/
|
|
305
|
-
function hasRequiredProps(obj, requiredProps) {
|
|
306
|
-
return requiredProps.every(prop => Object.prototype.hasOwnProperty.call(obj, prop) && obj[prop] !== undefined && obj[prop] !== null);
|
|
307
|
-
}
|
|
308
|
-
/**
|
|
309
|
-
* Validates a date is within a specified range.
|
|
310
|
-
*
|
|
311
|
-
* @param {Date} date - The date to validate.
|
|
312
|
-
* @param {Date} [minDate] - Optional minimum date (inclusive).
|
|
313
|
-
* @param {Date} [maxDate] - Optional maximum date (inclusive).
|
|
314
|
-
* @returns {boolean} True if date is within range.
|
|
315
|
-
*/
|
|
316
|
-
function isDateInRange(date, minDate, maxDate) {
|
|
317
|
-
if (!(date instanceof Date) || isNaN(date.getTime()))
|
|
318
|
-
return false;
|
|
319
|
-
if (minDate && date < minDate)
|
|
320
|
-
return false;
|
|
321
|
-
if (maxDate && date > maxDate)
|
|
322
|
-
return false;
|
|
323
|
-
return true;
|
|
324
|
-
}
|
|
325
|
-
/**
|
|
326
|
-
* Validates a string matches a specific regular expression pattern.
|
|
327
|
-
*
|
|
328
|
-
* @param {string} str - The input string.
|
|
329
|
-
* @param {RegExp} pattern - Regular expression to test against.
|
|
330
|
-
* @returns {boolean} True if string matches pattern.
|
|
331
|
-
*/
|
|
332
|
-
function matchesPattern(str, pattern) {
|
|
333
|
-
return pattern.test(str);
|
|
334
|
-
}
|
|
335
|
-
/**
|
|
336
|
-
* Validates data against multiple constraints.
|
|
337
|
-
*
|
|
338
|
-
* @param {unknown} value - The value to validate.
|
|
339
|
-
* @param {Array<(value: unknown) => boolean>} validators - Array of validation functions.
|
|
340
|
-
* @returns {boolean} True if value passes all validations.
|
|
341
|
-
*/
|
|
342
|
-
function validateAll(value, validators) {
|
|
343
|
-
return validators.every(validator => validator(value));
|
|
344
|
-
}
|
package/build/esm/config.d.ts
DELETED
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
import { Logger, LoggerLevels } from './utils/logger.utils';
|
|
2
|
-
/**
|
|
3
|
-
* Extends Express Request interface to add request ID tracking.
|
|
4
|
-
* Added by requestId middleware during request processing.
|
|
5
|
-
*/
|
|
6
|
-
declare global {
|
|
7
|
-
namespace Express {
|
|
8
|
-
interface Request {
|
|
9
|
-
/** Unique request identifier (set by middleware) */
|
|
10
|
-
id?: string;
|
|
11
|
-
/** Logger instance for the request (set by middleware) */
|
|
12
|
-
logger?: Logger;
|
|
13
|
-
/** User information (set by authentication middleware) */
|
|
14
|
-
user?: any;
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* Application runtime configuration loaded from environment variables.
|
|
20
|
-
*/
|
|
21
|
-
export declare let config: {
|
|
22
|
-
logger: {
|
|
23
|
-
/**
|
|
24
|
-
* Logging level (e.g., 'info', 'debug', 'warn', 'error').
|
|
25
|
-
*/
|
|
26
|
-
level: LoggerLevels;
|
|
27
|
-
/**
|
|
28
|
-
* Name of the logger instance (defaults to npm package name).
|
|
29
|
-
*/
|
|
30
|
-
name: string;
|
|
31
|
-
/**
|
|
32
|
-
* Enables pretty-print logging in development.
|
|
33
|
-
* Has no effect in production.
|
|
34
|
-
*/
|
|
35
|
-
pretty: boolean;
|
|
36
|
-
/**
|
|
37
|
-
* Single line output for pretty-print (default: false)
|
|
38
|
-
*/
|
|
39
|
-
singleLine: boolean;
|
|
40
|
-
};
|
|
41
|
-
cache: {
|
|
42
|
-
/**
|
|
43
|
-
* Default TTL (time to live) for cache entries in seconds
|
|
44
|
-
*/
|
|
45
|
-
defaultTtl: number;
|
|
46
|
-
};
|
|
47
|
-
};
|
|
48
|
-
export declare const defaultServerConfig: {
|
|
49
|
-
port: number;
|
|
50
|
-
host: string;
|
|
51
|
-
cors: false;
|
|
52
|
-
helmet: false;
|
|
53
|
-
compression: false;
|
|
54
|
-
bodyParser: {
|
|
55
|
-
json: {
|
|
56
|
-
limit: string;
|
|
57
|
-
};
|
|
58
|
-
urlencoded: {
|
|
59
|
-
extended: true;
|
|
60
|
-
limit: string;
|
|
61
|
-
};
|
|
62
|
-
};
|
|
63
|
-
cookieParser: false;
|
|
64
|
-
isMicroservice: false;
|
|
65
|
-
appName: string;
|
|
66
|
-
globalHeaders: {};
|
|
67
|
-
rateLimit: {
|
|
68
|
-
enable: false;
|
|
69
|
-
windowMs: number;
|
|
70
|
-
max: number;
|
|
71
|
-
message: string;
|
|
72
|
-
standardHeaders: true;
|
|
73
|
-
legacyHeaders: false;
|
|
74
|
-
};
|
|
75
|
-
requestLogging: {
|
|
76
|
-
enable: boolean;
|
|
77
|
-
ignorePaths: (req: import("express").Request<import("express-serve-static-core").ParamsDictionary, any, any, import("qs").ParsedQs, Record<string, any>>, _res: import("express").Response<any, Record<string, any>>) => boolean;
|
|
78
|
-
skipNotFoundRoutes: false;
|
|
79
|
-
};
|
|
80
|
-
openApi: {
|
|
81
|
-
enable: false;
|
|
82
|
-
mountPath: string;
|
|
83
|
-
verbose: false;
|
|
84
|
-
withGlobalPrefix: false;
|
|
85
|
-
};
|
|
86
|
-
healthCheck: {
|
|
87
|
-
path: string;
|
|
88
|
-
detailed: true;
|
|
89
|
-
};
|
|
90
|
-
requestTimeout: number;
|
|
91
|
-
responseTime: {
|
|
92
|
-
enable: false;
|
|
93
|
-
addHeader: true;
|
|
94
|
-
logOnComplete: false;
|
|
95
|
-
};
|
|
96
|
-
requestId: {
|
|
97
|
-
headerName: string;
|
|
98
|
-
exposeHeader: true;
|
|
99
|
-
generator: () => string;
|
|
100
|
-
};
|
|
101
|
-
metrics: {
|
|
102
|
-
enable: false;
|
|
103
|
-
path: string;
|
|
104
|
-
withGlobalPrefix: false;
|
|
105
|
-
};
|
|
106
|
-
serviceVersion: {
|
|
107
|
-
enable: false;
|
|
108
|
-
headerName: string;
|
|
109
|
-
version: string;
|
|
110
|
-
};
|
|
111
|
-
};
|
|
112
|
-
/**
|
|
113
|
-
* Update the @catbee/utils configuration.
|
|
114
|
-
* @param value Partial configuration object.
|
|
115
|
-
*/
|
|
116
|
-
export declare function setConfig(value: Partial<typeof config>): void;
|
|
117
|
-
/**
|
|
118
|
-
* Get the current @catbee/utils configuration.
|
|
119
|
-
* @returns The current configuration object.
|
|
120
|
-
*/
|
|
121
|
-
export declare function getConfig(): typeof config;
|