Registry / database / sql-strip-comments

sql-strip-comments

JSON →
library0.0.23jsnpmunverified

A zero-dependency library to remove line (-- ...) and block (/* ... */) comments from SQL code. Version 0.0.23 is the latest as of the metadata snapshot; the package sees low to moderate releases (last update appears 2020). Differentiators: it correctly ignores comments inside string literals, and does not treat adjacent operators like `--` as comment markers when inside double-quoted strings. Works in Node.js and browsers. Alternative to regex-based solutions that often break on edge cases with strings or multiline comments.

npm install sql-strip-comments
INSTALL
IMPORT
SIG · SQL-STRIP-COMMENTS
S
sql-strip-comments
databasejavascriptv0.0.23
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.

strip (default function)
import strip from 'sql-strip-comments'
const strip = require('sql-strip-comments')
Package is ESM-only starting from v0.0.23. Use import for ESM, require for CJS will fail unless you use a bundler that interops.
strip (default require)
const strip = require('sql-strip-comments')
const { strip } = require('sql-strip-comments')
The package exports a single function as default. Destructuring will give undefined.
TypeScript usage
import strip from 'sql-strip-comments'
import { strip } from 'sql-strip-comments'
Package does not ship TypeScript declarations; use @types/sql-strip-comments or declare module.

Demonstrates removing both line and block comments from SQL, preserving newlines and string literals.

import strip from 'sql-strip-comments'; const sql = ` SELECT * FROM customers -- comment line WHERE id = 1 /* block comment */ `; console.log(strip(sql)); // Output: // // SELECT * // FROM customers // // WHERE id = 1
Debug
Known issues
breakingPackage switched from CJS to ESM in v0.0.23, breaking require() in Node.js without bundler.
fix
Use dynamic import() or switch to bundler that supports ESM. Alternatively pin to v0.0.22.
affects: >=0.0.23
gotchaNested block comments (e.g., /* /* inner */ */) are not supported and may produce incorrect output.
fix
Avoid nested block comments in SQL input, or preprocess to handle such cases.
affects: *
gotchaString literals containing comment-like patterns are preserved correctly, but only for double-quoted strings. Single-quoted strings are not checked.
fix
If your SQL uses single quotes for identifiers or strings, test edge cases.
affects: *
Errors
Common errors & fixes
TypeError: strip is not a function
Using destructured import from default export.
fix
Use `import strip from 'sql-strip-comments'` instead of `import { strip }...`
ERR_REQUIRE_ESM
Using require() with ESM-only version.
fix
Upgrade Node to 12+ and use dynamic import, or downgrade to v0.0.22.
SQL syntax error: unexpected comment removal
Nested block comments were present and incorrectly processed.
fix
Remove nested comments manually or use alternative library.
Upgrade
Version history
0.0.23latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
11 hits · last 30 days
node
8
Meta
1
OpenAI (training)
1
Resources
sql-strip-comments — npm install sql-strip-comments · libregistry