Skip to content

escapeLike

function escapeLike(value): string;

Defined in: filters/compile.ts:73

Escape the LIKE/ILIKE wildcards (%, _) and the escape character itself (\) with a backslash, so a user’s text matches literally — used by the contains/startsWith/endsWith affordances. Backslash is Postgres’s default LIKE escape; the kysely/knex adapters add an ESCAPE clause on SQLite (no default escape) and MySQL (none under NO_BACKSLASH_ESCAPES). Using it yourself on SQLite, add ESCAPE '\' to your LIKE.

Parameter Type
value string

string

import { escapeLike } from "@xtandard/lib/filters";
escapeLike("50%_off"); // → "50\\%\\_off" (prints as 50\%\_off)
const pattern = `%${escapeLike("50%")}%`; // a literal "50%" anywhere