@cosmotech/core 1.6.9 → 1.6.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs.js +42 -15
- package/dist/index.esm.js +42 -15
- package/package.json +1 -1
package/dist/index.cjs.js
CHANGED
|
@@ -134,32 +134,43 @@ var Parser = /** @class */ (function () {
|
|
|
134
134
|
this._simpleValueRegExp = new RegExp("[" + this.comma + "\r\n]");
|
|
135
135
|
this._replaceQuoteRegExp = new RegExp(this.quote + this.quote, 'g');
|
|
136
136
|
}
|
|
137
|
-
Parser.prototype.File = function () {
|
|
138
|
-
var
|
|
139
|
-
var row;
|
|
137
|
+
Parser.prototype.File = function (output) {
|
|
138
|
+
var rows = [];
|
|
140
139
|
while (true) {
|
|
141
140
|
var tempointer = this.pointer;
|
|
142
|
-
row = this.Row();
|
|
141
|
+
var row = this.Row();
|
|
143
142
|
if (row.length > 0) {
|
|
144
143
|
this.linePointer = tempointer;
|
|
145
|
-
|
|
144
|
+
rows.push(row);
|
|
146
145
|
}
|
|
147
146
|
else {
|
|
148
147
|
if (this.linePointer && this.pointer !== this.input.length) {
|
|
149
|
-
|
|
148
|
+
rows.pop();
|
|
150
149
|
this.pointer = this.linePointer;
|
|
151
150
|
}
|
|
152
151
|
break;
|
|
153
152
|
}
|
|
154
153
|
if (this.EOF()) {
|
|
155
154
|
if (this.linePointer && this.pointer !== this.input.length) {
|
|
156
|
-
|
|
155
|
+
rows.pop();
|
|
157
156
|
this.pointer = this.linePointer;
|
|
158
157
|
}
|
|
159
158
|
break;
|
|
160
159
|
}
|
|
161
160
|
}
|
|
162
|
-
|
|
161
|
+
if (output && output === "objects") {
|
|
162
|
+
if (rows.length === 0) {
|
|
163
|
+
return [];
|
|
164
|
+
}
|
|
165
|
+
var headers_1 = rows.shift();
|
|
166
|
+
return rows.map(function (row) { return headers_1.reduce(function (data, k, i) {
|
|
167
|
+
data[k] = row[i];
|
|
168
|
+
return data;
|
|
169
|
+
}, {}); });
|
|
170
|
+
}
|
|
171
|
+
else {
|
|
172
|
+
return rows;
|
|
173
|
+
}
|
|
163
174
|
};
|
|
164
175
|
Parser.prototype.Row = function () {
|
|
165
176
|
var row = [];
|
|
@@ -436,14 +447,30 @@ var stringify = function (input, sep) {
|
|
|
436
447
|
return ret;
|
|
437
448
|
};
|
|
438
449
|
CSV.stringify = stringify;
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
450
|
+
function parse$2(input, sepOrOpts, quo) {
|
|
451
|
+
// Create an options hash, using positional parameters or the passed in options hash for values
|
|
452
|
+
var opts = typeof sepOrOpts === "object" ? sepOrOpts : {};
|
|
453
|
+
if (typeof sepOrOpts === "string") {
|
|
454
|
+
opts.comma = sepOrOpts;
|
|
443
455
|
}
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
}
|
|
456
|
+
if (quo) {
|
|
457
|
+
opts.quote = quo;
|
|
458
|
+
}
|
|
459
|
+
// try to detect the separator if not provided
|
|
460
|
+
if (opts.comma === undefined) {
|
|
461
|
+
opts.comma = detect(input);
|
|
462
|
+
}
|
|
463
|
+
// Clean characters, if necessary
|
|
464
|
+
// TODO: We should probably throw an error here to signal bad input to the user
|
|
465
|
+
if (opts.comma) {
|
|
466
|
+
opts.comma = opts.comma[0];
|
|
467
|
+
}
|
|
468
|
+
if (opts.quote) {
|
|
469
|
+
opts.quote = opts.quote[0];
|
|
470
|
+
}
|
|
471
|
+
var csv = new Parser_1.Parser(input, opts.comma, opts.quote);
|
|
472
|
+
return csv.File(opts.output);
|
|
473
|
+
}
|
|
447
474
|
CSV.parse = parse$2;
|
|
448
475
|
function read$2(input, sep, quo, callback) {
|
|
449
476
|
if (callback === undefined) {
|
package/dist/index.esm.js
CHANGED
|
@@ -125,32 +125,43 @@ var Parser = /** @class */ (function () {
|
|
|
125
125
|
this._simpleValueRegExp = new RegExp("[" + this.comma + "\r\n]");
|
|
126
126
|
this._replaceQuoteRegExp = new RegExp(this.quote + this.quote, 'g');
|
|
127
127
|
}
|
|
128
|
-
Parser.prototype.File = function () {
|
|
129
|
-
var
|
|
130
|
-
var row;
|
|
128
|
+
Parser.prototype.File = function (output) {
|
|
129
|
+
var rows = [];
|
|
131
130
|
while (true) {
|
|
132
131
|
var tempointer = this.pointer;
|
|
133
|
-
row = this.Row();
|
|
132
|
+
var row = this.Row();
|
|
134
133
|
if (row.length > 0) {
|
|
135
134
|
this.linePointer = tempointer;
|
|
136
|
-
|
|
135
|
+
rows.push(row);
|
|
137
136
|
}
|
|
138
137
|
else {
|
|
139
138
|
if (this.linePointer && this.pointer !== this.input.length) {
|
|
140
|
-
|
|
139
|
+
rows.pop();
|
|
141
140
|
this.pointer = this.linePointer;
|
|
142
141
|
}
|
|
143
142
|
break;
|
|
144
143
|
}
|
|
145
144
|
if (this.EOF()) {
|
|
146
145
|
if (this.linePointer && this.pointer !== this.input.length) {
|
|
147
|
-
|
|
146
|
+
rows.pop();
|
|
148
147
|
this.pointer = this.linePointer;
|
|
149
148
|
}
|
|
150
149
|
break;
|
|
151
150
|
}
|
|
152
151
|
}
|
|
153
|
-
|
|
152
|
+
if (output && output === "objects") {
|
|
153
|
+
if (rows.length === 0) {
|
|
154
|
+
return [];
|
|
155
|
+
}
|
|
156
|
+
var headers_1 = rows.shift();
|
|
157
|
+
return rows.map(function (row) { return headers_1.reduce(function (data, k, i) {
|
|
158
|
+
data[k] = row[i];
|
|
159
|
+
return data;
|
|
160
|
+
}, {}); });
|
|
161
|
+
}
|
|
162
|
+
else {
|
|
163
|
+
return rows;
|
|
164
|
+
}
|
|
154
165
|
};
|
|
155
166
|
Parser.prototype.Row = function () {
|
|
156
167
|
var row = [];
|
|
@@ -427,14 +438,30 @@ var stringify = function (input, sep) {
|
|
|
427
438
|
return ret;
|
|
428
439
|
};
|
|
429
440
|
CSV.stringify = stringify;
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
441
|
+
function parse$2(input, sepOrOpts, quo) {
|
|
442
|
+
// Create an options hash, using positional parameters or the passed in options hash for values
|
|
443
|
+
var opts = typeof sepOrOpts === "object" ? sepOrOpts : {};
|
|
444
|
+
if (typeof sepOrOpts === "string") {
|
|
445
|
+
opts.comma = sepOrOpts;
|
|
434
446
|
}
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
}
|
|
447
|
+
if (quo) {
|
|
448
|
+
opts.quote = quo;
|
|
449
|
+
}
|
|
450
|
+
// try to detect the separator if not provided
|
|
451
|
+
if (opts.comma === undefined) {
|
|
452
|
+
opts.comma = detect(input);
|
|
453
|
+
}
|
|
454
|
+
// Clean characters, if necessary
|
|
455
|
+
// TODO: We should probably throw an error here to signal bad input to the user
|
|
456
|
+
if (opts.comma) {
|
|
457
|
+
opts.comma = opts.comma[0];
|
|
458
|
+
}
|
|
459
|
+
if (opts.quote) {
|
|
460
|
+
opts.quote = opts.quote[0];
|
|
461
|
+
}
|
|
462
|
+
var csv = new Parser_1.Parser(input, opts.comma, opts.quote);
|
|
463
|
+
return csv.File(opts.output);
|
|
464
|
+
}
|
|
438
465
|
CSV.parse = parse$2;
|
|
439
466
|
function read$2(input, sep, quo, callback) {
|
|
440
467
|
if (callback === undefined) {
|