Skip to content

Commit

Permalink
build: apply lint to demo and exclude dist
Browse files Browse the repository at this point in the history
  • Loading branch information
wdavidw committed Nov 20, 2024
1 parent 1213de8 commit 7335c6d
Show file tree
Hide file tree
Showing 29 changed files with 414 additions and 375 deletions.
57 changes: 43 additions & 14 deletions demo/browser/server.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@

import express from 'express';
import path from 'path';
import { fileURLToPath } from 'url';
import express from "express";
import path from "path";
import { fileURLToPath } from "url";
const __dirname = path.dirname(fileURLToPath(import.meta.url));

const app = express();
Expand All @@ -12,16 +11,46 @@ const port = 3000;
// console.log(parse);

app.use(express.static(__dirname));
app.use('/lib/esm/csv/', express.static(`${__dirname}/../../packages/csv/dist/esm/`));
app.use('/lib/esm/generate/', express.static(`${__dirname}/../../packages/csv-generate/dist/esm/`));
app.use('/lib/esm/parse/', express.static(`${__dirname}/../../packages/csv-parse/dist/esm/`));
app.use('/lib/esm/transform/', express.static(`${__dirname}/../../packages/stream-transform/dist/esm/`));
app.use('/lib/esm/stringify/', express.static(`${__dirname}/../../packages/csv-stringify/dist/esm/`));
app.use('/lib/iife/csv/', express.static(`${__dirname}/../../packages/csv/dist/iife/`));
app.use('/lib/iife/generate/', express.static(`${__dirname}/../../packages/csv-generate/dist/iife/`));
app.use('/lib/iife/parse/', express.static(`${__dirname}/../../packages/csv-parse/dist/iife/`));
app.use('/lib/iife/transform/', express.static(`${__dirname}/../../packages/stream-transform/dist/iife/`));
app.use('/lib/iife/stringify/', express.static(`${__dirname}/../../packages/csv-stringify/dist/iife/`));
app.use(
"/lib/esm/csv/",
express.static(`${__dirname}/../../packages/csv/dist/esm/`),
);
app.use(
"/lib/esm/generate/",
express.static(`${__dirname}/../../packages/csv-generate/dist/esm/`),
);
app.use(
"/lib/esm/parse/",
express.static(`${__dirname}/../../packages/csv-parse/dist/esm/`),
);
app.use(
"/lib/esm/transform/",
express.static(`${__dirname}/../../packages/stream-transform/dist/esm/`),
);
app.use(
"/lib/esm/stringify/",
express.static(`${__dirname}/../../packages/csv-stringify/dist/esm/`),
);
app.use(
"/lib/iife/csv/",
express.static(`${__dirname}/../../packages/csv/dist/iife/`),
);
app.use(
"/lib/iife/generate/",
express.static(`${__dirname}/../../packages/csv-generate/dist/iife/`),
);
app.use(
"/lib/iife/parse/",
express.static(`${__dirname}/../../packages/csv-parse/dist/iife/`),
);
app.use(
"/lib/iife/transform/",
express.static(`${__dirname}/../../packages/stream-transform/dist/iife/`),
);
app.use(
"/lib/iife/stringify/",
express.static(`${__dirname}/../../packages/csv-stringify/dist/iife/`),
);

