-
-
diff --git a/packages/csv-stringify/samples/browser/index.js b/packages/csv-stringify/samples/browser/index.js
deleted file mode 100644
index 72c52eb7f..000000000
--- a/packages/csv-stringify/samples/browser/index.js
+++ /dev/null
@@ -1,10 +0,0 @@
-const express = require("express");
-const app = express();
-const port = 3000;
-
-app.use(express.static(__dirname));
-app.use("/lib", express.static(`${__dirname}/../../lib/browser`));
-
-app.listen(port, () => {
- console.log(`Example app listening at http://localhost:${port}`);
-});
diff --git a/packages/csv-stringify/test/api.callback.coffee b/packages/csv-stringify/test/api.callback.coffee
deleted file mode 100644
index e5e6a014b..000000000
--- a/packages/csv-stringify/test/api.callback.coffee
+++ /dev/null
@@ -1,43 +0,0 @@
-
-import fs from 'fs'
-import { generate } from 'csv-generate'
-import { stringify } from '../lib/index.js'
-
-describe 'api.callback', ->
-
- it '2 args: data, callback', (next) ->
- data = ''
- stringifier = stringify [
- ['field_1','field_2'], ['value 1','value 2']
- ], (err, data) ->
- data.should.eql 'field_1,field_2\nvalue 1,value 2\n'
- next()
-
- it '2 args: options, callback', (next) ->
- data = ''
- stringifier = stringify eof: false, (err, data) ->
- data.should.eql 'field_1,field_2\nvalue 1,value 2'
- next()
- stringifier.write ['field_1','field_2']
- stringifier.write ['value 1','value 2']
- stringifier.end()
-
- it '3 args: data, options, callback', (next) ->
- data = ''
- stringifier = stringify [
- ['field_1','field_2'], ['value 1','value 2']
- ], eof: false, (err, data) ->
- data.should.eql 'field_1,field_2\nvalue 1,value 2'
- next()
-
- it 'catch error in end handler, see #386', (next) ->
- input =
- Array.from( length: 200000 ).map ->
- Array.from( length: 100 ).map ->
- 'ABCDEFGHIJKLMNOPQRSTUVXYZ0123456789'
- stringify input, (err, res) ->
- err.should.match
- code: 'ERR_STRING_TOO_LONG'
- message: 'Cannot create a string longer than 0x1fffffe8 characters'
- next()
-
\ No newline at end of file
diff --git a/packages/csv-stringify/test/api.callback.js b/packages/csv-stringify/test/api.callback.js
new file mode 100644
index 000000000..b6a8af32c
--- /dev/null
+++ b/packages/csv-stringify/test/api.callback.js
@@ -0,0 +1,56 @@
+import "should";
+import { stringify } from "../lib/index.js";
+
+describe("api.callback", function () {
+ it("2 args: data, callback", function (next) {
+ stringify(
+ [
+ ["field_1", "field_2"],
+ ["value 1", "value 2"],
+ ],
+ (err, data) => {
+ data.should.eql("field_1,field_2\nvalue 1,value 2\n");
+ next();
+ },
+ );
+ });
+
+ it("2 args: options, callback", function (next) {
+ const stringifier = stringify({ eof: false }, (err, data) => {
+ data.should.eql("field_1,field_2\nvalue 1,value 2");
+ next();
+ });
+ stringifier.write(["field_1", "field_2"]);
+ stringifier.write(["value 1", "value 2"]);
+ stringifier.end();
+ });
+
+ it("3 args: data, options, callback", function (next) {
+ stringify(
+ [
+ ["field_1", "field_2"],
+ ["value 1", "value 2"],
+ ],
+ { eof: false },
+ (err, data) => {
+ data.should.eql("field_1,field_2\nvalue 1,value 2");
+ next();
+ },
+ );
+ });
+
+ it("catch error in end handler, see #386", function (next) {
+ const input = Array.from({ length: 200000 }).map(() =>
+ Array.from({ length: 100 }).map(
+ () => "ABCDEFGHIJKLMNOPQRSTUVXYZ0123456789",
+ ),
+ );
+ stringify(input, (err) => {
+ err.should.match({
+ code: "ERR_STRING_TOO_LONG",
+ message: "Cannot create a string longer than 0x1fffffe8 characters",
+ });
+ next();
+ });
+ });
+});
diff --git a/packages/csv-stringify/test/api.coffee b/packages/csv-stringify/test/api.coffee
deleted file mode 100644
index b0a036a4d..000000000
--- a/packages/csv-stringify/test/api.coffee
+++ /dev/null
@@ -1,60 +0,0 @@
-
-import fs from 'fs'
-import { generate } from 'csv-generate'
-import { stringify } from '../lib/index.js'
-
-describe 'API', ->
-
- it '0 arg: write input and stream output', (next) ->
- data = ''
- stringifier = stringify()
- stringifier.on 'readable', ->
- data += d while d = stringifier.read()
- stringifier.on 'err', (err) ->
- next err
- stringifier.on 'finish', ->
- data.should.eql 'field_1,field_2\nvalue 1,value 2\n'
- next()
- stringifier.write ['field_1','field_2']
- stringifier.write ['value 1','value 2']
- stringifier.end()
-
- it '1 arg: option; write input and stream output', (next) ->
- data = ''
- generator = generate length: 2, objectMode: true, seed: 1, columns: 2
- stringifier = stringify eof: false
- stringifier.on 'readable', ->
- data += d while d = stringifier.read()
- generator.on 'error', next
- generator.on 'end', (err) ->
- stringifier.end()
- generator.on 'readable', ->
- stringifier.write row while row = generator.read()
- stringifier.on 'finish', ->
- data.should.eql """
- OMH,ONKCHhJmjadoA
- D,GeACHiN
- """
- next()
-
- it '1 arg: data and stream output', (next) ->
- data = ''
- stringifier = stringify [
- ['field_1','field_2'], ['value 1','value 2']
- ]
- stringifier.on 'readable', ->
- data += d while d = stringifier.read()
- stringifier.on 'finish', ->
- data.should.eql 'field_1,field_2\nvalue 1,value 2\n'
- next()
-
- it '2 args: data, option and stream output', (next) ->
- data = ''
- stringifier = stringify [
- ['field_1','field_2'], ['value 1','value 2']
- ], eof: false
- stringifier.on 'readable', ->
- data += d while d = stringifier.read()
- stringifier.on 'finish', ->
- data.should.eql 'field_1,field_2\nvalue 1,value 2'
- next()
diff --git a/packages/csv-stringify/test/api.js b/packages/csv-stringify/test/api.js
new file mode 100644
index 000000000..a3de3d268
--- /dev/null
+++ b/packages/csv-stringify/test/api.js
@@ -0,0 +1,96 @@
+import "should";
+import { generate } from "csv-generate";
+import { stringify } from "../lib/index.js";
+
+describe("API", function () {
+ it("0 arg: write input and stream output", function (next) {
+ let data = "";
+ const stringifier = stringify();
+ stringifier.on("readable", () => {
+ let d;
+ while ((d = stringifier.read())) {
+ data += d;
+ }
+ });
+ stringifier.on("err", (err) => {
+ next(err);
+ });
+ stringifier.on("finish", () => {
+ data.should.eql("field_1,field_2\nvalue 1,value 2\n");
+ next();
+ });
+ stringifier.write(["field_1", "field_2"]);
+ stringifier.write(["value 1", "value 2"]);
+ stringifier.end();
+ });
+
+ it("1 arg: option; write input and stream output", function (next) {
+ let data = "";
+ const generator = generate({
+ length: 2,
+ objectMode: true,
+ seed: 1,
+ columns: 2,
+ });
+ const stringifier = stringify({ eof: false });
+ stringifier.on("readable", () => {
+ let d;
+ while ((d = stringifier.read())) {
+ data += d;
+ }
+ });
+ generator.on("error", next);
+ generator.on("end", () => {
+ stringifier.end();
+ });
+ generator.on("readable", () => {
+ let row;
+ while ((row = generator.read())) {
+ stringifier.write(row);
+ }
+ });
+ stringifier.on("finish", () => {
+ data.should.eql("OMH,ONKCHhJmjadoA\nD,GeACHiN");
+ next();
+ });
+ });
+
+ it("1 arg: data and stream output", function (next) {
+ let data = "";
+ const stringifier = stringify([
+ ["field_1", "field_2"],
+ ["value 1", "value 2"],
+ ]);
+ stringifier.on("readable", () => {
+ let d;
+ while ((d = stringifier.read())) {
+ data += d;
+ }
+ });
+ stringifier.on("finish", () => {
+ data.should.eql("field_1,field_2\nvalue 1,value 2\n");
+ next();
+ });
+ });
+
+ it("2 args: data, option and stream output", function (next) {
+ let data = "";
+ const stringifier = stringify(
+ [
+ ["field_1", "field_2"],
+ ["value 1", "value 2"],
+ ],
+ { eof: false },
+ );
+ stringifier.on("readable", () => {
+ let d;
+ while ((d = stringifier.read())) {
+ data += d;
+ }
+ });
+ stringifier.on("finish", () => {
+ data.should.eql("field_1,field_2\nvalue 1,value 2");
+ next();
+ });
+ });
+});
diff --git a/packages/csv-stringify/test/api.pipe.coffee b/packages/csv-stringify/test/api.pipe.coffee
deleted file mode 100644
index 60a27f954..000000000
--- a/packages/csv-stringify/test/api.pipe.coffee
+++ /dev/null
@@ -1,47 +0,0 @@
-
-import fs from 'fs'
-import { generate } from 'csv-generate'
-import { stringify } from '../lib/index.js'
-
-describe 'API pipe', ->
-
- it 'pipe from source to destination', (next) ->
- data = ''
- generator = generate length: 2, objectMode: true, seed: 1, columns: 2
- stringifier = stringify eof: false
- ws = fs.createWriteStream '/tmp/large.out'
- generator.pipe(stringifier).pipe(ws).on 'finish', ->
- fs.readFile '/tmp/large.out', 'ascii', (err, data) ->
- data.should.eql """
- OMH,ONKCHhJmjadoA
- D,GeACHiN
- """
- fs.unlink '/tmp/large.out', next
-
- it 'pipe to destination', (next) ->
- data = ''
- generate length: 1000, objectMode: true, seed: 1, columns: 2, (err, data) ->
- stringifier = stringify eof: false
- ws = fs.createWriteStream '/tmp/large.out'
- stringifier.pipe ws
- for row in data
- stringifier.write row
- stringifier.end()
- ws.on 'finish', ->
- fs.readFile '/tmp/large.out', 'ascii', (err, data) ->
- data.split('\n').length.should.eql 1000 unless err
- next err
-
- it 'pipe from source', (next) ->
- data = ''
- generator = generate length: 2, objectMode: true, seed: 1, columns: 2
- stringifier = generator.pipe stringify eof: false
- stringifier.on 'readable', ->
- while(d = stringifier.read())
- data += d
- stringifier.on 'finish', ->
- data.should.eql """
- OMH,ONKCHhJmjadoA
- D,GeACHiN
- """
- next()
diff --git a/packages/csv-stringify/test/api.pipe.js b/packages/csv-stringify/test/api.pipe.js
new file mode 100644
index 000000000..5199f7e2d
--- /dev/null
+++ b/packages/csv-stringify/test/api.pipe.js
@@ -0,0 +1,70 @@
+import "should";
+import fs from "fs";
+import { generate } from "csv-generate";
+import { stringify } from "../lib/index.js";
+
+describe("API pipe", function () {
+ it("pipe from source to destination", function (next) {
+ const generator = generate({
+ length: 2,
+ objectMode: true,
+ seed: 1,
+ columns: 2,
+ });
+ const stringifier = stringify({ eof: false });
+ const ws = fs.createWriteStream("/tmp/large.out");
+ generator
+ .pipe(stringifier)
+ .pipe(ws)
+ .on("finish", () => {
+ fs.readFile("/tmp/large.out", "ascii", (err, data) => {
+ data.should.eql("OMH,ONKCHhJmjadoA\nD,GeACHiN");
+ fs.unlink("/tmp/large.out", next);
+ });
+ });
+ });
+
+ it("pipe to destination", function (next) {
+ generate(
+ { length: 1000, objectMode: true, seed: 1, columns: 2 },
+ (err, data) => {
+ const stringifier = stringify({ eof: false });
+ const ws = fs.createWriteStream("/tmp/large.out");
+ stringifier.pipe(ws);
+ for (const row of data) {
+ stringifier.write(row);
+ }
+ stringifier.end();
+ ws.on("finish", () => {
+ fs.readFile("/tmp/large.out", "ascii", (err, data) => {
+ if (!err) {
+ data.split("\n").length.should.eql(1000);
+ }
+ next(err);
+ });
+ });
+ },
+ );
+ });
+
+ it("pipe from source", function (next) {
+ let data = "";
+ const generator = generate({
+ length: 2,
+ objectMode: true,
+ seed: 1,
+ columns: 2,
+ });
+ const stringifier = generator.pipe(stringify({ eof: false }));
+ stringifier.on("readable", () => {
+ let d;
+ while ((d = stringifier.read())) {
+ data += d;
+ }
+ });
+ stringifier.on("finish", () => {
+ data.should.eql("OMH,ONKCHhJmjadoA\nD,GeACHiN");
+ next();
+ });
+ });
+});
diff --git a/packages/csv-stringify/test/api.sync.coffee b/packages/csv-stringify/test/api.sync.coffee
deleted file mode 100644
index ab7e861ef..000000000
--- a/packages/csv-stringify/test/api.sync.coffee
+++ /dev/null
@@ -1,21 +0,0 @@
-
-import { stringify } from '../lib/sync.js'
-
-describe 'sync', ->
-
- it 'work on object', ->
- data = stringify [ {a: '1', b: '2'}, {a: '3', b: '4'}]
- data.should.eql "1,2\n3,4\n"
-
- it 'work on array', ->
- data = stringify [ ['1', '2'], ['3', '4']]
- data.should.eql "1,2\n3,4\n"
-
- it 'pass options', ->
- data = stringify [ {a: '1', b: '2'}, {a: '3', b: '4'}], quoted: true, eof: false
- data.should.eql '"1","2"\n"3","4"'
-
- it 'catch error', ->
- (->
- stringify([ 1, {a: '3', b: '4'}])
- ).should.throw 'Invalid Record: expect an array or an object, got 1'
diff --git a/packages/csv-stringify/test/api.sync.js b/packages/csv-stringify/test/api.sync.js
new file mode 100644
index 000000000..2a97b1206
--- /dev/null
+++ b/packages/csv-stringify/test/api.sync.js
@@ -0,0 +1,37 @@
+import "should";
+import { stringify } from "../lib/sync.js";
+
+describe("sync", function () {
+ it("work on object", function () {
+ const data = stringify([
+ { a: "1", b: "2" },
+ { a: "3", b: "4" },
+ ]);
+ data.should.eql("1,2\n3,4\n");
+ });
+
+ it("work on array", function () {
+ const data = stringify([
+ ["1", "2"],
+ ["3", "4"],
+ ]);
+ data.should.eql("1,2\n3,4\n");
+ });
+
+ it("pass options", function () {
+ const data = stringify(
+ [
+ { a: "1", b: "2" },
+ { a: "3", b: "4" },
+ ],
+ { quoted: true, eof: false },
+ );
+ data.should.eql('"1","2"\n"3","4"');
+ });
+
+ it("catch error", function () {
+ (() => {
+ stringify([1, { a: "3", b: "4" }]);
+ }).should.throw("Invalid Record: expect an array or an object, got 1");
+ });
+});
diff --git a/packages/csv-stringify/test/api.types.sync.ts b/packages/csv-stringify/test/api.types.sync.ts
index 07dc3c6b3..73ecbf2d5 100644
--- a/packages/csv-stringify/test/api.types.sync.ts
+++ b/packages/csv-stringify/test/api.types.sync.ts
@@ -1,53 +1,56 @@
-
-import 'should'
+import "should";
import {
stringify,
- RecordDelimiter, Cast, PlainObject, Input,
- ColumnOption, CastingContext,
-Options
-} from '../lib/sync.js'
-
-describe('API Types', () => {
+ RecordDelimiter,
+ Cast,
+ PlainObject,
+ Input,
+ ColumnOption,
+ CastingContext,
+ Options,
+} from "../lib/sync.js";
- it('stringify return string', () => {
- const input: Input = [[1,2,3]];
- const stringifier: string = stringify(input)
- stringifier
- })
+describe("API Types", function () {
+ it("stringify return string", function () {
+ const input: Input = [[1, 2, 3]];
+ const stringifier: string = stringify(input);
+ stringifier;
+ });
- it('Options', () => {
+ it("Options", function () {
(options: Options) => {
- const rd: RecordDelimiter | undefined = options.record_delimiter
- const cast = options.cast
- const castBoolean : Cast
| undefined = cast?.boolean
- const columns: readonly string[] | PlainObject | readonly ColumnOption[] | undefined = options.columns
- return [
- rd, castBoolean, columns
- ]
- }
- })
-
- it('CastingContext', () => {
+ const rd: RecordDelimiter | undefined = options.record_delimiter;
+ const cast = options.cast;
+ const castBoolean: Cast | undefined = cast?.boolean;
+ const columns:
+ | ReadonlyArray
+ | PlainObject
+ | undefined = options.columns;
+ return [rd, castBoolean, columns];
+ };
+ });
+
+ it("CastingContext", function () {
const options: Options = {
cast: {
boolean: (value: boolean, context: CastingContext) => {
- return `${value} ${context.index}`
- }
- }
- }
- return options
- })
+ return `${value} ${context.index}`;
+ },
+ },
+ };
+ return options;
+ });
- it('allows cast to return an object', () => {
+ it("allows cast to return an object", function () {
const options: Options = {
cast: {
boolean: (value: boolean) => ({
value: value.toString(),
- delimiter: ';',
- quote: false
- })
- }
- }
- })
-
-})
+ delimiter: ";",
+ quote: false,
+ }),
+ },
+ };
+ options;
+ });
+});
diff --git a/packages/csv-stringify/test/api.types.ts b/packages/csv-stringify/test/api.types.ts
index 9907e65ef..3e18e1d5e 100644
--- a/packages/csv-stringify/test/api.types.ts
+++ b/packages/csv-stringify/test/api.types.ts
@@ -1,166 +1,174 @@
+import "should";
+import {
+ stringify,
+ CastingContext,
+ Options,
+ Stringifier,
+} from "../lib/index.js";
-import 'should'
-import { stringify, CastingContext, Options, Stringifier } from '../lib/index.js'
-import { stringify as stringifySync } from '../lib/index.js'
-
-describe('API Types', () => {
-
- describe('Parser', () => {
-
- it('Expose options', () => {
- const stringifier: Stringifier = stringify()
- const options: Options = stringifier.options
- const keys: any = Object.keys(options)
- keys.sort().should.eql([
- 'bom', 'cast', 'columns', 'delimiter', 'eof', 'escape',
- 'escape_formulas', 'header', 'on_record', 'quote', 'quoted',
- 'quoted_empty', 'quoted_match', 'quoted_string', 'record_delimiter'
- ])
- })
-
- it('Receive Callback', (next) => {
- stringify([['a'], ['b']], function(err: Error | undefined, output: string){
- if(err !== undefined){
- output.should.eql('a\nb')
- }
- next(err)
- })
- })
-
- })
-
- describe('Options', () => {
-
- it('bom', () => {
- const options: Options = {}
- options.bom = true
- })
-
- it('cast', () => {
- const options: Options = {}
+describe("API Types", function () {
+ describe("Parser", function () {
+ it("Expose options", function () {
+ const stringifier: Stringifier = stringify();
+ const options: Options = stringifier.options;
+ const keys = Object.keys(options);
+ keys
+ .sort()
+ .should.eql([
+ "bom",
+ "cast",
+ "columns",
+ "delimiter",
+ "eof",
+ "escape",
+ "escape_formulas",
+ "header",
+ "on_record",
+ "quote",
+ "quoted",
+ "quoted_empty",
+ "quoted_match",
+ "quoted_string",
+ "record_delimiter",
+ ]);
+ });
+
+ it("Receive Callback", function (next) {
+ stringify(
+ [["a"], ["b"]],
+ function (err: Error | undefined, output: string) {
+ if (err !== undefined) {
+ output.should.eql("a\nb");
+ }
+ next(err);
+ },
+ );
+ });
+ });
+
+ describe("Options", function () {
+ it("bom", function () {
+ const options: Options = {};
+ options.bom = true;
+ });
+
+ it("cast", function () {
+ const options: Options = {};
options.cast = {
boolean: (value: boolean) => {
- return value ? 'true': 'false'
+ return value ? "true" : "false";
},
date: (value: Date) => {
- return value ? 'true': 'false'
+ return value ? "true" : "false";
},
number: (value: number) => {
- return value ? 'true': 'false'
+ return value ? "true" : "false";
},
bigint: (value: bigint) => {
- return value ? 'true': 'false'
+ return value ? "true" : "false";
},
object: (value: object) => {
- return value ? 'true': 'false'
+ return value ? "true" : "false";
},
string: (value: string) => {
- return value ? 'true': 'false'
+ return value ? "true" : "false";
},
- }
- })
-
- it('columns', () => {
- const options: Options = {}
- options.columns = [
- 'b',
- 'a'
- ]
+ };
+ });
+
+ it("columns", function () {
+ const options: Options = {};
+ options.columns = ["b", "a"];
+ options.columns = [{ key: "b" }, { key: "a" }];
options.columns = [
- { key: 'b' },
- { key: 'a' }
- ]
+ { key: "b", header: "B" },
+ { key: "a", header: "A" },
+ "c",
+ { key: "d" },
+ ];
options.columns = {
- field1: 'column1',
- field3: 'column3'
- }
- })
-
- it("columns as const", () => {
+ field1: "column1",
+ field3: "column3",
+ };
+ });
+
+ it("columns as const", function () {
const options: Options = {};
options.columns = ["b", "a"];
options.columns = ["b", "a"] as const;
});
-
- it('delimiter', () => {
- const options: Options = {}
- options.delimiter = ':'
- options.delimiter = Buffer.from(':')
- })
-
- it('escape', () => {
- const options: Options = {}
- options.escape = '"'
- options.escape = Buffer.from('"')
- })
-
- it('escape_formulas', () => {
- const options: Options = {}
- options.escape_formulas = true
- })
-
- it('header', () => {
- const options: Options = {}
- options.header = true
- })
-
- it('quote', () => {
- const options: Options = {}
- options.quote = "\""
- options.quote = Buffer.from("\"")
- options.quote = true
- options.quote = false
- })
-
- it('quoted', () => {
- const options: Options = {}
- options.quoted = true
- options.quoted = false
- })
-
- it('quoted_empty', () => {
- const options: Options = {}
- options.quoted_empty = true
- options.quoted_empty = false
- })
-
- it('quoted_match', () => {
- const options: Options = {}
- options.quoted_match = "\""
- options.quoted_match = /\"/
- options.quoted_match = [
- "\"",
- /\"/
- ]
- })
-
- it('quoted_string', () => {
- const options: Options = {}
- options.quoted_string = true
- options.quoted_string = false
- })
-
- it('record_delimiter', () => {
- const options: Options = {}
- options.record_delimiter = '|'
- options.record_delimiter = Buffer.from('|')
- })
-
- })
-
- describe('CastingContext', () => {
-
- it('all properties', () => {
+
+ it("delimiter", function () {
+ const options: Options = {};
+ options.delimiter = ":";
+ options.delimiter = Buffer.from(":");
+ });
+
+ it("escape", function () {
+ const options: Options = {};
+ options.escape = '"';
+ options.escape = Buffer.from('"');
+ });
+
+ it("escape_formulas", function () {
+ const options: Options = {};
+ options.escape_formulas = true;
+ });
+
+ it("header", function () {
+ const options: Options = {};
+ options.header = true;
+ });
+
+ it("quote", function () {
+ const options: Options = {};
+ options.quote = '"';
+ options.quote = Buffer.from('"');
+ options.quote = true;
+ options.quote = false;
+ });
+
+ it("quoted", function () {
+ const options: Options = {};
+ options.quoted = true;
+ options.quoted = false;
+ });
+
+ it("quoted_empty", function () {
+ const options: Options = {};
+ options.quoted_empty = true;
+ options.quoted_empty = false;
+ });
+
+ it("quoted_match", function () {
+ const options: Options = {};
+ options.quoted_match = '"';
+ options.quoted_match = /"/;
+ options.quoted_match = ['"', /"/];
+ });
+
+ it("quoted_string", function () {
+ const options: Options = {};
+ options.quoted_string = true;
+ options.quoted_string = false;
+ });
+
+ it("record_delimiter", function () {
+ const options: Options = {};
+ options.record_delimiter = "|";
+ options.record_delimiter = Buffer.from("|");
+ });
+ });
+
+ describe("CastingContext", function () {
+ it("all properties", function () {
(context: CastingContext) => {
- const column: number|string|undefined = context.column
- const header: boolean = context.header
- const index: number = context.index
- const records: number = context.records
- return [
- column, header, index, records
- ]
- }
- })
- })
-
-})
+ const column: number | string | undefined = context.column;
+ const header: boolean = context.header;
+ const index: number = context.index;
+ const records: number = context.records;
+ return [column, header, index, records];
+ };
+ });
+ });
+});
diff --git a/packages/csv-stringify/test/api.web_stream.coffee b/packages/csv-stringify/test/api.web_stream.coffee
deleted file mode 100644
index d0744f2e0..000000000
--- a/packages/csv-stringify/test/api.web_stream.coffee
+++ /dev/null
@@ -1,18 +0,0 @@
-
-# import {generate as generateStream} from 'csv-generate/stream'
-# import {stringify as stringifyStream} from '../lib/stream.js'
-# import {stringify as stringifyClassic} from '../lib/index.js'
-#
-# describe 'api stream', ->
-#
-# it.skip 'perf stream with iterator', ->
-# generator = generateStream
-# objectMode: true,
-# length: 5
-# stringifier = stringifyStream()
-# stream = generator.pipeThrough stringifier
-# chunks = []
-# for await chunk from stream
-# chunks.push chunk
-# # records.length.should.eql 5
-# console.log(chunks)
diff --git a/packages/csv-stringify/test/api.web_stream.js b/packages/csv-stringify/test/api.web_stream.js
new file mode 100644
index 000000000..4a67386a6
--- /dev/null
+++ b/packages/csv-stringify/test/api.web_stream.js
@@ -0,0 +1,21 @@
+import "should";
+// import { generate as generateStream } from "csv-generate/stream";
+// import { stringify as stringifyStream } from "../lib/stream.js";
+// import { stringify as stringifyClassic } from "../lib/index.js";
+
+describe("api stream", function () {
+ it.skip("perf stream with iterator", function () {
+ // const generator = generateStream({
+ // objectMode: true,
+ // length: 5
+ // })
+ // const stringifier = stringifyStream()
+ // const stream = generator.pipeThrough(stringifier)
+ // const chunks = []
+ // for await (const chunk of stream) {
+ // chunks.push(chunk)
+ // }
+ // // records.length.should.eql 5
+ // console.log(chunks)
+ });
+});
diff --git a/packages/csv-stringify/test/api.write.coffee b/packages/csv-stringify/test/api.write.coffee
deleted file mode 100644
index e241d3e81..000000000
--- a/packages/csv-stringify/test/api.write.coffee
+++ /dev/null
@@ -1,127 +0,0 @@
-
-import { stringify } from '../lib/index.js'
-
-describe 'API write', ->
-
- it 'arrays', (next) ->
- count = 0
- data = ''
- stringifier = stringify eof: false
- stringifier.on 'readable', ->
- while(d = stringifier.read())
- data += d
- stringifier.on 'record', (record, index) ->
- record.should.be.an.instanceof Array
- count.should.eql index
- count++
- stringifier.on 'finish', ->
- count.should.eql 10
- data.should.eql """
- Test 0,0,\"\"\"\"
- Test 1,1,\"\"\"\"
- Test 2,2,\"\"\"\"
- Test 3,3,\"\"\"\"
- Test 4,4,\"\"\"\"
- Test 5,5,\"\"\"\"
- Test 6,6,\"\"\"\"
- Test 7,7,\"\"\"\"
- Test 8,8,\"\"\"\"
- Test 9,9,\"\"\"\"
- """
- next()
- for i in [0...10]
- stringifier.write ["Test #{i}", i, '"']
- stringifier.end()
-
- it 'objects with column options', (next) ->
- count = 0
- data = ''
- stringifier = stringify(columns: ['name','value','escape'], eof: false)
- stringifier.on 'readable', ->
- while(d = stringifier.read())
- data += d
- stringifier.on 'record', (record, index) ->
- record.should.be.an.Object
- record.should.not.be.an.instanceOf Array
- count.should.eql index
- count++
- stringifier.on 'finish', ->
- count.should.eql 10
- data.should.eql """
- Test 0,0,\"\"\"\"
- Test 1,1,\"\"\"\"
- Test 2,2,\"\"\"\"
- Test 3,3,\"\"\"\"
- Test 4,4,\"\"\"\"
- Test 5,5,\"\"\"\"
- Test 6,6,\"\"\"\"
- Test 7,7,\"\"\"\"
- Test 8,8,\"\"\"\"
- Test 9,9,\"\"\"\"
- """
- next()
- for i in [0...10]
- stringifier.write {name: "Test #{i}", value:i, escape: '"', ovni: "ET #{i}"}
- stringifier.end()
-
- it 'throw error if not writable', (next) ->
- stringifier = stringify()
- stringifier.on 'error', (err) ->
- err.message.should.eql 'write after end'
- next()
- stringifier.write ['abc','123']
- stringifier.end()
- stringifier.write ['def', '456']
-
- it 'accepts full write API', (next) ->
- stringifier = stringify()
- stringifier.on 'finish', ->
- next()
- stringifier.write ['abc','123'], 'utf8' , (e,d) ->
- stringifier.end()
-
- it 'write invalid record null', (next) ->
- stringifier = stringify()
- stringifier.on 'error', (err) ->
- # Until Node.js 13
- err.message.should.eql 'May not write null values to stream'
- next()
- stringifier.on 'end', ->
- next Error 'Oh no!'
- try
- stringifier.write null, 'utf8' , (e,d) ->
- stringifier.end()
- catch err
- # Since Node.js 14
- err.message.should.eql 'May not write null values to stream'
- next()
-
- it 'write invalid record true', (next) ->
- stringifier = stringify()
- stringifier.on 'error', (err) ->
- err.message.should.eql 'Invalid Record: expect an array or an object, got true'
- next()
- stringifier.on 'end', ->
- next Error 'Oh no!'
- stringifier.write true, 'utf8' , (e,d) ->
- stringifier.end()
-
- describe 'input', ->
-
- it 'array are immutable', (next) ->
- chunks = [['a', 'b'], ['c', 'd']]
- stringify chunks, (err) ->
- chunks.should.eql [['a', 'b'], ['c', 'd']] unless err
- next err
-
- it 'object (with columns are immutable', (next) ->
- chunks = [{a: 1, b: 2}, {a: 3, b: 4}]
- stringify chunks, columns: ['b'], (err, data) ->
- chunks.should.eql [{a: 1, b: 2}, {a: 3, b: 4}] unless err
- next err
-
- it 'object (without columns) are immutable', (next) ->
- chunks = [{a: 1, b: 2}, {a: 3, b: 4}]
- stringify chunks, (err, data) ->
- chunks.should.eql [{a: 1, b: 2}, {a: 3, b: 4}] unless err
- next err
diff --git a/packages/csv-stringify/test/api.write.js b/packages/csv-stringify/test/api.write.js
new file mode 100644
index 000000000..fc3665ade
--- /dev/null
+++ b/packages/csv-stringify/test/api.write.js
@@ -0,0 +1,197 @@
+import "should";
+import dedent from "dedent";
+import { stringify } from "../lib/index.js";
+
+describe("API write", function () {
+ it("arrays", function (next) {
+ let count = 0;
+ let data = "";
+ const stringifier = stringify({ eof: false });
+ stringifier.on("readable", () => {
+ let d;
+ while ((d = stringifier.read())) {
+ data += d;
+ }
+ });
+ stringifier.on("record", (record, index) => {
+ record.should.be.an.instanceof(Array);
+ count.should.eql(index);
+ count++;
+ });
+ stringifier.on("finish", () => {
+ count.should.eql(10);
+ data.should.eql(
+ dedent`
+ Test 0,0,""""
+ Test 1,1,""""
+ Test 2,2,""""
+ Test 3,3,""""
+ Test 4,4,""""
+ Test 5,5,""""
+ Test 6,6,""""
+ Test 7,7,""""
+ Test 8,8,""""
+ Test 9,9,""""
+ `,
+ );
+ next();
+ });
+ for (let i = 0; i < 10; i++) {
+ stringifier.write([`Test ${i}`, i, '"']);
+ }
+ stringifier.end();
+ });
+
+ it("objects with column options", function (next) {
+ let count = 0;
+ let data = "";
+ const stringifier = stringify({
+ columns: ["name", "value", "escape"],
+ eof: false,
+ });
+ stringifier.on("readable", () => {
+ let d;
+ while ((d = stringifier.read())) {
+ data += d;
+ }
+ });
+ stringifier.on("record", (record, index) => {
+ record.should.be.an.Object();
+ record.should.not.be.an.instanceOf(Array);
+ count.should.eql(index);
+ count++;
+ });
+ stringifier.on("finish", () => {
+ count.should.eql(10);
+ data.should.eql(
+ dedent`
+ Test 0,0,""""
+ Test 1,1,""""
+ Test 2,2,""""
+ Test 3,3,""""
+ Test 4,4,""""
+ Test 5,5,""""
+ Test 6,6,""""
+ Test 7,7,""""
+ Test 8,8,""""
+ Test 9,9,""""
+ `,
+ );
+ next();
+ });
+ for (let i = 0; i < 10; i++) {
+ stringifier.write({
+ name: `Test ${i}`,
+ value: i,
+ escape: '"',
+ ovni: `ET ${i}`,
+ });
+ }
+ stringifier.end();
+ });
+
+ it("throw error if not writable", function (next) {
+ const stringifier = stringify();
+ stringifier.on("error", (err) => {
+ err.message.should.eql("write after end");
+ next();
+ });
+ stringifier.write(["abc", "123"]);
+ stringifier.end();
+ stringifier.write(["def", "456"]);
+ });
+
+ it("accepts full write API", function (next) {
+ const stringifier = stringify();
+ stringifier.on("finish", () => {
+ next();
+ });
+ stringifier.write(["abc", "123"], "utf8", () => {
+ stringifier.end();
+ });
+ });
+
+ it("write invalid record null", function (next) {
+ const stringifier = stringify();
+ stringifier.on("error", (err) => {
+ // Until Node.js 13
+ err.message.should.eql("May not write null values to stream");
+ next();
+ });
+ stringifier.on("end", () => {
+ next(Error("Oh no!"));
+ });
+ try {
+ stringifier.write(null, "utf8", () => {
+ stringifier.end();
+ });
+ } catch (err) {
+ // Since Node.js 14
+ err.message.should.eql("May not write null values to stream");
+ next();
+ }
+ });
+
+ it("write invalid record true", function (next) {
+ const stringifier = stringify();
+ stringifier.on("error", (err) => {
+ err.message.should.eql(
+ "Invalid Record: expect an array or an object, got true",
+ );
+ next();
+ });
+ stringifier.on("end", () => {
+ next(Error("Oh no!"));
+ });
+ stringifier.write(true, "utf8", () => {
+ stringifier.end();
+ });
+ });
+
+ describe("input", function () {
+ it("array are immutable", function (next) {
+ const chunks = [
+ ["a", "b"],
+ ["c", "d"],
+ ];
+ stringify(chunks, (err) => {
+ if (!err)
+ chunks.should.eql([
+ ["a", "b"],
+ ["c", "d"],
+ ]);
+ next(err);
+ });
+ });
+
+ it("object (with columns are immutable", function (next) {
+ const chunks = [
+ { a: 1, b: 2 },
+ { a: 3, b: 4 },
+ ];
+ stringify(chunks, { columns: ["b"] }, (err) => {
+ if (!err)
+ chunks.should.eql([
+ { a: 1, b: 2 },
+ { a: 3, b: 4 },
+ ]);
+ next(err);
+ });
+ });
+
+ it("object (without columns) are immutable", function (next) {
+ const chunks = [
+ { a: 1, b: 2 },
+ { a: 3, b: 4 },
+ ];
+ stringify(chunks, (err) => {
+ if (!err)
+ chunks.should.eql([
+ { a: 1, b: 2 },
+ { a: 3, b: 4 },
+ ]);
+ next(err);
+ });
+ });
+ });
+});
diff --git a/packages/csv-stringify/test/loaders/all.js b/packages/csv-stringify/test/loaders/all.js
deleted file mode 100644
index 4e81c3449..000000000
--- a/packages/csv-stringify/test/loaders/all.js
+++ /dev/null
@@ -1,15 +0,0 @@
-import * as coffee from "./coffee.js";
-import * as ts from "ts-node/esm";
-
-const coffeeRegex = /\.coffee$|\.litcoffee$|\.coffee\.md$/;
-const tsRegex = /\.ts$/;
-
-export function load(url, context, next) {
- if (coffeeRegex.test(url)) {
- return coffee.load.apply(this, arguments);
- }
- if (tsRegex.test(url)) {
- return ts.load.apply(this, arguments);
- }
- return next(url, context, next);
-}
diff --git a/packages/csv-stringify/test/loaders/coffee.js b/packages/csv-stringify/test/loaders/coffee.js
deleted file mode 100644
index 75b15abe0..000000000
--- a/packages/csv-stringify/test/loaders/coffee.js
+++ /dev/null
@@ -1,20 +0,0 @@
-import CoffeeScript from "coffeescript";
-
-// See https://github.com/nodejs/node/issues/36396
-const extensionsRegex = /\.coffee$|\.litcoffee$|\.coffee\.md$/;
-
-export async function load(url, context, next) {
- if (extensionsRegex.test(url)) {
- const format = "module";
- const { source: rawSource } = await next(url, { format });
- const source = CoffeeScript.compile(rawSource.toString(), {
- bare: true,
- inlineMap: true,
- filename: url,
- header: false,
- sourceMap: false,
- });
- return { format, source };
- }
- return next(url, context);
-}
diff --git a/packages/csv-stringify/test/loaders/legacy/all.js b/packages/csv-stringify/test/loaders/legacy/all.js
deleted file mode 100644
index f5e57e542..000000000
--- a/packages/csv-stringify/test/loaders/legacy/all.js
+++ /dev/null
@@ -1,36 +0,0 @@
-import * as coffee from "./coffee.js";
-import * as ts from "ts-node/esm";
-
-const coffeeRegex = /\.coffee$|\.litcoffee$|\.coffee\.md$/;
-const tsRegex = /\.ts$/;
-
-export function resolve(specifier) {
- if (coffeeRegex.test(specifier)) {
- return coffee.resolve.apply(this, arguments);
- }
- if (tsRegex.test(specifier)) {
- return ts.resolve.apply(this, arguments);
- }
- return ts.resolve.apply(this, arguments);
-}
-
-export function getFormat(url) {
- if (coffeeRegex.test(url)) {
- return coffee.getFormat.apply(this, arguments);
- }
- if (tsRegex.test(url)) {
- return ts.getFormat.apply(this, arguments);
- }
- return ts.getFormat.apply(this, arguments);
-}
-
-export function transformSource(source, context) {
- const { url } = context;
- if (coffeeRegex.test(url)) {
- return coffee.transformSource.apply(this, arguments);
- }
- if (tsRegex.test(url)) {
- return ts.transformSource.apply(this, arguments);
- }
- return ts.transformSource.apply(this, arguments);
-}
diff --git a/packages/csv-stringify/test/loaders/legacy/coffee.js b/packages/csv-stringify/test/loaders/legacy/coffee.js
deleted file mode 100644
index 6a9975db9..000000000
--- a/packages/csv-stringify/test/loaders/legacy/coffee.js
+++ /dev/null
@@ -1,50 +0,0 @@
-// coffeescript-loader.mjs
-import { URL, pathToFileURL } from "url";
-import CoffeeScript from "coffeescript";
-import { cwd } from "process";
-
-const baseURL = pathToFileURL(`${cwd()}/`).href;
-
-// CoffeeScript files end in .coffee, .litcoffee or .coffee.md.
-const extensionsRegex = /\.coffee$|\.litcoffee$|\.coffee\.md$/;
-
-export function resolve(specifier, context, defaultResolve) {
- const { parentURL = baseURL } = context;
- // Node.js normally errors on unknown file extensions, so return a URL for
- // specifiers ending in the CoffeeScript file extensions.
- if (extensionsRegex.test(specifier)) {
- return {
- url: new URL(specifier, parentURL).href,
- stop: true,
- };
- }
- // Let Node.js handle all other specifiers.
- return defaultResolve(specifier, context, defaultResolve);
-}
-
-export function getFormat(url, context, defaultGetFormat) {
- // Now that we patched resolve to let CoffeeScript URLs through, we need to
- // tell Node.js what format such URLs should be interpreted as. For the
- // purposes of this loader, all CoffeeScript URLs are ES modules.
- if (extensionsRegex.test(url)) {
- return {
- format: "module",
- stop: true,
- };
- }
- // Let Node.js handle all other URLs.
- return defaultGetFormat(url, context, defaultGetFormat);
-}
-
-export function transformSource(source, context, defaultTransformSource) {
- const { url } = context;
-
- if (extensionsRegex.test(url)) {
- return {
- source: CoffeeScript.compile(String(source), { bare: true }),
- };
- }
-
- // Let Node.js handle all other sources.
- return defaultTransformSource(source, context, defaultTransformSource);
-}
diff --git a/packages/csv-stringify/test/option.bom.coffee b/packages/csv-stringify/test/option.bom.coffee
deleted file mode 100644
index 70d90f2aa..000000000
--- a/packages/csv-stringify/test/option.bom.coffee
+++ /dev/null
@@ -1,56 +0,0 @@
-
-import { stringify } from '../lib/index.js'
-import { stringify as stringifySync } from '../lib/sync.js'
-
-describe 'Option `bom`', ->
-
- it 'validate', ->
- (->
- stringify [], bom: 'invalid', (->)
- ).should.throw
- code: 'CSV_OPTION_BOOLEAN_INVALID_TYPE'
- message: 'option `bom` is optional and must be a boolean value, got "invalid"'
-
- it 'empty', (next) ->
- stringify [], bom: true, (err, data) ->
- data.should.eql Buffer.from([239, 187, 191]).toString()
- next()
-
- it 'value is `true`', (next) ->
- stringify [
- value: 'ok'
- ], bom: true, (err, data) ->
- data.should.eql Buffer.from([239, 187, 191]).toString()+'ok\n'
- next()
-
- it 'value is `false`', (next) ->
- stringify [
- value: 'ok'
- ], bom: false, (err, data) ->
- data.should.eql 'ok\n'
- next()
-
- describe 'sync ', ->
-
- it 'validate', ->
- (->
- stringifySync [], bom: 'invalid'
- ).should.throw
- code: 'CSV_OPTION_BOOLEAN_INVALID_TYPE'
- message: 'option `bom` is optional and must be a boolean value, got "invalid"'
-
- it 'empty', ->
- data = stringifySync [], bom: true
- data.should.eql Buffer.from([239, 187, 191]).toString()
-
- it 'value is `true`', ->
- res = stringifySync [
- value: 'ok'
- ], bom: true
- res.should.eql '\ufeffok\n'
-
- it 'value is `false`', ->
- res = stringifySync [
- value: 'ok'
- ], bom: false
- res.should.eql 'ok\n'
diff --git a/packages/csv-stringify/test/option.bom.js b/packages/csv-stringify/test/option.bom.js
new file mode 100644
index 000000000..36e431af8
--- /dev/null
+++ b/packages/csv-stringify/test/option.bom.js
@@ -0,0 +1,27 @@
+import "should";
+import { stringify } from "../lib/index.js";
+import { stringify as stringifySync } from "../lib/sync.js";
+
+describe("Option `bom`", function () {
+ it("validate", function () {
+ (() => {
+ stringify([], { bom: "invalid" }, () => {});
+ }).should.throw({
+ code: "CSV_OPTION_BOOLEAN_INVALID_TYPE",
+ message:
+ 'option `bom` is optional and must be a boolean value, got "invalid"',
+ });
+ });
+
+ describe("sync ", function () {
+ it("validate", function () {
+ (() => {
+ stringifySync([], { bom: "invalid" });
+ }).should.throw({
+ code: "CSV_OPTION_BOOLEAN_INVALID_TYPE",
+ message:
+ 'option `bom` is optional and must be a boolean value, got "invalid"',
+ });
+ });
+ });
+});
diff --git a/packages/csv-stringify/test/option.bom.ts b/packages/csv-stringify/test/option.bom.ts
new file mode 100644
index 000000000..0512d5802
--- /dev/null
+++ b/packages/csv-stringify/test/option.bom.ts
@@ -0,0 +1,73 @@
+import "should";
+import { stringify } from "../lib/index.js";
+import { stringify as stringifySync } from "../lib/sync.js";
+
+describe("Option `bom`", function () {
+ it("empty", function (next) {
+ stringify([], { bom: true }, (err, data) => {
+ data.should.eql(Buffer.from([239, 187, 191]).toString());
+ next();
+ });
+ });
+
+ it("value is `true`", function (next) {
+ stringify(
+ [
+ {
+ value: "ok",
+ },
+ ],
+ { bom: true },
+ (err, data) => {
+ data.should.eql(Buffer.from([239, 187, 191]).toString() + "ok\n");
+ next();
+ },
+ );
+ });
+
+ it("value is `false`", function (next) {
+ stringify(
+ [
+ {
+ value: "ok",
+ },
+ ],
+ { bom: false },
+ (err, data) => {
+ data.should.eql("ok\n");
+ next();
+ },
+ );
+ });
+
+ describe("sync ", function () {
+ it("empty", function () {
+ const data = stringifySync([], { bom: true });
+ data.should.eql(Buffer.from([239, 187, 191]).toString());
+ });
+
+ it("value is `true`", function () {
+ const res = stringifySync(
+ [
+ {
+ value: "ok",
+ },
+ ],
+ { bom: true },
+ );
+ res.should.eql("\ufeffok\n");
+ });
+
+ it("value is `false`", function () {
+ const res = stringifySync(
+ [
+ {
+ value: "ok",
+ },
+ ],
+ { bom: false },
+ );
+ res.should.eql("ok\n");
+ });
+ });
+});
diff --git a/packages/csv-stringify/test/option.cast.coffee b/packages/csv-stringify/test/option.cast.coffee
deleted file mode 100644
index afa949c90..000000000
--- a/packages/csv-stringify/test/option.cast.coffee
+++ /dev/null
@@ -1,198 +0,0 @@
-
-import { stringify } from '../lib/index.js'
-
-describe 'Option `cast`', ->
-
- describe 'default', ->
-
- it 'default BigInt formatter', (next) ->
- stringify [
- value: BigInt 9007199254740991
- ], (err, data) ->
- data.should.eql '9007199254740991\n' unless err
- next err
-
- describe 'udf', ->
-
- it 'handle string formatter', (next) ->
- stringify [
- value: 'ok'
- ], {cast: string: -> 'X'}, (err, data) ->
- data.should.eql 'X\n' unless err
- next err
-
- it 'handle boolean formatter', (next) ->
- stringify [
- value: true
- ], {cast: boolean: -> 'X'}, (err, data) ->
- data.should.eql 'X\n' unless err
- next err
-
- it 'handle date formatter', (next) ->
- stringify [
- value: new Date
- ], {cast: date: -> 'X'}, (err, data) ->
- data.should.eql 'X\n' unless err
- next err
-
- it 'handle number formatter', (next) ->
- stringify [
- value: 3.14
- ], {cast: number: (value) -> '' + value * 2 }, (err, data) ->
- data.should.eql '6.28\n' unless err
- next err
-
- it 'handle bigint formatter', (next) ->
- stringify [
- value: BigInt(9007199254740991)
- ], {cast: bigint: (value) -> '' + value / BigInt(2) }, (err, data) ->
- data.should.eql '4503599627370495\n' unless err
- next err
-
- it 'handle object formatter', (next) ->
- stringify [
- value: a: 1
- ], {cast: object: -> 'X'}, (err, data) ->
- data.should.eql 'X\n' unless err
- next err
-
- it 'catch error', (next) ->
- stringify [
- value: true
- ], {cast: boolean: (value) -> throw Error 'Catchme'}, (err, data) ->
- err.message.should.eql 'Catchme'
- next()
-
- it 'return null', (next) ->
- # We might change this behavior in futures version, allowing to skip a field
- # if the return value is null or undefined, see #83
- stringify [
- { a: true, b: true }
- { a: false, b: true }
- { a: true, b: false }
- { a: false, b: false }
- ], {cast: boolean: (value) -> if value then '1' else null}, (err, data) ->
- data.trim().should.eql """
- 1,1
- ,1
- 1,
- ,
- """
- next()
-
- it 'boolean must return a string', (next) ->
- stringify [
- value: true
- ], {cast: boolean: (value) -> if value then 1 else 0}, (err, data) ->
- err.message.should.eql 'Invalid Casting Value: returned value must return a string, an object, null or undefined, got 1'
- next()
-
- describe 'context', ->
-
- it 'expose the expected properties', (next) ->
- stringify [
- ['a']
- ], cast: string: (value, context) ->
- Object.keys(context).sort().should.eql [
- 'column', 'header', 'index', 'records'
- ]
- null
- , next
-
- it 'index and column on array', (next) ->
- stringify [
- [true, false]
- ], cast: boolean: (value, context) ->
- if value
- context.index.should.equal 0
- context.column.should.equal 0
- 'yes'
- else
- context.index.should.equal 1
- context.column.should.equal 1
- 'no'
- , (err, data) ->
- data.trim().should.eql 'yes,no' unless err
- next err
-
- it 'index and column on object', (next) ->
- stringify [
- is_true: true
- is_false: false
- ], cast: boolean: (value, context) ->
- if value
- context.index.should.equal 0
- context.column.should.equal 'is_true'
- 'yes'
- else
- context.index.should.equal 1
- context.column.should.equal 'is_false'
- 'no'
- , (err, data) ->
- data.trim().should.eql 'yes,no' unless err
- next err
-
- it 'header', (next) ->
- stringify [
- ['value 1']
- ['value 2']
- ], header: true, columns: ['header'], cast: string: (value, context) ->
- "#{value} | #{context.header}"
- , (err, data) ->
- data.trim().should.eql """
- header | true
- value 1 | false
- value 2 | false
- """
- next err
-
- describe 'option header', ->
-
- it 'records with header and columns as array', (next) ->
- stringify [
- ['value 1']
- ['value 2']
- ], header: true, columns: ['header'], cast: string: (value, context) ->
- "#{context.records}"
- , (err, data) ->
- data.trim().should.eql '0\n0\n1' unless err
- next err
-
- it 'records without header', (next) ->
- stringify [
- ['record 1']
- ['record 2']
- ], cast: string: (value, context) ->
- "#{context.records}"
- , (err, data) ->
- data.trim().should.eql '0\n1' unless err
- next err
-
- describe 'info object', ->
-
- it 'modify escape', (next) ->
- stringify [
- ['record " 1']
- ['record " 2']
- ['record " 3']
- ], eof: false, escape: '#', cast: string: (value, context) ->
- return value if context.records is 2
- value: value, escape: ['\\', '"'][context.records]
- , (err, data) ->
- data.should.eql """
- "record \\" 1"
- "record "" 2"
- "record #" 3"
- """
- next err
-
- it 'validate and normalize local options', (next) ->
- stringify [
- ['invalid cast']
- ], eof: false, escape: '#', cast: string: (value) ->
- value: value, quote: NaN
- , (err) ->
- err.code.should.eql 'CSV_OPTION_QUOTE_INVALID_TYPE'
- next()
-
-
diff --git a/packages/csv-stringify/test/option.cast.js b/packages/csv-stringify/test/option.cast.js
new file mode 100644
index 000000000..643c3c24e
--- /dev/null
+++ b/packages/csv-stringify/test/option.cast.js
@@ -0,0 +1,45 @@
+import "should";
+import { stringify } from "../lib/index.js";
+
+describe("Option `cast`", function () {
+ describe("udf", function () {
+ it("boolean must return a string", function (next) {
+ stringify(
+ [
+ {
+ value: true,
+ },
+ ],
+ { cast: { boolean: (value) => (value ? 1 : 0) } },
+ (err) => {
+ err.message.should.eql(
+ "Invalid Casting Value: returned value must return a string, an object, null or undefined, got 1",
+ );
+ next();
+ },
+ );
+ });
+ });
+
+ describe("info object", function () {
+ it("validate and normalize local options", function (next) {
+ stringify(
+ [["invalid cast"]],
+ {
+ eof: false,
+ escape: "#",
+ cast: {
+ string: (value) => ({
+ value: value,
+ quote: NaN,
+ }),
+ },
+ },
+ (err) => {
+ err.code.should.eql("CSV_OPTION_QUOTE_INVALID_TYPE");
+ next();
+ },
+ );
+ });
+ });
+});
diff --git a/packages/csv-stringify/test/option.cast.ts b/packages/csv-stringify/test/option.cast.ts
new file mode 100644
index 000000000..f966eb77d
--- /dev/null
+++ b/packages/csv-stringify/test/option.cast.ts
@@ -0,0 +1,311 @@
+import "should";
+import dedent from "dedent";
+import { stringify } from "../lib/index.js";
+
+describe("Option `cast`", function () {
+ describe("default", function () {
+ it("default BigInt formatter", function (next) {
+ stringify(
+ [
+ {
+ value: BigInt(9007199254740991),
+ },
+ ],
+ (err, data) => {
+ if (!err) data.should.eql("9007199254740991\n");
+ next(err);
+ },
+ );
+ });
+ });
+
+ describe("udf", function () {
+ it("handle string formatter", function (next) {
+ stringify(
+ [
+ {
+ value: "ok",
+ },
+ ],
+ { cast: { string: () => "X" } },
+ (err, data) => {
+ if (!err) data.should.eql("X\n");
+ next(err);
+ },
+ );
+ });
+
+ it("handle boolean formatter", function (next) {
+ stringify(
+ [
+ {
+ value: true,
+ },
+ ],
+ { cast: { boolean: () => "X" } },
+ (err, data) => {
+ if (!err) data.should.eql("X\n");
+ next(err);
+ },
+ );
+ });
+
+ it("handle date formatter", function (next) {
+ stringify(
+ [
+ {
+ value: new Date(),
+ },
+ ],
+ { cast: { date: () => "X" } },
+ (err, data) => {
+ if (!err) data.should.eql("X\n");
+ next(err);
+ },
+ );
+ });
+
+ it("handle number formatter", function (next) {
+ stringify(
+ [
+ {
+ value: 3.14,
+ },
+ ],
+ { cast: { number: (value) => "" + value * 2 } },
+ (err, data) => {
+ if (!err) data.should.eql("6.28\n");
+ next(err);
+ },
+ );
+ });
+
+ it("handle bigint formatter", function (next) {
+ stringify(
+ [
+ {
+ value: BigInt(9007199254740991),
+ },
+ ],
+ { cast: { bigint: (value) => "" + value / BigInt(2) } },
+ (err, data) => {
+ if (!err) data.should.eql("4503599627370495\n");
+ next(err);
+ },
+ );
+ });
+
+ it("handle object formatter", function (next) {
+ stringify(
+ [
+ {
+ value: { a: 1 },
+ },
+ ],
+ { cast: { object: () => "X" } },
+ (err, data) => {
+ if (!err) data.should.eql("X\n");
+ next(err);
+ },
+ );
+ });
+
+ it("catch error", function (next) {
+ stringify(
+ [
+ {
+ value: true,
+ },
+ ],
+ {
+ cast: {
+ boolean: () => {
+ throw Error("Catchme");
+ },
+ },
+ },
+ (err) => {
+ if (!err) return next(Error("Invalid assessment"));
+ err.message.should.eql("Catchme");
+ next();
+ },
+ );
+ });
+
+ it("return null", function (next) {
+ stringify(
+ [
+ { a: true, b: true },
+ { a: false, b: true },
+ { a: true, b: false },
+ { a: false, b: false },
+ ],
+ { cast: { boolean: (value) => (value ? "1" : null) } },
+ (err, data) => {
+ if (err) return next(err);
+ data.trim().should.eql("1,1\n,1\n1,\n,");
+ next();
+ },
+ );
+ });
+ });
+
+ describe("context", function () {
+ it("expose the expected properties", function (next) {
+ stringify(
+ [["a"]],
+ {
+ cast: {
+ string: (value, context) => {
+ Object.keys(context)
+ .sort()
+ .should.eql(["column", "header", "index", "records"]);
+ return "";
+ },
+ },
+ },
+ next,
+ );
+ });
+
+ it("index and column on array", function (next) {
+ stringify(
+ [[true, false]],
+ {
+ cast: {
+ boolean: (value, context) => {
+ if (context.column == null) throw Error("Invalid assessment");
+ if (value) {
+ context.index.should.equal(0);
+ context.column.should.equal(0);
+ return "yes";
+ } else {
+ context.index.should.equal(1);
+ context.column.should.equal(1);
+ return "no";
+ }
+ },
+ },
+ },
+ (err, data) => {
+ if (!err) data.trim().should.eql("yes,no");
+ next(err);
+ },
+ );
+ });
+
+ it("index and column on object", function (next) {
+ stringify(
+ [
+ {
+ is_true: true,
+ is_false: false,
+ },
+ ],
+ {
+ cast: {
+ boolean: (value, context) => {
+ if (!context.column) throw Error("Invalid assessment");
+ if (value) {
+ context.index.should.equal(0);
+ context.column.should.equal("is_true");
+ return "yes";
+ } else {
+ context.index.should.equal(1);
+ context.column.should.equal("is_false");
+ return "no";
+ }
+ },
+ },
+ },
+ (err, data) => {
+ if (!err) data.trim().should.eql("yes,no");
+ next(err);
+ },
+ );
+ });
+
+ it("header", function (next) {
+ stringify(
+ [["value 1"], ["value 2"]],
+ {
+ header: true,
+ columns: ["header"],
+ cast: {
+ string: (value, context) => `${value} | ${context.header}`,
+ },
+ },
+ (err, data) => {
+ if (!err)
+ data
+ .trim()
+ .should.eql("header | true\nvalue 1 | false\nvalue 2 | false");
+ next(err);
+ },
+ );
+ });
+ });
+
+ describe("option header", function () {
+ it("records with header and columns as array", function (next) {
+ stringify(
+ [["value 1"], ["value 2"]],
+ {
+ header: true,
+ columns: ["header"],
+ cast: {
+ string: (value, context) => `${context.records}`,
+ },
+ },
+ (err, data) => {
+ if (!err) data.trim().should.eql("0\n0\n1");
+ next(err);
+ },
+ );
+ });
+
+ it("records without header", function (next) {
+ stringify(
+ [["record 1"], ["record 2"]],
+ {
+ cast: {
+ string: (value, context) => `${context.records}`,
+ },
+ },
+ (err, data) => {
+ if (!err) data.trim().should.eql("0\n1");
+ next(err);
+ },
+ );
+ });
+ });
+
+ describe("info object", function () {
+ it("modify escape", function (next) {
+ stringify(
+ [['record " 1'], ['record " 2'], ['record " 3']],
+ {
+ eof: false,
+ escape: "#",
+ cast: {
+ string: (value, context) => {
+ if (context.records === 2) return value;
+ return {
+ value: value,
+ escape: ["\\", '"'][context.records],
+ };
+ },
+ },
+ },
+ (err, data) => {
+ data.should.eql(dedent`
+ "record \" 1"
+ "record "" 2"
+ "record #" 3"
+ `);
+ next(err);
+ },
+ );
+ });
+ });
+});
diff --git a/packages/csv-stringify/test/option.columns.coffee b/packages/csv-stringify/test/option.columns.coffee
deleted file mode 100644
index aec2f955e..000000000
--- a/packages/csv-stringify/test/option.columns.coffee
+++ /dev/null
@@ -1,119 +0,0 @@
-
-import { stringify } from '../lib/index.js'
-
-describe 'Option `columns`', ->
-
- describe 'definition', ->
-
- it 'validates option types', ->
- (->
- stringify [], columns: true, (->)
- ).should.throw 'Invalid option "columns": expect an array or an object'
- (->
- stringify [], columns: false, (->)
- ).should.throw 'Invalid option "columns": expect an array or an object'
- (->
- stringify [], columns: '', (->)
- ).should.throw 'Invalid option "columns": expect an array or an object'
- (->
- stringify [], columns: (->), (->)
- ).should.throw 'Invalid option "columns": expect an array or an object'
-
- it 'validates column definition', ->
- (->
- stringify [], columns: [
- key_does_not_exists: 'yes'
- ], (->)
- ).should.throw 'Invalid column definition: property "key" is required'
- (->
- stringify [], columns: [
- true
- ], (->)
- ).should.throw 'Invalid column definition: expect a string or an object'
-
- it 'is an array with column object', (next) ->
- stringify [
- {a: '11', b: '12'}
- {a: '21', b: '22'}
- ], columns: [
- { key: 'b' }
- { key: 'a' }
- ], (err, records) ->
- records.should.eql "12,11\n22,21\n"
- next err
-
- it 'is an array of strings', (next) ->
- stringify [
- {a: '11', b: '12'}
- {a: '21', b: '22'}
- ], columns: [
- 'b'
- 'a'
- ], (err, records) ->
- records.should.eql "12,11\n22,21\n"
- next err
-
- it 'is an array of strings matching nested object', (next) ->
- stringify [
- {a: {a1: '1a1', a2: '1a2'}, b: '1b'}
- {a: {a1: '2a1', a2: '2a2'}, b: '2b'}
- ], columns: [
- 'b'
- 'a.a2'
- ], (err, records) ->
- records.should.eql "1b,1a2\n2b,2a2\n"
- next err
-
- it 'is an array of strings matching nested [object]', (next) ->
- stringify [
- {a: [{}, {a1: '1a1', a2: '1a2'}], b: '1b'}
- {a: [{}, {a1: '2a1', a2: '2a2'}], b: '2b'}
- ], columns: [
- 'b'
- 'a[1].a2'
- ], (err, records) ->
- records.should.eql "1b,1a2\n2b,2a2\n"
- next err
-
- it 'is an array of strings with parent key not matching a nested object', (next) ->
- stringify [
- {a: undefined, b: '1b'}
- {a: null, b: '2b'}
- {a: false, b: '3b'}
- ], columns: [
- 'b'
- 'a.a2'
- ], (err, records) ->
- records.should.eql "1b,\n2b,\n3b,\n"
- next err
-
- it 'can still access fields with dots', (next) ->
- stringify [
- {'foo.bar': '1'}
- {'foo.bar': '2'}
- ], header: true, (err, records) ->
- records.should.eql "foo.bar\n1\n2\n" unless err
- next err
-
- describe 'input', ->
-
- it 'is an array, should be the same length', (next) ->
- # Since there is not columns set in input options, we just expect
- # the output stream to contains 2 fields
- stringify [
- [ '20322051544','1979','8.8017226E7','ABC','45','2000-01-01' ]
- [ '28392898392','1974','8.8392926E7','DEF','23','2050-11-27' ]
- ], columns: ["FIELD_1", "FIELD_2"], (err, data) ->
- data.should.eql '20322051544,1979\n28392898392,1974\n' unless err
- next err
-
- it 'is a readable stream', (next) ->
- ws = stringify
- header: true
- columns: field1: 'column1', field3: 'column3'
- , (err, data) ->
- data.should.eql 'column1,column3\nval11,val13\nval21,val23\n' unless err
- next err
- ws.write {field1: 'val11', field2: 'val12', field3: 'val13'}
- ws.write {field1: 'val21', field2: 'val22', field3: 'val23'}
- ws.end()
diff --git a/packages/csv-stringify/test/option.columns.js b/packages/csv-stringify/test/option.columns.js
new file mode 100644
index 000000000..a83bd1dd1
--- /dev/null
+++ b/packages/csv-stringify/test/option.columns.js
@@ -0,0 +1,48 @@
+import "should";
+import { stringify } from "../lib/index.js";
+
+describe("Option `columns`", function () {
+ describe("definition", function () {
+ it("validates option types", function () {
+ (() => {
+ stringify([], { columns: true }, () => {});
+ }).should.throw('Invalid option "columns": expect an array or an object');
+ (() => {
+ stringify([], { columns: false }, () => {});
+ }).should.throw('Invalid option "columns": expect an array or an object');
+ (() => {
+ stringify([], { columns: "" }, () => {});
+ }).should.throw('Invalid option "columns": expect an array or an object');
+ (() => {
+ stringify([], { columns: () => {} }, () => {});
+ }).should.throw('Invalid option "columns": expect an array or an object');
+ });
+
+ it("validates column definition", function () {
+ (() => {
+ stringify(
+ [],
+ {
+ columns: [
+ {
+ key_does_not_exists: "yes",
+ },
+ ],
+ },
+ () => {},
+ );
+ }).should.throw('Invalid column definition: property "key" is required');
+ (() => {
+ stringify(
+ [],
+ {
+ columns: [true],
+ },
+ () => {},
+ );
+ }).should.throw(
+ "Invalid column definition: expect a string or an object",
+ );
+ });
+ });
+});
diff --git a/packages/csv-stringify/test/option.columns.ts b/packages/csv-stringify/test/option.columns.ts
new file mode 100644
index 000000000..c5e5783fe
--- /dev/null
+++ b/packages/csv-stringify/test/option.columns.ts
@@ -0,0 +1,135 @@
+import "should";
+import { stringify } from "../lib/index.js";
+
+describe("Option `columns`", function () {
+ describe("definition", function () {
+ it("is an array with column object", function (next) {
+ stringify(
+ [
+ { a: "11", b: "12" },
+ { a: "21", b: "22" },
+ ],
+ {
+ columns: [{ key: "b" }, { key: "a" }],
+ },
+ (err, records) => {
+ records.should.eql("12,11\n22,21\n");
+ next(err);
+ },
+ );
+ });
+
+ it("is an array of strings", function (next) {
+ stringify(
+ [
+ { a: "11", b: "12" },
+ { a: "21", b: "22" },
+ ],
+ {
+ columns: ["b", "a"],
+ },
+ (err, records) => {
+ records.should.eql("12,11\n22,21\n");
+ next(err);
+ },
+ );
+ });
+
+ it("is an array of strings matching nested object", function (next) {
+ stringify(
+ [
+ { a: { a1: "1a1", a2: "1a2" }, b: "1b" },
+ { a: { a1: "2a1", a2: "2a2" }, b: "2b" },
+ ],
+ {
+ columns: ["b", "a.a2"],
+ },
+ (err, records) => {
+ records.should.eql("1b,1a2\n2b,2a2\n");
+ next(err);
+ },
+ );
+ });
+
+ it("is an array of strings matching nested [object]", function (next) {
+ stringify(
+ [
+ { a: [{}, { a1: "1a1", a2: "1a2" }], b: "1b" },
+ { a: [{}, { a1: "2a1", a2: "2a2" }], b: "2b" },
+ ],
+ {
+ columns: ["b", "a[1].a2"],
+ },
+ (err, records) => {
+ records.should.eql("1b,1a2\n2b,2a2\n");
+ next(err);
+ },
+ );
+ });
+
+ it("is an array of strings with parent key not matching a nested object", function (next) {
+ stringify(
+ [
+ { a: undefined, b: "1b" },
+ { a: null, b: "2b" },
+ { a: false, b: "3b" },
+ ],
+ {
+ columns: ["b", "a.a2"],
+ },
+ (err, records) => {
+ records.should.eql("1b,\n2b,\n3b,\n");
+ next(err);
+ },
+ );
+ });
+
+ it("can still access fields with dots", function (next) {
+ stringify(
+ [{ "foo.bar": "1" }, { "foo.bar": "2" }],
+ {
+ header: true,
+ },
+ (err, records) => {
+ if (!err) records.should.eql("foo.bar\n1\n2\n");
+ next(err);
+ },
+ );
+ });
+ });
+
+ describe("input", function () {
+ it("is an array, should be the same length", function (next) {
+ stringify(
+ [
+ ["20322051544", "1979", "8.8017226E7", "ABC", "45", "2000-01-01"],
+ ["28392898392", "1974", "8.8392926E7", "DEF", "23", "2050-11-27"],
+ ],
+ {
+ columns: ["FIELD_1", "FIELD_2"],
+ },
+ (err, data) => {
+ if (!err) data.should.eql("20322051544,1979\n28392898392,1974\n");
+ next(err);
+ },
+ );
+ });
+
+ it("is a readable stream", function (next) {
+ const ws = stringify(
+ {
+ header: true,
+ columns: { field1: "column1", field3: "column3" },
+ },
+ (err, data) => {
+ if (!err)
+ data.should.eql("column1,column3\nval11,val13\nval21,val23\n");
+ next(err);
+ },
+ );
+ ws.write({ field1: "val11", field2: "val12", field3: "val13" });
+ ws.write({ field1: "val21", field2: "val22", field3: "val23" });
+ ws.end();
+ });
+ });
+});
diff --git a/packages/csv-stringify/test/option.delimiter.coffee b/packages/csv-stringify/test/option.delimiter.coffee
deleted file mode 100644
index 366a2af3e..000000000
--- a/packages/csv-stringify/test/option.delimiter.coffee
+++ /dev/null
@@ -1,73 +0,0 @@
-
-import { stringify } from '../lib/index.js'
-
-describe 'Option `delimiter`', ->
-
- it 'validation', ->
- stringify [], delimiter: ''
- stringify [], delimiter: ','
- stringify [], delimiter: ',,'
- stringify [], delimiter: Buffer.from ','
- ( ->
- stringify [], delimiter: true
- ).should.throw
- code: 'CSV_OPTION_DELIMITER_INVALID_TYPE'
- message: 'option `delimiter` must be a buffer or a string, got true'
- ( ->
- stringify [], delimiter: false
- ).should.throw
- code: 'CSV_OPTION_DELIMITER_INVALID_TYPE'
- message: 'option `delimiter` must be a buffer or a string, got false'
- ( ->
- stringify [], delimiter: 123
- ).should.throw
- code: 'CSV_OPTION_DELIMITER_INVALID_TYPE'
- message: 'option `delimiter` must be a buffer or a string, got 123'
-
- it 'with default value', (next) ->
- stringify [
- [ '20322051544','','8.8017226E7','45','']
- [ '','1974','8.8392926E7','','']
- ], eof: false, (err, data) ->
- return next err if err
- data.should.eql """
- 20322051544,,8.8017226E7,45,
- ,1974,8.8392926E7,,
- """
- next()
-
- it 'disabled if empty', (next) ->
- stringify [
- [ 'a',1]
- [ 'b',2]
- ], delimiter: '', eof: false, (err, data) ->
- return next err if err
- data.should.eql """
- a1
- b2
- """
- next()
-
- it 'with on character', (next) ->
- stringify [
- [ '20322051544','','8.8017226E7','45','']
- [ '','1974','8.8392926E7','','']
- ], delimiter: '\t', eof: false, (err, data) ->
- return next err if err
- data.should.eql """
- 20322051544\t\t8.8017226E7\t45\t
- \t1974\t8.8392926E7\t\t
- """
- next()
-
- it 'with multiple character', (next) ->
- stringify [
- [ 'a','b']
- [ 'c','d']
- ], delimiter: ':)(:', eof: false, (err, data) ->
- return next err if err
- data.should.eql """
- a:)(:b
- c:)(:d
- """
- next()
diff --git a/packages/csv-stringify/test/option.delimiter.js b/packages/csv-stringify/test/option.delimiter.js
new file mode 100644
index 000000000..4c5217cb3
--- /dev/null
+++ b/packages/csv-stringify/test/option.delimiter.js
@@ -0,0 +1,25 @@
+import "should";
+import { stringify } from "../lib/index.js";
+
+describe("Option `delimiter`", function () {
+ it("validation", function () {
+ (() => {
+ stringify([], { delimiter: true });
+ }).should.throw({
+ code: "CSV_OPTION_DELIMITER_INVALID_TYPE",
+ message: "option `delimiter` must be a buffer or a string, got true",
+ });
+ (() => {
+ stringify([], { delimiter: false });
+ }).should.throw({
+ code: "CSV_OPTION_DELIMITER_INVALID_TYPE",
+ message: "option `delimiter` must be a buffer or a string, got false",
+ });
+ (() => {
+ stringify([], { delimiter: 123 });
+ }).should.throw({
+ code: "CSV_OPTION_DELIMITER_INVALID_TYPE",
+ message: "option `delimiter` must be a buffer or a string, got 123",
+ });
+ });
+});
diff --git a/packages/csv-stringify/test/option.delimiter.ts b/packages/csv-stringify/test/option.delimiter.ts
new file mode 100644
index 000000000..38b205729
--- /dev/null
+++ b/packages/csv-stringify/test/option.delimiter.ts
@@ -0,0 +1,84 @@
+import "should";
+import { stringify } from "../lib/index.js";
+
+describe("Option `delimiter`", function () {
+ it("validation", function () {
+ stringify([], { delimiter: "" });
+ stringify([], { delimiter: "," });
+ stringify([], { delimiter: ",," });
+ stringify([], { delimiter: Buffer.from(",") });
+ });
+
+ it("with default value", function (next) {
+ stringify(
+ [
+ ["20322051544", "", "8.8017226E7", "45", ""],
+ ["", "1974", "8.8392926E7", "", ""],
+ ],
+ {
+ eof: false,
+ },
+ (err, data) => {
+ if (err) return next(err);
+ data.should.eql("20322051544,,8.8017226E7,45,\n,1974,8.8392926E7,,");
+ next();
+ },
+ );
+ });
+
+ it("disabled if empty", function (next) {
+ stringify(
+ [
+ ["a", 1],
+ ["b", 2],
+ ],
+ {
+ delimiter: "",
+ eof: false,
+ },
+ (err, data) => {
+ if (err) return next(err);
+ data.should.eql("a1\nb2");
+ next();
+ },
+ );
+ });
+
+ it("with on character", function (next) {
+ stringify(
+ [
+ ["20322051544", "", "8.8017226E7", "45", ""],
+ ["", "1974", "8.8392926E7", "", ""],
+ ],
+ {
+ delimiter: "\t",
+ eof: false,
+ },
+ (err, data) => {
+ if (err) return next(err);
+ data.should.eql(
+ "20322051544\t\t8.8017226E7\t45\t\n\t1974\t8.8392926E7\t\t",
+ );
+ next();
+ },
+ );
+ });
+
+ it("with multiple character", function (next) {
+ stringify(
+ [
+ ["a", "b"],
+ ["c", "d"],
+ ],
+ {
+ delimiter: ":)(:",
+ eof: false,
+ },
+ (err, data) => {
+ if (err) return next(err);
+ data.should.eql("a:)(:b\nc:)(:d");
+ next();
+ },
+ );
+ });
+});
diff --git a/packages/csv-stringify/test/option.eof.coffee b/packages/csv-stringify/test/option.eof.coffee
deleted file mode 100644
index 20380319c..000000000
--- a/packages/csv-stringify/test/option.eof.coffee
+++ /dev/null
@@ -1,22 +0,0 @@
-
-import { stringify } from '../lib/index.js'
-
-describe 'Option `eof`', ->
-
- it 'print line break when true', (next) ->
- stringify [
- ['a','b','c']
- ['1','2','3']
- ], eof: true, (err, data) ->
- return next err if err
- data.should.eql "a,b,c\n1,2,3\n"
- next()
-
- it 'dont print line break when false', (next) ->
- stringify [
- ['a','b','c']
- ['1','2','3']
- ], eof: false, (err, data) ->
- return next err if err
- data.should.eql "a,b,c\n1,2,3"
- next()
diff --git a/packages/csv-stringify/test/option.eof.ts b/packages/csv-stringify/test/option.eof.ts
new file mode 100644
index 000000000..64c5be4f3
--- /dev/null
+++ b/packages/csv-stringify/test/option.eof.ts
@@ -0,0 +1,34 @@
+import "should";
+import { stringify } from "../lib/index.js";
+
+describe("Option `eof`", function () {
+ it("print line break when true", function (next) {
+ stringify(
+ [
+ ["a", "b", "c"],
+ ["1", "2", "3"],
+ ],
+ { eof: true },
+ (err, data) => {
+ if (err) return next(err);
+ data.should.eql("a,b,c\n1,2,3\n");
+ next();
+ },
+ );
+ });
+
+ it("dont print line break when false", function (next) {
+ stringify(
+ [
+ ["a", "b", "c"],
+ ["1", "2", "3"],
+ ],
+ { eof: false },
+ (err, data) => {
+ if (err) return next(err);
+ data.should.eql("a,b,c\n1,2,3");
+ next();
+ },
+ );
+ });
+});
diff --git a/packages/csv-stringify/test/option.escape.coffee b/packages/csv-stringify/test/option.escape.coffee
deleted file mode 100644
index 006bfdfee..000000000
--- a/packages/csv-stringify/test/option.escape.coffee
+++ /dev/null
@@ -1,78 +0,0 @@
-
-import { stringify } from '../lib/index.js'
-
-describe 'Option `escape`', ->
-
- it 'default', (next) ->
- stringifier = stringify [
- ['abc', 'def']
- ], ->
- stringifier.options.escape.should.eql('"')
- next()
-
- it 'validation', ->
- stringify [], escape: ','
- stringify [], escape: Buffer.from ','
- ( ->
- stringify [], escape: true
- ).should.throw 'Invalid Option: escape must be a buffer or a string, got true'
- ( ->
- stringify [], escape: false
- ).should.throw 'Invalid Option: escape must be a buffer or a string, got false'
- ( ->
- stringify [], escape: 123
- ).should.throw 'Invalid Option: escape must be a buffer or a string, got 123'
- ( ->
- stringify [], escape: 'XX'
- ).should.throw 'Invalid Option: escape must be one character, got 2 characters'
-
- it 'only apply to quote and escape characters', (next) ->
- stringify [
- [ '-', '1"2' ]
- [ '-', '"' ]
- [ '-', '"abc' ]
- [ '-', 'def"' ]
- ], escape: '"', eof: false, (err, data) ->
- return next err if err
- data.should.eql """
- -,"1""2"
- -,"\"\""
- -,"\""abc"
- -,"def\"""
- """
- next()
-
- it 'escape delimiter', (next) ->
- stringify [
- [ 'a', 'b,c', 'd' ]
- ], escape: '"', delimiter: ',', eof: false, (err, data) ->
- return next err if err
- data.should.eql """
- a,"b,c",d
- """
- next()
-
- it 'escape record_delimiter', (next) ->
- stringify [
- [ 'a', 'b\nc', 'd' ]
- ], escape: '"', record_delimiter: '\n', eof: false, (err, data) ->
- return next err if err
- data.should.eql """
- a,"b\nc",d
- """
- next()
-
- it 'should honor the backslash escape characters', (next) ->
- stringify [
- [ '1"2','3"4"5' ]
- [ '\\abc', 'def\\' ]
- [ 'escape and quote','\\"' ] # actually \"
- ], escape: '\\', eof: false, (err, data) ->
- return next err if err
- data.should.eql """
- "1\\"2","3\\"4\\"5"
- \\abc,def\\
- escape and quote,"\\\\\\\""
- """
- # for the "escape char and quote char" value we want: \\\"
- next()
diff --git a/packages/csv-stringify/test/option.escape.js b/packages/csv-stringify/test/option.escape.js
new file mode 100644
index 000000000..b4026dc41
--- /dev/null
+++ b/packages/csv-stringify/test/option.escape.js
@@ -0,0 +1,27 @@
+import "should";
+import { stringify } from "../lib/index.js";
+
+describe("Option `escape`", function () {
+ it("validation", function () {
+ (() => {
+ stringify([], { escape: true });
+ }).should.throw(
+ "Invalid Option: escape must be a buffer or a string, got true",
+ );
+ (() => {
+ stringify([], { escape: false });
+ }).should.throw(
+ "Invalid Option: escape must be a buffer or a string, got false",
+ );
+ (() => {
+ stringify([], { escape: 123 });
+ }).should.throw(
+ "Invalid Option: escape must be a buffer or a string, got 123",
+ );
+ (() => {
+ stringify([], { escape: "XX" });
+ }).should.throw(
+ "Invalid Option: escape must be one character, got 2 characters",
+ );
+ });
+});
diff --git a/packages/csv-stringify/test/option.escape.ts b/packages/csv-stringify/test/option.escape.ts
new file mode 100644
index 000000000..d84143b6c
--- /dev/null
+++ b/packages/csv-stringify/test/option.escape.ts
@@ -0,0 +1,85 @@
+import "should";
+import dedent from "dedent";
+import { stringify } from "../lib/index.js";
+
+describe("Option `escape`", function () {
+ it("default", function (next) {
+ const stringifier = stringify([["abc", "def"]], () => {
+ stringifier.options.escape.should.eql('"');
+ next();
+ });
+ });
+
+ it("validation", function () {
+ stringify([], { escape: "," });
+ stringify([], { escape: Buffer.from(",") });
+ });
+
+ it("only apply to quote and escape characters", function (next) {
+ stringify(
+ [
+ ["-", '1"2'],
+ ["-", '"'],
+ ["-", '"abc'],
+ ["-", 'def"'],
+ ],
+ { escape: '"', eof: false },
+ (err, data) => {
+ if (err) return next(err);
+ data.should.eql(dedent`
+ -,"1""2"
+ -,""""
+ -,"""abc"
+ -,"def"""
+ `);
+ next();
+ },
+ );
+ });
+
+ it("escape delimiter", function (next) {
+ stringify(
+ [["a", "b,c", "d"]],
+ { escape: '"', delimiter: ",", eof: false },
+ (err, data) => {
+ if (err) return next(err);
+ data.should.eql('a,"b,c",d');
+ next();
+ },
+ );
+ });
+
+ it("escape record_delimiter", function (next) {
+ stringify(
+ [["a", "b\nc", "d"]],
+ { escape: '"', record_delimiter: "\n", eof: false },
+ (err, data) => {
+ if (err) return next(err);
+ data.should.eql('a,"b\nc",d');
+ next();
+ },
+ );
+ });
+
+ it("should honor the backslash escape characters", function (next) {
+ stringify(
+ [
+ ['1"2', '3"4"5'],
+ ["\\abc", "def\\"],
+ ["escape and quote", '\\"'],
+ ],
+ { escape: "\\", eof: false },
+ (err, data) => {
+ if (err) return next(err);
+ data.should.eql(
+ [
+ '"1\\"2","3\\"4\\"5"',
+ "\\abc,def\\",
+ 'escape and quote,"\\\\\\""',
+ ].join("\n"),
+ );
+ next();
+ },
+ );
+ });
+});
diff --git a/packages/csv-stringify/test/option.escape_formulas.coffee b/packages/csv-stringify/test/option.escape_formulas.coffee
deleted file mode 100644
index fd606031f..000000000
--- a/packages/csv-stringify/test/option.escape_formulas.coffee
+++ /dev/null
@@ -1,64 +0,0 @@
-
-import { stringify } from '../lib/index.js'
-
-describe 'Option `escape_formulas`', ->
-
- it 'default to `false`', (next) ->
- stringifier = stringify [
- ['abc', 'def']
- ], ->
- stringifier.options.escape_formulas.should.be.false()
- next()
-
- it 'validation', ->
- (->
- stringify [
- ['abc', 'def']
- ], escape_formulas: 'invalid'
- ).should.throw
- code: 'CSV_OPTION_ESCAPE_FORMULAS_INVALID_TYPE'
- message: 'option `escape_formulas` must be a boolean, got "invalid"'
-
- it 'escape =, +, -, @, \\t, \\r and unicode equivalent signs', (next) ->
- stringify [
- [ '=a',1]
- [ '+b',2]
- [ '-c',3]
- [ '@d',4]
- [ '\te',5]
- [ '\rf',6]
- [ 'g',7]
- [ '\uFF1Dh',8]
- [ '\uFF0Bi',9]
- [ '\uFF0Dj',10]
- [ '\uFF20k',11]
- [ '\uFF0Cl',12] # \uFF0C is 'full width comma' and should not be escaped
- ], escape_formulas: true, eof: false, (err, data) ->
- return next err if err
- data.should.eql """
- '=a,1
- '+b,2
- '-c,3
- '@d,4
- '\te,5
- '\rf,6
- g,7
- '\uFF1Dh,8
- '\uFF0Bi,9
- '\uFF0Dj,10
- '\uFF20k,11
- \uFF0Cl,12
- """
- next()
-
- it 'with `quoted` option', (next) ->
- stringify [
- [ '=a',1]
- [ 'b',2]
- ], escape_formulas: true, quoted: true, eof: false, (err, data) ->
- return next err if err
- data.should.eql """
- "'=a","1"
- "b","2"
- """
- next()
diff --git a/packages/csv-stringify/test/option.escape_formulas.js b/packages/csv-stringify/test/option.escape_formulas.js
new file mode 100644
index 000000000..a9abe00e9
--- /dev/null
+++ b/packages/csv-stringify/test/option.escape_formulas.js
@@ -0,0 +1,13 @@
+import "should";
+import { stringify } from "../lib/index.js";
+
+describe("Option `escape_formulas`", function () {
+ it("validation", function () {
+ (() => {
+ stringify([["abc", "def"]], { escape_formulas: "invalid" });
+ }).should.throw({
+ code: "CSV_OPTION_ESCAPE_FORMULAS_INVALID_TYPE",
+ message: 'option `escape_formulas` must be a boolean, got "invalid"',
+ });
+ });
+});
diff --git a/packages/csv-stringify/test/option.escape_formulas.ts b/packages/csv-stringify/test/option.escape_formulas.ts
new file mode 100644
index 000000000..9963c6531
--- /dev/null
+++ b/packages/csv-stringify/test/option.escape_formulas.ts
@@ -0,0 +1,77 @@
+import "should";
+import dedent from "dedent";
+import { stringify } from "../lib/index.js";
+
+describe("Option `escape_formulas`", function () {
+ it("default to `false`", function (next) {
+ const stringifier = stringify([["abc", "def"]], () => {
+ stringifier.options.escape_formulas.should.be.false();
+ next();
+ });
+ });
+
+ it("escape =, +, -, @, \\t, \\r and unicode equivalent signs", function (next) {
+ stringify(
+ [
+ ["=a", 1],
+ ["+b", 2],
+ ["-c", 3],
+ ["@d", 4],
+ ["\te", 5],
+ ["\rf", 6],
+ ["g", 7],
+ ["\uFF1Dh", 8],
+ ["\uFF0Bi", 9],
+ ["\uFF0Dj", 10],
+ ["\uFF20k", 11],
+ ["\uFF0Cl", 12], // \uFF0C is 'full width comma' and should not be escaped
+ ],
+ {
+ escape_formulas: true,
+ eof: false,
+ },
+ (err, data) => {
+ if (err) return next(err);
+ data.should.eql(
+ [
+ "'=a,1",
+ "'+b,2",
+ "'-c,3",
+ "'@d,4",
+ "'\te,5",
+ "'\rf,6",
+ "g,7",
+ "'\uFF1Dh,8",
+ "'\uFF0Bi,9",
+ "'\uFF0Dj,10",
+ "'\uFF20k,11",
+ "\uFF0Cl,12",
+ ].join("\n"),
+ );
+ next();
+ },
+ );
+ });
+
+ it("with `quoted` option", function (next) {
+ stringify(
+ [
+ ["=a", 1],
+ ["b", 2],
+ ],
+ {
+ escape_formulas: true,
+ quoted: true,
+ eof: false,
+ },
+ (err, data) => {
+ if (err) return next(err);
+ data.should.eql(dedent`
+ "'=a","1"
+ "b","2"
+ `);
+ next();
+ },
+ );
+ });
+});
diff --git a/packages/csv-stringify/test/option.header.coffee b/packages/csv-stringify/test/option.header.coffee
deleted file mode 100644
index 7f3b88cf0..000000000
--- a/packages/csv-stringify/test/option.header.coffee
+++ /dev/null
@@ -1,140 +0,0 @@
-
-import { stringify } from '../lib/index.js'
-import { stringify as stringifySync } from '../lib/sync.js'
-
-describe 'Option `header`', ->
-
- it 'as "true" and without "column" option with objects', (next) ->
- stringify [
- {field1: 'val11', field2: 'val12', field3: 'val13'}
- {field1: 'val21', field2: 'val22', field3: 'val23'}
- ], header: true, (err, data) ->
- return next err if err
- data.should.eql 'field1,field2,field3\nval11,val12,val13\nval21,val22,val23\n'
- next()
-
- it 'must get columns from somewhere', (next) ->
- stringify [
- ['h1', 'h2', 'h3']
- ['1', '2', '3']
- ['4', '5', '6']
- ], header: true, (err, data) ->
- err.message.should.eql 'Undiscoverable Columns: header option requires column option or object records'
- next()
-
- it 'is immutable', (next) ->
- options = header: true, quotedEmpty:true, delimiter: "|"
- data1 = [ { a:'1', b:'2', c:'3' }, {a: '4', b: '5', c: '6'} ]
- data2 = [ { x:'1', y:'2', z:'3' }, {x: '4', y: '5', z: '6' } ]
- stringify data1, options, (err, result1) ->
- stringify data2, options, (err, result2) ->
- result1.should.eql "a|b|c\n1|2|3\n4|5|6\n" unless err
- result2.should.eql "x|y|z\n1|2|3\n4|5|6\n" unless err
- next err
-
- describe 'event', ->
-
- it 'emit header', (next) ->
- count = 0
- data = ''
- stringifier = stringify(columns: [ 'col1', 'col2' ], header: true)
- stringifier.on 'readable', ->
- while(d = stringifier.read())
- data += d
- stringifier.on 'record', (record, index) ->
- count++
- stringifier.on 'finish', ->
- count.should.eql 2
- data.should.eql 'col1,col2\nfoo1,goo1\nfoo2,goo2\n'
- next()
- stringifier.write col1: 'foo1', col2: 'goo1'
- stringifier.write col1: 'foo2', col2: 'goo2'
- stringifier.end()
-
- it 'emit header even without a source', (next) ->
- count = 0
- data = ''
- stringifier = stringify(columns: [ 'col1', 'col2' ], header: true)
- stringifier.on 'readable', ->
- while(d = stringifier.read())
- data += d
- stringifier.on 'end', ->
- data.should.eql 'col1,col2\n'
- next()
- stringifier.end()
-
- describe 'without records', ->
-
- it 'print headers if no records to parse', (next) ->
- stringify [], header: true, columns: ['some', 'headers'], (err, data) ->
- data.should.eql 'some,headers\n'
- next()
-
- it 'print headers if no records to parse in sync mode, fix #343', ->
- data = stringifySync [], header: true, columns: ['some', 'headers']
- data.should.eql 'some,headers\n'
-
- it 'not print headers if no records to parse and no header option', (next) ->
- stringify [], header: false, columns: ['some', 'headers'], (err, data) ->
- data.should.eql ''
- next()
-
- describe 'with column', ->
-
- it 'filter records array properties not listed as columns', (next) ->
- stringify [
- [ 20322051544, 1979, 'ABC', 45, ]
- [ 28392898392, 1974, 'DEF', 23, ]
- ], header: true, columns: ["a", "b"], eof: false, (err, data) ->
- data.should.eql """
- a,b
- 20322051544,1979
- 28392898392,1974
- """ unless err
- next err
-
- it 'filter records object properties not listed as columns', (next) ->
- stringify [
- { a: 20322051544, b: '1979', c: '8.8017226E7' }
- { a: 28392898392, b: '1974', c: '8.8392926E7' }
- ], header: true, columns: ["a", "c"], eof: false, (err, data) ->
- data.should.eql """
- a,c
- 20322051544,8.8017226E7
- 28392898392,8.8392926E7
- """
- next()
-
- it 'map the column property name to display name', (next) ->
- stringify [
- { field1: 'val11', field2: 'val12', field3: 'val13' }
- { field1: 'val21', field2: 'val22', field3: 'val23' }
- ], header: true, columns: {field1: 'column1', field3: 'column3'}, (err, data) ->
- data.should.eql 'column1,column3\nval11,val13\nval21,val23\n' unless err
- next err
-
- it 'map the column property name to display name', (next) ->
- stringify [
- { field1: 'val11', field2: 'val12', field3: 'val13' }
- { field1: 'val21', field2: 'val22', field3: 'val23' }
- ], header: true, columns: {field1: 'column1', field3: 'column3'}, (err, data) ->
- data.should.eql 'column1,column3\nval11,val13\nval21,val23\n' unless err
- next err
-
- describe 'nested columns', ->
-
- it 'and nested properties', (next) ->
- stringify [
- { field1: {nested: 'val11'}, field2: 'val12', field3: 'val13' }
- { field1: {}, field2: 'val22', field3: 'val23' }
- ], header: true, columns: {'field1.nested': 'column1', field3: 'column3'}, (err, data) ->
- data.should.eql 'column1,column3\nval11,val13\n,val23\n' unless err
- next err
-
- it 'also work for nested properties', (next) ->
- stringify [
- { field1: {nested: 'val11'}, field2: 'val12', field3: 'val13' }
- { field1: {}, field2: 'val22', field3: 'val23' }
- ], header: true, columns: {'field1.nested': 'column1', field3: 'column3'}, (err, data) ->
- data.should.eql 'column1,column3\nval11,val13\n,val23\n' unless err
- next err
diff --git a/packages/csv-stringify/test/option.header.ts b/packages/csv-stringify/test/option.header.ts
new file mode 100644
index 000000000..296d07dcc
--- /dev/null
+++ b/packages/csv-stringify/test/option.header.ts
@@ -0,0 +1,270 @@
+import "should";
+import dedent from "dedent";
+import { stringify } from "../lib/index.js";
+import { stringify as stringifySync } from "../lib/sync.js";
+
+describe("Option `header`", function () {
+ it('as "true" and without "column" option with objects', function (next) {
+ stringify(
+ [
+ { field1: "val11", field2: "val12", field3: "val13" },
+ { field1: "val21", field2: "val22", field3: "val23" },
+ ],
+ {
+ header: true,
+ },
+ (err, data) => {
+ if (err) return next(err);
+ data.should.eql(
+ dedent`
+ field1,field2,field3
+ val11,val12,val13
+ val21,val22,val23
+ ` + "\n",
+ );
+ next();
+ },
+ );
+ });
+
+ it("must get columns from somewhere", function (next) {
+ stringify(
+ [
+ ["h1", "h2", "h3"],
+ ["1", "2", "3"],
+ ["4", "5", "6"],
+ ],
+ {
+ header: true,
+ },
+ (err) => {
+ if (!err) return next(Error("Invalid assessment"));
+ err.message.should.eql(
+ "Undiscoverable Columns: header option requires column option or object records",
+ );
+ next();
+ },
+ );
+ });
+
+ it("is immutable", function (next) {
+ const options = { header: true, quotedEmpty: true, delimiter: "|" };
+ const data1 = [
+ { a: "1", b: "2", c: "3" },
+ { a: "4", b: "5", c: "6" },
+ ];
+ const data2 = [
+ { x: "1", y: "2", z: "3" },
+ { x: "4", y: "5", z: "6" },
+ ];
+ stringify(data1, options, (err, result1) => {
+ stringify(data2, options, (err, result2) => {
+ if (!err) {
+ result1.should.eql("a|b|c\n1|2|3\n4|5|6\n");
+ result2.should.eql("x|y|z\n1|2|3\n4|5|6\n");
+ }
+ next(err);
+ });
+ });
+ });
+
+ describe("event", function () {
+ it("emit header", function (next) {
+ let count = 0;
+ let data = "";
+ const stringifier = stringify({
+ columns: ["col1", "col2"],
+ header: true,
+ });
+ stringifier.on("readable", () => {
+ let d;
+ while ((d = stringifier.read())) {
+ data += d;
+ }
+ });
+ stringifier.on("record", () => {
+ count++;
+ });
+ stringifier.on("finish", () => {
+ count.should.eql(2);
+ data.should.eql("col1,col2\nfoo1,goo1\nfoo2,goo2\n");
+ next();
+ });
+ stringifier.write({ col1: "foo1", col2: "goo1" });
+ stringifier.write({ col1: "foo2", col2: "goo2" });
+ stringifier.end();
+ });
+
+ it("emit header even without a source", function (next) {
+ let data = "";
+ const stringifier = stringify({
+ columns: ["col1", "col2"],
+ header: true,
+ });
+ stringifier.on("readable", () => {
+ let d;
+ while ((d = stringifier.read())) {
+ data += d;
+ }
+ });
+ stringifier.on("end", () => {
+ data.should.eql("col1,col2\n");
+ next();
+ });
+ stringifier.end();
+ });
+ });
+
+ describe("without records", function () {
+ it("print headers if no records to parse", function (next) {
+ stringify(
+ [],
+ {
+ header: true,
+ columns: ["some", "headers"],
+ },
+ (err, data) => {
+ data.should.eql("some,headers\n");
+ next();
+ },
+ );
+ });
+
+ it("print headers if no records to parse in sync mode, fix #343", function () {
+ const data = stringifySync([], {
+ header: true,
+ columns: ["some", "headers"],
+ });
+ data.should.eql("some,headers\n");
+ });
+
+ it("not print headers if no records to parse and no header option", function (next) {
+ stringify(
+ [],
+ {
+ header: false,
+ columns: ["some", "headers"],
+ },
+ (err, data) => {
+ data.should.eql("");
+ next();
+ },
+ );
+ });
+ });
+
+ describe("with column", function () {
+ it("filter records array properties not listed as columns", function (next) {
+ stringify(
+ [
+ [20322051544, 1979, "ABC", 45],
+ [28392898392, 1974, "DEF", 23],
+ ],
+ {
+ header: true,
+ columns: ["a", "b"],
+ eof: false,
+ },
+ (err, data) => {
+ if (!err) {
+ data.should.eql(
+ dedent`
+ a,b
+ 20322051544,1979
+ 28392898392,1974
+ `,
+ );
+ }
+ next(err);
+ },
+ );
+ });
+
+ it("filter records object properties not listed as columns", function (next) {
+ stringify(
+ [
+ { a: 20322051544, b: "1979", c: "8.8017226E7" },
+ { a: 28392898392, b: "1974", c: "8.8392926E7" },
+ ],
+ {
+ header: true,
+ columns: ["a", "c"],
+ eof: false,
+ },
+ (err, data) => {
+ data.should.eql(
+ dedent`
+ a,c
+ 20322051544,8.8017226E7
+ 28392898392,8.8392926E7
+ `,
+ );
+ next();
+ },
+ );
+ });
+
+ it("map the column property name to display name", function (next) {
+ stringify(
+ [
+ { field1: "val11", field2: "val12", field3: "val13" },
+ { field1: "val21", field2: "val22", field3: "val23" },
+ ],
+ {
+ header: true,
+ columns: { field1: "column1", field3: "column3" },
+ },
+ (err, data) => {
+ if (!err) {
+ data.should.eql(
+ dedent`
+ column1,column3\nval11,val13\nval21,val23
+ ` + "\n",
+ );
+ }
+ next(err);
+ },
+ );
+ });
+ });
+
+ describe("nested columns", function () {
+ it("and nested properties", function (next) {
+ stringify(
+ [
+ { field1: { nested: "val11" }, field2: "val12", field3: "val13" },
+ { field1: {}, field2: "val22", field3: "val23" },
+ ],
+ {
+ header: true,
+ columns: { "field1.nested": "column1", field3: "column3" },
+ },
+ (err, data) => {
+ if (!err) {
+ data.should.eql("column1,column3\nval11,val13\n,val23\n");
+ }
+ next(err);
+ },
+ );
+ });
+
+ it("also work for nested properties", function (next) {
+ stringify(
+ [
+ { field1: { nested: "val11" }, field2: "val12", field3: "val13" },
+ { field1: {}, field2: "val22", field3: "val23" },
+ ],
+ {
+ header: true,
+ columns: { "field1.nested": "column1", field3: "column3" },
+ },
+ (err, data) => {
+ if (!err) {
+ data.should.eql("column1,column3\nval11,val13\n,val23\n");
+ }
+ next(err);
+ },
+ );
+ });
+ });
+});
diff --git a/packages/csv-stringify/test/option.quote.coffee b/packages/csv-stringify/test/option.quote.coffee
deleted file mode 100644
index 575265fc9..000000000
--- a/packages/csv-stringify/test/option.quote.coffee
+++ /dev/null
@@ -1,137 +0,0 @@
-
-import { stringify } from '../lib/index.js'
-
-describe 'Option `quote`', ->
-
- it 'default', (next) ->
- stringifier = stringify [], ->
- stringifier.options.quote.should.eql('"')
- next()
-
- it 'validation', ->
- stringify [], quote: ''
- stringify [], quote: '"'
- stringify [], quote: '||'
- stringify [], quote: Buffer.from '"'
- stringify [], quote: true
- stringify [], quote: false
- ( ->
- stringify [], quote: 123
- ).should.throw 'option `quote` must be a boolean, a buffer or a string, got 123'
-
- it 'disabled if empty', (next) ->
- stringify [
- [ '20322051544','"','8.8017226E7',45,'"ok"' ]
- [ '','1974','8.8392926E7','','' ]
- ], {eof: false, quote: ''}, (err, data) ->
- data.should.eql """
- 20322051544,",8.8017226E7,45,"ok"
- ,1974,8.8392926E7,,
- """
- next()
-
- it 'custom value with quoted', (next) ->
- stringify [
- [ 'a','','b' ]
- [ '','c','' ]
- ], eof: false, quote: '|', quoted: true, (err, data) ->
- data.should.eql """
- |a|,,|b|
- ,|c|,
- """
- next()
-
- it 'fields with separator inside fields', (next) ->
- stringify [
- [ '20322051544','1979.0','8.8017226E7','ABC,45','2000-01-01' ]
- [ '28392898392','1974.0','8.8392926E7','DEF','23','2050-11-27' ]
- ], eof: false, (err, data) ->
- data.should.eql """
- 20322051544,1979.0,8.8017226E7,"ABC,45",2000-01-01
- 28392898392,1974.0,8.8392926E7,DEF,23,2050-11-27
- """
- next()
-
- it 'fields containing delimiters', (next) ->
- stringify [
- [ '20322051544',',1979.0,8.8017226E7,ABC,45,2000-01-01' ]
- [ '28392898392','1974.0','8.8392926E7','DEF','23','2050-11-27' ]
- [ '28392898392,1974.0','8.8392926E7','DEF,23,2050-11-27,' ]
- ], eof: false, (err, data) ->
- data.should.eql """
- 20322051544,",1979.0,8.8017226E7,ABC,45,2000-01-01"
- 28392898392,1974.0,8.8392926E7,DEF,23,2050-11-27
- "28392898392,1974.0",8.8392926E7,"DEF,23,2050-11-27,"
- """
- next()
-
- it 'fields containing quotes', (next) ->
- stringify [
- [ '20322051544','1979.0','8.801"7226E7','ABC','45','2000-01-01' ]
- [ '28392898392','1974.0','8.8392926E7','DEF','2"3','2050-11-27' ]
- ], eof: false, (err, data) ->
- data.should.eql """
- 20322051544,1979.0,"8.801""7226E7",ABC,45,2000-01-01
- 28392898392,1974.0,8.8392926E7,DEF,"2""3",2050-11-27
- """
- next()
-
- it 'empty fields', (next) ->
- stringify [
- [ '20322051544','','8.8017226E7','45','' ]
- [ '','1974','8.8392926E7','','' ]
- ], eof: false, (err, data) ->
- data.should.eql """
- 20322051544,,8.8017226E7,45,
- ,1974,8.8392926E7,,
- """
- next()
-
- it 'fields containing quotes and double quotes escape', (next) ->
- stringify [
- [ '20322051544','"','8.8017226E7',45,'"ok"' ]
- [ '','1974','8.8392926E7','','' ]
- ], eof: false, (err, data) ->
- data.should.eql """
- 20322051544,\"\"\"\",8.8017226E7,45,\"\"\"ok\"\"\"
- ,1974,8.8392926E7,,
- """
- next()
-
- it 'fields with line breaks inside quotes', (next) ->
- stringify [
- [ '20322051544','\n',',8.8017226E7',45,'\nok\n' ]
- [ '\n','1974','8.8392926E7','','\n' ]
- ], eof: false, (err, data) ->
- data.should.eql """
- 20322051544,"
- ",",8.8017226E7",45,"
- ok
- "
- "
- ",1974,8.8392926E7,,"
- "
- """
- next()
-
- it 'field where quote string is empty', (next) ->
- stringify [
- [ '20322051544','"','8.8017226E7',45,'"ok"' ]
- [ '','1974','8.8392926E7','','' ]
- ], {eof: false, quote: ''}, (err, data) ->
- data.should.eql """
- 20322051544,",8.8017226E7,45,"ok"
- ,1974,8.8392926E7,,
- """
- next()
-
- it 'fields with linebreaks and different record delimiter', (next) ->
- stringify [
- [ '123\n456', 789]
- [ '','1974' ]
- ], {eof: false, record_delimiter: '__'}, (err, data) ->
- data.should.eql """
- 123
- 456,789__,1974
- """
- next()
diff --git a/packages/csv-stringify/test/option.quote.js b/packages/csv-stringify/test/option.quote.js
new file mode 100644
index 000000000..dde617a74
--- /dev/null
+++ b/packages/csv-stringify/test/option.quote.js
@@ -0,0 +1,12 @@
+import "should";
+import { stringify } from "../lib/index.js";
+
+describe("Option `quote`", function () {
+ it("validation", function () {
+ (() => {
+ stringify([], { quote: 123 });
+ }).should.throw(
+ "option `quote` must be a boolean, a buffer or a string, got 123",
+ );
+ });
+});
diff --git a/packages/csv-stringify/test/option.quote.ts b/packages/csv-stringify/test/option.quote.ts
new file mode 100644
index 000000000..851b31501
--- /dev/null
+++ b/packages/csv-stringify/test/option.quote.ts
@@ -0,0 +1,228 @@
+import "should";
+import dedent from "dedent";
+import { stringify } from "../lib/index.js";
+
+describe("Option `quote`", function () {
+ it("default", function (next) {
+ const stringifier = stringify([], () => {
+ stringifier.options.quote.should.eql('"');
+ next();
+ });
+ });
+
+ it("validation", function () {
+ stringify([], { quote: "" });
+ stringify([], { quote: '"' });
+ stringify([], { quote: "||" });
+ stringify([], { quote: Buffer.from('"') });
+ stringify([], { quote: true });
+ stringify([], { quote: false });
+ });
+
+ it("disabled if empty", function (next) {
+ stringify(
+ [
+ ["20322051544", '"', "8.8017226E7", 45, '"ok"'],
+ ["", "1974", "8.8392926E7", "", ""],
+ ],
+ {
+ eof: false,
+ quote: "",
+ },
+ (err, data) => {
+ data.should.eql(
+ dedent`
+ 20322051544,",8.8017226E7,45,"ok"
+ ,1974,8.8392926E7,,
+ `,
+ );
+ next();
+ },
+ );
+ });
+
+ it("custom value with quoted", function (next) {
+ stringify(
+ [
+ ["a", "", "b"],
+ ["", "c", ""],
+ ],
+ {
+ eof: false,
+ quote: "|",
+ quoted: true,
+ },
+ (err, data) => {
+ data.should.eql("|a|,,|b|\n,|c|,");
+ next();
+ },
+ );
+ });
+
+ it("fields with separator inside fields", function (next) {
+ stringify(
+ [
+ ["20322051544", "1979.0", "8.8017226E7", "ABC,45", "2000-01-01"],
+ ["28392898392", "1974.0", "8.8392926E7", "DEF", "23", "2050-11-27"],
+ ],
+ {
+ eof: false,
+ },
+ (err, data) => {
+ data.should.eql(
+ dedent`
+ 20322051544,1979.0,8.8017226E7,"ABC,45",2000-01-01
+ 28392898392,1974.0,8.8392926E7,DEF,23,2050-11-27
+ `,
+ );
+ next();
+ },
+ );
+ });
+
+ it("fields containing delimiters", function (next) {
+ stringify(
+ [
+ ["20322051544", ",1979.0,8.8017226E7,ABC,45,2000-01-01"],
+ ["28392898392", "1974.0", "8.8392926E7", "DEF", "23", "2050-11-27"],
+ ["28392898392,1974.0", "8.8392926E7", "DEF,23,2050-11-27,"],
+ ],
+ {
+ eof: false,
+ },
+ (err, data) => {
+ data.should.eql(
+ dedent`
+ 20322051544,",1979.0,8.8017226E7,ABC,45,2000-01-01"
+ 28392898392,1974.0,8.8392926E7,DEF,23,2050-11-27\n"28392898392,1974.0",8.8392926E7,"DEF,23,2050-11-27,"
+ `,
+ );
+ next();
+ },
+ );
+ });
+
+ it("fields containing quotes", function (next) {
+ stringify(
+ [
+ ["20322051544", "1979.0", '8.801"7226E7', "ABC", "45", "2000-01-01"],
+ ["28392898392", "1974.0", "8.8392926E7", "DEF", '2"3', "2050-11-27"],
+ ],
+ {
+ eof: false,
+ },
+ (err, data) => {
+ data.should.eql(
+ dedent`
+ 20322051544,1979.0,"8.801""7226E7",ABC,45,2000-01-01
+ 28392898392,1974.0,8.8392926E7,DEF,"2""3",2050-11-27
+ `,
+ );
+ next();
+ },
+ );
+ });
+
+ it("empty fields", function (next) {
+ stringify(
+ [
+ ["20322051544", "", "8.8017226E7", "45", ""],
+ ["", "1974", "8.8392926E7", "", ""],
+ ],
+ {
+ eof: false,
+ },
+ (err, data) => {
+ data.should.eql(dedent`
+ 20322051544,,8.8017226E7,45,
+ ,1974,8.8392926E7,,
+ `);
+ next();
+ },
+ );
+ });
+
+ it("fields containing quotes and double quotes escape", function (next) {
+ stringify(
+ [
+ ["20322051544", '"', "8.8017226E7", 45, '"ok"'],
+ ["", "1974", "8.8392926E7", "", ""],
+ ],
+ {
+ eof: false,
+ },
+ (err, data) => {
+ data.should.eql(
+ dedent`
+ 20322051544,"""",8.8017226E7,45,"""ok"""
+ ,1974,8.8392926E7,,
+ `,
+ );
+ next();
+ },
+ );
+ });
+
+ it("fields with line breaks inside quotes", function (next) {
+ stringify(
+ [
+ ["20322051544", "\n", ",8.8017226E7", 45, "\nok\n"],
+ ["\n", "1974", "8.8392926E7", "", "\n"],
+ ],
+ {
+ eof: false,
+ },
+ (err, data) => {
+ data.should.eql(
+ dedent`
+ 20322051544,"\n",",8.8017226E7",45,"\nok\n"
+ "\n",1974,8.8392926E7,,"\n"
+ `,
+ );
+ next();
+ },
+ );
+ });
+
+ it("field where quote string is empty", function (next) {
+ stringify(
+ [
+ ["20322051544", '"', "8.8017226E7", 45, '"ok"'],
+ ["", "1974", "8.8392926E7", "", ""],
+ ],
+ {
+ eof: false,
+ quote: "",
+ },
+ (err, data) => {
+ data.should.eql(
+ dedent`
+ 20322051544,",8.8017226E7,45,"ok"
+ ,1974,8.8392926E7,,
+ `,
+ );
+ next();
+ },
+ );
+ });
+
+ it("fields with linebreaks and different record delimiter", function (next) {
+ stringify(
+ [
+ ["123\n456", 789],
+ ["", "1974"],
+ ],
+ {
+ eof: false,
+ record_delimiter: "__",
+ },
+ (err, data) => {
+ data.should.eql(dedent`
+ 123
+ 456,789__,1974
+ `);
+ next();
+ },
+ );
+ });
+});
diff --git a/packages/csv-stringify/test/option.quoted.coffee b/packages/csv-stringify/test/option.quoted.coffee
deleted file mode 100644
index a4b8b4ed4..000000000
--- a/packages/csv-stringify/test/option.quoted.coffee
+++ /dev/null
@@ -1,49 +0,0 @@
-
-import { stringify } from '../lib/index.js'
-
-describe 'Option `quoted`', ->
-
- it 'surround fields', (next) ->
- count = 0
- data = ''
- stringifier = stringify quoted: true, eof: false
- stringifier.on 'readable', ->
- while(d = stringifier.read())
- data += d
- stringifier.on 'record', (record, index) ->
- count++
- stringifier.on 'finish', ->
- count.should.eql 2
- data.should.eql """
- "20322051544","1979.0","8.801""7226E7","ABC"
- "283928""98392","1974.0","8.8392926E7","DEF"
- """
- next()
- stringifier.write [ '20322051544','1979.0','8.801"7226E7','ABC' ]
- stringifier.write [ '283928"98392','1974.0','8.8392926E7','DEF' ]
- stringifier.end()
-
- it 'is executed after cast and apply to numbers', (next) ->
- stringify [
- [10.1]
- ],
- delimiter: ';'
- cast: number: (value) ->
- value.toString().replace '.', ','
- quoted_match: ','
- , (err, data) ->
- data.should.eql '"10,1"\n' unless err
- next err
-
- it 'local option in cast overwriting global', (next) ->
- stringify [
- ['10.1', '10.2']
- ],
- delimiter: ';'
- cast: string: (value, {index}) ->
- value: value.replace '.', ','
- quoted_match: if index is 0 then ',' else null
- quoted_match: ','
- , (err, data) ->
- data.should.eql '"10,1";10,2\n' unless err
- next err
diff --git a/packages/csv-stringify/test/option.quoted.ts b/packages/csv-stringify/test/option.quoted.ts
new file mode 100644
index 000000000..1358c0c79
--- /dev/null
+++ b/packages/csv-stringify/test/option.quoted.ts
@@ -0,0 +1,72 @@
+import "should";
+import dedent from "dedent";
+import { stringify } from "../lib/index.js";
+
+describe("Option `quoted`", function () {
+ it("surround fields", function (next) {
+ let count = 0;
+ let data = "";
+ const stringifier = stringify({ quoted: true, eof: false });
+ stringifier.on("readable", () => {
+ let d;
+ while ((d = stringifier.read())) {
+ data += d;
+ }
+ });
+ stringifier.on("record", () => {
+ count++;
+ });
+ stringifier.on("finish", () => {
+ count.should.eql(2);
+ data.should.eql(
+ dedent`
+ "20322051544","1979.0","8.801""7226E7","ABC"
+ "283928""98392","1974.0","8.8392926E7","DEF"
+ `,
+ );
+ next();
+ });
+ stringifier.write(["20322051544", "1979.0", '8.801"7226E7', "ABC"]);
+ stringifier.write(['283928"98392', "1974.0", "8.8392926E7", "DEF"]);
+ stringifier.end();
+ });
+
+ it("is executed after cast and apply to numbers", function (next) {
+ stringify(
+ [[10.1]],
+ {
+ delimiter: ";",
+ cast: {
+ number: (value) => {
+ return value.toString().replace(".", ",");
+ },
+ },
+ quoted_match: ",",
+ },
+ (err, data) => {
+ if (!err) data.should.eql('"10,1"\n');
+ next(err);
+ },
+ );
+ });
+
+ it("local option in cast overwriting global", function (next) {
+ stringify(
+ [["10.1", "10.2"]],
+ {
+ delimiter: ";",
+ cast: {
+ string: (value, { index }) => ({
+ value: value.replace(".", ","),
+ quoted_match: index === 0 ? "," : null,
+ }),
+ },
+ quoted_match: ",",
+ },
+ (err, data) => {
+ if (!err) data.should.eql('"10,1";10,2\n');
+ next(err);
+ },
+ );
+ });
+});
diff --git a/packages/csv-stringify/test/option.quoted_empty.coffee b/packages/csv-stringify/test/option.quoted_empty.coffee
deleted file mode 100644
index d019acbcb..000000000
--- a/packages/csv-stringify/test/option.quoted_empty.coffee
+++ /dev/null
@@ -1,76 +0,0 @@
-
-import { stringify } from '../lib/index.js'
-
-describe 'Option `quoted_empty`', ->
-
- it 'quotes empty fields (when all not quoted)', (next) ->
- count = 0
- data = ''
- stringifier = stringify quoted: false, quoted_empty: true, eof: false
- stringifier.on 'readable', ->
- while(d = stringifier.read())
- data += d
- stringifier.on 'record', (record, index) ->
- count++
- stringifier.on 'finish', ->
- count.should.eql 1
- data.should.eql """
- "","","", ,0,""
- """
- next()
- stringifier.write [ undefined,null,'',' ',0,false ]
- stringifier.end()
-
- it 'quotes empty fields (when strings quoted)', (next) ->
- count = 0
- data = ''
- stringifier = stringify quoted_empty: true, quoted_string: true, eof: false
- stringifier.on 'readable', ->
- while(d = stringifier.read())
- data += d
- stringifier.on 'record', (record, index) ->
- count++
- stringifier.on 'finish', ->
- count.should.eql 1
- data.should.eql """
- "","",""," ",0,""
- """
- next()
- stringifier.write [ undefined,null,'',' ',0,false ]
- stringifier.end()
-
- it 'prevents quoting empty fields (when strings quoted)', (next) ->
- count = 0
- data = ''
- stringifier = stringify quoted_empty: false, quoted_string: true, eof: false
- stringifier.on 'readable', ->
- while(d = stringifier.read())
- data += d
- stringifier.on 'record', (record, index) ->
- count++
- stringifier.on 'finish', ->
- count.should.eql 1
- data.should.eql """
- ,,," ",0,
- """
- next()
- stringifier.write [ undefined,null,'',' ',0,false ]
- stringifier.end()
-
- it 'quotes empty fields (when all quoted)', (next) ->
- count = 0
- data = ''
- stringifier = stringify quoted: true, quoted_empty: true, eof: false
- stringifier.on 'readable', ->
- while(d = stringifier.read())
- data += d
- stringifier.on 'record', (record, index) ->
- count++
- stringifier.on 'finish', ->
- count.should.eql 1
- data.should.eql """
- "","",""," ","0",""
- """
- next()
- stringifier.write [ undefined,null,'',' ',0,false ]
- stringifier.end()
diff --git a/packages/csv-stringify/test/option.quoted_empty.ts b/packages/csv-stringify/test/option.quoted_empty.ts
new file mode 100644
index 000000000..46647b397
--- /dev/null
+++ b/packages/csv-stringify/test/option.quoted_empty.ts
@@ -0,0 +1,108 @@
+import "should";
+import { stringify } from "../lib/index.js";
+
+describe("Option `quoted_empty`", function () {
+ it("quotes empty fields (when all not quoted)", function (next) {
+ let count = 0;
+ let data = "";
+ const stringifier = stringify({
+ quoted: false,
+ quoted_empty: true,
+ eof: false,
+ });
+ stringifier.on("readable", () => {
+ let d;
+ while ((d = stringifier.read())) {
+ data += d;
+ }
+ });
+ stringifier.on("record", () => {
+ count++;
+ });
+ stringifier.on("finish", () => {
+ count.should.eql(1);
+ data.should.eql('"","","", ,0,""');
+ next();
+ });
+ stringifier.write([undefined, null, "", " ", 0, false]);
+ stringifier.end();
+ });
+
+ it("quotes empty fields (when strings quoted)", function (next) {
+ let count = 0;
+ let data = "";
+ const stringifier = stringify({
+ quoted_empty: true,
+ quoted_string: true,
+ eof: false,
+ });
+ stringifier.on("readable", () => {
+ let d;
+ while ((d = stringifier.read())) {
+ data += d;
+ }
+ });
+ stringifier.on("record", () => {
+ count++;
+ });
+ stringifier.on("finish", () => {
+ count.should.eql(1);
+ data.should.eql('"","",""," ",0,""');
+ next();
+ });
+ stringifier.write([undefined, null, "", " ", 0, false]);
+ stringifier.end();
+ });
+
+ it("prevents quoting empty fields (when strings quoted)", function (next) {
+ let count = 0;
+ let data = "";
+ const stringifier = stringify({
+ quoted_empty: false,
+ quoted_string: true,
+ eof: false,
+ });
+ stringifier.on("readable", () => {
+ let d;
+ while ((d = stringifier.read())) {
+ data += d;
+ }
+ });
+ stringifier.on("record", () => {
+ count++;
+ });
+ stringifier.on("finish", () => {
+ count.should.eql(1);
+ data.should.eql(',,," ",0,');
+ next();
+ });
+ stringifier.write([undefined, null, "", " ", 0, false]);
+ stringifier.end();
+ });
+
+ it("quotes empty fields (when all quoted)", function (next) {
+ let count = 0;
+ let data = "";
+ const stringifier = stringify({
+ quoted: true,
+ quoted_empty: true,
+ eof: false,
+ });
+ stringifier.on("readable", () => {
+ let d;
+ while ((d = stringifier.read())) {
+ data += d;
+ }
+ });
+ stringifier.on("record", () => {
+ count++;
+ });
+ stringifier.on("finish", () => {
+ count.should.eql(1);
+ data.should.eql('"","",""," ","0",""');
+ next();
+ });
+ stringifier.write([undefined, null, "", " ", 0, false]);
+ stringifier.end();
+ });
+});
diff --git a/packages/csv-stringify/test/option.quoted_match.coffee b/packages/csv-stringify/test/option.quoted_match.coffee
deleted file mode 100644
index dd4e7d3fc..000000000
--- a/packages/csv-stringify/test/option.quoted_match.coffee
+++ /dev/null
@@ -1,99 +0,0 @@
-
-import { stringify } from '../lib/index.js'
-
-describe 'Option `quoted_match`', ->
-
- it 'default to `null`', (next) ->
- stringifier = stringify [
- ['abc', 'def']
- ], ->
- should(stringifier.options.quoted_match).be.null()
- next()
-
- it 'a string', (next) ->
- count = 0
- data = ''
- stringify [
- ['abc', 'def']
- ], quoted_match: 'e', eof: false, (err, data) ->
- data.should.eql '''
- abc,"def"
- ''' unless err
- next err
-
- it 'a regex', (next) ->
- count = 0
- data = ''
- stringify [
- ['abcd', 'efg']
- ], quoted_match: /^\w{3}$/, eof: false, (err, data) ->
- data.should.eql '''
- abcd,"efg"
- ''' unless err
- next err
-
- it 'an array', (next) ->
- count = 0
- data = ''
- stringify [
- ['ab', 'cd', 'efg']
- ], quoted_match: ['d', /^\w{3}$/], eof: false, (err, data) ->
- data.should.eql '''
- ab,"cd","efg"
- ''' unless err
- next err
-
- it 'an empty string regex with no other "quoted" options (#344)', (next) ->
- count = 0
- data = ''
- stringify [
- ['a', null, undefined, '', 'b']
- ], quoted_match: /^$/, eof: false, (err, data) ->
- data.should.eql '''
- a,,,"",b
- ''' unless err
- next err
-
- it 'an empty string regex with all other "quoted" options set to false (#344)', (next) ->
- count = 0
- data = ''
- stringify [
- ['a', null, undefined, '', 'b']
- ], quoted: false, quoted_empty: false, quoted_string: false, quoted_match: /^$/, eof: false, (err, data) ->
- data.should.eql '''
- a,,,"",b
- ''' unless err
- next err
-
- it 'an empty string regex has higher priority than the "quoted" option', (next) ->
- count = 0
- data = ''
- stringify [
- ['a', null, undefined, '', 'b']
- ], quoted: true, quoted_match: /^$/, eof: false, (err, data) ->
- data.should.eql '''
- "a",,,"","b"
- ''' unless err
- next err
-
- it "an empty string regex does not conflict with quoted_string set to true", (next) ->
- count = 0
- data = ''
- stringify [
- ['a', null, undefined, '', 'b']
- ], quoted_string: true, quoted_match: /^$/, eof: false, (err, data) ->
- data.should.eql '''
- "a",,,"","b"
- ''' unless err
- next err
-
- it "an empty string regex does not conflict with quoted_empty set to true", (next) ->
- count = 0
- data = ''
- stringify [
- ['a', null, undefined, '' , 'b']
- ], quoted_empty: true, quoted_match: /^$/, eof: false, (err, data) ->
- data.should.eql '''
- a,"","","",b
- ''' unless err
- next err
diff --git a/packages/csv-stringify/test/option.quoted_match.ts b/packages/csv-stringify/test/option.quoted_match.ts
new file mode 100644
index 000000000..6609199fc
--- /dev/null
+++ b/packages/csv-stringify/test/option.quoted_match.ts
@@ -0,0 +1,122 @@
+import "should";
+import should from "should";
+import { stringify } from "../lib/index.js";
+
+describe("Option `quoted_match`", function () {
+ it("default to `null`", function (next) {
+ const stringifier = stringify([["abc", "def"]], () => {
+ should(stringifier.options.quoted_match).be.null();
+ next();
+ });
+ });
+
+ it("a string", function (next) {
+ stringify(
+ [["abc", "def"]],
+ { quoted_match: "e", eof: false },
+ (err, data) => {
+ if (!err) {
+ data.should.eql('abc,"def"');
+ }
+ next(err);
+ },
+ );
+ });
+
+ it("a regex", function (next) {
+ stringify(
+ [["abcd", "efg"]],
+ { quoted_match: /^\w{3}$/, eof: false },
+ (err, data) => {
+ if (!err) {
+ data.should.eql('abcd,"efg"');
+ }
+ next(err);
+ },
+ );
+ });
+
+ it("an array", function (next) {
+ stringify(
+ [["ab", "cd", "efg"]],
+ { quoted_match: ["d", /^\w{3}$/], eof: false },
+ (err, data) => {
+ if (!err) {
+ data.should.eql('ab,"cd","efg"');
+ }
+ next(err);
+ },
+ );
+ });
+
+ it('an empty string regex with no other "quoted" options (#344)', function (next) {
+ stringify(
+ [["a", null, undefined, "", "b"]],
+ { quoted_match: /^$/, eof: false },
+ (err, data) => {
+ if (!err) {
+ data.should.eql('a,,,"",b');
+ }
+ next(err);
+ },
+ );
+ });
+
+ it('an empty string regex with all other "quoted" options set to false (#344)', function (next) {
+ stringify(
+ [["a", null, undefined, "", "b"]],
+ {
+ quoted: false,
+ quoted_empty: false,
+ quoted_string: false,
+ quoted_match: /^$/,
+ eof: false,
+ },
+ (err, data) => {
+ if (!err) {
+ data.should.eql('a,,,"",b');
+ }
+ next(err);
+ },
+ );
+ });
+
+ it('an empty string regex has higher priority than the "quoted" option', function (next) {
+ stringify(
+ [["a", null, undefined, "", "b"]],
+ { quoted: true, quoted_match: /^$/, eof: false },
+ (err, data) => {
+ if (!err) {
+ data.should.eql('"a",,,"","b"');
+ }
+ next(err);
+ },
+ );
+ });
+
+ it("an empty string regex does not conflict with quoted_string set to true", function (next) {
+ stringify(
+ [["a", null, undefined, "", "b"]],
+ { quoted_string: true, quoted_match: /^$/, eof: false },
+ (err, data) => {
+ if (!err) {
+ data.should.eql('"a",,,"","b"');
+ }
+ next(err);
+ },
+ );
+ });
+
+ it("an empty string regex does not conflict with quoted_empty set to true", function (next) {
+ stringify(
+ [["a", null, undefined, "", "b"]],
+ { quoted_empty: true, quoted_match: /^$/, eof: false },
+ (err, data) => {
+ if (!err) {
+ data.should.eql('a,"","","",b');
+ }
+ next(err);
+ },
+ );
+ });
+});
diff --git a/packages/csv-stringify/test/option.quoted_string.coffee b/packages/csv-stringify/test/option.quoted_string.coffee
deleted file mode 100644
index 99343a7e3..000000000
--- a/packages/csv-stringify/test/option.quoted_string.coffee
+++ /dev/null
@@ -1,34 +0,0 @@
-
-import { stringify } from '../lib/index.js'
-
-describe 'Option `quoted_string`', ->
-
- it 'quotes string fields', (next) ->
- stringify [
- [ undefined,null,'',' ','x',0,false ]
- ],
- quoted_string: true
- eof: false
- , (err, data) ->
- data.toString().should.eql """
- ,,""," ","x",0,
- """ unless err
- next err
-
- it 'quotes empty string fields (when all quoted)', (next) ->
- count = 0
- data = ''
- stringifier = stringify quoted: true, quoted_string: true, eof: false
- stringifier.on 'readable', ->
- while(d = stringifier.read())
- data += d
- stringifier.on 'record', (record, index) ->
- count++
- stringifier.on 'finish', ->
- count.should.eql 1
- data.should.eql """
- ,,""," ","x","0",
- """
- next()
- stringifier.write [ undefined,null,'',' ','x',0,false ]
- stringifier.end()
diff --git a/packages/csv-stringify/test/option.quoted_string.ts b/packages/csv-stringify/test/option.quoted_string.ts
new file mode 100644
index 000000000..f3ee7ca75
--- /dev/null
+++ b/packages/csv-stringify/test/option.quoted_string.ts
@@ -0,0 +1,45 @@
+import "should";
+import { stringify } from "../lib/index.js";
+
+describe("Option `quoted_string`", function () {
+ it("quotes string fields", function (next) {
+ stringify(
+ [[undefined, null, "", " ", "x", 0, false]],
+ {
+ quoted_string: true,
+ eof: false,
+ },
+ (err, data) => {
+ if (err) return next(err);
+ data.toString().should.eql(',,""," ","x",0,');
+ next();
+ },
+ );
+ });
+
+ it("quotes empty string fields (when all quoted)", function (next) {
+ let count = 0;
+ let data = "";
+ const stringifier = stringify({
+ quoted: true,
+ quoted_string: true,
+ eof: false,
+ });
+ stringifier.on("readable", () => {
+ let d;
+ while ((d = stringifier.read())) {
+ data += d;
+ }
+ });
+ stringifier.on("record", () => {
+ count++;
+ });
+ stringifier.on("finish", () => {
+ count.should.eql(1);
+ data.should.eql(',,""," ","x","0",');
+ next();
+ });
+ stringifier.write([undefined, null, "", " ", "x", 0, false]);
+ stringifier.end();
+ });
+});
diff --git a/packages/csv-stringify/test/option.record_delimiter.coffee b/packages/csv-stringify/test/option.record_delimiter.coffee
deleted file mode 100644
index c6b302a95..000000000
--- a/packages/csv-stringify/test/option.record_delimiter.coffee
+++ /dev/null
@@ -1,82 +0,0 @@
-
-import { stringify } from '../lib/index.js'
-
-describe 'Option `record_delimiter`', ->
-
- it 'validation', ->
- stringify [], record_delimiter: ''
- stringify [], record_delimiter: ','
- stringify [], record_delimiter: ',,'
- stringify [], record_delimiter: Buffer.from ','
- ( ->
- stringify [], record_delimiter: true
- ).should.throw 'Invalid Option: record_delimiter must be a buffer or a string, got true'
- ( ->
- stringify [], record_delimiter: false
- ).should.throw 'Invalid Option: record_delimiter must be a buffer or a string, got false'
- ( ->
- stringify [], record_delimiter: 123
- ).should.throw 'Invalid Option: record_delimiter must be a buffer or a string, got 123'
-
- it 'Test line breaks custom string', (next) ->
- stringify [
- [ '20322051544','8.8017226E7','ABC' ]
- [ '28392898392','8.8392926E7','DEF' ]
- ], record_delimiter: '::', (err, result) ->
- return next err if err
- result.should.eql '20322051544,8.8017226E7,ABC::28392898392,8.8392926E7,DEF::'
- next()
-
- it 'Test line breaks custom buffer', (next) ->
- stringify [
- [ '20322051544','8.8017226E7','ABC' ]
- [ '28392898392','8.8392926E7','DEF' ]
- ], record_delimiter: Buffer.from('::'), (err, result) ->
- return next err if err
- result.should.eql '20322051544,8.8017226E7,ABC::28392898392,8.8392926E7,DEF::'
- next()
-
- it 'Test line breaks unix', (next) ->
- stringify [
- [ '20322051544','8.8017226E7','ABC' ]
- [ '28392898392','8.8392926E7','DEF' ]
- ], record_delimiter: 'unix', (err, result) ->
- return next err if err
- result.should.eql '20322051544,8.8017226E7,ABC\n28392898392,8.8392926E7,DEF\n'
- next()
-
- it 'Test line breaks unicode', (next) ->
- stringify [
- [ '20322051544','8.8017226E7','ABC' ]
- [ '28392898392','8.8392926E7','DEF' ]
- ], record_delimiter: 'unicode', (err, result) ->
- return next err if err
- result.should.eql '20322051544,8.8017226E7,ABC\u202828392898392,8.8392926E7,DEF\u2028'
- next()
-
- it 'Test line breaks mac', (next) ->
- stringify [
- [ '20322051544','8.8017226E7','ABC' ]
- [ '28392898392','8.8392926E7','DEF' ]
- ], record_delimiter: 'mac', (err, result) ->
- return next err if err
- result.should.eql '20322051544,8.8017226E7,ABC\r28392898392,8.8392926E7,DEF\r'
- next()
-
- it 'Test line breaks windows', (next) ->
- stringify [
- [ '20322051544','8.8017226E7','ABC' ]
- [ '28392898392','8.8392926E7','DEF' ]
- ], record_delimiter: 'windows', (err, result) ->
- return next err if err
- result.should.eql '20322051544,8.8017226E7,ABC\r\n28392898392,8.8392926E7,DEF\r\n'
- next()
-
- it 'Test line breaks ascii', (next) ->
- stringify [
- [ '20322051544','8.8017226E7','ABC' ]
- [ '28392898392','8.8392926E7','DEF' ]
- ], record_delimiter: 'ascii', delimiter: '\u001f', (err, result) ->
- return next err if err
- result.should.eql '20322051544\u001f8.8017226E7\u001fABC\u001e28392898392\u001f8.8392926E7\u001fDEF\u001e'
- next()
diff --git a/packages/csv-stringify/test/option.record_delimiter.js b/packages/csv-stringify/test/option.record_delimiter.js
new file mode 100644
index 000000000..86b745829
--- /dev/null
+++ b/packages/csv-stringify/test/option.record_delimiter.js
@@ -0,0 +1,21 @@
+import { stringify } from "../lib/index.js";
+
+describe("Option `record_delimiter`", function () {
+ it("validation", function () {
+ (() => {
+ stringify([], { record_delimiter: true });
+ }).should.throw(
+ "Invalid Option: record_delimiter must be a buffer or a string, got true",
+ );
+ (() => {
+ stringify([], { record_delimiter: false });
+ }).should.throw(
+ "Invalid Option: record_delimiter must be a buffer or a string, got false",
+ );
+ (() => {
+ stringify([], { record_delimiter: 123 });
+ }).should.throw(
+ "Invalid Option: record_delimiter must be a buffer or a string, got 123",
+ );
+ });
+});
diff --git a/packages/csv-stringify/test/option.record_delimiter.ts b/packages/csv-stringify/test/option.record_delimiter.ts
new file mode 100644
index 000000000..d8b539822
--- /dev/null
+++ b/packages/csv-stringify/test/option.record_delimiter.ts
@@ -0,0 +1,129 @@
+import { stringify } from "../lib/index.js";
+
+describe("Option `record_delimiter`", function () {
+ it("validation", function () {
+ stringify([], { record_delimiter: "" });
+ stringify([], { record_delimiter: "," });
+ stringify([], { record_delimiter: ",," });
+ stringify([], { record_delimiter: Buffer.from(",") });
+ });
+
+ it("Test line breaks custom string", function (next) {
+ stringify(
+ [
+ ["20322051544", "8.8017226E7", "ABC"],
+ ["28392898392", "8.8392926E7", "DEF"],
+ ],
+ { record_delimiter: "::" },
+ (err, result) => {
+ if (err) return next(err);
+ result.should.eql(
+ "20322051544,8.8017226E7,ABC::28392898392,8.8392926E7,DEF::",
+ );
+ next();
+ },
+ );
+ });
+
+ it("Test line breaks custom buffer", function (next) {
+ stringify(
+ [
+ ["20322051544", "8.8017226E7", "ABC"],
+ ["28392898392", "8.8392926E7", "DEF"],
+ ],
+ { record_delimiter: Buffer.from("::") },
+ (err, result) => {
+ if (err) return next(err);
+ result.should.eql(
+ "20322051544,8.8017226E7,ABC::28392898392,8.8392926E7,DEF::",
+ );
+ next();
+ },
+ );
+ });
+
+ it("Test line breaks unix", function (next) {
+ stringify(
+ [
+ ["20322051544", "8.8017226E7", "ABC"],
+ ["28392898392", "8.8392926E7", "DEF"],
+ ],
+ { record_delimiter: "unix" },
+ (err, result) => {
+ if (err) return next(err);
+ result.should.eql(
+ "20322051544,8.8017226E7,ABC\n28392898392,8.8392926E7,DEF\n",
+ );
+ next();
+ },
+ );
+ });
+
+ it("Test line breaks unicode", function (next) {
+ stringify(
+ [
+ ["20322051544", "8.8017226E7", "ABC"],
+ ["28392898392", "8.8392926E7", "DEF"],
+ ],
+ { record_delimiter: "unicode" },
+ (err, result) => {
+ if (err) return next(err);
+ result.should.eql(
+ "20322051544,8.8017226E7,ABC\u202828392898392,8.8392926E7,DEF\u2028",
+ );
+ next();
+ },
+ );
+ });
+
+ it("Test line breaks mac", function (next) {
+ stringify(
+ [
+ ["20322051544", "8.8017226E7", "ABC"],
+ ["28392898392", "8.8392926E7", "DEF"],
+ ],
+ { record_delimiter: "mac" },
+ (err, result) => {
+ if (err) return next(err);
+ result.should.eql(
+ "20322051544,8.8017226E7,ABC\r28392898392,8.8392926E7,DEF\r",
+ );
+ next();
+ },
+ );
+ });
+
+ it("Test line breaks windows", function (next) {
+ stringify(
+ [
+ ["20322051544", "8.8017226E7", "ABC"],
+ ["28392898392", "8.8392926E7", "DEF"],
+ ],
+ { record_delimiter: "windows" },
+ (err, result) => {
+ if (err) return next(err);
+ result.should.eql(
+ "20322051544,8.8017226E7,ABC\r\n28392898392,8.8392926E7,DEF\r\n",
+ );
+ next();
+ },
+ );
+ });
+
+ it("Test line breaks ascii", function (next) {
+ stringify(
+ [
+ ["20322051544", "8.8017226E7", "ABC"],
+ ["28392898392", "8.8392926E7", "DEF"],
+ ],
+ { record_delimiter: "ascii", delimiter: "\u001f" },
+ (err, result) => {
+ if (err) return next(err);
+ result.should.eql(
+ "20322051544\u001f8.8017226E7\u001fABC\u001e28392898392\u001f8.8392926E7\u001fDEF\u001e",
+ );
+ next();
+ },
+ );
+ });
+});
diff --git a/packages/csv-stringify/test/options.coffee b/packages/csv-stringify/test/options.coffee
deleted file mode 100644
index a0910ca60..000000000
--- a/packages/csv-stringify/test/options.coffee
+++ /dev/null
@@ -1,9 +0,0 @@
-
-import { stringify } from '../lib/index.js'
-
-describe 'Options', ->
-
- it 'underscore options', ->
- stringifier = stringify recordDelimiter: ':'
- stringifier.options.record_delimiter.should.eql ':'
- (stringifier.options.recordDelimiter is undefined).should.be.true()
diff --git a/packages/csv-stringify/test/options.js b/packages/csv-stringify/test/options.js
new file mode 100644
index 000000000..f0e9eac1b
--- /dev/null
+++ b/packages/csv-stringify/test/options.js
@@ -0,0 +1,9 @@
+import { stringify } from "../lib/index.js";
+
+describe("Options", function () {
+ it("underscore options", function () {
+ const stringifier = stringify({ recordDelimiter: ":" });
+ stringifier.options.record_delimiter.should.eql(":");
+ (stringifier.options.recordDelimiter === undefined).should.be.true();
+ });
+});
diff --git a/packages/csv-stringify/test/samples.coffee b/packages/csv-stringify/test/samples.coffee
deleted file mode 100644
index 500e7525f..000000000
--- a/packages/csv-stringify/test/samples.coffee
+++ /dev/null
@@ -1,30 +0,0 @@
-
-import fs from 'node:fs/promises'
-import path from 'node:path'
-import { spawn } from 'node:child_process'
-
-__dirname = new URL( '.', import.meta.url).pathname
-dir = path.resolve __dirname, '../samples'
-samples = await fs.readdir dir
-
-describe 'Samples', ->
-
- samples
- .filter (sample) ->
- return false unless /\.(js|ts)?$/.test sample
- true
- .map (sample) ->
-
- it "Sample #{sample}", () ->
- data = await fs.readFile path.resolve(dir, sample), 'utf8'
- return if /^["|']skip test["|']/.test data
- new Promise (resolve, reject) ->
- ext = /\.(\w+)?$/.exec(sample)[0]
- [cmd, ...args] = switch ext
- when '.js'
- ['node', path.resolve dir, sample]
- when '.ts'
- ['node', '--loader', 'ts-node/esm', path.resolve dir, sample]
- spawn(cmd, args)
- .on 'close', (code) -> if code is 0 then resolve() else reject(new Error 'Failure')
- .stdout.on 'data', (->)
diff --git a/packages/csv-stringify/test/samples.js b/packages/csv-stringify/test/samples.js
new file mode 100644
index 000000000..5919a5514
--- /dev/null
+++ b/packages/csv-stringify/test/samples.js
@@ -0,0 +1,44 @@
+import fs from "node:fs/promises";
+import path from "node:path";
+import { spawn } from "node:child_process";
+
+const __dirname = new URL(".", import.meta.url).pathname;
+const dir = path.resolve(__dirname, "../samples");
+const samples = await fs.readdir(dir);
+
+describe("Samples", function () {
+ /* eslint mocha/no-setup-in-describe: "off" */
+ samples
+ .filter((sample) => {
+ if (!/\.(js|ts)?$/.test(sample)) return false;
+ return true;
+ })
+ .map((sample) => {
+ it(`Sample ${sample}`, async function () {
+ const data = await fs.readFile(path.resolve(dir, sample), "utf8");
+ if (/^["|']skip test["|']/.test(data)) return;
+ return new Promise((resolve, reject) => {
+ const ext = /\.(\w+)?$/.exec(sample)[0];
+ let cmd, args;
+ switch (ext) {
+ case ".js":
+ [cmd, ...args] = ["node", path.resolve(dir, sample)];
+ break;
+ case ".ts":
+ [cmd, ...args] = [
+ "node",
+ "--loader",
+ "ts-node/esm",
+ path.resolve(dir, sample),
+ ];
+ break;
+ }
+ spawn(cmd, args)
+ .on("close", (code) =>
+ code === 0 ? resolve() : reject(new Error("Failure")),
+ )
+ .stdout.on("data", () => {});
+ });
+ });
+ });
+});
diff --git a/packages/csv-stringify/test/types.js b/packages/csv-stringify/test/types.js
new file mode 100644
index 000000000..ead04c9e7
--- /dev/null
+++ b/packages/csv-stringify/test/types.js
@@ -0,0 +1,27 @@
+import { stringify } from "../lib/index.js";
+
+describe("types", function () {
+ describe("defaults", function () {
+ it("should map date to getTime", function (next) {
+ const date = new Date();
+ stringify([{ value: date }], (err, data) => {
+ if (!err) data.should.eql(date.getTime() + "\n");
+ next(err);
+ });
+ });
+
+ it("should map true boolean value to 1", function (next) {
+ stringify([{ value: true }], (err, data) => {
+ if (!err) data.should.eql("1\n");
+ next(err);
+ });
+ });
+
+ it("should map object to its json representation", function (next) {
+ stringify([{ value: { a: 1 } }], (err, data) => {
+ if (!err) data.should.eql('"{""a"":1}"\n');
+ next(err);
+ });
+ });
+ });
+});
diff --git a/packages/csv-stringify/tsconfig.json b/packages/csv-stringify/tsconfig.json
index 4db508a7c..5da38148b 100644
--- a/packages/csv-stringify/tsconfig.json
+++ b/packages/csv-stringify/tsconfig.json
@@ -4,6 +4,6 @@
"esModuleInterop": true,
"module": "ES2020",
"moduleResolution": "node",
- "strict": true,
+ "strict": true
}
}
diff --git a/packages/csv/CHANGELOG.md b/packages/csv/CHANGELOG.md
index 643fc6c62..fd910b4b9 100644
--- a/packages/csv/CHANGELOG.md
+++ b/packages/csv/CHANGELOG.md
@@ -3,6 +3,45 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
+## [6.4.1](https://github.com/adaltas/node-csv/compare/csv@6.3.11...csv@6.4.1) (2025-07-16)
+
+**Note:** Version bump only for package csv
+
+## 6.4.0 (2025-07-10)
+
+### Features
+
+- add unicode chars to formula escape ([#387](https://github.com/adaltas/node-csv/issues/387)) ([1fc177c](https://github.com/adaltas/node-csv/commit/1fc177c605e8a88e403539806890695a6ba72dec))
+- backport support for node 14 ([dbfeb78](https://github.com/adaltas/node-csv/commit/dbfeb78f61ed36f02936d63a53345708ca213e45))
+- backward support for node 8 ([496231d](https://github.com/adaltas/node-csv/commit/496231dfd838f0a6a72269a5a2390a4c637cef95))
+- esm migration ([b5c0d4b](https://github.com/adaltas/node-csv/commit/b5c0d4b191c8b57397808c0922a3f08248506a9f))
+- export ts types in sync ([890bf8d](https://github.com/adaltas/node-csv/commit/890bf8d950c18a05cab5e35a461d0847d9425156))
+- replace ts types with typesVersions ([acb41d5](https://github.com/adaltas/node-csv/commit/acb41d5031669f2d582e40da1c80f5fd4738fee4))
+- ts module Node16 and type declaration to exports field ([#341](https://github.com/adaltas/node-csv/issues/341)) ([4b0283d](https://github.com/adaltas/node-csv/commit/4b0283d17b7fa46daa1f87380759ba72c71ec79b))
+- wg stream api ([8a5eb7d](https://github.com/adaltas/node-csv/commit/8a5eb7dfd31b22217db4fbbc832d707221850785))
+
+### Bug Fixes
+
+- commonjs types, run tsc and lint to validate changes ([#397](https://github.com/adaltas/node-csv/issues/397)) ([e6870fe](https://github.com/adaltas/node-csv/commit/e6870fe272c119e273196522c9771d12ff8b2a35))
+- correct exports in package.json with webpack ([154eafb](https://github.com/adaltas/node-csv/commit/154eafbac866eb4499a0d392f8dcd057695c2586))
+- **csv-demo-ts-cjs-node16:** upgrade module definition after latest typescript ([87fe919](https://github.com/adaltas/node-csv/commit/87fe91996fb2a8895c252177fca4f0cb59a518f9))
+- **csv-demo-webpack-ts:** simplify export paths ([8d63a14](https://github.com/adaltas/node-csv/commit/8d63a14313bb6b26f13fafb740cc686f1dfaa65f))
+- **csv-generate:** finish called twice in node 16 ([3decdf1](https://github.com/adaltas/node-csv/commit/3decdf169ce3b8e0c5cadd257816c346c8e4d3fa))
+- **csv-stringify:** bom and header in sync mode with no records (fix [#343](https://github.com/adaltas/node-csv/issues/343)) ([bff158f](https://github.com/adaltas/node-csv/commit/bff158fbc9001b2cf7177ecd0f16dc97edac55f2))
+- **csv-stringify:** node 12 compatibility in flush ([9145b75](https://github.com/adaltas/node-csv/commit/9145b75012ec71a0b4152036af2275bf28c460e0))
+- **csv-stringify:** quote_match with empty string pattern quotes empty strings ([#345](https://github.com/adaltas/node-csv/issues/345)) ([1c22d2e](https://github.com/adaltas/node-csv/commit/1c22d2e07f66dd747150b5a7499b5ebd5bc0f25c)), closes [#344](https://github.com/adaltas/node-csv/issues/344)
+- **csv:** export csv_sync ([1353284](https://github.com/adaltas/node-csv/commit/1353284aa02bb9f4f727d2653e398a869eebe20d))
+- **csv:** fixed CJS types under modern `modernResolution` options ([#388](https://github.com/adaltas/node-csv/issues/388)) ([54d03e4](https://github.com/adaltas/node-csv/commit/54d03e4779033ef7d574dffa98a7c3ce93da345d))
+- **csv:** remove ts files in cjs dist ([d0d1089](https://github.com/adaltas/node-csv/commit/d0d1089c3ef9053c9adb9a9747ce11d5ea5cfe49))
+- dont insert polyfills in cjs [#303](https://github.com/adaltas/node-csv/issues/303) ([9baf334](https://github.com/adaltas/node-csv/commit/9baf334044dab90b4a0d096a7e456d0fd5807d5b))
+- esm exports in package.json files ([c48fe47](https://github.com/adaltas/node-csv/commit/c48fe478ced7560aa078fbc36ec33d6007111e2b)), closes [#308](https://github.com/adaltas/node-csv/issues/308)
+- export original lib esm modules ([be25349](https://github.com/adaltas/node-csv/commit/be2534928ba21156e9cde1e15d2e8593d62ffe71))
+- expose browser esm modules ([eb87355](https://github.com/adaltas/node-csv/commit/eb873557c65912f065d2581d30a17a96b0bfd2d6))
+- fallback to setTimeout is setImmediate is undefined ([3d6a2d0](https://github.com/adaltas/node-csv/commit/3d6a2d0a655af342f28456b46db7ccfe7ee9d664))
+- refer to esm files in dist ([b780fbd](https://github.com/adaltas/node-csv/commit/b780fbd26f5e54494e511eb2e004d3cdedee3593))
+- remove samples from publicatgion ([12c221d](https://github.com/adaltas/node-csv/commit/12c221dc37add26f094e3bb7f94b50ee06ff5be6))
+- uncaught errors with large stream chunks (fix [#386](https://github.com/adaltas/node-csv/issues/386)) ([1d500ed](https://github.com/adaltas/node-csv/commit/1d500edf38ba06fc80409974e08c37c6a40f27a1))
+
## [6.3.11](https://github.com/adaltas/node-csv/compare/csv@6.3.10...csv@6.3.11) (2024-11-21)
**Note:** Version bump only for package csv
diff --git a/packages/csv/dist/cjs/index.cjs b/packages/csv/dist/cjs/index.cjs
index c3947d6e8..d4aa04a42 100644
--- a/packages/csv/dist/cjs/index.cjs
+++ b/packages/csv/dist/cjs/index.cjs
@@ -579,7 +579,7 @@ const normalize_options$1 = function (opts) {
);
}
// Normalize option `columns`
- options.cast_first_line_to_header = null;
+ options.cast_first_line_to_header = undefined;
if (options.columns === true) {
// Fields in the first line are converted as-is to columns
options.cast_first_line_to_header = undefined;
@@ -1111,7 +1111,7 @@ const normalize_options$1 = function (opts) {
// Normalize option `to`
if (options.to === undefined || options.to === null) {
options.to = -1;
- } else {
+ } else if (options.to !== -1) {
if (typeof options.to === "string" && /\d+/.test(options.to)) {
options.to = parseInt(options.to);
}
@@ -1130,7 +1130,7 @@ const normalize_options$1 = function (opts) {
// Normalize option `to_line`
if (options.to_line === undefined || options.to_line === null) {
options.to_line = -1;
- } else {
+ } else if (options.to_line !== -1) {
if (typeof options.to_line === "string" && /\d+/.test(options.to_line)) {
options.to_line = parseInt(options.to_line);
}
@@ -1261,10 +1261,14 @@ const transform$1 = function (original_options = {}) {
this.state.bufBytesStart += bomLength;
buf = buf.slice(bomLength);
// Renormalize original options with the new encoding
- this.options = normalize_options$1({
+ const options = normalize_options$1({
...this.original_options,
encoding: encoding,
});
+ // Properties are merged with the existing options instance
+ for (const key in options) {
+ this.options[key] = options[key];
+ }
// Options will re-evaluate the Buffer with the new encoding
({ comment, escape, quote } = this.options);
break;
@@ -2007,10 +2011,14 @@ const transform$1 = function (original_options = {}) {
if (skip_records_with_error) {
this.state.recordHasError = true;
if (this.options.on_skip !== undefined) {
- this.options.on_skip(
- err,
- raw ? this.state.rawBuffer.toString(encoding) : undefined,
- );
+ try {
+ this.options.on_skip(
+ err,
+ raw ? this.state.rawBuffer.toString(encoding) : undefined,
+ );
+ } catch (err) {
+ return err;
+ }
}
// this.emit('skip', err, raw ? this.state.rawBuffer.toString(encoding) : undefined);
return undefined;
@@ -2402,6 +2410,7 @@ const reIsDeepProp = /\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/;
const reIsPlainProp = /^\w*$/;
const getTag = function (value) {
+ // if (!value) value === undefined ? "[object Undefined]" : "[object Null]";
return Object.prototype.toString.call(value);
};
diff --git a/packages/csv/dist/cjs/index.d.cts b/packages/csv/dist/cjs/index.d.cts
index c9770f8df..9dc9a1ee7 100644
--- a/packages/csv/dist/cjs/index.d.cts
+++ b/packages/csv/dist/cjs/index.d.cts
@@ -1,14 +1,13 @@
-
// Alias to the modules exposing the stream and callback APIs
-import { generate } from 'csv-generate';
-import { parse } from 'csv-parse';
-import { transform } from 'stream-transform';
-import { stringify } from 'csv-stringify';
+import { generate } from "csv-generate";
+import { parse } from "csv-parse";
+import { transform } from "stream-transform";
+import { stringify } from "csv-stringify";
export { generate, parse, transform, stringify };
-export * as generator from 'csv-generate';
-export * as parser from 'csv-parse';
-export * as transformer from 'stream-transform';
-export * as stringifier from 'csv-stringify';
+export * as generator from "csv-generate";
+export * as parser from "csv-parse";
+export * as transformer from "stream-transform";
+export * as stringifier from "csv-stringify";
diff --git a/packages/csv/dist/cjs/sync.cjs b/packages/csv/dist/cjs/sync.cjs
index 527f8b588..b762dc8ef 100644
--- a/packages/csv/dist/cjs/sync.cjs
+++ b/packages/csv/dist/cjs/sync.cjs
@@ -577,7 +577,7 @@ const normalize_options$1 = function (opts) {
);
}
// Normalize option `columns`
- options.cast_first_line_to_header = null;
+ options.cast_first_line_to_header = undefined;
if (options.columns === true) {
// Fields in the first line are converted as-is to columns
options.cast_first_line_to_header = undefined;
@@ -1109,7 +1109,7 @@ const normalize_options$1 = function (opts) {
// Normalize option `to`
if (options.to === undefined || options.to === null) {
options.to = -1;
- } else {
+ } else if (options.to !== -1) {
if (typeof options.to === "string" && /\d+/.test(options.to)) {
options.to = parseInt(options.to);
}
@@ -1128,7 +1128,7 @@ const normalize_options$1 = function (opts) {
// Normalize option `to_line`
if (options.to_line === undefined || options.to_line === null) {
options.to_line = -1;
- } else {
+ } else if (options.to_line !== -1) {
if (typeof options.to_line === "string" && /\d+/.test(options.to_line)) {
options.to_line = parseInt(options.to_line);
}
@@ -1259,10 +1259,14 @@ const transform$1 = function (original_options = {}) {
this.state.bufBytesStart += bomLength;
buf = buf.slice(bomLength);
// Renormalize original options with the new encoding
- this.options = normalize_options$1({
+ const options = normalize_options$1({
...this.original_options,
encoding: encoding,
});
+ // Properties are merged with the existing options instance
+ for (const key in options) {
+ this.options[key] = options[key];
+ }
// Options will re-evaluate the Buffer with the new encoding
({ comment, escape, quote } = this.options);
break;
@@ -2005,10 +2009,14 @@ const transform$1 = function (original_options = {}) {
if (skip_records_with_error) {
this.state.recordHasError = true;
if (this.options.on_skip !== undefined) {
- this.options.on_skip(
- err,
- raw ? this.state.rawBuffer.toString(encoding) : undefined,
- );
+ try {
+ this.options.on_skip(
+ err,
+ raw ? this.state.rawBuffer.toString(encoding) : undefined,
+ );
+ } catch (err) {
+ return err;
+ }
}
// this.emit('skip', err, raw ? this.state.rawBuffer.toString(encoding) : undefined);
return undefined;
@@ -2062,10 +2070,13 @@ const parse = function (data, opts = {}) {
}
};
const close = () => {};
- const err1 = parser.parse(data, false, push, close);
- if (err1 !== undefined) throw err1;
- const err2 = parser.parse(undefined, true, push, close);
- if (err2 !== undefined) throw err2;
+ const error = parser.parse(data, true, push, close);
+ if (error !== undefined) throw error;
+ // 250606: `parser.parse` was implemented as 2 calls:
+ // const err1 = parser.parse(data, false, push, close);
+ // if (err1 !== undefined) throw err1;
+ // const err2 = parser.parse(undefined, true, push, close);
+ // if (err2 !== undefined) throw err2;
return records;
};
@@ -2094,6 +2105,7 @@ const reIsDeepProp = /\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/;
const reIsPlainProp = /^\w*$/;
const getTag = function (value) {
+ // if (!value) value === undefined ? "[object Undefined]" : "[object Null]";
return Object.prototype.toString.call(value);
};
diff --git a/packages/csv/dist/cjs/sync.d.cts b/packages/csv/dist/cjs/sync.d.cts
index b1812592d..8bdf6763f 100644
--- a/packages/csv/dist/cjs/sync.d.cts
+++ b/packages/csv/dist/cjs/sync.d.cts
@@ -1,14 +1,13 @@
-
// Alias to the modules exposing the sync APIs
-import { generate } from 'csv-generate/sync'
-import { parse } from 'csv-parse/sync';
-import { transform } from 'stream-transform/sync';
-import { stringify } from 'csv-stringify/sync';
+import { generate } from "csv-generate/sync";
+import { parse } from "csv-parse/sync";
+import { transform } from "stream-transform/sync";
+import { stringify } from "csv-stringify/sync";
-export { generate, parse, transform, stringify }
+export { generate, parse, transform, stringify };
-export * as generator from 'csv-generate/sync';
-export * as parser from 'csv-parse/sync';
-export * as transformer from 'stream-transform/sync';
-export * as stringifier from 'csv-stringify/sync';
+export * as generator from "csv-generate/sync";
+export * as parser from "csv-parse/sync";
+export * as transformer from "stream-transform/sync";
+export * as stringifier from "csv-stringify/sync";
diff --git a/packages/csv/dist/esm/index.d.ts b/packages/csv/dist/esm/index.d.ts
index c9770f8df..9dc9a1ee7 100644
--- a/packages/csv/dist/esm/index.d.ts
+++ b/packages/csv/dist/esm/index.d.ts
@@ -1,14 +1,13 @@
-
// Alias to the modules exposing the stream and callback APIs
-import { generate } from 'csv-generate';
-import { parse } from 'csv-parse';
-import { transform } from 'stream-transform';
-import { stringify } from 'csv-stringify';
+import { generate } from "csv-generate";
+import { parse } from "csv-parse";
+import { transform } from "stream-transform";
+import { stringify } from "csv-stringify";
export { generate, parse, transform, stringify };
-export * as generator from 'csv-generate';
-export * as parser from 'csv-parse';
-export * as transformer from 'stream-transform';
-export * as stringifier from 'csv-stringify';
+export * as generator from "csv-generate";
+export * as parser from "csv-parse";
+export * as transformer from "stream-transform";
+export * as stringifier from "csv-stringify";
diff --git a/packages/csv/dist/esm/index.js b/packages/csv/dist/esm/index.js
index 93a5b12ff..3c7b1f8a3 100644
--- a/packages/csv/dist/esm/index.js
+++ b/packages/csv/dist/esm/index.js
@@ -831,8 +831,8 @@ function bidirectionalIndexOf (buffer, val, byteOffset, encoding, dir) {
byteOffset = 0;
} else if (byteOffset > 0x7fffffff) {
byteOffset = 0x7fffffff;
- } else if (byteOffset < -0x80000000) {
- byteOffset = -0x80000000;
+ } else if (byteOffset < -2147483648) {
+ byteOffset = -2147483648;
}
byteOffset = +byteOffset; // Coerce to Number.
if (isNaN(byteOffset)) {
@@ -1591,7 +1591,7 @@ Buffer.prototype.writeIntBE = function writeIntBE (value, offset, byteLength, no
Buffer.prototype.writeInt8 = function writeInt8 (value, offset, noAssert) {
value = +value;
offset = offset | 0;
- if (!noAssert) checkInt(this, value, offset, 1, 0x7f, -0x80);
+ if (!noAssert) checkInt(this, value, offset, 1, 0x7f, -128);
if (!Buffer.TYPED_ARRAY_SUPPORT) value = Math.floor(value);
if (value < 0) value = 0xff + value + 1;
this[offset] = (value & 0xff);
@@ -1601,7 +1601,7 @@ Buffer.prototype.writeInt8 = function writeInt8 (value, offset, noAssert) {
Buffer.prototype.writeInt16LE = function writeInt16LE (value, offset, noAssert) {
value = +value;
offset = offset | 0;
- if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000);
+ if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -32768);
if (Buffer.TYPED_ARRAY_SUPPORT) {
this[offset] = (value & 0xff);
this[offset + 1] = (value >>> 8);
@@ -1614,7 +1614,7 @@ Buffer.prototype.writeInt16LE = function writeInt16LE (value, offset, noAssert)
Buffer.prototype.writeInt16BE = function writeInt16BE (value, offset, noAssert) {
value = +value;
offset = offset | 0;
- if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000);
+ if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -32768);
if (Buffer.TYPED_ARRAY_SUPPORT) {
this[offset] = (value >>> 8);
this[offset + 1] = (value & 0xff);
@@ -1627,7 +1627,7 @@ Buffer.prototype.writeInt16BE = function writeInt16BE (value, offset, noAssert)
Buffer.prototype.writeInt32LE = function writeInt32LE (value, offset, noAssert) {
value = +value;
offset = offset | 0;
- if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000);
+ if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -2147483648);
if (Buffer.TYPED_ARRAY_SUPPORT) {
this[offset] = (value & 0xff);
this[offset + 1] = (value >>> 8);
@@ -1642,7 +1642,7 @@ Buffer.prototype.writeInt32LE = function writeInt32LE (value, offset, noAssert)
Buffer.prototype.writeInt32BE = function writeInt32BE (value, offset, noAssert) {
value = +value;
offset = offset | 0;
- if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000);
+ if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -2147483648);
if (value < 0) value = 0xffffffff + value + 1;
if (Buffer.TYPED_ARRAY_SUPPORT) {
this[offset] = (value >>> 24);
@@ -2000,7 +2000,9 @@ EventEmitter.init = function() {
this.domain = null;
if (EventEmitter.usingDomains) {
// if there is an active domain, then attach to it.
- if (domain.active) ;
+ if (domain.active && !(this instanceof domain.Domain)) {
+ this.domain = domain.active;
+ }
}
if (!this._events || this._events === Object.getPrototypeOf(this)._events) {
@@ -2569,94 +2571,19 @@ function Item(fun, array) {
Item.prototype.run = function () {
this.fun.apply(null, this.array);
};
-var title = 'browser';
-var platform = 'browser';
-var browser = true;
var env = {};
-var argv = [];
-var version = ''; // empty string to avoid regexp issues
-var versions = {};
-var release = {};
-var config = {};
-
-function noop() {}
-
-var on = noop;
-var addListener = noop;
-var once = noop;
-var off = noop;
-var removeListener = noop;
-var removeAllListeners = noop;
-var emit = noop;
-
-function binding(name) {
- throw new Error('process.binding is not supported');
-}
-
-function cwd () { return '/' }
-function chdir (dir) {
- throw new Error('process.chdir is not supported');
-}function umask() { return 0; }
// from https://github.com/kumavis/browser-process-hrtime/blob/master/index.js
var performance = global$1.performance || {};
-var performanceNow =
- performance.now ||
+performance.now ||
performance.mozNow ||
performance.msNow ||
performance.oNow ||
performance.webkitNow ||
function(){ return (new Date()).getTime() };
-// generate timestamp or delta
-// see http://nodejs.org/api/process.html#process_process_hrtime
-function hrtime(previousTimestamp){
- var clocktime = performanceNow.call(performance)*1e-3;
- var seconds = Math.floor(clocktime);
- var nanoseconds = Math.floor((clocktime%1)*1e9);
- if (previousTimestamp) {
- seconds = seconds - previousTimestamp[0];
- nanoseconds = nanoseconds - previousTimestamp[1];
- if (nanoseconds<0) {
- seconds--;
- nanoseconds += 1e9;
- }
- }
- return [seconds,nanoseconds]
-}
-
-var startTime = new Date();
-function uptime() {
- var currentTime = new Date();
- var dif = currentTime - startTime;
- return dif / 1000;
-}
-
var process = {
- nextTick: nextTick,
- title: title,
- browser: browser,
- env: env,
- argv: argv,
- version: version,
- versions: versions,
- on: on,
- addListener: addListener,
- once: once,
- off: off,
- removeListener: removeListener,
- removeAllListeners: removeAllListeners,
- emit: emit,
- binding: binding,
- cwd: cwd,
- chdir: chdir,
- umask: umask,
- hrtime: hrtime,
- platform: platform,
- release: release,
- config: config,
- uptime: uptime
-};
+ env: env};
var inherits;
if (typeof Object.create === 'function'){
@@ -5762,7 +5689,7 @@ const normalize_options$1 = function (opts) {
);
}
// Normalize option `columns`
- options.cast_first_line_to_header = null;
+ options.cast_first_line_to_header = undefined;
if (options.columns === true) {
// Fields in the first line are converted as-is to columns
options.cast_first_line_to_header = undefined;
@@ -6294,7 +6221,7 @@ const normalize_options$1 = function (opts) {
// Normalize option `to`
if (options.to === undefined || options.to === null) {
options.to = -1;
- } else {
+ } else if (options.to !== -1) {
if (typeof options.to === "string" && /\d+/.test(options.to)) {
options.to = parseInt(options.to);
}
@@ -6313,7 +6240,7 @@ const normalize_options$1 = function (opts) {
// Normalize option `to_line`
if (options.to_line === undefined || options.to_line === null) {
options.to_line = -1;
- } else {
+ } else if (options.to_line !== -1) {
if (typeof options.to_line === "string" && /\d+/.test(options.to_line)) {
options.to_line = parseInt(options.to_line);
}
@@ -6444,10 +6371,14 @@ const transform$1 = function (original_options = {}) {
this.state.bufBytesStart += bomLength;
buf = buf.slice(bomLength);
// Renormalize original options with the new encoding
- this.options = normalize_options$1({
+ const options = normalize_options$1({
...this.original_options,
encoding: encoding,
});
+ // Properties are merged with the existing options instance
+ for (const key in options) {
+ this.options[key] = options[key];
+ }
// Options will re-evaluate the Buffer with the new encoding
({ comment, escape, quote } = this.options);
break;
@@ -7190,10 +7121,14 @@ const transform$1 = function (original_options = {}) {
if (skip_records_with_error) {
this.state.recordHasError = true;
if (this.options.on_skip !== undefined) {
- this.options.on_skip(
- err,
- raw ? this.state.rawBuffer.toString(encoding) : undefined,
- );
+ try {
+ this.options.on_skip(
+ err,
+ raw ? this.state.rawBuffer.toString(encoding) : undefined,
+ );
+ } catch (err) {
+ return err;
+ }
}
// this.emit('skip', err, raw ? this.state.rawBuffer.toString(encoding) : undefined);
return undefined;
@@ -7577,6 +7512,7 @@ const reIsDeepProp = /\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/;
const reIsPlainProp = /^\w*$/;
const getTag = function (value) {
+ // if (!value) value === undefined ? "[object Undefined]" : "[object Null]";
return Object.prototype.toString.call(value);
};
diff --git a/packages/csv/dist/esm/sync.d.ts b/packages/csv/dist/esm/sync.d.ts
index b1812592d..8bdf6763f 100644
--- a/packages/csv/dist/esm/sync.d.ts
+++ b/packages/csv/dist/esm/sync.d.ts
@@ -1,14 +1,13 @@
-
// Alias to the modules exposing the sync APIs
-import { generate } from 'csv-generate/sync'
-import { parse } from 'csv-parse/sync';
-import { transform } from 'stream-transform/sync';
-import { stringify } from 'csv-stringify/sync';
+import { generate } from "csv-generate/sync";
+import { parse } from "csv-parse/sync";
+import { transform } from "stream-transform/sync";
+import { stringify } from "csv-stringify/sync";
-export { generate, parse, transform, stringify }
+export { generate, parse, transform, stringify };
-export * as generator from 'csv-generate/sync';
-export * as parser from 'csv-parse/sync';
-export * as transformer from 'stream-transform/sync';
-export * as stringifier from 'csv-stringify/sync';
+export * as generator from "csv-generate/sync";
+export * as parser from "csv-parse/sync";
+export * as transformer from "stream-transform/sync";
+export * as stringifier from "csv-stringify/sync";
diff --git a/packages/csv/dist/esm/sync.js b/packages/csv/dist/esm/sync.js
index efc0e6d38..d49b9aca4 100644
--- a/packages/csv/dist/esm/sync.js
+++ b/packages/csv/dist/esm/sync.js
@@ -831,8 +831,8 @@ function bidirectionalIndexOf (buffer, val, byteOffset, encoding, dir) {
byteOffset = 0;
} else if (byteOffset > 0x7fffffff) {
byteOffset = 0x7fffffff;
- } else if (byteOffset < -0x80000000) {
- byteOffset = -0x80000000;
+ } else if (byteOffset < -2147483648) {
+ byteOffset = -2147483648;
}
byteOffset = +byteOffset; // Coerce to Number.
if (isNaN(byteOffset)) {
@@ -1591,7 +1591,7 @@ Buffer.prototype.writeIntBE = function writeIntBE (value, offset, byteLength, no
Buffer.prototype.writeInt8 = function writeInt8 (value, offset, noAssert) {
value = +value;
offset = offset | 0;
- if (!noAssert) checkInt(this, value, offset, 1, 0x7f, -0x80);
+ if (!noAssert) checkInt(this, value, offset, 1, 0x7f, -128);
if (!Buffer.TYPED_ARRAY_SUPPORT) value = Math.floor(value);
if (value < 0) value = 0xff + value + 1;
this[offset] = (value & 0xff);
@@ -1601,7 +1601,7 @@ Buffer.prototype.writeInt8 = function writeInt8 (value, offset, noAssert) {
Buffer.prototype.writeInt16LE = function writeInt16LE (value, offset, noAssert) {
value = +value;
offset = offset | 0;
- if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000);
+ if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -32768);
if (Buffer.TYPED_ARRAY_SUPPORT) {
this[offset] = (value & 0xff);
this[offset + 1] = (value >>> 8);
@@ -1614,7 +1614,7 @@ Buffer.prototype.writeInt16LE = function writeInt16LE (value, offset, noAssert)
Buffer.prototype.writeInt16BE = function writeInt16BE (value, offset, noAssert) {
value = +value;
offset = offset | 0;
- if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000);
+ if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -32768);
if (Buffer.TYPED_ARRAY_SUPPORT) {
this[offset] = (value >>> 8);
this[offset + 1] = (value & 0xff);
@@ -1627,7 +1627,7 @@ Buffer.prototype.writeInt16BE = function writeInt16BE (value, offset, noAssert)
Buffer.prototype.writeInt32LE = function writeInt32LE (value, offset, noAssert) {
value = +value;
offset = offset | 0;
- if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000);
+ if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -2147483648);
if (Buffer.TYPED_ARRAY_SUPPORT) {
this[offset] = (value & 0xff);
this[offset + 1] = (value >>> 8);
@@ -1642,7 +1642,7 @@ Buffer.prototype.writeInt32LE = function writeInt32LE (value, offset, noAssert)
Buffer.prototype.writeInt32BE = function writeInt32BE (value, offset, noAssert) {
value = +value;
offset = offset | 0;
- if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000);
+ if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -2147483648);
if (value < 0) value = 0xffffffff + value + 1;
if (Buffer.TYPED_ARRAY_SUPPORT) {
this[offset] = (value >>> 24);
@@ -2000,7 +2000,9 @@ EventEmitter.init = function() {
this.domain = null;
if (EventEmitter.usingDomains) {
// if there is an active domain, then attach to it.
- if (domain.active) ;
+ if (domain.active && !(this instanceof domain.Domain)) {
+ this.domain = domain.active;
+ }
}
if (!this._events || this._events === Object.getPrototypeOf(this)._events) {
@@ -2569,94 +2571,19 @@ function Item(fun, array) {
Item.prototype.run = function () {
this.fun.apply(null, this.array);
};
-var title = 'browser';
-var platform = 'browser';
-var browser = true;
var env = {};
-var argv = [];
-var version = ''; // empty string to avoid regexp issues
-var versions = {};
-var release = {};
-var config = {};
-
-function noop() {}
-
-var on = noop;
-var addListener = noop;
-var once = noop;
-var off = noop;
-var removeListener = noop;
-var removeAllListeners = noop;
-var emit = noop;
-
-function binding(name) {
- throw new Error('process.binding is not supported');
-}
-
-function cwd () { return '/' }
-function chdir (dir) {
- throw new Error('process.chdir is not supported');
-}function umask() { return 0; }
// from https://github.com/kumavis/browser-process-hrtime/blob/master/index.js
var performance = global$1.performance || {};
-var performanceNow =
- performance.now ||
+performance.now ||
performance.mozNow ||
performance.msNow ||
performance.oNow ||
performance.webkitNow ||
function(){ return (new Date()).getTime() };
-// generate timestamp or delta
-// see http://nodejs.org/api/process.html#process_process_hrtime
-function hrtime(previousTimestamp){
- var clocktime = performanceNow.call(performance)*1e-3;
- var seconds = Math.floor(clocktime);
- var nanoseconds = Math.floor((clocktime%1)*1e9);
- if (previousTimestamp) {
- seconds = seconds - previousTimestamp[0];
- nanoseconds = nanoseconds - previousTimestamp[1];
- if (nanoseconds<0) {
- seconds--;
- nanoseconds += 1e9;
- }
- }
- return [seconds,nanoseconds]
-}
-
-var startTime = new Date();
-function uptime() {
- var currentTime = new Date();
- var dif = currentTime - startTime;
- return dif / 1000;
-}
-
var process = {
- nextTick: nextTick,
- title: title,
- browser: browser,
- env: env,
- argv: argv,
- version: version,
- versions: versions,
- on: on,
- addListener: addListener,
- once: once,
- off: off,
- removeListener: removeListener,
- removeAllListeners: removeAllListeners,
- emit: emit,
- binding: binding,
- cwd: cwd,
- chdir: chdir,
- umask: umask,
- hrtime: hrtime,
- platform: platform,
- release: release,
- config: config,
- uptime: uptime
-};
+ env: env};
var inherits;
if (typeof Object.create === 'function'){
@@ -5760,7 +5687,7 @@ const normalize_options$1 = function (opts) {
);
}
// Normalize option `columns`
- options.cast_first_line_to_header = null;
+ options.cast_first_line_to_header = undefined;
if (options.columns === true) {
// Fields in the first line are converted as-is to columns
options.cast_first_line_to_header = undefined;
@@ -6292,7 +6219,7 @@ const normalize_options$1 = function (opts) {
// Normalize option `to`
if (options.to === undefined || options.to === null) {
options.to = -1;
- } else {
+ } else if (options.to !== -1) {
if (typeof options.to === "string" && /\d+/.test(options.to)) {
options.to = parseInt(options.to);
}
@@ -6311,7 +6238,7 @@ const normalize_options$1 = function (opts) {
// Normalize option `to_line`
if (options.to_line === undefined || options.to_line === null) {
options.to_line = -1;
- } else {
+ } else if (options.to_line !== -1) {
if (typeof options.to_line === "string" && /\d+/.test(options.to_line)) {
options.to_line = parseInt(options.to_line);
}
@@ -6442,10 +6369,14 @@ const transform$1 = function (original_options = {}) {
this.state.bufBytesStart += bomLength;
buf = buf.slice(bomLength);
// Renormalize original options with the new encoding
- this.options = normalize_options$1({
+ const options = normalize_options$1({
...this.original_options,
encoding: encoding,
});
+ // Properties are merged with the existing options instance
+ for (const key in options) {
+ this.options[key] = options[key];
+ }
// Options will re-evaluate the Buffer with the new encoding
({ comment, escape, quote } = this.options);
break;
@@ -7188,10 +7119,14 @@ const transform$1 = function (original_options = {}) {
if (skip_records_with_error) {
this.state.recordHasError = true;
if (this.options.on_skip !== undefined) {
- this.options.on_skip(
- err,
- raw ? this.state.rawBuffer.toString(encoding) : undefined,
- );
+ try {
+ this.options.on_skip(
+ err,
+ raw ? this.state.rawBuffer.toString(encoding) : undefined,
+ );
+ } catch (err) {
+ return err;
+ }
}
// this.emit('skip', err, raw ? this.state.rawBuffer.toString(encoding) : undefined);
return undefined;
@@ -7245,10 +7180,13 @@ const parse = function (data, opts = {}) {
}
};
const close = () => {};
- const err1 = parser.parse(data, false, push, close);
- if (err1 !== undefined) throw err1;
- const err2 = parser.parse(undefined, true, push, close);
- if (err2 !== undefined) throw err2;
+ const error = parser.parse(data, true, push, close);
+ if (error !== undefined) throw error;
+ // 250606: `parser.parse` was implemented as 2 calls:
+ // const err1 = parser.parse(data, false, push, close);
+ // if (err1 !== undefined) throw err1;
+ // const err2 = parser.parse(undefined, true, push, close);
+ // if (err2 !== undefined) throw err2;
return records;
};
@@ -7277,6 +7215,7 @@ const reIsDeepProp = /\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/;
const reIsPlainProp = /^\w*$/;
const getTag = function (value) {
+ // if (!value) value === undefined ? "[object Undefined]" : "[object Null]";
return Object.prototype.toString.call(value);
};
diff --git a/packages/csv/dist/iife/index.js b/packages/csv/dist/iife/index.js
index 3665e7439..c06182ad4 100644
--- a/packages/csv/dist/iife/index.js
+++ b/packages/csv/dist/iife/index.js
@@ -834,8 +834,8 @@ var csv = (function (exports) {
byteOffset = 0;
} else if (byteOffset > 0x7fffffff) {
byteOffset = 0x7fffffff;
- } else if (byteOffset < -0x80000000) {
- byteOffset = -0x80000000;
+ } else if (byteOffset < -2147483648) {
+ byteOffset = -2147483648;
}
byteOffset = +byteOffset; // Coerce to Number.
if (isNaN(byteOffset)) {
@@ -1594,7 +1594,7 @@ var csv = (function (exports) {
Buffer.prototype.writeInt8 = function writeInt8 (value, offset, noAssert) {
value = +value;
offset = offset | 0;
- if (!noAssert) checkInt(this, value, offset, 1, 0x7f, -0x80);
+ if (!noAssert) checkInt(this, value, offset, 1, 0x7f, -128);
if (!Buffer.TYPED_ARRAY_SUPPORT) value = Math.floor(value);
if (value < 0) value = 0xff + value + 1;
this[offset] = (value & 0xff);
@@ -1604,7 +1604,7 @@ var csv = (function (exports) {
Buffer.prototype.writeInt16LE = function writeInt16LE (value, offset, noAssert) {
value = +value;
offset = offset | 0;
- if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000);
+ if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -32768);
if (Buffer.TYPED_ARRAY_SUPPORT) {
this[offset] = (value & 0xff);
this[offset + 1] = (value >>> 8);
@@ -1617,7 +1617,7 @@ var csv = (function (exports) {
Buffer.prototype.writeInt16BE = function writeInt16BE (value, offset, noAssert) {
value = +value;
offset = offset | 0;
- if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000);
+ if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -32768);
if (Buffer.TYPED_ARRAY_SUPPORT) {
this[offset] = (value >>> 8);
this[offset + 1] = (value & 0xff);
@@ -1630,7 +1630,7 @@ var csv = (function (exports) {
Buffer.prototype.writeInt32LE = function writeInt32LE (value, offset, noAssert) {
value = +value;
offset = offset | 0;
- if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000);
+ if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -2147483648);
if (Buffer.TYPED_ARRAY_SUPPORT) {
this[offset] = (value & 0xff);
this[offset + 1] = (value >>> 8);
@@ -1645,7 +1645,7 @@ var csv = (function (exports) {
Buffer.prototype.writeInt32BE = function writeInt32BE (value, offset, noAssert) {
value = +value;
offset = offset | 0;
- if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000);
+ if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -2147483648);
if (value < 0) value = 0xffffffff + value + 1;
if (Buffer.TYPED_ARRAY_SUPPORT) {
this[offset] = (value >>> 24);
@@ -2003,7 +2003,9 @@ var csv = (function (exports) {
this.domain = null;
if (EventEmitter.usingDomains) {
// if there is an active domain, then attach to it.
- if (domain.active) ;
+ if (domain.active && !(this instanceof domain.Domain)) {
+ this.domain = domain.active;
+ }
}
if (!this._events || this._events === Object.getPrototypeOf(this)._events) {
@@ -2572,94 +2574,19 @@ var csv = (function (exports) {
Item.prototype.run = function () {
this.fun.apply(null, this.array);
};
- var title = 'browser';
- var platform = 'browser';
- var browser = true;
var env = {};
- var argv = [];
- var version = ''; // empty string to avoid regexp issues
- var versions = {};
- var release = {};
- var config = {};
-
- function noop() {}
-
- var on = noop;
- var addListener = noop;
- var once = noop;
- var off = noop;
- var removeListener = noop;
- var removeAllListeners = noop;
- var emit = noop;
-
- function binding(name) {
- throw new Error('process.binding is not supported');
- }
-
- function cwd () { return '/' }
- function chdir (dir) {
- throw new Error('process.chdir is not supported');
- }function umask() { return 0; }
// from https://github.com/kumavis/browser-process-hrtime/blob/master/index.js
var performance = global$1.performance || {};
- var performanceNow =
- performance.now ||
+ performance.now ||
performance.mozNow ||
performance.msNow ||
performance.oNow ||
performance.webkitNow ||
function(){ return (new Date()).getTime() };
- // generate timestamp or delta
- // see http://nodejs.org/api/process.html#process_process_hrtime
- function hrtime(previousTimestamp){
- var clocktime = performanceNow.call(performance)*1e-3;
- var seconds = Math.floor(clocktime);
- var nanoseconds = Math.floor((clocktime%1)*1e9);
- if (previousTimestamp) {
- seconds = seconds - previousTimestamp[0];
- nanoseconds = nanoseconds - previousTimestamp[1];
- if (nanoseconds<0) {
- seconds--;
- nanoseconds += 1e9;
- }
- }
- return [seconds,nanoseconds]
- }
-
- var startTime = new Date();
- function uptime() {
- var currentTime = new Date();
- var dif = currentTime - startTime;
- return dif / 1000;
- }
-
var process = {
- nextTick: nextTick,
- title: title,
- browser: browser,
- env: env,
- argv: argv,
- version: version,
- versions: versions,
- on: on,
- addListener: addListener,
- once: once,
- off: off,
- removeListener: removeListener,
- removeAllListeners: removeAllListeners,
- emit: emit,
- binding: binding,
- cwd: cwd,
- chdir: chdir,
- umask: umask,
- hrtime: hrtime,
- platform: platform,
- release: release,
- config: config,
- uptime: uptime
- };
+ env: env};
var inherits;
if (typeof Object.create === 'function'){
@@ -5765,7 +5692,7 @@ var csv = (function (exports) {
);
}
// Normalize option `columns`
- options.cast_first_line_to_header = null;
+ options.cast_first_line_to_header = undefined;
if (options.columns === true) {
// Fields in the first line are converted as-is to columns
options.cast_first_line_to_header = undefined;
@@ -6297,7 +6224,7 @@ var csv = (function (exports) {
// Normalize option `to`
if (options.to === undefined || options.to === null) {
options.to = -1;
- } else {
+ } else if (options.to !== -1) {
if (typeof options.to === "string" && /\d+/.test(options.to)) {
options.to = parseInt(options.to);
}
@@ -6316,7 +6243,7 @@ var csv = (function (exports) {
// Normalize option `to_line`
if (options.to_line === undefined || options.to_line === null) {
options.to_line = -1;
- } else {
+ } else if (options.to_line !== -1) {
if (typeof options.to_line === "string" && /\d+/.test(options.to_line)) {
options.to_line = parseInt(options.to_line);
}
@@ -6447,10 +6374,14 @@ var csv = (function (exports) {
this.state.bufBytesStart += bomLength;
buf = buf.slice(bomLength);
// Renormalize original options with the new encoding
- this.options = normalize_options$1({
+ const options = normalize_options$1({
...this.original_options,
encoding: encoding,
});
+ // Properties are merged with the existing options instance
+ for (const key in options) {
+ this.options[key] = options[key];
+ }
// Options will re-evaluate the Buffer with the new encoding
({ comment, escape, quote } = this.options);
break;
@@ -7193,10 +7124,14 @@ var csv = (function (exports) {
if (skip_records_with_error) {
this.state.recordHasError = true;
if (this.options.on_skip !== undefined) {
- this.options.on_skip(
- err,
- raw ? this.state.rawBuffer.toString(encoding) : undefined,
- );
+ try {
+ this.options.on_skip(
+ err,
+ raw ? this.state.rawBuffer.toString(encoding) : undefined,
+ );
+ } catch (err) {
+ return err;
+ }
}
// this.emit('skip', err, raw ? this.state.rawBuffer.toString(encoding) : undefined);
return undefined;
@@ -7580,6 +7515,7 @@ var csv = (function (exports) {
const reIsPlainProp = /^\w*$/;
const getTag = function (value) {
+ // if (!value) value === undefined ? "[object Undefined]" : "[object Null]";
return Object.prototype.toString.call(value);
};
diff --git a/packages/csv/dist/iife/sync.js b/packages/csv/dist/iife/sync.js
index 30438d4f8..b856d5f29 100644
--- a/packages/csv/dist/iife/sync.js
+++ b/packages/csv/dist/iife/sync.js
@@ -834,8 +834,8 @@ var csv_sync = (function (exports) {
byteOffset = 0;
} else if (byteOffset > 0x7fffffff) {
byteOffset = 0x7fffffff;
- } else if (byteOffset < -0x80000000) {
- byteOffset = -0x80000000;
+ } else if (byteOffset < -2147483648) {
+ byteOffset = -2147483648;
}
byteOffset = +byteOffset; // Coerce to Number.
if (isNaN(byteOffset)) {
@@ -1594,7 +1594,7 @@ var csv_sync = (function (exports) {
Buffer.prototype.writeInt8 = function writeInt8 (value, offset, noAssert) {
value = +value;
offset = offset | 0;
- if (!noAssert) checkInt(this, value, offset, 1, 0x7f, -0x80);
+ if (!noAssert) checkInt(this, value, offset, 1, 0x7f, -128);
if (!Buffer.TYPED_ARRAY_SUPPORT) value = Math.floor(value);
if (value < 0) value = 0xff + value + 1;
this[offset] = (value & 0xff);
@@ -1604,7 +1604,7 @@ var csv_sync = (function (exports) {
Buffer.prototype.writeInt16LE = function writeInt16LE (value, offset, noAssert) {
value = +value;
offset = offset | 0;
- if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000);
+ if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -32768);
if (Buffer.TYPED_ARRAY_SUPPORT) {
this[offset] = (value & 0xff);
this[offset + 1] = (value >>> 8);
@@ -1617,7 +1617,7 @@ var csv_sync = (function (exports) {
Buffer.prototype.writeInt16BE = function writeInt16BE (value, offset, noAssert) {
value = +value;
offset = offset | 0;
- if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000);
+ if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -32768);
if (Buffer.TYPED_ARRAY_SUPPORT) {
this[offset] = (value >>> 8);
this[offset + 1] = (value & 0xff);
@@ -1630,7 +1630,7 @@ var csv_sync = (function (exports) {
Buffer.prototype.writeInt32LE = function writeInt32LE (value, offset, noAssert) {
value = +value;
offset = offset | 0;
- if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000);
+ if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -2147483648);
if (Buffer.TYPED_ARRAY_SUPPORT) {
this[offset] = (value & 0xff);
this[offset + 1] = (value >>> 8);
@@ -1645,7 +1645,7 @@ var csv_sync = (function (exports) {
Buffer.prototype.writeInt32BE = function writeInt32BE (value, offset, noAssert) {
value = +value;
offset = offset | 0;
- if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000);
+ if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -2147483648);
if (value < 0) value = 0xffffffff + value + 1;
if (Buffer.TYPED_ARRAY_SUPPORT) {
this[offset] = (value >>> 24);
@@ -2003,7 +2003,9 @@ var csv_sync = (function (exports) {
this.domain = null;
if (EventEmitter.usingDomains) {
// if there is an active domain, then attach to it.
- if (domain.active) ;
+ if (domain.active && !(this instanceof domain.Domain)) {
+ this.domain = domain.active;
+ }
}
if (!this._events || this._events === Object.getPrototypeOf(this)._events) {
@@ -2572,94 +2574,19 @@ var csv_sync = (function (exports) {
Item.prototype.run = function () {
this.fun.apply(null, this.array);
};
- var title = 'browser';
- var platform = 'browser';
- var browser = true;
var env = {};
- var argv = [];
- var version = ''; // empty string to avoid regexp issues
- var versions = {};
- var release = {};
- var config = {};
-
- function noop() {}
-
- var on = noop;
- var addListener = noop;
- var once = noop;
- var off = noop;
- var removeListener = noop;
- var removeAllListeners = noop;
- var emit = noop;
-
- function binding(name) {
- throw new Error('process.binding is not supported');
- }
-
- function cwd () { return '/' }
- function chdir (dir) {
- throw new Error('process.chdir is not supported');
- }function umask() { return 0; }
// from https://github.com/kumavis/browser-process-hrtime/blob/master/index.js
var performance = global$1.performance || {};
- var performanceNow =
- performance.now ||
+ performance.now ||
performance.mozNow ||
performance.msNow ||
performance.oNow ||
performance.webkitNow ||
function(){ return (new Date()).getTime() };
- // generate timestamp or delta
- // see http://nodejs.org/api/process.html#process_process_hrtime
- function hrtime(previousTimestamp){
- var clocktime = performanceNow.call(performance)*1e-3;
- var seconds = Math.floor(clocktime);
- var nanoseconds = Math.floor((clocktime%1)*1e9);
- if (previousTimestamp) {
- seconds = seconds - previousTimestamp[0];
- nanoseconds = nanoseconds - previousTimestamp[1];
- if (nanoseconds<0) {
- seconds--;
- nanoseconds += 1e9;
- }
- }
- return [seconds,nanoseconds]
- }
-
- var startTime = new Date();
- function uptime() {
- var currentTime = new Date();
- var dif = currentTime - startTime;
- return dif / 1000;
- }
-
var process = {
- nextTick: nextTick,
- title: title,
- browser: browser,
- env: env,
- argv: argv,
- version: version,
- versions: versions,
- on: on,
- addListener: addListener,
- once: once,
- off: off,
- removeListener: removeListener,
- removeAllListeners: removeAllListeners,
- emit: emit,
- binding: binding,
- cwd: cwd,
- chdir: chdir,
- umask: umask,
- hrtime: hrtime,
- platform: platform,
- release: release,
- config: config,
- uptime: uptime
- };
+ env: env};
var inherits;
if (typeof Object.create === 'function'){
@@ -5763,7 +5690,7 @@ var csv_sync = (function (exports) {
);
}
// Normalize option `columns`
- options.cast_first_line_to_header = null;
+ options.cast_first_line_to_header = undefined;
if (options.columns === true) {
// Fields in the first line are converted as-is to columns
options.cast_first_line_to_header = undefined;
@@ -6295,7 +6222,7 @@ var csv_sync = (function (exports) {
// Normalize option `to`
if (options.to === undefined || options.to === null) {
options.to = -1;
- } else {
+ } else if (options.to !== -1) {
if (typeof options.to === "string" && /\d+/.test(options.to)) {
options.to = parseInt(options.to);
}
@@ -6314,7 +6241,7 @@ var csv_sync = (function (exports) {
// Normalize option `to_line`
if (options.to_line === undefined || options.to_line === null) {
options.to_line = -1;
- } else {
+ } else if (options.to_line !== -1) {
if (typeof options.to_line === "string" && /\d+/.test(options.to_line)) {
options.to_line = parseInt(options.to_line);
}
@@ -6445,10 +6372,14 @@ var csv_sync = (function (exports) {
this.state.bufBytesStart += bomLength;
buf = buf.slice(bomLength);
// Renormalize original options with the new encoding
- this.options = normalize_options$1({
+ const options = normalize_options$1({
...this.original_options,
encoding: encoding,
});
+ // Properties are merged with the existing options instance
+ for (const key in options) {
+ this.options[key] = options[key];
+ }
// Options will re-evaluate the Buffer with the new encoding
({ comment, escape, quote } = this.options);
break;
@@ -7191,10 +7122,14 @@ var csv_sync = (function (exports) {
if (skip_records_with_error) {
this.state.recordHasError = true;
if (this.options.on_skip !== undefined) {
- this.options.on_skip(
- err,
- raw ? this.state.rawBuffer.toString(encoding) : undefined,
- );
+ try {
+ this.options.on_skip(
+ err,
+ raw ? this.state.rawBuffer.toString(encoding) : undefined,
+ );
+ } catch (err) {
+ return err;
+ }
}
// this.emit('skip', err, raw ? this.state.rawBuffer.toString(encoding) : undefined);
return undefined;
@@ -7248,10 +7183,13 @@ var csv_sync = (function (exports) {
}
};
const close = () => {};
- const err1 = parser.parse(data, false, push, close);
- if (err1 !== undefined) throw err1;
- const err2 = parser.parse(undefined, true, push, close);
- if (err2 !== undefined) throw err2;
+ const error = parser.parse(data, true, push, close);
+ if (error !== undefined) throw error;
+ // 250606: `parser.parse` was implemented as 2 calls:
+ // const err1 = parser.parse(data, false, push, close);
+ // if (err1 !== undefined) throw err1;
+ // const err2 = parser.parse(undefined, true, push, close);
+ // if (err2 !== undefined) throw err2;
return records;
};
@@ -7280,6 +7218,7 @@ var csv_sync = (function (exports) {
const reIsPlainProp = /^\w*$/;
const getTag = function (value) {
+ // if (!value) value === undefined ? "[object Undefined]" : "[object Null]";
return Object.prototype.toString.call(value);
};
diff --git a/packages/csv/dist/umd/index.js b/packages/csv/dist/umd/index.js
index f20f7f8ee..a9cc1bd73 100644
--- a/packages/csv/dist/umd/index.js
+++ b/packages/csv/dist/umd/index.js
@@ -837,8 +837,8 @@
byteOffset = 0;
} else if (byteOffset > 0x7fffffff) {
byteOffset = 0x7fffffff;
- } else if (byteOffset < -0x80000000) {
- byteOffset = -0x80000000;
+ } else if (byteOffset < -2147483648) {
+ byteOffset = -2147483648;
}
byteOffset = +byteOffset; // Coerce to Number.
if (isNaN(byteOffset)) {
@@ -1597,7 +1597,7 @@
Buffer.prototype.writeInt8 = function writeInt8 (value, offset, noAssert) {
value = +value;
offset = offset | 0;
- if (!noAssert) checkInt(this, value, offset, 1, 0x7f, -0x80);
+ if (!noAssert) checkInt(this, value, offset, 1, 0x7f, -128);
if (!Buffer.TYPED_ARRAY_SUPPORT) value = Math.floor(value);
if (value < 0) value = 0xff + value + 1;
this[offset] = (value & 0xff);
@@ -1607,7 +1607,7 @@
Buffer.prototype.writeInt16LE = function writeInt16LE (value, offset, noAssert) {
value = +value;
offset = offset | 0;
- if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000);
+ if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -32768);
if (Buffer.TYPED_ARRAY_SUPPORT) {
this[offset] = (value & 0xff);
this[offset + 1] = (value >>> 8);
@@ -1620,7 +1620,7 @@
Buffer.prototype.writeInt16BE = function writeInt16BE (value, offset, noAssert) {
value = +value;
offset = offset | 0;
- if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000);
+ if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -32768);
if (Buffer.TYPED_ARRAY_SUPPORT) {
this[offset] = (value >>> 8);
this[offset + 1] = (value & 0xff);
@@ -1633,7 +1633,7 @@
Buffer.prototype.writeInt32LE = function writeInt32LE (value, offset, noAssert) {
value = +value;
offset = offset | 0;
- if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000);
+ if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -2147483648);
if (Buffer.TYPED_ARRAY_SUPPORT) {
this[offset] = (value & 0xff);
this[offset + 1] = (value >>> 8);
@@ -1648,7 +1648,7 @@
Buffer.prototype.writeInt32BE = function writeInt32BE (value, offset, noAssert) {
value = +value;
offset = offset | 0;
- if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000);
+ if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -2147483648);
if (value < 0) value = 0xffffffff + value + 1;
if (Buffer.TYPED_ARRAY_SUPPORT) {
this[offset] = (value >>> 24);
@@ -2006,7 +2006,9 @@
this.domain = null;
if (EventEmitter.usingDomains) {
// if there is an active domain, then attach to it.
- if (domain.active) ;
+ if (domain.active && !(this instanceof domain.Domain)) {
+ this.domain = domain.active;
+ }
}
if (!this._events || this._events === Object.getPrototypeOf(this)._events) {
@@ -2575,94 +2577,19 @@
Item.prototype.run = function () {
this.fun.apply(null, this.array);
};
- var title = 'browser';
- var platform = 'browser';
- var browser = true;
var env = {};
- var argv = [];
- var version = ''; // empty string to avoid regexp issues
- var versions = {};
- var release = {};
- var config = {};
-
- function noop() {}
-
- var on = noop;
- var addListener = noop;
- var once = noop;
- var off = noop;
- var removeListener = noop;
- var removeAllListeners = noop;
- var emit = noop;
-
- function binding(name) {
- throw new Error('process.binding is not supported');
- }
-
- function cwd () { return '/' }
- function chdir (dir) {
- throw new Error('process.chdir is not supported');
- }function umask() { return 0; }
// from https://github.com/kumavis/browser-process-hrtime/blob/master/index.js
var performance = global$1.performance || {};
- var performanceNow =
- performance.now ||
+ performance.now ||
performance.mozNow ||
performance.msNow ||
performance.oNow ||
performance.webkitNow ||
function(){ return (new Date()).getTime() };
- // generate timestamp or delta
- // see http://nodejs.org/api/process.html#process_process_hrtime
- function hrtime(previousTimestamp){
- var clocktime = performanceNow.call(performance)*1e-3;
- var seconds = Math.floor(clocktime);
- var nanoseconds = Math.floor((clocktime%1)*1e9);
- if (previousTimestamp) {
- seconds = seconds - previousTimestamp[0];
- nanoseconds = nanoseconds - previousTimestamp[1];
- if (nanoseconds<0) {
- seconds--;
- nanoseconds += 1e9;
- }
- }
- return [seconds,nanoseconds]
- }
-
- var startTime = new Date();
- function uptime() {
- var currentTime = new Date();
- var dif = currentTime - startTime;
- return dif / 1000;
- }
-
var process = {
- nextTick: nextTick,
- title: title,
- browser: browser,
- env: env,
- argv: argv,
- version: version,
- versions: versions,
- on: on,
- addListener: addListener,
- once: once,
- off: off,
- removeListener: removeListener,
- removeAllListeners: removeAllListeners,
- emit: emit,
- binding: binding,
- cwd: cwd,
- chdir: chdir,
- umask: umask,
- hrtime: hrtime,
- platform: platform,
- release: release,
- config: config,
- uptime: uptime
- };
+ env: env};
var inherits;
if (typeof Object.create === 'function'){
@@ -5768,7 +5695,7 @@
);
}
// Normalize option `columns`
- options.cast_first_line_to_header = null;
+ options.cast_first_line_to_header = undefined;
if (options.columns === true) {
// Fields in the first line are converted as-is to columns
options.cast_first_line_to_header = undefined;
@@ -6300,7 +6227,7 @@
// Normalize option `to`
if (options.to === undefined || options.to === null) {
options.to = -1;
- } else {
+ } else if (options.to !== -1) {
if (typeof options.to === "string" && /\d+/.test(options.to)) {
options.to = parseInt(options.to);
}
@@ -6319,7 +6246,7 @@
// Normalize option `to_line`
if (options.to_line === undefined || options.to_line === null) {
options.to_line = -1;
- } else {
+ } else if (options.to_line !== -1) {
if (typeof options.to_line === "string" && /\d+/.test(options.to_line)) {
options.to_line = parseInt(options.to_line);
}
@@ -6450,10 +6377,14 @@
this.state.bufBytesStart += bomLength;
buf = buf.slice(bomLength);
// Renormalize original options with the new encoding
- this.options = normalize_options$1({
+ const options = normalize_options$1({
...this.original_options,
encoding: encoding,
});
+ // Properties are merged with the existing options instance
+ for (const key in options) {
+ this.options[key] = options[key];
+ }
// Options will re-evaluate the Buffer with the new encoding
({ comment, escape, quote } = this.options);
break;
@@ -7196,10 +7127,14 @@
if (skip_records_with_error) {
this.state.recordHasError = true;
if (this.options.on_skip !== undefined) {
- this.options.on_skip(
- err,
- raw ? this.state.rawBuffer.toString(encoding) : undefined,
- );
+ try {
+ this.options.on_skip(
+ err,
+ raw ? this.state.rawBuffer.toString(encoding) : undefined,
+ );
+ } catch (err) {
+ return err;
+ }
}
// this.emit('skip', err, raw ? this.state.rawBuffer.toString(encoding) : undefined);
return undefined;
@@ -7583,6 +7518,7 @@
const reIsPlainProp = /^\w*$/;
const getTag = function (value) {
+ // if (!value) value === undefined ? "[object Undefined]" : "[object Null]";
return Object.prototype.toString.call(value);
};
diff --git a/packages/csv/dist/umd/sync.js b/packages/csv/dist/umd/sync.js
index b9c23d14b..391b52b1a 100644
--- a/packages/csv/dist/umd/sync.js
+++ b/packages/csv/dist/umd/sync.js
@@ -837,8 +837,8 @@
byteOffset = 0;
} else if (byteOffset > 0x7fffffff) {
byteOffset = 0x7fffffff;
- } else if (byteOffset < -0x80000000) {
- byteOffset = -0x80000000;
+ } else if (byteOffset < -2147483648) {
+ byteOffset = -2147483648;
}
byteOffset = +byteOffset; // Coerce to Number.
if (isNaN(byteOffset)) {
@@ -1597,7 +1597,7 @@
Buffer.prototype.writeInt8 = function writeInt8 (value, offset, noAssert) {
value = +value;
offset = offset | 0;
- if (!noAssert) checkInt(this, value, offset, 1, 0x7f, -0x80);
+ if (!noAssert) checkInt(this, value, offset, 1, 0x7f, -128);
if (!Buffer.TYPED_ARRAY_SUPPORT) value = Math.floor(value);
if (value < 0) value = 0xff + value + 1;
this[offset] = (value & 0xff);
@@ -1607,7 +1607,7 @@
Buffer.prototype.writeInt16LE = function writeInt16LE (value, offset, noAssert) {
value = +value;
offset = offset | 0;
- if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000);
+ if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -32768);
if (Buffer.TYPED_ARRAY_SUPPORT) {
this[offset] = (value & 0xff);
this[offset + 1] = (value >>> 8);
@@ -1620,7 +1620,7 @@
Buffer.prototype.writeInt16BE = function writeInt16BE (value, offset, noAssert) {
value = +value;
offset = offset | 0;
- if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000);
+ if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -32768);
if (Buffer.TYPED_ARRAY_SUPPORT) {
this[offset] = (value >>> 8);
this[offset + 1] = (value & 0xff);
@@ -1633,7 +1633,7 @@
Buffer.prototype.writeInt32LE = function writeInt32LE (value, offset, noAssert) {
value = +value;
offset = offset | 0;
- if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000);
+ if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -2147483648);
if (Buffer.TYPED_ARRAY_SUPPORT) {
this[offset] = (value & 0xff);
this[offset + 1] = (value >>> 8);
@@ -1648,7 +1648,7 @@
Buffer.prototype.writeInt32BE = function writeInt32BE (value, offset, noAssert) {
value = +value;
offset = offset | 0;
- if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000);
+ if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -2147483648);
if (value < 0) value = 0xffffffff + value + 1;
if (Buffer.TYPED_ARRAY_SUPPORT) {
this[offset] = (value >>> 24);
@@ -2006,7 +2006,9 @@
this.domain = null;
if (EventEmitter.usingDomains) {
// if there is an active domain, then attach to it.
- if (domain.active) ;
+ if (domain.active && !(this instanceof domain.Domain)) {
+ this.domain = domain.active;
+ }
}
if (!this._events || this._events === Object.getPrototypeOf(this)._events) {
@@ -2575,94 +2577,19 @@
Item.prototype.run = function () {
this.fun.apply(null, this.array);
};
- var title = 'browser';
- var platform = 'browser';
- var browser = true;
var env = {};
- var argv = [];
- var version = ''; // empty string to avoid regexp issues
- var versions = {};
- var release = {};
- var config = {};
-
- function noop() {}
-
- var on = noop;
- var addListener = noop;
- var once = noop;
- var off = noop;
- var removeListener = noop;
- var removeAllListeners = noop;
- var emit = noop;
-
- function binding(name) {
- throw new Error('process.binding is not supported');
- }
-
- function cwd () { return '/' }
- function chdir (dir) {
- throw new Error('process.chdir is not supported');
- }function umask() { return 0; }
// from https://github.com/kumavis/browser-process-hrtime/blob/master/index.js
var performance = global$1.performance || {};
- var performanceNow =
- performance.now ||
+ performance.now ||
performance.mozNow ||
performance.msNow ||
performance.oNow ||
performance.webkitNow ||
function(){ return (new Date()).getTime() };
- // generate timestamp or delta
- // see http://nodejs.org/api/process.html#process_process_hrtime
- function hrtime(previousTimestamp){
- var clocktime = performanceNow.call(performance)*1e-3;
- var seconds = Math.floor(clocktime);
- var nanoseconds = Math.floor((clocktime%1)*1e9);
- if (previousTimestamp) {
- seconds = seconds - previousTimestamp[0];
- nanoseconds = nanoseconds - previousTimestamp[1];
- if (nanoseconds<0) {
- seconds--;
- nanoseconds += 1e9;
- }
- }
- return [seconds,nanoseconds]
- }
-
- var startTime = new Date();
- function uptime() {
- var currentTime = new Date();
- var dif = currentTime - startTime;
- return dif / 1000;
- }
-
var process = {
- nextTick: nextTick,
- title: title,
- browser: browser,
- env: env,
- argv: argv,
- version: version,
- versions: versions,
- on: on,
- addListener: addListener,
- once: once,
- off: off,
- removeListener: removeListener,
- removeAllListeners: removeAllListeners,
- emit: emit,
- binding: binding,
- cwd: cwd,
- chdir: chdir,
- umask: umask,
- hrtime: hrtime,
- platform: platform,
- release: release,
- config: config,
- uptime: uptime
- };
+ env: env};
var inherits;
if (typeof Object.create === 'function'){
@@ -5766,7 +5693,7 @@
);
}
// Normalize option `columns`
- options.cast_first_line_to_header = null;
+ options.cast_first_line_to_header = undefined;
if (options.columns === true) {
// Fields in the first line are converted as-is to columns
options.cast_first_line_to_header = undefined;
@@ -6298,7 +6225,7 @@
// Normalize option `to`
if (options.to === undefined || options.to === null) {
options.to = -1;
- } else {
+ } else if (options.to !== -1) {
if (typeof options.to === "string" && /\d+/.test(options.to)) {
options.to = parseInt(options.to);
}
@@ -6317,7 +6244,7 @@
// Normalize option `to_line`
if (options.to_line === undefined || options.to_line === null) {
options.to_line = -1;
- } else {
+ } else if (options.to_line !== -1) {
if (typeof options.to_line === "string" && /\d+/.test(options.to_line)) {
options.to_line = parseInt(options.to_line);
}
@@ -6448,10 +6375,14 @@
this.state.bufBytesStart += bomLength;
buf = buf.slice(bomLength);
// Renormalize original options with the new encoding
- this.options = normalize_options$1({
+ const options = normalize_options$1({
...this.original_options,
encoding: encoding,
});
+ // Properties are merged with the existing options instance
+ for (const key in options) {
+ this.options[key] = options[key];
+ }
// Options will re-evaluate the Buffer with the new encoding
({ comment, escape, quote } = this.options);
break;
@@ -7194,10 +7125,14 @@
if (skip_records_with_error) {
this.state.recordHasError = true;
if (this.options.on_skip !== undefined) {
- this.options.on_skip(
- err,
- raw ? this.state.rawBuffer.toString(encoding) : undefined,
- );
+ try {
+ this.options.on_skip(
+ err,
+ raw ? this.state.rawBuffer.toString(encoding) : undefined,
+ );
+ } catch (err) {
+ return err;
+ }
}
// this.emit('skip', err, raw ? this.state.rawBuffer.toString(encoding) : undefined);
return undefined;
@@ -7251,10 +7186,13 @@
}
};
const close = () => {};
- const err1 = parser.parse(data, false, push, close);
- if (err1 !== undefined) throw err1;
- const err2 = parser.parse(undefined, true, push, close);
- if (err2 !== undefined) throw err2;
+ const error = parser.parse(data, true, push, close);
+ if (error !== undefined) throw error;
+ // 250606: `parser.parse` was implemented as 2 calls:
+ // const err1 = parser.parse(data, false, push, close);
+ // if (err1 !== undefined) throw err1;
+ // const err2 = parser.parse(undefined, true, push, close);
+ // if (err2 !== undefined) throw err2;
return records;
};
@@ -7283,6 +7221,7 @@
const reIsPlainProp = /^\w*$/;
const getTag = function (value) {
+ // if (!value) value === undefined ? "[object Undefined]" : "[object Null]";
return Object.prototype.toString.call(value);
};
diff --git a/packages/csv/lib/index.d.ts b/packages/csv/lib/index.d.ts
index c9770f8df..9dc9a1ee7 100644
--- a/packages/csv/lib/index.d.ts
+++ b/packages/csv/lib/index.d.ts
@@ -1,14 +1,13 @@
-
// Alias to the modules exposing the stream and callback APIs
-import { generate } from 'csv-generate';
-import { parse } from 'csv-parse';
-import { transform } from 'stream-transform';
-import { stringify } from 'csv-stringify';
+import { generate } from "csv-generate";
+import { parse } from "csv-parse";
+import { transform } from "stream-transform";
+import { stringify } from "csv-stringify";
export { generate, parse, transform, stringify };
-export * as generator from 'csv-generate';
-export * as parser from 'csv-parse';
-export * as transformer from 'stream-transform';
-export * as stringifier from 'csv-stringify';
+export * as generator from "csv-generate";
+export * as parser from "csv-parse";
+export * as transformer from "stream-transform";
+export * as stringifier from "csv-stringify";
diff --git a/packages/csv/lib/sync.d.ts b/packages/csv/lib/sync.d.ts
index b1812592d..8bdf6763f 100644
--- a/packages/csv/lib/sync.d.ts
+++ b/packages/csv/lib/sync.d.ts
@@ -1,14 +1,13 @@
-
// Alias to the modules exposing the sync APIs
-import { generate } from 'csv-generate/sync'
-import { parse } from 'csv-parse/sync';
-import { transform } from 'stream-transform/sync';
-import { stringify } from 'csv-stringify/sync';
+import { generate } from "csv-generate/sync";
+import { parse } from "csv-parse/sync";
+import { transform } from "stream-transform/sync";
+import { stringify } from "csv-stringify/sync";
-export { generate, parse, transform, stringify }
+export { generate, parse, transform, stringify };
-export * as generator from 'csv-generate/sync';
-export * as parser from 'csv-parse/sync';
-export * as transformer from 'stream-transform/sync';
-export * as stringifier from 'csv-stringify/sync';
+export * as generator from "csv-generate/sync";
+export * as parser from "csv-parse/sync";
+export * as transformer from "stream-transform/sync";
+export * as stringifier from "csv-stringify/sync";
diff --git a/packages/csv/package.json b/packages/csv/package.json
index b41fef512..471d4ed39 100644
--- a/packages/csv/package.json
+++ b/packages/csv/package.json
@@ -1,6 +1,6 @@
{
"name": "csv",
- "version": "6.3.11",
+ "version": "6.4.1",
"description": "A mature CSV toolset with simple api, full of options and tested against large datasets.",
"keywords": [
"node",
@@ -23,30 +23,24 @@
"David Worms (https://www.adaltas.com)"
],
"dependencies": {
- "csv-generate": "^4.4.2",
- "csv-parse": "^5.6.0",
- "csv-stringify": "^6.5.2",
- "stream-transform": "^3.3.3"
+ "csv-generate": "^4.5.0",
+ "csv-parse": "^6.1.0",
+ "csv-stringify": "^6.6.0",
+ "stream-transform": "^3.4.0"
},
"devDependencies": {
- "@eslint/js": "^9.15.0",
- "@rollup/plugin-node-resolve": "^15.3.0",
- "@types/mocha": "^10.0.9",
- "@types/node": "^22.9.1",
- "coffeescript": "~2.7.0",
+ "@rollup/plugin-node-resolve": "^16.0.1",
+ "@types/mocha": "^10.0.10",
+ "@types/node": "^22.15.30",
"each": "^2.7.2",
- "eslint": "^9.15.0",
- "eslint-config-prettier": "^9.1.0",
- "eslint-plugin-mocha": "^10.5.0",
- "eslint-plugin-prettier": "^5.2.1",
- "mocha": "~10.8.2",
- "prettier": "^3.3.3",
- "rollup": "^4.27.3",
+ "mocha": "~11.5.0",
+ "prettier": "^3.5.3",
+ "rollup": "^4.41.1",
"rollup-plugin-node-builtins": "^2.1.2",
"rollup-plugin-node-globals": "^1.4.0",
"should": "~13.2.3",
"ts-node": "^10.9.2",
- "typescript": "^5.6.3"
+ "typescript": "^5.8.3"
},
"engines": {
"node": ">= 0.1.90"
@@ -90,19 +84,12 @@
"main": "./dist/cjs/index.cjs",
"mocha": {
"inline-diffs": true,
- "loader": "./test/loaders/all.js",
+ "loader": "ts-node/esm",
"recursive": true,
"reporter": "spec",
- "require": [
- "should"
- ],
"throw-deprecation": false,
"timeout": 40000
},
- "lint-staged": {
- "*.js": "npm run lint:fix",
- "*.md": "prettier -w"
- },
"repository": {
"type": "git",
"url": "https://github.com/adaltas/node-csv.git",
@@ -117,8 +104,8 @@
"lint:fix": "eslint --fix",
"lint:ts": "tsc --noEmit true",
"preversion": "npm run build && git add dist",
- "test": "mocha 'test/**/*.{coffee,ts}'",
- "test:legacy": "mocha --ignore test/samples.coffee --loader=./test/loaders/legacy/all.js 'test/**/*.{coffee,ts}'"
+ "test": "mocha 'test/**/*.{js,ts}'",
+ "test:legacy": "mocha --ignore test/samples.js 'test/**/*.{js,ts}'"
},
"type": "module",
"types": "dist/esm/index.d.ts",
diff --git a/packages/csv/test/api.coffee b/packages/csv/test/api.coffee
deleted file mode 100644
index f467fc7f8..000000000
--- a/packages/csv/test/api.coffee
+++ /dev/null
@@ -1,32 +0,0 @@
-
-import {generate, parse, stringify, transform} from '../lib/index.js'
-
-describe 'api', ->
-
- it 'generate', (next) ->
- generate length: 1, columns: 1, seed: 1, encoding: 'utf8', (err, data) ->
- data.should.eql 'OMH' unless err
- next err
-
- it 'parse', (next) ->
- parse 'abc,def', (err, data) ->
- data.should.eql [ [ 'abc', 'def' ] ] unless err
- next err
-
- it 'stringify', (next) ->
- stringify [ [ 'abc', 'def' ] ], (err, data) ->
- data.should.eql 'abc,def\n' unless err
- next err
-
- it 'transform', (next) ->
- transform [
- ['abc','def']
- ], (record) ->
- record.push(record.shift())
- record
- , (err, output) ->
- output.should.eql [
- [ 'def', 'abc' ]
- ] unless err
- next err
-
diff --git a/packages/csv/test/api.js b/packages/csv/test/api.js
new file mode 100644
index 000000000..3e743dc6f
--- /dev/null
+++ b/packages/csv/test/api.js
@@ -0,0 +1,42 @@
+import "should";
+import { generate, parse, stringify, transform } from "../lib/index.js";
+
+describe("api", function () {
+ it("generate", function (next) {
+ generate(
+ { length: 1, columns: 1, seed: 1, encoding: "utf8" },
+ (err, data) => {
+ if (!err) data.should.eql("OMH");
+ next(err);
+ },
+ );
+ });
+
+ it("parse", function (next) {
+ parse("abc,def", (err, data) => {
+ if (!err) data.should.eql([["abc", "def"]]);
+ next(err);
+ });
+ });
+
+ it("stringify", function (next) {
+ stringify([["abc", "def"]], (err, data) => {
+ if (!err) data.should.eql("abc,def\n");
+ next(err);
+ });
+ });
+
+ it("transform", function (next) {
+ transform(
+ [["abc", "def"]],
+ (record) => {
+ record.push(record.shift());
+ return record;
+ },
+ (err, output) => {
+ if (!err) output.should.eql([["def", "abc"]]);
+ next(err);
+ },
+ );
+ });
+});
diff --git a/packages/csv/test/api.types.sync.ts b/packages/csv/test/api.types.sync.ts
index 66aefcd4d..f61e98fcc 100644
--- a/packages/csv/test/api.types.sync.ts
+++ b/packages/csv/test/api.types.sync.ts
@@ -1,56 +1,49 @@
+import "should";
+import csv, { generate, parse, stringify, transform } from "../lib/sync.js";
-import 'should'
-import csv, {generate, parse, stringify, transform} from '../lib/sync.js'
-
-describe('API Types', () => {
-
- describe('usage', () => {
-
- it('generate', () => {
+describe("API Types", function () {
+ describe("usage with named export", function () {
+ it("generate", function () {
// with options + handler
const output: string = generate(1);
return output;
- })
+ });
- it('parse', () => {
- const output: string = parse('');
+ it("parse", function () {
+ const output: string[][] = parse("");
return output;
- })
+ });
- it('stringify', () => {
+ it("stringify", function () {
const output: string = stringify([]);
return output;
- })
+ });
- it('transform', () => {
- const output: any = transform([], () => {});
+ it("transform", function () {
+ const output: void[] = transform([], () => {});
return output;
- })
-
- })
+ });
+ });
- describe('usage', () => {
-
- it('csv.generate', () => {
- const options: csv.generator.Options = {}
+ describe("usage with default export", function () {
+ it("csv.generate", function () {
+ const options: csv.generator.Options = {};
return options;
- })
-
- it('csv.parse', () => {
- const options: csv.parser.Options = {}
- return options;
- })
-
- it('csv.stringifier', () => {
- const options: csv.stringifier.Options = {}
+ });
+
+ it("csv.parse", function () {
+ const options: csv.parser.Options = {};
return options;
- })
-
- it('csv.transform', () => {
- const options: csv.transformer.Options = {}
+ });
+
+ it("csv.stringifier", function () {
+ const options: csv.stringifier.Options = {};
return options;
- })
-
- })
+ });
-})
+ it("csv.transform", function () {
+ const options: csv.transformer.Options = {};
+ return options;
+ });
+ });
+});
diff --git a/packages/csv/test/api.types.ts b/packages/csv/test/api.types.ts
index 9bb15c0db..4bd4f7422 100644
--- a/packages/csv/test/api.types.ts
+++ b/packages/csv/test/api.types.ts
@@ -1,42 +1,54 @@
+import "should";
+import { generate, parse, parser, stringify, transform } from "../lib/index.js";
-import 'should'
-import {generate, parse, parser, stringify, transform} from '../lib/index.js'
-
-describe('API Types', () => {
-
- describe('Initialisation', () => {
-
- it('generate', () => {
+describe("API Types", function () {
+ describe("Initialisation", function () {
+ it("generate", function () {
// with options + handler
- generate({length: 1}, (err: Error | undefined, records: Array>) => err || records)
- })
-
- it('parse', () => {
+ generate(
+ { length: 1 },
+ (err: Error | undefined, records: Array>) =>
+ err || records,
+ );
+ });
+
+ it("parse", function () {
// With input + handler
- parse('abc,def', {}, (err: parser.CsvError | undefined, records: Array>) => err?.message || records)
- })
-
- it('stringify', () => {
+ parse(
+ "abc,def",
+ {},
+ (err: parser.CsvError | undefined, records: Array>) =>
+ err?.message || records,
+ );
+ });
+
+ it("stringify", function () {
// With handler
- stringify( (err: Error | undefined, output: string) => err || output )
- })
+ stringify((err: Error | undefined, output: string) => err || output);
+ });
- it('transform', () => {
+ it("transform", function () {
// With handler
- const transformer = transform( record => record )
- transformer.should.be.an.Object() // Disable unused variable warning
+ const transformer = transform((record) => record);
+ transformer.should.be.an.Object(); // Disable unused variable warning
// With handler + callback
- transform( record => record, (err, records) => err || records )
+ transform(
+ (record) => record,
+ (err, records) => err || records,
+ );
// With records + handler
- transform( ['record'], record => record )
+ transform(["record"], (record) => record);
// With options + handler
- transform( {consume: true}, record => record )
+ transform({ consume: true }, (record) => record);
// With records + options + handler
- transform( ['record'], {consume: true}, record => record )
+ transform(["record"], { consume: true }, (record) => record);
// With records + options + handler + callback
- transform( ['record'], {consume: true}, record => record, (err, records) => err || records )
- })
-
- })
-
-})
+ transform(
+ ["record"],
+ { consume: true },
+ (record) => record,
+ (err, records) => err || records,
+ );
+ });
+ });
+});
diff --git a/packages/csv/test/loaders/all.js b/packages/csv/test/loaders/all.js
deleted file mode 100644
index 4e81c3449..000000000
--- a/packages/csv/test/loaders/all.js
+++ /dev/null
@@ -1,15 +0,0 @@
-import * as coffee from "./coffee.js";
-import * as ts from "ts-node/esm";
-
-const coffeeRegex = /\.coffee$|\.litcoffee$|\.coffee\.md$/;
-const tsRegex = /\.ts$/;
-
-export function load(url, context, next) {
- if (coffeeRegex.test(url)) {
- return coffee.load.apply(this, arguments);
- }
- if (tsRegex.test(url)) {
- return ts.load.apply(this, arguments);
- }
- return next(url, context, next);
-}
diff --git a/packages/csv/test/loaders/coffee.js b/packages/csv/test/loaders/coffee.js
deleted file mode 100644
index 75b15abe0..000000000
--- a/packages/csv/test/loaders/coffee.js
+++ /dev/null
@@ -1,20 +0,0 @@
-import CoffeeScript from "coffeescript";
-
-// See https://github.com/nodejs/node/issues/36396
-const extensionsRegex = /\.coffee$|\.litcoffee$|\.coffee\.md$/;
-
-export async function load(url, context, next) {
- if (extensionsRegex.test(url)) {
- const format = "module";
- const { source: rawSource } = await next(url, { format });
- const source = CoffeeScript.compile(rawSource.toString(), {
- bare: true,
- inlineMap: true,
- filename: url,
- header: false,
- sourceMap: false,
- });
- return { format, source };
- }
- return next(url, context);
-}
diff --git a/packages/csv/test/loaders/legacy/all.js b/packages/csv/test/loaders/legacy/all.js
deleted file mode 100644
index f5e57e542..000000000
--- a/packages/csv/test/loaders/legacy/all.js
+++ /dev/null
@@ -1,36 +0,0 @@
-import * as coffee from "./coffee.js";
-import * as ts from "ts-node/esm";
-
-const coffeeRegex = /\.coffee$|\.litcoffee$|\.coffee\.md$/;
-const tsRegex = /\.ts$/;
-
-export function resolve(specifier) {
- if (coffeeRegex.test(specifier)) {
- return coffee.resolve.apply(this, arguments);
- }
- if (tsRegex.test(specifier)) {
- return ts.resolve.apply(this, arguments);
- }
- return ts.resolve.apply(this, arguments);
-}
-
-export function getFormat(url) {
- if (coffeeRegex.test(url)) {
- return coffee.getFormat.apply(this, arguments);
- }
- if (tsRegex.test(url)) {
- return ts.getFormat.apply(this, arguments);
- }
- return ts.getFormat.apply(this, arguments);
-}
-
-export function transformSource(source, context) {
- const { url } = context;
- if (coffeeRegex.test(url)) {
- return coffee.transformSource.apply(this, arguments);
- }
- if (tsRegex.test(url)) {
- return ts.transformSource.apply(this, arguments);
- }
- return ts.transformSource.apply(this, arguments);
-}
diff --git a/packages/csv/test/loaders/legacy/coffee.js b/packages/csv/test/loaders/legacy/coffee.js
deleted file mode 100644
index 6a9975db9..000000000
--- a/packages/csv/test/loaders/legacy/coffee.js
+++ /dev/null
@@ -1,50 +0,0 @@
-// coffeescript-loader.mjs
-import { URL, pathToFileURL } from "url";
-import CoffeeScript from "coffeescript";
-import { cwd } from "process";
-
-const baseURL = pathToFileURL(`${cwd()}/`).href;
-
-// CoffeeScript files end in .coffee, .litcoffee or .coffee.md.
-const extensionsRegex = /\.coffee$|\.litcoffee$|\.coffee\.md$/;
-
-export function resolve(specifier, context, defaultResolve) {
- const { parentURL = baseURL } = context;
- // Node.js normally errors on unknown file extensions, so return a URL for
- // specifiers ending in the CoffeeScript file extensions.
- if (extensionsRegex.test(specifier)) {
- return {
- url: new URL(specifier, parentURL).href,
- stop: true,
- };
- }
- // Let Node.js handle all other specifiers.
- return defaultResolve(specifier, context, defaultResolve);
-}
-
-export function getFormat(url, context, defaultGetFormat) {
- // Now that we patched resolve to let CoffeeScript URLs through, we need to
- // tell Node.js what format such URLs should be interpreted as. For the
- // purposes of this loader, all CoffeeScript URLs are ES modules.
- if (extensionsRegex.test(url)) {
- return {
- format: "module",
- stop: true,
- };
- }
- // Let Node.js handle all other URLs.
- return defaultGetFormat(url, context, defaultGetFormat);
-}
-
-export function transformSource(source, context, defaultTransformSource) {
- const { url } = context;
-
- if (extensionsRegex.test(url)) {
- return {
- source: CoffeeScript.compile(String(source), { bare: true }),
- };
- }
-
- // Let Node.js handle all other sources.
- return defaultTransformSource(source, context, defaultTransformSource);
-}
diff --git a/packages/csv/test/samples.coffee b/packages/csv/test/samples.coffee
deleted file mode 100644
index 500e7525f..000000000
--- a/packages/csv/test/samples.coffee
+++ /dev/null
@@ -1,30 +0,0 @@
-
-import fs from 'node:fs/promises'
-import path from 'node:path'
-import { spawn } from 'node:child_process'
-
-__dirname = new URL( '.', import.meta.url).pathname
-dir = path.resolve __dirname, '../samples'
-samples = await fs.readdir dir
-
-describe 'Samples', ->
-
- samples
- .filter (sample) ->
- return false unless /\.(js|ts)?$/.test sample
- true
- .map (sample) ->
-
- it "Sample #{sample}", () ->
- data = await fs.readFile path.resolve(dir, sample), 'utf8'
- return if /^["|']skip test["|']/.test data
- new Promise (resolve, reject) ->
- ext = /\.(\w+)?$/.exec(sample)[0]
- [cmd, ...args] = switch ext
- when '.js'
- ['node', path.resolve dir, sample]
- when '.ts'
- ['node', '--loader', 'ts-node/esm', path.resolve dir, sample]
- spawn(cmd, args)
- .on 'close', (code) -> if code is 0 then resolve() else reject(new Error 'Failure')
- .stdout.on 'data', (->)
diff --git a/packages/csv/test/samples.js b/packages/csv/test/samples.js
new file mode 100644
index 000000000..5919a5514
--- /dev/null
+++ b/packages/csv/test/samples.js
@@ -0,0 +1,44 @@
+import fs from "node:fs/promises";
+import path from "node:path";
+import { spawn } from "node:child_process";
+
+const __dirname = new URL(".", import.meta.url).pathname;
+const dir = path.resolve(__dirname, "../samples");
+const samples = await fs.readdir(dir);
+
+describe("Samples", function () {
+ /* eslint mocha/no-setup-in-describe: "off" */
+ samples
+ .filter((sample) => {
+ if (!/\.(js|ts)?$/.test(sample)) return false;
+ return true;
+ })
+ .map((sample) => {
+ it(`Sample ${sample}`, async function () {
+ const data = await fs.readFile(path.resolve(dir, sample), "utf8");
+ if (/^["|']skip test["|']/.test(data)) return;
+ return new Promise((resolve, reject) => {
+ const ext = /\.(\w+)?$/.exec(sample)[0];
+ let cmd, args;
+ switch (ext) {
+ case ".js":
+ [cmd, ...args] = ["node", path.resolve(dir, sample)];
+ break;
+ case ".ts":
+ [cmd, ...args] = [
+ "node",
+ "--loader",
+ "ts-node/esm",
+ path.resolve(dir, sample),
+ ];
+ break;
+ }
+ spawn(cmd, args)
+ .on("close", (code) =>
+ code === 0 ? resolve() : reject(new Error("Failure")),
+ )
+ .stdout.on("data", () => {});
+ });
+ });
+ });
+});
diff --git a/packages/csv/test/sync.coffee b/packages/csv/test/sync.coffee
deleted file mode 100644
index 7122fe231..000000000
--- a/packages/csv/test/sync.coffee
+++ /dev/null
@@ -1,25 +0,0 @@
-
-import {generate, parse, transform, stringify} from '../lib/sync.js'
-
-describe 'api sync', ->
-
- it 'generate', ->
- generate length: 1, columns: 1, seed: 1, objectMode: true
- .should.eql [ [ 'OMH' ] ]
-
- it 'parse', ->
- parse 'abc,def'
- .should.eql [ [ 'abc', 'def' ] ]
-
- it 'transform', ->
- transform [
- [ 'abc', 'def' ]
- ], (record) ->
- record.push record.shift()
- record
- .should.eql [ [ 'def', 'abc' ] ]
-
- it 'stringify', ->
- stringify [ [ 'abc', 'def' ] ]
- .should.eql 'abc,def\n'
-
diff --git a/packages/csv/test/sync.js b/packages/csv/test/sync.js
new file mode 100644
index 000000000..6f3ad8077
--- /dev/null
+++ b/packages/csv/test/sync.js
@@ -0,0 +1,25 @@
+import "should";
+import { generate, parse, transform, stringify } from "../lib/sync.js";
+
+describe("api sync", function () {
+ it("generate", function () {
+ generate({ length: 1, columns: 1, seed: 1, objectMode: true }).should.eql([
+ ["OMH"],
+ ]);
+ });
+
+ it("parse", function () {
+ parse("abc,def").should.eql([["abc", "def"]]);
+ });
+
+ it("transform", function () {
+ transform([["abc", "def"]], (record) => {
+ record.push(record.shift());
+ return record;
+ }).should.eql([["def", "abc"]]);
+ });
+
+ it("stringify", function () {
+ stringify([["abc", "def"]]).should.eql("abc,def\n");
+ });
+});
diff --git a/packages/stream-transform/CHANGELOG.md b/packages/stream-transform/CHANGELOG.md
index 89ca86deb..7a750552e 100644
--- a/packages/stream-transform/CHANGELOG.md
+++ b/packages/stream-transform/CHANGELOG.md
@@ -3,6 +3,41 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
+## 3.4.0 (2025-07-10)
+
+### Features
+
+- backport support for node 14 ([dbfeb78](https://github.com/adaltas/node-csv/commit/dbfeb78f61ed36f02936d63a53345708ca213e45))
+- backward support for node 8 ([496231d](https://github.com/adaltas/node-csv/commit/496231dfd838f0a6a72269a5a2390a4c637cef95))
+- esm migration ([b5c0d4b](https://github.com/adaltas/node-csv/commit/b5c0d4b191c8b57397808c0922a3f08248506a9f))
+- export ts types in sync ([890bf8d](https://github.com/adaltas/node-csv/commit/890bf8d950c18a05cab5e35a461d0847d9425156))
+- replace ts types with typesVersions ([acb41d5](https://github.com/adaltas/node-csv/commit/acb41d5031669f2d582e40da1c80f5fd4738fee4))
+- **stream-transform:** handler promise support ([df337ec](https://github.com/adaltas/node-csv/commit/df337ec44cfd9a4536641ca7e2f0f5c1404ea74d))
+- **stream-transform:** ts extends options with stream.TransformOptions ([eb64b12](https://github.com/adaltas/node-csv/commit/eb64b12774e8371cb1043a0c4a33ed9dc73a1c50))
+- ts module Node16 and type declaration to exports field ([#341](https://github.com/adaltas/node-csv/issues/341)) ([4b0283d](https://github.com/adaltas/node-csv/commit/4b0283d17b7fa46daa1f87380759ba72c71ec79b))
+- wg stream api ([8a5eb7d](https://github.com/adaltas/node-csv/commit/8a5eb7dfd31b22217db4fbbc832d707221850785))
+
+### Bug Fixes
+
+- commonjs types, run tsc and lint to validate changes ([#397](https://github.com/adaltas/node-csv/issues/397)) ([e6870fe](https://github.com/adaltas/node-csv/commit/e6870fe272c119e273196522c9771d12ff8b2a35))
+- correct exports in package.json with webpack ([154eafb](https://github.com/adaltas/node-csv/commit/154eafbac866eb4499a0d392f8dcd057695c2586))
+- **csv-demo-ts-cjs-node16:** upgrade module definition after latest typescript ([87fe919](https://github.com/adaltas/node-csv/commit/87fe91996fb2a8895c252177fca4f0cb59a518f9))
+- **csv-demo-webpack-ts:** remove polyfill ([47a99bd](https://github.com/adaltas/node-csv/commit/47a99bd944d1d943e6374227dbc4e20aaa2c8c7f))
+- **csv-demo-webpack-ts:** simplify export paths ([8d63a14](https://github.com/adaltas/node-csv/commit/8d63a14313bb6b26f13fafb740cc686f1dfaa65f))
+- **csv-generate:** finish called twice in node 16 ([3decdf1](https://github.com/adaltas/node-csv/commit/3decdf169ce3b8e0c5cadd257816c346c8e4d3fa))
+- dont insert polyfills in cjs [#303](https://github.com/adaltas/node-csv/issues/303) ([9baf334](https://github.com/adaltas/node-csv/commit/9baf334044dab90b4a0d096a7e456d0fd5807d5b))
+- esm exports in package.json files ([c48fe47](https://github.com/adaltas/node-csv/commit/c48fe478ced7560aa078fbc36ec33d6007111e2b)), closes [#308](https://github.com/adaltas/node-csv/issues/308)
+- export original lib esm modules ([be25349](https://github.com/adaltas/node-csv/commit/be2534928ba21156e9cde1e15d2e8593d62ffe71))
+- expose browser esm modules ([eb87355](https://github.com/adaltas/node-csv/commit/eb873557c65912f065d2581d30a17a96b0bfd2d6))
+- fallback to setTimeout is setImmediate is undefined ([3d6a2d0](https://github.com/adaltas/node-csv/commit/3d6a2d0a655af342f28456b46db7ccfe7ee9d664))
+- refer to esm files in dist ([b780fbd](https://github.com/adaltas/node-csv/commit/b780fbd26f5e54494e511eb2e004d3cdedee3593))
+- remove samples from publicatgion ([12c221d](https://github.com/adaltas/node-csv/commit/12c221dc37add26f094e3bb7f94b50ee06ff5be6))
+- **stream-transform:** backpressure after push ([3e83f4e](https://github.com/adaltas/node-csv/commit/3e83f4e604b7b944835de18afcb41716ce4bbfad))
+- **stream-transform:** finish event call multiple times ([4f45103](https://github.com/adaltas/node-csv/commit/4f451038ef083b65d58ccee6fe3d041b106cc1cf))
+- **stream-transform:** sync callback usage in async handler ([4dd562b](https://github.com/adaltas/node-csv/commit/4dd562b65b99803b45858f449f67e52e2ef15726))
+- support ts node16 resolution in cjs ([#354](https://github.com/adaltas/node-csv/issues/354)) ([fa09d03](https://github.com/adaltas/node-csv/commit/fa09d03aaf0008b2790656871ca6b2c4be12d14c))
+- support TypeScript moduleResolution node16 ([#368](https://github.com/adaltas/node-csv/issues/368)) ([f4d7c97](https://github.com/adaltas/node-csv/commit/f4d7c97f39fb73e9d248eee21e61e7dc48015c78))
+
## [3.3.3](https://github.com/adaltas/node-csv/compare/stream-transform@3.3.2...stream-transform@3.3.3) (2024-11-21)
**Note:** Version bump only for package stream-transform
diff --git a/packages/stream-transform/dist/cjs/index.d.cts b/packages/stream-transform/dist/cjs/index.d.cts
index 396629866..fb703dbd7 100644
--- a/packages/stream-transform/dist/cjs/index.d.cts
+++ b/packages/stream-transform/dist/cjs/index.d.cts
@@ -2,39 +2,59 @@
import * as stream from "stream";
-export type Handler = (record: T, callback: HandlerCallback, params?: any) => U
-export type HandlerCallback = (err?: null | Error, record?: T) => void
-export type Callback = (err?: null | Error, output?: string) => void
+export type Handler = (
+ record: T,
+ callback: HandlerCallback,
+ params?: any,
+) => U;
+export type HandlerCallback = (err?: null | Error, record?: T) => void;
+export type Callback = (err?: null | Error, output?: string) => void;
export interface Options extends stream.TransformOptions {
- /**
- * In the absence of a consumer, like a `stream.Readable`, trigger the consumption of the stream.
- */
- consume?: boolean
- /**
- * The number of transformation callbacks to run in parallel; only apply with asynchronous handlers; default to "100".
- */
- parallel?: number
- /**
- * Pass user defined parameters to the user handler as last argument.
- */
- params?: any
+ /**
+ * In the absence of a consumer, like a `stream.Readable`, trigger the consumption of the stream.
+ */
+ consume?: boolean;
+ /**
+ * The number of transformation callbacks to run in parallel; only apply with asynchronous handlers; default to "100".
+ */
+ parallel?: number;
+ /**
+ * Pass user defined parameters to the user handler as last argument.
+ */
+ params?: any;
}
export interface State {
- finished: number
- running: number
- started: number
+ finished: number;
+ running: number;
+ started: number;
}
export class Transformer extends stream.Transform {
- constructor(options: Options)
- readonly options: Options
- readonly state: State
+ constructor(options: Options);
+ readonly options: Options;
+ readonly state: State;
}
-declare function transform(handler: Handler, callback?: Callback): Transformer
-declare function transform(records: Array, handler: Handler, callback?: Callback): Transformer
-declare function transform(options: Options, handler: Handler, callback?: Callback): Transformer
-declare function transform(records: Array, options: Options, handler: Handler, callback?: Callback): Transformer
+declare function transform(
+ handler: Handler,
+ callback?: Callback,
+): Transformer;
+declare function transform(
+ records: Array,
+ handler: Handler,
+ callback?: Callback,
+): Transformer;
+declare function transform(
+ options: Options,
+ handler: Handler,
+ callback?: Callback,
+): Transformer;
+declare function transform(
+ records: Array,
+ options: Options,
+ handler: Handler,
+ callback?: Callback,
+): Transformer;
export default transform;
-export { transform }
+export { transform };
diff --git a/packages/stream-transform/dist/cjs/sync.d.cts b/packages/stream-transform/dist/cjs/sync.d.cts
index 03f421701..772b9ce20 100644
--- a/packages/stream-transform/dist/cjs/sync.d.cts
+++ b/packages/stream-transform/dist/cjs/sync.d.cts
@@ -1,10 +1,17 @@
///
-import { Options } from './index.cjs';
+import { Options } from "./index.cjs";
-export type Handler = (record: T) => U
+export type Handler = (record: T) => U;
// export default transform;
-export function transform(records: Array, handler: Handler): Array
-export function transform(records: Array, options: Options, handler: Handler): Array
+export function transform(
+ records: Array,
+ handler: Handler,
+): Array;
+export function transform(
+ records: Array,
+ options: Options,
+ handler: Handler,
+): Array;
export { Options };
diff --git a/packages/stream-transform/dist/esm/index.d.ts b/packages/stream-transform/dist/esm/index.d.ts
index 396629866..fb703dbd7 100644
--- a/packages/stream-transform/dist/esm/index.d.ts
+++ b/packages/stream-transform/dist/esm/index.d.ts
@@ -2,39 +2,59 @@
import * as stream from "stream";
-export type Handler = (record: T, callback: HandlerCallback, params?: any) => U
-export type HandlerCallback = (err?: null | Error, record?: T) => void
-export type Callback = (err?: null | Error, output?: string) => void
+export type Handler = (
+ record: T,
+ callback: HandlerCallback,
+ params?: any,
+) => U;
+export type HandlerCallback = (err?: null | Error, record?: T) => void;
+export type Callback = (err?: null | Error, output?: string) => void;
export interface Options extends stream.TransformOptions {
- /**
- * In the absence of a consumer, like a `stream.Readable`, trigger the consumption of the stream.
- */
- consume?: boolean
- /**
- * The number of transformation callbacks to run in parallel; only apply with asynchronous handlers; default to "100".
- */
- parallel?: number
- /**
- * Pass user defined parameters to the user handler as last argument.
- */
- params?: any
+ /**
+ * In the absence of a consumer, like a `stream.Readable`, trigger the consumption of the stream.
+ */
+ consume?: boolean;
+ /**
+ * The number of transformation callbacks to run in parallel; only apply with asynchronous handlers; default to "100".
+ */
+ parallel?: number;
+ /**
+ * Pass user defined parameters to the user handler as last argument.
+ */
+ params?: any;
}
export interface State {
- finished: number
- running: number
- started: number
+ finished: number;
+ running: number;
+ started: number;
}
export class Transformer extends stream.Transform {
- constructor(options: Options)
- readonly options: Options
- readonly state: State
+ constructor(options: Options);
+ readonly options: Options;
+ readonly state: State;
}
-declare function transform(handler: Handler, callback?: Callback): Transformer
-declare function transform(records: Array, handler: Handler, callback?: Callback): Transformer
-declare function transform(options: Options, handler: Handler, callback?: Callback): Transformer
-declare function transform(records: Array, options: Options, handler: Handler, callback?: Callback): Transformer
+declare function transform(
+ handler: Handler,
+ callback?: Callback,
+): Transformer;
+declare function transform(
+ records: Array,
+ handler: Handler,
+ callback?: Callback,
+): Transformer;
+declare function transform(
+ options: Options,
+ handler: Handler,
+ callback?: Callback,
+): Transformer;
+declare function transform(
+ records: Array,
+ options: Options,
+ handler: Handler,
+ callback?: Callback,
+): Transformer;
export default transform;
-export { transform }
+export { transform };
diff --git a/packages/stream-transform/dist/esm/index.js b/packages/stream-transform/dist/esm/index.js
index 9fa056bf9..4452b7ecf 100644
--- a/packages/stream-transform/dist/esm/index.js
+++ b/packages/stream-transform/dist/esm/index.js
@@ -28,7 +28,9 @@ EventEmitter.init = function() {
this.domain = null;
if (EventEmitter.usingDomains) {
// if there is an active domain, then attach to it.
- if (domain.active) ;
+ if (domain.active && !(this instanceof domain.Domain)) {
+ this.domain = domain.active;
+ }
}
if (!this._events || this._events === Object.getPrototypeOf(this)._events) {
@@ -1297,8 +1299,8 @@ function bidirectionalIndexOf (buffer, val, byteOffset, encoding, dir) {
byteOffset = 0;
} else if (byteOffset > 0x7fffffff) {
byteOffset = 0x7fffffff;
- } else if (byteOffset < -0x80000000) {
- byteOffset = -0x80000000;
+ } else if (byteOffset < -2147483648) {
+ byteOffset = -2147483648;
}
byteOffset = +byteOffset; // Coerce to Number.
if (isNaN(byteOffset)) {
@@ -2057,7 +2059,7 @@ Buffer.prototype.writeIntBE = function writeIntBE (value, offset, byteLength, no
Buffer.prototype.writeInt8 = function writeInt8 (value, offset, noAssert) {
value = +value;
offset = offset | 0;
- if (!noAssert) checkInt(this, value, offset, 1, 0x7f, -0x80);
+ if (!noAssert) checkInt(this, value, offset, 1, 0x7f, -128);
if (!Buffer.TYPED_ARRAY_SUPPORT) value = Math.floor(value);
if (value < 0) value = 0xff + value + 1;
this[offset] = (value & 0xff);
@@ -2067,7 +2069,7 @@ Buffer.prototype.writeInt8 = function writeInt8 (value, offset, noAssert) {
Buffer.prototype.writeInt16LE = function writeInt16LE (value, offset, noAssert) {
value = +value;
offset = offset | 0;
- if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000);
+ if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -32768);
if (Buffer.TYPED_ARRAY_SUPPORT) {
this[offset] = (value & 0xff);
this[offset + 1] = (value >>> 8);
@@ -2080,7 +2082,7 @@ Buffer.prototype.writeInt16LE = function writeInt16LE (value, offset, noAssert)
Buffer.prototype.writeInt16BE = function writeInt16BE (value, offset, noAssert) {
value = +value;
offset = offset | 0;
- if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000);
+ if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -32768);
if (Buffer.TYPED_ARRAY_SUPPORT) {
this[offset] = (value >>> 8);
this[offset + 1] = (value & 0xff);
@@ -2093,7 +2095,7 @@ Buffer.prototype.writeInt16BE = function writeInt16BE (value, offset, noAssert)
Buffer.prototype.writeInt32LE = function writeInt32LE (value, offset, noAssert) {
value = +value;
offset = offset | 0;
- if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000);
+ if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -2147483648);
if (Buffer.TYPED_ARRAY_SUPPORT) {
this[offset] = (value & 0xff);
this[offset + 1] = (value >>> 8);
@@ -2108,7 +2110,7 @@ Buffer.prototype.writeInt32LE = function writeInt32LE (value, offset, noAssert)
Buffer.prototype.writeInt32BE = function writeInt32BE (value, offset, noAssert) {
value = +value;
offset = offset | 0;
- if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000);
+ if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -2147483648);
if (value < 0) value = 0xffffffff + value + 1;
if (Buffer.TYPED_ARRAY_SUPPORT) {
this[offset] = (value >>> 24);
@@ -2569,94 +2571,19 @@ function Item(fun, array) {
Item.prototype.run = function () {
this.fun.apply(null, this.array);
};
-var title = 'browser';
-var platform = 'browser';
-var browser = true;
var env = {};
-var argv = [];
-var version = ''; // empty string to avoid regexp issues
-var versions = {};
-var release = {};
-var config = {};
-
-function noop() {}
-
-var on = noop;
-var addListener = noop;
-var once = noop;
-var off = noop;
-var removeListener = noop;
-var removeAllListeners = noop;
-var emit = noop;
-
-function binding(name) {
- throw new Error('process.binding is not supported');
-}
-
-function cwd () { return '/' }
-function chdir (dir) {
- throw new Error('process.chdir is not supported');
-}function umask() { return 0; }
// from https://github.com/kumavis/browser-process-hrtime/blob/master/index.js
var performance = global$1.performance || {};
-var performanceNow =
- performance.now ||
+performance.now ||
performance.mozNow ||
performance.msNow ||
performance.oNow ||
performance.webkitNow ||
function(){ return (new Date()).getTime() };
-// generate timestamp or delta
-// see http://nodejs.org/api/process.html#process_process_hrtime
-function hrtime(previousTimestamp){
- var clocktime = performanceNow.call(performance)*1e-3;
- var seconds = Math.floor(clocktime);
- var nanoseconds = Math.floor((clocktime%1)*1e9);
- if (previousTimestamp) {
- seconds = seconds - previousTimestamp[0];
- nanoseconds = nanoseconds - previousTimestamp[1];
- if (nanoseconds<0) {
- seconds--;
- nanoseconds += 1e9;
- }
- }
- return [seconds,nanoseconds]
-}
-
-var startTime = new Date();
-function uptime() {
- var currentTime = new Date();
- var dif = currentTime - startTime;
- return dif / 1000;
-}
-
var process = {
- nextTick: nextTick,
- title: title,
- browser: browser,
- env: env,
- argv: argv,
- version: version,
- versions: versions,
- on: on,
- addListener: addListener,
- once: once,
- off: off,
- removeListener: removeListener,
- removeAllListeners: removeAllListeners,
- emit: emit,
- binding: binding,
- cwd: cwd,
- chdir: chdir,
- umask: umask,
- hrtime: hrtime,
- platform: platform,
- release: release,
- config: config,
- uptime: uptime
-};
+ env: env};
var inherits;
if (typeof Object.create === 'function'){
diff --git a/packages/stream-transform/dist/esm/sync.d.ts b/packages/stream-transform/dist/esm/sync.d.ts
index 538c3e5ff..1e7bd7986 100644
--- a/packages/stream-transform/dist/esm/sync.d.ts
+++ b/packages/stream-transform/dist/esm/sync.d.ts
@@ -1,10 +1,17 @@
///
-import { Options } from './index.js';
+import { Options } from "./index.js";
-export type Handler = (record: T) => U
+export type Handler = (record: T) => U;
// export default transform;
-export function transform(records: Array, handler: Handler): Array
-export function transform(records: Array, options: Options, handler: Handler): Array