@AppKu/StashKu

@AppKu/StashKu

v1.0.46

Class

Filter

The Filter represents a conditional expression. That is, a tree of conditions that can be used to filter objects and data based on "properties", "operations", and "values" in logical "and" "or" groupings.

Constructor

new Filter(treeopt)

Creates a new Filter instance.

Parameters

Source

Members

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

Methods

static

isEmpty(filter) → {Boolean}

Checks if the specified filter is empty (contains no logical conditions) and returns a true if empty, false if not.

Parameters

Returns

  • Boolean

Source

static

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 is null then null is returned.

Throws

SyntaxError if the string is unparsable.

Source

static

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

clone() → {Filter}

Creates a clone of this filter.

Note: Instance values on filter items are not deep-cloned.

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