aboutsummaryrefslogtreecommitdiff
path: root/src/modules
diff options
context:
space:
mode:
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