import Entity from "../entity/entity" ; import Search from "./search" ; import WhereField from "./where-field" ; export default class WhereText < TEntity extends Entity > extends WhereField < TEntity > { private value ! : string ; private exactValue = false ; match ( value ) { this . value = value ; return this . search ; } matchExact ( value ) { this . exact . value = value ; return this . search ; } matches ( value ) { return this . match ( value ) ; } matchExactly ( value ) { return this . matchExact ( value ) ; } matchesExactly ( value ) { return this . matchExact ( value ) ; } get exact ( ) { this . exactValue = true ; return this ; } get exactly ( ) { return this . exact ; } toString ( ) { let matchPunctuation = /[,.<>{}[\]"':;!@#$%^&*()\-+=~|]/g ; let escapedValue = this . value . replace ( matchPunctuation , '\\$&' ) ; if ( this . exactValue ) { return this . buildQuery ( `"${ escapedValue }"` ) ; } else { return this . buildQuery ( `'${ escapedValue }'` ) ; } } }