tnhu / find-object

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

find-object

Find object(s) in a JSON tree.

Install

npm i --save find-object

or

yarn add find-object

Usage

import { findFirst, findAll } from 'find-object'

const users = [
  { user: 'barney',  age: 36, active: true },
  { user: 'fred',    age: 40, active: false },
  { user: 'pebbles', age: 1,  active: true }
]

findFirst(users, { user: 'fred' }) // user[1]
findAll(users, { active: true })   // [ user[0], users[2] ]
findAll(users, { unknown: true })  // []
findAll(users, { age: Object })    // find all objects that have age key, returns shallow copy of users

License

MIT

About

License:MIT License


Languages

Language:TypeScript 100.0%