aboutsummaryrefslogtreecommitdiff
path: root/src/modules
diff options
context:
space:
mode:
authorEric Cheng <[email protected]>2022-10-26 16:42:17 -0400
committerGitHub <[email protected]>2022-10-26 22:42:17 +0200
commit09e835664add0a342dd089f31bbae7d880198493 (patch)
tree14f6f85c6d9fa10cbeba9ef96d405e05a3a3d843 /src/modules
parent64b031a9e385d1461b2c158abfa1851ba11a8397 (diff)
downloadfaker-09e835664add0a342dd089f31bbae7d880198493.tar.xz
faker-09e835664add0a342dd089f31bbae7d880198493.zip
feat(internet): add options to url() (#1480)
Diffstat (limited to 'src/modules')
-rw-r--r--src/modules/internet/index.ts21
1 files changed, 18 insertions, 3 deletions
diff --git a/src/modules/internet/index.ts b/src/modules/internet/index.ts
index 1c7e85cc..60e3ac55 100644
--- a/src/modules/internet/index.ts
+++ b/src/modules/internet/index.ts
@@ -20,6 +20,8 @@ export type HTTPStatusCodeType =
| 'serverError'
| 'redirection';
+export type HTTPProtocolType = 'http' | 'https';
+
/**
* Module to generate internet related entries.
*/
@@ -226,15 +228,28 @@ export class InternetModule {
}
/**
- * Generates a random url.
+ * Generates a random http(s) url.
+ *
+ * @param options Optional options object.
+ * @param options.appendSlash Whether to append a slash to the end of the url (path). Defaults to a random boolean value.
+ * @param options.protocol The protocol to use. Defaults to `'https'`.
*
* @example
* faker.internet.url() // 'https://remarkable-hackwork.info'
+ * faker.internet.url({ appendSlash: true }) // 'https://slow-timer.info/'
+ * faker.internet.url({ protocol: 'http', appendSlash: false }) // 'http://www.terrible-idea.com'
*
* @since 2.1.5
*/
- url(): string {
- return `${this.protocol()}://${this.domainName()}`;
+ url(
+ options: {
+ appendSlash?: boolean;
+ protocol?: HTTPProtocolType;
+ } = {}
+ ): string {
+ const { appendSlash = this.faker.datatype.boolean(), protocol = 'https' } =
+ options;
+ return `${protocol}://${this.domainName()}${appendSlash ? '/' : ''}`;
}
/**