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

tabdat

v0.0.3

Published

Process tabular data efficiently and easily.

Downloads

14

Readme

About

TabDat is a package for working with tabular data in CSV format. It leverages Papa Parse for the CSV to JSON conversion, and then mostly utilizes Lodash for the manipulation of the data. It is intended for users who want to easily work with tabular data in Node.js and particularly for users who may be used to working with data frames in R/Python/etc.

Contributing

This is a side project (read: low priority) of mine so any contributions are welcome - just submit a pull request on GitHub. I really would like to see a robust Node.js package that allows for working with tabular data in a way that is similar to R/Python so I am hoping to get additional contributors and to be able to really flesh this package out in a thorough manner.

Installation

npm i tabdat

Usage

The standard workflow looks like this:

const TabDat = require('tabdat')

TabDat.convert('/path/to/file.csv').then(data => {
  td = new TabDat.TabDat(data)
  td.sortBy(row => row.mpg)
    .filter(row => countryOfOrigin === 'USA')
    .printTable()
})

Note that all methods are chainable.

Available Methods

Convert

convert(filepath)

Converts a CSV file to JSON for further processing. filepath is a string pointing to the correct location. Returns a promise with the converted data.


Add a new column

addCol(name, userFunction)

Adds a new column to the data and populates the column via the provided userFunction. name is a string representing the name of the new column and userFunction is a function.

For example:

addCol('myNewCol', row => row.mpg * 2)

This will create a new row called myNewCol and the values in this column will be the product of the value in the mpg column and 2.


Add a new row

addRow(row)

Adds a new row to the data. row is an object.

For example:

addRow({
  countryOfOrigin: 'USA',
  mpg: 28,
  numCylinders: 6
})

Note: The keys of the object must match those that are already in the data (i.e. you can't add a new column this way, use addCol for that).


Delete a column

deleteCol(colNames)

Deletes the column(s) that are specified in the array colNames.

For example:

deleteCol(['mpg', 'numCylinders'])

Filter the data

filter(userFunction)

Filters the data based on the provided function.

For example:

filter(row => row.mpg > 30)

Print the column names to the console

printColNames()

Prints to the console an array containing all of the current column names (object keys) in the data.


Print the data as a table to the console

printTable()

Prints the data to the console in a tabular format.


Rename a column

renameCol(oldColName, newColName)

Renames the column oldColName to the name provided in newColName. Both arguments are strings.

For example:

renameCol('countryOfOrigin', 'country')

This will change the name of the column countryOfOrigin to country.


Save the data to a CSV file

save(filepath)

Saves the data in its current state to a CSV file in the location provided in the filepath argument (which is a string).

For example:

save('path/to/save/to.csv')

Get the number of rows and columns (printed to the console)

size()

Prints to the console the current number of rows/columns the data consists of.


Sort the data

sortBy(criteria)

Sorts the data by the given criteria which can either be a function or an array.

For example:

sortBy(row => row.mpg)

This will sort the data in ascending order by the values in the mpg column.

sortBy(['countryOfOrigin', 'mpg'])

This will sort the data first by countryOfOrigin and then by mpg.