Socket
Socket
Sign inDemoInstall

igniculus

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

igniculus - npm Package Compare versions

Comparing version 0.4.0 to 0.5.0

16

index.js
'use strict';
const dataTypes = ['BIGINT', 'NUMERIC', 'BIT', 'SMALLINT', 'DECIMAL', 'SMALLMONEY', 'INT', 'INTEGER', 'TINYINT', 'MONEY', 'FLOAT', 'REAL', 'DATE', 'DATETIMEOFFSET', 'DATETIME2', 'SMALLDATETIME', 'DATETIME', 'TIME', 'CHAR', 'VARCHAR', 'TEXT', 'NCHAR', 'NVARCHAR', 'NTEXT', 'BINARY', 'VARBINARY', 'IMAGE'];
let dataTypes = ['BIGINT', 'NUMERIC', 'BIT', 'SMALLINT', 'DECIMAL', 'SMALLMONEY', 'INT', 'INTEGER', 'TINYINT', 'MONEY', 'FLOAT', 'REAL', 'DATE', 'DATETIMEOFFSET', 'DATETIME2', 'SMALLDATETIME', 'DATETIME', 'TIME', 'CHAR', 'VARCHAR', 'TEXT', 'NCHAR', 'NVARCHAR', 'NTEXT', 'BINARY', 'VARBINARY', 'IMAGE'];
const standardKeywords = ['ADD', 'ALTER', 'BEGIN', 'BY', 'CASCADE', 'CASE', 'CHECK', 'CHECKPOINT', 'COMMIT', 'CONSTRAINT', 'CONTINUE', 'CREATE', 'CROSS', 'DATABASE', 'DECLARE', 'DEFAULT', 'DELETE', 'DISTINCT', 'DROP', 'ELSE', 'END', 'EXCEPT', 'EXEC', 'EXECUTE', 'FOREIGN', 'FROM', 'FULL', 'GO', 'GROUP', 'HAVING', 'IDENTITY', 'IF', 'INDEX', 'INNER', 'INSERT', 'INTERSECT', 'INTO', 'JOIN', 'KEY', 'LEFT', 'MERGE', 'MODIFY', 'ON', 'ORDER', 'OUTER', 'PREPARE', 'PRIMARY', 'PROC', 'PROCEDURE', 'REFERENCES', 'RETURN', 'RIGHT', 'SAVE', 'SELECT', 'SET', 'TABLE', 'TOP', 'TRAN', 'TRANSACTION', 'TRIGGER', 'TRUNCATE', 'UNION', 'UNIQUE', 'UPDATE', 'USE', 'VALUES', 'VIEW', 'WHEN', 'WHERE', 'WHILE', 'WITH'];
let standardKeywords = ['ACTION', 'ADD', 'ALTER', 'BEGIN', 'BY', 'CASCADE', 'CASE', 'CHECK', 'CHECKPOINT', 'COMMIT', 'CONSTRAINT', 'CONTINUE', 'CREATE', 'CROSS', 'DATABASE', 'DECLARE', 'DEFAULT', 'DELETE', 'DISTINCT', 'DROP', 'ELSE', 'END', 'EXCEPT', 'EXEC', 'EXECUTE', 'FOREIGN', 'FROM', 'FULL', 'GO', 'GROUP', 'HAVING', 'IDENTITY', 'IF', 'INDEX', 'INNER', 'INSERT', 'INTERSECT', 'INTO', 'JOIN', 'KEY', 'LEFT', 'MERGE', 'MODIFY', 'NO', 'ON', 'ORDER', 'OUTER', 'PREPARE', 'PRIMARY', 'PROC', 'PROCEDURE', 'REFERENCES', 'RETURN', 'RIGHT', 'SAVE', 'SELECT', 'SET', 'TABLE', 'TOP', 'TRAN', 'TRANSACTION', 'TRIGGER', 'TRUNCATE', 'UNION', 'UNIQUE', 'UPDATE', 'USE', 'VALUES', 'VIEW', 'WHEN', 'WHERE', 'WHILE', 'WITH'];
const lesserKeywords = ['ALL', 'AND', 'ANY', 'AS', 'ASC', 'AVG', 'BETWEEN', 'COUNT', 'DESC', 'EXISTS', 'IN', 'IS', 'LIKE', 'MAX', 'MIN', 'NOT', 'NULL', 'OR', 'SOME', 'SUM'];
let lesserKeywords = ['ALL', 'AND', 'ANY', 'AS', 'ASC', 'AVG', 'BETWEEN', 'COUNT', 'DESC', 'EXISTS', 'IN', 'IS', 'LIKE', 'MAX', 'MIN', 'NOT', 'NULL', 'OR', 'SOME', 'SUM'];

