@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.
- package/LICENSE +1 -1
- package/README.md +102 -52
- package/array/index.cjs +215 -74
- package/array/index.d.ts +345 -2
- package/array/index.mjs +201 -74
- package/async/index.cjs +116 -39
- package/async/index.d.ts +292 -2
- package/async/index.mjs +116 -40
- package/cache/index.cjs +2 -2
- package/cache/index.d.ts +156 -2
- package/cache/index.mjs +3 -3
- package/config/index.cjs +80 -66
- package/config/index.d.ts +65 -3
- package/config/index.mjs +77 -65
- package/context-store/index.cjs +2 -3
- package/context-store/index.d.ts +193 -2
- package/context-store/index.mjs +2 -3
- package/crypto/index.cjs +55 -5
- package/crypto/index.d.ts +225 -2
- package/crypto/index.mjs +52 -7
- package/date/index.cjs +676 -2
- package/date/index.d.ts +676 -2
- package/date/index.mjs +665 -3
- package/decorator/index.cjs +2172 -0
- package/{decorators/decorators.utils.d.ts → decorator/index.d.ts} +58 -54
- package/decorator/index.mjs +2131 -0
- package/{dir → directory}/index.cjs +5 -4
- package/{dir/dir.utils.d.ts → directory/index.d.ts} +24 -21
- package/{dir → directory}/index.mjs +5 -4
- package/env/index.cjs +100 -68
- package/env/index.d.ts +391 -2
- package/env/index.mjs +100 -68
- package/exception/index.cjs +1 -1
- package/exception/index.d.ts +233 -2
- package/exception/index.mjs +1 -1
- package/fs/index.cjs +71 -37
- package/fs/index.d.ts +206 -2
- package/fs/index.mjs +65 -35
- package/http-status-codes/index.cjs +1 -1
- package/http-status-codes/index.d.ts +268 -2
- package/http-status-codes/index.mjs +1 -1
- package/id/index.cjs +1 -1
- package/id/index.d.ts +38 -2
- package/id/index.mjs +1 -1
- package/index.cjs +13 -13
- package/index.d.ts +5 -5
- package/index.mjs +5 -5
- package/logger/index.cjs +13 -15
- package/logger/index.d.ts +190 -2
- package/logger/index.mjs +14 -16
- package/middleware/index.cjs +1 -1
- package/middleware/index.d.ts +104 -2
- package/middleware/index.mjs +1 -1
- package/object/index.cjs +379 -0
- package/{obj/obj.utils.d.ts → object/index.d.ts} +73 -33
- package/object/index.mjs +360 -0
- package/package.json +41 -23
- package/performance/index.cjs +4 -4
- package/performance/index.d.ts +139 -2
- package/performance/index.mjs +4 -4
- package/request/index.cjs +37 -25
- package/request/index.d.ts +242 -3
- package/request/index.mjs +37 -25
- package/response/index.cjs +1 -1
- package/response/index.d.ts +319 -3
- package/response/index.mjs +1 -1
- package/server/index.cjs +249 -146
- package/server/index.d.ts +866 -5
- package/server/index.mjs +248 -144
- package/stream/index.cjs +1 -1
- package/stream/index.d.ts +91 -2
- package/stream/index.mjs +1 -1
- package/string/index.cjs +34 -1
- package/string/index.d.ts +146 -2
- package/string/index.mjs +31 -2
- package/type/index.cjs +19 -2
- package/type/index.d.ts +144 -2
- package/type/index.mjs +17 -3
- package/types/index.cjs +1 -1
- package/types/index.d.ts +775 -5
- package/types/index.mjs +1 -1
- package/url/index.cjs +63 -5
- package/url/index.d.ts +200 -2
- package/url/index.mjs +59 -6
- package/{validate → validation}/index.cjs +91 -44
- package/{validate/validate.utils.d.ts → validation/index.d.ts} +33 -24
- package/{validate → validation}/index.mjs +87 -44
- 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/index.cjs +0 -913
- package/decorators/index.d.ts +0 -25
- package/decorators/index.mjs +0 -872
- package/dir/index.d.ts +0 -25
- 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/index.cjs +0 -317
- package/obj/index.d.ts +0 -25
- package/obj/index.mjs +0 -301
- 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/server/server.d.ts
DELETED
|
@@ -1,303 +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 express, { Express, Router } from 'express';
|
|
26
|
-
import http from 'http';
|
|
27
|
-
import https from 'https';
|
|
28
|
-
import { ServerConfig, ServerHooks } from '@catbee/utils/types';
|
|
29
|
-
/**
|
|
30
|
-
* Generate standardized error message for missing dependencies.
|
|
31
|
-
*/
|
|
32
|
-
export declare const getDependencyErrorMessage: (packageName: string, x?: string) => string;
|
|
33
|
-
/**
|
|
34
|
-
* Map of critical dependencies to their error messages.
|
|
35
|
-
*/
|
|
36
|
-
export declare const DependencyErrors: {
|
|
37
|
-
express: string;
|
|
38
|
-
helmet: string;
|
|
39
|
-
cors: string;
|
|
40
|
-
compression: string;
|
|
41
|
-
'express-rate-limit': string;
|
|
42
|
-
'cookie-parser': string;
|
|
43
|
-
'@scalar/express-api-reference': string;
|
|
44
|
-
'prom-client': string;
|
|
45
|
-
};
|
|
46
|
-
/**
|
|
47
|
-
* Production-ready Express server with enterprise features.
|
|
48
|
-
*
|
|
49
|
-
* Core Features:
|
|
50
|
-
* - Security: Helmet, CORS, rate limiting, timeouts
|
|
51
|
-
* - Monitoring: Request logs, metrics, health checks
|
|
52
|
-
* - Performance: Compression, caching, static files
|
|
53
|
-
* - Reliability: Graceful shutdown, error handling
|
|
54
|
-
* - Developer UX: OpenAPI docs, debugging tools
|
|
55
|
-
* - Extensibility: Hooks, middleware, custom routes
|
|
56
|
-
*
|
|
57
|
-
* Designed for microservices and production workloads.
|
|
58
|
-
* Includes K8s readiness probes and zero-downtime support.
|
|
59
|
-
*/
|
|
60
|
-
export declare class ExpressServer {
|
|
61
|
-
/** Prometheus client registry for metrics collection */
|
|
62
|
-
private register;
|
|
63
|
-
/** HTTP server instance (null when not running) */
|
|
64
|
-
protected server: http.Server | https.Server | null;
|
|
65
|
-
/** Merged configuration with defaults applied */
|
|
66
|
-
protected config: ServerConfig;
|
|
67
|
-
/** User-defined lifecycle hooks */
|
|
68
|
-
protected hooks: ServerHooks;
|
|
69
|
-
/** Global API prefix (from config) */
|
|
70
|
-
protected globalPrefix: string;
|
|
71
|
-
/** Internal fallback router */
|
|
72
|
-
private rootRouter;
|
|
73
|
-
/** User-supplied router */
|
|
74
|
-
private externalRouter?;
|
|
75
|
-
/** Internal Express app instance */
|
|
76
|
-
private app;
|
|
77
|
-
/** Set of active WebSocket connections */
|
|
78
|
-
private connections;
|
|
79
|
-
/** Flag indicating if the server is shutting down */
|
|
80
|
-
private isShuttingDown;
|
|
81
|
-
/**
|
|
82
|
-
* Collection of registered health check functions.
|
|
83
|
-
* These are executed when the health check endpoint is accessed.
|
|
84
|
-
*/
|
|
85
|
-
private healthChecks;
|
|
86
|
-
/** Prometheus metrics for monitoring */
|
|
87
|
-
private requestCounter?;
|
|
88
|
-
private routeTimings?;
|
|
89
|
-
private requestSizes?;
|
|
90
|
-
private clientIPs?;
|
|
91
|
-
/** Promise that resolves when initialization (middleware + routes) is complete */
|
|
92
|
-
private initPromise;
|
|
93
|
-
/**
|
|
94
|
-
* Initializes server with intelligent defaults and security best practices.
|
|
95
|
-
* All settings can be customized via config and hooks.
|
|
96
|
-
*
|
|
97
|
-
* Default Security:
|
|
98
|
-
* - Secure headers (Helmet)
|
|
99
|
-
* - Rate limiting
|
|
100
|
-
* - Request timeouts
|
|
101
|
-
* - Body size limits
|
|
102
|
-
* - CORS protection
|
|
103
|
-
*
|
|
104
|
-
* Default Monitoring:
|
|
105
|
-
* - Request/Response logging
|
|
106
|
-
* - Prometheus metrics
|
|
107
|
-
* - Health checks
|
|
108
|
-
* - Request tracing
|
|
109
|
-
*/
|
|
110
|
-
constructor(config: Partial<ServerConfig>, hooks?: ServerHooks);
|
|
111
|
-
/**
|
|
112
|
-
* Execute a lifecycle hook safely with comprehensive error handling.
|
|
113
|
-
* Prevents hook failures from crashing the server while logging issues.
|
|
114
|
-
*
|
|
115
|
-
* @param hook Name of the lifecycle hook to execute
|
|
116
|
-
* @param args Arguments to pass to the hook function
|
|
117
|
-
*/
|
|
118
|
-
private runHook;
|
|
119
|
-
/**
|
|
120
|
-
* Initialize the Express server with middleware and routes.
|
|
121
|
-
*/
|
|
122
|
-
private initialize;
|
|
123
|
-
/**
|
|
124
|
-
* Configure and register all middlewares in the optimal order.
|
|
125
|
-
*
|
|
126
|
-
* Middleware Order (CRITICAL - don't change without understanding implications):
|
|
127
|
-
* 1. Basic server configuration (trust proxy, x-powered-by)
|
|
128
|
-
* 2. Request ID generation (for tracing)
|
|
129
|
-
* 3. Request context setup (for logging correlation)
|
|
130
|
-
* 4. Timeout protection (prevents hanging requests)
|
|
131
|
-
* 5. Response time tracking (for performance monitoring)
|
|
132
|
-
* 6. Request logging (after ID/context setup)
|
|
133
|
-
* 7. Custom request hooks
|
|
134
|
-
* 8. Security middleware (rate limiting, CORS, Helmet)
|
|
135
|
-
* 9. Response compression
|
|
136
|
-
* 10. Static file serving
|
|
137
|
-
* 11. Request parsing (body parsing, cookies)
|
|
138
|
-
* 12. API documentation (OpenAPI)
|
|
139
|
-
* 13. Global headers
|
|
140
|
-
* 14. Custom response hooks
|
|
141
|
-
*/
|
|
142
|
-
protected setupMiddleware(): Promise<void>;
|
|
143
|
-
/**
|
|
144
|
-
* Configure server routes and error handling.
|
|
145
|
-
* Sets up in following order:
|
|
146
|
-
*
|
|
147
|
-
* 1. Built-in routes (health, metrics)
|
|
148
|
-
* 2. Application routes
|
|
149
|
-
* 3. 404 handler
|
|
150
|
-
* 4. Error handler
|
|
151
|
-
*/
|
|
152
|
-
protected setupRoutes(): Promise<void>;
|
|
153
|
-
/**
|
|
154
|
-
* Register a new health check function for monitoring service dependencies.
|
|
155
|
-
*
|
|
156
|
-
* Health checks are executed when the health endpoint is accessed and
|
|
157
|
-
* help determine if the service is ready to handle requests.
|
|
158
|
-
*
|
|
159
|
-
* Examples:
|
|
160
|
-
* - Database connectivity
|
|
161
|
-
* - External service availability
|
|
162
|
-
* - File system access
|
|
163
|
-
* - Memory/CPU usage checks
|
|
164
|
-
*
|
|
165
|
-
* @param name Unique identifier for the check (used in detailed responses)
|
|
166
|
-
* @param check Function returning boolean or Promise<boolean> indicating health
|
|
167
|
-
* @returns This instance for method chaining
|
|
168
|
-
*/
|
|
169
|
-
registerHealthCheck(name: string, check: () => Promise<boolean> | boolean): this;
|
|
170
|
-
/**
|
|
171
|
-
* Run registered health checks and return whether the service is ready.
|
|
172
|
-
* Useful for readiness probes in deployment tooling.
|
|
173
|
-
*
|
|
174
|
-
* @returns Promise resolving to `true` when all checks pass, otherwise `false`.
|
|
175
|
-
*/
|
|
176
|
-
ready(): Promise<boolean>;
|
|
177
|
-
/**
|
|
178
|
-
* Get the underlying Express application instance.
|
|
179
|
-
* Use this for advanced Express features not exposed by this wrapper.
|
|
180
|
-
*
|
|
181
|
-
* @returns The raw Express app instance
|
|
182
|
-
*/
|
|
183
|
-
getApp(): Express;
|
|
184
|
-
/**
|
|
185
|
-
* Get the active HTTP/HTTPS server instance.
|
|
186
|
-
* Returns null if the server is not currently running.
|
|
187
|
-
*
|
|
188
|
-
* @returns The HTTP/HTTPS server instance or null
|
|
189
|
-
*/
|
|
190
|
-
getServer(): http.Server | https.Server | null;
|
|
191
|
-
/**
|
|
192
|
-
* Start the HTTP server and begin listening for requests.
|
|
193
|
-
*
|
|
194
|
-
* This method:
|
|
195
|
-
* - Executes beforeStart hooks
|
|
196
|
-
* - Binds to the configured host/port
|
|
197
|
-
* - Sets up error handling for startup failures
|
|
198
|
-
* - Executes afterStart hooks on success
|
|
199
|
-
* - Logs startup information
|
|
200
|
-
*
|
|
201
|
-
* @returns Promise resolving to the running HTTP server instance
|
|
202
|
-
* @throws Error if server fails to start or port is already in use
|
|
203
|
-
*/
|
|
204
|
-
start(): Promise<http.Server | https.Server>;
|
|
205
|
-
/**
|
|
206
|
-
* Stop the HTTP server gracefully.
|
|
207
|
-
*
|
|
208
|
-
* This method:
|
|
209
|
-
* - Executes beforeStop hooks
|
|
210
|
-
* - Stops accepting new connections
|
|
211
|
-
* - Waits for existing connections to finish
|
|
212
|
-
* - Closes the server
|
|
213
|
-
* - Executes afterStop hooks
|
|
214
|
-
* - Logs shutdown information
|
|
215
|
-
*
|
|
216
|
-
* Graceful shutdown ensures:
|
|
217
|
-
* - No requests are dropped
|
|
218
|
-
* - Resources are properly cleaned up
|
|
219
|
-
* - Monitoring systems are notified
|
|
220
|
-
*/
|
|
221
|
-
stop(force?: boolean): Promise<void>;
|
|
222
|
-
/**
|
|
223
|
-
* Enable graceful shutdown on OS signals for production deployment.
|
|
224
|
-
*
|
|
225
|
-
* This is essential for:
|
|
226
|
-
* - Container orchestration (Docker, Kubernetes)
|
|
227
|
-
* - Process managers (PM2, systemd)
|
|
228
|
-
* - Load balancer health checks
|
|
229
|
-
* - Zero-downtime deployments
|
|
230
|
-
*
|
|
231
|
-
* @param signals Array of process signals to listen for (default: SIGINT, SIGTERM)
|
|
232
|
-
*/
|
|
233
|
-
enableGracefulShutdown(signals?: NodeJS.Signals[]): this;
|
|
234
|
-
/**
|
|
235
|
-
* Set an externally created base router.
|
|
236
|
-
* This will override the internal rootRouter.
|
|
237
|
-
*/
|
|
238
|
-
setBaseRouter(router: Router): this;
|
|
239
|
-
/**
|
|
240
|
-
* Create and register a new router (only used if not injecting one externally - use `setBaseRouter` instead).
|
|
241
|
-
*/
|
|
242
|
-
createRouter(prefix?: string): Router;
|
|
243
|
-
/**
|
|
244
|
-
* Register a new route handler with support for multiple HTTP methods.
|
|
245
|
-
* The route is automatically registered under the globalPrefix if set.
|
|
246
|
-
*
|
|
247
|
-
* @param methods Array of HTTP methods (get, post, put, delete, etc.)
|
|
248
|
-
* @param path Route path with Express path patterns support
|
|
249
|
-
* @param handlers One or more Express request handlers (middleware + final handler)
|
|
250
|
-
* @returns This instance for method chaining
|
|
251
|
-
*/
|
|
252
|
-
registerRoute(methods: Array<keyof Pick<Express, 'get' | 'post' | 'put' | 'delete' | 'patch' | 'options' | 'head'>>, path: string, ...handlers: Array<express.RequestHandler>): this;
|
|
253
|
-
/**
|
|
254
|
-
* Register custom middleware with optional path restriction.
|
|
255
|
-
*
|
|
256
|
-
* Use this for:
|
|
257
|
-
* - Adding authentication to specific routes
|
|
258
|
-
* - Custom logging or validation
|
|
259
|
-
* - Request transformation
|
|
260
|
-
* - Third-party middleware integration
|
|
261
|
-
*
|
|
262
|
-
* @param path Optional path prefix or middleware function if no path
|
|
263
|
-
* @param middleware Middleware handler (required if path is provided)
|
|
264
|
-
* @returns This instance for method chaining
|
|
265
|
-
*/
|
|
266
|
-
registerMiddleware(path: string | express.RequestHandler, middleware?: express.RequestHandler): this;
|
|
267
|
-
/**
|
|
268
|
-
* Register one or more middleware functions to be applied globally.
|
|
269
|
-
* This is a simpler alternative to registerMiddleware when you just want
|
|
270
|
-
* to add middleware without path restrictions.
|
|
271
|
-
*
|
|
272
|
-
* @param middlewares One or more Express middleware functions
|
|
273
|
-
* @returns This instance for method chaining
|
|
274
|
-
*/
|
|
275
|
-
useMiddleware(...middlewares: express.RequestHandler[]): this;
|
|
276
|
-
/**
|
|
277
|
-
* Get Prometheus registry (to add custom counters/histograms)
|
|
278
|
-
*
|
|
279
|
-
* @return {*} {client.Registry}
|
|
280
|
-
*/
|
|
281
|
-
getMetricsRegistry(): typeof import("prom-client").Registry;
|
|
282
|
-
/**
|
|
283
|
-
* Get server configuration
|
|
284
|
-
*
|
|
285
|
-
* @return {*} {ServerConfig}
|
|
286
|
-
*/
|
|
287
|
-
getConfig(): ServerConfig;
|
|
288
|
-
/**
|
|
289
|
-
* Wait until server initialization (middleware + routes) has completed.
|
|
290
|
-
* Useful for integration tests that inspect app before starting.
|
|
291
|
-
*/
|
|
292
|
-
waitUntilReady(): Promise<void>;
|
|
293
|
-
private normalizePath;
|
|
294
|
-
private normalizeRouteForMetrics;
|
|
295
|
-
/**
|
|
296
|
-
* Destroy all active connections (gracefully if possible).
|
|
297
|
-
* If a connection does not close cleanly, it will be force-destroyed.
|
|
298
|
-
*/
|
|
299
|
-
private destroyConnections;
|
|
300
|
-
private validateHttpsFiles;
|
|
301
|
-
private isBuiltServerConfig;
|
|
302
|
-
private throwDependancyError;
|
|
303
|
-
}
|
package/stream/stream.utils.d.ts
DELETED
|
@@ -1,111 +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 { Readable, Transform } from 'stream';
|
|
26
|
-
import type { BufferEncoding } from '@catbee/utils/crypto';
|
|
27
|
-
/**
|
|
28
|
-
* Convert a buffer or string to a readable stream.
|
|
29
|
-
*
|
|
30
|
-
* @param data - Buffer or string to convert
|
|
31
|
-
* @returns Readable stream containing the data
|
|
32
|
-
*
|
|
33
|
-
* @example
|
|
34
|
-
* ```typescript
|
|
35
|
-
* const stream = bufferToStream(Buffer.from('Hello world'));
|
|
36
|
-
* // or
|
|
37
|
-
* const stream = bufferToStream('Hello world');
|
|
38
|
-
* ```
|
|
39
|
-
*/
|
|
40
|
-
export declare function bufferToStream(data: Buffer | string): Readable;
|
|
41
|
-
/**
|
|
42
|
-
* Convert a readable stream to a buffer.
|
|
43
|
-
*
|
|
44
|
-
* @param stream - Readable stream to convert
|
|
45
|
-
* @returns Promise resolving to a buffer containing all stream data
|
|
46
|
-
*
|
|
47
|
-
* @example
|
|
48
|
-
* ```typescript
|
|
49
|
-
* const buffer = await streamToBuffer(fs.createReadStream('file.txt'));
|
|
50
|
-
* console.log(buffer.toString()); // Contents of file.txt
|
|
51
|
-
* ```
|
|
52
|
-
*/
|
|
53
|
-
export declare function streamToBuffer(stream: Readable): Promise<Buffer>;
|
|
54
|
-
/**
|
|
55
|
-
* Convert a readable stream to a string.
|
|
56
|
-
*
|
|
57
|
-
* @param stream - Readable stream to convert
|
|
58
|
-
* @param encoding - Character encoding (default: 'utf8')
|
|
59
|
-
* @returns Promise resolving to a string containing all stream data
|
|
60
|
-
*
|
|
61
|
-
* @example
|
|
62
|
-
* ```typescript
|
|
63
|
-
* const content = await streamToString(fs.createReadStream('file.txt'));
|
|
64
|
-
* console.log(content); // Contents of file.txt as string
|
|
65
|
-
* ```
|
|
66
|
-
*/
|
|
67
|
-
export declare function streamToString(stream: Readable, encoding?: BufferEncoding): Promise<string>;
|
|
68
|
-
/**
|
|
69
|
-
* Create a transform stream that limits the rate of data flow.
|
|
70
|
-
*
|
|
71
|
-
* @param bytesPerSecond - Maximum bytes per second
|
|
72
|
-
* @returns Transform stream that throttles data flow
|
|
73
|
-
*/
|
|
74
|
-
export declare function createThrottleStream(bytesPerSecond: number): Transform;
|
|
75
|
-
/**
|
|
76
|
-
* Create a transform stream that batches data into chunks of specified size.
|
|
77
|
-
*
|
|
78
|
-
* @param size - Size of each batch (items for object mode, bytes for binary mode)
|
|
79
|
-
* @param options - Stream options
|
|
80
|
-
* @returns Transform stream that batches data
|
|
81
|
-
*
|
|
82
|
-
* @example
|
|
83
|
-
* ```typescript
|
|
84
|
-
* // Batch lines from a file into arrays of 100 lines each
|
|
85
|
-
* createReadStream('large-file.txt')
|
|
86
|
-
* .pipe(createLineStream())
|
|
87
|
-
* .pipe(createBatchStream(100))
|
|
88
|
-
* .on('data', batch => console.log(`Processing batch of ${batch.length} lines`));
|
|
89
|
-
* ```
|
|
90
|
-
*/
|
|
91
|
-
export declare function createBatchStream(size: number, options?: {
|
|
92
|
-
objectMode?: boolean;
|
|
93
|
-
}): Transform;
|
|
94
|
-
/**
|
|
95
|
-
* Create a transform stream that splits text data by newlines.
|
|
96
|
-
*
|
|
97
|
-
* @param options - Options for the line stream
|
|
98
|
-
* @returns Transform stream that emits lines
|
|
99
|
-
*
|
|
100
|
-
* @example
|
|
101
|
-
* ```typescript
|
|
102
|
-
* // Process a file line by line
|
|
103
|
-
* createReadStream('file.txt')
|
|
104
|
-
* .pipe(createLineStream())
|
|
105
|
-
* .on('data', line => console.log(`Line: ${line}`));
|
|
106
|
-
* ```
|
|
107
|
-
*/
|
|
108
|
-
export declare function createLineStream(options?: {
|
|
109
|
-
encoding?: BufferEncoding;
|
|
110
|
-
includeNewlines?: boolean;
|
|
111
|
-
}): Transform;
|
package/string/string.utils.d.ts
DELETED
|
@@ -1,124 +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
|
-
* Capitalizes the first character of a string.
|
|
27
|
-
*
|
|
28
|
-
* @param {string} str - The input string.
|
|
29
|
-
* @returns {string} The string with the first character in uppercase.
|
|
30
|
-
*/
|
|
31
|
-
export declare function capitalize(str: string): string;
|
|
32
|
-
/**
|
|
33
|
-
* Converts a string to kebab-case (e.g., "FooBar test" → "foo-bar-test").
|
|
34
|
-
*
|
|
35
|
-
* @param {string} str - The input string.
|
|
36
|
-
* @returns {string} The kebab-cased string.
|
|
37
|
-
*/
|
|
38
|
-
export declare function toKebabCase(str: string): string;
|
|
39
|
-
/**
|
|
40
|
-
* Converts a kebab-case or snake_case string to camelCase.
|
|
41
|
-
*
|
|
42
|
-
* @param {string} str - The input string.
|
|
43
|
-
* @returns {string} The camelCased string.
|
|
44
|
-
*/
|
|
45
|
-
export declare function toCamelCase(str: string): string;
|
|
46
|
-
/**
|
|
47
|
-
* Converts a string to a URL-friendly slug (lowercase, dashes, alphanumeric).
|
|
48
|
-
*
|
|
49
|
-
* @param {string} str - The input string.
|
|
50
|
-
* @returns {string} The slugified string.
|
|
51
|
-
*/
|
|
52
|
-
export declare function slugify(str: string): string;
|
|
53
|
-
/**
|
|
54
|
-
* Truncates a string to a specific length, appending '...' if truncated.
|
|
55
|
-
*
|
|
56
|
-
* @param {string} str - The input string.
|
|
57
|
-
* @param {number} len - The maximum length.
|
|
58
|
-
* @returns {string} The truncated string.
|
|
59
|
-
*/
|
|
60
|
-
export declare function truncate(str: string, len: number): string;
|
|
61
|
-
/**
|
|
62
|
-
* Converts a string to PascalCase (e.g., "foo-bar" → "FooBar").
|
|
63
|
-
*
|
|
64
|
-
* @param {string} str - The input string.
|
|
65
|
-
* @returns {string} The PascalCased string.
|
|
66
|
-
*/
|
|
67
|
-
export declare function toPascalCase(str: string): string;
|
|
68
|
-
/**
|
|
69
|
-
* Converts a string to snake_case (e.g., "FooBar test" → "foo_bar_test").
|
|
70
|
-
*
|
|
71
|
-
* @param {string} str - The input string.
|
|
72
|
-
* @returns {string} The snake_cased string.
|
|
73
|
-
*/
|
|
74
|
-
export declare function toSnakeCase(str: string): string;
|
|
75
|
-
/**
|
|
76
|
-
* Masks a string by replacing characters with a mask character.
|
|
77
|
-
* Useful for hiding sensitive information like credit cards or passwords.
|
|
78
|
-
*
|
|
79
|
-
* @param {string} str - The string to mask.
|
|
80
|
-
* @param {number} [visibleStart=0] - Number of characters to show at start.
|
|
81
|
-
* @param {number} [visibleEnd=0] - Number of characters to show at end.
|
|
82
|
-
* @param {string} [maskChar="*"] - Character to use for masking.
|
|
83
|
-
* @returns {string} The masked string.
|
|
84
|
-
*/
|
|
85
|
-
export declare function mask(str: string, visibleStart?: number, visibleEnd?: number, maskChar?: string): string;
|
|
86
|
-
/**
|
|
87
|
-
* Removes all HTML tags from a string.
|
|
88
|
-
*
|
|
89
|
-
* @param {string} str - The HTML string to process.
|
|
90
|
-
* @returns {string} The string with HTML tags removed.
|
|
91
|
-
*/
|
|
92
|
-
export declare function stripHtml(str: string): string;
|
|
93
|
-
/**
|
|
94
|
-
* Performs case-insensitive string comparison.
|
|
95
|
-
*
|
|
96
|
-
* @param {string} a - First string.
|
|
97
|
-
* @param {string} b - Second string.
|
|
98
|
-
* @returns {boolean} True if the strings are equal ignoring case.
|
|
99
|
-
*/
|
|
100
|
-
export declare function equalsIgnoreCase(a: string, b: string): boolean;
|
|
101
|
-
/**
|
|
102
|
-
* Reverses a string.
|
|
103
|
-
*
|
|
104
|
-
* @param {string} str - The string to reverse.
|
|
105
|
-
* @returns {string} The reversed string.
|
|
106
|
-
*/
|
|
107
|
-
export declare function reverse(str: string): string;
|
|
108
|
-
/**
|
|
109
|
-
* Counts occurrences of a substring within a string.
|
|
110
|
-
*
|
|
111
|
-
* @param {string} str - The source string.
|
|
112
|
-
* @param {string} substring - The substring to count.
|
|
113
|
-
* @param {boolean} [caseSensitive=true] - Whether to perform case-sensitive counting.
|
|
114
|
-
* @returns {number} Number of occurrences.
|
|
115
|
-
*/
|
|
116
|
-
export declare function countOccurrences(str: string, substring: string, caseSensitive?: boolean): number;
|
|
117
|
-
/**
|
|
118
|
-
* Convert a string to Title Case (each word capitalized).
|
|
119
|
-
* Preserves existing spacing and punctuation between words.
|
|
120
|
-
*
|
|
121
|
-
* @param str - Input string
|
|
122
|
-
* @returns Title-cased string
|
|
123
|
-
*/
|
|
124
|
-
export declare function toTitleCase(str: string): string;
|
package/type/type.utils.d.ts
DELETED
|
@@ -1,129 +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
|
-
* Check if a value is of a specific primitive type.
|
|
27
|
-
*
|
|
28
|
-
* @param value - Value to check
|
|
29
|
-
* @param type - Type to check against
|
|
30
|
-
* @returns Whether the value is of the specified type
|
|
31
|
-
*
|
|
32
|
-
* @example
|
|
33
|
-
* ```typescript
|
|
34
|
-
* isPrimitiveType('hello', 'string'); // true
|
|
35
|
-
* isPrimitiveType(42, 'number'); // true
|
|
36
|
-
* isPrimitiveType(true, 'boolean'); // true
|
|
37
|
-
* isPrimitiveType(null, 'null'); // true
|
|
38
|
-
* isPrimitiveType(undefined, 'undefined'); // true
|
|
39
|
-
* isPrimitiveType({}, 'object'); // true
|
|
40
|
-
* isPrimitiveType([], 'array'); // true
|
|
41
|
-
* ```
|
|
42
|
-
*/
|
|
43
|
-
export declare function isPrimitiveType(value: unknown, type: 'string' | 'number' | 'boolean' | 'symbol' | 'bigint' | 'function' | 'object' | 'array' | 'null' | 'undefined'): boolean;
|
|
44
|
-
/**
|
|
45
|
-
* Get the primitive type of a value as a string.
|
|
46
|
-
*
|
|
47
|
-
* @param value - Value to get the type of
|
|
48
|
-
* @returns String representing the type
|
|
49
|
-
*
|
|
50
|
-
* @example
|
|
51
|
-
* ```typescript
|
|
52
|
-
* getTypeOf('hello'); // 'string'
|
|
53
|
-
* getTypeOf(42); // 'number'
|
|
54
|
-
* getTypeOf([]); // 'array'
|
|
55
|
-
* getTypeOf(null); // 'null'
|
|
56
|
-
* ```
|
|
57
|
-
*/
|
|
58
|
-
export declare function getTypeOf(value: unknown): string;
|
|
59
|
-
/**
|
|
60
|
-
* Type guard for checking if a value is an array of a specific type.
|
|
61
|
-
*
|
|
62
|
-
* @param value - Value to check
|
|
63
|
-
* @param itemTypeGuard - Function that checks if items are of the expected type
|
|
64
|
-
* @returns True if the value is an array with items of the expected type
|
|
65
|
-
*
|
|
66
|
-
* @example
|
|
67
|
-
* ```typescript
|
|
68
|
-
* isArrayOf([1, 2, 3], (item): item is number => typeof item === 'number'); // true
|
|
69
|
-
* isArrayOf(['a', 'b', 'c'], (item): item is string => typeof item === 'string'); // true
|
|
70
|
-
* isArrayOf([1, '2', 3], (item): item is number => typeof item === 'number'); // false
|
|
71
|
-
* ```
|
|
72
|
-
*/
|
|
73
|
-
export declare function isArrayOf<T>(value: unknown, itemTypeGuard: (item: unknown) => item is T): value is T[];
|
|
74
|
-
/**
|
|
75
|
-
* Convert a value to a string.
|
|
76
|
-
*
|
|
77
|
-
* @param value - Value to convert
|
|
78
|
-
* @param defaultValue - Default value if conversion fails
|
|
79
|
-
* @returns String representation of the value
|
|
80
|
-
*/
|
|
81
|
-
export declare function toStr(value: unknown, defaultValue?: string): string;
|
|
82
|
-
/**
|
|
83
|
-
* Convert a value to a number.
|
|
84
|
-
*
|
|
85
|
-
* @param value - Value to convert
|
|
86
|
-
* @param defaultValue - Default value if conversion fails
|
|
87
|
-
* @returns Numeric representation of the value
|
|
88
|
-
*/
|
|
89
|
-
export declare function toNum(value: unknown, defaultValue?: number): number;
|
|
90
|
-
/**
|
|
91
|
-
* Convert a value to a boolean.
|
|
92
|
-
*
|
|
93
|
-
* @param value - Value to convert
|
|
94
|
-
* @param defaultValue - Default value if conversion fails
|
|
95
|
-
* @returns Boolean representation of the value
|
|
96
|
-
*/
|
|
97
|
-
export declare function toBool(value: unknown, defaultValue?: boolean): boolean;
|
|
98
|
-
/**
|
|
99
|
-
* Ensure a value matches the expected type, or provide a default.
|
|
100
|
-
*
|
|
101
|
-
* @param value - Value to check
|
|
102
|
-
* @param expectedType - Expected primitive type
|
|
103
|
-
* @param defaultValue - Default value to use if type doesn't match
|
|
104
|
-
* @returns The value if it matches the type, otherwise the default
|
|
105
|
-
*
|
|
106
|
-
* @example
|
|
107
|
-
* ```typescript
|
|
108
|
-
* ensureType(42, 'number', 0); // 42
|
|
109
|
-
* ensureType('42', 'number', 0); // 0
|
|
110
|
-
* ensureType(undefined, 'string', 'default'); // 'default'
|
|
111
|
-
* ```
|
|
112
|
-
*/
|
|
113
|
-
export declare function ensureType<T>(value: unknown, expectedType: string, defaultValue: T): T;
|
|
114
|
-
/**
|
|
115
|
-
* Check whether a value is neither null nor undefined.
|
|
116
|
-
* Useful in filter chains and guards.
|
|
117
|
-
*
|
|
118
|
-
* @param value - Value to check
|
|
119
|
-
* @returns True when value !== null && value !== undefined
|
|
120
|
-
*/
|
|
121
|
-
export declare function isDefined<T>(value: T | null | undefined): value is T;
|
|
122
|
-
/**
|
|
123
|
-
* Check whether a value is empty.
|
|
124
|
-
* Supports strings, arrays, maps, sets and plain objects.
|
|
125
|
-
*
|
|
126
|
-
* @param value - Value to inspect
|
|
127
|
-
* @returns True when value is considered empty
|
|
128
|
-
*/
|
|
129
|
-
export declare function isEmpty(value: any): boolean;
|