# @jynnantonnyx/nest-csv-parser

> CSV parser for NestJS framework (forked from original nest-csv-parser)

Latest version **2.1.0** (published 2020-06-05) · MIT license · 0 weekly downloads

## Install

```sh
npm install @jynnantonnyx/nest-csv-parser
pnpm add @jynnantonnyx/nest-csv-parser
yarn add @jynnantonnyx/nest-csv-parser
bun add @jynnantonnyx/nest-csv-parser
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.1.0 |
| Published | 2020-06-05 |
| First published | 2020-06-05 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 6 |
| Unpacked size | 79.2 KB |
| Known vulnerabilities | 0 (+4 in 3 direct dependencies) |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Chad Patten |
| Maintainers | jynnantonnyx |
| Keywords | csv, parse, nest, nestjs |

## Links

- npm: https://www.npmjs.com/package/@jynnantonnyx/nest-csv-parser
- Repository: https://github.com/jynnantonnyx/nest-csv-parser
- Homepage: https://github.com/jynnantonnyx/nest-csv-parser#readme
- Issues: https://github.com/jynnantonnyx/nest-csv-parser/issues
- npm.io page: https://npm.io/package/@jynnantonnyx/nest-csv-parser

## Dependencies (6)

- [rxjs](https://npm.io/package/rxjs.md) ^6.5.5
- [csv-parser](https://npm.io/package/csv-parser.md) 2.3.2
- [@nestjs/core](https://npm.io/package/@nestjs/core.md) 6.11.11
- [@nestjs/common](https://npm.io/package/@nestjs/common.md) 6.11.11
- [reflect-metadata](https://npm.io/package/reflect-metadata.md) 0.1.13
- [class-transformer](https://npm.io/package/class-transformer.md) 0.2.3

## Alternatives

- [csv-to-markdown-table](https://npm.io/package/csv-to-markdown-table.md) — 47.0K weekly downloads
- [@sapphire/ratelimits](https://npm.io/package/@sapphire/ratelimits.md) — 4.4K weekly downloads
- [js-csvparser](https://npm.io/package/js-csvparser.md) — 2.0K weekly downloads
- [@adadapted/js-sdk](https://npm.io/package/@adadapted/js-sdk.md) — 251 weekly downloads
- [@grapecity/spread-sheets-sparklines](https://npm.io/package/@grapecity/spread-sheets-sparklines.md) — 103 weekly downloads

## Recent versions

- 2.1.0 (latest) — 2020-06-05

## README

# CSV Parser for NestJS

[Nest](https://github.com/nestjs/nest) framework library.

Wrapper for [csv-parser library](https://github.com/mafintosh/csv-parser)

This project is a fork of the original [nest-csv-parser](https://github.com/mCzolko/nest-csv-parser).

Additions in this version:
* The ability to inspect the headers that were parsed (via the `ParsedData.headers` field)

## Installation

```bash
$ npm install @jynnantonnyx/nest-csv-parser
# or if you using Yarn
$ yarn add @jynnantonnyx/nest-csv-parser
```

Add `@jynnantonnyx/nest-csv-parser` as a dependency.

```js
import { Module } from '@nestjs/common'
import { CsvModule } from '@jynnantonnyx/nest-csv-parser'
// ...imports of your app dependecies

@Module({
  imports: [
    CsvModule, // <-- add into imports
    ...
  ],
  controllers: [ ... ],
  providers: [ ... ]
})
export class AppModule {}
```

## Usage

Parser will create instance of entity for each line in CSV stream.

```js
// app.parser.ts
import { Injectable } from '@nestjs/common'
import { CsvParser } from '@jynnantonnyx/nest-csv-parser'

class Entity {
  foo: string
  bar: string
}

@Injectable()
export class AppService {
  constructor(
    private readonly csvParser: CsvParser
  ) {}

  async parse() {
    // Create stream from file (or get it from S3)
    const stream = fs.createReadStream(__dirname + '/some.csv');
    const data: ParsedData<Entitiy> data = await csvParser.parse(stream, Entity);
    const entities: Entity[] = data.list;

    // Inspect headers
    const headers: string[] = data.headers;

    return entities;
  }
}
```

## API

`csvParser.parse(stream, Entity, count, offset, csvConfig)` has 5 parameters.

### stream

required

First parameter has to be the stream of the CSV file. [NodeJS Reference](https://nodejs.org/api/stream.html)

### Entity

required

Has to be object from which will parser create instance.

### count (optional)

default: null

How many lines you want to parse.

### offset (optional)

default: null

Offset is similar to SQL databases. Skips the N lines from the beginning of the file.

### csvConfig (optional)

default

```js
{ strict: true, separator: ';' }
```

Just a configuration object  for [csv-parser library](https://github.com/mafintosh/csv-parser) options you can find [here](https://github.com/mafintosh/csv-parser#api)

## Development

```bash
# clone repository
$ git clone git@github.com:jynnantonnyx/nest-csv-parser.git
$ cd nest-csv-parser

# install dependencies
$ npm install

# watch mode
$ npm test:watch
```

## Test

```bash
# unit tests
$ npm test
```

---
_Source: https://npm.io/package/@jynnantonnyx/nest-csv-parser · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
