Description
Utilities used in most IO modules. Typically called from other J5e methods, not by user code.
Details

Namespaces


timer

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

Sebastien Chopin

Sebastien's Medium article for more information


<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 integer
Parameters
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
mapped value (integer)
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 value
Parameters
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
constrained value
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 milliseconds
Parameters
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

David Walsh


<static> toFixed( number [, digits ] ) → {Number}

Description
Format a number such that it has a given number of digits after the decimal point
Parameters
Name Type Attributes Default Description
number Number The number to format
digits Number <optional>
0 The number of digits after the decimal point
Returns
Formatted number
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 zeros
Parameters
Name Type Description
value number An input value
length number The desired length
Returns
The padded string
Examples
pad(3, 2); // -> "03"
Details