@catbee/utils 2.0.0-next.0 → 2.0.0-next.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.
Files changed (97) hide show
  1. package/README.md +52 -16
  2. package/array/index.cjs +180 -71
  3. package/array/index.d.ts +293 -1
  4. package/array/index.mjs +171 -72
  5. package/async/index.cjs +92 -36
  6. package/async/index.d.ts +275 -1
  7. package/async/index.mjs +92 -36
  8. package/cache/index.cjs +1 -1
  9. package/cache/index.d.ts +155 -1
  10. package/cache/index.mjs +2 -2
  11. package/config/index.cjs +78 -64
  12. package/config/index.d.ts +64 -2
  13. package/config/index.mjs +76 -64
  14. package/context-store/index.d.ts +192 -1
  15. package/crypto/index.d.ts +163 -1
  16. package/date/index.cjs +46 -1
  17. package/date/index.d.ts +190 -1
  18. package/date/index.mjs +45 -2
  19. package/decorators/index.cjs +1156 -18
  20. package/decorators/index.d.ts +684 -1
  21. package/decorators/index.mjs +1156 -18
  22. package/dir/index.cjs +4 -3
  23. package/dir/index.d.ts +195 -1
  24. package/dir/index.mjs +4 -3
  25. package/env/index.cjs +10 -26
  26. package/env/index.d.ts +379 -1
  27. package/env/index.mjs +10 -26
  28. package/exception/index.d.ts +232 -1
  29. package/fs/index.cjs +70 -36
  30. package/fs/index.d.ts +205 -1
  31. package/fs/index.mjs +64 -34
  32. package/http-status-codes/index.d.ts +267 -1
  33. package/id/index.d.ts +37 -1
  34. package/index.cjs +3 -3
  35. package/index.d.ts +1 -1
  36. package/index.mjs +1 -1
  37. package/logger/index.cjs +11 -11
  38. package/logger/index.d.ts +189 -1
  39. package/logger/index.mjs +12 -12
  40. package/middleware/index.d.ts +103 -1
  41. package/obj/index.cjs +150 -162
  42. package/obj/index.d.ts +136 -1
  43. package/obj/index.mjs +150 -162
  44. package/package.json +11 -11
  45. package/performance/index.cjs +2 -2
  46. package/performance/index.d.ts +138 -1
  47. package/performance/index.mjs +2 -2
  48. package/request/index.cjs +1 -1
  49. package/request/index.d.ts +241 -2
  50. package/request/index.mjs +1 -1
  51. package/response/index.d.ts +318 -2
  52. package/server/index.cjs +27 -23
  53. package/server/index.d.ts +785 -4
  54. package/server/index.mjs +28 -23
  55. package/stream/index.d.ts +90 -1
  56. package/string/index.d.ts +102 -1
  57. package/type/index.cjs +1 -1
  58. package/type/index.d.ts +107 -1
  59. package/type/index.mjs +1 -1
  60. package/types/index.d.ts +774 -4
  61. package/url/index.cjs +2 -4
  62. package/url/index.d.ts +142 -1
  63. package/url/index.mjs +2 -4
  64. package/{validate → validation}/index.cjs +89 -42
  65. package/{validate/validate.utils.d.ts → validation/index.d.ts} +32 -23
  66. package/{validate → validation}/index.mjs +85 -42
  67. package/array/array.utils.d.ts +0 -191
  68. package/async/async.utils.d.ts +0 -296
  69. package/cache/cache.utils.d.ts +0 -176
  70. package/config/config.d.ts +0 -57
  71. package/context-store/context-store.utils.d.ts +0 -212
  72. package/crypto/crypto.utils.d.ts +0 -183
  73. package/date/date.utils.d.ts +0 -190
  74. package/decorators/decorators.utils.d.ts +0 -705
  75. package/dir/dir.utils.d.ts +0 -216
  76. package/env/env.utils.d.ts +0 -400
  77. package/exception/exception.utils.d.ts +0 -253
  78. package/fs/fs.utils.d.ts +0 -196
  79. package/http-status-codes/http-status-codes.d.ts +0 -289
  80. package/id/id.utils.d.ts +0 -59
  81. package/logger/logger.utils.d.ts +0 -210
  82. package/middleware/middleware.utils.d.ts +0 -123
  83. package/obj/obj.utils.d.ts +0 -156
  84. package/performance/performance.utils.d.ts +0 -159
  85. package/request/request.utils.d.ts +0 -109
  86. package/response/response.utils.d.ts +0 -186
  87. package/server/server.builder.d.ts +0 -531
  88. package/server/server.d.ts +0 -303
  89. package/stream/stream.utils.d.ts +0 -111
  90. package/string/string.utils.d.ts +0 -124
  91. package/type/type.utils.d.ts +0 -129
  92. package/types/api-response.d.ts +0 -175
  93. package/types/common.d.ts +0 -148
  94. package/types/config.d.ts +0 -88
  95. package/types/server.d.ts +0 -291
  96. package/url/url.utils.d.ts +0 -164
  97. package/validate/index.d.ts +0 -25
