Skip to content

Commit

Permalink
Merge pull request #121 from KaiVolland/function-expressions
Browse files Browse the repository at this point in the history
Introduces StrMatchesFunctionFilter
  • Loading branch information
KaiVolland authored May 17, 2019
2 parents d3fa1cd + 551d732 commit 41704e1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
18 changes: 17 additions & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,29 @@ export type Operator = ComparisonOperator | CombinationOperator | NegationOperat
*/
export interface Filter extends Array<any> {}

/**
* A FunctionFilter that expects a string (propertyName) as second arguement and
* a regular expression as third argument. An actual parser implementation has to
* return a value for this function expression.
*/
export interface StrMatchesFunctionFilter extends Filter {
0: 'FN_strMatches';
1: string;
2: RegExp;
}

/**
* A Filter that expresses a function.
*/
export type FunctionFilter = StrMatchesFunctionFilter;

/**
* A ComparisonFilter compares a value of an object (by key) with an expected
* value.
*/
export interface ComparisonFilter extends Filter {
0: ComparisonOperator;
1: string;
1: string | FunctionFilter;
2: string|number|boolean|null;
}

Expand Down
2 changes: 1 addition & 1 deletion sample.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const sampleStyle: Style = {
{
name: 'Twelve year old Peter',
filter: ['&&',
['==', 'name', 'Peter'],
['==', ['FN_strMatches', 'name', /Peter/], true],
['==', 'age', 12]
],
scaleDenominator: {
Expand Down

0 comments on commit 41704e1

Please sign in to comment.