0.1.10 • Published 8 years ago
nodeobj-selector v0.1.10
nodeobj-selector
var selector = require('./nodeobj-selector.js')
var mydata = {
a:[{
helo:{
a:1,
b:2
}
},{
helo:{
a:3,
b:4
}
},{
helo:{
a:5,
b:6
}
}]
}
console.log(selector(mydata, ['a','[0:-1]','helo', 'a']))
// [ 1, 3, 5 ]
console.log(selector(mydata, ['a','[1:2]','helo', 'a']))
// [ 3, 5 ]
console.log(selector(mydata, ['helo', 'a']))
// [ 1, 3, 5 ]
console.log(selector(mydata, ['a']))
// [ [ { helo: [Object] }, { helo: [Object] }, { helo: [Object] } ],
// 1,
// 3,
// 5 ]
selector(mydata, ['a', '[0:-1]', 'helo', 'a'], function(data){
console.log(' data: ', data)
return data
})// the function is sync
console.log(JSON.stringify(mydata))
selector(mydata, ['a', '[0:-1]', 'helo', 'a'], function(data){
return null
})
console.log(JSON.stringify(mydata))
selector(mydata, ['a', '[0:-1]', 'helo', 'a'], function(data){
return "123"
})
console.log(JSON.stringify(mydata))
selector(mydata, ['a', '[0:-1]', 'helo', 'a'], function(data){
// remove the object
})
console.log(JSON.stringify(mydata))