@catbee/utils 2.0.0-next.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.
Files changed (122) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +102 -52
  3. package/array/index.cjs +215 -74
  4. package/array/index.d.ts +345 -2
  5. package/array/index.mjs +201 -74
  6. package/async/index.cjs +116 -39
  7. package/async/index.d.ts +292 -2
  8. package/async/index.mjs +116 -40
  9. package/cache/index.cjs +2 -2
  10. package/cache/index.d.ts +156 -2
  11. package/cache/index.mjs +3 -3
  12. package/config/index.cjs +80 -66
  13. package/config/index.d.ts +65 -3
  14. package/config/index.mjs +77 -65
  15. package/context-store/index.cjs +2 -3
  16. package/context-store/index.d.ts +193 -2
  17. package/context-store/index.mjs +2 -3
  18. package/crypto/index.cjs +55 -5
  19. package/crypto/index.d.ts +225 -2
  20. package/crypto/index.mjs +52 -7
  21. package/date/index.cjs +676 -2
  22. package/date/index.d.ts +676 -2
  23. package/date/index.mjs +665 -3
  24. package/decorator/index.cjs +2172 -0
  25. package/{decorators/decorators.utils.d.ts → decorator/index.d.ts} +58 -54
  26. package/decorator/index.mjs +2131 -0
  27. package/{dir → directory}/index.cjs +5 -4
  28. package/{dir/dir.utils.d.ts → directory/index.d.ts} +24 -21
  29. package/{dir → directory}/index.mjs +5 -4
  30. package/env/index.cjs +100 -68
  31. package/env/index.d.ts +391 -2
  32. package/env/index.mjs +100 -68
  33. package/exception/index.cjs +1 -1
  34. package/exception/index.d.ts +233 -2
  35. package/exception/index.mjs +1 -1
  36. package/fs/index.cjs +71 -37
  37. package/fs/index.d.ts +206 -2
  38. package/fs/index.mjs +65 -35
  39. package/http-status-codes/index.cjs +1 -1
  40. package/http-status-codes/index.d.ts +268 -2
  41. package/http-status-codes/index.mjs +1 -1
  42. package/id/index.cjs +1 -1
  43. package/id/index.d.ts +38 -2
  44. package/id/index.mjs +1 -1
  45. package/index.cjs +13 -13
  46. package/index.d.ts +5 -5
  47. package/index.mjs +5 -5
  48. package/logger/index.cjs +13 -15
  49. package/logger/index.d.ts +190 -2
  50. package/logger/index.mjs +14 -16
  51. package/middleware/index.cjs +1 -1
  52. package/middleware/index.d.ts +104 -2
  53. package/middleware/index.mjs +1 -1
  54. package/object/index.cjs +379 -0
  55. package/{obj/obj.utils.d.ts → object/index.d.ts} +73 -33
  56. package/object/index.mjs +360 -0
  57. package/package.json +41 -23
  58. package/performance/index.cjs +4 -4
  59. package/performance/index.d.ts +139 -2
  60. package/performance/index.mjs +4 -4
  61. package/request/index.cjs +37 -25
  62. package/request/index.d.ts +242 -3
  63. package/request/index.mjs +37 -25
  64. package/response/index.cjs +1 -1
  65. package/response/index.d.ts +319 -3
  66. package/response/index.mjs +1 -1
  67. package/server/index.cjs +249 -146
  68. package/server/index.d.ts +866 -5
  69. package/server/index.mjs +248 -144
  70. package/stream/index.cjs +1 -1
  71. package/stream/index.d.ts +91 -2
  72. package/stream/index.mjs +1 -1
  73. package/string/index.cjs +34 -1
  74. package/string/index.d.ts +146 -2
  75. package/string/index.mjs +31 -2
  76. package/type/index.cjs +19 -2
  77. package/type/index.d.ts +144 -2
  78. package/type/index.mjs +17 -3
  79. package/types/index.cjs +1 -1
  80. package/types/index.d.ts +775 -5
  81. package/types/index.mjs +1 -1
  82. package/url/index.cjs +63 -5
  83. package/url/index.d.ts +200 -2
  84. package/url/index.mjs +59 -6
  85. package/{validate → validation}/index.cjs +91 -44
  86. package/{validate/validate.utils.d.ts → validation/index.d.ts} +33 -24
  87. package/{validate → validation}/index.mjs +87 -44
  88. package/array/array.utils.d.ts +0 -191
  89. package/async/async.utils.d.ts +0 -296
  90. package/cache/cache.utils.d.ts +0 -176
  91. package/config/config.d.ts +0 -57
  92. package/context-store/context-store.utils.d.ts +0 -212
  93. package/crypto/crypto.utils.d.ts +0 -183
  94. package/date/date.utils.d.ts +0 -190
  95. package/decorators/index.cjs +0 -913
  96. package/decorators/index.d.ts +0 -25
  97. package/decorators/index.mjs +0 -872
  98. package/dir/index.d.ts +0 -25
  99. package/env/env.utils.d.ts +0 -400
  100. package/exception/exception.utils.d.ts +0 -253
  101. package/fs/fs.utils.d.ts +0 -196
  102. package/http-status-codes/http-status-codes.d.ts +0 -289
  103. package/id/id.utils.d.ts +0 -59
  104. package/logger/logger.utils.d.ts +0 -210
  105. package/middleware/middleware.utils.d.ts +0 -123
  106. package/obj/index.cjs +0 -317
  107. package/obj/index.d.ts +0 -25
  108. package/obj/index.mjs +0 -301
  109. package/performance/performance.utils.d.ts +0 -159
  110. package/request/request.utils.d.ts +0 -109
  111. package/response/response.utils.d.ts +0 -186
  112. package/server/server.builder.d.ts +0 -531
  113. package/server/server.d.ts +0 -303
  114. package/stream/stream.utils.d.ts +0 -111
  115. package/string/string.utils.d.ts +0 -124
  116. package/type/type.utils.d.ts +0 -129
  117. package/types/api-response.d.ts +0 -175
  118. package/types/common.d.ts +0 -148
  119. package/types/config.d.ts +0 -88
  120. package/types/server.d.ts +0 -291
  121. package/url/url.utils.d.ts +0 -164
  122. package/validate/index.d.ts +0 -25
