Comparing version 0.5.5 to 1.0.0
'use strict'; | ||
var EOL = require('os').EOL; | ||
var utils = require('./utils'); | ||
const EOL = require('os').EOL; | ||
const utils = require('./utils'); | ||
var parsingErrorCode = { | ||
const parsingErrorCode = { | ||
unclosedMLC: 0, // Unclosed multi-line comment. | ||
@@ -16,3 +16,3 @@ unclosedText: 1, // Unclosed text block. | ||
var errorMessages = [ | ||
const errorMessages = [ | ||
{name: 'unclosedMLC', message: 'Unclosed multi-line comment.'}, | ||
@@ -26,3 +26,3 @@ {name: 'unclosedText', message: 'Unclosed text block.'}, | ||
function SQLParsingError(code, position) { | ||
var temp = Error.apply(this, arguments); | ||
const temp = Error.apply(this, arguments); | ||
temp.name = this.name = 'SQLParsingError'; | ||
@@ -46,4 +46,4 @@ this.stack = temp.stack; | ||
level = level > 0 ? parseInt(level) : 0; | ||
var gap = utils.messageGap(level + 1); | ||
var lines = [ | ||
const gap = utils.messageGap(level + 1); | ||
const lines = [ | ||
'SQLParsingError {', | ||
@@ -63,4 +63,4 @@ gap + 'code: parsingErrorCode.' + errorMessages[this.code].name, | ||
module.exports = { | ||
SQLParsingError: SQLParsingError, | ||
parsingErrorCode: parsingErrorCode | ||
SQLParsingError, | ||
parsingErrorCode | ||
}; |
'use strict'; | ||
var parser = require('./parser'); | ||
var error = require('./error'); | ||
const parser = require('./parser'); | ||
const error = require('./error'); | ||
@@ -6,0 +6,0 @@ parser.SQLParsingError = error.SQLParsingError; |
'use strict'; | ||
var errorLib = require('./error'); | ||
var utils = require('./utils'); | ||
const errorLib = require('./error'); | ||
const utils = require('./utils'); | ||
var PEC = errorLib.parsingErrorCode; | ||
const PEC = errorLib.parsingErrorCode; | ||
// symbols that need no spaces around them: | ||
var compressors = '.,;:()[]=<>+-*/|!?@#'; | ||
const compressors = '.,;:()[]=<>+-*/|!?@#'; | ||
@@ -27,11 +27,12 @@ //////////////////////////////////////////// | ||
var idx = 0, // current index | ||
let idx = 0, // current index | ||
result = '', // resulting sql | ||
len = sql.length, // sql length | ||
space = false; // add a space on the next step | ||
const len = sql.length, // sql length | ||
EOL = utils.getEOL(sql), // end-of-line | ||
space = false, // add a space on the next step | ||
compress = options && options.compress; // option 'compress' | ||
do { | ||
var s = sql[idx], // current symbol; | ||
const s = sql[idx], // current symbol; | ||
s1 = sql[idx + 1]; // next symbol; | ||
@@ -49,3 +50,3 @@ | ||
if (s === '-' && s1 === '-') { | ||
var lb = sql.indexOf(EOL, idx + 2); | ||
const lb = sql.indexOf(EOL, idx + 2); | ||
if (lb < 0) { | ||
@@ -60,3 +61,3 @@ break; | ||
if (s === '/' && s1 === '*') { | ||
var end = sql.indexOf('*/', idx + 2); | ||
const end = sql.indexOf('*/', idx + 2); | ||
if (end < 0) { | ||
@@ -66,3 +67,3 @@ throwError(PEC.unclosedMLC); | ||
var nestedIdx = sql.substr(idx + 2, end - idx).search(/\/\*/); | ||
const nestedIdx = sql.substr(idx + 2, end - idx).search(/\/\*/); | ||
if (nestedIdx !== -1) { | ||
@@ -80,3 +81,3 @@ idx += 2 + nestedIdx; | ||
var closeIdx, text; | ||
let closeIdx, text; | ||
@@ -107,3 +108,3 @@ if (s === '"') { | ||
if (closeIdx > 0) { | ||
var step = closeIdx; | ||
let step = closeIdx; | ||
while (++step < len && sql[step] === '\'') ; | ||
@@ -125,13 +126,13 @@ if ((step - closeIdx) % 2) { | ||
text = sql.substr(idx, closeIdx - idx + 1); | ||
var hasLB = text.indexOf(EOL) > 0; | ||
const hasLB = text.indexOf(EOL) > 0; | ||
if (hasLB) { | ||
text = text.split(EOL).map(function (m) { | ||
text = text.split(EOL).map(m => { | ||
return m.replace(/^\s+|\s+$/g, ''); | ||
}).join('\\n'); | ||
} | ||
var hasTabs = text.indexOf('\t') > 0; | ||
const hasTabs = text.indexOf('\t') > 0; | ||
if (hasLB || hasTabs) { | ||
var prev = idx ? sql[idx - 1] : ''; | ||
const prev = idx ? sql[idx - 1] : ''; | ||
if (prev !== 'E' && prev !== 'e') { | ||
var r = result ? result[result.length - 1] : ''; | ||
const r = result ? result[result.length - 1] : ''; | ||
if (r && r !== ' ' && compressors.indexOf(r) < 0) { | ||
@@ -182,3 +183,3 @@ result += ' '; | ||
function throwError(code) { | ||
var position = utils.getIndexPos(sql, idx, EOL); | ||
const position = utils.getIndexPos(sql, idx, EOL); | ||
throw new errorLib.SQLParsingError(code, position); | ||
@@ -185,0 +186,0 @@ } |
'use strict'; | ||
var os = require('os'); | ||
const os = require('os'); | ||
@@ -8,3 +8,3 @@ ////////////////////////////////////// | ||
function getEOL(text) { | ||
var idx = 0, unix = 0, windows = 0; | ||
let idx = 0, unix = 0, windows = 0; | ||
while (idx < text.length) { | ||
@@ -31,3 +31,3 @@ idx = text.indexOf('\n', idx); | ||
function getIndexPos(text, index, eol) { | ||
var lineIdx = 0, colIdx = index, pos = 0; | ||
let lineIdx = 0, colIdx = index, pos = 0; | ||
do { | ||
@@ -55,5 +55,5 @@ pos = text.indexOf(eol, pos); | ||
module.exports = { | ||
getEOL: getEOL, | ||
getIndexPos: getIndexPos, | ||
messageGap: messageGap | ||
getEOL, | ||
getIndexPos, | ||
messageGap | ||
}; |
{ | ||
"name": "pg-minify", | ||
"version": "0.5.5", | ||
"version": "1.0.0", | ||
"description": "Minifies PostgreSQL scripts.", | ||
@@ -42,12 +42,12 @@ "main": "lib/index.js", | ||
"engines": { | ||
"node": ">=0.12", | ||
"npm": ">=1.4" | ||
"node": ">=4.0", | ||
"npm": ">=2.15" | ||
}, | ||
"devDependencies": { | ||
"coveralls": "3.0.2", | ||
"eslint": "5.7.0", | ||
"coveralls": "3.0.3", | ||
"eslint": "5.16.0", | ||
"istanbul": "0.4.5", | ||
"jasmine-node": "1.16.2", | ||
"typescript": "3.1.3" | ||
"typescript": "3.4.3" | ||
} | ||
} |
@@ -38,5 +38,5 @@ pg-minify | ||
```js | ||
var minify = require('pg-minify'); | ||
const minify = require('pg-minify'); | ||
var sql = 'SELECT 1; -- comments'; | ||
const sql = 'SELECT 1; -- comments'; | ||
@@ -49,3 +49,3 @@ minify(sql); //=> SELECT 1; | ||
```js | ||
var sql = 'SELECT * FROM "table" WHERE col = 123; -- comments'; | ||
const sql = 'SELECT * FROM "table" WHERE col = 123; -- comments'; | ||
@@ -100,3 +100,3 @@ minify(sql, {compress: true}); | ||
Copyright © 2018 [Vitaly Tomilov](https://github.com/vitaly-t); | ||
Copyright © 2019 [Vitaly Tomilov](https://github.com/vitaly-t); | ||
Released under the MIT license. | ||
@@ -103,0 +103,0 @@ |
//////////////////////////////////////// | ||
// Requires pg-minify v0.5.5 or later. | ||
// For pg-minify v1.0.0 or later. | ||
//////////////////////////////////////// | ||
@@ -4,0 +4,0 @@ |
@@ -14,3 +14,3 @@ ## TypeScript for pg-minify | ||
var sql = 'SELECT 1; -- comments'; | ||
const sql = 'SELECT 1; -- comments'; | ||
@@ -17,0 +17,0 @@ minify(sql); //=> SELECT 1; |
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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
14805
0