Global

This is the global namespace. Functions are available without having to prepend them with a namespace identifier.

Static properties

Image any

HTML Image.

Methods

NUM

NUM(number: number, numDecimals?: number)

Returns a formatted number as a string. If a culture is specified when executing a ruleset, the formatting of that culture will be used.

Parameters

number number

A numeric value.

numDecimals number

(optional) The number of decimals. Defaults to 0.

Return type

string

Examples

CUR

Returns a formatted currency number as a string. If a culture is specified when executing a ruleset, the formatting of that culture will be used.

Parameters

number number

A numeric value.

numDecimals number

(optional) The number of decimals. Defaults to 2.

Return type

string

Examples

CURN

Returns a formatted currency number as a string without the currency symbol. If a culture is specified when executing a ruleset, the formatting of that culture will be used.

Parameters

number number

A numeric value.

numDecimals number

(optional) The number of decimals. Defaults to 2.

Return type

string

Examples

DATESTR

Returns a formatted date as a string. If a culture is specified when executing a ruleset, the formatting of that culture will be used. See Intl.DateTimeFormat for more information on the formatting options.

Parameters

date Date | string

A JavaScript Date object or an ISO 8601 formatted string.

options Intl.DateTimeFormatOptions

(optional) The formatting options.

Return type

string

Examples

AGE

Returns the amount of full years passed since a given JavaScript Date Object.

Parameters

birthDate Date | string

A JavaScript Date object or an ISO 8601 formatted string.

Return type

number

Examples

DATE

Creates a JavaScript Date Object. Is more reliable than using 'new Date()' to create a date, as DATE() ignores timezones.

Parameters

year number | string | Date

The year or a YYYY-MM-DD string.

month number

(optional) The month. 1-based (1=January, 2=February, etc.).

day number

(optional) The day.

Return type

Date

Examples

TODAY

Returns the current date as a JavaScript Date Object at the start of the day (midnight, 00:00).

Parameters

Return type

Date

Examples

NOW

Returns the current date and time as a JavaScript Date Object accurate to the millisecond.

Parameters

Return type

Date

Examples

DAY

Returns the day of a given JavaScript Date Object.

Parameters

date Date | string

A JavaScript Date object or an ISO 8601 formatted string.

Return type

number

Examples

WEEKDAY

Returns the day of the week of a given JavaScript Date Object. Differs from JS Date's getDay() method, in that it is 1-based. (e.g. Sunday = 1, instead of 0. Saturday = 7)

Parameters

date Date | string

A JavaScript Date object or an ISO 8601 formatted string.

Return type

number

Examples

MONTH

Returns the month of a given JavaScript Date Object. Differs from JS Date's getMonth() method, in that it is 1-based. (e.g. January = 1, instead of 0.)

Parameters

date Date | string

A JavaScript Date object or an ISO 8601 formatted string.

Return type

number

Examples

YEAR

Returns the year of a given JavaScript Date Object.

Parameters

date Date | string

A JavaScript Date object or an ISO 8601 formatted string.

Return type

number

Examples

YEARMONTH

Returns the year and month of a given JavaScript Date Object.

Parameters

date Date | string

A JavaScript Date object or an ISO 8601 formatted string.

Return type

string

Examples

YEARMONTHDAY

Returns the year, month and day of a given JavaScript Date Object. Note: this is similar to calling .toShortDateString() on a Date. See also:

  • Date.toShortDateString

Parameters

date Date | string

A JavaScript Date object or an ISO 8601 formatted string.

Return type

string

Examples

MONTHDAY

Returns the month and day of a given JavaScript Date Object.

Parameters

date Date | string

A JavaScript Date object or an ISO 8601 formatted string.

Return type

string

Examples

DAYDIFF

Returns the amount of full days between two dates. See also:

  • Date.diff

Parameters

dateFrom Date | string

A JavaScript Date object or an ISO 8601 formatted string.

dateTo Date | string

A JavaScript Date object or an ISO 8601 formatted string.

Return type

