@catbee/utils 1.1.0 → 2.0.0-next.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (121) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +27 -27
  3. package/array/array.utils.d.ts +191 -0
  4. package/array/index.cjs +246 -0
  5. package/array/index.d.ts +25 -0
  6. package/array/index.mjs +228 -0
  7. package/async/async.utils.d.ts +296 -0
  8. package/async/index.cjs +428 -0
  9. package/async/index.d.ts +25 -0
  10. package/async/index.mjs +407 -0
  11. package/cache/cache.utils.d.ts +176 -0
  12. package/cache/index.cjs +292 -0
  13. package/cache/index.d.ts +25 -0
  14. package/cache/index.mjs +290 -0
  15. package/config/config.d.ts +57 -0
  16. package/config/index.cjs +136 -0
  17. package/config/index.d.ts +26 -0
  18. package/config/index.mjs +131 -0
  19. package/context-store/context-store.utils.d.ts +212 -0
  20. package/context-store/index.cjs +267 -0
  21. package/context-store/index.d.ts +25 -0
  22. package/context-store/index.mjs +261 -0
  23. package/crypto/crypto.utils.d.ts +183 -0
  24. package/crypto/index.cjs +182 -0
  25. package/crypto/index.d.ts +25 -0
  26. package/crypto/index.mjs +166 -0
  27. package/date/date.utils.d.ts +190 -0
  28. package/date/index.cjs +295 -0
  29. package/date/index.d.ts +25 -0
  30. package/date/index.mjs +283 -0
  31. package/decorators/decorators.utils.d.ts +705 -0
  32. package/decorators/index.cjs +913 -0
  33. package/decorators/index.d.ts +25 -0
  34. package/decorators/index.mjs +872 -0
  35. package/dir/dir.utils.d.ts +216 -0
  36. package/dir/index.cjs +416 -0
  37. package/dir/index.d.ts +25 -0
  38. package/dir/index.mjs +389 -0
  39. package/env/env.utils.d.ts +400 -0
  40. package/env/index.cjs +761 -0
  41. package/env/index.d.ts +25 -0
  42. package/env/index.mjs +758 -0
  43. package/exception/exception.utils.d.ts +253 -0
  44. package/exception/index.cjs +362 -0
  45. package/exception/index.d.ts +25 -0
  46. package/exception/index.mjs +338 -0
  47. package/fs/fs.utils.d.ts +196 -0
  48. package/fs/index.cjs +253 -0
  49. package/fs/index.d.ts +25 -0
  50. package/fs/index.mjs +228 -0
  51. package/http-status-codes/http-status-codes.d.ts +289 -0
  52. package/http-status-codes/index.cjs +96 -0
  53. package/http-status-codes/index.d.ts +25 -0
  54. package/http-status-codes/index.mjs +94 -0
  55. package/id/id.utils.d.ts +59 -0
  56. package/id/index.cjs +62 -0
  57. package/id/index.d.ts +25 -0
  58. package/id/index.mjs +56 -0
  59. package/index.cjs +218 -0
  60. package/index.d.ts +51 -0
  61. package/index.mjs +51 -0
  62. package/logger/index.cjs +334 -0
  63. package/logger/index.d.ts +25 -0
  64. package/logger/index.mjs +313 -0
  65. package/logger/logger.utils.d.ts +210 -0
  66. package/middleware/index.cjs +177 -0
  67. package/middleware/index.d.ts +25 -0
  68. package/middleware/index.mjs +170 -0
  69. package/middleware/middleware.utils.d.ts +123 -0
  70. package/obj/index.cjs +317 -0
  71. package/obj/index.d.ts +25 -0
  72. package/obj/index.mjs +301 -0
  73. package/obj/obj.utils.d.ts +156 -0
  74. package/package.json +171 -19
  75. package/performance/index.cjs +231 -0
  76. package/performance/index.d.ts +25 -0
  77. package/performance/index.mjs +225 -0
  78. package/performance/performance.utils.d.ts +159 -0
  79. package/request/index.cjs +202 -0
  80. package/request/index.d.ts +26 -0
  81. package/request/index.mjs +194 -0
  82. package/request/request.utils.d.ts +109 -0
  83. package/response/index.cjs +234 -0
  84. package/response/index.d.ts +26 -0
  85. package/response/index.mjs +222 -0
  86. package/response/response.utils.d.ts +186 -0
  87. package/server/index.cjs +1627 -0
  88. package/server/index.d.ts +28 -0
  89. package/server/index.mjs +1617 -0
  90. package/server/server.builder.d.ts +531 -0
  91. package/server/server.d.ts +303 -0
  92. package/stream/index.cjs +151 -0
  93. package/stream/index.d.ts +25 -0
  94. package/stream/index.mjs +144 -0
  95. package/stream/stream.utils.d.ts +111 -0
  96. package/string/index.cjs +109 -0
  97. package/string/index.d.ts +25 -0
  98. package/string/index.mjs +95 -0
  99. package/string/string.utils.d.ts +124 -0
  100. package/type/index.cjs +129 -0
  101. package/type/index.d.ts +25 -0
  102. package/type/index.mjs +119 -0
  103. package/type/type.utils.d.ts +129 -0
  104. package/types/api-response.d.ts +175 -0
  105. package/types/common.d.ts +148 -0
  106. package/types/config.d.ts +88 -0
  107. package/types/index.cjs +34 -0
  108. package/types/index.d.ts +28 -0
  109. package/types/index.mjs +32 -0
  110. package/types/server.d.ts +291 -0
  111. package/url/index.cjs +201 -0
  112. package/url/index.d.ts +25 -0
  113. package/url/index.mjs +189 -0
  114. package/url/url.utils.d.ts +164 -0
  115. package/validate/index.cjs +212 -0
  116. package/validate/index.d.ts +25 -0
  117. package/validate/index.mjs +188 -0
  118. package/validate/validate.utils.d.ts +200 -0
  119. package/build/index.cjs +0 -7694
  120. package/build/index.d.ts +0 -5792
  121. package/build/index.mjs +0 -7386