@@ -1,7 +1,7 @@
1
1
  /*
2
2
  * The MIT License
3
3
  *
4
- * Copyright (c) 2025 Catbee Technologies. https://catbee.in/license
4
+ * Copyright (c) 2026 Catbee Technologies. https://catbee.in/license
5
5
  *
6
6
  * Permission is hereby granted, free of charge, to any person obtaining a copy
7
7
  * of this software and associated documentation files (the "Software"), to deal
@@ -31,63 +31,64 @@
31
31
  * @param str - The input string or number.
32
32
  * @returns True if valid port number, else false.
33
33
  */
34
- export declare function isPort(value: string | number): boolean;
34
+ declare function isPort(value: string | number): boolean;
35
35
  /**
36
36
  * Checks if a string is a valid email address.
37
37
  *
38
38
  * @param {string} str - The input string.
39
39
  * @returns {boolean} True if valid email, else false.
40
40
  */
41
- export declare function isEmail(str: string): boolean;
41
+ declare function isEmail(str: string): boolean;
42
42
  /**
43
43
  * Checks if a string is a valid UUID (versions 1-5).
44
44
  *
45
45
  * @param {string} str - The input string.
46
46
  * @returns {boolean} True if valid UUID, else false.
47
47
  */
48
- export declare function isUUID(str: string): boolean;
48
+ declare function isUUID(str: string): boolean;
49
49
  /**
50
50
  * Checks if a string is a valid URL.
51
51
  *
52
52
  * @param {string} str - The input string.
53
+ * @param {string[]} [allowedProtocols=['http', 'https', 'ws', 'wss']] - Allowed URL protocols.
53
54
  * @returns {boolean} True if valid URL, else false.
54
55
  */
55
- export declare function isURL(str: string): boolean;
56
+ declare function isURL(str: string, allowedProtocols?: string[]): boolean;
56
57
  /**
57
58
  * Checks if a string is a valid international phone number (E.164 or common patterns).
58
59
  *
59
60
  * @param {string} str - The input string.
60
61
  * @returns {boolean} True if looks like a phone number.
61
62
  */
62
- export declare function isPhone(str: string): boolean;
63
+ declare function isPhone(str: string): boolean;
63
64
  /**
64
65
  * Checks if a string is strictly alphanumeric (letters/numbers only).
65
66
  *
66
67
  * @param {string} str - The input string.
67
68
  * @returns {boolean} True if alphanumeric.
68
69
  */
69
- export declare function isAlphanumeric(str: string): boolean;
70
+ declare function isAlphanumeric(str: string): boolean;
70
71
  /**
71
72
  * Checks if a string or number can be safely parsed to a number.
72
73
  *
73
74
  * @param {string | number} value - The value to check.
74
75
  * @returns {boolean} True if the value is numeric.
75
76
  */
