2.0.0 • Published 7 years ago

filtero v2.0.0

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

filtero

Build Status npm version

Fileter an object by your own rule (function) which received keys and values of the object as parameters. Returns a filtered new object.

Install

npm i filtero -S

Syntax

filtero(obj, compareFunction [, thisArg])

obj

Target object to be filtered

compareFunction

A function that defines the filtering rule. It will have key and value as parameters while iterating the object. If the function returns a truthy value. The current key/value pair will be reserved in the returning object, and vice versa.

thisArg optional

The value of this provided for the call to compareFunction.

Usage

import filtero from 'filtero'

const obj = {
  a: 1,
  b: 2,
  c: 3,
  d: 'D'
}

filtero(obj, (k, v) => k === 'a')
// { a: 1 }

filtero(obj, (k, v) => ['b', 'c'].indexOf(k) >= 0)
// { b: 2, c: 3 }

filtero(obj, (k, v) => typeof v === 'string')
// { d: 'D' }
2.0.0

7 years ago

1.1.1

7 years ago

1.1.0

7 years ago

1.0.5

7 years ago

1.0.4

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago