fix(core): update

This commit is contained in:
Philipp Kunz 2019-12-15 18:15:03 +00:00
parent e7f06a7f44
commit 5f49532fc2
3 changed files with 28 additions and 20 deletions

25
package-lock.json generated
View File

@ -279,9 +279,9 @@
}
},
"@pushrocks/smartstring": {
"version": "3.0.14",
"resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartstring/-/smartstring-3.0.14.tgz",
"integrity": "sha512-hN3IwTb5VBUis8Z5U5U6dDCnap6zBmkc9/IVx8lxAbsxl5TYQ4RiYlJ2JM4tih7EdE80ZeSdpprzChYrWmSwDg==",
"version": "3.0.17",
"resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartstring/-/smartstring-3.0.17.tgz",
"integrity": "sha512-60JQptpgw+PjxoC5Gx+Y9m3/dtMstHC5ElpdJhIlbJ7dQV7LkCGSonLAG+NZhPbvrhow2KZ3fob8stW0Iuy3JQ==",
"requires": {
"crypto-random-string": "^3.0.1",
"js-base64": "^2.5.1",
@ -304,21 +304,22 @@
}
},
"@pushrocks/tapbundle": {
"version": "3.0.13",
"resolved": "https://verdaccio.lossless.one/@pushrocks%2ftapbundle/-/tapbundle-3.0.13.tgz",
"integrity": "sha512-23O4UMBafCuD+RnUlXNvtT9DGbL1HMD+xZE1Zcr7Ll7WvgxUgRQQfk9kq6qbLLbjaRe1J2Ijsgh1HuZbBaucLQ==",
"version": "3.2.0",
"resolved": "https://verdaccio.lossless.one/@pushrocks%2ftapbundle/-/tapbundle-3.2.0.tgz",
"integrity": "sha512-xnKIGe7NJqxWBaFeKIEXShDjV2wap1XJqmlp3m1MKqmIF62vRpZnkzpyE1ZAoNwiYQmIsXIpvP/PDv+iPevPfw==",
"dev": true,
"requires": {
"@pushrocks/early": "^3.0.3",
"@pushrocks/smartdelay": "^2.0.3",
"@pushrocks/smartfile": "^7.0.6",
"@pushrocks/smartpromise": "^3.0.2",
"smartchai": "^2.0.1"
}
},
"@types/chai": {
"version": "4.2.3",
"resolved": "https://verdaccio.lossless.one/@types%2fchai/-/chai-4.2.3.tgz",
"integrity": "sha512-VRw2xEGbll3ZiTQ4J02/hUjNqZoue1bMhoo2dgM2LXjDdyaq4q80HgBDHwpI0/VKlo4Eg+BavyQMv/NYgTetzA==",
"version": "4.2.7",
"resolved": "https://verdaccio.lossless.one/@types%2fchai/-/chai-4.2.7.tgz",
"integrity": "sha512-luq8meHGYwvky0O7u0eQZdA7B4Wd9owUCqvbw2m3XCrCU8mplYOujMBbvyS547AxJkC+pGnd0Cm15eNxEUNU8g==",
"dev": true
},
"@types/chai-as-promised": {
@ -395,9 +396,9 @@
"dev": true
},
"@types/node": {
"version": "12.7.12",
"resolved": "https://verdaccio.lossless.one/@types%2fnode/-/node-12.7.12.tgz",
"integrity": "sha512-KPYGmfD0/b1eXurQ59fXD1GBzhSQfz6/lKBxkaHX9dKTzjXbK68Zt7yGUxUsCS1jeTy/8aL+d9JEr+S54mpkWQ==",
"version": "12.12.17",
"resolved": "https://verdaccio.lossless.one/@types%2fnode/-/node-12.12.17.tgz",
"integrity": "sha512-Is+l3mcHvs47sKy+afn2O1rV4ldZFU7W8101cNlOd+MRbjM4Onida8jSZnJdTe/0Pcf25g9BNIUsuugmE6puHA==",
"dev": true
},
"@types/through2": {

View File

@ -17,12 +17,12 @@
"@gitzone/tsrun": "^1.2.8",
"@gitzone/tstest": "^1.0.28",
"@pushrocks/smartfile": "^7.0.6",
"@pushrocks/tapbundle": "^3.0.13",
"@types/node": "^12.7.12"
"@pushrocks/tapbundle": "^3.2.0",
"@types/node": "^12.12.17"
},
"dependencies": {
"@pushrocks/smartpromise": "^3.0.6",
"@pushrocks/smartstring": "^3.0.14"
"@pushrocks/smartstring": "^3.0.17"
},
"files": [
"ts/*",

View File

@ -55,6 +55,8 @@ export class Csv {
public keyFrame: string = null;
public data: any[];
private base64RecognitionPrefix = '####12345####';
public options: ICsvConstructorOptions = {
headers: true,
unquote: true
@ -71,7 +73,7 @@ export class Csv {
csvStringToParse = csvStringToParse.replace(
/"(.*?)"/gi,
(match, p1, offset, originalString) => {
return plugins.smartstring.base64.encode(match);
return this.base64RecognitionPrefix + plugins.smartstring.base64.encode(match);
}
);
}
@ -137,8 +139,9 @@ export class Csv {
this.headers = headerRow.split(this.keyFrame);
if (this.options.unquote) {
const unquotedHeaders: string[] = [];
for (const header of this.headers) {
if (plugins.smartstring.type.isBase64(header)) {
for (let header of this.headers) {
if (header.startsWith(this.base64RecognitionPrefix)) {
header = header.replace(this.base64RecognitionPrefix, '');
unquotedHeaders.push(plugins.smartstring.base64.decode(header).replace(/['"]+/g, ''));
} else {
unquotedHeaders.push(header);
@ -155,8 +158,12 @@ export class Csv {
let resultJson: any = {};
for (let i = 0; i < neededIterations; i++) {
let value = dataArray[i];
if (this.options.unquote && plugins.smartstring.type.isBase64(value)) {
value = plugins.smartstring.base64.decode(value).replace(/['"]+/g, '').replace(/['"]+/g, '');
if (this.options.unquote && value.startsWith(this.base64RecognitionPrefix)) {
value = value.replace(this.base64RecognitionPrefix, '');
value = plugins.smartstring.base64
.decode(value)
.replace(/['"]+/g, '')
.replace(/['"]+/g, '');
}
resultJson[this.headers[i]] = value;
}