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
.