Kreya base script API reference
The following Kreya APIs are available in all Kreya scripts and Kreya operation scripts under the kreya
namespace.
These can be accessed directly through the kreya
object:
kreya.trace('Hello world!');
Variables
environment
const environment: EnvironmentContainerScriptApi;
EnvironmentContainerScriptApi
Gets APIs related to the Kreya environment.
faker
const faker: FakerScriptApi;
FakerScriptApi
The faker API to generate fake data.
variables
const variables: UserVariablesScriptApi;
UserVariablesScriptApi
Gets the storage to set and retrieve custom variables, which are accessible in other operations and via templating.
Functions
sleep()
function sleep(millisecondsTimeout: number): void;
Sleeps for a certain length of time.
Parameters
Parameter | Type | Description |
---|---|---|
millisecondsTimeout | number | Milliseconds to sleep. |
Returns
void
test()
Call Signature
function test(name: string, callback: () => Promise<void>): Promise<void>;
Runs a test.
Parameters
Parameter | Type | Description |
---|---|---|
name | string | A descriptive name of the test. |
callback | () => Promise <void > | The test code. |
Returns
Promise
<void
>
Call Signature
function test(name: string, callback: () => void): void;
Runs a test.
Parameters
Parameter | Type | Description |
---|---|---|
name | string | A descriptive name of the test. |
callback | () => void | The test code. |
Returns
void
trace()
function trace(message: any): void;
Adds a trace message to the Kreya trace log.
Parameters
Parameter | Type | Description |
---|---|---|
message | any | The message to log. |
Returns
void
Type Aliases
EnvironmentContainerScriptApi
type EnvironmentContainerScriptApi = {
active: EnvironmentScriptApi;
};
APIs related to the Kreya environment.
Properties
active
readonly active: EnvironmentScriptApi;
Access to the active Kreya environment.
EnvironmentScriptApi
type EnvironmentScriptApi = {
content: {
};
id: string;
name: string;
};
APIs to access the environment.
Properties
content
readonly content: {
};
Gets the content JSON of the environment.
id
readonly id: string;
Gets the unique id of the environment.
name
readonly name: string;
Gets the name of the environment.
FakerAddress
type FakerAddress = {
locale: string;
random: FakerRandomizer;
buildingNumber: string;
cardinalDirection: string;
city: string;
cityPrefix: string;
citySuffix: string;
country: string;
countryCode: string;
county: string;
direction: string;
fullAddress: string;
latitude: number;
longitude: number;
ordinalDirection: string;
secondaryAddress: string;
state: string;
stateAbbr: string;
streetAddress: string;
streetName: string;
streetSuffix: string;
zipCode: string;
};
Methods for generating an address.
Properties
locale
locale: string;
random
random: FakerRandomizer;
Methods
buildingNumber()
buildingNumber(): string;
Get a building number.
Returns
string
A random building number.
cardinalDirection()
cardinalDirection(useAbbreviation?: boolean): string;
Generates a cardinal direction. IE: North, South, E, W.
Parameters
Parameter | Type | Description |
---|---|---|
useAbbreviation ? | boolean | When true, directions such as West turn into W. |
Returns
string
A random cardinal direction
city()
city(): string;
Get a city name.
Returns
string
A random city name.
cityPrefix()
cityPrefix(): string;
Get a city prefix.
Returns
string
A random city prefix.
citySuffix()
citySuffix(): string;
Get a city suffix.
Returns
string
A random city suffix.
country()
country(): string;
Get a country.
Returns
string
A random country.
countryCode()
countryCode(): string;
Get a random ISO 3166-1 country code.
Returns
string
A random country code.
county()
county(): string;
Get a county.
Returns
string
A random county.
direction()
direction(useAbbreviation?: boolean): string;
Generates a cardinal or ordinal direction. IE: Northwest, South, SW, E.
Parameters
Parameter | Type | Description |
---|---|---|
useAbbreviation ? | boolean | When true, directions such as Northwest turn into NW. |
Returns
string
A random cardinal or ordinal direction.
fullAddress()
fullAddress(): string;
Get a full address like Street, City, Country.
Returns
string
A random full address.
latitude()
latitude(min?: number, max?: number): number;
Get a Latitude.
Parameters
Parameter | Type | Description |
---|---|---|
min ? | number | The minimum value. |
max ? | number | The maximum value. |
Returns
number
A random latitude value.
longitude()
longitude(min?: number, max?: number): number;
Get a Longitude.
Parameters
Parameter | Type | Description |
---|---|---|
min ? | number | The minimum value. |
max ? | number | The maximum value. |
Returns
number
A random longitude value.
ordinalDirection()
ordinalDirection(useAbbreviation?: boolean): string;
Generates an ordinal direction. IE: Northwest, Southeast, SW, NE.
Parameters
Parameter | Type | Description |
---|---|---|
useAbbreviation ? | boolean | When true, directions such as Northwest turn into NW. |
Returns
string
A random ordinal direction.
secondaryAddress()
secondaryAddress(): string;
Get a secondary address like 'Apt. 2' or 'Suite 321'.
Returns
string
A random secondary address.
state()
state(): string;
Get a random state state.
Returns
string
A random state.
stateAbbr()
stateAbbr(): string;
Get a state abbreviation.
Returns
string
An abbreviation for a random state.
streetAddress()
streetAddress(useFullAddress?: boolean): string;
Get a street address.
Parameters
Parameter | Type | Description |
---|---|---|
useFullAddress ? | boolean | . |
Returns
string
A random street address.
streetName()
streetName(): string;
Get a street name.
Returns
string
A random street name.
streetSuffix()
streetSuffix(): string;
Get a street suffix.
Returns
string
A random street suffix.
zipCode()
zipCode(format?: string): string;
Get a zipcode.
Parameters
Parameter | Type | Description |
---|---|---|
format ? | string | If a format is provided it will fill the format with letters and numbers. Example "???? ##" can become "QYTE 78". |
Returns
string
A random zipcode.
FakerCommerce
type FakerCommerce = {
locale: string;
random: FakerRandomizer;
categories: string[];
color: string;
department: string;
ean13: string;
ean8: string;
price: string;
product: string;
productAdjective: string;
productDescription: string;
productMaterial: string;
productName: string;
};
Methods relating to commerce.
Properties
locale
locale: string;
random
random: FakerRandomizer;
Methods
categories()
categories(num: number): string[];
Get random product categories.
Parameters
Parameter | Type | Description |
---|---|---|
num | number | The amount of categories to be generated. |
Returns
string
[]
A collection of random product categories.
color()
color(): string;
Get a random color.
Returns
string
A random color.
department()
department(max?: number, returnMax?: boolean): string;
Get a random commerce department.
Parameters
Parameter | Type | Description |
---|---|---|
max ? | number | The maximum amount of departments |
returnMax ? | boolean | If true the method returns the max amount of values, otherwise the number of categories returned is between 1 and max. |
Returns
string
A random commerce department.
ean13()
ean13(): string;
Get a random EAN-13 barcode number.
Returns
string
A random EAN-13 barcode number.
ean8()
ean8(): string;
Get a random EAN-8 barcode number.
Returns
string
A random EAN-8 barcode number.
price()
price(
min?: number,
max?: number,
decimals?: number,
symbol?: string): string;
Get a random product price.
Parameters
Parameter | Type | Description |
---|---|---|
min ? | number | The minimum price. |
max ? | number | The maximum price. |
decimals ? | number | How many decimals the number may include. |
symbol ? | string | The symbol in front of the price. |
Returns
string
A randomly generated price.
product()
product(): string;
Get a random product.
Returns
string
A random product.
productAdjective()
productAdjective(): string;
Random product adjective.
Returns
string
A random product adjective.
productDescription()
productDescription(): string;
Random product description.
Returns
string
A random product description.
productMaterial()
productMaterial(): string;
Random product material.
Returns
string
A random product material.
productName()
productName(): string;
Get a random product name.
Returns
string
A random product name.
FakerCompany
type FakerCompany = {
locale: string;
random: FakerRandomizer;
bs: string;
catchPhrase: string;
companyName: string;
companySuffix: string;
};
Generates a random company name and phrases
Properties
locale
locale: string;
random
random: FakerRandomizer;
Methods
bs()
bs(): string;
Get a company BS phrase.
Returns
string
A random company BS phrase.
catchPhrase()
catchPhrase(): string;
Get a company catch phrase.
Returns
string
A random company catch phrase.
companyName()
Call Signature
companyName(formatIndex?: number): string;
Get a company name.
Parameters
Parameter | Type | Description |
---|---|---|
formatIndex ? | number | 0: name + suffix, 1: name-name, 2: name, name and name." |
Returns
string
A random company name.
Call Signature
companyName(format: string): string;
Get a company name. The format can use any name.* and company.* methods.
Parameters
Parameter | Type | Description |
---|---|---|
format | string | Example: "{{name.lastName}} {{company.companySuffix}}" |
Returns
string
A random company name in the given format.
companySuffix()
companySuffix(): string;
Get a company suffix. "Inc" and "LLC" etc.
Returns
string
A random company suffix.
FakerCurrency
type FakerCurrency = {
code: string;
description: string;
symbol: string;
};
Represents a currency
Properties
code
code: string;
The currency code. IE: USD.
description
description: string;
The long for description of the currency. IE: "US Dollar"
symbol
symbol: string;
The currency symbol. IE: $
FakerDatabase
type FakerDatabase = {
locale: string;
random: FakerRandomizer;
collation: string;
column: string;
engine: string;
type: string;
};
Generates some random database stuff.
Properties
locale
locale: string;
random
random: FakerRandomizer;
Methods
collation()
collation(): string;
Generates a collation.
Returns
string
A random collation.
column()
column(): string;
Generates a column name.
Returns
string
A random column name.
engine()
engine(): string;
Generates a storage engine.
Returns
string
A random storage engine.
type()
type(): string;
Generates a column type.
Returns
string
A random column type.
FakerDate
type FakerDate = {
locale: string;
random: FakerRandomizer;
between: Date;
future: Date;
month: string;
past: Date;
recent: Date;
soon: Date;
timeZoneString: string;
weekday: string;
};
Methods for generating dates
Properties
locale
locale: string;
random
random: FakerRandomizer;
Methods
between()
between(start: Date, end: Date): Date;
Get a random DateTime
between start
and end
.
Parameters
Parameter | Type | Description |
---|---|---|
start | Date | is used from this parameter. |
end | Date | End time |
Returns
Date
future()
future(yearsToGoForward?: number, refDate?: Date): Date;
Get a DateTime
in the future between refDate
and yearsToGoForward
.
Parameters
Parameter | Type | Description |
---|---|---|
yearsToGoForward ? | number | . Default is 1 year. |
refDate ? | Date | . |
Returns
Date
month()
month(abbreviation?: boolean, useContext?: boolean): string;
Get a random month.
Parameters
Parameter | Type | Description |
---|---|---|
abbreviation ? | boolean | |
useContext ? | boolean |
Returns
string
past()
past(yearsToGoBack?: number, refDate?: Date): Date;
Get a DateTime
in the past between refDate
and yearsToGoBack
.
Parameters
Parameter | Type | Description |
---|---|---|
yearsToGoBack ? | number | . Default is 1 year. |
refDate ? | Date | . |
Returns
Date
recent()
recent(days?: number, refDate?: Date): Date;
Get a random DateTime
within the last few days.
Parameters
Parameter | Type | Description |
---|---|---|
days ? | number | Number of days to go back. |
refDate ? | Date | . |
Returns
Date
soon()
soon(days?: number, refDate?: Date): Date;
Get a DateTime
that will happen soon.
Parameters
Parameter | Type | Description |
---|---|---|
days ? | number | ahead. |
refDate ? | Date | . |
Returns
Date
timeZoneString()
timeZoneString(): string;
Get a timezone string. Eg: America/Los_Angeles
Returns
string
weekday()
weekday(abbreviation?: boolean, useContext?: boolean): string;
Get a random weekday.
Parameters
Parameter | Type | Description |
---|---|---|
abbreviation ? | boolean | |
useContext ? | boolean |
Returns
string
FakerFinance
type FakerFinance = {
locale: string;
random: FakerRandomizer;
account: string;
accountName: string;
amount: number;
bic: string;
bitcoinAddress: string;
creditCardCvv: string;
currency: FakerCurrency;
ethereumAddress: string;
iban: string;
litecoinAddress: string;
routingNumber: string;
transactionType: string;
};
Provides financial randomness.
Properties
locale
locale: string;
random
random: FakerRandomizer;
Methods
account()
account(length?: number): string;
Get an account number. Default length is 8 digits.
Parameters
Parameter | Type | Description |
---|---|---|
length ? | number | The length of the account number. |
Returns
string
accountName()
accountName(): string;
Get an account name. Like "savings", "checking", "Home Loan" etc..
Returns
string
amount()
amount(
min?: number,
max?: number,
decimals?: number): number;
Get a random amount. Default 0 - 1000.
Parameters
Parameter | Type | Description |
---|---|---|
min ? | number | Min value. Default 0. |
max ? | number | Max value. Default 1000. |
decimals ? | number | Decimal places. Default 2. |
Returns
number
bic()
bic(): string;
Generates Bank Identifier Code (BIC) code.
Returns
string
bitcoinAddress()
bitcoinAddress(): string;
Generates a random Bitcoin address.
Returns
string
creditCardCvv()
creditCardCvv(): string;
Generate a credit card CVV.
Returns
string
currency()
currency(includeFundCodes?: boolean): FakerCurrency;
Get a random currency.
Parameters
Parameter | Type | Description |
---|---|---|
includeFundCodes ? | boolean |
Returns
ethereumAddress()
ethereumAddress(): string;
Generate a random Ethereum address.
Returns
string
iban()
iban(formatted?: boolean, countryCode?: string): string;
Generates an International Bank Account Number (IBAN).
Parameters
Parameter | Type | Description |
---|---|---|
formatted ? | boolean | Formatted IBAN containing spaces. |
countryCode ? | string | A two letter ISO3166 country code. Throws an exception if the country code is not found or is an invalid length. |
Returns
string
litecoinAddress()
litecoinAddress(): string;
Generate a random Litecoin address.
Returns
string
routingNumber()
routingNumber(): string;
Generates an ABA routing number with valid check digit.
Returns
string
transactionType()
transactionType(): string;
Get a transaction type: "deposit", "withdrawal", "payment", or "invoice".
Returns
string
FakerHacker
type FakerHacker = {
locale: string;
random: FakerRandomizer;
abbreviation: string;
adjective: string;
ingVerb: string;
noun: string;
phrase: string;
verb: string;
};
Hackerish words
Properties
locale
locale: string;
random
random: FakerRandomizer;
Methods
abbreviation()
abbreviation(): string;
Returns an abbreviation.
Returns
string
A random abbreviation.
adjective()
adjective(): string;
Returns a adjective.
Returns
string
A random adjective.
ingVerb()
ingVerb(): string;
Returns a verb ending with -ing.
Returns
string
A random -ing verb.
noun()
noun(): string;
Returns a noun.
Returns
string
A random noun.
phrase()
phrase(): string;
Returns a phrase.
Returns
string
A random phrase.
verb()
verb(): string;
Returns a verb.
Returns
string
A random verb.
FakerImages
type FakerImages = {
locale: string;
random: FakerRandomizer;
dataUri: string;
loremFlickrUrl: string;
picsumUrl: string;
placeholderUrl: string;
placeImgUrl: string;
};
Generates images URLs.
Properties
locale
locale: string;
random
random: FakerRandomizer;
Methods
dataUri()
dataUri(
width: number,
height: number,
htmlColor?: string): string;
Get a SVG data URI image with a specific width and height.
Parameters
Parameter | Type | Description |
---|---|---|
width | number | Width of the image. |
height | number | Height of the image. |
htmlColor ? | string | An html color in named format 'grey', RGB format 'rgb(r,g,b)', or hex format '#888888'. |
Returns
string
loremFlickrUrl()
loremFlickrUrl(
width?: number,
height?: number,
keywords?: string,
grascale?: boolean,
matchAllKeywords?: boolean,
lockId?: number): string;
Get an image from https://loremflickr.com service.
Parameters
Parameter | Type | Description |
---|---|---|
width ? | number | The image width. |
height ? | number | The image height. |
keywords ? | string | Space or comma delimited list of keywords you want the picture to contain. IE: "cat, dog" for images with cats and dogs. |
grascale ? | boolean | Grayscale the image. |
matchAllKeywords ? | boolean | True tries to match an image with all specified keywords. False tries to match an image with any specified keyword. |
lockId ? | number | Deterministic image id. By default, this method generates URLs with image lock ids. So, if a random seed is set, repeat runs of this method will generate the same lock id sequence for images. If you want explicit control over the lock id, you can pass it as a parameter here. Additionally, if you don't want any lock ids, pass -1 for this parameter this method will generate a URL that will result in a new random image every time the HTTP URL is hit. |
Returns
string
picsumUrl()
picsumUrl(
width?: number,
height?: number,
grayscale?: boolean,
blur?: boolean,
imageId?: number): string;
Get an image from the https://picsum.photos service.
Parameters
Parameter | Type | Description |
---|---|---|
width ? | number | Width of the image. |
height ? | number | Height of the image. |
grayscale ? | boolean | Grayscale (no color) image. |
blur ? | boolean | Blurry image. |
imageId ? | number | Optional Image ID found here https://picsum.photos/images |
Returns
string
placeholderUrl()
placeholderUrl(
width: number,
height: number,
text?: string,
backColor?: string,
textColor?: string,
format?: string): string;
Get an image from https://placeholder.com service.
Parameters
Parameter | Type | Description |
---|---|---|
width | number | Width of the image. |
height | number | Height of the image. |
text ? | string | |
backColor ? | string | HTML color code for the background color. |
textColor ? | string | HTML color code for the foreground (text) color. |
format ? | string | Image format. Supported values: 'jpg', 'jpeg', 'png', 'gif', 'webp'. |
Returns
string
placeImgUrl()
placeImgUrl(
width?: number,
height?: number,
category?: string): string;
Get an image from the https://placeimg.com service.
Parameters
Parameter | Type | Description |
---|---|---|
width ? | number | Width of the image. |
height ? | number | Height of the image. |
category ? | string | for string categories. |
Returns
string
FakerInternet
type FakerInternet = {
locale: string;
random: FakerRandomizer;
avatar: string;
color: string;
domainName: string;
domainSuffix: string;
domainWord: string;
email: string;
exampleEmail: string;
ip: string;
ipv6: string;
mac: string;
password: string;
port: number;
protocol: string;
url: string;
urlRootedPath: string;
urlWithPath: string;
userAgent: string;
userName: string;
userNameUnicode: string;
};
Random Internet things like email addresses
Properties
locale
locale: string;
random
random: FakerRandomizer;
Methods
avatar()
avatar(): string;
Generates a legit Internet URL avatar from twitter accounts.
Returns
string
A string containing a URL avatar from twitter accounts.
color()
color(
baseRed?: number,
baseGreen?: number,
baseBlue?: number,
grayscale?: boolean): string;
Gets a random aesthetically pleasing color near the base RGB. See here.
Parameters
Parameter | Type | Description |
---|---|---|
baseRed ? | number | Red base color |
baseGreen ? | number | Green base color |
baseBlue ? | number | Blue base color |
grayscale ? | boolean | Output a gray scale color |
Returns
string
A random color.
domainName()
domainName(): string;
Generates a random domain name.
Returns
string
A random domain name.
domainSuffix()
domainSuffix(): string;
Generates a domain name suffix like .com, .net, .org
Returns
string
A random domain suffix.
domainWord()
domainWord(): string;
Generates a domain word used for domain names.
Returns
string
A random domain word.
email()
email(
firstName?: string,
lastName?: string,
provider?: string,
uniqueSuffix?: string): string;
Generates an email address.
Parameters
Parameter | Type | Description |
---|---|---|
firstName ? | string | Always use this first name. |
lastName ? | string | Sometimes used depending on randomness. See 'UserName'. |
provider ? | string | Always use the provider. |
uniqueSuffix ? | string | value each time before calling this method to ensure that email accounts that are generated are totally unique. |
Returns
string
An email address
exampleEmail()
exampleEmail(firstName?: string, lastName?: string): string;
Generates an example email with @example.com.
Parameters
Parameter | Type | Description |
---|---|---|
firstName ? | string | Optional: first name of the user. |
lastName ? | string | Optional: last name of the user. |
Returns
string
An example email ending with @example.com.
ip()
ip(): string;
Gets a random IPv4 address string.
Returns
string
A random IPv4 address.
ipv6()
ipv6(): string;
Generates a random IPv6 address string.
Returns
string
A random IPv6 address.
mac()
mac(separator?: string): string;
Gets a random mac address.
Parameters
Parameter | Type | Description |
---|---|---|
separator ? | string | The string the mac address should be separated with. |
Returns
string
A random mac address.
password()
password(
length?: number,
memorable?: boolean,
regexPattern?: string,
prefix?: string): string;
Generates a random password.
Parameters
Parameter | Type | Description |
---|---|---|
length ? | number | Length of the password. |
memorable ? | boolean | A memorable password (ie: all lower case). |
regexPattern ? | string | Regex pattern that the password should follow. |
prefix ? | string | Password prefix. |
Returns
string
A random password.
port()
port(): number;
Generates a random port number.
Returns
number
A random port number
protocol()
protocol(): string;
Returns a random protocol. HTTP or HTTPS.
Returns
string
A random protocol.
url()
url(): string;
Generates a random URL.
Returns
string
A random URL.
urlRootedPath()
urlRootedPath(fileExt?: string): string;
Get a rooted URL path like: /foo/bar. Optionally with file extension.
Parameters
Parameter | Type | Description |
---|---|---|
fileExt ? | string | is null, then a rooted URL directory is returned. |
Returns
string
Returns a rooted URL path like: /foo/bar; optionally with a file extension.
urlWithPath()
urlWithPath(
protocol?: string,
domain?: string,
fileExt?: string): string;
Get an absolute URL with random path.
Parameters
Parameter | Type | Description |
---|---|---|
protocol ? | string | Protocol part of the URL, random if null |
domain ? | string | Domain part of the URL, random if null |
fileExt ? | string | The file extension to use in the path, directory if null |
Returns
string
An URL with a random path.
userAgent()
userAgent(): string;
Generates a random user agent.
Returns
string
A random user agent.
userName()
userName(firstName?: string, lastName?: string): string;
Generates user names.
Parameters
Parameter | Type | Description |
---|---|---|
firstName ? | string | First name is always part of the returned user name. |
lastName ? | string | Last name may or may not be used. |
Returns
string
A random user name.
userNameUnicode()
userNameUnicode(firstName?: string, lastName?: string): string;
Generates a user name preserving Unicode characters.
Parameters
Parameter | Type | Description |
---|---|---|
firstName ? | string | First name is always part of the returned user name. |
lastName ? | string | Last name may or may not be used. |
Returns
string
FakerLorem
type FakerLorem = {
locale: string;
random: FakerRandomizer;
letter: string;
lines: string;
paragraph: string;
paragraphs: string;
sentence: string;
sentences: string;
slug: string;
text: string;
word: string;
words: string[];
};
Generates plain old boring text.
Properties
locale
locale: string;
random
random: FakerRandomizer;
Methods
letter()
letter(num?: number): string;
Get a character letter.
Parameters
Parameter | Type | Description |
---|---|---|
num ? | number | The number of characters to return. |
Returns
string
lines()
lines(lineCount?: number, separator?: string): string;
Get lines of lorem.
Parameters
Parameter | Type | Description |
---|---|---|
lineCount ? | number | The amount of lines to generate. Defaults between 1 and 5. |
separator ? | string | The string to separate the lines. |
Returns
string
paragraph()
paragraph(min?: number): string;
Get a paragraph.
Parameters
Parameter | Type | Description |
---|---|---|
min ? | number | method. |
Returns
string
paragraphs()
Call Signature
paragraphs(count?: number, separator?: string): string;
Get a specified number of paragraphs.
Parameters
Parameter | Type | Description |
---|---|---|
count ? | number | Number of paragraphs. |
separator ? | string | The string to separate paragraphs. |
Returns
string
Call Signature
paragraphs(
min: number,
max: number,
separator?: string): string;
Get a random number of paragraphs between min
and max
.
Parameters
Parameter | Type | Description |
---|---|---|
min | number | Minimum number of paragraphs. |
max | number | Maximum number of paragraphs. |
separator ? | string | The string to separate the paragraphs. |
Returns
string
sentence()
sentence(wordCount?: number, range?: number): string;
Get a random sentence of specific number of words.
Parameters
Parameter | Type | Description |
---|---|---|
wordCount ? | number | Get a sentence with wordCount words. Defaults between 3 and 10. |
range ? | number | Add anywhere between 0 to 'range' additional words to wordCount. Default is 0. |
Returns
string
sentences()
sentences(sentenceCount?: number, separator?: string): string;
Get some sentences.
Parameters
Parameter | Type | Description |
---|---|---|
sentenceCount ? | number | The number of sentences. |
separator ? | string | The string to separate sentences. |
Returns
string
slug()
slug(wordcount?: number): string;
Slugify lorem words.
Parameters
Parameter | Type | Description |
---|---|---|
wordcount ? | number | The amount of words to slugify. |
Returns
string
text()
text(): string;
Get random text on a random lorem methods.
Returns
string
word()
word(): string;
Get a random lorem word.
Returns
string
words()
words(num?: number): string[];
Get an array of random lorem words.
Parameters
Parameter | Type | Description |
---|---|---|
num ? | number | The number of random lorem words to return. |
Returns
string
[]
FakerMusic
type FakerMusic = {
locale: string;
random: FakerRandomizer;
genre: string;
};
Properties
locale
locale: string;
random
random: FakerRandomizer;
Methods
genre()
genre(): string;
Get a music genre
Returns
string
FakerName
type FakerName = {
item: FakerName;
locale: string;
random: FakerRandomizer;
findName: string;
firstName: string;
fullName: string;
jobArea: string;
jobDescriptor: string;
jobTitle: string;
jobType: string;
lastName: string;
prefix: string;
suffix: string;
};
Methods for generating names
Properties
item
readonly item: FakerName;
locale
locale: string;
random
random: FakerRandomizer;
Methods
findName()
findName(
firstName?: string,
lastName?: string,
withPrefix?: boolean,
withSuffix?: boolean): string;
Parameters
Parameter | Type |
---|---|
firstName ? | string |
lastName ? | string |
withPrefix ? | boolean |
withSuffix ? | boolean |
Returns
string
firstName()
firstName(): string;
Returns
string
fullName()
fullName(): string;
Returns
string
jobArea()
jobArea(): string;
Get a job area expertise.
Returns
string
jobDescriptor()
jobDescriptor(): string;
Get a job description.
Returns
string
jobTitle()
jobTitle(): string;
Gets a random job title.
Returns
string
jobType()
jobType(): string;
Get a type of job.
Returns
string
lastName()
lastName(): string;
Returns
string
prefix()
prefix(): string;
Returns
string
suffix()
suffix(): string;
Gets a random suffix for a name.
Returns
string
FakerPhoneNumbers
type FakerPhoneNumbers = {
locale: string;
random: FakerRandomizer;
phoneNumber: string;
phoneNumberFormat: string;
};
Generates phone numbers
Properties
locale
locale: string;
random
random: FakerRandomizer;
Methods
phoneNumber()
phoneNumber(format?: string): string;
Get a phone number.
Parameters
Parameter | Type | Description |
---|---|---|
format ? | string | Format of phone number in any format. Replaces # characters with numbers. IE: '###-###-####' or '(###) ###-####'. |
Returns
string
A random phone number.
phoneNumberFormat()
phoneNumberFormat(phoneFormatsArrayIndex?: number): string;
Gets a phone number based on the locale's phone_number.formats[] array index.
Parameters
Parameter | Type | Description |
---|---|---|
phoneFormatsArrayIndex ? | number | The array index as defined in the locale's phone_number.formats[] array. |
Returns
string
A random phone number.
FakerRandomizer
type FakerRandomizer = {
alphaNumeric: string;
bool: boolean;
byte: number;
bytes: Uint8Array;
char: string;
chars: string[];
clampString: string;
decimal: number;
digits: number[];
double: number;
even: number;
float: number;
guid: Guid;
hash: string;
hexadecimal: string;
int: number;
long: number;
number: number;
odd: number;
randomLocale: string;
replace: string;
replaceNumbers: string;
replaceSymbols: string;
sByte: number;
short: number;
string: string;
string2: string;
uInt: number;
uLong: number;
uShort: number;
utf16String: string;
uuid: Guid;
word: string;
words: string;
wordsArray: string[];
};
A randomizer that randomizes things.
Methods
alphaNumeric()
alphaNumeric(length: number): string;
Returns a random set of alpha numeric characters 0-9, a-z.
Parameters
Parameter | Type | Description |
---|---|---|
length | number |
Returns
string
bool()
Call Signature
bool(): boolean;
Get a random boolean.
Returns
boolean
Call Signature
bool(weight: number): boolean;
Get a random boolean.
Parameters
Parameter | Type | Description |
---|---|---|
weight | number | The probability of true. Ranges from 0 to 1. |
Returns
boolean
byte()
byte(min?: number, max?: number): number;
Generate a random byte between 0 and 255.
Parameters
Parameter | Type | Description |
---|---|---|
min ? | number | Min value, inclusive. Default byte.MinValue 0 |
max ? | number | Max value, inclusive. Default byte.MaxValue 255 |
Returns
number
bytes()
bytes(count: number): Uint8Array;
Get a random sequence of bytes.
Parameters
Parameter | Type | Description |
---|---|---|
count | number | The size of the byte array |
Returns
Uint8Array
char()
char(min?: string, max?: string): string;
Generate a random char between MinValue and MaxValue.
Parameters
Parameter | Type | Description |
---|---|---|
min ? | string | Min value, inclusive. Default char.MinValue |
max ? | string | Max value, inclusive. Default char.MaxValue |
Returns
string
chars()
chars(
min?: string,
max?: string,
count?: number): string[];
Generate a random chars between MinValue and MaxValue.
Parameters
Parameter | Type | Description |
---|---|---|
min ? | string | Min value, inclusive. Default char.MinValue |
max ? | string | Max value, inclusive. Default char.MaxValue |
count ? | number | The length of chars to return |
Returns
string
[]
clampString()
clampString(
str: string,
min?: number,
max?: number): string;
Clamps the length of a string between min and max characters. If the string is below the minimum, the string is appended with random characters up to the minimum length. If the string is over the maximum, the string is truncated at maximum characters; additionally, if the result string ends with whitespace, it is replaced with a random characters.
Parameters
Parameter | Type | Description |
---|---|---|
str | string | |
min ? | number | |
max ? | number |
Returns
string
decimal()
decimal(min?: number, max?: number): number;
Get a random decimal, between 0.0 and 1.0.
Parameters
Parameter | Type | Description |
---|---|---|
min ? | number | Minimum, inclusive. Default 0.0 |
max ? | number | Maximum, exclusive. Default 1.0 |
Returns
number
digits()
digits(
count: number,
minDigit?: number,
maxDigit?: number): number[];
Get a random sequence of digits.
Parameters
Parameter | Type | Description |
---|---|---|
count | number | How many |
minDigit ? | number | minimum digit, inclusive |
maxDigit ? | number | maximum digit, inclusive |
Returns
number
[]
double()
double(min?: number, max?: number): number;
Get a random double, between 0.0 and 1.0.
Parameters
Parameter | Type | Description |
---|---|---|
min ? | number | Minimum, inclusive. Default 0.0 |
max ? | number | Maximum, exclusive. Default 1.0 |
Returns
number
even()
even(min?: number, max?: number): number;
Returns a random even number. If the range does not contain any even numbers, an ArgumentException
is thrown.
Parameters
Parameter | Type | Description |
---|---|---|
min ? | number | Lower bound, inclusive |
max ? | number | Upper bound, inclusive |
Returns
number
float()
float(min?: number, max?: number): number;
Get a random float, between 0.0 and 1.0.
Parameters
Parameter | Type | Description |
---|---|---|
min ? | number | Minimum, inclusive. Default 0.0 |
max ? | number | Maximum, inclusive. Default 1.0 |
Returns
number
guid()
guid(): Guid;
Get a random GUID.
Returns
hash()
hash(length?: number, upperCase?: boolean): string;
Return a random hex hash. Default 40 characters, aka SHA-1.
Parameters
Parameter | Type | Description |
---|---|---|
length ? | number | The length of the hash string. Default, 40 characters, aka SHA-1. |
upperCase ? | boolean | Returns the hex string with uppercase characters. |
Returns
string
hexadecimal()
hexadecimal(length?: number, prefix?: string): string;
Generates a random hexadecimal string.
Parameters
Parameter | Type | Description |
---|---|---|
length ? | number | |
prefix ? | string |
Returns
string
int()
int(min?: number, max?: number): number;
Generate a random int between MinValue and MaxValue.
Parameters
Parameter | Type | Description |
---|---|---|
min ? | number | Min value, inclusive. Default int.MinValue |
max ? | number | Max value, inclusive. Default int.MaxValue |
Returns
number
long()
long(min?: number, max?: number): number;
Generate a random long between MinValue and MaxValue.
Parameters
Parameter | Type | Description |
---|---|---|
min ? | number | Min value, inclusive. Default long.MinValue |
max ? | number | Max value, inclusive. Default long.MaxValue |
Returns
number
number()
Call Signature
number(max: number): number;
Get an int from 0 to max.
Parameters
Parameter | Type | Description |
---|---|---|
max | number | Upper bound, inclusive. |
Returns
number
Call Signature
number(min?: number, max?: number): number;
Get an int from min to max.
Parameters
Parameter | Type | Description |
---|---|---|
min ? | number | Lower bound, inclusive |
max ? | number | Upper bound, inclusive |
Returns
number
odd()
odd(min?: number, max?: number): number;
Returns a random odd number. If the range does not contain any odd numbers, an ArgumentException
is thrown.
Parameters
Parameter | Type | Description |
---|---|---|
min ? | number | Lower bound, inclusive |
max ? | number | Upper bound, inclusive |
Returns
number
randomLocale()
randomLocale(): string;
Returns a random locale.
Returns
string
replace()
replace(format: string): string;
Replaces symbols with numbers and letters. # = number, ? = letter, * = number or letter. IE: ###???* -> 283QED4. Letters are uppercase.
Parameters
Parameter | Type | Description |
---|---|---|
format | string |
Returns
string
replaceNumbers()
replaceNumbers(format: string, symbol?: string): string;
Replaces symbols with numbers. IE: ### -> 283
Parameters
Parameter | Type | Description |
---|---|---|
format | string | The string format |
symbol ? | string | The symbol to search for in format that will be replaced with a number |
Returns
string
replaceSymbols()
replaceSymbols(
format: string,
symbol: string,
func: () => string): string;
Replaces each character instance in a string. Func is called each time a symbol is encountered.
Parameters
Parameter | Type | Description |
---|---|---|
format | string | The string with symbols to replace. |
symbol | string | The symbol to search for in the string. |
func | () => string | The function that produces a character for replacement. Invoked each time the replacement symbol is encountered. |
Returns
string
sByte()
sByte(min?: number, max?: number): number;
Generate a random sbyte between -128 and 127.
Parameters
Parameter | Type | Description |
---|---|---|
min ? | number | Min value, inclusive. Default sbyte.MinValue -128 |
max ? | number | Max value, inclusive. Default sbyte.MaxValue 127 |
Returns
number
short()
short(min?: number, max?: number): number;
Generate a random short between MinValue and MaxValue.
Parameters
Parameter | Type | Description |
---|---|---|
min ? | number | Min value, inclusive. Default short.MinValue -32768 |
max ? | number | Max value, inclusive. Default short.MaxValue 32767 |
Returns
number
string()
Call Signature
string(
length?: number,
minChar?: string,
maxChar?: string): string;
Get a string of characters of a specific length.
Uses Int32)
.
Note: This method can return ill-formed UTF16 Unicode strings with unpaired surrogates.
Use Boolean)
for technically valid Unicode.
Parameters
Parameter | Type | Description |
---|---|---|
length ? | number | The exact length of the result string. If null, a random length is chosen between 40 and 80. |
minChar ? | string | Min character value, inclusive. Default char.MinValue |
maxChar ? | string | Max character value, inclusive. Default char.MaxValue |
Returns
string
Call Signature
string(
minLength: number,
maxLength: number,
minChar?: string,
maxChar?: string): string;
Get a string of characters between minLength
and maxLength
.
Uses Int32)
.
Note: This method can return ill-formed UTF16 Unicode strings with unpaired surrogates.
Use Boolean)
for technically valid Unicode.
Parameters
Parameter | Type | Description |
---|---|---|
minLength | number | Lower-bound string length. Inclusive. |
maxLength | number | Upper-bound string length. Inclusive. |
minChar ? | string | Min character value, inclusive. Default char.MinValue |
maxChar ? | string | Max character value, inclusive. Default char.MaxValue |
Returns
string
string2()
Call Signature
string2(length: number, chars?: string): string;
Get a string of characters with a specific length drawing characters from chars
.
The returned string may contain repeating characters from the chars
string.
Parameters
Parameter | Type | Description |
---|---|---|
length | number | The length of the string to return. |
chars ? | string | The pool of characters to draw from. The returned string may contain repeat characters from the pool. |
Returns
string
Call Signature
string2(
minLength: number,
maxLength: number,
chars?: string): string;
Get a string of characters with a specific length drawing characters from chars
.
The returned string may contain repeating characters from the chars
string.
Parameters
Parameter | Type | Description |
---|---|---|
minLength | number | The minimum length of the string to return, inclusive. |
maxLength | number | The maximum length of the string to return, inclusive. |
chars ? | string | The pool of characters to draw from. The returned string may contain repeat characters from the pool. |
Returns
string
uInt()
uInt(min?: number, max?: number): number;
Generate a random uint between MinValue and MaxValue.
Parameters
Parameter | Type | Description |
---|---|---|
min ? | number | Min value, inclusive. Default uint.MinValue |
max ? | number | Max value, inclusive. Default uint.MaxValue |
Returns
number
uLong()
uLong(min?: number, max?: number): number;
Generate a random ulong between MinValue and MaxValue.
Parameters
Parameter | Type | Description |
---|---|---|
min ? | number | Min value, inclusive. Default ulong.MinValue |
max ? | number | Max value, inclusive. Default ulong.MaxValue |
Returns
number
uShort()
uShort(min?: number, max?: number): number;
Generate a random ushort between MinValue and MaxValue.
Parameters
Parameter | Type | Description |
---|---|---|
min ? | number | Min value, inclusive. Default ushort.MinValue 0 |
max ? | number | Max value, inclusive. Default ushort.MaxValue 65535 |
Returns
number
utf16String()
utf16String(
minLength?: number,
maxLength?: number,
excludeSurrogates?: boolean): string;
Get a string of valid UTF16 Unicode characters. This method returns a string where each character IsLetterOrDigit() is true.
Parameters
Parameter | Type | Description |
---|---|---|
minLength ? | number | The minimum length of the string to return, inclusive. |
maxLength ? | number | The maximum length of the string to return, inclusive. |
excludeSurrogates ? | boolean | Excludes surrogate pairs from the returned string. |
Returns
string
uuid()
uuid(): Guid;
Get a random GUID. Alias for Randomizer.Guid().
Returns
word()
word(): string;
Returns a single word or phrase in English.
Returns
string
words()
words(count?: number): string;
Gets some random words and phrases in English.
Parameters
Parameter | Type | Description |
---|---|---|
count ? | number | Number of times to call Word() |
Returns
string
wordsArray()
Call Signature
wordsArray(min: number, max: number): string[];
Get a range of words in an array (English).
Parameters
Parameter | Type | Description |
---|---|---|
min | number | Minimum word count, inclusive. |
max | number | Maximum word count, inclusive. |
Returns
string
[]
Call Signature
wordsArray(count: number): string[];
Get a specific number of words in an array (English).
Parameters
Parameter | Type | Description |
---|---|---|
count | number |
Returns
string
[]
FakerScriptApi
type FakerScriptApi = {
address: FakerAddress;
commerce: FakerCommerce;
company: FakerCompany;
database: FakerDatabase;
date: FakerDate;
finance: FakerFinance;
hacker: FakerHacker;
image: FakerImages;
internet: FakerInternet;
lorem: FakerLorem;
music: FakerMusic;
name: FakerName;
phone: FakerPhoneNumbers;
random: FakerRandomizer;
system: FakerSystem;
vehicle: FakerVehicle;
};
The faker methods to generate fake, but realistic, data.
Properties
address
readonly address: FakerAddress;
Methods for generating an address.
commerce
readonly commerce: FakerCommerce;
Methods relating to commerce.
company
readonly company: FakerCompany;
Methods for generating random company names and phrases.
database
readonly database: FakerDatabase;
Generates some random database stuff.
date
readonly date: FakerDate;
Methods for generating dates.
finance
readonly finance: FakerFinance;
Provides financial randomness.
hacker
readonly hacker: FakerHacker;
Hackerish words.
image
readonly image: FakerImages;
Generates images URLs.
internet
readonly internet: FakerInternet;
Random Internet things like email addresses.
lorem
readonly lorem: FakerLorem;
Generates plain old boring text.
music
readonly music: FakerMusic;
Methods for generating music related stuff.
name
readonly name: FakerName;
Methods for generating names.
phone
readonly phone: FakerPhoneNumbers;
Generates phone numbers.
random
readonly random: FakerRandomizer;
A randomizer that randomizes things.
system
readonly system: FakerSystem;
Generates fake data for many computer systems properties.
vehicle
readonly vehicle: FakerVehicle;
Methods for generating vehicle information.
FakerSystem
type FakerSystem = {
locale: string;
random: FakerRandomizer;
androidId: string;
applePushToken: string;
blackBerryPin: string;
commonFileExt: string;
commonFileName: string;
commonFileType: string;
directoryPath: string;
fileExt: string;
fileName: string;
filePath: string;
fileType: string;
mimeType: string;
semver: string;
};
Generates fake data for many computer systems properties
Properties
locale
locale: string;
random
random: FakerRandomizer;
Methods
androidId()
androidId(): string;
Get a random GCM registration ID.
Returns
string
A random GCM registration ID.
applePushToken()
applePushToken(): string;
Get a random Apple Push Token.
Returns
string
A random Apple Push Token.
blackBerryPin()
blackBerryPin(): string;
Get a random BlackBerry Device PIN.
Returns
string
A random BlackBerry Device PIN.
commonFileExt()
commonFileExt(): string;
Returns a commonly used file extension.
Returns
string
A commonly used file extension.
commonFileName()
commonFileName(ext?: string): string;
Generates a random file name with a common file extension.
Extension can be overwritten with ext
.
Parameters
Parameter | Type | Description |
---|---|---|
ext ? | string | The extensions to be used for a file name. |
Returns
string
A random file name with a common extension or ext
.
commonFileType()
commonFileType(): string;
Returns a commonly used file type.
Returns
string
A commonly used file type.
directoryPath()
directoryPath(): string;
Get a random directory path (Unix).
Returns
string
A random Unix directory path.
fileExt()
fileExt(mimeType?: string): string;
Gets a random extension for the given mime type.
Parameters
Parameter | Type | Description |
---|---|---|
mimeType ? | string |
Returns
string
A random extension for the given mime type.
fileName()
fileName(ext?: string): string;
Get a random file name.
Parameters
Parameter | Type | Description |
---|---|---|
ext ? | string | The extension the file name will have. If null is provided, a random extension will be picked. |
Returns
string
A random file name with the given ext
or a random extension
filePath()
filePath(): string;
Get a random file path (Unix).
Returns
string
A random Unix file path.
fileType()
fileType(): string;
Returns any file type available as mime-type.
Returns
string
Any file type available as mime-type.
mimeType()
mimeType(): string;
Get a random mime type.
Returns
string
A random mime type.
semver()
semver(): string;
Get a random semver version string.
Returns
string
A random semver version string.
FakerVehicle
type FakerVehicle = {
locale: string;
random: FakerRandomizer;
fuel: string;
manufacturer: string;
model: string;
type: string;
vin: string;
};
Methods for generating vehicle information
Properties
locale
locale: string;
random
random: FakerRandomizer;
Methods
fuel()
fuel(): string;
Get a vehicle fuel type. IE: Electric, Gasoline, Diesel.
Returns
string
manufacturer()
manufacturer(): string;
Get a vehicle manufacture name. IE: Toyota, Ford, Porsche.
Returns
string
model()
model(): string;
Get a vehicle model. IE: Camry, Civic, Accord.
Returns
string
type()
type(): string;
Get a vehicle type. IE: Minivan, SUV, Sedan.
Returns
string
vin()
vin(strict?: boolean): string;
Generate a vehicle identification number (VIN).
Parameters
Parameter | Type | Description |
---|---|---|
strict ? | boolean | Limits the acceptable characters to alpha numeric uppercase except I, O and Q. |
Returns
string
Guid
type Guid = {
variant: number;
version: number;
toString: string;
};
Properties
variant
readonly variant: number;
version
readonly version: number;
Methods
toString()
toString(): string;
Returns
string
UserVariablesScriptApi
type UserVariablesScriptApi = {
delete: void;
get: any;
has: boolean;
keys: Iterable<string>;
set: void;
};
The storage to set and retrieve custom variables, which are accessible in other operations and via templating.
Methods
delete()
delete(key: string): void;
Deletes the specified variable.
Parameters
Parameter | Type | Description |
---|---|---|
key | string | The key of the variable. |
Returns
void
get()
get(key: string): any;
Gets the value of a variable.
Parameters
Parameter | Type | Description |
---|---|---|
key | string | The key of the variable. |
Returns
any
The value of the variable or undefined if the variable does not exist.
has()
has(key: string): boolean;
Checks whether the specified variable exists.
Parameters
Parameter | Type | Description |
---|---|---|
key | string | The key of the variable. |
Returns
boolean
True when the variable exists, otherwise false.
keys()
keys(): Iterable<string>;
Returns the keys of all stored variables.
Returns
Iterable
<string
>
The keys of all stored variables.
set()
set(key: string, value: any): void;
Sets a variable. Setting undefined as a value deletes the variable.
Parameters
Parameter | Type | Description |
---|---|---|
key | string | The key of the variable. |
value | any | The value of the variable. |
Returns
void