Wondering what’s next for npm?Check out our public roadmap! »

    @arnaudnyc/object-filter

    1.0.2 • Public • Published

    Object Filter

    Coverage Status

    Creates a copy of an object containing all elements for which the provided filter callback returns true.

    Like Array.prototype.filter() but for objects.

    This project has no dependencies.

    Installation

    npm

    npm install @arnaudnyc/object-filter

    yarn

    yarn add @arnaudnyc/object-filter

    Usage

    const objectFilter = require('@arnaudnyc/object-filter');
    
    const object = {
      keep: 'yes',
      discard: 'no',
    };
    
    const filteredByProperty = objectFilter(object, property => property === 'keep');
    console.log('filteredByProperty:', filteredByProperty); // filteredByProperty: { keep: 'yes' }
    
    const filteredByValue = objectFilter(object, (property, value) => value === 'yes');
    console.log('filteredByValue:', filteredByValue); // filteredByValue: { keep: 'yes' }
    
    // no mutation
    console.log('object:', object); // object: { keep: 'yes', discard: 'no' }
    

    Testing

    npm test or yarn test

    Credits

    Made with ❤️ in 🗽

    License

    MIT

    Install

    npm i @arnaudnyc/object-filter

    DownloadsWeekly Downloads

    109

    Version

    1.0.2

    License

    MIT

    Unpacked Size

    6.57 kB

    Total Files

    8

    Last publish

    Collaborators

    • avatar