-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathisInformationStatus.ts
49 lines (45 loc) · 1.89 KB
/
isInformationStatus.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import { HttpInformationStatusCodes } from '../HttpStatusCodes';
import { HttpInformationReasonPhrases } from '../HttpReasonPhrases';
/**
* Checks whether the status code belongs to `HttpInformationStatusCodes` enum.
* The range is all standard code between [100 - 199]
*
* To check the entire 1xx range use `is1xxInformationStatusCode(code: number)` instead.
* @param statusCode - The integer status code. e.g. 100
* @returns `true` if matches `false` otherwise
*/
export const isInformationStatusCode = (statusCode: number): boolean =>
HttpInformationStatusCodes[statusCode] !== undefined;
/**
* Checks whether the status code belongs to 1xx family of status codes.
*
* @param statusCode - The integer status code. e.g. 100
* @returns `true` if matches `false` otherwise
*/
export const is1xxInformationStatusCode = (statusCode: number): boolean =>
statusCode >= 100 && statusCode <= 199;
/**
* Checks whether the input string belongs to `HttpInformationReasonPhrases` enum.
*
* The match is case sensitive
*
* @param reasonPhrase - The reason phrase. e.g. 'Ok'
* @returns `true` if matches `false` otherwise
*/
export const isInformationReasonPhrase = (reasonPhrase: string): boolean =>
(Object.values(HttpInformationReasonPhrases) as string[]).includes(
reasonPhrase
) === true;
/**
* Checks whether the input integer or string belongs to
* `HttpInformationStatusCodes` or `HttpInformationReasonPhrases` enum.
* For integer input, the range is all standard code between [100 - 199].
* For string input, the match is case sensitive.
*
* To check the entire 1xx range use `is1xxInformationStatusCode(code: number)` instead.
* @param status - e.g. 'Ok' or 200
* @returns `true` if matches `false` otherwise
*/
export const isInformationStatus = (status: string | number): boolean =>
isInformationStatusCode(status as number) ||
isInformationReasonPhrase(status as string);