package/url/index.mjs ADDED
@@ -0,0 +1,189 @@
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
+ import { URL, URLSearchParams } from 'url';
26
+
27
+ var __defProp = Object.defineProperty;
28
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
29
+ function appendQueryParams(url, params) {
30
+ const urlObj = new URL(url);
31
+ for (const [key, value] of Object.entries(params)) {
32
+ urlObj.searchParams.set(key, value.toString());
33
+ }
34
+ return urlObj.toString();
35
+ }
36
+ __name(appendQueryParams, "appendQueryParams");
37
+ function parseQueryString(query) {
38
+ const cleanQuery = query.startsWith("?") ? query.slice(1) : query;
39
+ return Object.fromEntries(new URLSearchParams(cleanQuery));
40
+ }
41
+ __name(parseQueryString, "parseQueryString");
42
+ function isValidUrl(url, requireHttps = false) {
43
+ try {
44
+ const parsedUrl = new URL(url);
45
+ if (!parsedUrl.protocol || !parsedUrl.hostname) return false;
46
+ if (requireHttps && parsedUrl.protocol !== "https:") return false;
47
+ return true;
48
+ } catch {
49
+ return false;
50
+ }
51
+ }
52
+ __name(isValidUrl, "isValidUrl");
53
+ function getDomain(url, removeSubdomains = false) {
54
+ try {
55
+ const { hostname } = new URL(url);
56
+ if (!removeSubdomains) {
57
+ return hostname;
58
+ }
59
+ const parts = hostname.split(".");
60
+ if (parts.length <= 2) return hostname;
61
+ const secondLevelDomains = [
62
+ "co",
63
+ "com",
64
+ "org",
65
+ "net",
66
+ "gov",
67
+ "edu",
68
+ "ac"
69
+ ];
70
+ const sld = parts[parts.length - 2];
71
+ if (secondLevelDomains.includes(sld) && parts.length > 2) {
72
+ return parts.slice(-3).join(".");
73
+ }
74
+ return parts.slice(-2).join(".");
75
+ } catch {
76
+ return "";
77
+ }
78
+ }
79
+ __name(getDomain, "getDomain");
80
+ function joinPaths(...segments) {
81
+ let result = segments.filter((s) => s !== void 0 && s !== null).map((segment, index) => {
82
+ if (index === 0) return segment.replace(/\/+$/, "");
83
+ return segment.replace(/^\/+|\/+$/g, "");
84
+ }).filter(Boolean).join("/");
85
+ if (segments[0] === "" && !result.startsWith("/")) result = "/" + result;
86
+ return result;
87
+ }
88
+ __name(joinPaths, "joinPaths");
89
+ function normalizeUrl(url, base) {
90
+ try {
91
+ if (url.startsWith("//")) {
92
+ url = `https:${url}`;
93
+ }
94
+ const parsedUrl = base ? new URL(url, base) : new URL(url);
95
+ parsedUrl.pathname = parsedUrl.pathname.replace(/\/+/g, "/");
96
+ parsedUrl.pathname = parsedUrl.pathname.replace(/\/+$/, "");
97
+ parsedUrl.hostname = parsedUrl.hostname.toLowerCase();
98
+ return parsedUrl.toString();
99
+ } catch {
100
+ return url;
101
+ }
102
+ }
103
+ __name(normalizeUrl, "normalizeUrl");
104
+ function createUrlBuilder(baseUrl) {
105
+ return {
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, params) {
114
+ const url = joinPaths(baseUrl, path);
115
+ return params ? appendQueryParams(url, params) : url;
116
+ },
117
+ /**
118
+ * Creates a full URL with query parameters but no additional path.
119
+ *
120
+ * @param {Record<string, any>} params - Query parameters to add.
121
+ * @returns {string} The complete URL with query parameters.
122
+ */
123
+ query(params) {
124
+ return appendQueryParams(baseUrl, params);
125
+ }
126
+ };
127
+ }
128
+ __name(createUrlBuilder, "createUrlBuilder");
129
+ function extractQueryParams(url, paramNames) {
130
+ try {
131
+ const parsedUrl = new URL(url);
132
+ const result = {};
133
+ for (const name of paramNames) {
134
+ const value = parsedUrl.searchParams.get(name);
135
+ if (value !== null) {
136
+ result[name] = value;
137
+ }
138
+ }
139
+ return result;
140
+ } catch {
141
+ return {};
142
+ }
143
+ }
144
+ __name(extractQueryParams, "extractQueryParams");
145
+ function removeQueryParams(url, paramsToRemove) {
146
+ try {
147
+ const parsedUrl = new URL(url);
148
+ for (const param of paramsToRemove) {
149
+ parsedUrl.searchParams.delete(param);
150
+ }
151
+ return parsedUrl.toString();
152
+ } catch {
153
+ return url;
154
+ }
155
+ }
156
+ __name(removeQueryParams, "removeQueryParams");
157
+ function getExtension(url) {
158
+ try {
159
+ const { pathname } = new URL(url);
160
+ const match = pathname.match(/\.([^./\\?#]+)$/);
161
+ return match ? match[1].toLowerCase() : "";
162
+ } catch {
163
+ const match = url.match(/\.([^./\\?#]+)$/);
164
+ return match ? match[1].toLowerCase() : "";
165
+ }
166
+ }
167
+ __name(getExtension, "getExtension");
168
+ function parseTypedQueryParams(url, converters) {
169
+ try {
170
+ const { searchParams } = new URL(url);
171
+ const result = {};
172
+ for (const [key, value] of searchParams.entries()) {
173
+ if (converters && key in converters) {
174
+ try {
175
+ result[key] = converters[key](value);
176
+ } catch {
177
+ }
178
+ } else {
179
+ result[key] = value;
180
+ }
181
+ }
182
+ return result;
183
+ } catch {
184
+ return {};
185
+ }
186
+ }
187
+ __name(parseTypedQueryParams, "parseTypedQueryParams");
188
+
189
+ export { appendQueryParams, createUrlBuilder, extractQueryParams, getDomain, getExtension, isValidUrl, joinPaths, normalizeUrl, parseQueryString, parseTypedQueryParams, removeQueryParams };
@@ -0,0 +1,164 @@
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
+ * 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
+ export 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
+ export 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
+ export 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
+ export 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
+ export 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
+ export 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
+ export 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
+ export 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
+ export 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
+ export 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
+ export declare function parseTypedQueryParams<T extends Record<string, any>>(url: string, converters?: Record<keyof T, (val: string) => any>): Partial<T>;
@@ -0,0 +1,212 @@
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
+ 'use strict';
26
+
27
+ var __defProp = Object.defineProperty;
28
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
29
+
30
+ // src/validate/validate.utils.ts
31
+ function isPort(value) {
32
+ const port = typeof value === "string" ? Number(value.trim()) : value;
33
+ return Number.isInteger(port) && port > 0 && port <= 65535;
34
+ }
35
+ __name(isPort, "isPort");
36
+ function isEmail(str) {
37
+ if (typeof str !== "string" || str.length > 254) return false;
38
+ const atIndex = str.indexOf("@");
39
+ if (atIndex === -1 || atIndex !== str.lastIndexOf("@")) return false;
40
+ const local = str.slice(0, atIndex);
41
+ const domain = str.slice(atIndex + 1);
42
+ 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;
46
+ if (domain.includes("..")) return false;
47
+ const labels = domain.split(".");
48
+ if (labels.some((l) => !l.length)) return false;
49
+ if (labels.length < 2) return false;
50
+ const labelRegex = /^[A-Za-z0-9-]{1,63}$/;
51
+ for (const label of labels) {
52
+ if (!labelRegex.test(label)) return false;
53
+ if (label.startsWith("-") || label.endsWith("-")) return false;
54
+ }
55
+ const tld = labels[labels.length - 1];
56
+ if (!/^[A-Za-z]{2,63}$/.test(tld)) return false;
57
+ return true;
58
+ }
59
+ __name(isEmail, "isEmail");
60
+ 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);
62
+ }
63
+ __name(isUUID, "isUUID");
64
+ function isURL(str) {
65
+ try {
66
+ new URL(str);
67
+ return true;
68
+ } catch {
69
+ return false;
70
+ }
71
+ }
72
+ __name(isURL, "isURL");
73
+ 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);
78
+ }
79
+ __name(isPhone, "isPhone");
80
+ function isAlphanumeric(str) {
81
+ return /^[a-z0-9]+$/i.test(str);
82
+ }
83
+ __name(isAlphanumeric, "isAlphanumeric");
84
+ 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);
88
+ }
89
+ __name(isNumeric, "isNumeric");
90
+ function isHexColor(str) {
91
+ return /^#([a-f0-9]{6}|[a-f0-9]{3})$/i.test(str);
92
+ }
93
+ __name(isHexColor, "isHexColor");
94
+ 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;
97
+ const date = new Date(str);
98
+ return !isNaN(date.getTime()) && date.toISOString().startsWith(str.slice(0, 10));
99
+ }
100
+ __name(isISODate, "isISODate");
101
+ function isLengthBetween(str, min, max) {
102
+ return str.length >= min && str.length <= max;
103
+ }
104
+ __name(isLengthBetween, "isLengthBetween");
105
+ function isNumberBetween(value, min, max) {
106
+ return value >= min && value <= max;
107
+ }
108
+ __name(isNumberBetween, "isNumberBetween");
109
+ function isAlpha(str) {
110
+ return /^[a-zA-Z]+$/.test(str);
111
+ }
112
+ __name(isAlpha, "isAlpha");
113
+ function isStrongPassword(str) {
114
+ if (str.length < 8) return false;
115
+ const hasUpperCase = /[A-Z]/.test(str);
116
+ const hasLowerCase = /[a-z]/.test(str);
117
+ const hasNumbers = /[0-9]/.test(str);
118
+ const hasSpecialChar = /[!@#$%^&*()_+\-=[\]{};':"\\|,.<>?]/.test(str);
119
+ return hasUpperCase && hasLowerCase && hasNumbers && hasSpecialChar;
120
+ }
121
+ __name(isStrongPassword, "isStrongPassword");
122
+ function isIPv4(str) {
123
+ const parts = str.split(".");
124
+ 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;
128
+ });
129
+ }
130
+ __name(isIPv4, "isIPv4");
131
+ 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);
133
+ }
134
+ __name(isIPv6, "isIPv6");
135
+ function isCreditCard(str) {
136
+ const cardNumber = str.replace(/\D/g, "");
137
+ if (cardNumber.length < 13 || cardNumber.length > 19) return false;
138
+ 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;
145
+ }
146
+ sum += digit;
147
+ shouldDouble = !shouldDouble;
148
+ }
149
+ return sum % 10 === 0;
150
+ }
151
+ __name(isCreditCard, "isCreditCard");
152
+ function isValidJSON(str) {
153
+ try {
154
+ JSON.parse(str);
155
+ return true;
156
+ } catch {
157
+ return false;
158
+ }
159
+ }
160
+ __name(isValidJSON, "isValidJSON");
161
+ function isArray(value, itemGuard) {
162
+ if (!Array.isArray(value)) return false;
163
+ return !itemGuard || value.every((item) => itemGuard(item));
164
+ }
165
+ __name(isArray, "isArray");
166
+ function isBase64(str) {
167
+ return /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(str);
168
+ }
169
+ __name(isBase64, "isBase64");
170
+ function hasRequiredProps(obj, requiredProps) {
171
+ return requiredProps.every((prop) => Object.prototype.hasOwnProperty.call(obj, prop) && obj[prop] !== void 0 && obj[prop] !== null);
172
+ }
173
+ __name(hasRequiredProps, "hasRequiredProps");
174
+ function isDateInRange(date, minDate, maxDate) {
175
+ if (!(date instanceof Date) || isNaN(date.getTime())) return false;
176
+ if (minDate && date < minDate) return false;
177
+ if (maxDate && date > maxDate) return false;
178
+ return true;
179
+ }
180
+ __name(isDateInRange, "isDateInRange");
181
+ function matchesPattern(str, pattern) {
182
+ return pattern.test(str);
183
+ }
184
+ __name(matchesPattern, "matchesPattern");
185
+ function validateAll(value, validators) {
186
+ return validators.every((validator) => validator(value));
187
+ }
188
+ __name(validateAll, "validateAll");
189
+
190
+ exports.hasRequiredProps = hasRequiredProps;
191
+ exports.isAlpha = isAlpha;
192
+ exports.isAlphanumeric = isAlphanumeric;
193
+ exports.isArray = isArray;
194
+ exports.isBase64 = isBase64;
195
+ exports.isCreditCard = isCreditCard;
196
+ exports.isDateInRange = isDateInRange;
197
+ exports.isEmail = isEmail;
198
+ exports.isHexColor = isHexColor;
199
+ exports.isIPv4 = isIPv4;
200
+ exports.isIPv6 = isIPv6;
201
+ exports.isISODate = isISODate;
202
+ exports.isLengthBetween = isLengthBetween;
203
+ exports.isNumberBetween = isNumberBetween;
204
+ exports.isNumeric = isNumeric;
205
+ exports.isPhone = isPhone;
206
+ exports.isPort = isPort;
207
+ exports.isStrongPassword = isStrongPassword;
208
+ exports.isURL = isURL;
209
+ exports.isUUID = isUUID;
210
+ exports.isValidJSON = isValidJSON;
211
+ exports.matchesPattern = matchesPattern;
212
+ exports.validateAll = validateAll;
@@ -0,0 +1,25 @@
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
+ export * from './validate.utils';