New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

flexmonster-compressor

Package Overview
Dependencies
Maintainers
1
Versions
51
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

flexmonster-compressor - npm Package Compare versions

Comparing version 2.7.2 to 2.7.3

test/data/json-data-empty-1.json

2

package.json
{
"name": "flexmonster-compressor",
"version": "2.7.2",
"version": "2.7.3",
"description": "Flexmonster Compressor for Node.js – a special server-side compression tool that helps you to increase data loading speed from server to Flexmonster Pivot Table component.",

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

@@ -103,2 +103,5 @@ const version = require('../version');

var timeParts = timeStr.split(":");
if (timeParts.length == 1) {
return parseInt(timeParts[0]);
}
var hh = parseInt(timeParts[0]);

@@ -105,0 +108,0 @@ var mm = parseInt(timeParts[1]);

@@ -10,2 +10,3 @@ const { BaseReader, ColumnType } = require("./BaseReader");

this.FIELD_ENCLOSURE_TOKEN = '"';
this.isStarted = false;
}

@@ -29,2 +30,5 @@

input.on('close', () => {
if (this._header == null) {
stream.push(this.processHeaderRow(this.headerRow));
}
stream.push(null);

@@ -41,3 +45,4 @@ });

output += this.processHeaderRow(this.headerRow, row);
output += this.processDataRow(row);
output += this.processDataRow(row);
this.isStarted = true;
} else {

@@ -115,2 +120,5 @@ output += this.processDataRow(row);

chooseDelimiter(row) {
if (!row) {
return ',';
}
let commas = row.split(",").length;

@@ -117,0 +125,0 @@ let semicoloms = row.split(";").length;

@@ -36,3 +36,3 @@ const {

if (!_this._header) {
stream.push(_this.processRow(null));
stream.push(_this.processHeaderRow(_this.headerRow));
}

@@ -43,3 +43,3 @@ stream.push(null);

if (!_this._header) {
stream.push(_this.processRow(null));
stream.push(_this.processHeaderRow(_this.headerRow));
}

@@ -63,4 +63,4 @@ stream.push(null);

}
if (inputArray.length == 1) {
this.push(_this.processRow(null));
if (!_this._header) {
this.push(_this.processHeaderRow(_this.headerRow))
}

@@ -87,3 +87,3 @@ this.push(null);

if (!_this._header) {
stream.push(_this.processRow(null));
stream.push(_this.processHeaderRow(_this.headerRow));
}

@@ -90,0 +90,0 @@ stream.push(null);

module.exports = {
VERSION: "2.7.2",
VERSION: "2.7.3",
VERSION_COMPATIBLE: "2.213"
}

@@ -5,3 +5,3 @@ const assert = require('assert');

const toString = require('stream-to-string');
const { replaceNewLines, removeOcsvHeader } = require('./utils');
const { replaceNewLines, removeOcsvHeader, getOcsvHeader } = require('./utils');

@@ -20,2 +20,14 @@ describe('CSV', function () {

});
it('Empty string', async () => {
let compressed = await toString(compressor.compressCsv(""));
let actual = getOcsvHeader();
assert.equal(compressed.trim(), actual);
});
it('Just header', async () => {
let compressed = await toString(compressor.compressCsv("Column"));
let actual = `${getOcsvHeader()}\n+Column`;
assert.equal(compressed.trim(), actual);
});
});

@@ -5,3 +5,7 @@ const assert = require('assert');

const fs = require('fs');
const { replaceNewLines, removeOcsvHeader } = require('./utils');
const {
replaceNewLines,
removeOcsvHeader,
getOcsvHeader
} = require('./utils');

@@ -11,5 +15,5 @@ describe('JSON', () => {

it('as string', async () => {
let json = [
{ "Field": "Value 2" }
];
let json = [{
"Field": "Value 2"
}];
let compressed = await toString(compressor.compressJson(json));

@@ -19,8 +23,15 @@ let actual = `+Field\nValue 2`;

});
it('with header', async () => {
let json = [
{ "Field": { type: "string" } },
{ "Field": "Value 2" },
{ "Field": "Value 2" }
let json = [{
"Field": {
type: "string"
}
},
{
"Field": "Value 2"
},
{
"Field": "Value 2"
}
];

@@ -31,8 +42,15 @@ let compressed = await toString(compressor.compressJson(json));

});
it('as number', async () => {
let json = [
{ "Field": { type: "string" } },
{ "Field": 123 },
{ "Field": "Value 2" },
let json = [{
"Field": {
type: "string"
}
},
{
"Field": 123
},
{
"Field": "Value 2"
},
];

@@ -47,5 +65,8 @@ let compressed = await toString(compressor.compressJson(json));

it('as number', async () => {
let json = [
{ "Field": 123 },
{ "Field": 123 }
let json = [{
"Field": 123
},
{
"Field": 123
}
];

@@ -56,8 +77,15 @@ let compressed = await toString(compressor.compressJson(json));

});
it('as string', async () => {
let json = [
{ "Field": { type: "number"} },
{ "Field": "123.98" },
{ "Field": 123.99 }
let json = [{
"Field": {
type: "number"
}
},
{
"Field": "123.98"
},
{
"Field": 123.99
}
];

@@ -68,8 +96,15 @@ let compressed = await toString(compressor.compressJson(json));

});
it('empty value', async () => {
let json = [
{ "Field": { type: "number"} },
{ "Field": "" },
{ "Field": 123 }
let json = [{
"Field": {
type: "number"
}
},
{
"Field": ""
},
{
"Field": 123
}
];

@@ -84,7 +119,16 @@ let compressed = await toString(compressor.compressJson(json));

it('as string', async () => {
let json = [
{ "Field": { type: "month" } },
{ "Field": "April" },
{ "Field": "January" },
{ "Field": "January" }
let json = [{
"Field": {
type: "month"
}
},
{
"Field": "April"
},
{
"Field": "January"
},
{
"Field": "January"
}
];

@@ -99,7 +143,16 @@ let compressed = await toString(compressor.compressJson(json));

it('as string', async () => {
let json = [
{ "Field": { type: "weekday" } },
{ "Field": "Wednesday" },
{ "Field": "Monday" },
{ "Field": "Monday" }
let json = [{
"Field": {
type: "weekday"
}
},
{
"Field": "Wednesday"
},
{
"Field": "Monday"
},
{
"Field": "Monday"
}
];

@@ -115,5 +168,5 @@ let compressed = await toString(compressor.compressJson(json));

it('as string', async () => {
let json = [
{ "Field": "2016-01-20" }
];
let json = [{
"Field": "2016-01-20"
}];
let compressed = await toString(compressor.compressJson(json));

@@ -123,7 +176,7 @@ let actual = `d+Field\n1453248000`;

});
it('as Date object', async () => {
let json = [
{ "Field": new Date("2016-01-20") }
];
let json = [{
"Field": new Date("2016-01-20")
}];
let compressed = await toString(compressor.compressJson(json));

@@ -133,7 +186,12 @@ let actual = `d+Field\n1453248000`;

});
it('as timestamp (number)', async () => {
let json = [
{ "Field": { type: "date" } },
{ "Field": new Date("2016-01-20").getTime() }
let json = [{
"Field": {
type: "date"
}
},
{
"Field": new Date("2016-01-20").getTime()
}
];

@@ -146,5 +204,10 @@ let compressed = await toString(compressor.compressJson(json));

it('with header', async () => {
let json = [
{ "Field": { type: "date" } },
{ "Field": "2016-01-20" }
let json = [{
"Field": {
type: "date"
}
},
{
"Field": "2016-01-20"
}
];

@@ -155,7 +218,12 @@ let compressed = await toString(compressor.compressJson(json));

});
it('before 1970 (negative timestamp)', async () => {
let json = [
{ "Field": { type: "date" } },
{ "Field": "1915-01-20" }
let json = [{
"Field": {
type: "date"
}
},
{
"Field": "1915-01-20"
}
];

@@ -168,7 +236,14 @@ let compressed = await toString(compressor.compressJson(json));

it('timeZone +02:00', async () => {
let json = [
{ "Field": { type: "date" } },
{ "Field": "2016-01-20" }
let json = [{
"Field": {
type: "date"
}
},
{
"Field": "2016-01-20"
}
];
let compressed = await toString(compressor.compressJson(json, { timeZone: "+02:00"}));
let compressed = await toString(compressor.compressJson(json, {
timeZone: "+02:00"
}));
let actual = `d+Field\n1453240800`;

@@ -179,7 +254,14 @@ assert.equal(removeOcsvHeader(compressed), actual);

it('timeZone -02:00', async () => {
let json = [
{ "Field": { type: "date" } },
{ "Field": "2016-01-20" }
let json = [{
"Field": {
type: "date"
}
},
{
"Field": "2016-01-20"
}
];
let compressed = await toString(compressor.compressJson(json, { timeZone: "-02:00"}));
let compressed = await toString(compressor.compressJson(json, {
timeZone: "-02:00"
}));
let actual = `d+Field\n1453255200`;

@@ -192,5 +274,10 @@ assert.equal(removeOcsvHeader(compressed), actual);

it('as string', async () => {
let json = [
{ "Field": { type: "date string" } },
{ "Field": "2016-01-20" }
let json = [{
"Field": {
type: "date string"
}
},
{
"Field": "2016-01-20"
}
];

@@ -205,5 +292,10 @@ let compressed = await toString(compressor.compressJson(json));

it('as string', async () => {
let json = [
{ "Field": { type: "year/month/day" } },
{ "Field": "2016-01-20" }
let json = [{
"Field": {
type: "year/month/day"
}
},
{
"Field": "2016-01-20"
}
];

@@ -218,5 +310,10 @@ let compressed = await toString(compressor.compressJson(json));

it('as string', async () => {
let json = [
{ "Field": { type: "year/quarter/month/day" } },
{ "Field": "2016-01-20" }
let json = [{
"Field": {
type: "year/quarter/month/day"
}
},
{
"Field": "2016-01-20"
}
];

@@ -228,8 +325,13 @@ let compressed = await toString(compressor.compressJson(json));

});
describe("type time", () => {
it('as number', async () => {
let json = [
{ "Field": { type: "time" } },
{ "Field": 100 }
let json = [{
"Field": {
type: "time"
}
},
{
"Field": 100
}
];

@@ -242,5 +344,10 @@ let compressed = await toString(compressor.compressJson(json));

it('as string', async () => {
let json = [
{ "Field": { type: "time" } },
{ "Field": "100" }
let json = [{
"Field": {
type: "time"
}
},
{
"Field": "100"
}
];

@@ -253,5 +360,10 @@ let compressed = await toString(compressor.compressJson(json));

it('as date', async () => {
let json = [
{ "Field": { type: "time" } },
{ "Field": new Date(100) }
let json = [{
"Field": {
type: "time"
}
},
{
"Field": new Date(100)
}
];

@@ -266,5 +378,10 @@ let compressed = await toString(compressor.compressJson(json));

it('as number', async () => {
let json = [
{ "Field": { type: "datetime" } },
{ "Field": new Date("2016-01-21T23:59:59").getTime() }
let json = [{
"Field": {
type: "datetime"
}
},
{
"Field": new Date("2016-01-21T23:59:59").getTime()
}
];

@@ -277,5 +394,10 @@ let compressed = await toString(compressor.compressJson(json));

it('as date', async () => {
let json = [
{ "Field": { type: "datetime" } },
{ "Field": new Date("2016-01-21T23:59:59") }
let json = [{
"Field": {
type: "datetime"
}
},
{
"Field": new Date("2016-01-21T23:59:59")
}
];

@@ -290,9 +412,20 @@ let compressed = await toString(compressor.compressJson(json));

it('check levels', async () => {
let json = [
let json = [{
"Country": {
type: "level"
},
"State": {
type: "level",
parent: "Country"
},
"City": {
type: "level",
parent: "State"
}
},
{
"Country": { type: "level" },
"State": { type: "level", parent: "Country" },
"City": { type: "level", parent: "State" }
},
{ "Country": "USA", "State": "CA", "City": "Los Angeles" }
"Country": "USA",
"State": "CA",
"City": "Los Angeles"
}
];

@@ -334,6 +467,9 @@ let compressed = await toString(compressor.compressJson(json));

it('with header', async () => {
let json = [
{
"Field": { type: "string" },
"Date": { type: "date string" }
let json = [{
"Field": {
type: "string"
},
"Date": {
type: "date string"
}
},

@@ -350,3 +486,3 @@ ["Value1", "2018-01-01"]

let files = [
'./test/data/json-data-1',
'./test/data/json-data-1',
'./test/data/json-data-2',

@@ -363,2 +499,68 @@ './test/data/json-data-3',

});
describe('empty', () => {
it('array: empty', async () => {
let compressed = await toString(compressor.compressJson([]));
compressed = compressed.trim();
let actual = getOcsvHeader();
assert.equal(compressed, actual);
});
it('array: with header as array', async () => {
let compressed = await toString(compressor.compressJson([
["Column"]
]));
compressed = compressed.trim();
let actual = `${getOcsvHeader()}\n+Column`;
assert.equal(compressed, actual);
});
it('array: with header as object (meta)', async () => {
let compressed = await toString(compressor.compressJson([{
"Column": {
"type": "string"
}
}]));
compressed = compressed.trim();
let actual = `${getOcsvHeader()}\n+Column`;
assert.equal(compressed, actual);
});
it('array: with header as object (with data)', async () => {
let compressed = await toString(compressor.compressJson([{
"Column": "val"
}]));
compressed = compressed.trim();
let actual = `${getOcsvHeader()}\n+Column\nval`;
assert.equal(compressed, actual);
});
it('file: empty array', async () => {
let compressed = await toString(compressor.compressJsonFile('./test/data/json-data-empty-1.json'));
compressed = compressed.trim();
let actual = getOcsvHeader();
assert.equal(compressed, actual);
});
it('file: with header as array', async () => {
let compressed = await toString(compressor.compressJsonFile('./test/data/json-data-empty-2.json'));
compressed = compressed.trim();
let actual = `${getOcsvHeader()}\n+Column`;
assert.equal(compressed, actual);
});
it('file: with header as object (meta)', async () => {
let compressed = await toString(compressor.compressJsonFile('./test/data/json-data-empty-3.json'));
compressed = compressed.trim();
let actual = `${getOcsvHeader()}\n+Column`;
assert.equal(compressed, actual);
});
it('file: with header as object (with data)', async () => {
let compressed = await toString(compressor.compressJsonFile('./test/data/json-data-empty-4.json'));
compressed = compressed.trim();
let actual = `${getOcsvHeader()}\n+Column\nval`;
assert.equal(compressed, actual);
});
});
});

@@ -0,1 +1,3 @@

const version = require('../src/version');
module.exports.replaceNewLines = (data) => {

@@ -7,2 +9,6 @@ return data.replace(/\r\n/g, '\n');

return data.substring(data.indexOf("\n") + 1).trim();
}
module.exports.getOcsvHeader = () => {
return `___ocsv2___${version.VERSION}/${version.VERSION_COMPATIBLE}`;
}
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