diff --git a/index.d.ts b/index.d.ts index 1d5fd982c..991745726 100644 --- a/index.d.ts +++ b/index.d.ts @@ -43,13 +43,29 @@ export type Operator = ComparisonOperator | CombinationOperator | NegationOperat */ export interface Filter extends Array {} +/** + * 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; } diff --git a/sample.ts b/sample.ts index b687d6636..4da6ea411 100644 --- a/sample.ts +++ b/sample.ts @@ -37,7 +37,7 @@ const sampleStyle: Style = { { name: 'Twelve year old Peter', filter: ['&&', - ['==', 'name', 'Peter'], + ['==', ['FN_strMatches', 'name', /Peter/], true], ['==', 'age', 12] ], scaleDenominator: {