Constructor
new Filter(treeopt)
Creates a new Filter
instance.
Parameters
-
tree
Filter
|Filtering.LogicalGroup
<optional>
Create the filter with an existing filter tree object.
Source
Members
LOGIC
Source
OP
Source
dotBoolean
When enabled (default) the Filter will support dot-notation property names, allowing nested object value evaluation. If disabled, dot-notation property names will be treated as the explicit property name.
This only affects the operation of the test
function which evaluates objects with filter criteria.
Type
-
Boolean
Source
treeFiltering.LogicalGroup
Type
Source
Methods
and(property, opopt, valueopt) → {Filter}
Create a new Filter
instance and opening with a logical "and" operator.
Parameters
-
property
String
|Filter
|Filtering.LogicalGroup
|Modeling.PropertyDefinition
The property affected by the filter.
-
op
String
<optional>
The filter operator.
-
value
*
<optional>
The value used by the operator on the property value.
Returns
Source
fromObject(obj) → {Filter}
Creates a new Filter
instance using the object containing a filter tree.
Parameters
-
obj
Filtering.LogicalGroup
The filter tree object.
Returns
Source
isEmpty(filter) → {Boolean}
Checks if the specified filter is empty (contains no logical conditions) and returns a true
if empty, false
if not.
Parameters
-
filter
Filter
|Filtering.LogicalGroup
The filter to check.
Returns
-
Boolean
Source
or(property, opopt, valueopt) → {Filter}
Create a new Filter
instance and opening with a logical "or" operator.
Parameters
-
property
String
|Filter
|Filtering.LogicalGroup
|Modeling.PropertyDefinition
The property affected by the filter.
-
op
String
<optional>
The filter operator.
-
value
*
<optional>
The value used by the operator on the property value.
Returns
Source
parse(input) → {Filter}
Recursive function that parses each "group" it finds into a new Filter
instance.
Parameters
-
input
String
|Array.<ParserToken>
The input string to parse into a new
Filter
instance.
Returns
-
Filter
Returns a
Filter
instance when an input is given. If the input isnull
thennull
is returned.
Throws
SyntaxError if the string is unparsable.
Source
tmpl(inputs, …exp) → {String}
Converts a string template literal with expressions into an quote-escaped filter string. All string expressions in the template literal are escaped.
Note that other characters are still allowed.
Parameters
-
inputs
Array.<String>
The template strings
-
exp
any
<repeatable>
Expressions in the string
Returns
-
String
Example
```js
let fn = 'john';
let ln = 'jane"\'\'';
let x = Filter.tmpl`{FirstName} EQ "${fn}" OR {LastName} CONTAINS "${ln}"`;
console.log(x);
//"{FirstName} EQ "john" OR {LastName} CONTAINS "jane\"\'\'""
```
Source
add(logic, property, opopt, valueopt) → {Filter}
Adds a new condition or filter group to the tree using the given logical operator.
Parameters
-
logic
String
The logical operator.
-
property
String
|Filter
|Filtering.LogicalGroup
|Modeling.PropertyDefinition
The property (name) evaluated by the filter, an existing Filter, or a tokenizable filter string.
-
op
String
<optional>
The filter operator used when the
property
is a property name. -
value
*
<optional>
The value being compared to the evaluated property values using the specified operation.
Returns
Source
and(property, opopt, valueopt) → {Filter}
Adds a new condition using a logical "or" operator.
Parameters
-
property
String
|Filter
|Filtering.LogicalGroup
|Modeling.PropertyDefinition
The property affected by the filter.
-
op
String
<optional>
The filter operator.
-
value
*
<optional>
The value used by the operator on the property value.
Returns
Source
clone() → {Filter}
Creates a clone of this filter.
Note: Instance values on filter items are not deep-cloned.
Returns
Source
or(property, opopt, valueopt) → {Filter}
Adds a new condition using a logical "or" operator.
Parameters
-
property
String
|Filter
|Filtering.LogicalGroup
|Modeling.PropertyDefinition
The property affected by the filter.
-
op
String
<optional>
The filter operator.
-
value
*
<optional>
The value used by the operator on the property value.
Returns
Source
test(…models) → {Boolean}
Tests the filter criteria against the specified object(s). If any object fails a filter, or no objects are
specified, a false
value is returned. If all objects pass the filters, a true
value is returned.
Parameters
-
models
Model
<repeatable>
The objects to test the filter against.
Returns
-
Boolean
Source
toJSON() → {Filtering.LogicalGroup}
Returns the tree object to be utilized for stringifying into JSON.
Returns
Source
toString(fgopt) → {String}
Converts the filter to a readable string.
Parameters
-
fg
Filtering.LogicalGroup
|Filtering.Condition
<optional>
Optional filter condition or filter group to convert to a string.
Returns
-
String
Source
walk(cb)
Walks the tree of the filter and calls the callback for each logical group and condition.
Parameters
-
cb
Filtering.WalkCallback
The callback.