Nabbing Pleasant Monads

    filter-obj
    TypeScript icon, indicating that this package has built-in type declarations

    3.0.0 • Public • Published

    filter-obj

    Filter object keys and values into a new object

    Install

    $ npm install filter-obj
    

    Usage

    import filterObject from 'filter-obj';
    
    const object = {
    	foo: true,
    	bar: false
    };
    
    const newObject = filterObject(object, (key, value) => value === true);
    //=> {foo: true}
    
    const newObject2 = filterObject(object, ['bar']);
    //=> {bar: false}

    API

    filterObject(source, filter)

    filterObject(source, includeKeys)

    source

    Type: object

    The source object to filter properties from.

    filter

    Type: (sourceKey, sourceValue, source) => boolean

    A predicate function that detemines whether a property should be assigned to the new object.

    includeKeys

    Type: string[]

    An array of property names that should be assigned to the new object.

    Related

    • map-obj - Map object keys and values into a new object

    Install

    npm i filter-obj

    DownloadsWeekly Downloads

    5,329,650

    Version

    3.0.0

    License

    MIT

    Unpacked Size

    4.17 kB

    Total Files

    5

    Last publish

    Collaborators

    • sindresorhus