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 🙏

© 2024 – Pkg Stats / Ryan Hefner

delimited-file-reader

v1.0.7

Published

Reads delimited text files and delivers records in object format

Downloads

22

Readme

#DelimitedFileReader Build StatusInline docsnpm version

A promise enabled, ES6 Class for reading delimited text files and emitting the records as objects.

##Synopsis

Read the given file, listen to the various events to get the data:

const DelimitedFileReader = require('delimited-file-reader');

let fileReader = new DelimitedFileReader(',');

fileReader.on('comment', (comment) => {
    console.log(`comment: ${comment}`);
});

fileReader.on('data', (data) => {
    console.log(`data: ${JSON.stringify(data)}`);
});

fileReader.on('close', () => {
    console.log('Elvis has left the building!');
});

// The parse method takes a string filename or a read stream as an argument.
fileReader.parse('./simple-example.csv');


// comment: # Example file using comma delimited format with comments
// data: {"field_0":"value1-1","field_1":"value2-2"}
// data: {"field_0":"value2-1","field_1":"value2-2"}
// Elvis has left the building!

This code comes from the provided example file: simple-example.js

##Description

This class is a simple implementation of a delimited text file reader. The following are configurable.

In simpler terms:

  • I have a delimited text file or stream with lf or lf\cr as record delimiters.
  • The column delimiter can be expressed as a string or regular expresssion.
  • They're may be comments in the file using a defined string in the starting position.
  • I want to read the file and process each record as an object.
  • I may want to name the properties of each object or I may let the class name them.

##Project Features

  • ES6 Class
  • Promise enabled
  • Complete test coverage with Mocha and Chai
  • JSDoc generated API documentation
  • Rest parameters are used for maximum flexibility.

##Installation npm install delimited-file-reader --save

Git Repository: https://github.com/wildbillh/delimited-file-reader

##Documentation

There is JSDOC documentation provided: DelimitedFileReader.html

##Methods

###Constructor

constructor(delimiter = /[,]/, fields = [], commentChar = '#')

The constructor takes three defaulted parameters:

  1. delimiter - defaults to a common. Can be any valid string or regular expresssion.
  2. fields - defaults to an empty array. In this case, the class will generated field names. The user can also supply an array of strings.
  3. commentChar - The string to use to designate a comment line (if it occurs at position 0). Set this to null of the feature should be disabled.

###parse

parse(filename)

This method starts the process of reading the files and emitting events. Prior to calling this method, the desired event listeners should be instantiated.

##Events

  • close - File reading is complete and all records have been emitted.
  • comment - A comment was encountered. The entire line is returned.
  • data - Contains an object representing the record.
  • error - Contains the error message.
  • invalid - A record was encountered with the wrong number of fields. This can only occur if the user specifies field names. The entire line is returned.
Author: Bill Hodges