Internet
Module to generate internet related entries.
Overview
For user accounts, you may need an email()
and a password()
, as well as a ASCII username()
or Unicode displayName()
. Since the emails generated could coincidentally be real email addresses, you should not use these for sending real email addresses. If this is a concern, use exampleEmail()
instead.
For websites, you can generate a domainName()
or a full url()
.
To make your data more 🔥, you can use emoji()
.
You also have access to a number of the more technical elements of web requests, such as httpMethod
, httpStatusCode
, ip
, mac
, userAgent
, and port
.
color
Generates a random css hex color code in aesthetically pleasing color palette.
Available since v2.0.1
Parameters
Name | Type | Default | Description |
---|---|---|---|
options | { ... } | {} | An options object. |
options.blueBase? | number | 0 | The optional base blue in range between |
options.greenBase? | number | 0 | The optional base green in range between |
options.redBase? | number | 0 | The optional base red in range between |
Returns: string
function color(
options: {
redBase?: number;
greenBase?: number;
blueBase?: number;
} = {}
): string;
Examples
faker.internet.color() // '#30686e'
faker.internet.color({ redBase: 100, greenBase: 100, blueBase: 100 }) // '#4e5f8b'
Source
displayName
Generates a display name using the given person's name as base. The resulting display name may use one or both of the provided names. If the input names include Unicode characters, the resulting display name will contain Unicode characters. It will not contain spaces.
Available since v8.0.0
Parameters
Name | Type | Default | Description |
---|---|---|---|
options | { ... } | {} | An options object. |
options.firstName? | string | faker.person.firstName() | The optional first name to use. |
options.lastName? | string | faker.person.lastName() | The optional last name to use. |
Returns: string
function displayName(
options: {
firstName?: string;
lastName?: string;
} = {}
): string;
Examples
faker.internet.displayName() // 'Nettie_Zboncak40'
faker.internet.displayName({ firstName: 'Jeanne', lastName: 'Doe' }) // 'Jeanne98' - note surname not used.
faker.internet.displayName({ firstName: 'John', lastName: 'Doe' }) // 'John.Doe'
faker.internet.displayName({ firstName: 'Hélene', lastName: 'Müller' }) // 'Hélene_Müller11'
faker.internet.displayName({ firstName: 'Фёдор', lastName: 'Достоевский' }) // 'Фёдор.Достоевский50'
faker.internet.displayName({ firstName: '大羽', lastName: '陳' }) // '大羽.陳'
Source
domainName
Generates a random domain name.
Available since v2.0.1
Returns: string
function domainName(): string;
Examples
faker.internet.domainName() // 'slow-timer.info'
Source
domainSuffix
Returns a random domain suffix.
Available since v2.0.1
Returns: string
function domainSuffix(): string;
Examples
faker.internet.domainSuffix() // 'com'
faker.internet.domainSuffix() // 'name'
Source
domainWord
Generates a random domain word.
Available since v2.0.1
Returns: string
function domainWord(): string;
Examples
faker.internet.domainWord() // 'close-reality'
faker.internet.domainWord() // 'weird-cytoplasm'
Source
email
Generates an email address using the given person's name as base.
Available since v2.0.1
Parameters
Name | Type | Default | Description |
---|---|---|---|
options | { ... } | {} | The options to use. |
options.allowSpecialCharacters? | boolean | false | Whether special characters such as |
options.firstName? | string | faker.person.firstName() | The optional first name to use. |
options.lastName? | string | faker.person.lastName() | The optional last name to use. |
options.provider? | string | The mail provider domain to use. If not specified, a random free mail provider will be chosen. |
Returns: string
function email(
options: {
firstName?: string;
lastName?: string;
provider?: string;
allowSpecialCharacters?: boolean;
} = {}
): string;
Examples
faker.internet.email() // 'Kassandra4@hotmail.com'
faker.internet.email({ firstName: 'Jeanne'}) // 'Jeanne63@yahoo.com'
faker.internet.email({ firstName: 'Jeanne'}) // 'Jeanne_Smith63@yahoo.com'
faker.internet.email({ firstName: 'Jeanne', lastName: 'Doe' }) // 'Jeanne.Doe63@yahoo.com'
faker.internet.email({ firstName: 'Jeanne', lastName: 'Doe', provider: 'example.fakerjs.dev' }) // 'Jeanne_Doe88@example.fakerjs.dev'
faker.internet.email({ firstName: 'Jeanne', lastName: 'Doe', provider: 'example.fakerjs.dev', allowSpecialCharacters: true }) // 'Jeanne%Doe88@example.fakerjs.dev'
Source
emoji
Generates a random emoji.
Available since v6.2.0
Parameters
Name | Type | Default | Description |
---|---|---|---|
options | { ... } | {} | Options object. |
options.types? | EmojiType[] | Object.keys(faker.definitions.internet.emoji) | A list of the emoji types that should be used. |
Returns: string
function emoji(
options: {
types?: ReadonlyArray<EmojiType>;
} = {}
): string;
Examples
faker.internet.emoji() // '🥰'
faker.internet.emoji({ types: ['food', 'nature'] }) // '🥐'
Source
exampleEmail
Generates an email address using an example mail provider using the given person's name as base.
Available since v3.1.0
Parameters
Name | Type | Default | Description |
---|---|---|---|
options | { ... } | {} | An options object. |
options.allowSpecialCharacters? | boolean | false | Whether special characters such as |
options.firstName? | string | faker.person.firstName() | The optional first name to use. |
options.lastName? | string | faker.person.lastName() | The optional last name to use. |
Returns: string
function exampleEmail(
options: {
firstName?: string;
lastName?: string;
allowSpecialCharacters?: boolean;
} = {}
): string;
Examples
faker.internet.exampleEmail() // 'Helmer.Graham23@example.com'
faker.internet.exampleEmail({ firstName: 'Jeanne' }) // 'Jeanne96@example.net'
faker.internet.exampleEmail({ firstName: 'Jeanne' }) // 'Jeanne.Smith96@example.net'
faker.internet.exampleEmail({ firstName: 'Jeanne', lastName: 'Doe' }) // 'Jeanne_Doe96@example.net'
faker.internet.exampleEmail({ firstName: 'Jeanne', lastName: 'Doe', allowSpecialCharacters: true }) // 'Jeanne%Doe88@example.com'
Source
httpMethod
Returns a random http method.
Can be either of the following:
GET
POST
PUT
DELETE
PATCH
Available since v5.4.0
Returns: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH'
function httpMethod(): 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
Examples
faker.internet.httpMethod() // 'PATCH'
Source
httpStatusCode
Generates a random HTTP status code.
Available since v7.0.0
Parameters
Name | Type | Default | Description |
---|---|---|---|
options | { ... } | {} | Options object. |
options.types? | HTTPStatusCodeType[] | Object.keys(faker.definitions.internet.http_status_code) | A list of the HTTP status code types that should be used. |
Returns: number
function httpStatusCode(
options: {
types?: ReadonlyArray<HTTPStatusCodeType>;
} = {}
): number;
Examples
faker.internet.httpStatusCode() // 200
faker.internet.httpStatusCode({ types: ['success', 'serverError'] }) // 500
Source
ip
Generates a random IPv4 or IPv6 address.
Available since v2.0.1
Returns: string
function ip(): string;
Examples
faker.internet.ip() // '245.108.222.0'
faker.internet.ip() // '4e5:f9c5:4337:abfd:9caf:1135:41ad:d8d3'
Source
ipv4
Generates a random IPv4 address.
Available since v6.1.1
Parameters
Name | Type | Default | Description |
---|---|---|---|
options? | { ... } | { ... } | {} | The optional options object. |
options.cidrBlock? | string | '0.0.0.0/0' | The optional CIDR block to use. Must be in the format |
options.network? | 'any' | 'loopback' | 'private-a' | 'private-b' | 'private-c' | 'test-net-1' | 'test-net-2' | 'test-net-3' | 'link-local' | 'multicast' | 'any' | The optional network to use. This is intended as an alias for well-known |
Returns: string
function ipv4(
options?:
| {
cidrBlock?: string;
}
| {
network?: IPv4NetworkType;
}
): string;
Examples
faker.internet.ipv4() // '245.108.222.0'
faker.internet.ipv4({ cidrBlock: '192.168.0.0/16' }) // '192.168.215.224'
faker.internet.ipv4({ network: 'private-a' }) // '10.199.154.205'
Source
ipv6
Generates a random IPv6 address.
Available since v4.0.0
Returns: string
function ipv6(): string;
Examples
faker.internet.ipv6() // '269f:1230:73e3:318d:842b:daab:326d:897b'
Source
jwt
Generates a random JWT (JSON Web Token).
Please note that this method generates a random signature instead of a valid one.
Available since v9.1.0
Parameters
Name | Type | Default | Description |
---|---|---|---|
options | { ... } | {} | The optional options object. |
options.header? | Record<string, unknown> | {
alg: faker.internet.jwtAlgorithm(),
typ: 'JWT'
} | The header to use for the token. If present, it will replace any default values. |
options.payload? | Record<string, unknown> | {
iat: faker.date.recent(),
exp: faker.date.soon(),
nbf: faker.date.anytime(),
iss: faker.company.name(),
sub: faker.string.uuid(),
aud: faker.string.uuid(),
jti: faker.string.uuid()
} | The payload to use for the token. If present, it will replace any default values. |
options.refDate? | string | number | Date | faker.defaultRefDate() | The date to use as reference point for the newly generated date. |
Returns: string
function jwt(
options: {
header?: Record<string, unknown>;
payload?: Record<string, unknown>;
refDate?: string | Date | number;
} = {}
): string;
Examples
faker.internet.jwt()
faker.internet.jwt({ header: { alg: 'HS256' }}) // 'eyJhbGciOiJIUzI1NiJ9.eyJpYXQiOjE3MTg2MTM3MTIsImV4cCI6MTcxODYzMzY3OSwibmJmIjoxNjk3MjYzNjMwLCJpc3MiOiJEb3lsZSBhbmQgU29ucyIsInN1YiI6IjYxYWRkYWFmLWY4MjktNDkzZS1iNTI1LTJjMGJkNjkzOTdjNyIsImF1ZCI6IjczNjcyMjVjLWIwMWMtNGE1My1hYzQyLTYwOWJkZmI1MzBiOCIsImp0aSI6IjU2Y2ZkZjAxLWRhMzMtNGUxNi04MzJiLTFlYTk3ZGY1MTQ2YSJ9.5iUgaCaFVPZ8d1QD0xMjoeJbmPVyUfKfoRQ6Njzm5MLp5F4UMh5REbPCrW70fAkr'
faker.internet.jwt({ payload: { iss: 'Acme' }}) // 'eyJhbGciOiJFUzM4NCIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJBY21lIn0.syUt0GBukNac8Cn1AGKFq2SWAXWy1YIfl0uOYiwg6TZ3omAW0c7FGWY6bC7ZOFSt'
faker.internet.jwt({ refDate: '2020-01-01T00:00:00.000Z' }) // 'eyJhbGciOiJFUzM4NCIsInR5cCI6IkpXVCJ9.eyJpYXQiOjE1Nzc4MDY4NDUsImV4cCI6MTU3Nzg0NjI4MCwibmJmIjoxNTgxNTQyMDYwLCJpc3MiOiJLcmVpZ2VyLCBBbHRlbndlcnRoIGFuZCBQYXVjZWsiLCJzdWIiOiI5NzVjMjMyOS02MDlhLTRjYTYtYjBkZi05ZmY4MGZiNDUwN2QiLCJhdWQiOiI0ODQxZWYwNi01OWYwLTQzMWEtYmFmZi0xMjkxZmRhZDdhNjgiLCJqdGkiOiJmNDBjZTJiYi00ZWYyLTQ1MjMtOGIxMy1kN2Q4NTA5N2M2ZTUifQ.cuClEZQ0CyPIMVS5uxrMwWXz0wcqFFdt0oNne3PMryyly0jghkxVurss2TapMC3C'
See Also
Source
jwtAlgorithm
Generates a random JWT (JSON Web Token) Algorithm.
Available since v9.1.0
Returns: string
function jwtAlgorithm(): string;
Examples
faker.internet.jwtAlgorithm() // 'HS256'
faker.internet.jwtAlgorithm() // 'RS512'
Source
mac
Generates a random mac address.
Available since v3.0.0
Parameters
Name | Type | Default | Description |
---|---|---|---|
options? | string | { ... } | {} | The optional separator or an options object. |
options.separator? | string | ':' | The optional separator to use. Can be either |
Returns: string
function mac(
options?:
| string
| {
separator?: string;
}
): string;
Examples
faker.internet.mac() // '32:8e:2e:09:c6:05'
Source
password
Generates a random password-like string. Do not use this method for generating actual passwords for users. Since the source of the randomness is not cryptographically secure, neither is this generator.
Available since v2.0.1
Parameters
Name | Type | Default | Description |
---|---|---|---|
options | { ... } | {} | An options object. |
options.length? | number | 15 | The length of the password to generate. |
options.memorable? | boolean | false | Whether the generated password should be memorable. |
options.pattern? | RegExp | /\w/ | The pattern that all chars should match.
This option will be ignored, if |
options.prefix? | string | '' | The prefix to use. |
Returns: string
function password(
options: {
length?: number;
memorable?: boolean;
pattern?: RegExp;
prefix?: string;
} = {}
): string;
Examples
faker.internet.password() // '89G1wJuBLbGziIs'
faker.internet.password({ length: 20 }) // 'aF55c_8O9kZaPOrysFB_'
faker.internet.password({ length: 20, memorable: true }) // 'lawetimufozujosodedi'
faker.internet.password({ length: 20, memorable: true, pattern: /[A-Z]/ }) // 'HMAQDFFYLDDUTBKVNFVS'
faker.internet.password({ length: 20, memorable: true, pattern: /[A-Z]/, prefix: 'Hello ' }) // 'Hello IREOXTDWPERQSB'
Source
port
Generates a random port number.
Available since v5.4.0
Returns: number
function port(): number;
Examples
faker.internet.port() // '9414'
Source
protocol
Returns a random web protocol. Either http
or https
.
Available since v2.1.5
Returns: 'http' | 'https'
function protocol(): 'http' | 'https';
Examples
faker.internet.protocol() // 'http'
faker.internet.protocol() // 'https'
Source
url
Generates a random http(s) url.
Available since v2.1.5
Parameters
Name | Type | Default | Description |
---|---|---|---|
options | { ... } | {} | Optional options object. |
options.appendSlash? | boolean | faker.datatype.boolean() | Whether to append a slash to the end of the url (path). |
options.protocol? | HTTPProtocolType | 'https' | The protocol to use. |
Returns: string
function url(
options: {
appendSlash?: boolean;
protocol?: HTTPProtocolType;
} = {}
): string;
Examples
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'
Source
userAgent
Generates a random user agent string.
Available since v2.0.1
Returns: string
function userAgent(): string;
Examples
faker.internet.userAgent()
// 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_8_8) AppleWebKit/536.0.2 (KHTML, like Gecko) Chrome/27.0.849.0 Safari/536.0.2'
Source
username
Generates a username using the given person's name as base. The resulting username may use neither, one or both of the names provided. This will always return a plain ASCII string. Some basic stripping of accents and transliteration of characters will be done.
Available since v9.1.0
Parameters
Name | Type | Default | Description |
---|---|---|---|
options | { ... } | {} | An options object. |
options.firstName? | string | faker.person.firstName() | The optional first name to use. |
options.lastName? | string | faker.person.lastName() | The optional last name to use. |
Returns: string
function username(
options: {
firstName?: string;
lastName?: string;
} = {}
): string;
Examples
faker.internet.username() // 'Nettie_Zboncak40'
faker.internet.username({ firstName: 'Jeanne' }) // 'Jeanne98'
faker.internet.username({ firstName: 'Jeanne' }) // 'Jeanne.Smith98'
faker.internet.username({ firstName: 'Jeanne', lastName: 'Doe'}) // 'Jeanne_Doe98'
faker.internet.username({ firstName: 'John', lastName: 'Doe' }) // 'John.Doe'
faker.internet.username({ firstName: 'Hélene', lastName: 'Müller' }) // 'Helene_Muller11'
faker.internet.username({ firstName: 'Фёдор', lastName: 'Достоевский' }) // 'Fedor.Dostoevskii50'
faker.internet.username({ firstName: '大羽', lastName: '陳' }) // 'hlzp8d.tpv45' - note neither name is used
Source
userName
Deprecated
This method is deprecated and will be removed in a future version.
Use faker.internet.username()
instead.
Generates a username using the given person's name as base. The resulting username may use neither, one or both of the names provided. This will always return a plain ASCII string. Some basic stripping of accents and transliteration of characters will be done.
Available since v2.0.1
Parameters
Name | Type | Default | Description |
---|---|---|---|
options | { ... } | {} | An options object. |
options.firstName? | string | faker.person.firstName() | The optional first name to use. |
options.lastName? | string | faker.person.lastName() | The optional last name to use. |
Returns: string
function userName(
options: {
firstName?: string;
lastName?: string;
} = {}
): string;
Examples
faker.internet.userName() // 'Nettie_Zboncak40'
faker.internet.userName({ firstName: 'Jeanne' }) // 'Jeanne98'
faker.internet.userName({ firstName: 'Jeanne' }) // 'Jeanne.Smith98'
faker.internet.userName({ firstName: 'Jeanne', lastName: 'Doe'}) // 'Jeanne_Doe98'
faker.internet.userName({ firstName: 'John', lastName: 'Doe' }) // 'John.Doe'
faker.internet.userName({ firstName: 'Hélene', lastName: 'Müller' }) // 'Helene_Muller11'
faker.internet.userName({ firstName: 'Фёдор', lastName: 'Достоевский' }) // 'Fedor.Dostoevskii50'
faker.internet.userName({ firstName: '大羽', lastName: '陳' }) // 'hlzp8d.tpv45' - note neither name is used