import { CallExpr } from "../Expr" ; import { ExprEvaluatorContext , OperatorDescriptorMap } from "../ExprEvaluator" ; const operators = { concat : { call : ( context , call ) => { return "" . concat ( ... call . args . map ( a => String ( context . evaluate ( a ) ) ) ) ; } } , downcase : { call : ( context , call ) => { return String ( context . evaluate ( call . args [ 0 ] ) ) . toLocaleLowerCase ( ) ; } } , upcase : { call : ( context , call ) => { return String ( context . evaluate ( call . args [ 0 ] ) ) . toLocaleUpperCase ( ) ; } } , "~=" : { call : ( context , call ) => { const left = context . evaluate ( call . args [ 0 ] ) ; const right = context . evaluate ( call . args [ 1 ] ) ; if ( typeof left === "string" && typeof right === "string" ) { return left . includes ( right ) ; } return false ; } } , "^=" : { call : ( context , call ) => { const left = context . evaluate ( call . args [ 0 ] ) ; const right = context . evaluate ( call . args [ 1 ] ) ; if ( typeof left === "string" && typeof right === "string" ) { return left . startsWith ( right ) ; } return false ; } } , "$=" : { call : ( context , call ) => { const left = context . evaluate ( call . args [ 0 ] ) ; const right = context . evaluate ( call . args [ 1 ] ) ; if ( typeof left === "string" && typeof right === "string" ) { return left . endsWith ( right ) ; } return false ; } } } ; export const StringOperators = operators ; export type StringOperatorNames = keyof typeof operators ;