@@ -10,6 +10,7 @@ All HTTP Status Codes from [Wikipedia - List of HTTP status codes](https://en.wi
10
10
[ ![ Codacy Badge] ( https://app.codacy.com/project/badge/Grade/7d55170d359c475e9e586fd00e00841e )] ( https://app.codacy.com/gh/Skillnter/http-response-status-code/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_grade )
11
11
![ npms.io (final)] ( https://img.shields.io/npms-io/maintenance-score/http-response-status-code?color=brightgreen )
12
12
![ npm] ( https://img.shields.io/npm/dy/http-response-status-code )
13
+ [ ![ Socket Badge] ( https://socket.dev/api/badge/npm/package/http-response-status-code/1.7.4 )] ( https://socket.dev/npm/package/http-response-status-code/overview/1.7.4 )
13
14
[ ![ GitHub Pages] ( https://img.shields.io/badge/GitHub%20Pages-121013?logo=github&logoColor=white )] ( https://skillnter.github.io/http-response-status-code/ )
14
15
[ ![ Github Sponsors] ( https://img.shields.io/badge/GitHub%20Sponsors-30363D?&logo=GitHub-Sponsors&logoColor=EA4AAA )] ( https://github.com/sponsors/Skillnter )
15
16
[ ![ Open Collective] ( https://img.shields.io/badge/Open%20Collective-3385FF?logo=open-collective&logoColor=white )] ( https://opencollective.com/http-response-status-code )
@@ -53,10 +54,18 @@ npm install http-response-status-code
53
54
var STATUS_CODES = require (' http-response-status-code' );
54
55
// OR
55
56
import * as STATUS_CODES from ' http-response-status-code' ;
57
+ // OR
58
+ import { OK , getStatusName , CODES } from ' http-response-status-code' ;
56
59
57
60
console .log (STATUS_CODES .getStatusName (STATUS_CODES .OK ));
58
61
// OK
59
62
63
+ console .log (getStatusName (OK ));
64
+ // OK
65
+
66
+ console .log (OK );
67
+ // 200
68
+
60
69
console .log (STATUS_CODES .getStatusDescription (STATUS_CODES .INTERNAL_SERVER_ERROR ));
61
70
// Internal Server Error
62
71
@@ -92,7 +101,7 @@ Returns the HTTP status code from status code name.
92
101
93
102
#### Returns
94
103
95
- - ` code ` (` number ` ): The code number of the status if successful .
104
+ - ` code ` (` number ` ): The code number of the status if code exists .
96
105
- ` Error ` : An error object if something goes wrong, containing details about the issue.
97
106
98
107
### Example ([ Stackblitz] [ getStatusCode ] )
@@ -104,15 +113,15 @@ console.log(STATUS_CODES.getStatusCode("IM_A_TEAPOT")); // 418
104
113
105
114
### 2. Get Status Name
106
115
107
- Returns the HTTP status code name from status code.
116
+ Returns the HTTP status code name from status code (e.g., ` 418 ` ) .
108
117
109
118
#### Parameters
110
119
111
120
- ` code ` (` number ` ): The code number of the status (e.g., ` 418 ` ).
112
121
113
122
#### Returns
114
123
115
- - ` name ` (` String ` ): The name of the status code if successful .
124
+ - ` name ` (` String ` ): The name of the status code if name exists .
116
125
- ` Error ` : An error object if something goes wrong, containing details about the issue.
117
126
118
127
### Example ([ Stackblitz] [ getStatusName ] )
@@ -128,11 +137,11 @@ Returns the status description from HTTP status code (e.g., `418`).
128
137
129
138
#### Parameters
130
139
131
- - ` code ` (` number ` ): The code number of the status.
140
+ - ` code ` (` number ` ): The code number of the status (e.g., ` 418 ` ) .
132
141
133
142
#### Returns
134
143
135
- - ` name ` (` String ` ): The description of the status code if successful .
144
+ - ` name ` (` String ` ): The description of the status code if code exists .
136
145
- ` Error ` : An error object if something goes wrong, containing details about the issue.
137
146
138
147
### Example ([ Stackblitz] [ getStatusDescription ] )
@@ -148,11 +157,11 @@ Determines whether the specified status code represents an informational status.
148
157
149
158
#### Parameters
150
159
151
- - ` code ` (` number ` ): The code number of the status.
160
+ - ` code ` (` number ` ): The code number of the status (e.g., ` 100 ` ) .
152
161
153
162
#### Returns
154
163
155
- - ` result ` (` boolean ` ): Returns ` true ` if the status code represents a informational status code (1xx), otherwise returns ` false ` .
164
+ - ` isInformational ` (` boolean ` ): Returns ` true ` if the status code represents a informational status code (1xx), otherwise returns ` false ` .
156
165
- ` Error ` : An error object if something goes wrong, containing details about the issue.
157
166
158
167
### Example ([ Stackblitz] [ isInformational ] )
@@ -165,7 +174,7 @@ console.log(STATUS_CODES.isInformational(200)); // False
165
174
166
175
### 5. List Informational Codes
167
176
168
- Returns all the informational HTTP status codes.
177
+ Provides a list of all the informational HTTP status codes.
169
178
170
179
#### Returns
171
180
@@ -184,11 +193,11 @@ Determines whether the specified status code represents a success status.
184
193
185
194
#### Parameters
186
195
187
- - ` code ` (` number ` ): The code number of the status.
196
+ - ` code ` (` number ` ): The code number of the status (e.g., ` 200 ` ) .
188
197
189
198
#### Returns
190
199
191
- - ` result ` (` boolean ` ): Returns ` true ` if the status code represents a successful response (2xx), otherwise returns ` false ` .
200
+ - ` isSuccess ` (` boolean ` ): Returns ` true ` if the status code represents a success status code (2xx), otherwise returns ` false ` .
192
201
- ` Error ` : An error object if something goes wrong, containing details about the issue.
193
202
194
203
### Example ([ Stackblitz] [ isSuccess ] )
@@ -201,7 +210,7 @@ console.log(STATUS_CODES.isSuccess(100)); // False
201
210
202
211
### 7. List Success Codes
203
212
204
- Returns all the success HTTP status codes.
213
+ Provides a list of all the success HTTP status codes.
205
214
206
215
#### Returns
207
216
@@ -220,11 +229,11 @@ Determines whether the specified status code represents a redirection status.
220
229
221
230
#### Parameters
222
231
223
- - ` code ` (` number ` ): The code number of the status.
232
+ - ` code ` (` number ` ): The code number of the status (e.g., ` 300 ` ) .
224
233
225
234
#### Returns
226
235
227
- - ` result ` (` boolean ` ): Returns ` true ` if the status code represents a redirection status code (3xx), otherwise returns ` false ` .
236
+ - ` isRedirectional ` (` boolean ` ): Returns ` true ` if the status code represents a redirection status code (3xx), otherwise returns ` false ` .
228
237
- ` Error ` : An error object if something goes wrong, containing details about the issue.
229
238
230
239
### Example ([ Stackblitz] [ isRedirectional ] )
@@ -237,7 +246,7 @@ console.log(STATUS_CODES.isRedirectional(100)); // False
237
246
238
247
### 9. List Redirection Codes
239
248
240
- Returns all the redirection HTTP status codes.
249
+ Provides a list of all the redirection HTTP status codes.
241
250
242
251
#### Returns
243
252
@@ -256,11 +265,11 @@ Determines whether the specified status code represents a client side error stat
256
265
257
266
#### Parameters
258
267
259
- - ` code ` (` number ` ): The code number of the status.
268
+ - ` code ` (` number ` ): The code number of the status (e.g., ` 400 ` ) .
260
269
261
270
#### Returns
262
271
263
- - ` result ` (` boolean ` ): Returns ` true ` if the status code represents a client side error code (4xx), otherwise returns ` false ` .
272
+ - ` isClientError ` (` boolean ` ): Returns ` true ` if the status code represents a client side error code (4xx), otherwise returns ` false ` .
264
273
- ` Error ` : An error object if something goes wrong, containing details about the issue.
265
274
266
275
### Example ([ Stackblitz] [ isClientError ] )
@@ -273,7 +282,7 @@ console.log(STATUS_CODES.isClientError(100)); // False
273
282
274
283
### 11. List Client Side Error Codes
275
284
276
- Returns all the client side error HTTP status codes.
285
+ Provides a list of all the client side error HTTP status codes.
277
286
278
287
#### Returns
279
288
@@ -292,11 +301,11 @@ Determines whether the specified status code represents a server side error stat
292
301
293
302
#### Parameters
294
303
295
- - ` code ` (` number ` ): The code number of the status.
304
+ - ` code ` (` number ` ): The code number of the status (e.g., ` 500 ` ) .
296
305
297
306
#### Returns
298
307
299
- - ` result ` (` boolean ` ): Returns ` true ` if the status code represents a server side error code (5xx), otherwise returns ` false ` .
308
+ - ` isServerError ` (` boolean ` ): Returns ` true ` if the status code represents a server side error code (5xx), otherwise returns ` false ` .
300
309
- ` Error ` : An error object if something goes wrong, containing details about the issue.
301
310
302
311
### Example ([ Stackblitz] [ isServerError ] )
@@ -309,7 +318,7 @@ console.log(STATUS_CODES.isServerError(100)); // False
309
318
310
319
### 13. List Server Side Error Codes
311
320
312
- Returns all the server side error HTTP status codes.
321
+ Provides a list of all the server side error HTTP status codes.
313
322
314
323
#### Returns
315
324
@@ -328,11 +337,11 @@ Validates whether the provided status code is recognized as valid.
328
337
329
338
#### Parameters
330
339
331
- - ` code ` (` number ` ): The code number of the status.
340
+ - ` code ` (` number ` ): The code number of the status (e.g., ` 500 ` ) .
332
341
333
342
#### Returns
334
343
335
- - ` result ` (` boolean ` ): Returns ` true ` if the status code represents a valid status code (1xx, 2xx, ..., 5xx), otherwise returns ` false ` .
344
+ - ` isValidStatusCode ` (` boolean ` ): Returns ` true ` if the status code represents a valid status code (1xx, 2xx, ..., 5xx), otherwise returns ` false ` .
336
345
- ` Error ` : An error object if something goes wrong, containing details about the issue.
337
346
338
347
### Example ([ Stackblitz] [ isValidStatusCode ] )
@@ -368,6 +377,7 @@ console.log(STATUS_CODES.isValidStatusCode(999)); // False
368
377
| 303 | HTTP_CODE_303 | SEE_OTHER | See Other
369
378
| 304 | HTTP_CODE_304 | NOT_MODIFIED | Not Modified
370
379
| 305 | HTTP_CODE_305 | USE_PROXY | Use Proxy
380
+ | 306 | HTTP_CODE_306 | SWITCH_PROXY | Switch Proxy
371
381
| 307 | HTTP_CODE_307 | TEMPORARY_REDIRECT | Temporary Redirect
372
382
| 308 | HTTP_CODE_308 | PERMANENT_REDIRECT | Permanent Redirect
373
383
| 400 | HTTP_CODE_400 | BAD_REQUEST | Bad Request
0 commit comments