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 🙏

© 2025 – Pkg Stats / Ryan Hefner

csvtoobj

v1.0.6

Published

Validate and translate one or more CSVs to JSON.

Downloads

25

Readme

csvtoobj

Validate and translate one or more CSVs to JSON. Uses JSON configuration file to define mapping between CSVs and object and supports basic validation of CSV data.

installation

$ npm install --save csvtoobj

configuration

{
  "general": {
    "masterCsv": "masterCsv",
    "requireMatchingId": true
  },
  "csvFiles": {
    "masterCsv": {
      "name": "master.csv",
      "id": "id"
    },
    "slaveCsv": {
      "name": "slave.csv",
      "id": "Processor Transaction ID"
    }
  },
  "objects": {
    "recurring": {
      "currency": {
        "alias": "masterCsv",
        "name": "currency",
        "default": "USD",
        "rules": [
          {
            "def": "isIn",
            "args": [
              ["USD"]
            ]
          }
        ]
      },
      "amount": {
        "alias": "slaveCsv",
        "name": "Amount Per Period",
        "rules": [
          {"def": "isCurrency"}
        ]
      },
      "recurringUnit": {
        "alias": "slaveCsv",
        "name": "Frequency",
        "rules": [
          {
            "def": "isIn",
            "args": [
              ["MONTHLY"]
            ]
          }
        ]
      },
      "recurOn": {
        "alias": "slaveCsv",
        "name": "Monthly Payment Day",
        "rules": [
          {
            "def": "isInt",
            "args": [
              {
                "min": 1,
                "max": 28
              }
            ]
          }
        ]
      }
    },
    "paymentToken": {
      "firstName": {
        "alias": "slaveCsv",
        "name": "First Name",
        "rules": [
          {
            "def": "isByteLength",
            "args": [
              {
                "min": 1
              }
            ]
          }
        ]
      },
      "lastName": {
        "alias": "slaveCsv",
        "name": "Last Name",
        "rules": [
          {
            "def": "isByteLength",
            "args": [
              {
                "min": 1
              }
            ]
          }
        ]
      },
      "email": {
        "alias": "slaveCsv",
        "name": "Billing Email",
        "rules": [
          {"def": "isEmail"}
        ]
      },
      "address1": {
        "alias": "masterCsv",
        "name": "credit_card.billing_address.street_address",
        "rules": [
          {
            "def": "isByteLength",
            "args": [
              {
                "min": 1
              }
            ]
          }
        ]
      },
      "address2": {
        "alias": "masterCsv",
        "name": "credit_card.billing_address.extended_address"
      },
      "city": {
        "alias": "slaveCsv",
        "name": "Billing City",
        "rules": [
          {
            "def": "isByteLength",
            "args": [
              {
                "min": 1
              }
            ]
          }
        ]
      },
      "state": {
        "alias": "slaveCsv",
        "name": "Billing State",
        "rules": [
          {
            "def": "isByteLength",
            "args": [
              {
                "min": 1
              }
            ]
          }
        ]
      },
      "zip": {
        "alias": "slaveCsv",
        "name": "Billing Zip",
        "rules": [
          {
            "def": "isByteLength",
            "args": [
              {
                "min": 1
              }
            ]
          }
        ]
      },
      "country": {
        "alias": "slaveCsv",
        "name": "Address - Country",
        "rules": [
          {
            "lib": "countries",
            "def": "valid"
          }
        ]
      },
      "currency": {
        "alias": "masterCsv",
        "name": "currency",
        "default": "USD",
        "rules": [
          {
            "def": "isIn",
            "args": [
              ["USD"]
            ]
          }
        ]
      }
    }
  }
}

usage

const csvtoobj = require('csvtoobj');

csvtoobj(config, function(error, objects) {
  if (error) {
    console.log(error);
  } else {
    console.log(JSON.stringify(objects, null, 2));
  }
});

options

general

  • masterCsv: Which CSV will be used for master set of ids.
  • requireMatchingId: If true, will not attempt to build objects where ID is not represented in all CSVs

csvFiles

  • csvFile: The alias used to reference CSV in other parts of configuration. Example above is masterCsv and slaveCsv.
    • name: The filename which can be used to read the file.
    • id: The ID that will associate the CSV row with other CSVs in this set.

objects

  • objectName: The resulting name of the object in the root of returned object, examples above are recurring and paymentToken.
    • objectProperty: The name of a property associated with the object, examples above are recurring.firstName, recurring.lastName.
      • alias: Which CSV is associated with this property.
      • name: The column in the CSV associated with this property.
      • default: If not found or empty, the default value to use instead.
      • rules: Validation rules to run against property value.
        • lib: Which library to use for validation, see validation section below.
        • def: The function name which will be invoked on the lib.
        • args: Any args in addition to the already passed property value.

validation

Currently supported libraries:

  • validator (see https://www.npmjs.com/package/validator)
  • countries (see https://www.npmjs.com/package/country-data)

If failures occur, the details will be appended to the object root under:

object.failures

Failures do not result in objects being removed from list, it is up to the caller to decide what to do if validation failures are present.