76
- export declare function isNumeric(value: string | number): boolean;
77
+ declare function isNumeric(value: string | number): boolean;
77
78
  /**
78
79
  * Checks if a string is a valid hex color code (e.g. #FFF or #FFFFFF).
79
80
  *
80
81
  * @param {string} str - Input string.
81
82
  * @returns {boolean}
82
83
  */
83
- export declare function isHexColor(str: string): boolean;
84
+ declare function isHexColor(str: string): boolean;
84
85
  /**
85
86
  * Checks if a string is a valid date string.
86
87
  *
87
88
  * @param {string} str - Input string.
88
89
  * @returns {boolean}
89
90
  */
90
- export declare function isISODate(str: string): boolean;
91
+ declare function isISODate(str: string): boolean;
91
92
  /**
92
93
  * Checks if a string matches a specified length range.
93
94
  *
@@ -96,7 +97,7 @@ export declare function isISODate(str: string): boolean;
96
97
  * @param {number} max - Maximum length (inclusive).
97
98
  * @returns {boolean} True if string length is within range.
98
99
  */
99
- export declare function isLengthBetween(str: string, min: number, max: number): boolean;
100
+ declare function isLengthBetween(str: string, min: number, max: number): boolean;
100
101
  /**
101
102
  * Validates that a number is between specified min and max values (inclusive).
102
103
  *
@@ -105,50 +106,56 @@ export declare function isLengthBetween(str: string, min: number, max: number):
105
106
  * @param {number} max - Maximum value.
106
107
  * @returns {boolean} True if number is within range.
107
108
  */
108
- export declare function isNumberBetween(value: number, min: number, max: number): boolean;
109
+ declare function isNumberBetween(value: number, min: number, max: number): boolean;
109
110
  /**
110
111
  * Checks if a string contains only alphabetic characters.
111
112
  *
112
113
  * @param {string} str - The input string.
113
114
  * @returns {boolean} True if alphabetic only.
114
115
  */
115
- export declare function isAlpha(str: string): boolean;
116
+ declare function isAlpha(str: string): boolean;
116
117
  /**
117
118
  * Validates that a string contains at least one uppercase letter,
118
119
  * one lowercase letter, one number, and one special character.
119
120
  *
121
+ * - Minimum length of 8 characters.
122
+ * - At least one uppercase letter (A-Z).
123
+ * - At least one lowercase letter (a-z).
124
+ * - At least one digit (0-9).
125
+ * - At least one special character e.g. !@#$%^&*()_+-=[]{};':"\\|,.<>?/
126
+ *
120
127
  * @param {string} str - The input string.
121
128
  * @returns {boolean} True if string meets password complexity requirements.
122
129
  */
123
- export declare function isStrongPassword(str: string): boolean;
130
+ declare function isStrongPassword(str: string): boolean;
124
131
  /**
125
132
  * Checks if a string is a valid IPv4 address.
126
133
  *
127
134
  * @param {string} str - The input string.
128
135
  * @returns {boolean} True if valid IPv4 address.
129
136
  */
130
- export declare function isIPv4(str: string): boolean;
137
+ declare function isIPv4(str: string): boolean;
131
138
  /**
132
139
  * Checks if a string is a valid IPv6 address.
133
140
  *
134
141
  * @param {string} str - The input string.
135
142
  * @returns {boolean} True if valid IPv6 address.
136
143
  */
137
- export declare function isIPv6(str: string): boolean;
144
+ declare function isIPv6(str: string): boolean;
138
145
  /**
139
146
  * Validates a credit card number using the Luhn algorithm.
140
147
  *
141
148
  * @param {string} str - The credit card number string.
142
149
  * @returns {boolean} True if valid credit card number.
143
150
  */
144
- export declare function isCreditCard(str: string): boolean;
151
+ declare function isCreditCard(str: string): boolean;
145
152
  /**
146
153
  * Checks if a string is a valid JSON.
147
154
  *
148
155
  * @param {string} str - The input string.
149
156
  * @returns {boolean} True if valid JSON.
150
157
  */
