Skip to content

Instantly share code, notes, and snippets.

@WimJongeneel
Created December 29, 2019 13:26
Show Gist options
  • Save WimJongeneel/db7b79719b5f6af73cdd742799af0f8d to your computer and use it in GitHub Desktop.
Save WimJongeneel/db7b79719b5f6af73cdd742799af0f8d to your computer and use it in GitHub Desktop.
class ExprBuilder {
constructor(protected ast: Expr) { }
GetExpr = () => this.ast
equals(v: string | number | boolean | ExprBuilder) {
if (['string', 'number', 'boolean'].indexOf(typeof v) != -1) {
return new ExprBuilder(createBinaryExpression('==', this.ast, createValExpression(v)))
}
return new ExprBuilder(createBinaryExpression('==', this.ast, (v as ExprBuilder).GetExpr()))
}
and(e: ExprBuilder) {
return new ExprBuilder((createBinaryExpression('&&', this.ast, e.GetExpr())))
}
includes(e: ExprBuilder| string) {
if (typeof e == 'string')
return new ExprBuilder(createBinaryExpression('includes', this.ast, createValExpression(e)))
return new ExprBuilder(createBinaryExpression('includes', this.ast, e.GetExpr()))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment