@ooneex/http-status 0.0.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Ooneex
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,512 @@
1
+ # @ooneex/http-status
2
+
3
+ A comprehensive TypeScript/JavaScript library for working with HTTP status codes. This package provides all standard HTTP status codes with their corresponding text messages and utility methods to categorize and work with different status code types.
4
+
5
+ ![Browser](https://img.shields.io/badge/Browser-Compatible-green?style=flat-square&logo=googlechrome)
6
+ ![Bun](https://img.shields.io/badge/Bun-Compatible-orange?style=flat-square&logo=bun)
7
+ ![Deno](https://img.shields.io/badge/Deno-Compatible-blue?style=flat-square&logo=deno)
8
+ ![Node.js](https://img.shields.io/badge/Node.js-Compatible-green?style=flat-square&logo=node.js)
9
+ ![TypeScript](https://img.shields.io/badge/TypeScript-Ready-blue?style=flat-square&logo=typescript)
10
+ ![MIT License](https://img.shields.io/badge/License-MIT-yellow?style=flat-square)
11
+
12
+ ## Features
13
+
14
+ ✅ **Complete Status Code Collection** - All standard HTTP status codes from 1xx to 5xx
15
+
16
+ ✅ **Status Text Mapping** - Corresponding text messages for all status codes
17
+
18
+ ✅ **Type-Safe** - Full TypeScript support with proper type definitions
19
+
20
+ ✅ **Category Detection** - Methods to identify status code categories (informational, success, redirect, error)
21
+
22
+ ✅ **Lightweight** - No external dependencies required
23
+
24
+ ✅ **Cross-Platform** - Works in Browser, Node.js, Bun, and Deno
25
+
26
+ ✅ **Standards Compliant** - Based on official HTTP status code specifications
27
+
28
+ ✅ **Easy Integration** - Simple API for common HTTP status operations
29
+
30
+ ## Installation
31
+
32
+ ### Bun
33
+ ```bash
34
+ bun add @ooneex/http-status
35
+ ```
36
+
37
+ ### pnpm
38
+ ```bash
39
+ pnpm add @ooneex/http-status
40
+ ```
41
+
42
+ ### Yarn
43
+ ```bash
44
+ yarn add @ooneex/http-status
45
+ ```
46
+
47
+ ### npm
48
+ ```bash
49
+ npm install @ooneex/http-status
50
+ ```
51
+
52
+ ## Usage
53
+
54
+ ### Basic Usage
55
+
56
+ ```typescript
57
+ import { Status } from '@ooneex/http-status';
58
+
59
+ const status = new Status();
60
+
61
+ // Access status codes
62
+ console.log(Status.Code.OK); // 200
63
+ console.log(Status.Code.NotFound); // 404
64
+ console.log(Status.Code.InternalServerError); // 500
65
+
66
+ // Access status text
67
+ console.log(Status.Text[200]); // "OK"
68
+ console.log(Status.Text[404]); // "Not Found"
69
+ console.log(Status.Text[500]); // "Internal Server Error"
70
+
71
+ // Or use the exported constants directly
72
+ console.log(Status.Code.OK); // 200
73
+ console.log(Status.Text[Status.Code.NotFound]); // "Not Found"
74
+ ```
75
+
76
+ ### Status Code Category Detection
77
+
78
+ ```typescript
79
+ import { Status } from '@ooneex/http-status';
80
+
81
+ const status = new Status();
82
+
83
+ // Check if status code is successful (2xx)
84
+ console.log(status.isSuccessful(Status.Code.OK)); // true
85
+ console.log(status.isSuccessful(Status.Code.Created)); // true
86
+ console.log(status.isSuccessful(Status.Code.NotFound)); // false
87
+
88
+ // Check if status code is an error (4xx or 5xx)
89
+ console.log(status.isError(Status.Code.BadRequest)); // true
90
+ console.log(status.isError(Status.Code.InternalServerError)); // true
91
+ console.log(status.isError(Status.Code.OK)); // false
92
+
93
+ // Check specific error types
94
+ console.log(status.isClientError(Status.Code.BadRequest)); // true
95
+ console.log(status.isClientError(Status.Code.NotFound)); // true
96
+ console.log(status.isServerError(Status.Code.InternalServerError)); // true
97
+ console.log(status.isServerError(Status.Code.BadGateway)); // true
98
+
99
+ // Check for redirects (3xx)
100
+ console.log(status.isRedirect(Status.Code.MovedPermanently)); // true
101
+ console.log(status.isRedirect(Status.Code.Found)); // true
102
+
103
+ // Check for informational responses (1xx)
104
+ console.log(status.isInformational(Status.Code.Continue)); // true
105
+ console.log(status.isInformational(Status.Code.SwitchingProtocols)); // true
106
+ ```
107
+
108
+ ### Express.js Integration Example
109
+
110
+ ```typescript
111
+ import express from 'express';
112
+ import { Status } from '@ooneex/http-status';
113
+
114
+ const app = express();
115
+ const status = new Status();
116
+
117
+ app.get('/api/users/:id', (req, res) => {
118
+ const user = getUserById(req.params.id);
119
+
120
+ if (!user) {
121
+ return res.status(Status.Code.NotFound).json({
122
+ error: Status.Text[Status.Code.NotFound],
123
+ message: 'User not found'
124
+ });
125
+ }
126
+
127
+ res.status(Status.Code.OK).json(user);
128
+ });
129
+
130
+ app.use((error, req, res, next) => {
131
+ const statusCode = Status.Code.InternalServerError;
132
+
133
+ console.log(`Error ${statusCode}: ${Status.Text[statusCode]}`);
134
+ console.log(`Is Server Error: ${status.isServerError(statusCode)}`);
135
+
136
+ res.status(statusCode).json({
137
+ error: Status.Text[statusCode]
138
+ });
139
+ });
140
+ ```
141
+
142
+ ### Fetch API Integration Example
143
+
144
+ ```typescript
145
+ import { Status } from '@ooneex/http-status';
146
+
147
+ const status = new Status();
148
+
149
+ async function apiCall(url: string) {
150
+ try {
151
+ const response = await fetch(url);
152
+
153
+ console.log(`Response status: ${response.status} - ${Status.Text[response.status]}`);
154
+
155
+ if (status.isSuccessful(response.status)) {
156
+ return await response.json();
157
+ }
158
+
159
+ if (status.isClientError(response.status)) {
160
+ throw new Error(`Client error: ${Status.Text[response.status]}`);
161
+ }
162
+
163
+ if (status.isServerError(response.status)) {
164
+ throw new Error(`Server error: ${Status.Text[response.status]}`);
165
+ }
166
+
167
+ if (status.isRedirect(response.status)) {
168
+ console.log('Redirect response received');
169
+ // Handle redirect logic
170
+ }
171
+
172
+ } catch (error) {
173
+ console.error('API call failed:', error);
174
+ }
175
+ }
176
+ ```
177
+
178
+ ## API Reference
179
+
180
+ ### `Status` Class
181
+
182
+ The main class providing HTTP status code utility methods.
183
+
184
+ #### Static Properties
185
+
186
+ ##### `Status.Code`
187
+ Object containing all HTTP status codes as constants.
188
+
189
+ **Example:**
190
+ ```typescript
191
+ Status.Code.OK; // 200
192
+ Status.Code.NotFound; // 404
193
+ Status.Code.InternalServerError; // 500
194
+ ```
195
+
196
+ ##### `Status.Text`
197
+ Object mapping status codes to their text descriptions.
198
+
199
+ **Example:**
200
+ ```typescript
201
+ Status.Text[200]; // "OK"
202
+ Status.Text[404]; // "Not Found"
203
+ Status.Text[500]; // "Internal Server Error"
204
+ ```
205
+
206
+ #### Methods
207
+
208
+ ##### `isInformational(code: StatusCodeType): boolean`
209
+ Checks if a status code is informational (1xx).
210
+
211
+ **Parameters:**
212
+ - `code` - The HTTP status code to check
213
+
214
+ **Returns:** `true` if the status code is in the 1xx range
215
+
216
+ **Example:**
217
+ ```typescript
218
+ status.isInformational(100); // true (Continue)
219
+ status.isInformational(101); // true (Switching Protocols)
220
+ status.isInformational(200); // false (OK)
221
+ ```
222
+
223
+ ##### `isSuccessful(code: StatusCodeType): boolean`
224
+ Checks if a status code indicates success (2xx).
225
+
226
+ **Example:**
227
+ ```typescript
228
+ status.isSuccessful(200); // true (OK)
229
+ status.isSuccessful(201); // true (Created)
230
+ status.isSuccessful(204); // true (No Content)
231
+ status.isSuccessful(404); // false (Not Found)
232
+ ```
233
+
234
+ ##### `isRedirect(code: StatusCodeType): boolean`
235
+ Checks if a status code indicates a redirect (3xx).
236
+
237
+ **Example:**
238
+ ```typescript
239
+ status.isRedirect(301); // true (Moved Permanently)
240
+ status.isRedirect(302); // true (Found)
241
+ status.isRedirect(304); // true (Not Modified)
242
+ status.isRedirect(200); // false (OK)
243
+ ```
244
+
245
+ ##### `isClientError(code: StatusCodeType): boolean`
246
+ Checks if a status code indicates a client error (4xx).
247
+
248
+ **Example:**
249
+ ```typescript
250
+ status.isClientError(400); // true (Bad Request)
251
+ status.isClientError(404); // true (Not Found)
252
+ status.isClientError(403); // true (Forbidden)
253
+ status.isClientError(500); // false (Internal Server Error)
254
+ ```
255
+
256
+ ##### `isServerError(code: StatusCodeType): boolean`
257
+ Checks if a status code indicates a server error (5xx).
258
+
259
+ **Example:**
260
+ ```typescript
261
+ status.isServerError(500); // true (Internal Server Error)
262
+ status.isServerError(502); // true (Bad Gateway)
263
+ status.isServerError(503); // true (Service Unavailable)
264
+ status.isServerError(404); // false (Not Found)
265
+ ```
266
+
267
+ ##### `isError(code: StatusCodeType): boolean`
268
+ Checks if a status code indicates any error (4xx or 5xx).
269
+
270
+ **Example:**
271
+ ```typescript
272
+ status.isError(400); // true (Bad Request - client error)
273
+ status.isError(500); // true (Internal Server Error - server error)
274
+ status.isError(200); // false (OK - success)
275
+ status.isError(301); // false (Moved Permanently - redirect)
276
+ ```
277
+
278
+ ### Constants
279
+
280
+ #### `Status.Code`
281
+ Object containing all HTTP status codes as named constants.
282
+
283
+ **Available Status Codes:**
284
+
285
+ **1xx Informational:**
286
+ - `Continue` (100)
287
+ - `SwitchingProtocols` (101)
288
+ - `Processing` (102)
289
+ - `EarlyHints` (103)
290
+
291
+ **2xx Success:**
292
+ - `OK` (200)
293
+ - `Created` (201)
294
+ - `Accepted` (202)
295
+ - `NonAuthoritativeInfo` (203)
296
+ - `NoContent` (204)
297
+ - `ResetContent` (205)
298
+ - `PartialContent` (206)
299
+ - `MultiStatus` (207)
300
+ - `AlreadyReported` (208)
301
+ - `IMUsed` (226)
302
+
303
+ **3xx Redirection:**
304
+ - `MultipleChoices` (300)
305
+ - `MovedPermanently` (301)
306
+ - `Found` (302)
307
+ - `SeeOther` (303)
308
+ - `NotModified` (304)
309
+ - `UseProxy` (305)
310
+ - `TemporaryRedirect` (307)
311
+ - `PermanentRedirect` (308)
312
+
313
+ **4xx Client Error:**
314
+ - `BadRequest` (400)
315
+ - `Unauthorized` (401)
316
+ - `PaymentRequired` (402)
317
+ - `Forbidden` (403)
318
+ - `NotFound` (404)
319
+ - `MethodNotAllowed` (405)
320
+ - `NotAcceptable` (406)
321
+ - `ProxyAuthRequired` (407)
322
+ - `RequestTimeout` (408)
323
+ - `Conflict` (409)
324
+ - `Gone` (410)
325
+ - `LengthRequired` (411)
326
+ - `PreconditionFailed` (412)
327
+ - `ContentTooLarge` (413)
328
+ - `URITooLong` (414)
329
+ - `UnsupportedMediaType` (415)
330
+ - `RangeNotSatisfiable` (416)
331
+ - `ExpectationFailed` (417)
332
+ - `Teapot` (418)
333
+ - `MisdirectedRequest` (421)
334
+ - `UnprocessableEntity` (422)
335
+ - `Locked` (423)
336
+ - `FailedDependency` (424)
337
+ - `TooEarly` (425)
338
+ - `UpgradeRequired` (426)
339
+ - `PreconditionRequired` (428)
340
+ - `TooManyRequests` (429)
341
+ - `RequestHeaderFieldsTooLarge` (431)
342
+ - `UnavailableForLegalReasons` (451)
343
+
344
+ **5xx Server Error:**
345
+ - `InternalServerError` (500)
346
+ - `NotImplemented` (501)
347
+ - `BadGateway` (502)
348
+ - `ServiceUnavailable` (503)
349
+ - `GatewayTimeout` (504)
350
+ - `HTTPVersionNotSupported` (505)
351
+ - `VariantAlsoNegotiates` (506)
352
+ - `InsufficientStorage` (507)
353
+ - `LoopDetected` (508)
354
+ - `NotExtended` (510)
355
+ - `NetworkAuthenticationRequired` (511)
356
+
357
+ #### `Status.Text`
358
+ Object mapping status codes to their corresponding text descriptions.
359
+
360
+ **Example:**
361
+ ```typescript
362
+ import { Status } from '@ooneex/http-status';
363
+
364
+ Status.Text[Status.Code.OK]; // "OK"
365
+ Status.Text[Status.Code.NotFound]; // "Not Found"
366
+ Status.Text[Status.Code.InternalServerError]; // "Internal Server Error"
367
+ Status.Text[Status.Code.Teapot]; // "I'm a teapot"
368
+ ```
369
+
370
+ ### Types
371
+
372
+ #### `StatusCodeType`
373
+ TypeScript type representing all valid HTTP status codes.
374
+
375
+ **Example:**
376
+ ```typescript
377
+ import { StatusCodeType } from '@ooneex/http-status';
378
+
379
+ const code: StatusCodeType = 200; // Type-safe
380
+ const handler = (statusCode: StatusCodeType) => {
381
+ // Handle status code
382
+ };
383
+ ```
384
+
385
+ #### `StatusTextType`
386
+ TypeScript type representing all valid HTTP status text messages.
387
+
388
+ **Example:**
389
+ ```typescript
390
+ import { StatusTextType } from '@ooneex/http-status';
391
+
392
+ const message: StatusTextType = "OK"; // Type-safe
393
+ ```
394
+
395
+ ### Interface
396
+
397
+ #### `IStatus`
398
+ Interface defining all available status code detection methods.
399
+
400
+ **Example:**
401
+ ```typescript
402
+ import { IStatus } from '@ooneex/http-status';
403
+
404
+ class CustomStatusHandler implements IStatus {
405
+ isInformational(code: StatusCodeType): boolean {
406
+ // Custom implementation
407
+ return code >= 100 && code < 200;
408
+ }
409
+
410
+ isSuccessful(code: StatusCodeType): boolean {
411
+ // Custom implementation
412
+ return code >= 200 && code < 300;
413
+ }
414
+
415
+ // ... implement other required methods
416
+ }
417
+ ```
418
+
419
+ ## Common Use Cases
420
+
421
+ ### API Response Handling
422
+
423
+ ```typescript
424
+ import { Status } from '@ooneex/http-status';
425
+
426
+ const status = new Status();
427
+
428
+ function handleApiResponse(statusCode: number, data: any) {
429
+ if (status.isSuccessful(statusCode)) {
430
+ console.log('Success:', data);
431
+ return { success: true, data };
432
+ }
433
+
434
+ if (status.isClientError(statusCode)) {
435
+ console.error('Client Error:', Status.Text[statusCode]);
436
+ return { success: false, error: 'Client error occurred' };
437
+ }
438
+
439
+ if (status.isServerError(statusCode)) {
440
+ console.error('Server Error:', Status.Text[statusCode]);
441
+ return { success: false, error: 'Server error occurred' };
442
+ }
443
+
444
+ if (status.isRedirect(statusCode)) {
445
+ console.log('Redirect:', Status.Text[statusCode]);
446
+ return { success: true, redirect: true };
447
+ }
448
+ }
449
+ ```
450
+
451
+ ### HTTP Client Wrapper
452
+
453
+ ```typescript
454
+ import { Status } from '@ooneex/http-status';
455
+
456
+ class HttpClient {
457
+ private status = new Status();
458
+
459
+ async request(url: string, options?: RequestInit) {
460
+ try {
461
+ const response = await fetch(url, options);
462
+
463
+ return {
464
+ status: response.status,
465
+ statusText: Status.Text[response.status],
466
+ isSuccess: this.status.isSuccessful(response.status),
467
+ isError: this.status.isError(response.status),
468
+ isClientError: this.status.isClientError(response.status),
469
+ isServerError: this.status.isServerError(response.status),
470
+ data: response.ok ? await response.json() : null
471
+ };
472
+ } catch (error) {
473
+ return {
474
+ status: Status.Code.InternalServerError,
475
+ statusText: Status.Text[Status.Code.InternalServerError],
476
+ isSuccess: false,
477
+ isError: true,
478
+ isClientError: false,
479
+ isServerError: true,
480
+ data: null,
481
+ error
482
+ };
483
+ }
484
+ }
485
+ }
486
+ ```
487
+
488
+ ## License
489
+
490
+ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
491
+
492
+ ## Contributing
493
+
494
+ Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
495
+
496
+ ### Development Setup
497
+
498
+ 1. Clone the repository
499
+ 2. Install dependencies: `bun install`
500
+ 3. Run tests: `bun test`
501
+ 4. Build the project: `bun run build`
502
+
503
+ ### Guidelines
504
+
505
+ - Write tests for new features
506
+ - Follow the existing code style
507
+ - Update documentation for API changes
508
+ - Ensure all tests pass before submitting PR
509
+
510
+ ---
511
+
512
+ Made with ❤️ by the Ooneex team
@@ -0,0 +1,149 @@
1
+ declare const STATUS_CODE: {
2
+ readonly Continue: 100;
3
+ readonly SwitchingProtocols: 101;
4
+ readonly Processing: 102;
5
+ readonly EarlyHints: 103;
6
+ readonly OK: 200;
7
+ readonly Created: 201;
8
+ readonly Accepted: 202;
9
+ readonly NonAuthoritativeInfo: 203;
10
+ readonly NoContent: 204;
11
+ readonly ResetContent: 205;
12
+ readonly PartialContent: 206;
13
+ readonly MultiStatus: 207;
14
+ readonly AlreadyReported: 208;
15
+ readonly IMUsed: 226;
16
+ readonly MultipleChoices: 300;
17
+ readonly MovedPermanently: 301;
18
+ readonly Found: 302;
19
+ readonly SeeOther: 303;
20
+ readonly NotModified: 304;
21
+ readonly UseProxy: 305;
22
+ readonly TemporaryRedirect: 307;
23
+ readonly PermanentRedirect: 308;
24
+ readonly BadRequest: 400;
25
+ readonly Unauthorized: 401;
26
+ readonly PaymentRequired: 402;
27
+ readonly Forbidden: 403;
28
+ readonly NotFound: 404;
29
+ readonly MethodNotAllowed: 405;
30
+ readonly NotAcceptable: 406;
31
+ readonly ProxyAuthRequired: 407;
32
+ readonly RequestTimeout: 408;
33
+ readonly Conflict: 409;
34
+ readonly Gone: 410;
35
+ readonly LengthRequired: 411;
36
+ readonly PreconditionFailed: 412;
37
+ readonly ContentTooLarge: 413;
38
+ readonly URITooLong: 414;
39
+ readonly UnsupportedMediaType: 415;
40
+ readonly RangeNotSatisfiable: 416;
41
+ readonly ExpectationFailed: 417;
42
+ readonly Teapot: 418;
43
+ readonly MisdirectedRequest: 421;
44
+ readonly UnprocessableEntity: 422;
45
+ readonly Locked: 423;
46
+ readonly FailedDependency: 424;
47
+ readonly TooEarly: 425;
48
+ readonly UpgradeRequired: 426;
49
+ readonly PreconditionRequired: 428;
50
+ readonly TooManyRequests: 429;
51
+ readonly RequestHeaderFieldsTooLarge: 431;
52
+ readonly UnavailableForLegalReasons: 451;
53
+ readonly InternalServerError: 500;
54
+ readonly NotImplemented: 501;
55
+ readonly BadGateway: 502;
56
+ readonly ServiceUnavailable: 503;
57
+ readonly GatewayTimeout: 504;
58
+ readonly HTTPVersionNotSupported: 505;
59
+ readonly VariantAlsoNegotiates: 506;
60
+ readonly InsufficientStorage: 507;
61
+ readonly LoopDetected: 508;
62
+ readonly NotExtended: 510;
63
+ readonly NetworkAuthenticationRequired: 511;
64
+ };
65
+ declare const STATUS_TEXT: {
66
+ readonly 202: "Accepted";
67
+ readonly 208: "Already Reported";
68
+ readonly 502: "Bad Gateway";
69
+ readonly 400: "Bad Request";
70
+ readonly 409: "Conflict";
71
+ readonly 100: "Continue";
72
+ readonly 201: "Created";
73
+ readonly 103: "Early Hints";
74
+ readonly 417: "Expectation Failed";
75
+ readonly 424: "Failed Dependency";
76
+ readonly 403: "Forbidden";
77
+ readonly 302: "Found";
78
+ readonly 504: "Gateway Timeout";
79
+ readonly 410: "Gone";
80
+ readonly 505: "HTTP Version Not Supported";
81
+ readonly 226: "IM Used";
82
+ readonly 507: "Insufficient Storage";
83
+ readonly 500: "Internal Server Error";
84
+ readonly 411: "Length Required";
85
+ readonly 423: "Locked";
86
+ readonly 508: "Loop Detected";
87
+ readonly 405: "Method Not Allowed";
88
+ readonly 421: "Misdirected Request";
89
+ readonly 301: "Moved Permanently";
90
+ readonly 207: "Multi Status";
91
+ readonly 300: "Multiple Choices";
92
+ readonly 511: "Network Authentication Required";
93
+ readonly 204: "No Content";
94
+ readonly 203: "Non Authoritative Info";
95
+ readonly 406: "Not Acceptable";
96
+ readonly 510: "Not Extended";
97
+ readonly 404: "Not Found";
98
+ readonly 501: "Not Implemented";
99
+ readonly 304: "Not Modified";
100
+ readonly 200: "OK";
101
+ readonly 206: "Partial Content";
102
+ readonly 402: "Payment Required";
103
+ readonly 308: "Permanent Redirect";
104
+ readonly 412: "Precondition Failed";
105
+ readonly 428: "Precondition Required";
106
+ readonly 102: "Processing";
107
+ readonly 407: "Proxy Auth Required";
108
+ readonly 413: "Content Too Large";
109
+ readonly 431: "Request Header Fields Too Large";
110
+ readonly 408: "Request Timeout";
111
+ readonly 414: "URI Too Long";
112
+ readonly 416: "Range Not Satisfiable";
113
+ readonly 205: "Reset Content";
114
+ readonly 303: "See Other";
115
+ readonly 503: "Service Unavailable";
116
+ readonly 101: "Switching Protocols";
117
+ readonly 418: "I'm a teapot";
118
+ readonly 307: "Temporary Redirect";
119
+ readonly 425: "Too Early";
120
+ readonly 429: "Too Many Requests";
121
+ readonly 401: "Unauthorized";
122
+ readonly 451: "Unavailable For Legal Reasons";
123
+ readonly 422: "Unprocessable Entity";
124
+ readonly 415: "Unsupported Media Type";
125
+ readonly 426: "Upgrade Required";
126
+ readonly 305: "Use Proxy";
127
+ readonly 506: "Variant Also Negotiates";
128
+ };
129
+ type StatusCodeType = (typeof STATUS_CODE)[keyof typeof STATUS_CODE];
130
+ type StatusTextType = (typeof STATUS_TEXT)[keyof typeof STATUS_TEXT];
131
+ interface IHttpStatus {
132
+ isInformational: (code: StatusCodeType) => boolean;
133
+ isSuccessful: (code: StatusCodeType) => boolean;
134
+ isRedirect: (code: StatusCodeType) => boolean;
135
+ isClientError: (code: StatusCodeType) => boolean;
136
+ isServerError: (code: StatusCodeType) => boolean;
137
+ isError: (code: StatusCodeType) => boolean;
138
+ }
139
+ declare class HttpStatus implements IHttpStatus {
140
+ static Code: typeof STATUS_CODE;
141
+ static Text: typeof STATUS_TEXT;
142
+ isInformational: (code: StatusCodeType) => boolean;
143
+ isSuccessful: (code: StatusCodeType) => boolean;
144
+ isRedirect: (code: StatusCodeType) => boolean;
145
+ isClientError: (code: StatusCodeType) => boolean;
146
+ isServerError: (code: StatusCodeType) => boolean;
147
+ isError: (code: StatusCodeType) => boolean;
148
+ }
149
+ export { StatusTextType, StatusCodeType, IHttpStatus, HttpStatus };
package/dist/index.js ADDED
@@ -0,0 +1,3 @@
1
+ var t={Continue:100,SwitchingProtocols:101,Processing:102,EarlyHints:103,OK:200,Created:201,Accepted:202,NonAuthoritativeInfo:203,NoContent:204,ResetContent:205,PartialContent:206,MultiStatus:207,AlreadyReported:208,IMUsed:226,MultipleChoices:300,MovedPermanently:301,Found:302,SeeOther:303,NotModified:304,UseProxy:305,TemporaryRedirect:307,PermanentRedirect:308,BadRequest:400,Unauthorized:401,PaymentRequired:402,Forbidden:403,NotFound:404,MethodNotAllowed:405,NotAcceptable:406,ProxyAuthRequired:407,RequestTimeout:408,Conflict:409,Gone:410,LengthRequired:411,PreconditionFailed:412,ContentTooLarge:413,URITooLong:414,UnsupportedMediaType:415,RangeNotSatisfiable:416,ExpectationFailed:417,Teapot:418,MisdirectedRequest:421,UnprocessableEntity:422,Locked:423,FailedDependency:424,TooEarly:425,UpgradeRequired:426,PreconditionRequired:428,TooManyRequests:429,RequestHeaderFieldsTooLarge:431,UnavailableForLegalReasons:451,InternalServerError:500,NotImplemented:501,BadGateway:502,ServiceUnavailable:503,GatewayTimeout:504,HTTPVersionNotSupported:505,VariantAlsoNegotiates:506,InsufficientStorage:507,LoopDetected:508,NotExtended:510,NetworkAuthenticationRequired:511},o={202:"Accepted",208:"Already Reported",502:"Bad Gateway",400:"Bad Request",409:"Conflict",100:"Continue",201:"Created",103:"Early Hints",417:"Expectation Failed",424:"Failed Dependency",403:"Forbidden",302:"Found",504:"Gateway Timeout",410:"Gone",505:"HTTP Version Not Supported",226:"IM Used",507:"Insufficient Storage",500:"Internal Server Error",411:"Length Required",423:"Locked",508:"Loop Detected",405:"Method Not Allowed",421:"Misdirected Request",301:"Moved Permanently",207:"Multi Status",300:"Multiple Choices",511:"Network Authentication Required",204:"No Content",203:"Non Authoritative Info",406:"Not Acceptable",510:"Not Extended",404:"Not Found",501:"Not Implemented",304:"Not Modified",200:"OK",206:"Partial Content",402:"Payment Required",308:"Permanent Redirect",412:"Precondition Failed",428:"Precondition Required",102:"Processing",407:"Proxy Auth Required",413:"Content Too Large",431:"Request Header Fields Too Large",408:"Request Timeout",414:"URI Too Long",416:"Range Not Satisfiable",205:"Reset Content",303:"See Other",503:"Service Unavailable",101:"Switching Protocols",418:"I'm a teapot",307:"Temporary Redirect",425:"Too Early",429:"Too Many Requests",401:"Unauthorized",451:"Unavailable For Legal Reasons",422:"Unprocessable Entity",415:"Unsupported Media Type",426:"Upgrade Required",305:"Use Proxy",506:"Variant Also Negotiates"};class a{static Code=t;static Text=o;isInformational=(e)=>e>=t.Continue&&e<t.OK;isSuccessful=(e)=>e>=t.OK&&e<t.MultipleChoices;isRedirect=(e)=>e>=t.MultipleChoices&&e<t.BadRequest;isClientError=(e)=>e>=t.BadRequest&&e<t.InternalServerError;isServerError=(e)=>e>=t.InternalServerError&&e<600;isError=(e)=>this.isClientError(e)||this.isServerError(e)}export{a as HttpStatus};
2
+
3
+ //# debugId=140D9A65A1CC1E2164756E2164756E21
@@ -0,0 +1,10 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["src/index.ts"],
4
+ "sourcesContent": [
5
+ "const STATUS_CODE = {\n Continue: 100,\n SwitchingProtocols: 101,\n Processing: 102,\n EarlyHints: 103,\n\n OK: 200,\n Created: 201,\n Accepted: 202,\n NonAuthoritativeInfo: 203,\n NoContent: 204,\n ResetContent: 205,\n PartialContent: 206,\n MultiStatus: 207,\n AlreadyReported: 208,\n IMUsed: 226,\n\n MultipleChoices: 300,\n MovedPermanently: 301,\n Found: 302,\n SeeOther: 303,\n NotModified: 304,\n UseProxy: 305,\n TemporaryRedirect: 307,\n PermanentRedirect: 308,\n\n BadRequest: 400,\n Unauthorized: 401,\n PaymentRequired: 402,\n Forbidden: 403,\n NotFound: 404,\n MethodNotAllowed: 405,\n NotAcceptable: 406,\n ProxyAuthRequired: 407,\n RequestTimeout: 408,\n Conflict: 409,\n Gone: 410,\n LengthRequired: 411,\n PreconditionFailed: 412,\n ContentTooLarge: 413,\n URITooLong: 414,\n UnsupportedMediaType: 415,\n RangeNotSatisfiable: 416,\n ExpectationFailed: 417,\n Teapot: 418,\n MisdirectedRequest: 421,\n UnprocessableEntity: 422,\n Locked: 423,\n FailedDependency: 424,\n TooEarly: 425,\n UpgradeRequired: 426,\n PreconditionRequired: 428,\n TooManyRequests: 429,\n RequestHeaderFieldsTooLarge: 431,\n UnavailableForLegalReasons: 451,\n\n InternalServerError: 500,\n NotImplemented: 501,\n BadGateway: 502,\n ServiceUnavailable: 503,\n GatewayTimeout: 504,\n HTTPVersionNotSupported: 505,\n VariantAlsoNegotiates: 506,\n InsufficientStorage: 507,\n LoopDetected: 508,\n NotExtended: 510,\n NetworkAuthenticationRequired: 511,\n} as const;\n\nconst STATUS_TEXT = {\n 202: \"Accepted\",\n 208: \"Already Reported\",\n 502: \"Bad Gateway\",\n 400: \"Bad Request\",\n 409: \"Conflict\",\n 100: \"Continue\",\n 201: \"Created\",\n 103: \"Early Hints\",\n 417: \"Expectation Failed\",\n 424: \"Failed Dependency\",\n 403: \"Forbidden\",\n 302: \"Found\",\n 504: \"Gateway Timeout\",\n 410: \"Gone\",\n 505: \"HTTP Version Not Supported\",\n 226: \"IM Used\",\n 507: \"Insufficient Storage\",\n 500: \"Internal Server Error\",\n 411: \"Length Required\",\n 423: \"Locked\",\n 508: \"Loop Detected\",\n 405: \"Method Not Allowed\",\n 421: \"Misdirected Request\",\n 301: \"Moved Permanently\",\n 207: \"Multi Status\",\n 300: \"Multiple Choices\",\n 511: \"Network Authentication Required\",\n 204: \"No Content\",\n 203: \"Non Authoritative Info\",\n 406: \"Not Acceptable\",\n 510: \"Not Extended\",\n 404: \"Not Found\",\n 501: \"Not Implemented\",\n 304: \"Not Modified\",\n 200: \"OK\",\n 206: \"Partial Content\",\n 402: \"Payment Required\",\n 308: \"Permanent Redirect\",\n 412: \"Precondition Failed\",\n 428: \"Precondition Required\",\n 102: \"Processing\",\n 407: \"Proxy Auth Required\",\n 413: \"Content Too Large\",\n 431: \"Request Header Fields Too Large\",\n 408: \"Request Timeout\",\n 414: \"URI Too Long\",\n 416: \"Range Not Satisfiable\",\n 205: \"Reset Content\",\n 303: \"See Other\",\n 503: \"Service Unavailable\",\n 101: \"Switching Protocols\",\n 418: \"I'm a teapot\",\n 307: \"Temporary Redirect\",\n 425: \"Too Early\",\n 429: \"Too Many Requests\",\n 401: \"Unauthorized\",\n 451: \"Unavailable For Legal Reasons\",\n 422: \"Unprocessable Entity\",\n 415: \"Unsupported Media Type\",\n 426: \"Upgrade Required\",\n 305: \"Use Proxy\",\n 506: \"Variant Also Negotiates\",\n} as const;\n\nexport type StatusCodeType = (typeof STATUS_CODE)[keyof typeof STATUS_CODE];\nexport type StatusTextType = (typeof STATUS_TEXT)[keyof typeof STATUS_TEXT];\n\nexport interface IHttpStatus {\n isInformational: (code: StatusCodeType) => boolean;\n isSuccessful: (code: StatusCodeType) => boolean;\n isRedirect: (code: StatusCodeType) => boolean;\n isClientError: (code: StatusCodeType) => boolean;\n isServerError: (code: StatusCodeType) => boolean;\n isError: (code: StatusCodeType) => boolean;\n}\n\nexport class HttpStatus implements IHttpStatus {\n public static Code: typeof STATUS_CODE = STATUS_CODE;\n public static Text: typeof STATUS_TEXT = STATUS_TEXT;\n\n public isInformational: (code: StatusCodeType) => boolean = (code: StatusCodeType): boolean =>\n code >= STATUS_CODE.Continue && code < STATUS_CODE.OK;\n\n public isSuccessful: (code: StatusCodeType) => boolean = (code: StatusCodeType): boolean =>\n code >= STATUS_CODE.OK && code < STATUS_CODE.MultipleChoices;\n\n public isRedirect: (code: StatusCodeType) => boolean = (code: StatusCodeType): boolean =>\n code >= STATUS_CODE.MultipleChoices && code < STATUS_CODE.BadRequest;\n\n public isClientError: (code: StatusCodeType) => boolean = (code: StatusCodeType): boolean =>\n code >= STATUS_CODE.BadRequest && code < STATUS_CODE.InternalServerError;\n\n public isServerError: (code: StatusCodeType) => boolean = (code: StatusCodeType): boolean =>\n code >= STATUS_CODE.InternalServerError && code < 600;\n\n public isError: (code: StatusCodeType) => boolean = (code: StatusCodeType): boolean =>\n this.isClientError(code) || this.isServerError(code);\n}\n"
6
+ ],
7
+ "mappings": "AAAA,IAAM,EAAc,CAClB,SAAU,IACV,mBAAoB,IACpB,WAAY,IACZ,WAAY,IAEZ,GAAI,IACJ,QAAS,IACT,SAAU,IACV,qBAAsB,IACtB,UAAW,IACX,aAAc,IACd,eAAgB,IAChB,YAAa,IACb,gBAAiB,IACjB,OAAQ,IAER,gBAAiB,IACjB,iBAAkB,IAClB,MAAO,IACP,SAAU,IACV,YAAa,IACb,SAAU,IACV,kBAAmB,IACnB,kBAAmB,IAEnB,WAAY,IACZ,aAAc,IACd,gBAAiB,IACjB,UAAW,IACX,SAAU,IACV,iBAAkB,IAClB,cAAe,IACf,kBAAmB,IACnB,eAAgB,IAChB,SAAU,IACV,KAAM,IACN,eAAgB,IAChB,mBAAoB,IACpB,gBAAiB,IACjB,WAAY,IACZ,qBAAsB,IACtB,oBAAqB,IACrB,kBAAmB,IACnB,OAAQ,IACR,mBAAoB,IACpB,oBAAqB,IACrB,OAAQ,IACR,iBAAkB,IAClB,SAAU,IACV,gBAAiB,IACjB,qBAAsB,IACtB,gBAAiB,IACjB,4BAA6B,IAC7B,2BAA4B,IAE5B,oBAAqB,IACrB,eAAgB,IAChB,WAAY,IACZ,mBAAoB,IACpB,eAAgB,IAChB,wBAAyB,IACzB,sBAAuB,IACvB,oBAAqB,IACrB,aAAc,IACd,YAAa,IACb,8BAA+B,GACjC,EAEM,EAAc,CAClB,IAAK,WACL,IAAK,mBACL,IAAK,cACL,IAAK,cACL,IAAK,WACL,IAAK,WACL,IAAK,UACL,IAAK,cACL,IAAK,qBACL,IAAK,oBACL,IAAK,YACL,IAAK,QACL,IAAK,kBACL,IAAK,OACL,IAAK,6BACL,IAAK,UACL,IAAK,uBACL,IAAK,wBACL,IAAK,kBACL,IAAK,SACL,IAAK,gBACL,IAAK,qBACL,IAAK,sBACL,IAAK,oBACL,IAAK,eACL,IAAK,mBACL,IAAK,kCACL,IAAK,aACL,IAAK,yBACL,IAAK,iBACL,IAAK,eACL,IAAK,YACL,IAAK,kBACL,IAAK,eACL,IAAK,KACL,IAAK,kBACL,IAAK,mBACL,IAAK,qBACL,IAAK,sBACL,IAAK,wBACL,IAAK,aACL,IAAK,sBACL,IAAK,oBACL,IAAK,kCACL,IAAK,kBACL,IAAK,eACL,IAAK,wBACL,IAAK,gBACL,IAAK,YACL,IAAK,sBACL,IAAK,sBACL,IAAK,eACL,IAAK,qBACL,IAAK,YACL,IAAK,oBACL,IAAK,eACL,IAAK,gCACL,IAAK,uBACL,IAAK,yBACL,IAAK,mBACL,IAAK,YACL,IAAK,yBACP,EAcO,MAAM,CAAkC,OAC/B,MAA2B,QAC3B,MAA2B,EAElC,gBAAqD,CAAC,IAC3D,GAAQ,EAAY,UAAY,EAAO,EAAY,GAE9C,aAAkD,CAAC,IACxD,GAAQ,EAAY,IAAM,EAAO,EAAY,gBAExC,WAAgD,CAAC,IACtD,GAAQ,EAAY,iBAAmB,EAAO,EAAY,WAErD,cAAmD,CAAC,IACzD,GAAQ,EAAY,YAAc,EAAO,EAAY,oBAEhD,cAAmD,CAAC,IACzD,GAAQ,EAAY,qBAAuB,EAAO,IAE7C,QAA6C,CAAC,IACnD,KAAK,cAAc,CAAI,GAAK,KAAK,cAAc,CAAI,CACvD",
8
+ "debugId": "140D9A65A1CC1E2164756E2164756E21",
9
+ "names": []
10
+ }
package/package.json ADDED
@@ -0,0 +1,34 @@
1
+ {
2
+ "name": "@ooneex/http-status",
3
+ "description": "",
4
+ "version": "0.0.1",
5
+ "type": "module",
6
+ "files": [
7
+ "dist",
8
+ "LICENSE",
9
+ "README.md",
10
+ "package.json"
11
+ ],
12
+ "module": "./dist/index.js",
13
+ "types": "./dist/index.d.ts",
14
+ "exports": {
15
+ ".": {
16
+ "import": {
17
+ "types": "./dist/index.d.ts",
18
+ "default": "./dist/index.js"
19
+ }
20
+ },
21
+ "./package.json": "./package.json"
22
+ },
23
+ "license": "MIT",
24
+ "scripts": {
25
+ "test": "bun test tests",
26
+ "build": "bunup",
27
+ "lint": "tsgo --noEmit && bunx biome lint",
28
+ "publish:prod": "bun publish --tolerate-republish --access public",
29
+ "publish:pack": "bun pm pack --destination ./dist",
30
+ "publish:dry": "bun publish --dry-run"
31
+ },
32
+ "devDependencies": {},
33
+ "peerDependencies": {}
34
+ }