From 3fb3a71bde4b8c7af5cf7b7c1ee058b7fbb7d8bb Mon Sep 17 00:00:00 2001 From: Doga Budak Date: Tue, 18 Apr 2023 10:19:47 +0200 Subject: [PATCH 1/4] feat: updated deprecated code --- .idea/.gitignore | 5 +++++ .idea/modules.xml | 8 ++++++++ .idea/node-csvtojson.iml | 12 ++++++++++++ .idea/vcs.xml | 6 ++++++ bin/csvtojson.js | 4 ++-- src/Converter.ts | 19 ++----------------- src/rowSplit.ts | 2 +- 7 files changed, 36 insertions(+), 20 deletions(-) create mode 100644 .idea/.gitignore create mode 100644 .idea/modules.xml create mode 100644 .idea/node-csvtojson.iml create mode 100644 .idea/vcs.xml diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..b58b603 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,5 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..2c4e074 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/node-csvtojson.iml b/.idea/node-csvtojson.iml new file mode 100644 index 0000000..0c8867d --- /dev/null +++ b/.idea/node-csvtojson.iml @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/bin/csvtojson.js b/bin/csvtojson.js index 1e79547..0bff307 100644 --- a/bin/csvtojson.js +++ b/bin/csvtojson.js @@ -43,8 +43,8 @@ function csvtojson() { } function stringToRegExp(str) { var lastSlash = str.lastIndexOf("/"); - var source = str.substring(1, lastSlash); - var flag = str.substring(lastSlash + 1); + var source = str.substr(1, lastSlash); + var flag = str.substr(lastSlash + 1); return new RegExp(source,flag); } function parse() { diff --git a/src/Converter.ts b/src/Converter.ts index 744b945..c29ea52 100644 --- a/src/Converter.ts +++ b/src/Converter.ts @@ -2,19 +2,10 @@ import { Transform, TransformOptions, Readable } from "stream"; import { CSVParseParam, mergeParams } from "./Parameters"; import { ParseRuntime, initParseRuntime } from "./ParseRuntime"; import P from "bluebird"; -import { stringToLines } from "./fileline"; -import { map } from "lodash/map"; -import { RowSplit, RowSplitResult } from "./rowSplit"; -import getEol from "./getEol"; -import lineToJson, { JSONResult } from "./lineToJson"; -import { Processor, ProcessLineResult } from "./Processor"; -// import { ProcessorFork } from "./ProcessFork"; +import { Processor } from "./Processor"; import { ProcessorLocal } from "./ProcessorLocal"; import { Result } from "./Result"; import CSVError from "./CSVError"; -import { bufFromString } from "./util"; - - export class Converter extends Transform implements PromiseLike { preRawData(onRawData: PreRawDataCallback): Converter { @@ -38,12 +29,6 @@ export class Converter extends Transform implements PromiseLike { } fromFile(filePath: string, options?: string | CreateReadStreamOption | undefined): Converter { const fs = require("fs"); - // var rs = null; - // this.wrapCallback(cb, function () { - // if (rs && rs.destroy) { - // rs.destroy(); - // } - // }); fs.exists(filePath, (exist) => { if (exist) { const rs = fs.createReadStream(filePath, options); @@ -66,7 +51,7 @@ export class Converter extends Transform implements PromiseLike { if (idx >= csvString.length) { this.push(null); } else { - const str = csvString.substr(idx, size); + const str = csvString.substring(idx, idx + size); this.push(str); idx += size; } diff --git a/src/rowSplit.ts b/src/rowSplit.ts index b6c6502..711fc3b 100644 --- a/src/rowSplit.ts +++ b/src/rowSplit.ts @@ -69,7 +69,7 @@ export class RowSplit { } else if (this.isQuoteOpen(e)) { //quote open e = e.substr(1); if (this.isQuoteClose(e)) { //quote close - e = e.substring(0, e.lastIndexOf(quote)); + e = e.substr(0, e.lastIndexOf(quote)); e = this.escapeQuote(e); row.push(e); continue; From 99616e457c3a2b1d9ada638ad4d4c539e4794e7c Mon Sep 17 00:00:00 2001 From: Doga Budak Date: Tue, 18 Apr 2023 10:19:56 +0200 Subject: [PATCH 2/4] feat: updated deprecated code --- .idea/.gitignore | 5 ----- .idea/modules.xml | 8 -------- .idea/node-csvtojson.iml | 12 ------------ .idea/vcs.xml | 6 ------ 4 files changed, 31 deletions(-) delete mode 100644 .idea/.gitignore delete mode 100644 .idea/modules.xml delete mode 100644 .idea/node-csvtojson.iml delete mode 100644 .idea/vcs.xml diff --git a/.idea/.gitignore b/.idea/.gitignore deleted file mode 100644 index b58b603..0000000 --- a/.idea/.gitignore +++ /dev/null @@ -1,5 +0,0 @@ -# Default ignored files -/shelf/ -/workspace.xml -# Editor-based HTTP Client requests -/httpRequests/ diff --git a/.idea/modules.xml b/.idea/modules.xml deleted file mode 100644 index 2c4e074..0000000 --- a/.idea/modules.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/.idea/node-csvtojson.iml b/.idea/node-csvtojson.iml deleted file mode 100644 index 0c8867d..0000000 --- a/.idea/node-csvtojson.iml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml deleted file mode 100644 index 94a25f7..0000000 --- a/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file From 72642115976a677977b4bdce0a489f66a03e1af3 Mon Sep 17 00:00:00 2001 From: Doga Budak Date: Tue, 18 Apr 2023 10:20:24 +0200 Subject: [PATCH 3/4] feat: updated .gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 2b3deaa..3c91699 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ Thumbs.db node_modules/ *.swp *.swo +.idea/ # intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) .grunt From e5b60c8a00ccf779b445cef0cabb31d015d30552 Mon Sep 17 00:00:00 2001 From: Doga Budak Date: Tue, 18 Apr 2023 12:41:13 +0200 Subject: [PATCH 4/4] fix: removed unnessesary lines --- src/Converter.ts | 6 ------ src/lineToJson.ts | 15 +++------------ v2/lineToJson.js | 1 - 3 files changed, 3 insertions(+), 19 deletions(-) diff --git a/src/Converter.ts b/src/Converter.ts index c29ea52..ea866ec 100644 --- a/src/Converter.ts +++ b/src/Converter.ts @@ -93,14 +93,8 @@ export class Converter extends Transform implements PromiseLike { this.params = mergeParams(param); this.runtime = initParseRuntime(this); this.result = new Result(this); - // if (this.params.fork) { - // this.processor = new ProcessorFork(this); - // } else { this.processor = new ProcessorLocal(this); - // } this.once("error", (err: any) => { - // console.log("BBB"); - //wait for next cycle to emit the errors. setImmediate(() => { this.result.processError(err); this.emit("done", err); diff --git a/src/lineToJson.ts b/src/lineToJson.ts index b89ee81..94709d4 100644 --- a/src/lineToJson.ts +++ b/src/lineToJson.ts @@ -2,9 +2,8 @@ import { Converter } from "./Converter"; import CSVError from "./CSVError"; import { CellParser, ColumnParam } from "./Parameters"; import set from "lodash/set"; -import { ParseRuntime } from "./ParseRuntime"; -var numReg = /^[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?$/; +const numReg = /^[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?$/; export default function (csvRows: string[][], conv: Converter): JSONResult[] { const res: JSONResult[] = []; @@ -58,10 +57,6 @@ function convertRowToJson(row: string[], headRow: string[], conv: Converter): { setPath(resultRow, head, convRes, conv,i); } } else { - // var flag = getFlag(head, i, param); - // if (flag === 'omit') { - // continue; - // } if (conv.parseParam.checkType) { const convertFunc = checkType(item, head, i, conv); item = convertFunc(item); @@ -193,12 +188,8 @@ function dynamicType(item) { } function booleanType(item) { - var trimed = item.trim(); - if (trimed.length === 5 && trimed.toLowerCase() === "false") { - return false; - } else { - return true; - } + const trimmed = item.trim(); + return !(trimmed.length === 5 && trimmed.toLowerCase() === "false"); } function jsonType(item) { diff --git a/v2/lineToJson.js b/v2/lineToJson.js index 119f329..cfad7e8 100644 --- a/v2/lineToJson.js +++ b/v2/lineToJson.js @@ -17,7 +17,6 @@ function default_1(csvRows, conv) { return res; } exports.default = default_1; -; function processRow(row, conv, index) { if (conv.parseParam.checkColumn && conv.parseRuntime.headers && row.length !== conv.parseRuntime.headers.length) { throw (CSVError_1.default.column_mismatched(conv.parseRuntime.parsedLineNumber + index));