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

salsacsv

v1.0.1

Published

A basic, explicit CSV parsing and formatting library for use in node.js. CSV strings are parsed and formatted using a set of column definitions for converting to and from CSV.

Downloads

6

Readme

A basic, explicit CSV parsing and formatting library for use in node.js. CSV strings are parsed and formatted using a set of column definitions for converting to and from CSV.

API

Table of Contents

salsacsv

Used for converting data to and from CSV.

toCSV

Converts an array of objects to a CSV string.

Parameters
  • rows Array<Object> Array of objects to form rows from.
  • columns Array<Column> An array containing columns.
  • options Object Parsing options. (optional, default {})
    • options.includeHeader Boolean? Whether the CSV has a header or not, the first line will be skipped if this is set to true.
    • options.delimiter String The delimiter for the CSV string. (optional, default ',')
Examples
toCSV([
    {
        name: 'Cat Chow',
        price: 529
    }
], [
    {
        header: 'Name',
        key: 'name'
    },
    {
        header: 'Price',
        key: 'price',
        converter: (value) => value / 100
    }
], {
    includeHeader: true
});
// "Name","Price"\n"Cat Chow",5.29

Returns String CSV string.

fromCSV

Converts a CSV string into objects.

Parameters
  • csvStr String CSV string.
  • columns Array<Column> An array containing columns. (optional, default [])
  • options Object Parsing options. (optional, default {})
    • options.includeHeader Boolean? Whether the CSV has a header or not.
    • options.includeEmptyValues Boolean? Whether to assign empty values to object or not.
    • options.delimiter String The delimiter of the CSV string. (optional, default ',')
Examples
fromCSV('"Name","Price"\n"Cat Chow",5.29', [
    {
        header: 'Name',
        key: 'name'
    },
    {
        header: 'Price',
        key: 'price',
        parser: (value) => Math.round(parseFloat(value) * 100)
    }
], {
    includeHeader: true
});
// { name: 'Cat Chow', price: 529 }
// using no column definitions
// there will be no type conversions if no parser is given, any returned values will be strings
fromCSV('"Cat Chow",5.29');
// { col1: 'Cat Chow', col2: '5.29' }
// using no column definitions (use header as keys)
fromCSV('"Name","Price"\n"Cat Chow",5.29', null, {
    includeHeader: true
});
// { Name: 'Cat Chow', Price: '5.29' }

Returns Array<Object> Array of objects.

cellLabel

Gets the cell label.

Parameters
  • rowNumber Number Zero-based row number.
  • columnNumber Number Zero-based column number.
Examples
cellLabel(0, 3); // A3

Returns String Cell label.

Column

An object describing the format of a column.

Type: Object

Properties

  • header String? The header to be used for this column.
  • key String? The object key for this column.
  • required Boolean? Indicates whether the value should be defined when getting value from CSV. Throws an error if the resulting value is null, undefined, or an empty string.
  • converter Converter? The function called to convert value to CSV.
  • parser Parser? The function called to parse value from CSV. Will not be called unless parseEmpty is set to true.
  • parseEmpty Boolean? Whether to parse empty values or not.

Converter

Function to convert value to raw CSV.

Type: Function

Parameters

Returns (String | Number | null | undefined) Value of cell.

ConverterDetails

Converter details

Type: Object

Properties

  • obj Object? Source object.
  • key String? The key of the value we want to take from the object for this column.
  • row Number? Row number.
  • column Number? Column number.

Parser

Function to parse value from raw CSV.

Type: Function

Parameters

Returns any Parsed value from CSV string.

ParserDetails

Parser details

Type: Object

Properties

  • key String? Name of key to assign to object.
  • row Number? Row number.
  • column Number? Column number.

License

MIT