filter-array-of-object

0.1.0 • Public • Published

filter-array-of-object

NPM version build status npm download

The goal is to be able based on input values in n HTML form to easily filter an array of objects.

The field names should have as names the key followed by an underscore and by one of the following possibilities:

  • equals (or nothing): if the value must be an exact match (number or string)
  • min: if the value is a number and must be >= to the value
  • max: if the value is a number and must be <= to the value
  • includes: if the value is a string and should include the value

Installation

$ npm i filter-array-of-object

Usage

import filter from 'filter-array-of-object';

let array = [
  { id: 1, bp: 100, mp: 0, name: 'water' },
  { id: 2, bp: 65, mp: -98, name: 'methanol' },
  { id: 3, bp: 78, mp: -114, name: 'ethanol' },
  { id: 4, bp: 97, mp: -126, name: 'n-propanol' },
  { id: 5, bp: 118, mp: -90, name: 'n-butanol' },
];

const results = filter(array, {
  bp_min: 60,
  bp_max: 100,
  name_includes: 'eth',
});

License

MIT

Readme

Keywords

none

Package Sidebar

Install

npm i filter-array-of-object

Weekly Downloads

1

Version

0.1.0

License

MIT

Unpacked Size

6.14 kB

Total Files

6

Last publish

Collaborators

  • targos
  • lpatiny
  • cheminfo-bot
  • stropitek