Add-on conveniences to make writing Vanilla JavaScript more expressive.
Usage: import { ... } from 'vpweb/stdlib';
Iterator of anything indexable with a length. Skips undefined items.
Parameters:
list
—*
— What to iterate overf(item,i)
—function(*,number):void
— Operation to perform
Create an iterator which will skip undefined items.
Parameters:
f(item,i)
—function(*,number):void
— Operation to perform
Returns: function(*):void
— Function which will iterate over its argument
Iterate over all keys of an object. Does not filter.
Parameters:
obj
—Object
— What to iterate overf(key,value)
—function(string,*):void
— Operation to perform on each key
Filtering mapper of anything indexable with a length, skipping undefined items and undefined callback results.
Parameters:
list
—*
— What to iterate overf(item,i)
—function(*,number):*
— Map an item into another value
Returns: Array
— All non-undefined results of f()
Map an object by key to an array.
Parameters:
obj
—Object
— What to iterate overf(key,value)
—function(string,*):*
— Map a key to another value
Returns: Array
— All results of f()
Fold anything indexable with a length.
Parameters:
list
—*
— What to iterate overacc
—*
— Initial value for your accumulatorf(acc,item,i)
—function(*,*,number):*
— Update accumulator with new value
Shift operation for Array-like objects
Alias of Array.prototype.shift()
Create a function which will shift this array-like thing
Parameters:
list
—Object
— Anything
Returns: function():*
— Function which will shift list at each call
Compare two scalars, returning 1, 0 or -1 depending on whether A is greater than, equal to or less than B.
Parameters:
a
—string|number
b
—string|number
Returns: number
— Result
Compare two things with a callback, returning 1, 0 or -1 depending on whether f(a), both or f(b) are true.
Parameters:
f
—function(*):boolean
— Evaluator
Tests whether something is a plain object (a.k.a. "object literal").
Parameters:
o
—*
— Anything
Returns: boolean
— Result