aboutsummaryrefslogtreecommitdiff
path: root/src/modules
diff options
context:
space:
mode:
authorjohge201 <[email protected]>2022-05-21 16:15:20 +0200
committerGitHub <[email protected]>2022-05-21 16:15:20 +0200
commit05f555bc7e304afaa657586ae88f2173507e084f (patch)
tree4abbb28774d092c9369b7adc170fcea2f1400c21 /src/modules
parentb0cdf29d3a7470b1211e724b68e243b8c96a7f4c (diff)
downloadfaker-05f555bc7e304afaa657586ae88f2173507e084f.tar.xz
faker-05f555bc7e304afaa657586ae88f2173507e084f.zip
feat(internet): HTTP random status code (#945)
Co-authored-by: ST-DDT <[email protected]> Co-authored-by: Piotr Kuczynski <[email protected]> Co-authored-by: johge201 <[email protected]> Co-authored-by: Sofia Bertmar <[email protected]> Co-authored-by: Sofia Bertmar <[email protected]> Co-authored-by: Shinigami <[email protected]>
Diffstat (limited to 'src/modules')
-rw-r--r--src/modules/internet/index.ts31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/modules/internet/index.ts b/src/modules/internet/index.ts
index 7e0baaec..f08ff321 100644
--- a/src/modules/internet/index.ts
+++ b/src/modules/internet/index.ts
@@ -13,6 +13,13 @@ export type EmojiType =
| 'symbol'
| 'flag';
+export type HTTPStatusCodeType =
+ | 'informational'
+ | 'success'
+ | 'clientError'
+ | 'serverError'
+ | 'redirection';
+
/**
* Module to generate internet related entries.
*/
@@ -181,6 +188,30 @@ export class Internet {
}
/**
+ * Generates a random HTTP status code.
+ *
+ * @param options Options object.
+ * @param options.types A list of the HTTP status code types that should be used.
+ *
+ * @example
+ * faker.internet.httpStatusCode() // 200
+ * faker.internet.httpStatusCode({ types: ['success', 'serverError'] }) // 500
+ */
+ httpStatusCode(
+ options: { types?: ReadonlyArray<HTTPStatusCodeType> } = {}
+ ): number {
+ const {
+ types = Object.keys(
+ this.faker.definitions.internet.http_status_code
+ ) as Array<HTTPStatusCodeType>,
+ } = options;
+ const httpStatusCodeType = this.faker.helpers.arrayElement(types);
+ return this.faker.helpers.arrayElement(
+ this.faker.definitions.internet.http_status_code[httpStatusCodeType]
+ );
+ }
+
+ /**
* Generates a random url.
*
* @example