number

Examples

SAMEDAY

Returns whether two dates are on the same day. See also:

  • Date.isSameDay

Parameters

dateA Date | string

A JavaScript Date object or an ISO 8601 formatted string.

dateB Date | string

A JavaScript Date object or an ISO 8601 formatted string.

Return type

boolean

Examples

MONTHDIFF

Returns the amount of full months between two dates. See also:

  • Date.diff

Parameters

dateFrom Date | string

A JavaScript Date object or an ISO 8601 formatted string.

dateTo Date | string

A JavaScript Date object or an ISO 8601 formatted string.

Return type

number

Examples

YEARDIFF

Returns the amount of full years between two dates. See also:

  • Date.diff

Parameters

dateFrom Date | string

A JavaScript Date object or an ISO 8601 formatted string.

dateTo Date | string

A JavaScript Date object or an ISO 8601 formatted string.

Return type

number

Examples

DATEDIFF

Returns an object containing the difference between two dates in various units. The output is similar to Date.diff(). See also:

  • Date.diff

Parameters

dateFrom Date | string

A JavaScript Date object or an ISO 8601 formatted string.

dateTo Date | string

A JavaScript Date object or an ISO 8601 formatted string.

absolute boolean

(optional) If true, will return a positive value for the difference.

Return type

DateDiffResult

Examples

ABS

Shorthand for Math.abs()

Parameters

x number

A number.

Return type

number

Examples

CEIL

Returns the smallest integer greater than or equal to a given number.

Parameters

x number

A number.

numDecimals number

(optional) Number of decimals. Can be negative to round down to number of integers.

Return type

number

Examples

FLOOR

Returns the largest integer less than or equal to a given number.

Parameters

x number

A number.

numDecimals number

(optional) Number of decimals. Can be negative to round down to number of integers.

Return type

number

Examples

ROUND

Returns the value of a number rounded to the nearest integer, using the 'Half Away From Zero' rounding mode.

Parameters

x number

A number.

numDecimals number

(optional) Number of decimals. Can be negative to round down to number of integers.

Return type

number

Examples

LOG

Shorthand for Math.log() - returns the natural logarithm (base e) of the given number.

Parameters

x number

A number.

Return type

number

Examples

EXP

Shorthand for Math.exp() - returns ex, where x is the argument, and e is Euler's number (also known as Napier's constant), the base of the natural logarithms.

Parameters

x number

A number.

Return type

number

Examples

POW

Shorthand for Math.pow() - returns the base to the exponent power. Note: for performance reasons it is better to use the ** operator instead of POW or Math.pow.

Parameters

base number

The base number.

exponent number

The exponent used to raise the base.

Return type

number

Examples

SQRT

Shorthand for Math.sqrt() - returns the square root of a number.

Parameters

x number

A number.

Return type

number

Examples

MIN

Returns the lowest-valued number passed into it.

Parameters

...numbers number[]

Numbers.

Return type

number

Examples

MAX

Returns the highest-valued number passed into it.

Parameters

...numbers number[]

Numbers.

Return type

number

Examples

CLAMP

Combines the logic of MIN and MAX - Clamps the input number between the min and max values.

Parameters

input number

The input value to be clamped.

min number

Lowest possible value to clamp the input to.

max number

Highest possible value to clamp the input to.

Return type

number

Examples

WRAP

Wraps a number within a given range. If the number exceeds the range, it will wrap around.

Parameters

value number

The input value to be wrapped.

min number

The minimum value of the range.

max number

The maximum value of the range.

Return type

number

Examples

MAP

Maps a number from one range to another

Parameters

value number

The input value to be mapped.

startA number

Current value range start.

endA number

Current value range end.

startB number

Target range start.

endB number

Target range end.

clamp boolean

(optional) Clamp the mapped value between target range. Defaults to false.

Return type

number

Examples

SOLVE

Attempt to find the input value that produces a given target result for a given function.

Parameters

fn (x: number) => number

The function to find the input for. Must have exactly one parameter (number) and must return a number.

