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

dbcsv

v0.0.3

Published

A simple csv file(s) backed database.

Downloads

1

Readme

dbcsv

Build Status

A simple database sourced from csv file(s). An alternative to csvdb which is actually really great and where you should be looking for this sort of functionality first. I needed something a little simpler and more specific for a project. Due to the nature of CSV files everything in dbcsv is treated as a string, even the numbers.

Use

var db = require('dbcsv')(<csv source filename>, [options object]);

Options

The options object may contain:

  • encoding string, encoding value of the CSV source, defaults to 'utf8'.
  • headers boolean, treat the first line as column headers, defaults to true. With this enabled you may alias columns with their header names in search() and column(), likewise results are returned as key, value pairs with the header value as the key. When disabled the column numerical index is used as the key. Column index may always be used in search() and column().
  • trim boolean, remove whitespace from entries, defaults to true.
  • headersLower boolean, transform header names to lowercase, defaults to true, only useful if headers is enabled.
  • separator string, used to indicate what separates each column defaults to a comma.

Properties

  • .headers array of column header values, will be numeric values if headers are disabled.
  • .numColumns the number of columns in the database.
  • .size the number of rows in the database (excluding the header row if headers are active).
  • .version the package version of this module

Methods

  • .column(key) return an array of all the data in a column, key is the column index (leftmost starting from 0), key may also be header value if headers are active.
  • .row(index) return single row array at numeric index starting at 0, if headers are enabled first data row is index 0.
  • .search(query) returns a two dimensional array of all rows exactly matching properties represented in the query object, if query is a function return all rows where function returns truthy.

Example

/example/basic.js applied to source file ../test/sample.csv.

var dbcsv = require('..'),
path = require('path');

var source = path.resolve(__dirname, './test/sample.csv');

var db = dbcsv(source);

console.log('-- .headers --');
console.log(db.headers);

console.log('-- .numColumns --');
console.log(db.numColumns);

console.log('-- .size --');
console.log(db.size);

console.log('-- .version --');
console.log(db.version);

console.log('-- .column(0) --');
console.log(db.column(0));

console.log('-- .row(0) --');
console.log(db.row(0));

console.log('-- .search({threshold : "3.0"}) --');
console.log(db.search({threshold : '3.0'}));
-- .headers --
[ 'id', 'threshold', 'description' ]

-- .numColumns --
3

-- .size --
4

-- .version --
0.0.0

-- .column(0) --
[ '1', '2', '3', '4' ]

-- .row(0) --
{ id: '1',
  threshold: '5.0',
  description: 'This is the first row of data' }

-- .search({threshold : "3.0"}) --
[ { id: '2',
    threshold: '3.0',
    description: 'This is the second row of data' },
  { id: '4',
    threshold: '3.0',
    description: 'This is the fourth row of data' } ]

ToDo

  • better csv parsing options
  • read only for now - the need to write out is not present yet
  • seperate "has headers" from "use headers" in configuration
  • there will be a conflict for headers if headers have numeric index