node package manager



JavaScript Style Guide
The purpose of this module is to support converting a csv (with delimiter support) to an array of json objects.
Using a custom map that can handle both simple fields renames and more complicated fields that are a result of calculations


Add to project

yarn add yap-csv


The module exposes two variables a Parser and ConverterConsts.
One is used for the actual parsing process and one provide consts helpers.

Simple Usage

const {Parser} = require('yap-csv')
// parserPromise is a Promise
.then((formattedData) => {
  // Do what you want with formattedData
.catch((e) => {

Stream Usage

const {Parser} = require('yap-csv')
const formattedData = []
// parserStream is a stream
const parserStream = Parser.parseSingleStream(FILE_NAME, FILE_LOCATION, DELIMITER, FIELDS_MAP, EXTRA_FIELDS_MAP)
parserStream.on('error', (e) => {
parserStream.on('data', (chunk) => {
parserStream.on('end', () => {
  // Do what you want with formattedData

Fields Specification

  • FILE_NAME - The name of the file being parsed
  • FILE_LOCATION - The location of the file being parsed
  • DELIMITER - The delimiter of the text
  • FIELDS_MAP - A conversion map of the fields
  • EXTRA_FIELDS_MAP - A conversion map for new fields that you would like to add


The following is an example of a map

const convertConsts = require('yap-csv').ConverterConsts
const FIELDS_MAP = {
  'FIELD1': 'simple_name_change',
  'FIELD2': {
    name: 'my_custom_number',
    type: convertConsts.NUMBER_TYPE
  'FIELD3': {
    name: 'functional_change',
    type: (dataObj) => {
      return dataObj['FIELD3'].toLowerCase()

As you can see using the fields map you can:

  • Preform simple field name changes
  • Convert to the helper types that are provided in this module
  • Preform conversions using a specified function that receives the original data object (before conversion)


The following is an example of a map of extra fields

  complicatedField: (convertedDataObj) => {
    return convertedDataObj['simple_name_change']

As you can see using the fields map you can add fields that are not in the original data.
Each field should be a function that receives that data after it passed the original formatting using the FIELDS_MAP.


The exported consts are:


According the the types we parse the results to a parseInt or parseFloat