@catbee/utils 0.0.8-rc.2 → 0.0.8-rc.3

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 (66) hide show
  1. package/build/cjs/config.d.ts +121 -0
  2. package/build/cjs/config.js +137 -0
  3. package/build/cjs/index.d.ts +26 -0
  4. package/build/cjs/index.js +68 -0
  5. package/build/cjs/servers/server.builder.d.ts +507 -0
  6. package/build/cjs/servers/server.builder.js +658 -0
  7. package/build/cjs/servers/server.d.ts +255 -0
  8. package/build/cjs/servers/server.js +970 -0
  9. package/build/cjs/types/api-response.d.ts +151 -0
  10. package/build/cjs/types/api-response.js +36 -0
  11. package/build/cjs/types/index.d.ts +124 -0
  12. package/build/cjs/types/index.js +25 -0
  13. package/build/cjs/types/server.d.ts +267 -0
  14. package/build/cjs/types/server.js +25 -0
  15. package/build/cjs/utils/array.utils.d.ts +167 -0
  16. package/build/cjs/utils/array.utils.js +363 -0
  17. package/build/cjs/utils/async.utils.d.ts +264 -0
  18. package/build/cjs/utils/async.utils.js +640 -0
  19. package/build/cjs/utils/cache.utils.d.ts +152 -0
  20. package/build/cjs/utils/cache.utils.js +298 -0
  21. package/build/cjs/utils/context-store.utils.d.ts +188 -0
  22. package/build/cjs/utils/context-store.utils.js +297 -0
  23. package/build/cjs/utils/crypto.utils.d.ts +159 -0
  24. package/build/cjs/utils/crypto.utils.js +295 -0
  25. package/build/cjs/utils/date.utils.d.ts +158 -0
  26. package/build/cjs/utils/date.utils.js +395 -0
  27. package/build/cjs/utils/decorators.utils.d.ts +511 -0
  28. package/build/cjs/utils/decorators.utils.js +1035 -0
  29. package/build/cjs/utils/dir.utils.d.ts +195 -0
  30. package/build/cjs/utils/dir.utils.js +500 -0
  31. package/build/cjs/utils/env.utils.d.ts +376 -0
  32. package/build/cjs/utils/env.utils.js +786 -0
  33. package/build/cjs/utils/exception.utils.d.ts +229 -0
  34. package/build/cjs/utils/exception.utils.js +408 -0
  35. package/build/cjs/utils/fs.utils.d.ts +163 -0
  36. package/build/cjs/utils/fs.utils.js +371 -0
  37. package/build/cjs/utils/http-status-codes.d.ts +265 -0
  38. package/build/cjs/utils/http-status-codes.js +297 -0
  39. package/build/cjs/utils/id.utils.d.ts +35 -0
  40. package/build/cjs/utils/id.utils.js +90 -0
  41. package/build/cjs/utils/logger.utils.d.ts +159 -0
  42. package/build/cjs/utils/logger.utils.js +350 -0
  43. package/build/cjs/utils/middleware.utils.d.ts +99 -0
  44. package/build/cjs/utils/middleware.utils.js +243 -0
  45. package/build/cjs/utils/obj.utils.d.ts +123 -0
  46. package/build/cjs/utils/obj.utils.js +428 -0
  47. package/build/cjs/utils/performance.utils.d.ts +135 -0
  48. package/build/cjs/utils/performance.utils.js +280 -0
  49. package/build/cjs/utils/request.utils.d.ts +85 -0
  50. package/build/cjs/utils/request.utils.js +199 -0
  51. package/build/cjs/utils/response.utils.d.ts +162 -0
  52. package/build/cjs/utils/response.utils.js +274 -0
  53. package/build/cjs/utils/stream.utils.d.ts +87 -0
  54. package/build/cjs/utils/stream.utils.js +217 -0
  55. package/build/cjs/utils/string.utils.d.ts +92 -0
  56. package/build/cjs/utils/string.utils.js +178 -0
  57. package/build/cjs/utils/type.utils.d.ts +89 -0
  58. package/build/cjs/utils/type.utils.js +195 -0
  59. package/build/cjs/utils/url.utils.d.ts +140 -0
  60. package/build/cjs/utils/url.utils.js +316 -0
  61. package/build/cjs/utils/validate.utils.d.ts +176 -0
  62. package/build/cjs/utils/validate.utils.js +344 -0
  63. package/build/esm/utils/context-store.utils.d.ts +1 -1
  64. package/build/esm/utils/context-store.utils.js +1 -1
  65. package/build/esm/utils/decorators.utils.js +1 -1
  66. package/package.json +287 -32
@@ -0,0 +1,265 @@
1
+ /**
2
+ * Complete HTTP status codes enum with descriptions.
3
+ * For use with API responses and error handling.
4
+ */
5
+ export declare enum HttpStatusCodes {
6
+ /**
7
+ * The server has received the request headers and the client should proceed to send the request body.
8
+ */
9
+ CONTINUE = 100,
10
+ /**
11
+ * The server is switching protocols according to the client's request.
12
+ */
13
+ SWITCHING_PROTOCOLS = 101,
14
+ /**
15
+ * Server has received the request and is still processing it.
16
+ */
17
+ PROCESSING = 102,
18
+ /**
19
+ * The server is sending preliminary headers while preparing the final response.
20
+ */
21
+ EARLY_HINTS = 103,
22
+ /**
23
+ * The request succeeded. The result meaning depends on the HTTP method used.
24
+ */
25
+ OK = 200,
26
+ /**
27
+ * The request succeeded and a new resource was created as a result.
28
+ */
29
+ CREATED = 201,
30
+ /**
31
+ * The request has been received but not yet acted upon.
32
+ */
33
+ ACCEPTED = 202,
34
+ /**
35
+ * The returned information is from a third-party source, not the origin server.
36
+ */
37
+ NON_AUTHORITATIVE_INFORMATION = 203,
38
+ /**
39
+ * The request succeeded but there's no content to send in the response.
40
+ */
41
+ NO_CONTENT = 204,
42
+ /**
43
+ * The client should reset the document view that caused this request.
44
+ */
45
+ RESET_CONTENT = 205,
46
+ /**
47
+ * The server is delivering only part of the resource due to a range header sent by the client.
48
+ */
49
+ PARTIAL_CONTENT = 206,
50
+ /**
51
+ * Conveys information about multiple resources, for complex operations.
52
+ */
53
+ MULTI_STATUS = 207,
54
+ /**
55
+ * The members of a DAV binding have already been enumerated and are not included in the response.
56
+ */
57
+ ALREADY_REPORTED = 208,
58
+ /**
59
+ * The server has fulfilled a request for the resource, and the response represents the result of one or more instance-manipulations.
60
+ */
61
+ IM_USED = 226,
62
+ /**
63
+ * The request has more than one possible response and the client should choose one.
64
+ */
65
+ MULTIPLE_CHOICES = 300,
66
+ /**
67
+ * The resource has been permanently moved to a new URL.
68
+ */
69
+ MOVED_PERMANENTLY = 301,
70
+ /**
71
+ * The resource has been temporarily moved to another URL.
72
+ */
73
+ MOVED_TEMPORARILY = 302,
74
+ /**
75
+ * The response to the request can be found under another URI using the GET method.
76
+ */
77
+ SEE_OTHER = 303,
78
+ /**
79
+ * The resource hasn't been modified since the last request.
80
+ */
81
+ NOT_MODIFIED = 304,
82
+ /**
83
+ * @deprecated
84
+ * Response must be accessed through a proxy.
85
+ */
86
+ USE_PROXY = 305,
87
+ /**
88
+ * The resource is temporarily available at a different URI, using the same HTTP method.
89
+ */
90
+ TEMPORARY_REDIRECT = 307,
91
+ /**
92
+ * The resource has been permanently moved to another URL, using the same HTTP method.
93
+ */
94
+ PERMANENT_REDIRECT = 308,
95
+ /**
96
+ * The server cannot process the request due to a client error (malformed request).
97
+ */
98
+ BAD_REQUEST = 400,
99
+ /**
100
+ * Authentication is required and has failed or not been provided.
101
+ */
102
+ UNAUTHORIZED = 401,
103
+ /**
104
+ * Reserved for future use, originally intended for digital payment systems.
105
+ */
106
+ PAYMENT_REQUIRED = 402,
107
+ /**
108
+ * The client doesn't have permission to access the requested resource.
109
+ */
110
+ FORBIDDEN = 403,
111
+ /**
112
+ * The requested resource could not be found on the server.
113
+ */
114
+ NOT_FOUND = 404,
115
+ /**
116
+ * The request method is not supported for the requested resource.
117
+ */
118
+ METHOD_NOT_ALLOWED = 405,
119
+ /**
120
+ * The server can't provide a response matching the list of acceptable values in the client's headers.
121
+ */
122
+ NOT_ACCEPTABLE = 406,
123
+ /**
124
+ * Authentication by a proxy is required.
125
+ */
126
+ PROXY_AUTHENTICATION_REQUIRED = 407,
127
+ /**
128
+ * The server timed out waiting for the request.
129
+ */
130
+ REQUEST_TIMEOUT = 408,
131
+ /**
132
+ * The request conflicts with the current state of the server.
133
+ */
134
+ CONFLICT = 409,
135
+ /**
136
+ * The resource has been permanently deleted with no forwarding address.
137
+ */
138
+ GONE = 410,
139
+ /**
140
+ * The server requires a Content-Length header field.
141
+ */
142
+ LENGTH_REQUIRED = 411,
143
+ /**
144
+ * Preconditions in the client's headers failed.
145
+ */
146
+ PRECONDITION_FAILED = 412,
147
+ /**
148
+ * Request entity is larger than limits defined by server.
149
+ */
150
+ REQUEST_TOO_LONG = 413,
151
+ /**
152
+ * The request payload exceeds server size limits.
153
+ * Modern equivalent of REQUEST_TOO_LONG.
154
+ */
155
+ PAYLOAD_TOO_LARGE = 413,
156
+ /**
157
+ * The URI requested is too long for the server to interpret.
158
+ */
159
+ REQUEST_URI_TOO_LONG = 414,
160
+ /**
161
+ * The server does not support the media type requested by the client.
162
+ */
163
+ UNSUPPORTED_MEDIA_TYPE = 415,
164
+ /**
165
+ * The range specified by the Range header cannot be fulfilled.
166
+ */
167
+ REQUESTED_RANGE_NOT_SATISFIABLE = 416,
168
+ /**
169
+ * The server cannot meet the expectations given in the Expect header.
170
+ */
171
+ EXPECTATION_FAILED = 417,
172
+ /**
173
+ * The server refuses to brew coffee because it is a teapot. (April Fools' joke)
174
+ */
175
+ IM_A_TEAPOT = 418,
176
+ /**
177
+ * The server cannot store the representation needed to complete the request.
178
+ */
179
+ INSUFFICIENT_SPACE_ON_RESOURCE = 419,
180
+ /**
181
+ * @deprecated
182
+ * A method has failed - specific to Spring Framework.
183
+ */
184
+ METHOD_FAILURE = 420,
185
+ /**
186
+ * The server cannot produce a response for the requested URI scheme and authority.
187
+ */
188
+ MISDIRECTED_REQUEST = 421,
189
+ /**
190
+ * The request was well-formed but has semantic errors preventing processing.
191
+ */
192
+ UNPROCESSABLE_ENTITY = 422,
193
+ /**
194
+ * The requested resource is locked against access.
195
+ */
196
+ LOCKED = 423,
197
+ /**
198
+ * The request failed due to the failure of a previous request.
199
+ */
200
+ FAILED_DEPENDENCY = 424,
201
+ /**
202
+ * The client should switch to a different protocol.
203
+ */
204
+ UPGRADE_REQUIRED = 426,
205
+ /**
206
+ * The server requires conditional requests to prevent lost updates.
207
+ */
208
+ PRECONDITION_REQUIRED = 428,
209
+ /**
210
+ * The client has sent too many requests in a given time period (rate limiting).
211
+ */
212
+ TOO_MANY_REQUESTS = 429,
213
+ /**
214
+ * Request headers are too large for the server to process.
215
+ */
216
+ REQUEST_HEADER_FIELDS_TOO_LARGE = 431,
217
+ /**
218
+ * Resource cannot be legally provided (e.g., censored by government).
219
+ */
220
+ UNAVAILABLE_FOR_LEGAL_REASONS = 451,
221
+ /**
222
+ * The server encountered an unexpected error preventing it from fulfilling the request.
223
+ */
224
+ INTERNAL_SERVER_ERROR = 500,
225
+ /**
226
+ * The server does not support the functionality required to fulfill the request.
227
+ */
228
+ NOT_IMPLEMENTED = 501,
229
+ /**
230
+ * The server, acting as a gateway, received an invalid response from an upstream server.
231
+ */
232
+ BAD_GATEWAY = 502,
233
+ /**
234
+ * The server is currently unable to handle the request due to temporary overload or maintenance.
235
+ */
236
+ SERVICE_UNAVAILABLE = 503,
237
+ /**
238
+ * The server, acting as a gateway, did not receive a timely response from an upstream server.
239
+ */
240
+ GATEWAY_TIMEOUT = 504,
241
+ /**
242
+ * The server does not support the HTTP protocol version used in the request.
243
+ */
244
+ HTTP_VERSION_NOT_SUPPORTED = 505,
245
+ /**
246
+ * Transparent content negotiation for the request resulted in circular reference.
247
+ */
248
+ VARIANT_ALSO_NEGOTIATES = 506,
249
+ /**
250
+ * The server cannot store the representation needed to complete the request.
251
+ */
252
+ INSUFFICIENT_STORAGE = 507,
253
+ /**
254
+ * The server detected an infinite loop while processing the request.
255
+ */
256
+ LOOP_DETECTED = 508,
257
+ /**
258
+ * Further extensions to the request are required for the server to fulfill it.
259
+ */
260
+ NOT_EXTENDED = 510,
261
+ /**
262
+ * The client needs to authenticate to gain network access.
263
+ */
264
+ NETWORK_AUTHENTICATION_REQUIRED = 511
265
+ }
@@ -0,0 +1,297 @@
1
+ "use strict";
2
+ /*
3
+ * The MIT License
4
+ *
5
+ * Copyright (c) 2025 Catbee Technologies. https://catbee-utils.npm.hprasath.com/license
6
+ *
7
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ * of this software and associated documentation files (the "Software"), to deal
9
+ * in the Software without restriction, including without limitation the rights
10
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ * copies of the Software, and to permit persons to whom the Software is
12
+ * furnished to do so, subject to the following conditions:
13
+ *
14
+ * The above copyright notice and this permission notice shall be included in all
15
+ * copies or substantial portions of the Software.
16
+ *
17
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
+ * SOFTWARE.
24
+ */
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.HttpStatusCodes = void 0;
27
+ /**
28
+ * Complete HTTP status codes enum with descriptions.
29
+ * For use with API responses and error handling.
30
+ */
31
+ var HttpStatusCodes;
32
+ (function (HttpStatusCodes) {
33
+ // 1xx Informational
34
+ /**
35
+ * The server has received the request headers and the client should proceed to send the request body.
36
+ */
37
+ HttpStatusCodes[HttpStatusCodes["CONTINUE"] = 100] = "CONTINUE";
38
+ /**
39
+ * The server is switching protocols according to the client's request.
40
+ */
41
+ HttpStatusCodes[HttpStatusCodes["SWITCHING_PROTOCOLS"] = 101] = "SWITCHING_PROTOCOLS";
42
+ /**
43
+ * Server has received the request and is still processing it.
44
+ */
45
+ HttpStatusCodes[HttpStatusCodes["PROCESSING"] = 102] = "PROCESSING";
46
+ /**
47
+ * The server is sending preliminary headers while preparing the final response.
48
+ */
49
+ HttpStatusCodes[HttpStatusCodes["EARLY_HINTS"] = 103] = "EARLY_HINTS";
50
+ // 2xx Success
51
+ /**
52
+ * The request succeeded. The result meaning depends on the HTTP method used.
53
+ */
54
+ HttpStatusCodes[HttpStatusCodes["OK"] = 200] = "OK";
55
+ /**
56
+ * The request succeeded and a new resource was created as a result.
57
+ */
58
+ HttpStatusCodes[HttpStatusCodes["CREATED"] = 201] = "CREATED";
59
+ /**
60
+ * The request has been received but not yet acted upon.
61
+ */
62
+ HttpStatusCodes[HttpStatusCodes["ACCEPTED"] = 202] = "ACCEPTED";
63
+ /**
64
+ * The returned information is from a third-party source, not the origin server.
65
+ */
66
+ HttpStatusCodes[HttpStatusCodes["NON_AUTHORITATIVE_INFORMATION"] = 203] = "NON_AUTHORITATIVE_INFORMATION";
67
+ /**
68
+ * The request succeeded but there's no content to send in the response.
69
+ */
70
+ HttpStatusCodes[HttpStatusCodes["NO_CONTENT"] = 204] = "NO_CONTENT";
71
+ /**
72
+ * The client should reset the document view that caused this request.
73
+ */
74
+ HttpStatusCodes[HttpStatusCodes["RESET_CONTENT"] = 205] = "RESET_CONTENT";
75
+ /**
76
+ * The server is delivering only part of the resource due to a range header sent by the client.
77
+ */
78
+ HttpStatusCodes[HttpStatusCodes["PARTIAL_CONTENT"] = 206] = "PARTIAL_CONTENT";
79
+ /**
80
+ * Conveys information about multiple resources, for complex operations.
81
+ */
82
+ HttpStatusCodes[HttpStatusCodes["MULTI_STATUS"] = 207] = "MULTI_STATUS";
83
+ /**
84
+ * The members of a DAV binding have already been enumerated and are not included in the response.
85
+ */
86
+ HttpStatusCodes[HttpStatusCodes["ALREADY_REPORTED"] = 208] = "ALREADY_REPORTED";
87
+ /**
88
+ * The server has fulfilled a request for the resource, and the response represents the result of one or more instance-manipulations.
89
+ */
90
+ HttpStatusCodes[HttpStatusCodes["IM_USED"] = 226] = "IM_USED";
91
+ // 3xx Redirection
92
+ /**
93
+ * The request has more than one possible response and the client should choose one.
94
+ */
95
+ HttpStatusCodes[HttpStatusCodes["MULTIPLE_CHOICES"] = 300] = "MULTIPLE_CHOICES";
96
+ /**
97
+ * The resource has been permanently moved to a new URL.
98
+ */
99
+ HttpStatusCodes[HttpStatusCodes["MOVED_PERMANENTLY"] = 301] = "MOVED_PERMANENTLY";
100
+ /**
101
+ * The resource has been temporarily moved to another URL.
102
+ */
103
+ HttpStatusCodes[HttpStatusCodes["MOVED_TEMPORARILY"] = 302] = "MOVED_TEMPORARILY";
104
+ /**
105
+ * The response to the request can be found under another URI using the GET method.
106
+ */
107
+ HttpStatusCodes[HttpStatusCodes["SEE_OTHER"] = 303] = "SEE_OTHER";
108
+ /**
109
+ * The resource hasn't been modified since the last request.
110
+ */
111
+ HttpStatusCodes[HttpStatusCodes["NOT_MODIFIED"] = 304] = "NOT_MODIFIED";
112
+ /**
113
+ * @deprecated
114
+ * Response must be accessed through a proxy.
115
+ */
116
+ HttpStatusCodes[HttpStatusCodes["USE_PROXY"] = 305] = "USE_PROXY";
117
+ /**
118
+ * The resource is temporarily available at a different URI, using the same HTTP method.
119
+ */
120
+ HttpStatusCodes[HttpStatusCodes["TEMPORARY_REDIRECT"] = 307] = "TEMPORARY_REDIRECT";
121
+ /**
122
+ * The resource has been permanently moved to another URL, using the same HTTP method.
123
+ */
124
+ HttpStatusCodes[HttpStatusCodes["PERMANENT_REDIRECT"] = 308] = "PERMANENT_REDIRECT";
125
+ // 4xx Client Error
126
+ /**
127
+ * The server cannot process the request due to a client error (malformed request).
128
+ */
129
+ HttpStatusCodes[HttpStatusCodes["BAD_REQUEST"] = 400] = "BAD_REQUEST";
130
+ /**
131
+ * Authentication is required and has failed or not been provided.
132
+ */
133
+ HttpStatusCodes[HttpStatusCodes["UNAUTHORIZED"] = 401] = "UNAUTHORIZED";
134
+ /**
135
+ * Reserved for future use, originally intended for digital payment systems.
136
+ */
137
+ HttpStatusCodes[HttpStatusCodes["PAYMENT_REQUIRED"] = 402] = "PAYMENT_REQUIRED";
138
+ /**
139
+ * The client doesn't have permission to access the requested resource.
140
+ */
141
+ HttpStatusCodes[HttpStatusCodes["FORBIDDEN"] = 403] = "FORBIDDEN";
142
+ /**
143
+ * The requested resource could not be found on the server.
144
+ */
145
+ HttpStatusCodes[HttpStatusCodes["NOT_FOUND"] = 404] = "NOT_FOUND";
146
+ /**
147
+ * The request method is not supported for the requested resource.
148
+ */
149
+ HttpStatusCodes[HttpStatusCodes["METHOD_NOT_ALLOWED"] = 405] = "METHOD_NOT_ALLOWED";
150
+ /**
151
+ * The server can't provide a response matching the list of acceptable values in the client's headers.
152
+ */
153
+ HttpStatusCodes[HttpStatusCodes["NOT_ACCEPTABLE"] = 406] = "NOT_ACCEPTABLE";
154
+ /**
155
+ * Authentication by a proxy is required.
156
+ */
157
+ HttpStatusCodes[HttpStatusCodes["PROXY_AUTHENTICATION_REQUIRED"] = 407] = "PROXY_AUTHENTICATION_REQUIRED";
158
+ /**
159
+ * The server timed out waiting for the request.
160
+ */
161
+ HttpStatusCodes[HttpStatusCodes["REQUEST_TIMEOUT"] = 408] = "REQUEST_TIMEOUT";
162
+ /**
163
+ * The request conflicts with the current state of the server.
164
+ */
165
+ HttpStatusCodes[HttpStatusCodes["CONFLICT"] = 409] = "CONFLICT";
166
+ /**
167
+ * The resource has been permanently deleted with no forwarding address.
168
+ */
169
+ HttpStatusCodes[HttpStatusCodes["GONE"] = 410] = "GONE";
170
+ /**
171
+ * The server requires a Content-Length header field.
172
+ */
173
+ HttpStatusCodes[HttpStatusCodes["LENGTH_REQUIRED"] = 411] = "LENGTH_REQUIRED";
174
+ /**
175
+ * Preconditions in the client's headers failed.
176
+ */
177
+ HttpStatusCodes[HttpStatusCodes["PRECONDITION_FAILED"] = 412] = "PRECONDITION_FAILED";
178
+ /**
179
+ * Request entity is larger than limits defined by server.
180
+ */
181
+ HttpStatusCodes[HttpStatusCodes["REQUEST_TOO_LONG"] = 413] = "REQUEST_TOO_LONG";
182
+ /**
183
+ * The request payload exceeds server size limits.
184
+ * Modern equivalent of REQUEST_TOO_LONG.
185
+ */
186
+ HttpStatusCodes[HttpStatusCodes["PAYLOAD_TOO_LARGE"] = 413] = "PAYLOAD_TOO_LARGE";
187
+ /**
188
+ * The URI requested is too long for the server to interpret.
189
+ */
190
+ HttpStatusCodes[HttpStatusCodes["REQUEST_URI_TOO_LONG"] = 414] = "REQUEST_URI_TOO_LONG";
191
+ /**
192
+ * The server does not support the media type requested by the client.
193
+ */
194
+ HttpStatusCodes[HttpStatusCodes["UNSUPPORTED_MEDIA_TYPE"] = 415] = "UNSUPPORTED_MEDIA_TYPE";
195
+ /**
196
+ * The range specified by the Range header cannot be fulfilled.
197
+ */
198
+ HttpStatusCodes[HttpStatusCodes["REQUESTED_RANGE_NOT_SATISFIABLE"] = 416] = "REQUESTED_RANGE_NOT_SATISFIABLE";
199
+ /**
200
+ * The server cannot meet the expectations given in the Expect header.
201
+ */
202
+ HttpStatusCodes[HttpStatusCodes["EXPECTATION_FAILED"] = 417] = "EXPECTATION_FAILED";
203
+ /**
204
+ * The server refuses to brew coffee because it is a teapot. (April Fools' joke)
205
+ */
206
+ HttpStatusCodes[HttpStatusCodes["IM_A_TEAPOT"] = 418] = "IM_A_TEAPOT";
207
+ /**
208
+ * The server cannot store the representation needed to complete the request.
209
+ */
210
+ HttpStatusCodes[HttpStatusCodes["INSUFFICIENT_SPACE_ON_RESOURCE"] = 419] = "INSUFFICIENT_SPACE_ON_RESOURCE";
211
+ /**
212
+ * @deprecated
213
+ * A method has failed - specific to Spring Framework.
214
+ */
215
+ HttpStatusCodes[HttpStatusCodes["METHOD_FAILURE"] = 420] = "METHOD_FAILURE";
216
+ /**
217
+ * The server cannot produce a response for the requested URI scheme and authority.
218
+ */
219
+ HttpStatusCodes[HttpStatusCodes["MISDIRECTED_REQUEST"] = 421] = "MISDIRECTED_REQUEST";
220
+ /**
221
+ * The request was well-formed but has semantic errors preventing processing.
222
+ */
223
+ HttpStatusCodes[HttpStatusCodes["UNPROCESSABLE_ENTITY"] = 422] = "UNPROCESSABLE_ENTITY";
224
+ /**
225
+ * The requested resource is locked against access.
226
+ */
227
+ HttpStatusCodes[HttpStatusCodes["LOCKED"] = 423] = "LOCKED";
228
+ /**
229
+ * The request failed due to the failure of a previous request.
230
+ */
231
+ HttpStatusCodes[HttpStatusCodes["FAILED_DEPENDENCY"] = 424] = "FAILED_DEPENDENCY";
232
+ /**
233
+ * The client should switch to a different protocol.
234
+ */
235
+ HttpStatusCodes[HttpStatusCodes["UPGRADE_REQUIRED"] = 426] = "UPGRADE_REQUIRED";
236
+ /**
237
+ * The server requires conditional requests to prevent lost updates.
238
+ */
239
+ HttpStatusCodes[HttpStatusCodes["PRECONDITION_REQUIRED"] = 428] = "PRECONDITION_REQUIRED";
240
+ /**
241
+ * The client has sent too many requests in a given time period (rate limiting).
242
+ */
243
+ HttpStatusCodes[HttpStatusCodes["TOO_MANY_REQUESTS"] = 429] = "TOO_MANY_REQUESTS";
244
+ /**
245
+ * Request headers are too large for the server to process.
246
+ */
247
+ HttpStatusCodes[HttpStatusCodes["REQUEST_HEADER_FIELDS_TOO_LARGE"] = 431] = "REQUEST_HEADER_FIELDS_TOO_LARGE";
248
+ /**
249
+ * Resource cannot be legally provided (e.g., censored by government).
250
+ */
251
+ HttpStatusCodes[HttpStatusCodes["UNAVAILABLE_FOR_LEGAL_REASONS"] = 451] = "UNAVAILABLE_FOR_LEGAL_REASONS";
252
+ // 5xx Server Error
253
+ /**
254
+ * The server encountered an unexpected error preventing it from fulfilling the request.
255
+ */
256
+ HttpStatusCodes[HttpStatusCodes["INTERNAL_SERVER_ERROR"] = 500] = "INTERNAL_SERVER_ERROR";
257
+ /**
258
+ * The server does not support the functionality required to fulfill the request.
259
+ */
260
+ HttpStatusCodes[HttpStatusCodes["NOT_IMPLEMENTED"] = 501] = "NOT_IMPLEMENTED";
261
+ /**
262
+ * The server, acting as a gateway, received an invalid response from an upstream server.
263
+ */
264
+ HttpStatusCodes[HttpStatusCodes["BAD_GATEWAY"] = 502] = "BAD_GATEWAY";
265
+ /**
266
+ * The server is currently unable to handle the request due to temporary overload or maintenance.
267
+ */
268
+ HttpStatusCodes[HttpStatusCodes["SERVICE_UNAVAILABLE"] = 503] = "SERVICE_UNAVAILABLE";
269
+ /**
270
+ * The server, acting as a gateway, did not receive a timely response from an upstream server.
271
+ */
272
+ HttpStatusCodes[HttpStatusCodes["GATEWAY_TIMEOUT"] = 504] = "GATEWAY_TIMEOUT";
273
+ /**
274
+ * The server does not support the HTTP protocol version used in the request.
275
+ */
276
+ HttpStatusCodes[HttpStatusCodes["HTTP_VERSION_NOT_SUPPORTED"] = 505] = "HTTP_VERSION_NOT_SUPPORTED";
277
+ /**
278
+ * Transparent content negotiation for the request resulted in circular reference.
279
+ */
280
+ HttpStatusCodes[HttpStatusCodes["VARIANT_ALSO_NEGOTIATES"] = 506] = "VARIANT_ALSO_NEGOTIATES";
281
+ /**
282
+ * The server cannot store the representation needed to complete the request.
283
+ */
284
+ HttpStatusCodes[HttpStatusCodes["INSUFFICIENT_STORAGE"] = 507] = "INSUFFICIENT_STORAGE";
285
+ /**
286
+ * The server detected an infinite loop while processing the request.
287
+ */
288
+ HttpStatusCodes[HttpStatusCodes["LOOP_DETECTED"] = 508] = "LOOP_DETECTED";
289
+ /**
290
+ * Further extensions to the request are required for the server to fulfill it.
291
+ */
292
+ HttpStatusCodes[HttpStatusCodes["NOT_EXTENDED"] = 510] = "NOT_EXTENDED";
293
+ /**
294
+ * The client needs to authenticate to gain network access.
295
+ */
296
+ HttpStatusCodes[HttpStatusCodes["NETWORK_AUTHENTICATION_REQUIRED"] = 511] = "NETWORK_AUTHENTICATION_REQUIRED";
297
+ })(HttpStatusCodes || (exports.HttpStatusCodes = HttpStatusCodes = {}));
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Generates a UUID v4 string (RFC 4122).
3
+ *
4
+ * @returns {string} UUID v4 (e.g., 'c0de1234-5678-9abc-def0-123456789abc')
5
+ */
6
+ export declare function uuid(): string;
7
+ /**
8
+ * Generates a nanoid-style random ID (URL-safe, customizable length).
9
+ *
10
+ * @param {number} length - Length of the ID (default: 21).
11
+ * @returns {string} Nanoid-style random string.
12
+ */
13
+ export declare function nanoId(length?: number): string;
14
+ /**
15
+ * Generates a cryptographically strong random hex string.
16
+ *
17
+ * @param {number} byteLength - Number of random bytes (default: 16 → 32 hex chars).
18
+ * @returns {string} Random hex string.
19
+ */
20
+ export declare function randomHex(byteLength?: number): string;
21
+ /**
22
+ * Generates a random integer between min (inclusive) and max (inclusive).
23
+ *
24
+ * @param {number} min - Minimum value.
25
+ * @param {number} max - Maximum value.
26
+ * @returns {number} Random integer in range.
27
+ */
28
+ export declare function randomInt(min: number, max: number): number;
29
+ /**
30
+ * Generates a cryptographically strong random base64 string.
31
+ *
32
+ * @param {number} byteLength - Number of random bytes (default: 16).
33
+ * @returns {string} Random base64 string (URL-safe, no padding).
34
+ */
35
+ export declare function randomBase64(byteLength?: number): string;
@@ -0,0 +1,90 @@
1
+ "use strict";
2
+ /*
3
+ * The MIT License
4
+ *
5
+ * Copyright (c) 2025 Catbee Technologies. https://catbee-utils.npm.hprasath.com/license
6
+ *
7
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ * of this software and associated documentation files (the "Software"), to deal
9
+ * in the Software without restriction, including without limitation the rights
10
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ * copies of the Software, and to permit persons to whom the Software is
12
+ * furnished to do so, subject to the following conditions:
13
+ *
14
+ * The above copyright notice and this permission notice shall be included in all
15
+ * copies or substantial portions of the Software.
16
+ *
17
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
+ * SOFTWARE.
24
+ */
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.uuid = uuid;
27
+ exports.nanoId = nanoId;
28
+ exports.randomHex = randomHex;
29
+ exports.randomInt = randomInt;
30
+ exports.randomBase64 = randomBase64;
31
+ const crypto_1 = require("crypto");
32
+ /**
33
+ * Generates a UUID v4 string (RFC 4122).
34
+ *
35
+ * @returns {string} UUID v4 (e.g., 'c0de1234-5678-9abc-def0-123456789abc')
36
+ */
37
+ function uuid() {
38
+ return (0, crypto_1.randomUUID)();
39
+ }
40
+ /**
41
+ * Generates a nanoid-style random ID (URL-safe, customizable length).
42
+ *
43
+ * @param {number} length - Length of the ID (default: 21).
44
+ * @returns {string} Nanoid-style random string.
45
+ */
46
+ function nanoId(length = 21) {
47
+ if (length <= 0)
48
+ return '';
49
+ let id = '';
50
+ while (id.length < length) {
51
+ id += (0, crypto_1.randomBytes)(Math.ceil((length * 3) / 4))
52
+ .toString('base64url')
53
+ .replace(/[+/=]/g, '');
54
+ }
55
+ return id.slice(0, length);
56
+ }
57
+ /**
58
+ * Generates a cryptographically strong random hex string.
59
+ *
60
+ * @param {number} byteLength - Number of random bytes (default: 16 → 32 hex chars).
61
+ * @returns {string} Random hex string.
62
+ */
63
+ function randomHex(byteLength = 16) {
64
+ // Use Node.js crypto for both Node and browser compatibility
65
+ // Prefer randomBytes if available (Node), fallback to getRandomValues for browser (not used here)
66
+ return (0, crypto_1.randomBytes)(byteLength)
67
+ .toString('hex')
68
+ .padStart(byteLength * 2, '0')
69
+ .slice(0, byteLength * 2);
70
+ }
71
+ /**
72
+ * Generates a random integer between min (inclusive) and max (inclusive).
73
+ *
74
+ * @param {number} min - Minimum value.
75
+ * @param {number} max - Maximum value.
76
+ * @returns {number} Random integer in range.
77
+ */
78
+ function randomInt(min, max) {
79
+ const range = max - min + 1;
80
+ return Math.floor(Math.random() * range) + min;
81
+ }
82
+ /**
83
+ * Generates a cryptographically strong random base64 string.
84
+ *
85
+ * @param {number} byteLength - Number of random bytes (default: 16).
86
+ * @returns {string} Random base64 string (URL-safe, no padding).
87
+ */
88
+ function randomBase64(byteLength = 16) {
89
+ return (0, crypto_1.randomBytes)(byteLength).toString('base64url');
90
+ }