packages/nql-string/README.md
Escape values for safe embedding in NQL filters.
escapeNqlString('can\'t stop');
// => "'can\\'t stop'"
`title:~${escapeNqlString(searchTerm)}`
The return value includes the surrounding quotes, so interpolate it directly rather than adding your own.
NQL delimits string values with quotes, so any value reaching a filter
unescaped can terminate the string literal early and break the parser — a URL
with a trailing ', or a post title containing ", is enough to make a filter
unparseable.
Two rules are easy to get wrong, which is why this is shared rather than reimplemented per app:
" inside a single-quoted string.\' and
\" — there is no \\ — so a lone backslash is a literal character and
doubling it would query a different value.The value must be non-empty: NQL's string rule requires at least one character.
This is a monorepo package.
Follow the instructions for the top-level repo.
git clone this repo & cd into it as usualpnpm to install top-level dependencies.pnpm lint run eslintpnpm test run the unit tests and typecheck