Skip to content

Commit

Permalink
build: prettify and lint staged files
Browse files Browse the repository at this point in the history
  • Loading branch information
wdavidw committed Aug 26, 2024
1 parent 09855f5 commit 8157783
Show file tree
Hide file tree
Showing 12 changed files with 175 additions and 142 deletions.
1 change: 1 addition & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
npm run lint:staged
10 changes: 8 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@
"cz-conventional-changelog": "^3.3.0",
"glob": "^11.0.0",
"husky": "^9.1.5",
"lerna": "^8.1.8"
"lerna": "^8.1.8",
"lint-staged": "^15.2.9"
},
"lint-staged": {
"*.js": "npm run lint:fix",
"*.md": "prettier -w"
},
"repository": {
"type": "git",
Expand All @@ -18,7 +23,8 @@
"publish": "lerna publish from-git --yes",
"lint:check": "lerna run lint:check",
"lint:fix": "lerna run lint:fix",
"pretest": "npm run lint",
"lint:staged": "npx lint-staged",
"pretest": "npm run build",
"test": "lerna run test",
"test:legacy": "lerna run test:legacy",
"version": "lerna version"
Expand Down
44 changes: 22 additions & 22 deletions packages/csv-generate/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

# CSV generator for Node.js and the web

[![Build Status](https://img.shields.io/github/actions/workflow/status/adaltas/node-csv/nodejs.yml?branch=master)](https://github.com/adaltas/node-csv/actions)
Expand All @@ -9,19 +8,19 @@ The [`csv-generate` package](https://csv.js.org/generate/) provides a flexible g

## Documentation

* [Project homepage](https://csv.js.org/generate/)
* [API](https://csv.js.org/generate/api/)
* [Options](https://csv.js.org/generate/options/)
* [Examples](https://csv.js.org/generate/examples/)
- [Project homepage](https://csv.js.org/generate/)
- [API](https://csv.js.org/generate/api/)
- [Options](https://csv.js.org/generate/options/)
- [Examples](https://csv.js.org/generate/examples/)

## Main features

* Scalable `stream.Readable` implementation
* random or pseudo-random seed based generation
* Idempotence with the "seed" option
* User-defined value generation
* Multiple types of values (integer, boolean, dates, ...)
* MIT License
- Scalable `stream.Readable` implementation
- random or pseudo-random seed based generation
- Idempotence with the "seed" option
- User-defined value generation
- Multiple types of values (integer, boolean, dates, ...)
- MIT License

## Usage

Expand All @@ -34,39 +33,40 @@ Use the callback and sync APIs for simplicity or the stream based API for scalab
The [API](https://csv.js.org/generate/api/) is available in multiple flavors. This example illustrates the stream API.

```js
import { generate } from 'csv-generate';
import assert from 'assert';
import { generate } from "csv-generate";
import assert from "assert";

const records = [];
// Initialize the generator
generate({
seed: 1,
objectMode: true,
columns: 2,
length: 2
length: 2,
})
// Use the readable stream api to consume generated records
.on('readable', function(){
let record; while((record = this.read()) !== null){
.on("readable", function () {
let record;
while ((record = this.read()) !== null) {
records.push(record);
}
})
// Catch any error
.on('error', function(err){
.on("error", function (err) {
console.error(err);
})
// Test that the generated records matched the expected records
.on('end', function(){
.on("end", function () {
assert.deepEqual(records, [
[ 'OMH', 'ONKCHhJmjadoA' ],
[ 'D', 'GeACHiN' ]
["OMH", "ONKCHhJmjadoA"],
["D", "GeACHiN"],
]);
});
```

## Development

Tests are executed with [Mocha](https://mochajs.org/). To install it, simple run `npm install` followed by `npm test`. It will install mocha and its dependencies in your project "node_modules" directory and run the test suite. The tests run against the CoffeeScript source files.
Tests are executed with [Mocha](https://mochajs.org/). To install it, simple run `npm install` followed by `npm test`. It will install mocha and its dependencies in your project "node_modules" directory and run the test suite. The tests run against the CoffeeScript source files.

To generate the JavaScript files, run `npm run coffee`.

Expand All @@ -76,4 +76,4 @@ The test suite is run online with [Travis](https://travis-ci.org/#!/adaltas/node

The project is sponsored by [Adaltas](https://www.adaltas.com), an Big Data consulting firm based in Paris, France.

* David Worms: <https://github.com/wdavidw>
- David Worms: <https://github.com/wdavidw>
9 changes: 7 additions & 2 deletions packages/csv-generate/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@
"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",
Expand All @@ -100,8 +104,9 @@
"build:rollup": "npx rollup -c",
"build:ts": "cp lib/index.d.ts dist/cjs/index.d.cts && cp lib/stream.d.ts dist/cjs/stream.d.cts && cp lib/sync.d.ts dist/cjs/sync.d.cts && cp lib/*.ts dist/esm",
"postbuild:ts": "find dist/cjs -name '*.d.cts' -exec sh -c \"sed -i \"s/\\.js'/\\.cjs'/g\" {} || sed -i '' \"s/\\.js'/\\.cjs'/g\" {}\" \\;",
"lint:check": "eslint && tsc --noEmit true",
"lint:fix": "eslint --fix && tsc --noEmit true",
"lint:check": "eslint",
"lint:fix": "eslint --fix",
"lint:ts": "tsc --noEmit true",
"preversion": "npm run build && git add dist",
"pretest": "npm run build",
"test": "mocha 'test/**/*.{coffee,ts}'",
Expand Down
62 changes: 29 additions & 33 deletions packages/csv-parse/README.md
Original file line number Diff line number Diff line change
@@ -1,36 +1,35 @@

# CSV parser for Node.js and the web

[![Build Status](https://img.shields.io/github/actions/workflow/status/adaltas/node-csv/nodejs.yml?branch=master)](https://github.com/adaltas/node-csv/actions)
[![NPM](https://img.shields.io/npm/dm/csv-parse)](https://www.npmjs.com/package/csv-parse)
[![NPM](https://img.shields.io/npm/v/csv-parse)](https://www.npmjs.com/package/csv-parse)

The [`csv-parse` package](https://csv.js.org/parse/) is a parser converting CSV text input into arrays or objects. It is part of the [CSV project](https://csv.js.org/).

It implements the Node.js [`stream.Transform` API](http://nodejs.org/api/stream.html#stream_class_stream_transform). It also provides a simple callback-based API for convenience. It is both extremely easy to use and powerful. It was first released in 2010 and is used against big data sets by a large community.

## Documentation

* [Project homepage](https://csv.js.org/parse/)
* [API](https://csv.js.org/parse/api/)
* [Options](https://csv.js.org/parse/options/)
* [Info properties](https://csv.js.org/parse/info/)
* [Common errors](https://csv.js.org/parse/errors/)
* [Examples](https://csv.js.org/project/examples/)
- [Project homepage](https://csv.js.org/parse/)
- [API](https://csv.js.org/parse/api/)
- [Options](https://csv.js.org/parse/options/)
- [Info properties](https://csv.js.org/parse/info/)
- [Common errors](https://csv.js.org/parse/errors/)
- [Examples](https://csv.js.org/project/examples/)

## Main features

* Flexible with lot of [options](https://csv.js.org/parse/options/)
* Multiple [distributions](https://csv.js.org/parse/distributions/): Node.js, Web, ECMAScript modules and CommonJS
* Follow the Node.js streaming API
* Simplicity with the optional callback API
* Support delimiters, quotes, escape characters and comments
* Line breaks discovery
* Support big datasets
* Complete test coverage and lot of samples for inspiration
* No external dependencies
* Work nicely with the [csv-generate](https://csv.js.org/generate/), [stream-transform](https://csv.js.org/transform/) and [csv-stringify](https://csv.js.org/stringify/) packages
* MIT License
- Flexible with lot of [options](https://csv.js.org/parse/options/)
- Multiple [distributions](https://csv.js.org/parse/distributions/): Node.js, Web, ECMAScript modules and CommonJS
- Follow the Node.js streaming API
- Simplicity with the optional callback API
- Support delimiters, quotes, escape characters and comments
- Line breaks discovery
- Support big datasets
- Complete test coverage and lot of samples for inspiration
- No external dependencies
- Work nicely with the [csv-generate](https://csv.js.org/generate/), [stream-transform](https://csv.js.org/transform/) and [csv-stringify](https://csv.js.org/stringify/) packages
- MIT License

## Usage

Expand All @@ -43,34 +42,31 @@ Use the callback and sync APIs for simplicity or the stream based API for scalab
The [API](https://csv.js.org/parse/api/) is available in multiple flavors. This example illustrates the stream API.

```js
import assert from 'assert';
import { parse } from 'csv-parse';
import assert from "assert";
import { parse } from "csv-parse";

const records = [];
// Initialize the parser
const parser = parse({
delimiter: ':'
delimiter: ":",
});
// Use the readable stream api to consume records
parser.on('readable', function(){
parser.on("readable", function () {
let record;
while ((record = parser.read()) !== null) {
records.push(record);
}
});
// Catch any error
parser.on('error', function(err){
parser.on("error", function (err) {
console.error(err.message);
});
// Test that the parsed records matched the expected records
parser.on('end', function(){
assert.deepStrictEqual(
records,
[
[ 'root','x','0','0','root','/root','/bin/bash' ],
[ 'someone','x','1022','1022','','/home/someone','/bin/bash' ]
]
);
parser.on("end", function () {
assert.deepStrictEqual(records, [
["root", "x", "0", "0", "root", "/root", "/bin/bash"],
["someone", "x", "1022", "1022", "", "/home/someone", "/bin/bash"],
]);
});
// Write data to the stream
parser.write("root:x:0:0:root:/root:/bin/bash\n");
Expand All @@ -83,4 +79,4 @@ parser.end();

The project is sponsored by [Adaltas](https://www.adaltas.com), an Big Data consulting firm based in Paris, France.

* David Worms: <https://github.com/wdavidw>
- David Worms: <https://github.com/wdavidw>
9 changes: 7 additions & 2 deletions packages/csv-parse/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@
"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",
Expand All @@ -113,8 +117,9 @@
"build:rollup": "npx rollup -c",
"build:ts": "cp lib/index.d.ts dist/cjs/index.d.cts && cp lib/sync.d.ts dist/cjs/sync.d.cts && cp lib/*.ts dist/esm",
"postbuild:ts": "find dist/cjs -name '*.d.cts' -exec sh -c \"sed -i \"s/\\.js'/\\.cjs'/g\" {} || sed -i '' \"s/\\.js'/\\.cjs'/g\" {}\" \\;",
"lint:check": "eslint && tsc --noEmit true",
"lint:fix": "eslint --fix && tsc --noEmit true",
"lint:check": "eslint",
"lint:fix": "eslint --fix",
"lint:ts": "tsc --noEmit true",
"preversion": "npm run build && git add dist",
"pretest": "npm run build",
"test": "mocha 'test/**/*.{coffee,ts}'",
Expand Down
37 changes: 18 additions & 19 deletions packages/csv-stringify/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

# CSV stringifier for Node.js and the web

[![Build Status](https://img.shields.io/github/actions/workflow/status/adaltas/node-csv/nodejs.yml?branch=master)](https://github.com/adaltas/node-csv/actions)
Expand All @@ -9,21 +8,21 @@ The [`csv-stringify` package](https://csv.js.org/stringify/) is a stringifier co

## Documentation

* [Project homepage](https://csv.js.org/stringify/)
* [API](https://csv.js.org/stringify/api/)
* [Options](https://csv.js.org/stringify/options/)
* [Examples](https://csv.js.org/stringify/examples/)
- [Project homepage](https://csv.js.org/stringify/)
- [API](https://csv.js.org/stringify/api/)
- [Options](https://csv.js.org/stringify/options/)
- [Examples](https://csv.js.org/stringify/examples/)

## Main features

* Follow the Node.js streaming API
* Simplicity with the optional callback API
* Support for custom formatters, delimiters, quotes, escape characters and header
* Support big datasets
* Complete test coverage and samples for inspiration
* Only 1 external dependency
* to be used conjointly with `csv-generate`, `csv-parse` and `stream-transform`
* MIT License
- Follow the Node.js streaming API
- Simplicity with the optional callback API
- Support for custom formatters, delimiters, quotes, escape characters and header
- Support big datasets
- Complete test coverage and samples for inspiration
- Only 1 external dependency
- to be used conjointly with `csv-generate`, `csv-parse` and `stream-transform`
- MIT License

## Usage

Expand All @@ -36,15 +35,15 @@ The module is built on the Node.js Stream API. Use the callback and sync APIs fo
The [API](https://csv.js.org/stringify/api/) is available in multiple flavors. This example illustrates the sync API.

```js
import { stringify } from 'csv-stringify/sync';
import assert from 'assert';
import { stringify } from "csv-stringify/sync";
import assert from "assert";

const output = stringify([
[ '1', '2', '3', '4' ],
[ 'a', 'b', 'c', 'd' ]
["1", "2", "3", "4"],
["a", "b", "c", "d"],
]);

assert.equal(output, '1,2,3,4\na,b,c,d\n');
assert.equal(output, "1,2,3,4\na,b,c,d\n");
```

## Development
Expand All @@ -59,4 +58,4 @@ The test suite is run online with [Travis](https://travis-ci.org/#!/adaltas/node

The project is sponsored by [Adaltas](https://www.adaltas.com), an Big Data consulting firm based in Paris, France.

* David Worms: <https://github.com/wdavidw>
- David Worms: <https://github.com/wdavidw>
9 changes: 7 additions & 2 deletions packages/csv-stringify/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@
"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",
Expand All @@ -90,8 +94,9 @@
"build:rollup": "npx rollup -c",
"build:ts": "cp lib/index.d.ts dist/cjs/index.d.cts && cp lib/sync.d.ts dist/cjs/sync.d.cts && cp lib/*.ts dist/esm",
"postbuild:ts": "find dist/cjs -name '*.d.cts' -exec sh -c \"sed -i \"s/\\.js'/\\.cjs'/g\" {} || sed -i '' \"s/\\.js'/\\.cjs'/g\" {}\" \\;",
"lint:check": "eslint && tsc --noEmit true",
"lint:fix": "eslint --fix && tsc --noEmit true",
"lint:check": "eslint",
"lint:fix": "eslint --fix",
"lint:ts": "tsc --noEmit true",
"preversion": "npm run build && git add dist",
"pretest": "npm run build",
"test": "mocha 'test/**/*.{coffee,ts}'",
Expand Down
Loading

0 comments on commit 8157783

Please sign in to comment.