Skip to content

Commit 255c1b4

Browse files
authored
Merge pull request #38 from Skillnter/dev
Refactoring & Named Imports
2 parents d3350c3 + 08e8717 commit 255c1b4

30 files changed

+8119
-8701
lines changed

README.md

Lines changed: 32 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ All HTTP Status Codes from [Wikipedia - List of HTTP status codes](https://en.wi
1010
[![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)
1111
![npms.io (final)](https://img.shields.io/npms-io/maintenance-score/http-response-status-code?color=brightgreen)
1212
![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)
1314
[![GitHub Pages](https://img.shields.io/badge/GitHub%20Pages-121013?logo=github&logoColor=white)](https://skillnter.github.io/http-response-status-code/)
1415
[![Github Sponsors](https://img.shields.io/badge/GitHub%20Sponsors-30363D?&logo=GitHub-Sponsors&logoColor=EA4AAA)](https://github.com/sponsors/Skillnter)
1516
[![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
5354
var STATUS_CODES = require('http-response-status-code');
5455
// OR
5556
import * as STATUS_CODES from 'http-response-status-code';
57+
// OR
58+
import { OK, getStatusName, CODES } from 'http-response-status-code';
5659

5760
console.log(STATUS_CODES.getStatusName(STATUS_CODES.OK));
5861
// OK
5962

63+
console.log(getStatusName(OK));
64+
// OK
65+
66+
console.log(OK);
67+
// 200
68+
6069
console.log(STATUS_CODES.getStatusDescription(STATUS_CODES.INTERNAL_SERVER_ERROR));
6170
// Internal Server Error
6271

@@ -92,7 +101,7 @@ Returns the HTTP status code from status code name.
92101

93102
#### Returns
94103

95-
- `code` (`number`): The code number of the status if successful.
104+
- `code` (`number`): The code number of the status if code exists.
96105
- `Error`: An error object if something goes wrong, containing details about the issue.
97106

98107
### Example ([Stackblitz][getStatusCode])
@@ -104,15 +113,15 @@ console.log(STATUS_CODES.getStatusCode("IM_A_TEAPOT")); // 418
104113

105114
### 2. Get Status Name
106115

107-
Returns the HTTP status code name from status code.
116+
Returns the HTTP status code name from status code (e.g., `418`).
108117

109118
#### Parameters
110119

111120
- `code` (`number`): The code number of the status (e.g., `418`).
112121

113122
#### Returns
114123

115-
- `name` (`String`): The name of the status code if successful.
124+
- `name` (`String`): The name of the status code if name exists.
116125
- `Error`: An error object if something goes wrong, containing details about the issue.
117126

118127
### Example ([Stackblitz][getStatusName])
@@ -128,11 +137,11 @@ Returns the status description from HTTP status code (e.g., `418`).
128137

129138
#### Parameters
130139

131-
- `code` (`number`): The code number of the status.
140+
- `code` (`number`): The code number of the status (e.g., `418`).
132141

133142
#### Returns
134143

135-
- `name` (`String`): The description of the status code if successful.
144+
- `name` (`String`): The description of the status code if code exists.
136145
- `Error`: An error object if something goes wrong, containing details about the issue.
137146

138147
### Example ([Stackblitz][getStatusDescription])
@@ -148,11 +157,11 @@ Determines whether the specified status code represents an informational status.
148157

149158
#### Parameters
150159

151-
- `code` (`number`): The code number of the status.
160+
- `code` (`number`): The code number of the status (e.g., `100`).
152161

153162
#### Returns
154163

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`.
156165
- `Error`: An error object if something goes wrong, containing details about the issue.
157166

158167
### Example ([Stackblitz][isInformational])
@@ -165,7 +174,7 @@ console.log(STATUS_CODES.isInformational(200)); // False
165174

166175
### 5. List Informational Codes
167176

168-
Returns all the informational HTTP status codes.
177+
Provides a list of all the informational HTTP status codes.
169178

170179
#### Returns
171180

@@ -184,11 +193,11 @@ Determines whether the specified status code represents a success status.
184193

185194
#### Parameters
186195

187-
- `code` (`number`): The code number of the status.
196+
- `code` (`number`): The code number of the status (e.g., `200`).
188197

189198
#### Returns
190199

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`.
192201
- `Error`: An error object if something goes wrong, containing details about the issue.
193202

194203
### Example ([Stackblitz][isSuccess])
@@ -201,7 +210,7 @@ console.log(STATUS_CODES.isSuccess(100)); // False
201210

202211
### 7. List Success Codes
203212

204-
Returns all the success HTTP status codes.
213+
Provides a list of all the success HTTP status codes.
205214

206215
#### Returns
207216

@@ -220,11 +229,11 @@ Determines whether the specified status code represents a redirection status.
220229

221230
#### Parameters
222231

223-
- `code` (`number`): The code number of the status.
232+
- `code` (`number`): The code number of the status (e.g., `300`).
224233

225234
#### Returns
226235

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`.
228237
- `Error`: An error object if something goes wrong, containing details about the issue.
229238

230239
### Example ([Stackblitz][isRedirectional])
@@ -237,7 +246,7 @@ console.log(STATUS_CODES.isRedirectional(100)); // False
237246

238247
### 9. List Redirection Codes
239248

240-
Returns all the redirection HTTP status codes.
249+
Provides a list of all the redirection HTTP status codes.
241250

242251
#### Returns
243252

@@ -256,11 +265,11 @@ Determines whether the specified status code represents a client side error stat
256265

257266
#### Parameters
258267

259-
- `code` (`number`): The code number of the status.
268+
- `code` (`number`): The code number of the status (e.g., `400`).
260269

261270
#### Returns
262271

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`.
264273
- `Error`: An error object if something goes wrong, containing details about the issue.
265274

266275
### Example ([Stackblitz][isClientError])
@@ -273,7 +282,7 @@ console.log(STATUS_CODES.isClientError(100)); // False
273282

274283
### 11. List Client Side Error Codes
275284

276-
Returns all the client side error HTTP status codes.
285+
Provides a list of all the client side error HTTP status codes.
277286

278287
#### Returns
279288

@@ -292,11 +301,11 @@ Determines whether the specified status code represents a server side error stat
292301

293302
#### Parameters
294303

295-
- `code` (`number`): The code number of the status.
304+
- `code` (`number`): The code number of the status (e.g., `500`).
296305

297306
#### Returns
298307

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`.
300309
- `Error`: An error object if something goes wrong, containing details about the issue.
301310

302311
### Example ([Stackblitz][isServerError])
@@ -309,7 +318,7 @@ console.log(STATUS_CODES.isServerError(100)); // False
309318

310319
### 13. List Server Side Error Codes
311320

312-
Returns all the server side error HTTP status codes.
321+
Provides a list of all the server side error HTTP status codes.
313322

314323
#### Returns
315324

@@ -328,11 +337,11 @@ Validates whether the provided status code is recognized as valid.
328337

329338
#### Parameters
330339

331-
- `code` (`number`): The code number of the status.
340+
- `code` (`number`): The code number of the status (e.g., `500`).
332341

333342
#### Returns
334343

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`.
336345
- `Error`: An error object if something goes wrong, containing details about the issue.
337346

338347
### Example ([Stackblitz][isValidStatusCode])
@@ -368,6 +377,7 @@ console.log(STATUS_CODES.isValidStatusCode(999)); // False
368377
| 303 | HTTP_CODE_303 | SEE_OTHER | See Other
369378
| 304 | HTTP_CODE_304 | NOT_MODIFIED | Not Modified
370379
| 305 | HTTP_CODE_305 | USE_PROXY | Use Proxy
380+
| 306 | HTTP_CODE_306 | SWITCH_PROXY | Switch Proxy
371381
| 307 | HTTP_CODE_307 | TEMPORARY_REDIRECT | Temporary Redirect
372382
| 308 | HTTP_CODE_308 | PERMANENT_REDIRECT | Permanent Redirect
373383
| 400 | HTTP_CODE_400 | BAD_REQUEST | Bad Request

index.d.ts

Lines changed: 0 additions & 2 deletions
This file was deleted.

0 commit comments

Comments
 (0)