Namespaces
Methods
-
<static> asyncForEach( array, callback )
-
Description
Wait for an async forEach loop. Does not run in parallel.Parameters
Name Type Description arrayArray.<array> An input array callbackfunction 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 valueNumber value to map fromLowNumber low end of originating range fromHighNumber high end of originating range toLowNumber low end of target range toHighNumber high end of target range Returns
Examples
Fn.map(500, 0, 1000, 0, 255); // -> 127Details
-
<static> fmap( value, fromLow, fromHigh, toLow, toHigh ) → {Number}
-
Description
Like map, but does not truncate the returned valueParameters
Name Type Description valueNumber value to map fromLowNumber low end of originating range fromHighNumber high end of originating range toLowNumber low end of target range toHighNumber high end of target range Returns
Details
-
<static> constrain( value, low, high ) → {Number}
-
Description
Constrain a value to a range.Parameters
Name Type Description valuenumber An input value lownumber The minimum allowed value (inclusive) highnumber The maximum allowed value (inclusive) Returns
Examples
constrain(120, 0, 100); // -> 100Details
-
<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 funcfunction The function to be debounced waitnumber The number of milliseconds to wait immediateboolean <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 numberNumber The number to format digitsNumber <optional> 0 The number of digits after the decimal point Returns
Examples
Fn.toFixed(5.4564, 2); // -> 5.46Fn.toFixed(1.5, 2); // -> 1.5Details
-
<static> pad( value, length ) → {String}
-
Description
left Pad a Number with zerosParameters
Name Type Description valuenumber An input value lengthnumber The desired length Returns
Examples
pad(3, 2); // -> "03"Details
