object-iterate
v0.0.3
Published
make object iterable
Downloads
9
Readme
object-iterate
Iterate over object with
map
,each
andfilter
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 force
API
Iterable.each
iterate over object and evaluate callback
callback params
value
prop valuekey
obviously keyobj
iterable 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
value
prop valuekey
obviously keyobj
iterable object
iterable.
.map((value, key, obj) => {
return key + value
})
Iterable.filter
filtering object calling callback on each prop
callback params
value
prop valuekey
obviously keyobj
iterable 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