Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

pg-minify

Package Overview
Dependencies
Maintainers
1
Versions
54
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pg-minify - npm Package Compare versions

Comparing version 1.3.0 to 1.4.0

26

lib/parser.js

@@ -23,2 +23,4 @@ 'use strict';

sql = sql.replace(/\r\n/g, '\n');
options = options || {};

@@ -30,4 +32,3 @@

const len = sql.length, // sql length
EOL = utils.getEOL(sql); // end-of-line
const len = sql.length;

@@ -39,3 +40,3 @@ do {

if (isGap(s)) {
while (++idx < len && isGap(sql[idx]));
while (++idx < len && isGap(sql[idx])) ;
if (idx < len) {

@@ -49,3 +50,3 @@ space = true;

if (s === '-' && s1 === '-') {
const lb = sql.indexOf(EOL, idx + 2);
const lb = sql.indexOf('\n', idx + 2);
if (lb < 0) {

@@ -83,3 +84,4 @@ break;

addSpace();
result += sql.substring(idx, lastClose + 2);
result += sql.substring(idx, lastClose + 2)
.replace(/\n/g, '\r\n');
}

@@ -99,3 +101,3 @@ idx = lastClose + 1;

text = sql.substring(idx, closeIdx + 1);
if (text.indexOf(EOL) > 0) {
if (text.indexOf('\n') > 0) {
throwError(PEC.multiLineQI);

@@ -119,6 +121,6 @@ }

let i = closeIdx;
while (sql[--i] === '\\');
while (sql[--i] === '\\') ;
if ((closeIdx - i) % 2) {
let step = closeIdx;
while (++step < len && sql[step] === '\'');
while (++step < len && sql[step] === '\'') ;
if ((step - closeIdx) % 2) {

@@ -140,5 +142,5 @@ closeIdx = step - 1;

text = sql.substring(idx, closeIdx + 1);
const hasLB = text.indexOf(EOL) > 0;
const hasLB = text.indexOf('\n') > 0;
if (hasLB) {
text = text.split(EOL).map(m => {
text = text.split('\n').map(m => {
return m.replace(/^\s+|\s+$/g, '');

@@ -181,3 +183,3 @@ }).join('\\n');

if (options.compress) {
while (idx < len - 1 && isGap(sql[idx + 1]) && idx++);
while (idx < len - 1 && isGap(sql[idx + 1]) && idx++) ;
}

@@ -196,3 +198,3 @@ }

function throwError(code) {
const position = utils.getIndexPos(sql, idx, EOL);
const position = utils.getIndexPos(sql, idx);
throw new errorLib.SQLParsingError(code, position);

@@ -199,0 +201,0 @@ }

'use strict';
const os = require('os');
const util = require('util');
//////////////////////////////////////
// Returns the End-Of-Line from text.
function getEOL(text) {
const m1 = text.match(/\r\n/g);
const m2 = text.match(/\n/g);
const w = m1 ? m1.length : 0;
const u = m2 ? m2.length - w : 0;
if (u === w) {
return os.EOL;
}
return u > w ? '\n' : '\r\n';
}
///////////////////////////////////////////////////////
// Returns {line, column} of an index within the text.
function getIndexPos(text, index, eol) {
function getIndexPos(text, index) {
let lineIdx = 0, colIdx = index, pos = 0;
do {
pos = text.indexOf(eol, pos);
if (pos === -1 || index < pos + eol.length) {
pos = text.indexOf('\n', pos);
if (pos === -1 || index < pos + 1) {
break;
}
lineIdx++;
pos += eol.length;
pos += 1;
colIdx = index - pos;

@@ -56,3 +42,2 @@ } while (pos < index);

module.exports = {
getEOL,
getIndexPos,

@@ -59,0 +44,0 @@ messageGap,

{
"name": "pg-minify",
"version": "1.3.0",
"version": "1.4.0",
"description": "Minifies PostgreSQL scripts.",

@@ -5,0 +5,0 @@ "main": "lib/index.js",

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