Git Product home page Git Product logo

nest-csv-parser's Introduction

Nest Logo

A progressive Node.js framework for building efficient and scalable server-side applications, heavily inspired by Angular.

NPM Version Package License NPM Downloads CircleCI Builds Coverage Status

CSV Parser for NestJS

Nest framework TypeScript starter repository.

Wrapper for csv-parser library

Installation

$ npm install nest-csv-parser
# or if you using Yarn
$ yarn add nest-csv-parser

Add nest-csv-parser as a dependency.

import { Module } from '@nestjs/common'
import { CsvModule } from '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.

// app.parser.ts
import { Injectable } from '@nestjs/common'
import { CsvParser } from '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 entities: Entity[] = await csvParser.parse(stream, Entity)

    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

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

{ strict: true, separator: ';' }

Just a configuration object for csv-parser library options you can find here

Development

# clone repository
$ git clone [email protected]:mCzolko/nest-csv-parser.git
$ cd nest-csv-parser

# install dependencies
$ yarn install

# watch mode
$ yarn test:watch

Test

# unit tests
$ yarn test

Author

Michael Czolko

ko-fi

nest-csv-parser's People

Contributors

mczolko avatar renovate-bot avatar renovate[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

nest-csv-parser's Issues

v2 has no exported member 'CsvModule`

I upgraded the package and received this error:

TSError: โจฏ Unable to compile TypeScript:
src/modules/elements/element.module.ts:4:10 - error TS2305: Module '"../../../../../node_modules/nest-csv-parser"' has no exported member 'CsvModule'.

4 import { CsvModule } from 'nest-csv-parser';
           ~~~~~~~~~

How to add multiple separators

How can I add multiple separators, currently the documentation only describes how to change the default one.

In my case I need to separate with a ,and a ;.

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Rate-Limited

These updates are currently rate-limited. Click on a checkbox below to force their creation now.

  • Update dependency @types/node to v11.15.54
  • Update dependency reflect-metadata to v0.2.2
  • Update Node.js to v17
  • Update dependency node to v20 (node, @types/node)
  • Update dependency prettier to v3
  • Update dependency ts-node to v10
  • Update dependency tsc-watch to v6
  • Update dependency tsconfig-paths to v4
  • Update dependency tslint to v6
  • Update dependency typescript to v5
  • Update nest monorepo to v10 (major) (@nestjs/common, @nestjs/testing)
  • ๐Ÿ” Create all rate-limited PRs at once ๐Ÿ”

Edited/Blocked

These updates have been manually edited so Renovate will no longer make changes. To discard all commits and start over, click on a checkbox.

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

circleci
.circleci/config.yml
  • circleci/node 10.22.1
  • circleci/node 10.22.1
  • circleci/node 10.22.1
npm
package.json
  • @nestjs/common 7.4.4
  • @nestjs/core 7.4.4
  • class-transformer 0.3.1
  • csv-parser 2.3.3
  • reflect-metadata 0.1.13
  • rxjs 6.6.2
  • @nestjs/testing 7.4.4
  • @types/jest 26.0.5
  • @types/node 11.15.20
  • coveralls 3.1.0
  • jest 26.1.0
  • prettier 2.0.5
  • ts-jest 26.1.3
  • ts-node 8.10.2
  • tsc-watch 4.2.9
  • tsconfig-paths 3.9.0
  • tslint 5.20.1
  • typescript 3.9.7
nvm
.nvmrc
  • node 10.22.1

  • Check this box to trigger a request for Renovate to run again on this repository

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.