{"id":43907,"library":"sql-highlight","title":"sql-highlight","description":"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.","status":"active","version":"6.1.0","language":"javascript","source_language":"en","source_url":"ssh://git@github.com/scriptcoded/sql-highlight","tags":["javascript","sql","syntax","highlight","highlighter","typescript"],"install":[{"cmd":"npm install sql-highlight","lang":"bash","label":"npm"},{"cmd":"yarn add sql-highlight","lang":"bash","label":"yarn"},{"cmd":"pnpm add sql-highlight","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"highlight is a named export, not a default export.","wrong":"import highlight from 'sql-highlight'","symbol":"highlight","correct":"import { highlight } from 'sql-highlight'"},{"note":"CommonJS require works, but ESM import is preferred for tree-shaking.","wrong":"const getSegments = require('sql-highlight').getSegments","symbol":"getSegments","correct":"import { getSegments } from 'sql-highlight'"},{"note":"HighlightOptions is a TypeScript type, not a runtime value.","wrong":"import { HighlightOptions } from 'sql-highlight'","symbol":"HighlightOptions","correct":"import type { HighlightOptions } from 'sql-highlight'"}],"quickstart":{"code":"import { highlight } from 'sql-highlight';\n\nconst sql = `SELECT * FROM users WHERE age > 18 ORDER BY name ASC`;\nconst html = highlight(sql, { html: true, classPrefix: 'sql-' });\ndocument.getElementById('output').innerHTML = html;","lang":"typescript","description":"Highlights a SQL query as HTML with custom CSS class prefix and inserts it into a DOM element."},"warnings":[{"fix":"npm install sql-highlight@latest","message":"Version 5.0.0 was prematurely released and has known issues; upgrade to 6.0.0+.","severity":"deprecated","affected_versions":">=5.0.0 <6.0.0"},{"fix":"Use a library like lodash.escape or the DOM's createTextNode for escaping.","message":"The default HTML escaper is basic and may not cover all edge cases; provide a custom escaper for XSS-sensitive contexts.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Update Node.js to version 14 or later, or use an older version of the library (e.g., 4.x).","message":"Requires Node.js >=14; older versions will throw an error on import.","severity":"gotcha","affected_versions":"<6.0.0"}],"env_vars":null,"search_vec":"'6.1.0':27 'activ':28 'altern':60 'ansi':17 'api':45 'beyond':79 'built':82 'built-in':81 'code':19 'css':75 'current':23 'custom':56 'definit':40 'depend':37 'escap':18 'focus':68 'frequent':31 'function':50 'getseg':53 'grammar':78 'heavier':59 'highlight':3,11,49,67,88,89 'highlight.js':64 'html':21 'javascript':6,85 'languag':77 'librari':7 'like':61 'maintain':29 'method':54 'offer':42 'output':22 'parser':84 'prism':62 'pure':5 'queri':13 'releas':32 'render':57 'requir':73 'runtim':36 'ship':38 'simpl':44 'singl':48 'sole':69 'sql':2,12,66,71,86 'sql-highlight':1,65 'stabl':24 'support':14 'syntax':10,87 'syntax-highlight':9 'termin':16 'typescript':39,90 'unlik':58 'version':25 'zero':35","created_at":"2026-06-05T17:02:03.251584+00:00","updated_at":"2026-06-05T17:02:03.251584+00:00","problems":[{"fix":"Add \"type\": \"module\" to package.json, or use require('sql-highlight') instead.","cause":"Using ES import syntax in a CommonJS file or without \"type\": \"module\" in package.json.","error":"SyntaxError: Cannot use import statement outside a module"},{"fix":"Use import { highlight } from 'sql-highlight'.","cause":"Default import used instead of named import.","error":"TypeError: highlight is not a function"},{"fix":"Run npm install sql-highlight and ensure the import path is 'sql-highlight' (not a relative path).","cause":"Package not installed or import path is incorrect.","error":"Module not found: Can't resolve 'sql-highlight'"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://github.com/scriptcoded/sql-highlight#readme","github":"ssh://git@github.com/scriptcoded/sql-highlight","docs":null,"changelog":null,"pypi":null,"npm":"sql-highlight","openapi_spec":null,"status_page":null,"smithery":null,"categories":["productivity"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-05","next_check":"2026-09-03","install_tag":null}}