package/url/index.cjs CHANGED
@@ -90,10 +90,8 @@ function joinPaths(...segments) {
90
90
  __name(joinPaths, "joinPaths");
91
91
  function normalizeUrl(url$1, base) {
92
92
  try {
93
- if (url$1.startsWith("//")) {
94
- url$1 = `https:${url$1}`;
95
- }
96
- const parsedUrl = base ? new url.URL(url$1, base) : new url.URL(url$1);
93
+ let normalized = url$1.startsWith("//") ? `https:${url$1}` : url$1;
94
+ const parsedUrl = base ? new url.URL(normalized, base) : new url.URL(normalized);
97
95
  parsedUrl.pathname = parsedUrl.pathname.replace(/\/+/g, "/");
98
96
  parsedUrl.pathname = parsedUrl.pathname.replace(/\/+$/, "");
99
97
  parsedUrl.hostname = parsedUrl.hostname.toLowerCase();
package/url/index.d.ts CHANGED
@@ -22,4 +22,145 @@
22
22
  * SOFTWARE.
23
23
  */
24
24
 
25
- export * from './url.utils';
25
+ /**
26
+ * Appends query parameters to a given URL.
27
+ *
28
+ * @param {string} url - The base URL to which query parameters will be appended.
29
+ * @param {Record<string, string | number>} params - Key-value pairs to add as query parameters.
30
+ * @returns {string} The new URL string with query parameters appended.
31
+ *
32
+ * @example
33
+ * appendQueryParams('https://example.com', { page: 1, limit: 10 });
34
+ * // -> 'https://example.com/?page=1&limit=10'
35
+ */
36
+ declare function appendQueryParams(url: string, params: Record<string, string | number>): string;
37
+ /**
38
+ * Parses a query string into a key-value object.
39
+ *
40
+ * @param {string} query - The query string (with or without leading '?').
41
+ * @returns {Record<string, string>} Object representing parsed query parameters.
42
+ *
43
+ * @example
44
+ * parseQueryString('?page=1&limit=10');
45
+ * // -> { page: '1', limit: '10' }
46
+ */
47
+ declare function parseQueryString(query: string): Record<string, string>;
48
+ /**
49
+ * Validates if a string is a valid URL.
50
+ *
51
+ * @param {string} url - The URL string to validate.
52
+ * @param {boolean} [requireHttps=false] - If true, requires the URL to use HTTPS.
53
+ * @returns {boolean} True if the URL is valid, false otherwise.
54
+ */
55
+ declare function isValidUrl(url: string, requireHttps?: boolean): boolean;
56
+ /**
57
+ * Extracts the domain name from a URL.
58
+ *
59
+ * @param {string} url - The URL to extract the domain from.
60
+ * @param {boolean} [removeSubdomains=false] - If true, removes subdomains (returns root domain only).
61
+ * @returns {string} The domain name.
62
+ *
63
+ * @example
64
+ * getDomain('https://api.example.com/path');
65
+ * // -> 'api.example.com'
66
+ *
67
+ * getDomain('https://api.example.com/path', true);
68
+ * // -> 'example.com'
69
+ */
70
+ declare function getDomain(url: string, removeSubdomains?: boolean): string;
71
+ /**
72
+ * Joins URL paths properly handling slashes.
73
+ *
74
+ * @param {...string[]} segments - URL path segments to join.
75
+ * @returns {string} Joined URL path.
76
+ *
77
+ * @example
78
+ * joinPaths('https://example.com/', '/api/', '/users');
79
+ * // -> 'https://example.com/api/users'
80
+ */
81
+ declare function joinPaths(...segments: string[]): string;
82
+ /**
83
+ * Normalizes a URL by resolving relative paths, handling protocol-relative URLs, etc.
84
+ *
85
+ * @param {string} url - The URL to normalize.
86
+ * @param {string} [base] - Optional base URL for resolving relative URLs.
87
+ * @returns {string} Normalized URL.
88
+ *
89
+ * @example
90
+ * normalizeUrl('HTTP://Example.COM/foo/../bar');
91
+ * // -> 'http://example.com/bar'
92
+ */
93
+ declare function normalizeUrl(url: string, base?: string): string;
94
+ /**
95
+ * Creates a URL builder for constructing URLs with a base URL.
96
+ *
97
+ * @param {string} baseUrl - The base URL to build upon.
98
+ * @returns {Object} URL builder methods.
99
+ *
100
+ * @example
101
+ * const api = createUrlBuilder('https://api.example.com');
102
+ * api.path('/users', { active: true });
103
+ * // -> 'https://api.example.com/users?active=true'
104
+ */
105
+ declare function createUrlBuilder(baseUrl: string): {
106
+ /**
107
+ * Creates a full URL with the given path and query parameters.
108
+ *
109
+ * @param {string} path - The path to append to the base URL.
110
+ * @param {Record<string, any>} [params] - Query parameters to add.
111
+ * @returns {string} The complete URL.
112
+ */
113
+ path(path: string, params?: Record<string, any>): string;
114
+ /**
115
+ * Creates a full URL with query parameters but no additional path.
116
+ *
117
+ * @param {Record<string, any>} params - Query parameters to add.
118
+ * @returns {string} The complete URL with query parameters.
119
+ */
120
+ query(params: Record<string, any>): string;
121
+ };
122
+ /**
123
+ * Extracts specific query parameters from a URL.
124
+ *
125
+ * @param {string} url - The URL to extract parameters from.
126
+ * @param {string[]} paramNames - Names of parameters to extract.
127
+ * @returns {Record<string, string>} Object containing the extracted parameters.
128
+ */
129
+ declare function extractQueryParams(url: string, paramNames: string[]): Record<string, string>;
130
+ /**
131
+ * Removes specified query parameters from a URL.
132
+ *
133
+ * @param {string} url - The URL to modify.
134
+ * @param {string[]} paramsToRemove - Names of parameters to remove.
135
+ * @returns {string} URL with parameters removed.
136
+ */
137
+ declare function removeQueryParams(url: string, paramsToRemove: string[]): string;
138
+ /**
139
+ * Gets the file extension from a URL path.
140
+ *
141
+ * @param {string} url - The URL to examine.
142
+ * @returns {string} The file extension (without dot) or empty string if none found.
143
+ *
144
+ * @example
145
+ * getExtension('https://example.com/document.pdf?v=1');
146
+ * // -> 'pdf'
147
+ */
148
+ declare function getExtension(url: string): string;
149
+ /**
150
+ * Parses URL query parameters into a strongly-typed object.
151
+ *
152
+ * @template T Expected type of the query parameters
153
+ * @param {string} url - The URL to parse.
154
+ * @param {Record<keyof T, (val: string) => any>} [converters] - Type converters for params.
155
+ * @returns {Partial<T>} Typed query parameters.
156
+ *
157
+ * @example
158
+ * parseTypedQueryParams<{page: number, q: string}>('https://example.com?page=2&q=test', {
159
+ * page: Number,
160
+ * q: String
161
+ * });
162
+ * // -> { page: 2, q: 'test' }
163
+ */
164
+ declare function parseTypedQueryParams<T extends Record<string, any>>(url: string, converters?: Record<keyof T, (val: string) => any>): Partial<T>;
165
+
166
+ export { appendQueryParams, createUrlBuilder, extractQueryParams, getDomain, getExtension, isValidUrl, joinPaths, normalizeUrl, parseQueryString, parseTypedQueryParams, removeQueryParams };
package/url/index.mjs CHANGED
@@ -88,10 +88,8 @@ function joinPaths(...segments) {
88
88
  __name(joinPaths, "joinPaths");
89
89
  function normalizeUrl(url, base) {
90
90
  try {
91
- if (url.startsWith("//")) {
92
- url = `https:${url}`;
93
- }
94
- const parsedUrl = base ? new URL(url, base) : new URL(url);
91
+ let normalized = url.startsWith("//") ? `https:${url}` : url;
92
+ const parsedUrl = base ? new URL(normalized, base) : new URL(normalized);
95
93
  parsedUrl.pathname = parsedUrl.pathname.replace(/\/+/g, "/");
96
94
  parsedUrl.pathname = parsedUrl.pathname.replace(/\/+$/, "");
97
95
  parsedUrl.hostname = parsedUrl.hostname.toLowerCase();
@@ -24,25 +24,41 @@
24
24
 
25
25
  'use strict';
26
26
 
27
+ var net = require('net');
28
+
29
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
30
+
31
+ var net__default = /*#__PURE__*/_interopDefault(net);
32
+
27
33
  var __defProp = Object.defineProperty;
28
34
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
29
-
30
- // src/validate/validate.utils.ts
35
+ var PORT_REGEX = /^[0-9]{1,5}$/;
36
+ 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;
37
+ var PHONE_ALLOWED_CHARS_REGEX = /^[+]?[0-9\s().-]+$/;
38
+ var ALPHANUMERIC_REGEX = /^[A-Za-z0-9]+$/;
39
+ var HEX_COLOR_REGEX = /^#([a-f0-9]{6}|[a-f0-9]{3})$/i;
40
+ var ISO_DATE_REGEX = /^\d{4}-\d{2}-\d{2}(T\d{2}:\d{2}:\d{2}(\.\d+)?(Z|[+-]\d{2}:\d{2})?)?$/;
41
+ var BASE64_REGEX = /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/;
42
+ var DOT_ATOM_REGEX = /^[A-Za-z0-9!#$%&'*+/=?^_`{|}~-]+(\.[A-Za-z0-9!#$%&'*+/=?^_`{|}~-]+)*$/;
43
+ var QUOTED_LOCAL_REGEX = /^"([\s\x21\x23-\x5B\x5D-\x7E]|\\[\x20-\x7E])*"$/;
44
+ var TLD_REGEX = /^[A-Za-z]{2,63}$/;
31
45
  function isPort(value) {
32
- const port = typeof value === "string" ? Number(value.trim()) : value;
46
+ if (typeof value === "number") return Number.isInteger(value) && value > 0 && value <= 65535;
47
+ if (!value || typeof value !== "string") return false;
48
+ const str = value.trim();
49
+ if (!PORT_REGEX.test(str)) return false;
50
+ const port = Number(str);
33
51
  return Number.isInteger(port) && port > 0 && port <= 65535;
34
52
  }
35
53
  __name(isPort, "isPort");
36
54
  function isEmail(str) {
37
- if (typeof str !== "string" || str.length > 254) return false;
55
+ if (!str || typeof str !== "string" || str.length > 254) return false;
38
56
  const atIndex = str.indexOf("@");
39
57
  if (atIndex === -1 || atIndex !== str.lastIndexOf("@")) return false;
40
58
  const local = str.slice(0, atIndex);
41
59
  const domain = str.slice(atIndex + 1);
42
60
  if (!local || !domain) return false;
43
- const dotAtom = /^[A-Za-z0-9!#$%&'*+/=?^_`{|}~-]+(\.[A-Za-z0-9!#$%&'*+/=?^_`{|}~-]+)*$/;
44
- const quotedLocal = /^"([\s\x21\x23-\x5B\x5D-\x7E]|\\[\x20-\x7E])*"$/;
45
- if (!dotAtom.test(local) && !quotedLocal.test(local)) return false;
61
+ if (!DOT_ATOM_REGEX.test(local) && !QUOTED_LOCAL_REGEX.test(local)) return false;
46
62
  if (domain.includes("..")) return false;
47
63
  const labels = domain.split(".");
48
64
  if (labels.some((l) => !l.length)) return false;
@@ -53,60 +69,74 @@ function isEmail(str) {
53
69
  if (label.startsWith("-") || label.endsWith("-")) return false;
54
70
  }
55
71
  const tld = labels[labels.length - 1];
56
- if (!/^[A-Za-z]{2,63}$/.test(tld)) return false;
72
+ if (!TLD_REGEX.test(tld)) return false;
57
73
  return true;
58
74
  }
59
75
  __name(isEmail, "isEmail");
60
76
  function isUUID(str) {
61
- 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);
77
+ return UUID_REGEX.test(str);
62
78
  }
63
79
  __name(isUUID, "isUUID");
64
- function isURL(str) {
80
+ function isURL(str, allowedProtocols = [
81
+ "http",
82
+ "https",
83
+ "ws",
84
+ "wss"
85
+ ]) {
86
+ if (!str || typeof str !== "string") return false;
65
87
  try {
66
- new URL(str);
67
- return true;
88
+ const url = new URL(str);
89
+ return allowedProtocols.includes(url.protocol.replace(":", ""));
68
90
  } catch {
69
91
  return false;
70
92
  }
71
93
  }
72
94
  __name(isURL, "isURL");
73
95
  function isPhone(str) {
74
- if (typeof str !== "string") return false;
75
- const digitsOnly = str.replace(/\D/g, "");
76
- if (digitsOnly.length < 6 || digitsOnly.length > 15) return false;
77
- return /^[+]?[\d\s().-]+$/.test(str);
96
+ if (!str || typeof str !== "string") return false;
97
+ const digits = str.replace(/\D/g, "");
98
+ if (digits.length < 6 || digits.length > 15) return false;
99
+ return PHONE_ALLOWED_CHARS_REGEX.test(str);
78
100
  }
79
101
  __name(isPhone, "isPhone");
80
102
  function isAlphanumeric(str) {
81
- return /^[a-z0-9]+$/i.test(str);
103
+ if (!str || typeof str !== "string") return false;
104
+ return ALPHANUMERIC_REGEX.test(str);
82
105
  }
83
106
  __name(isAlphanumeric, "isAlphanumeric");
84
107
  function isNumeric(value) {
85
- if (typeof value === "string" && value.trim() === "") return false;
86
- const num = typeof value === "number" ? value : Number(value);
87
- return typeof num === "number" && isFinite(num);
108
+ if (typeof value === "number") return Number.isFinite(value);
109
+ if (!value || typeof value !== "string") return false;
110
+ const str = value.trim();
111
+ if (str === "" || str.length > 16) return false;
112
+ const num = Number(str);
113
+ return Number.isFinite(num);
88
114
  }
89
115
  __name(isNumeric, "isNumeric");
90
116
  function isHexColor(str) {
91
- return /^#([a-f0-9]{6}|[a-f0-9]{3})$/i.test(str);
117
+ if (!str || typeof str !== "string") return false;
118
+ return HEX_COLOR_REGEX.test(str);
92
119
  }
93
120
  __name(isHexColor, "isHexColor");
94
121
  function isISODate(str) {
95
- const isoRegex = /^\d{4}-\d{2}-\d{2}(T\d{2}:\d{2}:\d{2}(\.\d+)?(Z|[+-]\d{2}:\d{2})?)?$/;
96
- if (!isoRegex.test(str)) return false;
122
+ if (!str || typeof str !== "string") return false;
123
+ if (!ISO_DATE_REGEX.test(str)) return false;
97
124
  const date = new Date(str);
98
- return !isNaN(date.getTime()) && date.toISOString().startsWith(str.slice(0, 10));
125
+ return !Number.isNaN(date.getTime());
99
126
  }
100
127
  __name(isISODate, "isISODate");
101
128
  function isLengthBetween(str, min, max) {
129
+ if (typeof str !== "string") return false;
102
130
  return str.length >= min && str.length <= max;
103
131
  }
104
132
  __name(isLengthBetween, "isLengthBetween");
105
133
  function isNumberBetween(value, min, max) {
134
+ if (typeof value !== "number" || !Number.isFinite(value)) return false;
106
135
  return value >= min && value <= max;
107
136
  }
108
137
  __name(isNumberBetween, "isNumberBetween");
109
138
  function isAlpha(str) {
139
+ if (!str || typeof str !== "string") return false;
110
140
  return /^[a-zA-Z]+$/.test(str);
111
141
  }
112
142
  __name(isAlpha, "isAlpha");
@@ -120,36 +150,43 @@ function isStrongPassword(str) {
120
150
  }
121
151
  __name(isStrongPassword, "isStrongPassword");
122
152
  function isIPv4(str) {
153
+ if (!str || typeof str !== "string") return false;
123
154
  const parts = str.split(".");
124
155
  if (parts.length !== 4) return false;
125
- return parts.every((part) => {
126
- const num = parseInt(part, 10);
127
- return part === num.toString() && num >= 0 && num <= 255;
156
+ return parts.every((p) => {
157
+ if (p.length > 3 || p.startsWith("0") && p.length > 1) return false;
158
+ const n = Number(p);
159
+ return Number.isInteger(n) && n >= 0 && n <= 255;
128
160
  });
129
161
  }
130
162
  __name(isIPv4, "isIPv4");
131
163
  function isIPv6(str) {
132
- 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);
164
+ if (!str || typeof str !== "string" || str.length > 45) return false;
165
+ try {
166
+ return net__default.default.isIP(str) === 6;
167
+ } catch {
168
+ return false;
169
+ }
133
170
  }
134
171
  __name(isIPv6, "isIPv6");
135
172
  function isCreditCard(str) {
136
- const cardNumber = str.replace(/\D/g, "");
137
- if (cardNumber.length < 13 || cardNumber.length > 19) return false;
173
+ if (!str || typeof str !== "string") return false;
174
+ const s = str.replace(/\D/g, "");
175
+ if (s.length < 13 || s.length > 19) return false;
138
176
  let sum = 0;
139
- let shouldDouble = false;
140
- for (let i = cardNumber.length - 1; i >= 0; i--) {
141
- let digit = parseInt(cardNumber.charAt(i), 10);
142
- if (shouldDouble) {
143
- digit *= 2;
144
- if (digit > 9) digit -= 9;
177
+ for (let i = 0, dbl = false; i < s.length; i++, dbl = !dbl) {
178
+ let d = s.charCodeAt(s.length - 1 - i) - 48;
179
+ if (dbl) {
180
+ d *= 2;
181
+ if (d > 9) d -= 9;
145
182
  }
146
- sum += digit;
147
- shouldDouble = !shouldDouble;
183
+ sum += d;
148
184
  }
149
185
  return sum % 10 === 0;
150
186
  }
151
187
  __name(isCreditCard, "isCreditCard");
152
188
  function isValidJSON(str) {
189
+ if (!str || typeof str !== "string") return false;
153
190
  try {
154
191
  JSON.parse(str);
155
192
  return true;
@@ -164,26 +201,36 @@ function isArray(value, itemGuard) {
164
201
  }
165
202
  __name(isArray, "isArray");
166
203
  function isBase64(str) {
167
- return /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(str);
204
+ if (!str || typeof str !== "string") return false;
205
+ return BASE64_REGEX.test(str);
168
206
  }
169
207
  __name(isBase64, "isBase64");
170
208
  function hasRequiredProps(obj, requiredProps) {
171
- return requiredProps.every((prop) => Object.prototype.hasOwnProperty.call(obj, prop) && obj[prop] !== void 0 && obj[prop] !== null);
209
+ if (!obj || typeof obj !== "object") return false;
210
+ return requiredProps.every((prop) => Object.prototype.hasOwnProperty.call(obj, prop) && obj[prop] != null);
172
211
  }
173
212
  __name(hasRequiredProps, "hasRequiredProps");
174
213
  function isDateInRange(date, minDate, maxDate) {
175
- if (!(date instanceof Date) || isNaN(date.getTime())) return false;
214
+ if (!(date instanceof Date) || !Number.isFinite(date.getTime())) return false;
176
215
  if (minDate && date < minDate) return false;
177
216
  if (maxDate && date > maxDate) return false;
178
217
  return true;
179
218
  }
180
219
  __name(isDateInRange, "isDateInRange");
181
220
  function matchesPattern(str, pattern) {
221
+ if (typeof str !== "string") return false;
182
222
  return pattern.test(str);
183
223
  }
184
224
  __name(matchesPattern, "matchesPattern");
185
225
  function validateAll(value, validators) {
186
- return validators.every((validator) => validator(value));
226
+ if (!Array.isArray(validators)) return false;
227
+ return validators.every((fn) => {
228
+ try {
229
+ return fn(value);
230
+ } catch {
231
+ return false;
232
+ }
233
+ });
187
234
  }
188
235
  __name(validateAll, "validateAll");
189
236
 
@@ -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 };