Registry / productivity / sql-highlight

sql-highlight

JSON →
library6.1.0jsnpmunverified

A pure JavaScript library for syntax-highlighting SQL queries, supporting both terminal (ANSI escape codes) and HTML output. Current stable version is 6.1.0, actively maintained with frequent releases. It has zero runtime dependencies, ships TypeScript definitions, and offers a simple API with a single highlight function and a getSegments method for custom rendering. Unlike heavier alternatives like Prism or highlight.js, sql-highlight focuses solely on SQL and requires no CSS or language grammars beyond its built-in parser.

npm install sql-highlight
INSTALL
IMPORT
SIG · SQL-HIGHLIGHT
S
sql-highlight
productivityjavascriptv6.1.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.

highlight
import { highlight } from 'sql-highlight'
import highlight from 'sql-highlight'
highlight is a named export, not a default export.
getSegments
import { getSegments } from 'sql-highlight'
const getSegments = require('sql-highlight').getSegments
CommonJS require works, but ESM import is preferred for tree-shaking.
HighlightOptions
import type { HighlightOptions } from 'sql-highlight'
import { HighlightOptions } from 'sql-highlight'
HighlightOptions is a TypeScript type, not a runtime value.

Highlights a SQL query as HTML with custom CSS class prefix and inserts it into a DOM element.

import { highlight } from 'sql-highlight'; const sql = `SELECT * FROM users WHERE age > 18 ORDER BY name ASC`; const html = highlight(sql, { html: true, classPrefix: 'sql-' }); document.getElementById('output').innerHTML = html;
Debug
Known issues
deprecatedVersion 5.0.0 was prematurely released and has known issues; upgrade to 6.0.0+.
fix
npm install sql-highlight@latest
affects: >=5.0.0 <6.0.0
gotchaThe default HTML escaper is basic and may not cover all edge cases; provide a custom escaper for XSS-sensitive contexts.
fix
Use a library like lodash.escape or the DOM's createTextNode for escaping.
affects: >=1.0.0
gotchaRequires Node.js >=14; older versions will throw an error on import.
fix
Update Node.js to version 14 or later, or use an older version of the library (e.g., 4.x).
affects: <6.0.0
Errors
Common errors & fixes
SyntaxError: Cannot use import statement outside a module
Using ES import syntax in a CommonJS file or without "type": "module" in package.json.
fix
Add "type": "module" to package.json, or use require('sql-highlight') instead.
TypeError: highlight is not a function
Default import used instead of named import.
fix
Use import { highlight } from 'sql-highlight'.
Module not found: Can't resolve 'sql-highlight'
Package not installed or import path is incorrect.
fix
Run npm install sql-highlight and ensure the import path is 'sql-highlight' (not a relative path).
Upgrade
Version history
6.1.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
26 hits · last 30 days
node
22
OpenAI (training)
1
Resources
sql-highlight — npm install sql-highlight · libregistry