@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.
- package/README.md +52 -16
- package/array/index.cjs +180 -71
- package/array/index.d.ts +293 -1
- package/array/index.mjs +171 -72
- package/async/index.cjs +92 -36
- package/async/index.d.ts +275 -1
- package/async/index.mjs +92 -36
- package/cache/index.cjs +1 -1
- package/cache/index.d.ts +155 -1
- package/cache/index.mjs +2 -2
- package/config/index.cjs +78 -64
- package/config/index.d.ts +64 -2
- package/config/index.mjs +76 -64
- package/context-store/index.d.ts +192 -1
- package/crypto/index.d.ts +163 -1
- package/date/index.cjs +46 -1
- package/date/index.d.ts +190 -1
- package/date/index.mjs +45 -2
- package/decorators/index.cjs +1156 -18
- package/decorators/index.d.ts +684 -1
- package/decorators/index.mjs +1156 -18
- package/dir/index.cjs +4 -3
- package/dir/index.d.ts +195 -1
- package/dir/index.mjs +4 -3
- package/env/index.cjs +10 -26
- package/env/index.d.ts +379 -1
- package/env/index.mjs +10 -26
- package/exception/index.d.ts +232 -1
- package/fs/index.cjs +70 -36
- package/fs/index.d.ts +205 -1
- package/fs/index.mjs +64 -34
- package/http-status-codes/index.d.ts +267 -1
- package/id/index.d.ts +37 -1
- package/index.cjs +3 -3
- package/index.d.ts +1 -1
- package/index.mjs +1 -1
- package/logger/index.cjs +11 -11
- package/logger/index.d.ts +189 -1
- package/logger/index.mjs +12 -12
- package/middleware/index.d.ts +103 -1
- package/obj/index.cjs +150 -162
- package/obj/index.d.ts +136 -1
- package/obj/index.mjs +150 -162
- package/package.json +11 -11
- package/performance/index.cjs +2 -2
- package/performance/index.d.ts +138 -1
- package/performance/index.mjs +2 -2
- package/request/index.cjs +1 -1
- package/request/index.d.ts +241 -2
- package/request/index.mjs +1 -1
- package/response/index.d.ts +318 -2
- package/server/index.cjs +27 -23
- package/server/index.d.ts +785 -4
- package/server/index.mjs +28 -23
- package/stream/index.d.ts +90 -1
- package/string/index.d.ts +102 -1
- package/type/index.cjs +1 -1
- package/type/index.d.ts +107 -1
- package/type/index.mjs +1 -1
- package/types/index.d.ts +774 -4
- package/url/index.cjs +2 -4
- package/url/index.d.ts +142 -1
- package/url/index.mjs +2 -4
- package/{validate → validation}/index.cjs +89 -42
- package/{validate/validate.utils.d.ts → validation/index.d.ts} +32 -23
- package/{validate → validation}/index.mjs +85 -42
- package/array/array.utils.d.ts +0 -191
- package/async/async.utils.d.ts +0 -296
- package/cache/cache.utils.d.ts +0 -176
- package/config/config.d.ts +0 -57
- package/context-store/context-store.utils.d.ts +0 -212
- package/crypto/crypto.utils.d.ts +0 -183
- package/date/date.utils.d.ts +0 -190
- package/decorators/decorators.utils.d.ts +0 -705
- package/dir/dir.utils.d.ts +0 -216
- package/env/env.utils.d.ts +0 -400
- package/exception/exception.utils.d.ts +0 -253
- package/fs/fs.utils.d.ts +0 -196
- package/http-status-codes/http-status-codes.d.ts +0 -289
- package/id/id.utils.d.ts +0 -59
- package/logger/logger.utils.d.ts +0 -210
- package/middleware/middleware.utils.d.ts +0 -123
- package/obj/obj.utils.d.ts +0 -156
- package/performance/performance.utils.d.ts +0 -159
- package/request/request.utils.d.ts +0 -109
- package/response/response.utils.d.ts +0 -186
- package/server/server.builder.d.ts +0 -531
- package/server/server.d.ts +0 -303
- package/stream/stream.utils.d.ts +0 -111
- package/string/string.utils.d.ts +0 -124
- package/type/type.utils.d.ts +0 -129
- package/types/api-response.d.ts +0 -175
- package/types/common.d.ts +0 -148
- package/types/config.d.ts +0 -88
- package/types/server.d.ts +0 -291
- package/url/url.utils.d.ts +0 -164
- package/validate/index.d.ts +0 -25
package/types/server.d.ts
DELETED
|
@@ -1,291 +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
|
-
import type { Express, json, NextFunction, urlencoded, Request, Response } from 'express';
|
|
26
|
-
import type { ExpressServer } from '@catbee/utils/server';
|
|
27
|
-
import type { HelmetOptions } from 'helmet';
|
|
28
|
-
import type { CompressionOptions } from 'compression';
|
|
29
|
-
import type { CookieParseOptions } from 'cookie-parser';
|
|
30
|
-
import type { CorsOptions } from 'cors';
|
|
31
|
-
import type http from 'http';
|
|
32
|
-
import type { ToggleConfig } from './common';
|
|
33
|
-
/**
|
|
34
|
-
* Server configuration interface with smart defaults and full customization.
|
|
35
|
-
* All options are designed with security and performance best practices.
|
|
36
|
-
* Most options can be overridden via environment variables.
|
|
37
|
-
*/
|
|
38
|
-
export interface ServerConfig {
|
|
39
|
-
/** Port the server should listen on (default: 3000, env: PORT)
|
|
40
|
-
* - default: 3000
|
|
41
|
-
*/
|
|
42
|
-
port: number;
|
|
43
|
-
/** Optional host address for binding (default: '0.0.0.0', env: HOST)
|
|
44
|
-
* - default: '0.0.0.0'
|
|
45
|
-
*/
|
|
46
|
-
host?: string;
|
|
47
|
-
/** CORS configuration (default: false disables CORS, or provide options object)
|
|
48
|
-
* - default: false
|
|
49
|
-
*/
|
|
50
|
-
cors?: ToggleConfig<CorsOptions>;
|
|
51
|
-
/** Enable Helmet security headers (default: false disables Helmet, or provide options object)
|
|
52
|
-
* - default: false
|
|
53
|
-
*/
|
|
54
|
-
helmet?: ToggleConfig<HelmetOptions>;
|
|
55
|
-
/** Enable gzip/deflate compression (default: false disables compression, or provide options object)
|
|
56
|
-
* - default: false
|
|
57
|
-
*/
|
|
58
|
-
compression?: ToggleConfig<CompressionOptions>;
|
|
59
|
-
/** Request body parsing with size limits
|
|
60
|
-
* - json: { limit: '1mb' }
|
|
61
|
-
* - urlencoded: { extended: true, limit: '1mb' }
|
|
62
|
-
*/
|
|
63
|
-
bodyParser?: {
|
|
64
|
-
/** JSON parser (default: { limit: '1mb' }) */
|
|
65
|
-
json?: Parameters<typeof json>[0];
|
|
66
|
-
/** URL-encoded parser (default: { extended: true, limit: '1mb' }) */
|
|
67
|
-
urlencoded?: Parameters<typeof urlencoded>[0];
|
|
68
|
-
};
|
|
69
|
-
/** Enable cookie parsing with options (default: false)
|
|
70
|
-
* - default: false
|
|
71
|
-
*/
|
|
72
|
-
cookieParser?: ToggleConfig<CookieParseOptions>;
|
|
73
|
-
/** Trust proxy headers (default: false)
|
|
74
|
-
* - default: false
|
|
75
|
-
*/
|
|
76
|
-
trustProxy?: boolean;
|
|
77
|
-
/** Static file serving configuration for assets, uploads, etc.
|
|
78
|
-
* - path: file system path to serve
|
|
79
|
-
* - route: URL route prefix (default: "/")
|
|
80
|
-
* - maxAge: cache max age (default: 0)
|
|
81
|
-
* - etag: enable ETag headers (default: true)
|
|
82
|
-
* - immutable: enable immutable caching (default: false)
|
|
83
|
-
* - lastModified: enable last-modified caching (default: true)
|
|
84
|
-
* - cacheControl: enable Cache-Control headers (default: true)
|
|
85
|
-
*/
|
|
86
|
-
staticFolders?: Array<{
|
|
87
|
-
/** URL route prefix (default: "/") */
|
|
88
|
-
path?: string;
|
|
89
|
-
/** File system path to serve */
|
|
90
|
-
directory: string;
|
|
91
|
-
/** Cache-Control: max-age=<duration> (default: 0) */
|
|
92
|
-
maxAge?: string;
|
|
93
|
-
/** Enable ETag headers (default: true) */
|
|
94
|
-
etag?: boolean;
|
|
95
|
-
/** Enable immutable caching (default: false) */
|
|
96
|
-
immutable?: boolean;
|
|
97
|
-
/** Enable last-modified caching (default: true) */
|
|
98
|
-
lastModified?: boolean;
|
|
99
|
-
/** Enable Cache-Control headers (default: true) */
|
|
100
|
-
cacheControl?: boolean;
|
|
101
|
-
}>;
|
|
102
|
-
/** Enable microservice mode (default: false)
|
|
103
|
-
* - default: false
|
|
104
|
-
*/
|
|
105
|
-
isMicroservice?: boolean;
|
|
106
|
-
/** Service name for headers/metrics (default: 'express_app', env: APP_NAME)
|
|
107
|
-
* - default: 'express_app'
|
|
108
|
-
*/
|
|
109
|
-
appName?: string;
|
|
110
|
-
/** Global response headers (default: {})
|
|
111
|
-
* - default: {}
|
|
112
|
-
*/
|
|
113
|
-
globalHeaders?: Record<string, string | (() => string)>;
|
|
114
|
-
/** Rate limiting settings
|
|
115
|
-
* - enable: false
|
|
116
|
-
* - windowMs: 15 * 60 * 1000
|
|
117
|
-
* - max: 100
|
|
118
|
-
* - message: 'Too many requests'
|
|
119
|
-
* - standardHeaders: true
|
|
120
|
-
* - legacyHeaders: false
|
|
121
|
-
*/
|
|
122
|
-
rateLimit?: {
|
|
123
|
-
/** Enable rate limiting (default: false) */
|
|
124
|
-
enable: boolean;
|
|
125
|
-
/** Time window in ms (default: 900000 - 15 minutes) */
|
|
126
|
-
windowMs?: number;
|
|
127
|
-
/** Max requests per window (default: 100) */
|
|
128
|
-
max?: number;
|
|
129
|
-
/** Rate limit message (default: 'Too many requests') */
|
|
130
|
-
message?: string;
|
|
131
|
-
/** Add standard headers (default: true) */
|
|
132
|
-
standardHeaders?: boolean;
|
|
133
|
-
/** Add legacy headers (default: false) */
|
|
134
|
-
legacyHeaders?: boolean;
|
|
135
|
-
};
|
|
136
|
-
/** Request logging configuration
|
|
137
|
-
* - enable: true in dev, false in prod
|
|
138
|
-
* - ignorePaths: skips /healthz, /favicon.ico, /metrics, /docs, /.well-known
|
|
139
|
-
* - skipNotFoundRoutes: false
|
|
140
|
-
*/
|
|
141
|
-
requestLogging?: {
|
|
142
|
-
/** Enable request logging (default: true in dev, false in prod) */
|
|
143
|
-
enable: boolean;
|
|
144
|
-
/** Ignore paths function or string[] (default: skips /healthz, /favicon.ico, /metrics, /docs, /.well-known) */
|
|
145
|
-
ignorePaths?: string[] | ((req: Request, res: Response) => boolean);
|
|
146
|
-
/** Skip logging for not found routes (default: false) */
|
|
147
|
-
skipNotFoundRoutes?: boolean;
|
|
148
|
-
};
|
|
149
|
-
/** Health check settings
|
|
150
|
-
* - path: '/healthz'
|
|
151
|
-
* - detailed: true
|
|
152
|
-
* - withGlobalPrefix: false
|
|
153
|
-
*/
|
|
154
|
-
healthCheck?: {
|
|
155
|
-
/** Health check path (default: '/healthz') */
|
|
156
|
-
path?: string;
|
|
157
|
-
/** Custom checks (default: []) */
|
|
158
|
-
checks?: Array<{
|
|
159
|
-
name: string;
|
|
160
|
-
check: () => Promise<boolean> | boolean;
|
|
161
|
-
}>;
|
|
162
|
-
/** Show detailed checks status in response (default: true) */
|
|
163
|
-
detailed?: boolean;
|
|
164
|
-
/** Include in global prefix (default: false) */
|
|
165
|
-
withGlobalPrefix?: boolean;
|
|
166
|
-
};
|
|
167
|
-
/** Request timeout in ms (default: 30000 - 30 seconds)
|
|
168
|
-
* - default: 30000
|
|
169
|
-
*/
|
|
170
|
-
requestTimeout?: number;
|
|
171
|
-
/** Response timing configuration
|
|
172
|
-
* - enable: false
|
|
173
|
-
* - addHeader: true
|
|
174
|
-
* - logOnComplete: false
|
|
175
|
-
*/
|
|
176
|
-
responseTime?: {
|
|
177
|
-
/** Enable timing (default: false) */
|
|
178
|
-
enable: boolean;
|
|
179
|
-
/** Add X-Response-Time header (default: true) */
|
|
180
|
-
addHeader?: boolean;
|
|
181
|
-
/** Log completion time (default: false) */
|
|
182
|
-
logOnComplete?: boolean;
|
|
183
|
-
};
|
|
184
|
-
/** Request ID configuration
|
|
185
|
-
* - headerName: 'x-request-id'
|
|
186
|
-
* - exposeHeader: true
|
|
187
|
-
* - generator: uuid()
|
|
188
|
-
*/
|
|
189
|
-
requestId?: {
|
|
190
|
-
/** Header name (default: 'x-request-id') */
|
|
191
|
-
headerName?: string;
|
|
192
|
-
/** Add to response headers (default: true) */
|
|
193
|
-
exposeHeader?: boolean;
|
|
194
|
-
/** ID generator (default: uuid()) */
|
|
195
|
-
generator?: () => string;
|
|
196
|
-
};
|
|
197
|
-
/** Global route prefix (default: '/')
|
|
198
|
-
* - default: '/'
|
|
199
|
-
*/
|
|
200
|
-
globalPrefix?: string;
|
|
201
|
-
/** OpenAPI documentation
|
|
202
|
-
* - enable: false
|
|
203
|
-
* - mountPath: '/docs'
|
|
204
|
-
* - verbose: false
|
|
205
|
-
* - withGlobalPrefix: false
|
|
206
|
-
*/
|
|
207
|
-
openApi?: {
|
|
208
|
-
/** Enable docs (default: false) */
|
|
209
|
-
enable: boolean;
|
|
210
|
-
/** UI path (default: '/docs') */
|
|
211
|
-
mountPath?: string;
|
|
212
|
-
/** Spec file path (required if enabled) */
|
|
213
|
-
filePath?: string;
|
|
214
|
-
/** Enable verbose logs (default: false) */
|
|
215
|
-
verbose?: boolean;
|
|
216
|
-
/** Include in global prefix (default: false) */
|
|
217
|
-
withGlobalPrefix?: boolean;
|
|
218
|
-
};
|
|
219
|
-
/** Prometheus metrics
|
|
220
|
-
* - enable: false
|
|
221
|
-
* - path: '/metrics'
|
|
222
|
-
* - withGlobalPrefix: false
|
|
223
|
-
*/
|
|
224
|
-
metrics?: {
|
|
225
|
-
/** Enable metrics (default: false) */
|
|
226
|
-
enable: boolean;
|
|
227
|
-
/** Metrics path (default: '/metrics') */
|
|
228
|
-
path?: string;
|
|
229
|
-
/** Include in global prefix (default: false) */
|
|
230
|
-
withGlobalPrefix?: boolean;
|
|
231
|
-
};
|
|
232
|
-
/** Service version header
|
|
233
|
-
* - enable: false
|
|
234
|
-
* - headerName: 'x-service-version'
|
|
235
|
-
* - version: '0.0.0'
|
|
236
|
-
*/
|
|
237
|
-
serviceVersion?: {
|
|
238
|
-
/** Enable version header (default: false) */
|
|
239
|
-
enable: boolean;
|
|
240
|
-
/** Header name (default: 'x-service-version') */
|
|
241
|
-
headerName?: string;
|
|
242
|
-
/** Version value (default: '0.0.0') */
|
|
243
|
-
version?: string | (() => string);
|
|
244
|
-
};
|
|
245
|
-
/**
|
|
246
|
-
* HTTPS configuration (if provided, server will use HTTPS)
|
|
247
|
-
* Requires 'key' and 'cert' at minimum.
|
|
248
|
-
* @command - to generate self-signed certificates
|
|
249
|
-
* ```bash
|
|
250
|
-
* choco install mkcert
|
|
251
|
-
* mkcert -key-file localhost-key.pem -cert-file localhost-cert.pem localhost 127.0.0.1 ::1
|
|
252
|
-
* ```
|
|
253
|
-
*/
|
|
254
|
-
https?: {
|
|
255
|
-
/** Path to SSL private key file (PEM) */
|
|
256
|
-
key: string;
|
|
257
|
-
/** Path to SSL certificate file (PEM) */
|
|
258
|
-
cert: string;
|
|
259
|
-
/** Optional path to CA bundle file (PEM) */
|
|
260
|
-
ca?: string;
|
|
261
|
-
/** Optional passphrase for the private key */
|
|
262
|
-
passphrase?: string;
|
|
263
|
-
/** Any other https.ServerOptions */
|
|
264
|
-
[key: string]: any;
|
|
265
|
-
};
|
|
266
|
-
}
|
|
267
|
-
/**
|
|
268
|
-
* Server lifecycle hooks for custom behavior injection.
|
|
269
|
-
* Allows extending server functionality without modifying core code.
|
|
270
|
-
* All hooks can be async and support error handling.
|
|
271
|
-
*/
|
|
272
|
-
export interface ServerHooks {
|
|
273
|
-
/** Called before any middleware or routes are initialized - good for early setup */
|
|
274
|
-
beforeInit?: (server: ExpressServer) => Promise<void> | void;
|
|
275
|
-
/** Called after middleware and routes are set up - good for final configuration */
|
|
276
|
-
afterInit?: (server: ExpressServer) => Promise<void> | void;
|
|
277
|
-
/** Called just before the server starts listening - good for last-minute checks */
|
|
278
|
-
beforeStart?: (app: Express) => Promise<void> | void;
|
|
279
|
-
/** Called after the server starts successfully - good for announcing readiness */
|
|
280
|
-
afterStart?: (server: http.Server) => Promise<void> | void;
|
|
281
|
-
/** Called before graceful shutdown begins - good for cleanup preparation */
|
|
282
|
-
beforeStop?: (server: http.Server) => Promise<void> | void;
|
|
283
|
-
/** Called after server has stopped - good for final cleanup */
|
|
284
|
-
afterStop?: () => Promise<void> | void;
|
|
285
|
-
/** Custom global error handler - overrides the default error handling */
|
|
286
|
-
onError?: (error: Error, req: Request, res: Response, next: NextFunction) => void;
|
|
287
|
-
/** Called at the start of each request - good for request preprocessing */
|
|
288
|
-
onRequest?: (req: Request, res: Response, next: NextFunction) => void;
|
|
289
|
-
/** Called before response is sent - good for response modification */
|
|
290
|
-
onResponse?: (req: Request, res: Response, next: NextFunction) => void;
|
|
291
|
-
}
|
package/url/url.utils.d.ts
DELETED
|
@@ -1,164 +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
|
-
* 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>;
|
package/validate/index.d.ts
DELETED
|
@@ -1,25 +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
|
-
export * from './validate.utils';
|