Skip to content

Commit db4ad7d

Browse files
committed
refactor: apply eslint recommandations
1 parent f40219a commit db4ad7d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+1395
-1326
lines changed

demo/cjs/lib/csv.ts

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,30 @@
1-
21
// Import the package main module
3-
import * as csv from 'csv'
2+
import * as csv from "csv";
43

54
// Generate 20 records
65
const generator: csv.generator.Generator = csv.generate({
7-
delimiter: '|',
8-
length: 20
9-
})
6+
delimiter: "|",
7+
length: 20,
8+
});
109
// Transform CSV data into records
1110
const parser: csv.parser.Parser = csv.parse({
12-
delimiter: '|'
13-
})
11+
delimiter: "|",
12+
});
1413
// Transform each value into uppercase
1514
const transformer: csv.transformer.Transformer = csv.transform((record) => {
16-
return record.map((value: string) => {
17-
return value.toUpperCase()
18-
});
19-
})
15+
return record.map((value: string) => {
16+
return value.toUpperCase();
17+
});
18+
});
2019
// Convert objects into a stream
2120
const stringifier: csv.stringifier.Stringifier = csv.stringify({
2221
cast: {
2322
string: (value: string, context: csv.stringifier.CastingContext) => {
2423
return context.index % 2 ? value.toLowerCase() : value.toUpperCase();
25-
}
24+
},
2625
},
2726
quoted: true,
28-
})
27+
});
2928

3029
// Run the pipeline
31-
generator
32-
.pipe(parser)
33-
.pipe(transformer)
34-
.pipe(stringifier)
35-
.pipe(process.stdout)
30+
generator.pipe(parser).pipe(transformer).pipe(stringifier).pipe(process.stdout);

demo/cjs/lib/csv_sync.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,30 @@
1-
21
// Import the package sync module
32
// Node.js >= 14
4-
import * as csv from 'csv/sync';
3+
import * as csv from "csv/sync";
54
// Node.js < 14
65
// import * as csv from 'csv/dist/cjs/sync';
76

87
// Generate 20 records
98
const input: string = csv.generate({
10-
delimiter: '|',
9+
delimiter: "|",
1110
length: 20,
1211
});
1312
// Transform CSV data into records
1413
const records: any = csv.parse(input, {
15-
delimiter: '|',
14+
delimiter: "|",
1615
});
1716
// Transform each value into uppercase
1817
const uppercaseRecords: any = csv.transform(records, (record) => {
19-
return record.map((value: string) => {
20-
return value.toUpperCase()
21-
});
18+
return record.map((value: string) => {
19+
return value.toUpperCase();
20+
});
2221
});
2322
// Convert objects into a stream
2423
const output: any = csv.stringify(uppercaseRecords, {
2524
cast: {
2625
string: (value: string, context: csv.stringifier.CastingContext) => {
2726
return context.index % 2 ? value.toLowerCase() : value.toUpperCase();
28-
}
27+
},
2928
},
3029
quoted: true,
3130
});

demo/cjs/lib/parse.ts

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,28 @@
1-
2-
import assert from 'node:assert'
3-
import { parse, Parser } from 'csv-parse'
1+
import assert from "node:assert";
2+
import { parse, Parser } from "csv-parse";
43