151
- export declare function isValidJSON(str: string): boolean;
158
+ declare function isValidJSON(str: string): boolean;
152
159
  /**
153
160
  * Type guard that checks if a value is an array.
154
161
  *
@@ -157,14 +164,14 @@ export declare function isValidJSON(str: string): boolean;
157
164
  * @param {(item: unknown) => boolean} [itemGuard] - Optional function to validate each item.
158
165
  * @returns {boolean} True if value is an array (with optional item validation).
159
166
  */
160
- export declare function isArray<T = unknown>(value: unknown, itemGuard?: (item: unknown) => item is T): value is T[];
167
+ declare function isArray<T = unknown>(value: unknown, itemGuard?: (item: unknown) => item is T): value is T[];
161
168
  /**
162
169
  * Checks if a string is a valid base64 encoded string.
163
170
  *
164
171
  * @param {string} str - The input string.
165
172
  * @returns {boolean} True if valid base64.
166
173
  */
167
- export declare function isBase64(str: string): boolean;
174
+ declare function isBase64(str: string): boolean;
168
175
  /**
169
176
  * Validates that an object has all required properties.
170
177
  *
@@ -172,7 +179,7 @@ export declare function isBase64(str: string): boolean;
172
179
  * @param {string[]} requiredProps - Array of required property names.
173
180
  * @returns {boolean} True if all required properties exist.
174
181
  */
175
- export declare function hasRequiredProps(obj: Record<string, unknown>, requiredProps: string[]): boolean;
182
+ declare function hasRequiredProps(obj: Record<string, unknown>, requiredProps: string[]): boolean;
176
183
  /**
177
184
  * Validates a date is within a specified range.
178
185
  *
@@ -181,7 +188,7 @@ export declare function hasRequiredProps(obj: Record<string, unknown>, requiredP
181
188
  * @param {Date} [maxDate] - Optional maximum date (inclusive).
182
189
  * @returns {boolean} True if date is within range.
183
190
  */
184
- export declare function isDateInRange(date: Date, minDate?: Date, maxDate?: Date): boolean;
191
+ declare function isDateInRange(date: Date, minDate?: Date, maxDate?: Date): boolean;
185
192
  /**
186
193
  * Validates a string matches a specific regular expression pattern.
187
194
  *
@@ -189,7 +196,7 @@ export declare function isDateInRange(date: Date, minDate?: Date, maxDate?: Date
189
196
  * @param {RegExp} pattern - Regular expression to test against.
190
197
  * @returns {boolean} True if string matches pattern.
191
198
  */
192
- export declare function matchesPattern(str: string, pattern: RegExp): boolean;
199
+ declare function matchesPattern(str: string, pattern: RegExp): boolean;
193
200
  /**
194
201
  * Validates data against multiple constraints.
195
202
  *
@@ -197,4 +204,6 @@ export declare function matchesPattern(str: string, pattern: RegExp): boolean;
197
204
  * @param {Array<(value: unknown) => boolean>} validators - Array of validation functions.
198
205
  * @returns {boolean} True if value passes all validations.
199
206
  */
200
- export declare function validateAll(value: unknown, validators: Array<(value: unknown) => boolean>): boolean;
207
+ declare function validateAll(value: unknown, validators: Array<(value: unknown) => boolean>): boolean;
208
+
209
+ export { hasRequiredProps, isAlpha, isAlphanumeric, isArray, isBase64, isCreditCard, isDateInRange, isEmail, isHexColor, isIPv4, isIPv6, isISODate, isLengthBetween, isNumberBetween, isNumeric, isPhone, isPort, isStrongPassword, isURL, isUUID, isValidJSON, matchesPattern, validateAll };
@@ -1,7 +1,7 @@
1
1
  /*
2
2
  * The MIT License
3
3
  *
4
- * Copyright (c) 2025 Catbee Technologies. https://catbee.in/license
4
+ * Copyright (c) 2026 Catbee Technologies. https://catbee.in/license
5
5
  *
6
6
  * Permission is hereby granted, free of charge, to any person obtaining a copy
7
7
  * of this software and associated documentation files (the "Software"), to deal
@@ -22,25 +22,37 @@
22
22
  * SOFTWARE.
23
23
  */
24
24
 
25
+ import net from 'net';
26
+
25
27
  var __defProp = Object.defineProperty;
26
28
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
27
-
28
- // src/validate/validate.utils.ts
29
+ var PORT_REGEX = /^[0-9]{1,5}$/;
30
+ var UUID_REGEX = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
31
+ var PHONE_ALLOWED_CHARS_REGEX = /^[+]?[0-9\s().-]+$/;
32
+ var ALPHANUMERIC_REGEX = /^[A-Za-z0-9]+$/;
33
+ var HEX_COLOR_REGEX = /^#([a-f0-9]{6}|[a-f0-9]{3})$/i;
34
+ var ISO_DATE_REGEX = /^\d{4}-\d{2}-\d{2}(T\d{2}:\d{2}:\d{2}(\.\d+)?(Z|[+-]\d{2}:\d{2})?)?$/;
35
+ var BASE64_REGEX = /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/;
36
+ var DOT_ATOM_REGEX = /^[A-Za-z0-9!#$%&'*+/=?^_`{|}~-]+(\.[A-Za-z0-9!#$%&'*+/=?^_`{|}~-]+)*$/;
37
+ var QUOTED_LOCAL_REGEX = /^"([\s\x21\x23-\x5B\x5D-\x7E]|\\[\x20-\x7E])*"$/;
38
+ var TLD_REGEX = /^[A-Za-z]{2,63}$/;
29
39
  function isPort(value) {
30
- const port = typeof value === "string" ? Number(value.trim()) : value;
40
+ if (typeof value === "number") return Number.isInteger(value) && value > 0 && value <= 65535;
41
+ if (!value || typeof value !== "string") return false;
42
+ const str = value.trim();
43
+ if (!PORT_REGEX.test(str)) return false;
44
+ const port = Number(str);
31
45
  return Number.isInteger(port) && port > 0 && port <= 65535;
32
46
  }
33
47
  __name(isPort, "isPort");
34
48
  function isEmail(str) {
35
- if (typeof str !== "string" || str.length > 254) return false;
49
+ if (!str || typeof str !== "string" || str.length > 254) return false;
36
50
  const atIndex = str.indexOf("@");
37
51
  if (atIndex === -1 || atIndex !== str.lastIndexOf("@")) return false;
38
52
  const local = str.slice(0, atIndex);
39
53
  const domain = str.slice(atIndex + 1);
40
54
  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;
55
+ if (!DOT_ATOM_REGEX.test(local) && !QUOTED_LOCAL_REGEX.test(local)) return false;
44
56
  if (domain.includes("..")) return false;
45
57
  const labels = domain.split(".");
46
58
  if (labels.some((l) => !l.length)) return false;
@@ -50,61 +62,75 @@ function isEmail(str) {
50
62
  if (!labelRegex.test(label)) return false;
51
63
  if (label.startsWith("-") || label.endsWith("-")) return false;
52
64
  }
53
- const tld = labels[labels.length - 1];
54
- if (!/^[A-Za-z]{2,63}$/.test(tld)) return false;
65
+ const tld = labels.at(-1) || "";
66
+ if (!TLD_REGEX.test(tld)) return false;
55
67
  return true;
56
68
  }
57
69
  __name(isEmail, "isEmail");
58
70
  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);
71
+ return UUID_REGEX.test(str);
60
72
  }
61
73
  __name(isUUID, "isUUID");
62
- function isURL(str) {
74
+ function isURL(str, allowedProtocols = [
75
+ "http",
76
+ "https",
77
+ "ws",
78
+ "wss"
79
+ ]) {
80
+ if (!str || typeof str !== "string") return false;
63
81
  try {
64
- new URL(str);
65
- return true;
82
+ const url = new URL(str);
83
+ return allowedProtocols.includes(url.protocol.replace(":", ""));
66
84
  } catch {
67
85
  return false;
68
86
  }
69
87
  }
70
88
  __name(isURL, "isURL");
71
89
  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);
90
+ if (!str || typeof str !== "string") return false;
91
+ const digits = str.replace(/\D/g, "");
92
+ if (digits.length < 6 || digits.length > 15) return false;
93
+ return PHONE_ALLOWED_CHARS_REGEX.test(str);
76
94
  }
77
95
  __name(isPhone, "isPhone");
78
96
  function isAlphanumeric(str) {
79
- return /^[a-z0-9]+$/i.test(str);
97
+ if (!str || typeof str !== "string") return false;
98
+ return ALPHANUMERIC_REGEX.test(str);
80
99
  }
81
100
  __name(isAlphanumeric, "isAlphanumeric");
82
101
  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);
102
+ if (typeof value === "number") return Number.isFinite(value);
103
+ if (!value || typeof value !== "string") return false;
104
+ const str = value.trim();
105
+ if (str === "" || str.length > 16) return false;
106
+ const num = Number(str);
107
+ return Number.isFinite(num);
86
108
  }
