![Oracle Drags Its Feet in the JavaScript Trademark Dispute](https://cdn.sanity.io/images/cgdhsj6q/production/919c3b22c24f93884c548d60cbb338e819ff2435-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
sql-highlight
Advanced tools
A simple and lightweight SQL syntax highlighting library written in pure JavaScript
SQL Highlight is a small package that highlights SQL queries. It can output to both the terminal with Unicode escape sequences, as well as to normal HTML. Oh, and there are no external dependencies 😉
Install via Yarn:
yarn add sql-highlight
Install via NPM:
npm install sql-highlight
In its most basic form:
const { highlight } = require('sql-highlight')
const sqlString = "SELECT `id`, `username` FROM `users` WHERE `email` = 'test@example.com'"
const highlighted = highlight(sqlString)
console.log(highlighted)
Output:
HTML mode:
import { highlight } from 'sql-highlight'
const sqlString = "SELECT `id`, `username` FROM `users` WHERE `email` = 'test@example.com'"
const highlighted = highlight(sqlString, {
html: true
})
document.body.innerHTML += highlighted
Output:
<span class="sql-hl-keyword">SELECT</span>
<span class="sql-hl-string">`id`</span>
<span class="sql-hl-special">,</span>
<span class="sql-hl-string">`username`</span>
<span class="sql-hl-keyword">FROM</span>
<span class="sql-hl-string">`users`</span>
<span class="sql-hl-keyword">WHERE</span>
<span class="sql-hl-string">`email`</span>
<span class="sql-hl-special">=</span>
<span class="sql-hl-string">'test@example.com'</span>
The following options may be passed to the highlight
function.
Option | Value | Default | Description |
---|---|---|---|
html | boolean | false | Set to true to render HTML instead of Unicode. |
classPrefix | string | 'sql-hl-' | Prefix to prepend to classes for HTML span-tags. Is appended with entity name. |
colors | Object | See below* | What color codes to use for Unicode rendering. |
* colors
option default value
{
keyword: '\x1b[35m', // SQL reserved keywords
function: '\x1b[31m', // Functions
number: '\x1b[32m', // Numbers
string: '\x1b[32m', // Strings
special: '\x1b[33m', // Special characters
bracket: '\x1b[33m', // Brackets (parentheses)
clear: '\x1b[0m' // Clear (inserted after each match)
}
See the contribution guidelines.
We use Jest for running our tests. The test suite can be run by running npm run test
. This will run both Jest and ESLint.
We use ESLint for making sure that our code remains pretty and consistent throughout the project. If your editor doesn't automatically pick up our config you can lint the code using npm run lint
.
Malcolm Nihlén - malcolm.nihlen@gmail.com
Distributed under the MIT licence. See LICENCE
for more information.
https://github.com/scriptcoded
This was initially a fork from https://github.com/pomahtuk/sequilize-highlight. The repo wasn't being updated, NPM wasn't serving the latest version and there was a severe memory leak. Though the latest version now exists on NPM, issues still persist. This repo serves to address those problems, as well as providing a cleaner interface that's not bound to Sequelize.
With version 3.0.0 the library was almost completely rewritten, which leaves very little similarity with the original repo.
4.0.0 (2021-07-16)
Sources have been moved to the lib
folder. If you're referencing files
directly (require(sql-highlight/index.js)
) you should instead
reference the new lib directory (require(sql-highlight/lib/index.js)
)
FAQs
A simple and lightweight library for highlighting SQL queries written in pure JavaScript
The npm package sql-highlight receives a total of 13,543 weekly downloads. As such, sql-highlight popularity was classified as popular.
We found that sql-highlight demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.