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 0.0.5 to 0.1.0

23

lib/parser.js

@@ -123,26 +123,15 @@ 'use strict';

function getIndexPos(text, index, eol) {
var line = 1, col = 1, pos = 0;
var lineIdx = 0, colIdx = index, pos = 0;
do {
pos = text.indexOf(eol, pos);
if (pos == -1) {
if (pos == -1 || index < pos + eol.length) {
break;
}
lineIdx++;
pos += eol.length;
if (pos <= index) {
line++;
}
colIdx = index - pos;
} while (pos < index);
if (index >= eol.length) {
var lastIdx = text.lastIndexOf(eol, index - eol.length);
if (lastIdx === -1) {
col = index;
} else {
col = index - lastIdx - eol.length + 1;
}
} else {
col = index + 1;
}
return {
line: line,
column: col
line: lineIdx + 1,
column: colIdx + 1
};

@@ -149,0 +138,0 @@ }

{
"name": "pg-minify",
"version": "0.0.5",
"version": "0.1.0",
"description": "Minifies PostgreSQL scripts.",

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

@@ -53,3 +53,3 @@ pg-minify

// error.message:
// Error parsing SQL at {line:1,col:7}: Unclosed text block.
// Error parsing SQL at {line:1,col:8}: Unclosed text block.
}

@@ -56,0 +56,0 @@ ```

@@ -96,3 +96,2 @@ 'use strict';

});

@@ -116,2 +115,3 @@

var errMsg = "Error parsing SQL at {line:1,col:1}: Unclosed text block.";
it("must throw an error", function () {

@@ -143,4 +143,19 @@ expect(function () {

}));
});
it("must report positions correctly", function () {
expect(getErrorPos("'").column).toBe(1);
expect(getErrorPos(" '").column).toBe(2);
expect(getErrorPos("s'").column).toBe(2);
expect(getErrorPos("s '").column).toBe(3);
});
function getErrorPos(sql) {
try {
minify(sql);
} catch (e) {
return e.position;
}
return null;
}
});

@@ -194,2 +209,16 @@

it("must work from the start", function () {
expect(pos("123456", 3)).toEqual({
line: 1,
column: 4
});
});
it("must work from the start", function () {
expect(pos("123456", 5)).toEqual({
line: 1,
column: 6
});
});
it("step over lines correctly", function () {

@@ -202,6 +231,6 @@ expect(pos("123\r\n456", 5)).toEqual({

it("must step back from a line break", function () {
it("must step over line breaks", function () {
expect(pos("123\r\n", 3)).toEqual({
line: 1,
column: 3
column: 4
});

@@ -208,0 +237,0 @@ });

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