Comparing version 0.4.4 to 0.4.5
'use strict'; | ||
var EOL = require('os').EOL; | ||
var utils = require('./utils'); | ||
@@ -41,3 +42,3 @@ var parsingErrorCode = { | ||
level = level > 0 ? parseInt(level) : 0; | ||
var gap = messageGap(level + 1); | ||
var gap = utils.messageGap(level + 1); | ||
var lines = [ | ||
@@ -48,3 +49,3 @@ 'SQLParsingError {', | ||
gap + 'position: {line: ' + this.position.line + ', col: ' + this.position.column + '}', | ||
messageGap(level) + '}' | ||
utils.messageGap(level) + '}' | ||
]; | ||
@@ -54,6 +55,2 @@ return lines.join(EOL); | ||
function messageGap(level) { | ||
return Array(1 + level * 4).join(' '); | ||
} | ||
SQLParsingError.prototype.inspect = function () { | ||
@@ -60,0 +57,0 @@ return this.toString(); |
@@ -6,5 +6,5 @@ 'use strict'; | ||
parser.minify.SQLParsingError = error.SQLParsingError; | ||
parser.minify.parsingErrorCode = error.parsingErrorCode; | ||
parser.SQLParsingError = error.SQLParsingError; | ||
parser.parsingErrorCode = error.parsingErrorCode; | ||
module.exports = parser.minify; | ||
module.exports = parser; |
'use strict'; | ||
var os = require('os'); | ||
var errorLib = require('./error'); | ||
var utils = require('./utils'); | ||
@@ -30,3 +30,3 @@ var PEC = errorLib.parsingErrorCode; | ||
len = sql.length, // sql length | ||
EOL = getEOL(sql), // end-of-line | ||
EOL = utils.getEOL(sql), // end-of-line | ||
space = false, // add a space on the next step | ||
@@ -167,3 +167,3 @@ compress = options && options.compress; // option 'compress' | ||
function throwError(code) { | ||
var position = getIndexPos(sql, idx, EOL); | ||
var position = utils.getIndexPos(sql, idx, EOL); | ||
throw new errorLib.SQLParsingError(code, position); | ||
@@ -173,43 +173,2 @@ } | ||
////////////////////////////////////// | ||
// Returns the End-Of-Line from text. | ||
function getEOL(text) { | ||
var idx = 0, unix = 0, windows = 0; | ||
while (idx < text.length) { | ||
idx = text.indexOf('\n', idx); | ||
if (idx === -1) { | ||
break; | ||
} | ||
if (idx > 0 && text[idx - 1] === '\r') { | ||
windows++; | ||
} else { | ||
unix++; | ||
} | ||
idx++; | ||
} | ||
if (unix === windows) { | ||
return os.EOL; | ||
} | ||
return unix > windows ? '\n' : '\r\n'; | ||
} | ||
/////////////////////////////////////////////////////// | ||
// Returns {line, column} of an index within the text. | ||
function getIndexPos(text, index, eol) { | ||
var lineIdx = 0, colIdx = index, pos = 0; | ||
do { | ||
pos = text.indexOf(eol, pos); | ||
if (pos === -1 || index < pos + eol.length) { | ||
break; | ||
} | ||
lineIdx++; | ||
pos += eol.length; | ||
colIdx = index - pos; | ||
} while (pos < index); | ||
return { | ||
line: lineIdx + 1, | ||
column: colIdx + 1 | ||
}; | ||
} | ||
//////////////////////////////////// | ||
@@ -221,8 +180,2 @@ // Identifies a gap / empty symbol. | ||
module.exports = { | ||
minify: minify, | ||
// these are exported only for testing: | ||
getEOL: getEOL, | ||
getIndexPos: getIndexPos | ||
}; | ||
module.exports = minify; |
{ | ||
"name": "pg-minify", | ||
"version": "0.4.4", | ||
"version": "0.4.5", | ||
"description": "Minifies PostgreSQL scripts.", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
pg-minify | ||
========= | ||
Minifies PostgreSQL scripts. | ||
@@ -10,3 +11,3 @@ | ||
Features: | ||
**Features:** | ||
@@ -21,2 +22,9 @@ * Removes both `/*multi-line*/` and `--single-line` comments | ||
This library is originally for PostgreSQL, though it works for MS-SQL and MySQL also. | ||
**Limitations:** | ||
* Multi-line quoted identifiers are not supported, throwing an error when encountered. | ||
* Nested multi-line comments are not supported - `/* /* nested */ */`. | ||
## Installing | ||
@@ -23,0 +31,0 @@ |
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
14132
8
289
102