flexmonster-compressor
Advanced tools
Comparing version 2.7.12 to 2.7.13
{ | ||
"name": "flexmonster-compressor", | ||
"version": "2.7.12", | ||
"version": "2.7.13", | ||
"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", |
@@ -56,5 +56,5 @@ const version = require('../version'); | ||
this._header.forEach(column => { | ||
columns.push(this.getColumnPrefix(column.type) + this.encodeChars(column.caption)); | ||
columns.push(this.getColumnPrefix(column.type) + column.caption); | ||
}); | ||
return `___ocsv2___${version.VERSION}/${version.VERSION_COMPATIBLE}\n` + columns.join(",") + `\n`; | ||
return columns.join(",") + `\n`; | ||
} | ||
@@ -65,3 +65,3 @@ | ||
for (let colIdx = 0; colIdx < this._header.length; colIdx++) { | ||
result.push(this.addMember(values[colIdx], colIdx, values)); | ||
result.push(values[colIdx] ? values[colIdx].toString() : ""); | ||
} | ||
@@ -71,71 +71,2 @@ return result.join(",") + "\n"; | ||
addMember(value, colIdx, _values) { | ||
let type = this._header[colIdx].type; | ||
if (type == ColumnType.FACT) { | ||
return value ? this.toNumber(value) : ""; | ||
} else if (type == ColumnType.STRING || type == ColumnType.WEEKDAY || type == ColumnType.MONTH || type == ColumnType.LEVELS) { | ||
let _col = this._header[colIdx].parentHierarchy ? this._header[colIdx].parentHierarchy : this._header[colIdx]; | ||
let v = value ? value.toString() : ""; | ||
if (type == ColumnType.LEVELS) { | ||
v = this.getFullLevelMemberCaption(_values, colIdx); | ||
} | ||
if (_col.members[v.toLowerCase()] !== undefined) { | ||
return "^" + _col.members[v.toLowerCase()]; | ||
} else { | ||
_col.members[v.toLowerCase()] = _col.membersCount++; | ||
return this.encodeChars(value ? value.toString() : ""); | ||
} | ||
} else if (type == ColumnType.DATE || | ||
type == ColumnType.DATE_STRING || | ||
type == ColumnType.DATE_WITH_MONTHS || | ||
type == ColumnType.DATE_WITH_QUARTERS) { | ||
return moment.utc(value).unix() - this._timeZoneOffset; | ||
} else if (type == ColumnType.DATETIME) { | ||
if (value instanceof Date) { | ||
return value.getTime(); | ||
} | ||
} else if (type == ColumnType.TIME) { | ||
if (value instanceof Date) { | ||
return value.getTime(); | ||
} | ||
if (typeof value == "string") { | ||
return this.timeStrToSeconds(value) | ||
} | ||
} | ||
return value ? value.toString() : ""; | ||
} | ||
//composes full level's member name in reverse order, example: "Chicago.Illinois.Midwest" | ||
getFullLevelMemberCaption(_values, colIdx) { | ||
let memberNames = []; | ||
while (this._header[colIdx].parentHierarchy) { | ||
memberNames.push(_values[colIdx]); | ||
colIdx--; | ||
} | ||
memberNames.push(_values[colIdx]); | ||
return memberNames.join("."); | ||
} | ||
timeStrToSeconds(timeStr) { | ||
var timeParts = timeStr.split(":"); | ||
if (timeParts.length == 1) { | ||
return parseInt(timeParts[0]); | ||
} | ||
var hh = parseInt(timeParts[0]); | ||
var mm = parseInt(timeParts[1]); | ||
var ss = parseInt(timeParts[2]); | ||
return isNaN(ss) ? hh * 60 + mm : | ||
hh * 3600 + mm * 60 + ss; | ||
} | ||
toNumber(value) { | ||
if (value == null) return NaN; | ||
if (typeof value === 'number') return value; | ||
if (typeof value !== 'string') value = value.toString(); | ||
var _pattern = /[^[,|\.|\-|\d|e]]*/gi; | ||
value = value.replace(",", "."); | ||
value = value.replace(_pattern, ""); | ||
return parseFloat(value); | ||
} | ||
encodeChars(input) { | ||
@@ -142,0 +73,0 @@ return input.replace(/,/g, "%d%").replace(/"/g, "%q%").replace(/\n/g, "%n%"); |
@@ -126,3 +126,19 @@ const { BaseReader, ColumnType } = require("./BaseReader"); | ||
return (commas > semicoloms) ? ',' : ';'; | ||
} | ||
} | ||
composeHeader() { | ||
let columns = []; | ||
this._header.forEach(column => { | ||
columns.push(this.getColumnPrefix(column.type) + column.caption); | ||
}); | ||
return columns.join(this.delimiter) + `\n`; | ||
} | ||
composeDataRow(values) { | ||
let result = []; | ||
for (let colIdx = 0; colIdx < this._header.length; colIdx++) { | ||
result.push(values[colIdx] ? values[colIdx].toString() : ""); | ||
} | ||
return result.join(this.delimiter) + "\n"; | ||
} | ||
} | ||
@@ -129,0 +145,0 @@ |
module.exports = { | ||
VERSION: "2.7.12", | ||
VERSION_COMPATIBLE: "2.213" | ||
VERSION: "2.7.13", | ||
VERSION_COMPATIBLE: "2.7.13" | ||
} |
@@ -7,4 +7,3 @@ const assert = require('assert'); | ||
replaceNewLines, | ||
removeOcsvHeader, | ||
getOcsvHeader | ||
removeHeaders | ||
} = require('./utils'); | ||
@@ -21,3 +20,3 @@ | ||
let actual = replaceNewLines(fs.readFileSync(`${filename}.ocsv`).toString()); | ||
assert.equal(removeOcsvHeader(compressed), removeOcsvHeader(actual)); | ||
assert.equal(removeHeaders(compressed), removeHeaders(actual)); | ||
}); | ||
@@ -30,3 +29,3 @@ }); | ||
let actual = replaceNewLines(fs.readFileSync(`${filename}.ocsv`).toString()); | ||
assert.equal(removeOcsvHeader(compressed), removeOcsvHeader(actual)); | ||
assert.equal(removeHeaders(compressed), removeHeaders(actual)); | ||
}); | ||
@@ -36,3 +35,3 @@ | ||
let compressed = await toString(compressor.compressCsv("")); | ||
let actual = getOcsvHeader(); | ||
let actual = ""; | ||
assert.equal(compressed.trim(), actual); | ||
@@ -43,5 +42,5 @@ }); | ||
let compressed = await toString(compressor.compressCsv("Column")); | ||
let actual = `${getOcsvHeader()}\n+Column`; | ||
let actual = "+Column"; | ||
assert.equal(compressed.trim(), actual); | ||
}); | ||
}); |
@@ -7,4 +7,3 @@ const assert = require('assert'); | ||
replaceNewLines, | ||
removeOcsvHeader, | ||
getOcsvHeader | ||
removeHeaders | ||
} = require('./utils'); | ||
@@ -19,4 +18,4 @@ | ||
let compressed = await toString(compressor.compressJson(json)); | ||
let actual = `+Field\nValue 2`; | ||
assert.equal(removeOcsvHeader(compressed), actual); | ||
let actual = `+Field\nValue 2\n`; | ||
assert.equal(removeHeaders(compressed), removeHeaders(actual)); | ||
}); | ||
@@ -38,4 +37,4 @@ | ||
let compressed = await toString(compressor.compressJson(json)); | ||
let actual = `+Field\nValue 2\n^0`; | ||
assert.equal(removeOcsvHeader(compressed), actual); | ||
let actual = `+Field\nValue 2\nValue 2\n`; | ||
assert.equal(removeHeaders(compressed), removeHeaders(actual)); | ||
}); | ||
@@ -57,4 +56,4 @@ | ||
let compressed = await toString(compressor.compressJson(json)); | ||
let actual = `+Field\n123\nValue 2`; | ||
assert.equal(removeOcsvHeader(compressed), actual); | ||
let actual = `+Field\n123\nValue 2\n`; | ||
assert.equal(removeHeaders(compressed), removeHeaders(actual)); | ||
}); | ||
@@ -73,4 +72,4 @@ }); | ||
let compressed = await toString(compressor.compressJson(json)); | ||
let actual = `-Field\n123\n123`; | ||
assert.equal(removeOcsvHeader(compressed), actual); | ||
let actual = `-Field\n123\n123\n`; | ||
assert.equal(removeHeaders(compressed), removeHeaders(actual)); | ||
}); | ||
@@ -92,4 +91,4 @@ | ||
let compressed = await toString(compressor.compressJson(json)); | ||
let actual = `-Field\n123.98\n123.99`; | ||
assert.equal(removeOcsvHeader(compressed), actual); | ||
let actual = `-Field\n123.98\n123.99\n`; | ||
assert.equal(removeHeaders(compressed), removeHeaders(actual)); | ||
}); | ||
@@ -111,4 +110,4 @@ | ||
let compressed = await toString(compressor.compressJson(json)); | ||
let actual = `-Field\n\n123`; | ||
assert.equal(removeOcsvHeader(compressed), actual); | ||
let actual = `-Field\n\n123\n`; | ||
assert.equal(removeHeaders(compressed), removeHeaders(actual)); | ||
}); | ||
@@ -135,4 +134,4 @@ }); | ||
let compressed = await toString(compressor.compressJson(json)); | ||
let actual = `m+Field\nApril\nJanuary\n^1`; | ||
assert.equal(removeOcsvHeader(compressed), actual); | ||
let actual = `m+Field\nApril\nJanuary\nJanuary\n`; | ||
assert.equal(removeHeaders(compressed), removeHeaders(actual)); | ||
}); | ||
@@ -159,4 +158,4 @@ }); | ||
let compressed = await toString(compressor.compressJson(json)); | ||
let actual = `w+Field\nWednesday\nMonday\n^1`; | ||
assert.equal(removeOcsvHeader(compressed), actual); | ||
let actual = `w+Field\nWednesday\nMonday\nMonday\n`; | ||
assert.equal(removeHeaders(compressed), removeHeaders(actual)); | ||
}); | ||
@@ -172,4 +171,4 @@ }); | ||
let compressed = await toString(compressor.compressJson(json)); | ||
let actual = `d+Field\n1453248000`; | ||
assert.equal(removeOcsvHeader(compressed), actual); | ||
let actual = `d+Field\n2016-01-20\n`; | ||
assert.equal(removeHeaders(compressed), removeHeaders(actual)); | ||
}); | ||
@@ -182,4 +181,4 @@ | ||
let compressed = await toString(compressor.compressJson(json)); | ||
let actual = `d+Field\n1453248000`; | ||
assert.equal(removeOcsvHeader(compressed), actual); | ||
let actual = `d+Field\nWed Jan 20 2016 02:00:00 GMT+0200 (Eastern European Standard Time)\n`; | ||
assert.equal(removeHeaders(compressed), removeHeaders(actual)); | ||
}); | ||
@@ -198,4 +197,4 @@ | ||
let compressed = await toString(compressor.compressJson(json)); | ||
let actual = `d+Field\n1453248000`; | ||
assert.equal(removeOcsvHeader(compressed), actual); | ||
let actual = `d+Field\n1453248000000\n`; | ||
assert.equal(removeHeaders(compressed), removeHeaders(actual)); | ||
}); | ||
@@ -214,4 +213,4 @@ | ||
let compressed = await toString(compressor.compressJson(json)); | ||
let actual = `d+Field\n1453248000`; | ||
assert.equal(removeOcsvHeader(compressed), actual); | ||
let actual = `d+Field\n2016-01-20\n`; | ||
assert.equal(removeHeaders(compressed), removeHeaders(actual)); | ||
}); | ||
@@ -230,4 +229,4 @@ | ||
let compressed = await toString(compressor.compressJson(json)); | ||
let actual = `d+Field\n-1734048000`; | ||
assert.equal(removeOcsvHeader(compressed), actual); | ||
let actual = `d+Field\n1915-01-20\n`; | ||
assert.equal(removeHeaders(compressed), removeHeaders(actual)); | ||
}); | ||
@@ -248,4 +247,4 @@ | ||
})); | ||
let actual = `d+Field\n1453240800`; | ||
assert.equal(removeOcsvHeader(compressed), actual); | ||
let actual = `d+Field\n2016-01-20\n`; | ||
assert.equal(removeHeaders(compressed), removeHeaders(actual)); | ||
}); | ||
@@ -266,4 +265,4 @@ | ||
})); | ||
let actual = `d+Field\n1453255200`; | ||
assert.equal(removeOcsvHeader(compressed), actual); | ||
let actual = `d+Field\n2016-01-20\n`; | ||
assert.equal(removeHeaders(compressed), removeHeaders(actual)); | ||
}); | ||
@@ -284,4 +283,4 @@ }); | ||
let compressed = await toString(compressor.compressJson(json)); | ||
let actual = `ds+Field\n1453248000`; | ||
assert.equal(removeOcsvHeader(compressed), actual); | ||
let actual = `ds+Field\n2016-01-20\n`; | ||
assert.equal(removeHeaders(compressed), removeHeaders(actual)); | ||
}); | ||
@@ -302,4 +301,4 @@ }); | ||
let compressed = await toString(compressor.compressJson(json)); | ||
let actual = `D+Field\n1453248000`; | ||
assert.equal(removeOcsvHeader(compressed), actual); | ||
let actual = `D+Field\n2016-01-20\n`; | ||
assert.equal(removeHeaders(compressed), removeHeaders(actual)); | ||
}); | ||
@@ -320,4 +319,4 @@ }); | ||
let compressed = await toString(compressor.compressJson(json)); | ||
let actual = `D4+Field\n1453248000`; | ||
assert.equal(removeOcsvHeader(compressed), actual); | ||
let actual = `D4+Field\n2016-01-20\n`; | ||
assert.equal(removeHeaders(compressed), removeHeaders(actual)); | ||
}); | ||
@@ -338,4 +337,4 @@ }); | ||
let compressed = await toString(compressor.compressJson(json)); | ||
let actual = `t+Field\n100`; | ||
assert.equal(removeOcsvHeader(compressed), actual); | ||
let actual = `t+Field\n100\n`; | ||
assert.equal(removeHeaders(compressed), removeHeaders(actual)); | ||
}); | ||
@@ -354,4 +353,4 @@ | ||
let compressed = await toString(compressor.compressJson(json)); | ||
let actual = `t+Field\n100`; | ||
assert.equal(removeOcsvHeader(compressed), actual); | ||
let actual = `t+Field\n100\n`; | ||
assert.equal(removeHeaders(compressed), removeHeaders(actual)); | ||
}); | ||
@@ -370,4 +369,4 @@ | ||
let compressed = await toString(compressor.compressJson(json)); | ||
let actual = `t+Field\n100`; | ||
assert.equal(removeOcsvHeader(compressed), actual); | ||
let actual = `t+Field\nThu Jan 01 1970 03:00:00 GMT+0300 (Eastern European Standard Time)\n`; | ||
assert.equal(removeHeaders(compressed), removeHeaders(actual)); | ||
}); | ||
@@ -388,4 +387,4 @@ }); | ||
let compressed = await toString(compressor.compressJson(json)); | ||
let actual = `dt+Field\n1453413599000`; | ||
assert.equal(removeOcsvHeader(compressed), actual); | ||
let actual = `dt+Field\n1453413599000\n`; | ||
assert.equal(removeHeaders(compressed), removeHeaders(actual)); | ||
}); | ||
@@ -404,4 +403,4 @@ | ||
let compressed = await toString(compressor.compressJson(json)); | ||
let actual = `dt+Field\n1453413599000`; | ||
assert.equal(removeOcsvHeader(compressed), actual); | ||
let actual = `dt+Field\nThu Jan 21 2016 23:59:59 GMT+0200 (Eastern European Standard Time)\n`; | ||
assert.equal(removeHeaders(compressed), removeHeaders(actual)); | ||
}); | ||
@@ -433,3 +432,3 @@ }); | ||
let actual = `+Country,+Country:State,+Country:State:City\nUSA,CA,Los Angeles`; | ||
assert.equal(removeOcsvHeader(compressed), actual); | ||
assert.equal(removeHeaders(compressed), removeHeaders(actual)); | ||
}); | ||
@@ -444,4 +443,4 @@ }); | ||
let compressed = await toString(compressor.compressJson(json)); | ||
let actual = `+Field,+Price`; | ||
assert.equal(removeOcsvHeader(compressed), actual); | ||
let actual = "+Field,+Price\n"; | ||
assert.equal(compressed, actual); | ||
}); | ||
@@ -455,4 +454,4 @@ it('few rows', async () => { | ||
let compressed = await toString(compressor.compressJson(json)); | ||
let actual = `+Field,-Price\nValue1,99\n^0,99`; | ||
assert.equal(removeOcsvHeader(compressed), actual); | ||
let actual = `+Field,-Price\nValue1,99\nValue1,99`; | ||
assert.equal(removeHeaders(compressed), removeHeaders(actual)); | ||
}); | ||
@@ -465,4 +464,4 @@ it('with date', async () => { | ||
let compressed = await toString(compressor.compressJson(json)); | ||
let actual = `+Field,d+Date\nValue1,1514764800`; | ||
assert.equal(removeOcsvHeader(compressed), actual); | ||
let actual = `+Field,d+Date\nValue1,2018-01-01`; | ||
assert.equal(removeHeaders(compressed), removeHeaders(actual)); | ||
}); | ||
@@ -481,4 +480,4 @@ it('with header', async () => { | ||
let compressed = await toString(compressor.compressJson(json)); | ||
let actual = `+Field,ds+Date\nValue1,1514764800`; | ||
assert.equal(removeOcsvHeader(compressed), actual); | ||
let actual = `+Field,ds+Date\nValue1,2018-01-01`; | ||
assert.equal(removeHeaders(compressed), removeHeaders(actual)); | ||
}); | ||
@@ -499,3 +498,3 @@ }); | ||
let actual = replaceNewLines(fs.readFileSync(`${filename}.ocsv`).toString()); | ||
assert.equal(removeOcsvHeader(compressed), removeOcsvHeader(actual)); | ||
assert.equal(removeHeaders(compressed), removeHeaders(actual)); | ||
}); | ||
@@ -509,4 +508,4 @@ }); | ||
compressed = compressed.trim(); | ||
let actual = getOcsvHeader(); | ||
assert.equal(compressed, actual); | ||
let actual = ""; | ||
assert.equal(removeHeaders(compressed), removeHeaders(actual)); | ||
}); | ||
@@ -519,4 +518,4 @@ | ||
compressed = compressed.trim(); | ||
let actual = `${getOcsvHeader()}\n+Column`; | ||
assert.equal(compressed, actual); | ||
let actual = "+Column"; | ||
assert.equal(removeHeaders(compressed), removeHeaders(actual)); | ||
}); | ||
@@ -531,4 +530,4 @@ | ||
compressed = compressed.trim(); | ||
let actual = `${getOcsvHeader()}\n+Column`; | ||
assert.equal(compressed, actual); | ||
let actual = "+Column"; | ||
assert.equal(removeHeaders(compressed), removeHeaders(actual)); | ||
}); | ||
@@ -541,4 +540,4 @@ | ||
compressed = compressed.trim(); | ||
let actual = `${getOcsvHeader()}\n+Column\nval`; | ||
assert.equal(compressed, actual); | ||
let actual = "Column\nval"; | ||
assert.equal(removeHeaders(compressed), removeHeaders(actual)); | ||
}); | ||
@@ -549,4 +548,4 @@ | ||
compressed = compressed.trim(); | ||
let actual = getOcsvHeader(); | ||
assert.equal(compressed, actual); | ||
let actual = ""; | ||
assert.equal(removeHeaders(compressed), removeHeaders(actual)); | ||
}); | ||
@@ -557,4 +556,4 @@ | ||
compressed = compressed.trim(); | ||
let actual = `${getOcsvHeader()}\n+Column`; | ||
assert.equal(compressed, actual); | ||
let actual = "+Column"; | ||
assert.equal(removeHeaders(compressed), actual); | ||
}); | ||
@@ -565,4 +564,4 @@ | ||
compressed = compressed.trim(); | ||
let actual = `${getOcsvHeader()}\n+Column`; | ||
assert.equal(compressed, actual); | ||
let actual = "+Column"; | ||
assert.equal(removeHeaders(compressed), actual); | ||
}); | ||
@@ -573,6 +572,6 @@ | ||
compressed = compressed.trim(); | ||
let actual = `${getOcsvHeader()}\n+Column\nval`; | ||
assert.equal(compressed, actual); | ||
let actual = "Column\nval"; | ||
assert.equal(removeHeaders(compressed), removeHeaders(actual)); | ||
}); | ||
}); | ||
}); |
@@ -6,9 +6,4 @@ const version = require('../src/version'); | ||
} | ||
module.exports.removeOcsvHeader = (data) => { | ||
module.exports.removeHeaders = (data) => { | ||
return data.substring(data.indexOf("\n") + 1).trim(); | ||
} | ||
module.exports.getOcsvHeader = () => { | ||
return `___ocsv2___${version.VERSION}/${version.VERSION_COMPATIBLE}`; | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
237536
6225