Skip to content

Commit 8e469d7

Browse files
committed
Add http method enum
1 parent 34bfd94 commit 8e469d7

File tree

4 files changed

+56
-7
lines changed

4 files changed

+56
-7
lines changed

README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,3 +135,21 @@ isRedirect(); // 3xx
135135
isClientError(); // 4xx
136136
isServerError(); // 5xx
137137
```
138+
139+
### Others
140+
141+
For convenience this module also exports a [Method](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods) typescript enum:
142+
143+
```ts
144+
export enum Method {
145+
GET = 'GET',
146+
HEAD = 'HEAD',
147+
POST = 'POST',
148+
PUT = 'PUT',
149+
DELETE = 'DELETE',
150+
CONNECT = 'CONNECT',
151+
OPTIONS = 'OPTIONS',
152+
TRACE = 'TRACE',
153+
PATCH = 'PATCH',
154+
}
155+
```

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "simple-http-status",
3-
"version": "1.0.0",
3+
"version": "1.1.0",
44
"author": "Flávio Carvalho",
55
"module": "dist/simple-http-status.esm.js",
66
"license": "MIT",

src/index.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,3 +79,15 @@ export const isRedirect = (status: number) => status >= 300 && status < 400;
7979
export const isClientError = (status: number) => status >= 400 && status < 500;
8080

8181
export const isServerError = (status: number) => status >= 500 && status < 600;
82+
83+
export enum Method {
84+
GET = 'GET',
85+
HEAD = 'HEAD',
86+
POST = 'POST',
87+
PUT = 'PUT',
88+
DELETE = 'DELETE',
89+
CONNECT = 'CONNECT',
90+
OPTIONS = 'OPTIONS',
91+
TRACE = 'TRACE',
92+
PATCH = 'PATCH',
93+
}

test/index.test.ts

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ import {
55
isRedirect,
66
isClientError,
77
isServerError,
8-
} from '../src';
8+
Method,
9+
} from '../dist';
910

1011
type Test = [
1112
Status,
@@ -115,21 +116,39 @@ const tests: Test[] = [
115116
tests.map(
116117
([status, [informational, success, redirect, clientError, serverError]]) => {
117118
describe(`[${status}]`, () => {
118-
it('[isInformational]', () => {
119+
it(`isInformational |> ${informational}`, () => {
119120
expect(isInformational(status)).toEqual(informational);
120121
});
121-
it('[isSuccess]', () => {
122+
it(`isSuccess |> ${success}`, () => {
122123
expect(isSuccess(status)).toEqual(success);
123124
});
124-
it('[isRedirect]', () => {
125+
it(`isRedirect |> ${redirect}`, () => {
125126
expect(isRedirect(status)).toEqual(redirect);
126127
});
127-
it('[isClientError]', () => {
128+
it(`isClientError |> ${clientError}`, () => {
128129
expect(isClientError(status)).toEqual(clientError);
129130
});
130-
it('[isServerError]', () => {
131+
it(`isServerError |> ${serverError}`, () => {
131132
expect(isServerError(status)).toEqual(serverError);
132133
});
133134
});
134135
}
135136
);
137+
138+
describe('[Method]', () => {
139+
it('Should contain all the HTTP methods', () => {
140+
expect(Method).toMatchInlineSnapshot(`
141+
Object {
142+
"CONNECT": "CONNECT",
143+
"DELETE": "DELETE",
144+
"GET": "GET",
145+
"HEAD": "HEAD",
146+
"OPTIONS": "OPTIONS",
147+
"PATCH": "PATCH",
148+
"POST": "POST",
149+
"PUT": "PUT",
150+
"TRACE": "TRACE",
151+
}
152+
`);
153+
});
154+
});

0 commit comments

Comments
 (0)