aboutsummaryrefslogtreecommitdiff
path: root/src/modules
diff options
context:
space:
mode:
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 ? '/' : ''}`;
}
/**