@neurodevs/node-csv-loader
TypeScript icon, indicating that this package has built-in type declarations

0.2.4 • Public • Published

node-csv-loader

A simple CSV file loader

Installation

Install the package using npm:

npm install @neurodevs/node-csv-loader

Or yarn:

yarn add @neurodevs/node-csv-loader

Usage

Basic Usage

To load a CSV file:

import { CsvLoaderImpl } from '@neurodevs/node-csv-loader'

async function loadCsv() {
  const loader = CsvLoaderImpl.Create()
  const data = await loader.load('/path/to/csv')
  console.log(data)
}

Disable Path Validation

This class automatically performs the following validations on the path you pass to the load method:

  • Asserts that you passed a path
  • Asserts that the file exists at the path
  • Asserts that the file extension is '.csv'

To turn off path validation (e.g., when you are certain of the file's existence or extension):

import { CsvLoaderImpl } from '@neurodevs/node-csv-loader'

const loader = CsvLoaderImpl.Create({ shouldValidatePath: false })

Testing

You can use the following test doubles for unit testing purposes:

import {
  CsvLoaderImpl,
  FakeCsvLoader,
  SpyCsvLoader
} from '@neurodevs/node-csv-loader'

// Use FakeCsvLoader for simulating inputs and outputs in tests
CsvLoaderImpl.Class = FakeCsvLoader

// Use SpyCsvLoader to test real behavior with enhanced internal visibility
CsvLoaderImpl.Class = SpyCsvLoader

const loader = CsvLoaderImpl.Create()
  • FakeCsvLoader: Provides a fake implementation to simulate CSV loading for testing.
  • SpyCsvLoader: Wraps the real implementation with enhanced visibility for inspecting internal behavior during testing.

Readme

Keywords

none

Package Sidebar

Install

npm i @neurodevs/node-csv-loader

Weekly Downloads

2

Version

0.2.4

License

none

Unpacked Size

31.2 kB

Total Files

41

Last publish

Collaborators

  • ericthecurious