{"name":"sql-highlight","version":"4.0.4","keywords":["sql","syntax","highlight","highlighter"],"author":{"name":"Malcolm Nihlén","email":"malcolm.nihlen@gmail.com"},"license":"MIT","_id":"sql-highlight@4.0.4","maintainers":[{"name":"script_coded","email":"malcolm.nihlen@gmail.com"}],"contributors":[{"name":"pomahtuk"}],"homepage":"https://github.com/scriptcoded/sql-highlight#readme","bugs":{"url":"https://github.com/scriptcoded/sql-highlight/issues"},"dist":{"shasum":"a5324cc8ce06d16a67150dee9ba2c5bdb97ad0f6","tarball":"http://registry-npm.ywwl.com/sql-highlight/download/sql-highlight-4.0.4.tgz","fileCount":6,"integrity":"sha512-ZEcXMSOl3FIGex35XqFMi3yrubYMj6G1/yLwFlyYn7jGW+7kQz9UoPe5zJYfxKbn7zG5TGAozX3w3lJKHpoyIg==","signatures":[{"sig":"MEYCIQDRhptAx1z9bpeT2XWK+d920YbMzK3LhKrJNQci1ahmVAIhAPeHZmGE4Z9MAwCtmH18E2ipGFPitPlaD6k7l1ZhTehB","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":11599,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJi3AnkACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmqvsQ//fzRDmXoCkhpsn3lc2nw4nMr81or6wGO2/0hLWuUf/k2Sx4Ld\r\n84iVqCy4AGw3o8GxItn7ue+bDKVWok9XjixFaCO0DSBPLHMsqIf3xXLpxoNk\r\nrgDOyR83hT4VXXeAX+ExjS7e28feim9tyxde1igYIsTS2kYQXOUBz2pCIMVT\r\n5W4dShoi3t1qmJKgi4T0DWl41z8sYhz+rM6dCF95NDVbUS+WuigiLJWMmlsq\r\nAkDw85qz7DkulcjvKqgNDwUoDZRU3fjLjVOCBDa8Az43/4oVdmoAj9kwZWhc\r\n9VEVGACv7RDx8Kqn+HW9WOrMGESwUpkAyYP1mgi3YOSoCLCdCQQ7AlmIrcDb\r\nn1Ugq+EucFywfoGmFrVv8+p7V2PeSiqUFunlpxZz27qWul5UhVL45Q820jBZ\r\nP20Aiybt10Ry4Qr5jZaq1A8ujwTL8Xfh9YG+vauX7+UJ93XoJNnRuRXR7Flo\r\nhHkr48iHaOM1JhMsfZo3fXRMTze27IPC+KQirnJ2cL2kUmM/AItv5oCi12nw\r\nHhlhK8dBNZM1WQXMSJ7K+v886WEpUN4RxUqcbOYSU/78Bxz2qbHlMwAXPkDG\r\nSaU0RIyMvOrUOomk4z2yhArAQIE0WASqgbz6HT3+M77ScmoANhaHob0embM5\r\nmo2A0LMrsPBTieqYS+7ODrZA1QBjo5V1JcY=\r\n=OkR/\r\n-----END PGP SIGNATURE-----\r\n","size":4858,"noattachment":false,"key":"/sql-highlight/-/sql-highlight-4.0.4.tgz"},"main":"lib/index.js","types":"./lib/index.d.ts","gitHead":"9ac3f1cc10fee9281bbf687b9eb6f47a686f8261","scripts":{"lint":"eslint .","test":"jest","pretest":"npm run lint","test:coverage":"jest --coverage","semantic-release":"semantic-release"},"_npmUser":{"name":"script_coded","email":"malcolm.nihlen@gmail.com"},"repository":{"url":"git+https://github.com/scriptcoded/sql-highlight.git","type":"git"},"_npmVersion":"7.20.0","description":"A simple and lightweight syntax highlighting library for SQL","directories":{},"_nodeVersion":"12.22.12","_hasShrinkwrap":false,"devDependencies":{"jest":"^27.0.6","eslint":"^7.30.0","semantic-release":"^17.4.4","eslint-plugin-jest":"^24.3.6","eslint-plugin-node":"^11.1.0","eslint-plugin-import":"^2.23.4","@semantic-release/git":"^9.0.0","eslint-plugin-promise":"^5.1.0","eslint-config-standard":"^16.0.3","eslint-plugin-standard":"^4.1.0","@semantic-release/changelog":"^5.0.1"},"_npmOperationalInternal":{"tmp":"tmp/sql-highlight_4.0.4_1658587620488_0.32391646903749827","host":"s3://npm-registry-packages"},"readme":"# sql-highlight\n> A simple and lightweight library for highlighting SQL queries written in pure\n> JavaScript\n\n[![Tests Status][tests-badge]][tests-url]\n[![Coverage Status][coveralls-badge]][coveralls-url]\n[![NPM Version][npm-version-badge]][npm-url]\n[![Bundle Size][bundlejs-badge]][bundlejs-url]\n\n> [!IMPORTANT]\n> Due to some recent issues with the release flow, the 5.0.0 release was somewhat prematurely released. With NPM not allowing unpublishing the current release is 6.0.0.\n\n## What's it all about?\nsql-highlight is a small package that highlights SQL queries. It can output to\nboth the terminal with Unicode escape sequences, as well as to normal HTML. Oh,\nand there are no external dependencies 😉\n\n## Installation\n\nsql-highlight is tested to work with Node.js 16, 18, 20 and 22.\n\nInstall with Yarn:\n```bash\nyarn add sql-highlight\n```\nInstall with NPM:\n```bash\nnpm install sql-highlight\n```\n\n## Usage\n\n**In its most basic form:**\n```js\nconst { highlight } = require('sql-highlight')\n\nconst sqlString = \"SELECT `id`, `username` FROM `users` WHERE `email` = 'test@example.com'\"\n\nconst highlighted = highlight(sqlString)\n\nconsole.log(highlighted)\n```\n\n**Output:**\n\n![Screenshot](screenshot.png)\n\n**HTML mode:**\n\n```js\nconst { highlight } = require('sql-highlight')\n\nconst sqlString = \"SELECT `id`, `username` FROM `users` WHERE `email` = 'test@example.com'\"\n\nconst highlighted = highlight(sqlString, {\n  html: true\n})\n\ndocument.body.innerHTML += highlighted\n```\n\n**Output:**\n```html\n<span class=\"sql-hl-keyword\">SELECT</span>\n<span class=\"sql-hl-identifier\">`id`</span>\n<span class=\"sql-hl-special\">,</span>\n<span class=\"sql-hl-identifier\">`username`</span>\n<span class=\"sql-hl-keyword\">FROM</span>\n<span class=\"sql-hl-identifier\">`users`</span>\n<span class=\"sql-hl-keyword\">WHERE</span>\n<span class=\"sql-hl-identifier\">`email`</span>\n<span class=\"sql-hl-special\">=</span>\n<span class=\"sql-hl-string\">'test@example.com'</span>\n```\n\n## Options\nThe following options may be passed to the `highlight` function.\n\n| Option | Value | Default | Description |\n| --- | --- | --- | --- |\n| html | `boolean` | `false` | Set to true to render HTML instead of Unicode.\n| htmlEscaper | `(str: string) => string` | Basic escaper | Function to escape HTML entities. Uses a basic escaper by default. If HTML mode is used in a browser environment this could be useful to escape strings using the DOM.\n| classPrefix | `string` | `'sql-hl-'` | Prefix to prepend to classes for HTML span-tags. Is appended with entity name.\n| colors | `Object` | _See below_* | What color codes to use for Unicode rendering. A list of basic color codes can be found [here](https://docs.rs/embedded-text/0.4.0/embedded_text/style/index.html#standard-color-codes).\n\n\\* `colors` option default value\n```js\n{\n  keyword: '\\x1b[35m',  // SQL reserved keywords\n  function: '\\x1b[31m', // Functions\n  number: '\\x1b[32m',   // Numbers\n  string: '\\x1b[32m',   // Strings\n  special: '\\x1b[33m',  // Special characters\n  bracket: '\\x1b[33m',  // Brackets (parentheses)\n  comment: '\\x1b[2m\\x1b[90m', // Comments\n  clear: '\\x1b[0m'      // Clear (inserted after each match)\n}\n```\n\n## Custom highlighting\n\nIn case you want to do the highlighting yourself you can use `getSegments` to only let sql-highlight parse the SQL string for you. You can then use the segments to highlight it yourself.\n\n```js\nconst { getSegments } = require('sql-highlight')\n\nconst sqlString = \"SELECT `id`, `username` FROM `users` WHERE `email` = 'test@example.com'\"\n\nconst segments = getSegments(sqlString)\n\nconsole.log(segments)\n```\n\n**Output:**\n```js\n[\n    { name: 'keyword', content: 'SELECT' },\n    { name: 'whitespace', content: ' ' },\n    { name: 'identifier', content: '`id`' },\n    { name: 'special', content: ',' },\n    { name: 'whitespace', content: ' ' },\n    { name: 'identifier', content: '`username`' },\n    { name: 'whitespace', content: ' ' },\n    { name: 'keyword', content: 'FROM' },\n    { name: 'whitespace', content: ' ' },\n    { name: 'identifier', content: '`users`' },\n    { name: 'whitespace', content: ' ' },\n    { name: 'keyword', content: 'WHERE' },\n    { name: 'whitespace', content: ' ' },\n    { name: 'identifier', content: '`email`' },\n    { name: 'whitespace', content: ' ' },\n    { name: 'special', content: '=' },\n    { name: 'whitespace', content: ' ' },\n    { name: 'string', content: \"'test@example.com'\" }\n]\n```\n\n## Contributing\n\nSee the [contribution guidelines](CONTRIBUTING.md).\n\n## Tests\n\nWe use [Jest](https://jestjs.io/) for running our tests. The test suite can be run by running `npm run test`. This will run both Jest and Biome.\n\n## Code style\n\nWe use [Biome](https://biomejs.dev/) 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`.\n\n## A note on Dependabot\n\n[Dependabot Auto\nMerge](https://github.com/marketplace/actions/dependabot-auto-merge) is\ninstalled in this repository to automatically merge dependabot PRs for minor\nversion updates. Only PRs that pass the tests get merged. No new releases will\nbe created for dependency updates as there are no production dependencies and a\nrelease would therefore be completely unnecessary.\n\n## Additional information\n\nMalcolm Nihlén - malcolm.nihlen@gmail.com\n\nDistributed under the MIT licence. See `LICENCE` for more information.\n\nhttps://github.com/scriptcoded\n\n## Disclaimer\nThis was initially a fork from https://github.com/pomahtuk/sequilize-highlight.\nThe repo wasn't being updated, NPM wasn't serving the latest version and there\nwas a severe memory leak. Though the latest version now exists on NPM, issues\nstill persist. This repo serves to address those problems, as well as providing\na cleaner interface that's not bound to Sequelize.\n\nWith version 3.0.0 the library was almost completely rewritten, which leaves\nvery little similarity with the original repo.\n\n[tests-badge]: https://img.shields.io/github/actions/workflow/status/scriptcoded/sql-highlight/test.yml?branch=main&label=tests\n[tests-url]: https://github.com/scriptcoded/sql-highlight/actions/workflows/test.yml\n[coveralls-badge]: https://coveralls.io/repos/github/scriptcoded/sql-highlight/badge.svg\n[coveralls-url]: https://coveralls.io/github/scriptcoded/sql-highlight\n[npm-version-badge]: https://img.shields.io/npm/v/sql-highlight.svg\n[npm-url]: https://npmjs.org/package/sql-highlight\n[bundlejs-badge]: https://deno.bundlejs.com/?bundle&q=sql-highlight&badge\n[bundlejs-url]: https://bundlejs.com/?bundle&q=sql-highlight\n","publish_time":1658587620691,"_cnpm_publish_time":1658587620691,"dist-tags":{"beta":"5.0.0-beta.2","latest":"6.1.0","next":"5.0.0"}}