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

row-to-object

v0.4.1

Published

Convert a row (from csv, excel) to a structured object and validate the object

Readme

row-to-object

Converting a row from CSV or Excel into an object

Install

$ npm install @toxus/row-to-object --save

Usage

const Conv = require('@toxus/row-to-object');

let converter = new Conv({ type: 'fieldName', fields: {
  id: 'UserNumber',
  name: 'Name',
  location: {
    street: 'Street',
    city: 'City'
  },
  email: [
    { type: "'work'", value: 'WorkEmail'},
    { type: "Newsletter | length > 0 ? 'newsletter' : undefined", 
      value: "Newsletter | length > 0 ? Newsletter : undefined"
    }
  ]
}})

let data = [ 
        ['UserNumber', 'Name', 'Amount', 'Street', 'City', 'WorkEmail', 'Newsletter'], 
        ['340', 'John Doe', '8,35', 'mainstreet 12', 'Amsterdam', '[email protected]', '[email protected]'], 
        ['463', 'Jane Doe', '10,95', 'localbase 55', 'Rotterdam', '[email protected]', '']
     ];
for (let l = 0; l < data.length; l++) {
  let obj = converter.convert(data[l]);
  if (obj) {
    console.log(obj)
  }
}
// will output
// {id: '340', name: 'John Doe', 
//    location: {street: 'mainstreet 12', city: 'Amsterdam'}, 
//    email: [
//      {type: 'work', value: '[email protected]}, 
//      type: 'newsletter, value: '[email protected]'}
//    ]
// {id: '463', name: 'Jane Doe', 
//    location: {street: 'localbase 55', city: 'Rotterdam'}
//    email: [{type: 'work', value: '[email protected]'}]
// }

Configuring

The conversion from the row (array) to an object is done by an configuration object. For every field in the final object an entry is made. An example:

let config = {
  city: "'Amsterdam'",
  fullName: "name",
  name: {_value: "someColumn", _required: true}
}

literal values

To add a literal value to the final object, the value has to be preceded with an =. Example: city: "=Amsterdam"

field value

There are two way to retrieve data from the row: direct (fullName: "name") or using a structure (fullName: _value: "name"). With the later structure the field can made required by adding the _required flag.

The fields can be addressed in different ways:

  • by the name given in the first column (type == fieldName)
  • by the number (index) of the column (type == index)
  • by the spreadsheet column name (A, AD) (type == letters)

When creating an object the format should be specified (default: index). The first row will be automatically skipped if the type is fieldName

object

A nested object can be created from the row. An example:

let config = {
  location: {
   "street": "WerkadresStraat",
   "city": "'Amsterdam'",
  }
}

This will generate an object:

  data = { location: { street: '1111', city: 'Amsterdam'}}  

If the field has the _required flag and has no value, the entire object will be removed

array of fields

An array can be contructed from the row by declaring the field as an array. Example:

let config = {
  location: [
    {
      _index: "work",
      "street": "WerkadresStraat",
      "city": "=Amsterdam",
    },
    {
      _index: "home",
      "street": "HomeStreet",
      "city": "=Some where",
    }
  ]
}

This will generate an object:

  data = { 
    location: [
      { street: '1111', city: 'Amsterdam', _index: "work"}, 
      {street: 'someval', city: "Some where", _index: "home"}
    ] 
  }  

To reference an special element then _index property can be used. The value of the index is added to the final object.

Maintainers

License

(c) 2019 Toxus, MIT