0.0.3 • Published 9 years ago
object-iterate v0.0.3
object-iterate
Iterate over object with
map,eachandfilter
Usage
$ npm i object-iterate const Iterable = require('object-iterate')
var o =
Iterable({a: 'a', b: 'b', c: true})
// get only props that have boolean values
.filter((value, key, obj) => {
return typeof value === 'string'
})
// map object by concating key and value
.map((value, key, obj) => {
return key + value
})
// log each new value
.each(function (value, key, obj) => {
console.log(value)
})
// Object.keys cached for better experience,
// so for deleting/setting props and also better perfomance,
// it is better to use builtin methods like set, kill, forceKill
o.kill(a)
// will remove a from object, ! but wont update cache
// so if u then iterate over object with each or map you will get a as undefined
o.force()
// reinit cache calling Object.keys, so now it's actually up-to-date
o.forceKill(b) // will kill and call forceAPI
Iterable.each
iterate over object and evaluate callback
callback params
valueprop valuekeyobviously keyobjiterable object
iterable.
.each((value, key, obj) => {
console.log(value)
})Iterable.map
map over object and return new object calling callback on each prop
callback params
valueprop valuekeyobviously keyobjiterable object
iterable.
.map((value, key, obj) => {
return key + value
})Iterable.filter
filtering object calling callback on each prop
callback params
valueprop valuekeyobviously keyobjiterable object
iterable.
.filter((value, key, obj) => {
return key + value
})Iterable.set
set new prop on object
iterable.set('dev', true)Iterable.kill
delete prop on object, but not force cache revaluating
iterable.kill('dev')Iterable.force
reinitializing cached variables
iterable.kill('dev').force()Iterable.forceKill
helper for kill + force combo
iterable.forceKill('dev')##license MIT