Search attributes easily within structures of type dictionary, list and embedded substructures with simple format 'dict.users.0.name'.
npm install deepfinder
const { deepFind } = require('deepfinder')
const user = {
name: 'ash',
links: {
pokehub: '@ash',
},
}
console.log(deepFind(user, 'links.pokehub'))
// output: '@ash'
const { deepFind } = require('deepfinder')
const user = {
name: 'ash',
pokemons: [{
name: 'pikachu',
},{
name: 'charmander',
}],
}
console.log(deepFind(user, 'pokemons.0.name'))
// output: 'pikachu'
const { deepFind } = require('deepfinder')
const user = {
name: 'ash',
pokemons: [{
name: 'pikachu',
},{
name: 'charmander',
}],
}
console.log(deepFind(user, 'pokemons.*.name'))
// output: ['pikachu', 'charmander']
const { deepFind } = require('deepfinder')
const user = {
name: 'ash',
pokemons: [{
name: 'pikachu',
},{
name: 'charmander',
ball: 'superball'
}],
}
console.log(deepFind(user, 'pokemons.?.ball'))
// output: 'superball'
Disclaimer: use this useful, optional and dangerous practice at your own risk.
const DeepFinder = require('deepfinder')
DeepFinder.nativify()
const pokemon = { name: 'mew' }
console.log(pokemon.deepFind('name'))
// output: 'mew'