Comparing version 1.0.1 to 1.1.0
## Changelog | ||
### 1.0.1 ~ _03 Jan 2018_ | ||
### 1.1.0 ~ _26 Feb 2018_ | ||
- Fixed types and keywords matching inside constants | ||
- Support for optional types and keywords casing | ||
- Performance improvements | ||
#### 1.0.1 ~ _03 Jan 2018_ | ||
- LICENSE and README updates | ||
@@ -5,0 +10,0 @@ - CHANGELOG |
130
index.js
@@ -5,5 +5,5 @@ 'use strict'; | ||
const defaultStandardKeywords = ['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 defaultStandardKeywords = ['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', 'FUNCTION', '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', 'RETURNS', 'RIGHT', 'SAVE', 'SELECT', 'SET', 'TABLE', 'TOP', 'TRAN', 'TRANSACTION', 'TRIGGER', 'TRUNCATE', 'UNION', 'UNIQUE', 'UPDATE', 'USE', 'VALUES', 'VIEW', 'WHEN', 'WHERE', 'WHILE', 'WITH']; | ||
const defaultLesserKeywords = ['ALL', 'AND', 'ANY', 'AS', 'ASC', 'AVG', 'BETWEEN', 'COUNT', 'DESC', 'EXISTS', 'IN', 'IS', 'LIKE', 'MAX', 'MIN', 'NOT', 'NULL', 'OR', 'SOME', 'SUM']; | ||
const defaultLesserKeywords = ['ALL', 'AND', 'ANY', 'AS', 'ASC', 'AVG', 'BETWEEN', 'COLLATE', 'COUNT', 'DESC', 'EXISTS', 'IN', 'IS', 'LIKE', 'MAX', 'MIN', 'NOT', 'NULL', 'OR', 'SOME', 'SUM']; | ||
@@ -15,10 +15,10 @@ let dataTypes = defaultDataTypes.slice(); | ||
const ANSIModes = { | ||
reset: '\x1b[0m', | ||
bold: '\x1b[1m', | ||
dim: '\x1b[2m', | ||
italic: '\x1b[3m', | ||
underline: '\x1b[4m', | ||
blink: '\x1b[5m', | ||
inverse: '\x1b[7m', | ||
hidden: '\x1b[8m', | ||
reset: '\x1b[0m', | ||
bold: '\x1b[1m', | ||
dim: '\x1b[2m', | ||
italic: '\x1b[3m', | ||
underline: '\x1b[4m', | ||
blink: '\x1b[5m', | ||
inverse: '\x1b[7m', | ||
hidden: '\x1b[8m', | ||
strikethrough: '\x1b[9m' | ||
@@ -29,20 +29,20 @@ }; | ||
fg: { | ||
black: '\x1b[30m', | ||
red: '\x1b[31m', | ||
green: '\x1b[32m', | ||
yellow: '\x1b[33m', | ||
blue: '\x1b[34m', | ||
magenta: '\x1b[35m', | ||
cyan: '\x1b[36m', | ||
white: '\x1b[37m' | ||
black: '\x1b[30m', | ||
red: '\x1b[31m', | ||
green: '\x1b[32m', | ||
yellow: '\x1b[33m', | ||
blue: '\x1b[34m', | ||
magenta: '\x1b[35m', | ||
cyan: '\x1b[36m', | ||
white: '\x1b[37m' | ||
}, | ||
bg: { | ||
black: '\x1b[40m', | ||
red: '\x1b[41m', | ||
green: '\x1b[42m', | ||
yellow: '\x1b[43m', | ||
blue: '\x1b[44m', | ||
magenta: '\x1b[45m', | ||
cyan: '\x1b[46m', | ||
white: '\x1b[47m' | ||
black: '\x1b[40m', | ||
red: '\x1b[41m', | ||
green: '\x1b[42m', | ||
yellow: '\x1b[43m', | ||
blue: '\x1b[44m', | ||
magenta: '\x1b[45m', | ||
cyan: '\x1b[46m', | ||
white: '\x1b[47m' | ||
} | ||
@@ -54,5 +54,5 @@ }; | ||
delimitedIdentifiers: { mode: 'dim', fg: 'yellow' }, | ||
dataTypes: { mode: 'dim', fg: 'green' }, | ||
standardKeywords: { mode: 'dim', fg: 'cyan' }, | ||
lesserKeywords: { mode: 'bold', fg: 'black' }, | ||
dataTypes: { mode: 'dim', fg: 'green', casing: 'uppercase' }, | ||
standardKeywords: { mode: 'dim', fg: 'cyan', casing: 'uppercase' }, | ||
lesserKeywords: { mode: 'bold', fg: 'black', casing: 'uppercase' }, | ||
prefix: { replace: /.*?: / } | ||
@@ -118,21 +118,45 @@ }; | ||
// Extract constants so no subsequent operations alter them. Mark their positions for reinsertion. | ||
let __constants = output.match(/('.*?')/g); | ||
if (__constants && __constants.length) { | ||
output = output.replace(/('.*?')/g, '⇝※⇜'); | ||
} | ||
if (runestone.dataTypes && runestone.dataTypes.sequence) { | ||
for (let i = 0; i < dataTypes.length; i++) { | ||
let regex = new RegExp('\\b' + dataTypes[i] + '\\b' + '(?![\'"\\]])', 'gi'); | ||
output = output.replace(regex, runestone.dataTypes.sequence + dataTypes[i] + ANSIModes.reset); | ||
} | ||
let regex = new RegExp('\\b' + '(' + dataTypes.join('|') + ')' + '\\b' + '(?![\'"\\]])', 'gi'); | ||
output = output.replace(regex, (match, g1) => { | ||
let word = g1; | ||
const casing = runestone.dataTypes.casing; | ||
if (typeof casing === 'string' && (casing === 'lowercase' || casing === 'uppercase')) | ||
word = casing === 'lowercase' ? word.toLowerCase() : word.toUpperCase(); | ||
return runestone.dataTypes.sequence + word + ANSIModes.reset; | ||
}); | ||
} | ||
if (runestone.standardKeywords && runestone.standardKeywords.sequence) { | ||
for (let i = 0; i < standardKeywords.length; i++) { | ||
let regex = new RegExp('\\b' + standardKeywords[i] + '\\b' + '(?![\'"\\]])', 'gi'); | ||
output = output.replace(regex, runestone.standardKeywords.sequence + standardKeywords[i] + ANSIModes.reset); | ||
} | ||
let regex = new RegExp('\\b' + '(' + standardKeywords.join('|') + ')' + '\\b' + '(?![\'"\\]])', 'gi'); | ||
output = output.replace(regex, (match, g1) => { | ||
let word = g1; | ||
const casing = runestone.standardKeywords.casing; | ||
if (typeof casing === 'string' && (casing === 'lowercase' || casing === 'uppercase')) | ||
word = casing === 'lowercase' ? word.toLowerCase() : word.toUpperCase(); | ||
return runestone.standardKeywords.sequence + word + ANSIModes.reset; | ||
}); | ||
} | ||
if (runestone.lesserKeywords && runestone.lesserKeywords.sequence) { | ||
for (let i = 0; i < lesserKeywords.length; i++) { | ||
let regex = new RegExp('\\b' + lesserKeywords[i] + '\\b' + '(?![\'"\\]])', 'gi'); | ||
output = output.replace(regex, runestone.lesserKeywords.sequence + lesserKeywords[i] + ANSIModes.reset); | ||
} | ||
let regex = new RegExp('\\b' + '(' + lesserKeywords.join('|') + ')' + '\\b' + '(?![\'"\\]])', 'gi'); | ||
output = output.replace(regex, (match, g1) => { | ||
let word = g1; | ||
const casing = runestone.lesserKeywords.casing; | ||
if (typeof casing === 'string' && (casing === 'lowercase' || casing === 'uppercase')) | ||
word = casing === 'lowercase' ? word.toLowerCase() : word.toUpperCase(); | ||
return runestone.lesserKeywords.sequence + word + ANSIModes.reset; | ||
}); | ||
} | ||
@@ -148,2 +172,13 @@ | ||
// If constants were found and extracted, reinsert them on the marked positions. | ||
if (__constants && __constants.length) { | ||
for (let i of __constants) { | ||
// If constants were to be formatted, apply the provided style. | ||
if (runestone.constants && runestone.constants.sequence) | ||
output = output.replace('⇝※⇜', runestone.constants.sequence + i + ANSIModes.reset); | ||
else | ||
output = output.replace('⇝※⇜', i); | ||
} | ||
} | ||
// If delimited identifiers were found and extracted, reinsert them on the marked positions. | ||
@@ -160,13 +195,6 @@ if (__identifiers && __identifiers.length) { | ||
if (runestone.constants && runestone.constants.sequence) { | ||
output = output.replace(/('.*?')/g, (match) => { | ||
return runestone.constants.sequence + voidFormatting(match) + ANSIModes.reset; | ||
}); | ||
} | ||
// Constants are to be formatted as a whole and no other format should exist inside them. Void any that could have been applied. | ||
else { | ||
output = output.replace(/('.*?')/g, (match) => { | ||
return voidFormatting(match); | ||
}); | ||
} | ||
output = output.replace(/('.*?')/g, (match) => { | ||
return voidFormatting(match); | ||
}); | ||
@@ -173,0 +201,0 @@ // If the given prefix was found and a replacement pattern was provided, substitute it. |
{ | ||
"name": "igniculus", | ||
"version": "1.0.1", | ||
"version": "1.1.0", | ||
"description": "SQL Syntax Highlighter and Logger. Unadorned and customizable.", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -23,3 +23,3 @@ # Igniculus | ||
'FROM [Printers] P ' + | ||
'WHERE P."online" AND P."check"'); | ||
'WHERE P."online" = 1 AND P."check" = 1'); | ||
``` | ||
@@ -96,6 +96,9 @@ | ||
- dataTypes.**types** - Array of custom data types. Replaces the ones by default. _E.g:_ `['SERIAL', 'TIMESTAMP']` | ||
- dataTypes.**casing** - Either `'lowercase'` or `'uppercase'`. If not defined data types won't be capitalized. | ||
- 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']` | ||
- standardKeywords.**casing** - Either `'lowercase'` or `'uppercase'`. If not defined standard keywords won't be capitalized. | ||
- 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']` | ||
- lesserKeywords.**casing** - Either `'lowercase'` or `'uppercase'`. If not defined lesser keywords won't be capitalized. | ||
- options.**prefix** | ||
@@ -113,4 +116,5 @@ - prefix.**text** - A prefix can be appended to every log through this option. This prefix can be styled like any previous options. | ||
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. | ||
> | ||
>Starting from [v1.1.0](https://github.com/Undre4m/igniculus/blob/master/CHANGELOG.md#110--26-feb-2018) _types_ and _keywords_ are no longer uppercased by default. Custom styles should use the `casing: 'uppercase'` option for this behaviour. Predefined style already provides this option so no changes should be required. | ||
### Styles | ||
@@ -171,5 +175,5 @@ | ||
constants: { mode: 'dim', fg: 'red' }, | ||
delimitedIdentifiers: { mode: 'dim', fg: 'yellow' }, | ||
dataTypes: { mode: 'dim', fg: 'green' }, | ||
standardKeywords: { mode: 'dim', fg: 'cyan' }, | ||
delimitedIdentifiers: { mode: 'dim', fg: 'yellow', casing: 'uppercase' }, | ||
dataTypes: { mode: 'dim', fg: 'green', casing: 'uppercase' }, | ||
standardKeywords: { mode: 'dim', fg: 'cyan', casing: 'uppercase' }, | ||
lesserKeywords: { mode: 'bold', fg: 'black' }, | ||
@@ -289,3 +293,3 @@ prefix: { replace: /.*?: / } | ||
### Future Upgrades | ||
Planned support for custom rules. | ||
Planned support for variables and custom rules. | ||
@@ -292,0 +296,0 @@ ## Maintainers |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
25905
241
297
6