Members
(constant) groupByAsync
- Source:
Promises the creation of an object composed of keys generated from the results
of running each element of collection thru then supplied function.
The corresponding value of each key is an collection of the elements responsible
for generating the key.
(constant) includesAsync
- Source:
Returns a promise returning true if an array includes a value
Example
if(await includesAsync(someArray, 'error')) {
...
}
(constant) indexOfAsync
- Source:
Returns a promise for the first index of an item in an array
(constant) keyByAsync
- Source:
Promises the creation an object composed of keys generated from the results
of running each element of collection thru then supplied function.
The corresponding value of each key is the last element responsible
for generating the key.
(constant) lastIndexOfAsync
- Source:
Returns a promise for the last index of an item in an array
(constant) uniqueByAsync
- Source:
Promises the creation of an array with the unique values from the
input array, the routine is supplied with a
function that determines on what the array should
be made unique.
Methods
(generator) append(array1, array2) → {Generator.<*, Array, *>}
- Source:
Appends one array to another
Example
// Updates array1
yield * append(array1, array2)
Parameters:
Name |
Type |
Description |
array1 |
Array
|
the destination |
array2 |
Array
|
the source |
Returns:
returns array1
-
Type
-
Generator.<*, Array, *>
appendAsync(destination, source) → {Promise.<Array>}
- Source:
Appends one array to another asynchronously
Parameters:
Name |
Type |
Description |
destination |
Array
|
|
source |
Array
|
|
Returns:
a promise for destination after appending
-
Type
-
Promise.<Array>
base64CompressAsync(source) → {Promise.<String>}
- Source:
Asynchronously apply lz-string base64 remapping of a string
Parameters:
Name |
Type |
Description |
source |
String
|
the data to compress |
Returns:
a promise for the compressed data
-
Type
-
Promise.<String>
base64CompressToUTF16Async(source) → {Promise.<String>}
- Source:
Asynchronously apply lz-string base64 remapping of a string to utf16
Parameters:
Name |
Type |
Description |
source |
String
|
the data to compress |
Returns:
a promise for the compressed data
-
Type
-
Promise.<String>
base64Decompress(base64Data) → {Promise.<String>}
- Source:
Asynchronously unmap base64 encoded data
Parameters:
Name |
Type |
Description |
base64Data |
String
|
the data to decompress |
Returns:
a promise for the uncompressed data
-
Type
-
Promise.<String>
base64decompressFromUTF16Async(base64Data) → {Promise.<String>}
- Source:
Asynchronously unmap base64 encoded data to a utf16 destination
Parameters:
Name |
Type |
Description |
base64Data |
String
|
the data to decompress |
Returns:
a promise for the uncompressed data
-
Type
-
Promise.<String>
branch(fn)
- Source:
Branches a pipeline by starting another "continuation" with
the current parameters. Starts a function but the pipeline
continues immediately creating two execution contexts
Parameters:
Name |
Type |
Description |
fn |
function
|
the function to start - can be async or generator |
call(fn, …config) → {function}
- Source:
Create a version of a function with its end
parameters supplied
Parameters:
Name |
Type |
Attributes |
Description |
fn |
function
|
GeneratorFunction
|
AsyncFunction
|
|
the function to configure |
config |
Array.<any>
|
<repeatable>
|
the additional parameters to pass |
Returns:
-
Type
-
function
compressAsync(source) → {Promise.<String>}
- Source:
Asynchronously compress a string of data with lz-string
Parameters:
Name |
Type |
Description |
source |
String
|
the data to compress |
Returns:
a promise for the compressed data
-
Type
-
Promise.<String>
compressToBase64Async(source) → {Promise.<String>}
- Source:
Asynchronously compress a string to a base64 format
Parameters:
Name |
Type |
Description |
source |
String
|
the data to compress |
Returns:
a promise for the base64 compressed data
-
Type
-
Promise.<String>
compressToBase64Async(compressedData) → {Promise.<String>}
- Source:
Asynchronously decompress a string from a base64 source
Parameters:
Name |
Type |
Description |
compressedData |
String
|
the data to decompress |
Returns:
a promise for the uncompressed data
-
Type
-
Promise.<String>
compressToEncodedURIComponentAsync(source) → {Promise.<String>}
- Source:
Asynchronously compress a string to a URI safe version
Parameters:
Name |
Type |
Description |
source |
String
|
the data to compress |
Returns:
a promise for the string of compressed data
-
Type
-
Promise.<String>
compressToUint8ArrayAsync(source) → {Promise.<Uint8Array>}
- Source:
Asynchronously compress a string to a Uint8Array
Parameters:
Name |
Type |
Description |
source |
String
|
the data to compress |
Returns:
a promise for the Uint8Array of compressed data
-
Type
-
Promise.<Uint8Array>
compressToUTF16Async(source) → {Promise.<String>}
- Source:
Asynchronously compress a string to a utf16 string
Parameters:
Name |
Type |
Description |
source |
String
|
the data to compress |
Returns:
a promise for the utf16 compressed data
-
Type
-
Promise.<String>
(generator) concat(array1, array2) → {Generator.<*, Array, *>}
- Source:
Concatenate two arrays into a new array
Example
const concatenated = yield * concat(array1, array2)
Parameters:
Name |
Type |
Description |
array1 |
Array
|
|
array2 |
Array
|
|
Returns:
the concatenated arrays
-
Type
-
Generator.<*, Array, *>
concatAsync(array1, array2) → {Promise.<Array>}
- Source:
Concatenates 2 arrays into a new array
Parameters:
Name |
Type |
Description |
array1 |
Array
|
|
array2 |
Array
|
|
Returns:
a promise for combined array
-
Type
-
Promise.<Array>
decompressAsync(compressedData) → {Promise.<String>}
- Source:
Asynchronously decompress a string from a string source
Parameters:
Name |
Type |
Description |
compressedData |
String
|
the data to decompress |
Returns:
a promise for the uncompressed data
-
Type
-
Promise.<String>
decompressFromEncodedURIComponentAsync(compressedData) → {Promise.<String>}
- Source:
Asynchronously decompress a string from a URL safe URI Component encoded source
Parameters:
Name |
Type |
Description |
compressedData |
String
|
the data to decompress |
Returns:
a promise for the uncompressed data
-
Type
-
Promise.<String>
decompressFromUint8ArrayAsync(compressedData) → {Promise.<String>}
- Source:
Asynchronously decompress a string from a utf16 source
Parameters:
Name |
Type |
Description |
compressedData |
String
|
the data to decompress |
Returns:
a promise for the uncompressed data
-
Type
-
Promise.<String>
decompressFromUTF16Async(compressedData) → {Promise.<String>}
- Source:
Asynchronously decompress a string from a utf16 source
Parameters:
Name |
Type |
Description |
compressedData |
String
|
the data to decompress |
Returns:
a promise for the uncompressed data
-
Type
-
Promise.<String>
(generator) every(collection, fn) → {Generator.<*, boolean, *>}
- Source:
Example
if(! yield * every(records, yielding(r=>r.valid))) return
Parameters:
Name |
Type |
Description |
collection |
Array
|
Object
|
|
fn |
Filter
|
|
Returns:
true if all of the collection items matched the filter
-
Type
-
Generator.<*, boolean, *>
everyAsync(array, fn) → {Promise.<Boolean>}
- Source:
Asynchronously check if every element in an array matches
a predicate
Parameters:
Name |
Type |
Description |
array |
Array
|
|
fn |
Filter
|
|
Returns:
promise for true if all items matched the filter
-
Type
-
Promise.<Boolean>
(generator) filter(collection, fn) → {Generator.<*, (Object|Array), *>}
- Source:
Example
const filtered = yield * filter(array, yielding(v=>v.value > 1000, 100))
Parameters:
Name |
Type |
Description |
collection |
Array
|
Object
|
|
fn |
Filter
|
|
Returns:
collection of elements matching the filter
-
Type
-
Generator.<*, (Object|Array), *>
filterAsync(array, filter) → {Promise.<Array>}
- Source:
Filters an array asynchronously
Parameters:
Name |
Type |
Description |
array |
Array
|
|
filter |
Filter
|
|
Returns:
promise for the filtered array
-
Type
-
Promise.<Array>
(generator) find(collection, fn, startopt) → {Generator.<*, *, *>}
- Source:
Example
const record = yield * find(arrayOfRecords, yielding(v=>v.id === '1234'))
Parameters:
Name |
Type |
Attributes |
Description |
collection |
Array
|
Object
|
|
|
fn |
Filter
|
|
|
start |
any
|
<optional>
|
the key to start at |
Returns:
the first matching value in the collection or null
-
Type
-
Generator.<*, *, *>
findAsync(array, filter) → {Promise.<(any|null)>}
- Source:
Finds an item in an array asynchronously
Parameters:
Name |
Type |
Description |
array |
Array
|
|
filter |
Filter
|
|
Returns:
promise for the item found or null if no match
-
Type
-
Promise.<(any|null)>
(generator) findIndex(collection, fn) → {Generator.<*, number, *>}
- Source:
Example
if(-1 === yield * findIndex(records, yielding(v=>v.id === '123')))
return
Parameters:
Name |
Type |
Description |
collection |
Array
|
Object
|
|
fn |
Filter
|
|
Returns:
Index of matching element or -1
-
Type
-
Generator.<*, number, *>
findIndexAsync(array, filter) → {Promise.<Number>}
- Source:
Finds an item index in an array asynchronously
Parameters:
Name |
Type |
Description |
array |
Array
|
|
filter |
Filter
|
|
Returns:
promise for the index of the first item to pass the filter or -1
-
Type
-
Promise.<Number>
(generator) forEach(collection, fn, startopt) → {Generator.<*, *, *>}
- Source:
Example
// Loop over all keys/value pairs in an object
yield * forEach(object, yielding((value, key)=> { ... }))
// Loop over all the values in an array
yield * forEach(array, generatorFunction)
function * generatorFunction(value, index) {
let i = 0
while(i < 10000) {
doSomething(value)
if(i % 100 === 0) yield
}
}
Parameters:
Name |
Type |
Attributes |
Description |
collection |
Array
|
Object
|
|
|
fn |
Process
|
|
|
start |
number
|
string
|
<optional>
|
|
Returns:
-
Type
-
Generator.<*, *, *>
forEachAsync(array, fn) → {Promise}
- Source:
Asynchronously loop over the elements of an array
Parameters:
Name |
Type |
Description |
array |
Array
|
|
fn |
Process
|
|
Returns:
promise for the end of the operation
-
Type
-
Promise
groupBy(collection, fn) → {Generator.<*, {}, *>}
- Source:
Creates an object composed of keys generated from the results
of running each element of collection thru then supplied function.
The corresponding value of each key is an collection of the elements responsible
for generating the key.
Example
let groups = yield * groupBy(records, yielding(v=>v.category))
...
console.log(groups['category1']) // -> [{id: 1, ...}, {id: 2, ...}]
Parameters:
Name |
Type |
Description |
collection |
Array
|
Object
|
|
fn |
Map
|
|
Returns:
a generator for the new object
-
Type
-
Generator.<*, {}, *>
includes(array, value) → {Generator.<*, boolean, *>}
- Source:
Returns true if an array includes a value
Example
prices = price * (yield * includes(items, yielding(v=>v.discount))) ? .4 : 1
Parameters:
Name |
Type |
Description |
array |
Array
|
|
value |
any
|
|
Returns:
-
Type
-
Generator.<*, boolean, *>
indexOf(array, value) → {Generator.<*, number, *>}
- Source:
Returns a generator for an index of an item in an array
Parameters:
Name |
Type |
Description |
array |
Array
|
the array to scan |
value |
*
|
the value to search for |
Returns:
-
Type
-
Generator.<*, number, *>
keyBy(collection, fn) → {Generator.<*, {}, *>}
- Source:
Creates an object composed of keys generated from the results
of running each element of collection thru then supplied function.
The corresponding value of each key is the last element responsible
for generating the key.
Example
let lookup = yield * keyBy(records, yielding(r=>r.id))
...
let row = lookup[id]
Parameters:
Name |
Type |
Description |
collection |
Array
|
Object
|
|
fn |
Map
|
|
Returns:
a generator for the new object
-
Type
-
Generator.<*, {}, *>
lastIndexOf(array, value) → {Generator.<*, number, *>}
- Source:
Returns a generator for an index of an item in an array
Example
let last = yield * lastIndexOf(collection, record)
Parameters:
Name |
Type |
Description |
array |
Array
|
the array to scan |
value |
*
|
the value to search for |
Returns:
-
Type
-
Generator.<*, number, *>
(generator) map(collection, fn) → {Generator.<*, (Array|Object), *>}
- Source:
Example
const values = yield * map(array, yielding(v=>v ** 2))
Parameters:
Name |
Type |
Description |
collection |
Array
|
Object
|
|
fn |
Map
|
|
Returns:
new collection of mapped values
-
Type
-
Generator.<*, (Array|Object), *>
mapAsync(array, mapFn) → {Promise.<Array>}
- Source:
Maps the contents of an array asynchronously
Parameters:
Name |
Type |
Description |
array |
Array
|
|
mapFn |
Map
|
|
Returns:
promise for the mapped array
-
Type
-
Promise.<Array>
parseAsync(json) → {Promise.<any>}
- Source:
Asynchronously parse JSON into an object
Parameters:
Name |
Type |
Description |
json |
String
|
the JSON to be parsed |
Returns:
a Promise for the parsed JSON
-
Type
-
Promise.<any>
- Source:
Create a function that executes a pipeline of
functions asynchronously
Parameters:
Returns:
an async function to execute the pipeline
-
Type
-
AsyncFunction
reduce(target, fn, initialopt) → {Generator.<*, *, *>}
- Source:
Example
async function sumAge(items) {
const output = await reduceAsync(items, (acc,cur)=>acc += cur.age, 0)
}
Parameters:
Name |
Type |
Attributes |
Description |
target |
Array
|
Object
|
|
|
fn |
Reduce
|
|
|
initial |
any
|
<optional>
|
|
Returns:
The result of processing the reduction function on all
of the items in the target
-
Type
-
Generator.<*, *, *>
reduceAsync(array, reduceFn, initialValue) → {Promise.<any>}
- Source:
Performs a reduce on an array asynchronously
Parameters:
Name |
Type |
Description |
array |
Array
|
|
reduceFn |
Reduce
|
|
initialValue |
any
|
|
Returns:
a promise for the reduced value
-
Type
-
Promise.<any>
- Source:
Create a function that repeats a function multiple times
passing the output of each iteration as the input to the next
Parameters:
Name |
Type |
Description |
fn |
function
|
the function to repeat |
times |
Number
|
the number of times to repeat |
Returns:
- a async function that repeats the operation
-
Type
-
AsyncFunction
run(coroutine, loopWhileMsRemainsopt, timeoutopt) → {Promise.<any>}
- Source:
Starts an idle time coroutine and returns a promise for its completion and
any value it might return.
You may pass a coroutine function or the result of calling such a function. The
latter helps when you must provide parameters to the coroutine.
Example
async function process() {
let answer = await run(function * () {
let total = 0
for(let i=1; i < 10000000; i++) {
total += i
if((i % 100) === 0) yield
}
return total
})
...
}
// Or
async function process(param) {
let answer = await run(someCoroutine(param))
}
Parameters:
Name |
Type |
Attributes |
Default |
Description |
coroutine |
Coroutine
|
Iterator
|
Generator.<*, *, *>
|
|
|
the routine to run or an iterator for an already started coroutine |
loopWhileMsRemains |
number
|
<optional>
|
2 (ms)
|
if less than the specified number of milliseconds remain the coroutine will continue in the next idle frame |
timeout |
number
|
<optional>
|
160 (ms)
|
the number of milliseconds before the coroutine will run even if the system is not idle |
Returns:
the result of the coroutine
The promise returned by run
has a terminate()
method
that can be used to stop the routine.
-
Type
-
Promise.<any>
singleton(fn, defaultValueopt) → {function}
- Source:
Creates a singleton executor of a generator function.
If the function is currently running it will be
terminated with the defaultValue and a new one started.
This would often be used with a UI to cancel a previous calculation
and begin updates on a new one.
Example
const job = singleton(function * (array, value) {
let output = []
for(let item of array) {
if(output.length % 100 === 0) yield
output.push(complexCalculation(array, value))
}
return output
}, [])
function doSomething(array) {
job(array, 2002).then(console.log)
}
doSomething(bigArray)
doSomething(otherArray) // -> console.log([]) from first one
Parameters:
Name |
Type |
Attributes |
Description |
fn |
function
|
|
the generator function to wrap |
defaultValue |
any
|
<optional>
|
a value to be returned if the current execution is
terminated by a new one starting |
Returns:
a function to execute the
generator and return the value
-
Type
-
function
(generator) some(collection, fn) → {Generator.<*, boolean, *>}
- Source:
Example
if(yield * some(collection, yielding(v=>v > 2000)) {
...
}
Parameters:
Name |
Type |
Description |
collection |
Array
|
Object
|
|
fn |
Filter
|
|
Returns:
true if at least one item matched the filter
-
Type
-
Generator.<*, boolean, *>
someAsync(array, fn) → {Promise.<Boolean>}
- Source:
Asynchronously apply an array some
operation
returning a promise for true
if at least
one item matches
Parameters:
Name |
Type |
Description |
array |
Array
|
|
fn |
Filter
|
|
Returns:
promise for true if at least one item matched the filter
-
Type
-
Promise.<Boolean>
sortAsync(array, sort) → {Promise.<Array>}
- Source:
Sort an array (in place) by a sorting function
Sorts an array in place asynchronously. This function is a yielding
implementation of Timsort (standard sort used in modern browsers). Timsort
is fast and stable making it ideal for multi-key sorts. It it not as fast
as Quicksort.
Example
async function process(data) {
return await sortAsync(data, v=>v.someProperty)
}
Parameters:
Returns:
a promise for the sorted array
-
Type
-
Promise.<Array>
stringifyAsync(data) → {Promise.<String>}
- Source:
Asynchronously stringify data into JSON
Parameters:
Name |
Type |
Description |
data |
any
|
Object to store |
Returns:
a Promise for the JSON representation of data
-
Type
-
Promise.<String>
- Source:
Tap into a pipeline to call a function that will probably
perform side effects but should not modify the result, its
return value is ignored
Parameters:
Name |
Type |
Description |
fn |
function
|
a function to be called at this point in
the pipeline |
Returns:
returning the passed in parameters
-
Type
-
AsyncFunction
uniqueBy(array, fnopt) → {Generator.<*, Array, *>}
- Source:
Create an array with the unique values from the
input array, the routine is supplied with a
function that determines on what the array should
be made unique.
Example
const uniqueValues = yield * uniqueBy(records, yielding(r=>r.id))
Parameters:
Name |
Type |
Attributes |
Description |
array |
Array
|
|
|
fn |
Map
|
<optional>
|
the function to determine uniqueness, if
omitted then the item itself is used |
Returns:
-
Type
-
Generator.<*, Array, *>
update(coroutine, …paramsopt) → {Promise.<any>}
- Source:
Start an animation coroutine, the animation will continue until
you return and will be broken up between frames by using a
yield
.
Parameters:
Name |
Type |
Attributes |
Description |
coroutine |
AnimationCoroutine
|
Iterator
|
|
The animation to run |
params |
*
|
<optional>
<repeatable>
|
Parameters to be passed to the animation function |
Returns:
a value that will be returned to the caller
when the animation is complete.
The promise returned by update
has a terminate()
method
that can be used to stop the routine.
-
Type
-
Promise.<any>
useInternalEngine(internal)
- Source:
Call with true to use the polyfilled version of
the idle callback, can be more stable in certain
circumstances
Parameters:
Name |
Type |
Description |
internal |
Boolean
|
|
wrapAsPromise(coroutine) → {PromiseFn|function}
- Source:
Returns a function that will execute the passed
Coroutine and return a Promise for its result. The
returned function will take any number of parameters
and pass them on to the coroutine.
Parameters:
Name |
Type |
Description |
coroutine |
Coroutine
|
The coroutine to run |
Returns:
a function that can be called to execute the coroutine
and return its result on completion
-
Type
-
PromiseFn
|
function
wrapAsPromiseAndYieldFn(fn) → {function}
- Source:
Create a promised function
Parameters:
Name |
Type |
Description |
fn |
function
|
|
Returns:
-
Type
-
function
yielding(fn, frequencyopt) → {Coroutine}
- Source:
Wraps a normal function into a generator function
that yield
s on a regular basis
Parameters:
Name |
Type |
Attributes |
Default |
Description |
fn |
function
|
|
|
the function to be wrapped |
frequency |
number
|
<optional>
|
8
|
the number of times the function should be called
before performing a yield |
Returns:
The wrapped yielding
version of the function passed
-
Type
-
Coroutine
Type Definitions
(generator) AnimationCoroutine()
- Source:
A coroutine to be used in high priority to animate.
Executing a yield
will cause the routine to resume at the start
of the next frame.
Returns:
the result of the function if any to be returned to the caller
(async) AsyncFunction(params) → {*}
- Source:
Parameters:
Name |
Type |
Description |
params |
*
|
the parameters to pass |
Returns:
result of calling the function
-
Type
-
*
(generator) Coroutine() → {number}
- Source:
A coroutine to be run during the gaps in other processing and animation.
The coroutine should yield
regularly to do a time check. A plain yield
will cause
a check against the standard time remaining specified when running. yield {number}
will
check that number
milliseconds are available and yield true
will abandon any more
processing on the current frame.
Returns:
the result of the function if any to be returned to the caller
Yields:
either undefined to perform a standard time remaining check, a number of milliseconds required for the next step or true if we should abandon the current frame
-
Type
-
number
- Source:
Parameters:
Name |
Type |
Description |
item1 |
any
|
|
Returns:
the value to sort item 1 by
-
Type
-
any
Filter(element, index, collection) → {Generator}
- Source:
Parameters:
Name |
Type |
Description |
element |
any
|
|
index |
number
|
|
collection |
Array
|
|
Returns:
a generator for a value of true if included in the filter
-
Type
-
Generator
(generator) GeneratorFunction(…params) → {*}
- Source:
Parameters:
Name |
Type |
Attributes |
Description |
params |
*
|
<repeatable>
|
the parameters to pass |
Returns:
the result of the coroutine
-
Type
-
*
IteratorResult
- Source:
Properties:
Name |
Type |
Attributes |
Description |
value |
any
|
<optional>
|
the returned value |
done |
boolean
|
|
whether the iterator is complete |
Map(element, index, collection) → {any}
- Source:
Parameters:
Name |
Type |
Description |
element |
any
|
|
index |
number
|
|
collection |
Array
|
|
Returns:
updated item
-
Type
-
any
Process(value, key, collection)
- Source:
Parameters:
Name |
Type |
Description |
value |
any
|
the value being processed |
key |
number
|
string
|
the key or index of the value |
collection |
Array
|
the collection being iterated |
PromiseFn(…parametersopt) → {Promise}
- Source:
Parameters:
Name |
Type |
Attributes |
Description |
parameters |
*
|
<optional>
<repeatable>
|
the parameters for the function |
Returns:
a promise for the result of the function
-
Type
-
Promise
Reduce(accumulator, element, index, collection) → {any}
- Source:
Parameters:
Name |
Type |
Description |
accumulator |
any
|
|
element |
any
|
|
index |
number
|
|
collection |
Array
|
|
Returns:
updated value
-
Type
-
any
SortFunction(item1, item2)
- Source:
Parameters:
Name |
Type |
Description |
item1 |
any
|
|
item2 |
any
|
|
Returns:
< 0 if item 2 is bigger than item 1, === 0 if they are the same else > 0