filter-value

3.1.1 • Public • Published

FILTER VALUE

Filter value is engine for filtering data by it's value

Installation

npm install --save filter-value

Example Usage

import FilterValue from 'filter-value';
var FilterValue = require('filter-value');

Example data

const a = [
    {
        'column1': 1,
        'column2': false,
        'column3': 'test',
    }, {
        'column1': 2,
        'column2': true,
        'column3': 'test2',
    }
]

Constructor

Creating new Filter value instance

    const filterValue = new FilterValue();
    const filterValue2 = new FilterValue(name);
    const filterValue3 = new FilterValue(name, value);
    const filterValue4 = new FilterValue(name, value, staticType);

Name

    filterValue.Name = 'new Name';
    const name = filterValue.Name;

Value

Valid values:

  • String
  • Number
  • Date
  • Function
  • Boolean
  • Regexp
  • Null
  • Array
    filterValue.Value = 'new value';
    const value = filterValue.Value;

Range filter

Range filter can be used with one value, which will filter smaller or bigger values.

Valid value for range

  • Number
  • String
  • Date*

Note: *Date will try to create date from given item in array if item isn't instance of Date

    filterValue.Value = {
        from: new Date(),
        to: new Date()
    };
 
    filterValue.Value = {
        from: new Date(),
        to: null
    };
 
    filterValue.Value = {
        from: null,
        to: new Date()
    };

Array filter

Array filter can be variety of types

Valid values for array

  • String
  • Number
  • Date
  • Function
  • Boolean
  • Regexp
  • Null

Limitations

Only one dimensional array can be used

    filterValue.Value = [
        'yes',
        false,
        null,
        new Date()
    ]

Type

When type is set value will automatically retype to chosen type. It's possible to get original value, example is shown below.

Valid types

  • Boolean
  • Date*
  • Number
  • Regexp**
  • String

*It's used native function new Date(arg)

**Using native function new RegExp() with escaping characters

    filterValue.Type = 'string';
    filterValue.removeType();
    const originalValue = filterValue.Original;
    const type = filterValue.Type;

Package Sidebar

Install

npm i filter-value

Weekly Downloads

3

Version

3.1.1

License

MIT

Unpacked Size

38.2 kB

Total Files

8

Last publish

Collaborators

  • silhan.jan