app.listen(port, () => {
console.log(`Example app listening at http://localhost:${port}`);
Expand Down
53 changes: 29 additions & 24 deletions demo/cjs/lib/csv.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,33 @@

// Import the package main module
const csv = require('csv');
const csv = require("csv");

// Run the pipeline
csv
// Generate 20 records
.generate({
delimiter: '|',
length: 20
})
// Transform CSV data into records
.pipe(csv.parse({
delimiter: '|'
}))
// Transform each value into uppercase
.pipe(csv.transform((record) => {
return record.map((value) => {
return value.toUpperCase()
});
}))
// Convert objects into a stream
.pipe(csv.stringify({
quoted: true,
encoding: 'utf8' // Support for Node.js 8
}))
// Print the CSV stream to stdout
.pipe(process.stdout, {end: false})
// Generate 20 records
.generate({
delimiter: "|",
length: 20,
})
// Transform CSV data into records
.pipe(
csv.parse({
delimiter: "|",
}),
)
// Transform each value into uppercase
.pipe(
csv.transform((record) => {
return record.map((value) => {
return value.toUpperCase();
});
}),
)
// Convert objects into a stream
.pipe(
csv.stringify({
quoted: true,
encoding: "utf8", // Support for Node.js 8
}),
)
// Print the CSV stream to stdout
.pipe(process.stdout, { end: false });
21 changes: 9 additions & 12 deletions demo/cjs/lib/csv_sync.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,25 @@

// Import the package sync module
const version = parseInt(/^v(\d+)/.exec(process.version)[1], 10)
const csv = require(
version >= 14 ? 'csv/sync' : 'csv/dist/cjs/sync.cjs'
);
const version = parseInt(/^v(\d+)/.exec(process.version)[1], 10);
const csv = require(version >= 14 ? "csv/sync" : "csv/dist/cjs/sync.cjs");

// Generate 20 records
const input = csv.generate({
delimiter: '|',
length: 20
delimiter: "|",
length: 20,
});
// Transform CSV data into records
const records = csv.parse(input, {
delimiter: '|'
delimiter: "|",
});
// Transform each value into uppercase
const uppercaseRecords = csv.transform(records, (record) => {
return record.map((value) => {
return value.toUpperCase()
});
return record.map((value) => {
return value.toUpperCase();
});
});
// Convert objects into a stream
const output = csv.stringify(uppercaseRecords, {
quoted: true
quoted: true,
});
// Print the CSV stream to stdout
process.stdout.write(output);
31 changes: 14 additions & 17 deletions demo/cjs/lib/parse.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,28 @@

const assert = require('node:assert');
const { parse } = require('csv-parse');
const assert = require("node:assert");
const { parse } = require("csv-parse");

const output = [];
// Create the parser
const parser = parse({
delimiter: ':'
delimiter: ":",
});
// Use the readable stream api to consume records
parser.on('readable', function(){
let record; while ((record = parser.read()) !== null) {
output.push(record)
parser.on("readable", function () {
let record;
while ((record = parser.read()) !== null) {
output.push(record);
}
});
// Catch any error
parser.on('error', function(err){
console.error(err.message)
parser.on("error", function (err) {
console.error(err.message);
});
// Test that the parsed records matched what's expected
parser.on('end', function(){
assert.deepStrictEqual(
output,
[
[ 'a','b','c' ],
[ '1','2','3' ]
]
)
parser.on("end", function () {
assert.deepStrictEqual(output, [
["a", "b", "c"],
["1", "2", "3"],
]);
});
// Write data to the stream
parser.write("a:b:c\n");
Expand Down
25 changes: 9 additions & 16 deletions demo/cjs/lib/parse_sync.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,15 @@

const assert = require('node:assert');
const version = parseInt(/^v(\d+)/.exec(process.version)[1], 10)
const assert = require("node:assert");
const version = parseInt(/^v(\d+)/.exec(process.version)[1], 10);
const { parse } = require(
version >= 14 ? 'csv-parse/sync' : 'csv-parse/dist/cjs/sync.cjs'
version >= 14 ? "csv-parse/sync" : "csv-parse/dist/cjs/sync.cjs",
);

// Create the parser
const records = parse([
"a:b:c\n",
"1:2:3\n"
].join(''), {
delimiter: ':'
const records = parse(["a:b:c\n", "1:2:3\n"].join(""), {
delimiter: ":",
});
// Test that the parsed records matched what's expected
assert.deepStrictEqual(
records,
[
[ 'a','b','c' ],
[ '1','2','3' ]
]
);
assert.deepStrictEqual(records, [
["a", "b", "c"],
["1", "2", "3"],
]);
8 changes: 4 additions & 4 deletions demo/eslint/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ module.exports = {
es2021: true,
},
// Adding airbnb-base throw an error
extends: ['eslint:recommended', 'plugin:import/recommended', 'airbnb-base'],
extends: ["eslint:recommended", "plugin:import/recommended", "airbnb-base"],
parserOptions: {
ecmaVersion: 'latest',
ecmaVersion: "latest",
},
rules: {
'import/no-unresolved': [2, { commonjs: false }],
'no-console': 'off',
"import/no-unresolved": [2, { commonjs: false }],
"no-console": "off",
},
};
4 changes: 2 additions & 2 deletions demo/eslint/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { stringify } = require('csv-stringify/sync');
const { stringify } = require("csv-stringify/sync");

const output = stringify([['a', 'b', 'c']]);
const output = stringify([["a", "b", "c"]]);

console.log(output);
51 changes: 28 additions & 23 deletions demo/esm/lib/csv.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,32 @@

// Import the package main module
import * as csv from 'csv'
import * as csv from "csv";

// Run the pipeline
csv
// Generate 20 records
.generate({
delimiter: '|',
length: 20
})
// Transform CSV data into records
.pipe(csv.parse({
delimiter: '|'
}))
// Transform each value into uppercase
.pipe(csv.transform((record) => {
return record.map((value) => {
return value.toUpperCase()
});
}))
// Convert objects into a stream
.pipe(csv.stringify({
quoted: true
}))
// Print the CSV stream to stdout
.pipe(process.stdout)
// Generate 20 records
.generate({
delimiter: "|",
length: 20,
})
// Transform CSV data into records
.pipe(
csv.parse({
delimiter: "|",
}),
)
// Transform each value into uppercase
.pipe(
csv.transform((record) => {
return record.map((value) => {
return value.toUpperCase();
});
}),
)
// Convert objects into a stream
.pipe(
csv.stringify({
quoted: true,
}),
)
// Print the CSV stream to stdout
.pipe(process.stdout);
17 changes: 8 additions & 9 deletions demo/esm/lib/csv_sync.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@

// Import the package sync module
import * as csv from 'csv/sync';
import * as csv from "csv/sync";

// Generate 20 records
const input = csv.generate({
delimiter: '|',
length: 20
delimiter: "|",
length: 20,
});
// Transform CSV data into records
const records = csv.parse(input, {
delimiter: '|'
delimiter: "|",
});
// Transform each value into uppercase
const uppercaseRecords = csv.transform(records, (record) => {
return record.map((value) => {
return value.toUpperCase()
});
return record.map((value) => {
return value.toUpperCase();
});
});
// Convert objects into a stream
const output = csv.stringify(uppercaseRecords, {
quoted: true
quoted: true,
});
// Print the CSV stream to stdout
process.stdout.write(output);
Loading

0 comments on commit 7335c6d

Please sign in to comment.