From 5f49532fc271cd348b1d81403227f04edd8bbafe Mon Sep 17 00:00:00 2001 From: Phil Kunz Date: Sun, 15 Dec 2019 18:15:03 +0000 Subject: [PATCH] fix(core): update --- package-lock.json | 25 +++++++++++++------------ package.json | 6 +++--- ts/index.ts | 17 ++++++++++++----- 3 files changed, 28 insertions(+), 20 deletions(-) diff --git a/package-lock.json b/package-lock.json index 9277693..359b29d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -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": { diff --git a/package.json b/package.json index 942568c..212ecdf 100644 --- a/package.json +++ b/package.json @@ -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/*", diff --git a/ts/index.ts b/ts/index.ts index 77a4904..2a2a19c 100644 --- a/ts/index.ts +++ b/ts/index.ts @@ -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; }