target number

The target result value.

start number

(optional) The input to start from. Defaults to 0.

step number

(optional) The initial step size. Defaults to 100.

accuracy number

(optional) The desired accuracy. If 0 is specified, the result must match exactly. Defaults to 1e-15.

maxIterations number

(optional) The maximum number of attempts to solve for the input. Defaults to 100.

Return type

number

Examples

RANDOM

Returns a floating-point, pseudo-random number in the range 0-1 (inclusive of 0, but not 1). If you pass in one parameter, it will return a random number between 0 and that number. When you pass in two parameters, it will return a random number between those two numbers.

Parameters

start number

(optional) The lower limit. Defaults to 0.

end number

(optional) The upper limit. Defaults to 1. The value itself is not included in the range.

Return type

number

Examples

RANDOMINT

Returns an integer, pseudo-random number in a given range. It will return a random number between those two numbers, including those two numbers.

Parameters

start number

The lower limit.

end number

The upper limit.

Return type

number

Examples

PICK

Returns an random element from a given array.

Parameters

array any[]

The array.

Return type

any

Examples

PLUCK

Returns an random element from a given array, but also removes that element from it!

Parameters

array any[]

The array.

Return type

any

Examples

RANGE

Creates an array of numbers in a given range.

Parameters

start number

The lower limit.

end number

The upper limit.

step number

(optional) The step size. Defaults to 1.

Return type

number[]

Examples

GUID

Returns a globally unique identifier (GUID). Each call will return a different GUID.

Parameters

fill number | string

(optional) Value to fill the result with.

Return type

string

Examples

EMPTYGUID

Returns a zero-filled globally unique identifier (GUID). Equal to calling GUID(0).

Parameters

Return type

string

Examples

NOT

Negates the specified parameter.

Parameters

boolean any

Value to be negated.

Return type

boolean

Examples

FOR

Iterates over the specified range and executes the specified function for each value. Returns the number of iterations.

Parameters

start number

The start value (inclusive).

end number

The end value (inclusive).

function Function

The function to be executed for each value.

step number

(optional) The step value.

Return type

number

Examples

REPEAT

Repeats the specified function the specified number of times. Returns the number of iterations. REPEAT(x, func) is shorthand for FOR(1, x, func).

Parameters

count number

The number of times to repeat the function.

function Function

The function to be executed for iteration. The function will be called with the iteration number as the first parameter, starting with 1 and ending with the count.

Return type

number

Examples

CLONE

Creates a (deep) copy of a given object.

Parameters

obj any

The object to clone.

Return type

any

Examples

COERCE

Tries to convert a string to what it represents.

Parameters

str any

The string to coerce.

Return type

any

Examples

CSV2JSON

Converts a CSV string to a JSON array. Will try to detect the separator automatically. Default newline character is '\n' - can be overriden with the 'lineSeparator' option.

Parameters

csv string

The CSV string to convert.

options { separator?: string, lineSeparator?: string, objects?: boolean, skipHeader?: boolean, coerce?: boolean }

(optional) The options object.

Return type

{ [key: string]: any; }[]

Examples

XML2JSON

Converts an XML string to a JSON object.

Parameters

xml string

The XML string to convert.

options { parseNumbers?: boolean, parserOptions?: any }

(optional) The options object. The property parseNumbers can be used to force numbers to be parsed as numbers. For more information on the parserOptions property click here.

Return type

{ [key: string]: any; }

Examples

JSON2XML

Converts a JSON object to an XML string.

Parameters

json { [key: string]: any; }

The JSON object to convert.

options { builderOptions?: any }

(optional) The options object. For more information on the builderOptions click here

Return type

string

Examples

XLSX2JSON

Converts an Excel file (base64 encoded) to a JSON object. Returns an array of sheets, each containing an array of rows, each containing an array of cells.

Parameters

base64file string

The base64 encoded Excel file. Can be a data URL.

Return type

{ name: string, data: any[][] }[]

Examples

Last updated