/** * Builds the patterns of the search queries' `LIKE`, for the dump, playlist * and user searches. A query's `%` and `_` are matched as themselves rather * than as wildcards: usernames hold underscores, and "a_b" must not find * "axb". * * @module */ /** * Returns the pattern matching text that contains `query`, or that starts * with it when `where` is `"prefix"`. The SQL must read `LIKE ? ESCAPE '\'`, * which the {@link LIKE} fragment spells. */ export function likePattern( query: string, where: "anywhere" | "prefix" = "anywhere", ): string { const escaped = query.replace(/[\\%_]/g, "\\$&"); return where === "prefix" ? `${escaped}%` : `%${escaped}%`; } /** Spells `LIKE ? ESCAPE '\'`, for a {@link likePattern} parameter. */ export const LIKE = "LIKE ? ESCAPE '\\'";