1.0.2 • Published 2 years ago

search-property v1.0.2

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

Search Property npm version

Simple package that finds any property on an object.

searchProperty() does a nested search, so you don't have to implement any custom code for deep searches.

Technology

TypeScript JavaScript

Quick links

Installation

npm install search-property

Examples

import { searchProperty, searchPropertyAll, searchProperties, searchPropertiesAll } from 'search-property'

const myObject = {
    id: 1,
    name: 'someName',
    nestedObject: {
        id: 2,
        colour: 'red',
        anotherNest: {
            id: 3,
            name: 'anotherName',
            speed: '50 km/h'
        }
    }
}

searchProperty('id', myObject)      // 1
searchProperty('speed', myObject)   // '50 km/h'

searchPropertyAll('id', myObject)   // [1, 2, 3]
searchPropertyAll('name', myObject) // ['someName', 'anotherName']

searchProperties(['id', 'speed'], myObject)    // [1, '50 km/h']

searchPropertiesAll(['id', 'speed'], myObject) // [[ 1, 2, 3], ['50 km/h']]

Contributors

View the full list of contributors.