Registry / database / sql-match

sql-match

JSON →
library2.0.0jsnpmunverified

A spec-compliant implementation of SQL LIKE pattern matching for Node.js (version 2.0.0). It supports % and _ wildcards with backslash escaping, matching JavaScript strings against SQL-like patterns. No external dependencies. Released as an ESM-only module since v2.0.0. Differentiators: lightweight, no dependencies, simple API with two functions (isSQLMatch, sqlToRegex) for direct comparison or reusable regex creation. Not actively maintained, but API stable.

npm install sql-match
INSTALL
IMPORT
SIG · SQL-MATCH
S
sql-match
databasejavascriptv2.0.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

isSQLMatch
import { isSQLMatch } from 'sql-match'
const { isSQLMatch } = require('sql-match')
ESM-only since v2.0.0. CommonJS require() will fail with ERR_REQUIRE_ESM.
sqlToRegex
import { sqlToRegex } from 'sql-match'
const sqlToRegex = require('sql-match').sqlToRegex
Same ESM restriction as isSQLMatch.
default import
import sqlMatch from 'sql-match'
const sqlMatch = require('sql-match')
CommonJS require() returns undefined because there is no default export. Only named exports exist.

Shows both direct string matching with isSQLMatch and reusable regex with sqlToRegex, including wildcards and escaping.

import { isSQLMatch, sqlToRegex } from 'sql-match'; // Direct comparison console.log(isSQLMatch('string', 'string')); // true console.log(isSQLMatch('%ing', 'string')); // true console.log(isSQLMatch('_tring', 'string')); // true console.log(isSQLMatch('%', 'anything')); // true console.log(isSQLMatch('_', 'a')); // true console.log(isSQLMatch('\\%', '%')); // true (escaped literal %) // Reusable regex const pattern = sqlToRegex('%ing'); console.log(['string', 'stringing'].every(s => pattern.test(s))); // true
Debug
Known issues
breakingVersion 2.0.0 switched to ESM-only; CommonJS require() throws ERR_REQUIRE_ESM.
fix
Use import { ... } from 'sql-match' or update Node to >=12 (for ESM support) and switch to dynamic import.
affects: >=2.0.0
gotchaJavaScript string interpretation can cause unexpected escape sequences. For example, isSQLMatch('\t', 't') returns true because '\t' is interpreted as tab character in non-raw string.
fix
Use String.raw to avoid interpretation: isSQLMatch(String.raw`\t`, 't') returns true.
affects: *
gotchaMatching a literal backslash requires four backslashes in non-raw strings: '\\\\' matches single backslash.
fix
Use String.raw`\\` to match a single backslash.
affects: *
Errors
Common errors & fixes
ERR_REQUIRE_ESM
Using require() on an ESM-only module (v2.0.0+).
fix
Replace require('sql-match') with import { isSQLMatch } from 'sql-match'.
TypeError: sqlMatch is not a function
Default import does not exist; only named exports are available.
fix
Use import { isSQLMatch } from 'sql-match' instead of import sqlMatch from 'sql-match'.
Upgrade
Version history
2.0.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
19 hits · last 30 days
node
14
Meta
2
OpenAI (training)
1
Resources
sql-match — npm install sql-match · libregistry