@@ -189,2 +189,5 @@ const ANSIModes = {

if (runestone.dataTypes) {
if (Array.isArray(runestone.dataTypes.types)) {
dataTypes = runestone.dataTypes.types;
}
runestone.dataTypes.sequence = forgeANSISequence(runestone.dataTypes);

@@ -194,2 +197,5 @@ }

if (runestone.standardKeywords) {
if (Array.isArray(runestone.standardKeywords.keywords)) {
standardKeywords = runestone.standardKeywords.keywords;
}
runestone.standardKeywords.sequence = forgeANSISequence(runestone.standardKeywords);

@@ -199,2 +205,5 @@ }

if (runestone.lesserKeywords) {
if (Array.isArray(runestone.lesserKeywords.keywords)) {
lesserKeywords = runestone.lesserKeywords.keywords;
}
runestone.lesserKeywords.sequence = forgeANSISequence(runestone.lesserKeywords);

@@ -223,1 +232,2 @@ }

module.exports = igniculus;
module.exports.log = illumine;

2

package.json
{
"name": "igniculus",
"version": "0.4.0",
"version": "0.5.0",
"description": "SQL Syntax Highlighter and Logger. Unadorned and customizable.",

@@ -5,0 +5,0 @@ "keywords": [

@@ -20,3 +20,5 @@ # Igniculus

igniculus('SELECT [port] AS Printer, \'on fire\' AS Status FROM [Printers] P WHERE P."online" AND P."check"');
igniculus('SELECT [port] AS Printer, \'on fire\' AS Status ' +
'FROM [Printers] P ' +
'WHERE P."online" AND P."check"');
```

@@ -26,5 +28,25 @@

## Logger
A reference to the log function is returned on initialization but can be accesed anywhere through `.log`
```js
// config.js
const igniculus = require('igniculus');
const options = { ... };
igniculus(options);
```
```js
// any.js
const igniculus = require('igniculus');
let query = 'SELECT ...';
igniculus.log(query);
```
## Options
A default color scheme is provided. However, you can define the highlight style for each rule, passing them along when instantiating the logger function:
A default color scheme is provided. However, you can define the highlight style for each rule when instantiating:

@@ -45,6 +67,11 @@ ```js

illumine('SELECT * FROM Student s WHERE s.programme = \'IT\' AND EXISTS (SELECT * FROM Enrolled e JOIN Class c ON c.code = e.code JOIN Tutor t ON t.tid = c.tid WHERE e.sid = s.sid AND t.name LIKE \'%Hoffman\')');
illumine('SELECT * FROM Student s ' +
'WHERE s.programme = \'IT\' AND EXISTS (' +
'SELECT * FROM Enrolled e ' +
'JOIN Class c ON c.code = e.code ' +
'JOIN Tutor t ON t.tid = c.tid ' +
'WHERE e.sid = s.sid AND t.name LIKE \'%Hoffman\')');
```
![Simple Query Custom](https://raw.githubusercontent.com/Undre4m/igniculus/master/media/subquery.png)
![Subquery](https://raw.githubusercontent.com/Undre4m/igniculus/master/media/subquery.png)

@@ -59,5 +86,8 @@ The _options_ argument is optional and each property should be one of the following.

- options.**delimitedIdentifiers** - Text between brackets or double quotes. _E.g:_ `[Employee]` or `"salary"`
- options.**dataTypes** - One of the included data types. For now it contains those defined in T-SQL. _E.g:_ `INTEGER` or `VARCHAR`
- options.**standardKeywords** - One the included keywords. Contains the most widely used T-SQL and SQL-92 Standard keywords. _E.g:_ `SELECT` or `CONSTRAINT`
- options.**lesserKeywords** - One of the included subset of keywords. _E.g:_ `ANY`, `AVG` or `DESC`
- options.**dataTypes** - One of the included data types. _E.g:_ `INTEGER` or `VARCHAR`
- dataTypes.**types** - Array of custom data types. Replaces the ones by default. _E.g:_ `['SERIAL', 'TIMESTAMP']`
- options.**standardKeywords** - One the included keywords. _E.g:_ `SELECT` or `CONSTRAINT`
- standardKeywords.**keywords** - Array of custom standard keywords. Replaces the ones by default. _E.g:_ `['CLUSTER', 'NATURAL']`
- options.**lesserKeywords** - One of the included lesser keywords. _E.g:_ `ANY`, `AVG` or `DESC`
- lesserKeywords.**keywords** - Array of custom lesser keywords. Replaces the ones by default. _E.g:_ `['VOLATILE', 'ASYMMETRIC']`
- options.**prefix**

@@ -71,2 +101,7 @@ - prefix.**text** - A prefix can be appended to every log through this option. This prefix can be styled like any previous options.

>#### A word on types and keywords
>Most often, highlighting every reserved keyword can make syntax difficult to read, defeating the purpose altogether. Therefore, three distinct rules are provided: _dataTypes_, _standardKeywords_ and _lesserKeywords_.
Each of these rules can be customized individually and come with a [predefined list](https://github.com/Undre4m/igniculus/blob/master/index.js#L3) of most widely used T-SQL and SQL-92 keywords and data types. Furthermore each of this lists can be customized as described above.
### Styles

@@ -147,3 +182,4 @@

igniculus("INSERT INTO [Printers] ([port], [name], [ready], [online], [check]) VALUES ('lp0', 'Bob Marley', 0, 1, 1)");
igniculus("INSERT INTO [Printers] ([port], [name], [ready], [online], [check]) " +
"VALUES ('lp0', 'Bob Marley', 0, 1, 1)");
```

@@ -153,5 +189,39 @@

```js
const igniculus = require('igniculus');
const options = {
delimitedIdentifiers: {
fg: 'yellow'
},
dataTypes: {
fg: 'magenta',
types: ['VARBINARY']
},
standardKeywords: {
fg: 'red',
keywords: ['CREATE', 'PRIMARY', 'KEY']
},
lesserKeywords: {
mode: 'bold',
fg: 'black',
keywords: ['TABLE', 'NOT', 'NULL']
},
prefix: {
text: '\n'
}
};
igniculus(options);
igniculus.log('CREATE TABLE User (' +
'[username] VARCHAR(20) NOT NULL, ' +
'[password] BINARY(64) NOT NULL, ' +
'[avatar] VARBINARY(MAX), PRIMARY KEY ([username]))');
```
![Custom Create](https://raw.githubusercontent.com/Undre4m/igniculus/master/media/simple-create-custom.png)
### Integration
Igniculus' logger is a _drop in_ replacement on any tool that passes the logging function either a `string` or `Object` paramater. In the latest case the `toString()` method will be called to obtain a `string` primitive.
Igniculus' logger is a _drop in_ replacement on any tool that passes the log function either a `string` or `Object` paramater. In the latest case the `toString()` method will be called to obtain a `string` primitive.

@@ -190,4 +260,3 @@ #### Sequelize

);
const sequelize = new Sequelize('database', 'username', 'password',
{
const sequelize = new Sequelize('database', 'username', 'password', {
logging: igniculus

@@ -209,3 +278,2 @@ });

- Custom keywords
- Custom rules

@@ -212,0 +280,0 @@ - Selecting log stream _E.g:_ `process.stdout`

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc