Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module.exports = {
parser: "@typescript-eslint/parser",
parserOptions: {
project: "./tsconfig.json"
project: "./tsconfig.build.json"
},
plugins: ["@typescript-eslint", "prettier"],
extends: [
Expand All @@ -14,8 +14,9 @@ module.exports = {
],
env: {
node: true,
mocha: true,
jest: true,
},
ignorePatterns: ["**/build", "**/node_modules"],
settings:{
"import/extensions": [
".ts"
Expand Down Expand Up @@ -51,6 +52,8 @@ module.exports = {
4,
{ "SwitchCase": 1 }
],
"import/prefer-default-export": 0,
"import/no-default-export": ["error"],
"no-restricted-syntax": ["error", "ForInStatement", "LabeledStatement", "WithStatement"],
"object-curly-spacing": ["error", "always"],
"no-underscore-dangle": 0,
Expand All @@ -65,7 +68,7 @@ module.exports = {
overrides: [
{
"files": [
"*.test.ts"
"*.spec.ts"
],
"rules": {
"@typescript-eslint/explicit-function-return-type": "off",
Expand All @@ -74,7 +77,8 @@ module.exports = {
},
{
"files": [
"*.js"
"*.js",
"examples/example-runner/bin/run-examples"
],
"rules": {
"@typescript-eslint/explicit-function-return-type": "off",
Expand Down
5 changes: 5 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ assignees: doug-martin, dustinsmith1024
**Describe the bug**
A clear and concise description of what the bug is.

**Parsing or Formatting?**

- [ ] Formatting
- [ ] Parsing

**To Reproduce**
Steps to reproduce the behavior:
1. Example file contents if applicable
Expand Down
5 changes: 5 additions & 0 deletions .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ assignees: doug-martin, dustinsmith1024

---

**Parsing or Formatting?**

- [ ] Formatting
- [ ] Parsing

**Is your feature request related to a problem? Please describe.**
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

Expand Down
6 changes: 4 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,7 @@ node_modules
benchmark/results
.nyc_output
build
**/tmp
coverage
coverage
**/*.tmp.csv
**/*.tsbuildinfo
lerna-debug.log
14 changes: 0 additions & 14 deletions .mocharc.js

This file was deleted.

24 changes: 0 additions & 24 deletions .nycrc

This file was deleted.

5 changes: 5 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,9 @@ node_js:
- "10"
- "8"

script:
- npm run bootstrap
- npm run build
- npm run test

after_success: npm run coverage
11 changes: 11 additions & 0 deletions History.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
# v4.0.0

* Migrated from mocha to jest
* Moved to `lerna`.
* Split `parse` and `format` packages
* Added running examples and checking output as part of the tests
* Updated docs for new directory layout
* Added typescript examples
* Added generics type support to format and parse streams
* [ADDED] Docs around using `strictColumnHandling` to emit errors when there are more columns than headers [#195]

# v3.7.0

* [ADDED] Ability to Transform Header [#287](https://github.com/C2FO/fast-csv/issues/287)
Expand Down
58 changes: 19 additions & 39 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,54 +7,33 @@

Fast-csv is library for parsing and formatting csvs or any other delimited value file in node.

## Installation
## Packages

`npm install -S fast-csv`
There are three packages published from this repo.

## Usage
### [`fast-csv`](./packages/fast-csv)

To use `fast-csv` in `javascript` you can require the module/
Exposes both formatting and parsing methods in a single package, use this if you need to parse and format files.

```js
const csv = require('fast-csv');
```
* [Docs](./packages/fast-csv/README.md)
* [JavaScript Examples](./examples/fast-csv-js/README.md)
* [TypeScript Examples](./examples/fast-csv-ts/README.md)

To import with typescript
###[`@fast-csv/parse`](./packages/parse)

```typescript
import * as csv from 'fast-csv';
```
Parsing package, use this if you only need to parse files.

## Documentation
* [Docs](./packages/parse/README.md)
* [JavaScript Examples](./examples/parsing-js/README.md)
* [TypeScript Examples](./examples/parsing-ts/README.md)

* [Parsing Docs](./docs/parsing.md)
* [Formatting Docs](./docs/formatting.md)
### [`@fast-csv/format`](./packages/format)

### Quick Examples

**parsing**

To read a csv with headers create a read stream and pipe it to parser.

```javascript
fs.createReadStream('path/to/my.csv')
.pipe(csv.parse({ headers: true }))
.on('data', row => console.log(row))
```

For more in depth parsing examples and docs check out the [parsing docs](./docs/parsing.md)

**formatting**

To format a csv you can write rows to a formatter.

```javascript
someStream
.pipe(csv.format({ headers: true })
.pipe(process.stdout);
```

For more in depth formatting examples and docs check out the [formatting docs](./docs/formatting.md)
Formatting package, use this if you only need to format files.

* [Docs](./packages/format/README.md)
* [JavaScript Examples](./examples/formatting-js/README.md)
* [TypeScript Examples](./examples/formatting-ts/README.md)

### Migrating from older versions

Expand All @@ -70,3 +49,4 @@ MIT <https://github.com/C2FO/fast-csv/raw/master/LICENSE>
* Twitter: [http://twitter.com/c2fo](http://twitter.com/c2fo) - 877.465.4045



File renamed without changes.
28 changes: 13 additions & 15 deletions benchmark/createData.js → examples/benchmark/createData.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,27 @@
const path = require('path');
const fastCsv = require('..');
const fastCsv = require('fast-csv');

const headers = [
[ 'first_name', 'last_name', 'email_address', 'address' ],
];
const headers = [['first_name', 'last_name', 'email_address', 'address']];

const nonQuotedLines = [
[ 'First1', 'Last1', 'email1@email.com', '1 Street St State ST 88888' ],
[ 'First1', 'Last1', 'email1@email.com', '' ],
[ 'First1', 'Last1', '', '' ],
[ 'First1', '', '', '' ],
[ '', '', '', '' ],
['First1', 'Last1', 'email1@email.com', '1 Street St State ST 88888'],
['First1', 'Last1', 'email1@email.com', ''],
['First1', 'Last1', '', ''],
['First1', '', '', ''],
['', '', '', ''],
];

const quotedLines = [
[ "First'1", '"Last1"', '"email1@email.com"', '1 Street St, State ST, 88888' ],
[ "First'1", '"Last1"', '"email1@email.com"', '""' ],
[ "First'1", '"Last1"', '""', '""' ],
[ "First'1", '""', '""', '""' ],
[ '""', '""', '""', '""' ],
["First'1", '"Last1"', '"email1@email.com"', '1 Street St, State ST, 88888'],
["First'1", '"Last1"', '"email1@email.com"', '""'],
["First'1", '"Last1"', '""', '""'],
["First'1", '""', '""', '""'],
['""', '""', '""', '""'],
];

const writeCsv = (count, lineOptions, filename) => {
console.log(`Writing ${filename}...`);
const rows = [ ...headers ];
const rows = [...headers];
const lineOptionLength = lineOptions.length;
for (let i = 0; i < count; i += 1) {
rows.push(lineOptions[i % lineOptionLength]);
Expand Down
4 changes: 2 additions & 2 deletions benchmark/index.js → examples/benchmark/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const path = require('path');
const fs = require('fs');
const fastCsv = require('..');
const fastCsv = require('fast-csv');

function camelize(str) {
return str.replace(/_(.)/g, (a, b) => b.toUpperCase());
Expand All @@ -10,7 +10,7 @@ const promisfyStream = (stream, expectedRows) => {
let count = 0;
return new Promise((res, rej) => {
stream
.on('data', row => {
.on('data', () => {
count += 1;
})
.on('end', () => {
Expand Down
12 changes: 12 additions & 0 deletions examples/benchmark/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "fast-csv-benchmarks",
"version": "4.0.0-alpha.0",
"private": true,
"description": "fast-csv examples",
"dependencies": {
"fast-csv": "^4.0.0-alpha.0"
},
"scripts": {
"benchmarks": "node ./index.js"
}
}
File renamed without changes.
Loading