Utilities

Functions

convertUnits(value,sourceUnit,targetUnit)(number | Vec)

Converts a value in source units to a value in the target units.

value
(number | Vec)

The value to convert, number or Vec.

sourceUnit
("in" | "ft" | "mm" | "cm" | "m" | "px" | "pc" | "pt")

The unit of the value.

targetUnit
("in" | "ft" | "mm" | "cm" | "m" | "px" | "pc" | "pt")

The unit to convert to.

toString(value)string

Converts any number, array or object to a string.

Numbers with very long fractional parts that are very close to a shorter number will be rounded.

For example: toString(0.9999999999999) = "1"

value
unknown

Any number or object to convert

range(start,stop,step)number[]
start
number

The first number in the array

stop
number
optional

The number to stop at. Note that this number will not be included in the array.

step
number
1

The increment. Keep this as 1 for integer ranges.

Returns An array of numbers from start to stop, in increments of step. The array is not inclusive of end.

pairs(array,loop)[T, T][]

Pairs-up elements in an array.

let a = [1, 2, 3];
pairs(a); // [[1, 2], [2, 3]]

If loop is set true the array of pairs will include a pair of the last and first elements, completing the cycle.

let a = [1, 2, 3];
pairs(a, true); // [[1, 2], [2, 3], [3, 1]]
array
T[]
loop
boolean
false