npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

csv-import-service

v0.2.0

Published

import-service

Readme

import-service

A lightweight, streaming, extensible TypeScript data-import-library for building data import pipelines.

Unlike traditional CSV libraries that only parse files, Import Service provides a complete import pipeline:

  Reader
     │
     ▼
Transformer
     │
     ▼
 Validator (optional)
     │
     ▼
   Writer
     │
     ▼
 Destination

It is designed for importing data from CSV, fixed-length files, delimited text, Excel, databases, queues, or any custom data source.

Detailed Flow

Import flow with data validation


Features

  • Streaming import using AsyncIterable
  • Generic type-safe pipeline
  • CSV transformer
  • Fixed-length record transformer
  • Custom delimiter support
  • Optional validation
  • Pluggable writers
  • Configurable exception handling
  • Configurable validation error handling
  • Automatic type conversion
  • Customizable primitive parsers
  • Large file friendly
  • Zero framework dependency

Installation

npm install import-service

or

yarn add import-service

Architecture

                AsyncIterable
                      │
                      ▼
                ImportService
                      │
         ┌────────────┼────────────┐
         ▼            ▼            ▼
   Transformer     Validator     Writer
         │            │            │
         └────────────┴────────────┘
                      │
                 Error Handler

Every component is independent.

Ports and adapters architecture

Hexagonal Architecture


Quick Example

const reader = await createReader("customers.csv")

const importer = new Importer(
    1,
    "customers.csv",
    reader,
    transformer.transform,
    writer.write
)

const result = await importer.import()

console.log(result)

Examples:


Using ImportService

ImportService follows an object-oriented style similar to Java dependency injection.

const service = new ImportService(
    1,
    "customers.csv",
    reader,
    transformer,
    writer,
    exceptionHandler,
    validator,
    errorHandler
)

await service.import()

Using Importer

Importer is a lightweight functional API inspired by JavaScript and Go.

const importer = new Importer(
    1,
    filename,
    reader,
    transformer.transform,
    writer.write,
    writer.flush,
    handleException,
    validate,
    handleError
)

await importer.import()

Choose the API that best matches your programming style.


CSV Transformer

Define a schema.

const attributes = {
    id: {
        type: "number"
    },
    name: {
        type: "string"
    },
    birthday: {
        type: "date"
    },
    active: {
        type: "boolean"
    }
}

Create a transformer.

const transformer = new CSVTransformer<Customer>(attributes)

Each row becomes

{
    id: 1,
    name: "John",
    birthday: Date,
    active: true
}

Fixed-Length Files

000001John Smith         19880101Y

Define field lengths.

const attrs = {
    id: {
        type: "number",
        length: 6
    },
    name: {
        type: "string",
        length: 20
    },
    birthday: {
        type: "date",
        length: 8
    },
    active: {
        type: "boolean",
        length: 1
    }
}

Then

const transformer = new FixedLengthTransformer<Customer>(attrs)

Validation

Validation is optional.

class CustomerValidator implements Validator<Customer> {
    async validate(customer) {
        const errors = []
        if (!customer.name) {
            errors.push({
                field: "name",
                code: "required"
            })
        }
        return errors
    }

}

Writer

class CustomerWriter implements Writer<Customer> {
    async write(customer) {
        await repository.save(customer)
        return 1
    }
}

Exception Handling

class ImportExceptionHandler implements ExHandler<string[]> {
    handleException(data, err) {
        console.error(err)
    }
}

Exceptions are separated from validation errors.


Validation Error Handling

class ValidationHandler implements ErrHandler<Customer> {
    handleError(customer, errors) {
        console.log(errors)
    }
}

Custom Primitive Parsers

The framework provides default parsers for:

  • number
  • date
  • boolean

These parsers are replaceable.

Boolean

Default values:

1
Y
T

become

true

You can replace the parser globally.

resources.parseBool = (res, key, value) => {
    res[key] = value === "true" || value === "TRUE"
}

Number

resources.parseNumber = (res, key, value) => {
    res[key] = Number(value.replace(",", "."))
}

Date

resources.parseDate = (res, key, value) => {
    res[key] = dayjs(value, "DD/MM/YYYY").toDate()
}

No framework modification is required.


Reading Files

const reader = await createReader("customers.csv")

The reader returns an AsyncIterable, allowing the framework to process very large files without loading them entirely into memory.


Logging

The library provides

LogWriter

for efficient buffered log writing.

const writer =
    new LogWriter(
        "error.log",
        "./logs"
    )

Built-in Utilities

The library also includes helper functions for:

  • File readers
  • Date formatting
  • ISO date conversion
  • Filename checking
  • Nullable handling
  • File discovery
  • Directory creation

Why Import Service?

Most Node.js libraries only parse CSV files.

CSV
 │
 ▼
Object

Import Service handles the complete import workflow.

File
 │
 ▼
Reader
 │
 ▼
Transformer
 │
 ▼
Validator
 │
 ▼
Writer
 │
 ▼
Database

It separates responsibilities, making every stage reusable and independently testable.


Design Goals

  • Streaming first
  • Generic
  • Type-safe
  • Framework independent
  • High performance
  • Easily testable
  • Extensible
  • Familiar to both Java and JavaScript developers

License

MIT License.