Skip to content

Commit ffcd11e

Browse files
silidKeyang
authored andcommitted
Convert trimLeft and trimRight to replace. (#264)
1 parent d0a5db0 commit ffcd11e

6 files changed

Lines changed: 12 additions & 12 deletions

File tree

src/ProcessorLocal.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ export class ProcessorLocal extends Processor {
8383
}
8484
// trim csv file has initial blank lines.
8585
if (params.ignoreEmpty && !runtime.started) {
86-
csv = csv.trimLeft();
86+
csv = csv.replace(/^\s+/, "");
8787
}
8888
const stringToLineResult = stringToLines(csv, runtime);
8989
if (!finalChunk) {

src/rowSplit.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ export class RowSplit {
5959
for (let i = 0, rowLen = rowArr.length; i < rowLen; i++) {
6060
let e = rowArr[i];
6161
if (!inquote && trim) {
62-
e = e.trimLeft();
62+
e = e.replace(/^\s+/, "");
6363
}
6464
const len = e.length;
6565
if (!inquote) {
@@ -80,7 +80,7 @@ export class RowSplit {
8080
}
8181
} else {
8282
if (trim) {
83-
e = e.trimRight();
83+
e = e.replace(/\s+$/, "");
8484
}
8585
row.push(e);
8686
continue;
@@ -92,7 +92,7 @@ export class RowSplit {
9292
quoteBuff += delimiter + e;
9393
quoteBuff = this.escapeQuote(quoteBuff);
9494
if (trim) {
95-
quoteBuff = quoteBuff.trimRight();
95+
quoteBuff = quoteBuff.replace(/\s+$/, "");
9696
}
9797
row.push(quoteBuff);
9898
quoteBuff = "";
@@ -139,7 +139,7 @@ export class RowSplit {
139139
const quote = this.quote;
140140
const escape = this.escape;
141141
if (this.conv.parseParam.trim) {
142-
str = str.trimRight();
142+
str = str.replace(/\s+$/, "");
143143
}
144144
let count = 0;
145145
let idx = str.length - 1;

v1/core/Converter.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ Converter.prototype.setPartialData = function (d) {
167167
Converter.prototype.processData = function (data, cb) {
168168
var params = this.param;
169169
if (params.ignoreEmpty && !params._headers) {
170-
data = data.trimLeft();
170+
data = data.replace(/^\s+/, "");
171171
}
172172
var eol = this.param.eol;
173173
var fileLines = fileline(data, this.param);

v1/core/rowSplit.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ module.exports = function rowSplit(rowStr, param) {
5555
quoteBuff += delimiter + e;
5656
quoteBuff = _escapeQuote(quoteBuff, quote, escape);
5757
if (trim) {
58-
quoteBuff = quoteBuff.trimRight();
58+
quoteBuff = quoteBuff.replace(/\s+$/, "");
5959
}
6060
row.push(quoteBuff);
6161
quoteBuff = "";

v2/ProcessorLocal.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

v2/rowSplit.js

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)