filter-value
v3.1.1
Published
Data engine is small data management lib for some sort and filter.
Downloads
12
Maintainers
Readme
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;