Namespaces
Methods
-
<static> asyncForEach( array, callback )
-
Description
Wait for an async forEach loop. Does not run in parallel.Parameters
Name Type Description array
Array.<array> An input array callback
function A function to execute when iteration is complete Examples
const waitFor = (ms) => new Promise(r => setTimeout(r, ms)); await asyncForEach([1, 2, 3], async (num) => { await waitFor(50); console.log(num); }); console.log('Done');
Details
-
<static> map( value, fromLow, fromHigh, toLow, toHigh ) → {Number}
-
Description
Map a value (number) from one range to another. Based on Arduino's map(). Truncates the returned value to an integerParameters
Name Type Description value
Number value to map fromLow
Number low end of originating range fromHigh
Number high end of originating range toLow
Number low end of target range toHigh
Number high end of target range Returns
Examples
Fn.map(500, 0, 1000, 0, 255); // -> 127
Details
-
<static> fmap( value, fromLow, fromHigh, toLow, toHigh ) → {Number}
-
Description
Like map, but does not truncate the returned valueParameters
Name Type Description value
Number value to map fromLow
Number low end of originating range fromHigh
Number high end of originating range toLow
Number low end of target range toHigh
Number high end of target range Returns
Details
-
<static> constrain( value, low, high ) → {Number}
-
Description
Constrain a value to a range.Parameters
Name Type Description value
number An input value low
number The minimum allowed value (inclusive) high
number The maximum allowed value (inclusive) Returns
Examples
constrain(120, 0, 100); // -> 100
Details
-
<inner> debounce( func, wait [, immediate ] ) → {function}
-
Description
Debounce a function so that it is not invoked unless it stops being called for N millisecondsParameters
Name Type Attributes Description func
function The function to be debounced wait
number The number of milliseconds to wait immediate
boolean <optional> Triggers the function on the leading edge Returns
Details
-
<static> toFixed( number [, digits ] ) → {Number}
-
Description
Format a number such that it has a given number of digits after the decimal pointParameters
Name Type Attributes Default Description number
Number The number to format digits
Number <optional> 0 The number of digits after the decimal point Returns
Examples
Fn.toFixed(5.4564, 2); // -> 5.46
Fn.toFixed(1.5, 2); // -> 1.5
Details
-
<static> pad( value, length ) → {String}
-
Description
left Pad a Number with zerosParameters
Name Type Description value
number An input value length
number The desired length Returns
Examples
pad(3, 2); // -> "03"
Details