87
109
  __name(isNumeric, "isNumeric");
88
110
  function isHexColor(str) {
89
- return /^#([a-f0-9]{6}|[a-f0-9]{3})$/i.test(str);
111
+ if (!str || typeof str !== "string") return false;
112
+ return HEX_COLOR_REGEX.test(str);
90
113
  }
91
114
  __name(isHexColor, "isHexColor");
92
115
  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;
116
+ if (!str || typeof str !== "string") return false;
117
+ if (!ISO_DATE_REGEX.test(str)) return false;
95
118
  const date = new Date(str);
96
- return !isNaN(date.getTime()) && date.toISOString().startsWith(str.slice(0, 10));
119
+ return !Number.isNaN(date.getTime());
97
120
  }
98
121
  __name(isISODate, "isISODate");
99
122
  function isLengthBetween(str, min, max) {
123
+ if (typeof str !== "string") return false;
100
124
  return str.length >= min && str.length <= max;
101
125
  }
102
126
  __name(isLengthBetween, "isLengthBetween");
103
127
  function isNumberBetween(value, min, max) {
128
+ if (typeof value !== "number" || !Number.isFinite(value)) return false;
104
129
  return value >= min && value <= max;
105
130
  }
106
131
  __name(isNumberBetween, "isNumberBetween");
107
132
  function isAlpha(str) {
133
+ if (!str || typeof str !== "string") return false;
108
134
  return /^[a-zA-Z]+$/.test(str);
109
135
  }
110
136
  __name(isAlpha, "isAlpha");
@@ -118,36 +144,43 @@ function isStrongPassword(str) {
118
144
  }
119
145
  __name(isStrongPassword, "isStrongPassword");
120
146
  function isIPv4(str) {
147
+ if (!str || typeof str !== "string") return false;
121
148
  const parts = str.split(".");
122
149
  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;
150
+ return parts.every((p) => {
151
+ if (p.length > 3 || p.startsWith("0") && p.length > 1) return false;
152
+ const n = Number(p);
153
+ return Number.isInteger(n) && n >= 0 && n <= 255;
126
154
  });
127
155
  }
128
156
  __name(isIPv4, "isIPv4");
129
157
  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);
158
+ if (!str || typeof str !== "string" || str.length > 45) return false;
159
+ try {
160
+ return net.isIP(str) === 6;
161
+ } catch {
162
+ return false;
163
+ }
131
164
  }
132
165
  __name(isIPv6, "isIPv6");
133
166
  function isCreditCard(str) {
134
- const cardNumber = str.replace(/\D/g, "");
135
- if (cardNumber.length < 13 || cardNumber.length > 19) return false;
167
+ if (!str || typeof str !== "string") return false;
168
+ const s = str.replace(/\D/g, "");
169
+ if (s.length < 13 || s.length > 19) return false;
136
170
  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;
171
+ for (let i = 0, dbl = false; i < s.length; i++, dbl = !dbl) {
172
+ let d = s.charCodeAt(s.length - 1 - i) - 48;
173
+ if (dbl) {
174
+ d *= 2;
175
+ if (d > 9) d -= 9;
143
176
  }
144
- sum += digit;
145
- shouldDouble = !shouldDouble;
177
+ sum += d;
146
178
  }
147
179
  return sum % 10 === 0;
148
180
  }
149
181
  __name(isCreditCard, "isCreditCard");
