Skip to content

Commit

Permalink
Support boolean.
Browse files Browse the repository at this point in the history
  • Loading branch information
domoritz committed Aug 2, 2018
1 parent 30a713f commit 7e71d53
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/predicate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,10 @@ export interface FieldOneOfPredicate extends FieldPredicateBase {
}

export interface FieldValidPredicate extends FieldPredicateBase {
valid: true;
/**
* If set to true the field's value has to be valid, meaning both not `null` and not [`NaN`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NaN).
*/
valid: boolean;
}

export function isFieldOneOfPredicate(predicate: any): predicate is FieldOneOfPredicate {
Expand Down Expand Up @@ -228,7 +231,7 @@ export function fieldFilterExpression(predicate: FieldPredicate, useInRange = tr
} else if (isFieldOneOfPredicate(predicate)) {
return `indexof([${predicateValuesExpr(predicate.oneOf, timeUnit).join(',')}], ${fieldExpr}) !== -1`;
} else if (isFieldValidPredicate(predicate)) {
return `${fieldExpr}!==null&&!isNaN(${fieldExpr})`;
return predicate.valid ? `${fieldExpr}!==null&&!isNaN(${fieldExpr})` : `${fieldExpr}===null||isNaN(${fieldExpr})`;
} else if (isFieldRangePredicate(predicate)) {
const lower = predicate.range[0];
const upper = predicate.range[1];
Expand Down

0 comments on commit 7e71d53

Please sign in to comment.