54
const output: any = [];
65
// Create the parser
76
const parser: Parser = parse({
8-
delimiter: ':'
7+
delimiter: ":",
98
});
109
// Use the readable stream api to consume records
11-
parser.on('readable', function(){
12-
let record; while ((record = parser.read()) !== null) {
13-
output.push(record)
10+
parser.on("readable", function () {
11+
let record;
12+
while ((record = parser.read()) !== null) {
13+
output.push(record);
1414
}
1515
});
1616
// Catch any error
17-
parser.on('error', function(err){
18-
console.error(err.message)
17+
parser.on("error", function (err) {
18+
console.error(err.message);
1919
});
2020
// Test that the parsed records matched what's expected
21-
parser.on('end', function(){
22-
assert.deepStrictEqual(
23-
output,
24-
[
25-
[ 'a','b','c' ],
26-
[ '1','2','3' ]
27-
]
28-
)
21+
parser.on("end", function () {
22+
assert.deepStrictEqual(output, [
23+
["a", "b", "c"],
24+
["1", "2", "3"],
25+
]);
2926
});
3027
// Write data to the stream
3128
parser.write("a:b:c\n");

demo/cjs/lib/parse_sync.ts

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,15 @@
1-
2-
import assert from 'node:assert'
1+
import assert from "node:assert";
32
// Node.js >= 14
4-
import { parse } from 'csv-parse/sync'
3+
import { parse } from "csv-parse/sync";
54
// Node.js < 14
65
// import { parse } from 'csv-parse/dist/cjs/sync'
76

87
// Create the parser
9-
const records: [] = parse([
10-
"a:b:c\n",
11-
"1:2:3\n"
12-
].join(''), {
13-
delimiter: ':'
8+
const records: [] = parse(["a:b:c\n", "1:2:3\n"].join(""), {
9+
delimiter: ":",
1410
});
1511
// Test that the parsed records matched what's expected
16-
assert.deepStrictEqual(
17-
records,
18-
[
19-
[ 'a','b','c' ],
20-
[ '1','2','3' ]
21-
]
22-
);
12+
assert.deepStrictEqual(records, [
13+
["a", "b", "c"],
14+
["1", "2", "3"],
15+
]);

demo/cjs/lib/stringify.ts

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,26 @@
1+
import assert from "node:assert";
2+
import { stringify, Stringifier } from "csv-stringify";
13

2-
import assert from 'node:assert'
3-
import { stringify, Stringifier } from 'csv-stringify';
4-
5-
let output: string = '';
4+
let output: string = "";
65
// Create the parser
76
const stringifier: Stringifier = stringify({
8-
delimiter: ':',
9-
encoding: 'utf8'
7+
delimiter: ":",
8+
encoding: "utf8",
109
});
1110
// Use the readable stream api to consume records
12-
stringifier.on('readable', function(){
13-
let record; while ((record = stringifier.read()) !== null) {
14-
output += record
11+
stringifier.on("readable", function () {
12+
let record;
13+
while ((record = stringifier.read()) !== null) {
14+
output += record;
1515
}
1616
});
1717
// Catch any error
18-
stringifier.on('error', function(err){
19-
console.error(err.message)
18+
stringifier.on("error", function (err) {
19+
console.error(err.message);
2020
});
2121
// Test that the parsed records matched what's expected
22-
stringifier.on('end', function(){
23-
assert.deepStrictEqual(
24-
output,
25-
'a:b:c\n1:2:3\n'
26-
)
22+
stringifier.on("end", function () {
23+
assert.deepStrictEqual(output, "a:b:c\n1:2:3\n");
2724
});
2825
// Write data to the stream
2926
stringifier.write(["a", "b", "c"]);

demo/esm/lib/csv.ts

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,30 @@
1-
21
// Import the package main module
3-
import * as csv from 'csv'
2+
import * as csv from "csv";
43

54
// Generate 20 records
65
const generator: csv.generator.Generator = csv.generate({
7-
delimiter: '|',
8-
length: 20
9-
})
6+
delimiter: "|",
7+
length: 20,
8+
});
109
// Transform CSV data into records
1110
const parser: csv.parser.Parser = csv.parse({
12-
delimiter: '|'
13-
})
11+
delimiter: "|",
12+
});
1413
// Transform each value into uppercase
1514
const transformer: csv.transformer.Transformer = csv.transform((record) => {
16-
return record.map((value: string) => {
17-
return value.toUpperCase()
18-
});
19-
})
15+
return record.map((value: string) => {
16+
return value.toUpperCase();
17+
});
18+
});
2019
// Convert objects into a stream
2120
const stringifier: csv.stringifier.Stringifier = csv.stringify({
2221
cast: {
2322
string: (value: string, context: csv.stringifier.CastingContext) => {
2423
return context.index % 2 ? value.toLowerCase() : value.toUpperCase();
25-
}
24+
},
2625
},
2726
quoted: true,
28-
})
27+
});
2928

3029
// Run the pipeline
31-
generator
32-
.pipe(parser)
33-
.pipe(transformer)
34-
.pipe(stringifier)
35-
.pipe(process.stdout)
30+
generator.pipe(parser).pipe(transformer).pipe(stringifier).pipe(process.stdout);

demo/esm/lib/csv_sync.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,27 @@
1-
21
// Import the package sync module
3-
import * as csv from 'csv/sync';
2+
import * as csv from "csv/sync";
43

54
// Generate 20 records
65
const input: string = csv.generate({
7-
delimiter: '|',
6+
delimiter: "|",
87
length: 20,
98
});
109
// Transform CSV data into records
1110
const records: any = csv.parse(input, {
12-
delimiter: '|',
11+
delimiter: "|",
1312
});
1413
// Transform each value into uppercase
1514
const uppercaseRecords: any = csv.transform(records, (record) => {
16-
return record.map((value: string) => {
17-
return value.toUpperCase()
18-
});
15+
return record.map((value: string) => {
16+
return value.toUpperCase();
17+
});
1918
});
2019
// Convert objects into a stream
2120
const output: any = csv.stringify(uppercaseRecords, {
2221
cast: {
2322
string: (value: string, context: csv.stringifier.CastingContext) => {
2423
return context.index % 2 ? value.toLowerCase() : value.toUpperCase();
25-
}
24+
},
2625
},
2726
quoted: true,
2827
});

demo/esm/lib/parse.ts

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,28 @@
1-
2-
import assert from 'assert'
3-
import { parse, Parser } from 'csv-parse'
1+
import assert from "assert";
2+
import { parse, Parser } from "csv-parse";
43

54
const output: any = [];
65
// Create the parser
76
const parser: Parser = parse({
8-
delimiter: ':'
7+
delimiter: ":",
98
});
109
// Use the readable stream api to consume records
11-
parser.on('readable', function(){
12-
let record; while ((record = parser.read()) !== null) {
13-
output.push(record)
10+
parser.on("readable", function () {
11+
let record;
12+
while ((record = parser.read()) !== null) {
13+
output.push(record);
1414
}
1515
});
1616
// Catch any error
17-
parser.on('error', function(err){
18-
console.error(err.message)
17+
parser.on("error", function (err) {
18+
console.error(err.message);
1919
});
2020
// Test that the parsed records matched what's expected
21-
parser.on('end', function(){
22-
assert.deepStrictEqual(
23-
output,
24-
[
25-
[ 'a','b','c' ],
26-
[ '1','2','3' ]
27-
]
28-
)
21+
parser.on("end", function () {
22+
assert.deepStrictEqual(output, [
23+
["a", "b", "c"],
24+
["1", "2", "3"],
25+
]);
2926
});
3027
// Write data to the stream
3128
parser.write("a:b:c\n");

demo/esm/lib/parse_sync.ts

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,12 @@
1-
2-
import assert from 'assert'
3-
import { parse } from 'csv-parse/sync'
1+
import assert from "assert";
2+
import { parse } from "csv-parse/sync";
43

54
// Create the parser
6-
const records: [] = parse([
7-
"a:b:c\n",
8-
"1:2:3\n"
9-
].join(''), {
10-
delimiter: ':'
5+
const records: [] = parse(["a:b:c\n", "1:2:3\n"].join(""), {
6+
delimiter: ":",
117
});
128
// Test that the parsed records matched what's expected
13-
assert.deepStrictEqual(
14-
records,
15-
[
16-
[ 'a','b','c' ],
17-
[ '1','2','3' ]
18-
]
19-
);
9+
assert.deepStrictEqual(records, [
10+
["a", "b", "c"],
11+
["1", "2", "3"],
12+
]);

0 commit comments

Comments
 (0)