150
182
  function isValidJSON(str) {
183
+ if (!str || typeof str !== "string") return false;
151
184
  try {
152
185
  JSON.parse(str);
153
186
  return true;
@@ -162,26 +195,36 @@ function isArray(value, itemGuard) {
162
195
  }
163
196
  __name(isArray, "isArray");
164
197
  function isBase64(str) {
165
- return /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(str);
198
+ if (!str || typeof str !== "string") return false;
199
+ return BASE64_REGEX.test(str);
166
200
  }
167
201
  __name(isBase64, "isBase64");
168
202
  function hasRequiredProps(obj, requiredProps) {
169
- return requiredProps.every((prop) => Object.prototype.hasOwnProperty.call(obj, prop) && obj[prop] !== void 0 && obj[prop] !== null);
203
+ if (!obj || typeof obj !== "object") return false;
204
+ return requiredProps.every((prop) => Object.hasOwn(obj, prop) && obj[prop] != null);
170
205
  }
171
206
  __name(hasRequiredProps, "hasRequiredProps");
172
207
  function isDateInRange(date, minDate, maxDate) {
173
- if (!(date instanceof Date) || isNaN(date.getTime())) return false;
208
+ if (!(date instanceof Date) || !Number.isFinite(date.getTime())) return false;
174
209
  if (minDate && date < minDate) return false;
175
210
  if (maxDate && date > maxDate) return false;
176
211
  return true;
177
212
  }
178
213
  __name(isDateInRange, "isDateInRange");
179
214
  function matchesPattern(str, pattern) {
215
+ if (typeof str !== "string") return false;
180
216
  return pattern.test(str);
181
217
  }
182
218
  __name(matchesPattern, "matchesPattern");
183
219
  function validateAll(value, validators) {
184
- return validators.every((validator) => validator(value));
220
+ if (!Array.isArray(validators)) return false;
221
+ return validators.every((fn) => {
222
+ try {
223
+ return fn(value);
224
+ } catch {
225
+ return false;
226
+ }
227
+ });
185
228
  }
186
229
  __name(validateAll, "validateAll");
187
230
 
@@ -1,191 +0,0 @@
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
- * Splits an array into chunks of the specified size.
27
- *
28
- * @template T The type of array elements.
29
- * @param {T[]} array - The array to split into chunks.
30
- * @param {number} size - The number of elements per chunk.
31
- * @returns {T[][]} A new array containing chunked arrays.
32
- * @throws {TypeError} If array is not an array.
33
- * @throws {Error} If chunk size is not a positive integer.
34
- */
35
- export declare function chunk<T>(array: readonly T[], size: number): T[][];
36
- /**
37
- * Removes duplicate values from an array.
38
- * Optionally enforces uniqueness by a key function.
39
- *
40
- * @template T The type of array elements.
41
- * @param {T[]} array - The input array.
42
- * @param {(item: T) => unknown} [keyFn] - Optional function to determine uniqueness by key.
43
- * @returns {T[]} A new array with unique values.
44
- */
45
- export declare function unique<T>(array: readonly T[], keyFn?: (item: T) => unknown): T[];
46
- /**
47
- * Deeply flattens a nested array to a single-level array.
48
- *
49
- * @template T The leaf type of array elements.
50
- * @param {any[]} array - The (possibly deeply nested) input array.
51
- * @returns {T[]} A deeply flattened array.
52
- */
53
- export declare function flattenDeep<T>(array: unknown[]): T[];
54
- /**
55
- * Returns a random element from an array, or undefined if empty.
56
- *
57
- * @template T The type of array elements.
58
- * @param {T[]} array - The input array.
59
- * @returns {T | undefined} A randomly selected item, or undefined if array is empty or not an array.
60
- */
61
- export declare function random<T>(array: readonly T[]): T | undefined;
62
- /**
63
- * Groups items in an array by a key or key function.
64
- *
65
- * @template T The type of array elements.
66
- * @overload
67
- * @param {T[]} array - The array to group.
68
- * @param {keyof T} key - Property key to group by.
69
- * @returns {Record<string, T[]>}
70
- * @overload
71
- * @param {T[]} array - The array to group.
72
- * @param {(item: T) => string | number | symbol} keyFn - Function to generate group key from item.
73
- * @returns {Record<K, T[]>}
74
- * @param {T[]} array - The array to group.
75
- * @param {keyof T | ((item: T) => string | number | symbol)} keyOrFn - Property key or key-generating function.
76
- * @returns {Record<string | number | symbol, T[]>} An object mapping group keys to item arrays.
77
- */
78
- export declare function groupBy<T>(array: T[], key: keyof T): Record<string, T[]>;
79
- export declare function groupBy<T, K extends string | number | symbol>(array: T[], keyFn: (item: T) => K): Record<K, T[]>;
80
- /**
81
- * Shuffles an array using the Fisher-Yates algorithm.
82
- *
83
- * @template T The type of array elements.
84
- * @param {T[]} array - The input array.
85
- * @returns {T[]} A new shuffled array.
86
- * @throws {TypeError} If array is not an array.
87
- */
88
- export declare function shuffle<T>(array: T[]): T[];
89
- /**
90
- * Returns an array of property values from an array of objects.
91
- *
92
- * @template T The type of array elements.
93
- * @template K The object property to pluck.
94
- * @param {T[]} array - The input array.
95
- * @param {K} key - The property name to pluck.
96
- * @returns {T[K][]} Array of property values.
97
- */
98
- export declare function pluck<T, K extends keyof T>(array: readonly T[], key: K): T[K][];
99
- /**
100
- * Returns values in array A that are not in array B.
101
- *
102
- * @template T The type of array elements.
103
- * @param {T[]} a - First array.
104
- * @param {T[]} b - Second array.
105
- * @returns {T[]} Elements in A that are not in B.
106
- */
107
- export declare function difference<T>(a: readonly T[], b: readonly T[]): T[];
108
- /**
109
- * Returns common values between arrays A and B.
110
- *
111
- * @template T The type of array elements.
112
- * @param {T[]} a - First array.
113
- * @param {T[]} b - Second array.
114
- * @returns {T[]} Elements that exist in both arrays.
115
- */
116
- export declare function intersect<T>(a: readonly T[], b: readonly T[]): T[];
117
- /**
118
- * Sorts an array of objects by a nested key using Merge Sort (O(n log n)).
119
- * Missing/undefined keys are sorted to the "end" (asc) or "start" (desc).
120
- *
121
- * @template T The type of array elements (objects).
122
- * @param {T[]} array - Array of objects to sort.
123
- * @param {string | ((item: T) => any)} key - Dot-notated key (e.g., "profile.age") or function.
124
- * @param {"asc" | "desc"} [direction="asc"] - Sort direction: 'asc' or 'desc'.
125
- * @returns {T[]} A new sorted array.
126
- * @throws {TypeError} If array is not an array.
127
- */
128
- export declare function mergeSort<T>(array: T[], key: string | ((item: T) => any), direction?: 'asc' | 'desc'): T[];
129
- /**
130
- * Combines multiple arrays into a single array of grouped elements.
131
- * Output array length equals the length of the shortest input array.
132
- *
133
- * @example zip([1, 2], ['a', 'b']) => [[1, 'a'], [2, 'b']]
134
- * @param {...Array<T>[]} arrays - Two or more arrays to zip together.
135
- * @returns {Array<T[]>} Array of grouped elements.
136
- */
137
- export declare function zip<T>(...arrays: ReadonlyArray<T>[]): T[][];
138
- /**
139
- * Splits an array into two arrays based on a predicate function.
140
- *
141
- * @template T The type of array elements.
142
- * @param {T[]} array - The input array.
143
- * @param {(item: T, index: number, array: T[]) => boolean} predicate - Function to test each element.
144
- * @returns {[T[], T[]]} A tuple of two arrays: [matched, unmatched].
145
- */
146
- export declare function partition<T>(array: T[], predicate: (item: T, index: number, array: T[]) => boolean): [T[], T[]];
147
- /**
148
- * Generates an array of numbers within a specified range.
149
- *
150
- * @param {number} start - Start of range (inclusive).
151
- * @param {number} end - End of range (exclusive).
152
- * @param {number} [step=1] - Step between numbers.
153
- * @returns {number[]} Array of numbers in range.
154
- */
155
- export declare function range(start: number, end: number, step?: number): number[];
156
- /**
157
- * Returns the first n elements of an array.
158
- *
159
- * @template T The type of array elements.
160
- * @param {T[]} array - The input array.
161
- * @param {number} [n=1] - Number of elements to take.
162
- * @returns {T[]} New array with first n elements.
163
- */
164
- export declare function take<T>(array: T[], n?: number): T[];
165
- /**
166
- * Takes elements from the array while predicate returns true.
167
- *
168
- * @template T The type of array elements.
169
- * @param {T[]} array - The input array.
170
- * @param {(item: T, index: number) => boolean} predicate - Function to test each element.
171
- * @returns {T[]} New array with taken elements.
172
- */
173
- export declare function takeWhile<T>(array: T[], predicate: (item: T, index: number) => boolean): T[];
174
- /**
175
- * Removes all falsy values from an array.
176
- * False, null, 0, "", undefined, and NaN are falsy.
177
- *
178
- * @template T The type of array elements.
179
- * @param {T[]} array - The input array.
180
- * @returns {NonNullable<T>[]} New array with falsy values removed.
181
- */
182
- export declare function compact<T>(array: T[]): NonNullable<T>[];
183
- /**
184
- * Counts array elements by a key function.
185
- *
186
- * @template T The type of array elements.
187
- * @param {T[]} array - The input array.
188
- * @param {(item: T) => string | number | symbol} keyFn - Function to generate count key.
189
- * @returns {Record<string, number>} Object with counts by key.
190
- */
191
- export declare function countBy<T>(array: T[], keyFn: (item: T) => string | number | symbol): Record<string, number>;