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

markty-csv

v0.0.1

Published

Nano csv parser for Javascript.

Downloads

1

Readme

:microscope: Nano CSV parser for javascript using Markty.js.

Quick start

For Node.js

npm install markty-csv

var csv = require('markty-csv')
// or using ES6:
import csv from 'markty-csv'

const someCSV = `
a,b,c
1,2,3
4,5,6
`

console.log( CSV(someCSV) )

// > prints:
// [
//   [a,b,c],
//   [1,2,3],
//   [4,5,6]
// ]

In-Browser

Find latest version here.

To get the umd version:

  1. Observe the URL here and see the latest version used after @ like @0.0.1.
  2. Just modify the URL to get something like this: https://unpkg.com/[email protected]/dist/martycsv.umd.js

Then just import it normally :

<script type="text/javascript" src="https://unpkg.com/[email protected]/dist/martycsv.umd.js"></script>

Then the exported name is marktycsv(), so you can just:

<script>
var someCSV = 'a,b,c\n1,2,3\n4,5,6';
console.log( marktycsv(someCSV) )
</script>

// > prints:
// [
//   [a,b,c],
//   [1,2,3],
//   [4,5,6]
// ]

FEATURES

  • :microscope: Ridiculously SMALL:: 100 LOC, 800 bytes gzipped
  • :zap: Blazing fast :zap: see benchmarks
  • @TODO:
    • [ ] parse integers like 1, 2, 3 as javascript int...
    • [ ] parse float like 3.14 as javascript float
    • [ ] parse boolean like true, false as javascript boolean
    • [ ] parse signed numbers like +27, -23 as javascript's signed mumber
    • [ ] parse infinity like +inf, inf, -inf as javascript's Inf, -Inf
    • [ ] parse hexadecimals like 0xDEADBEEF
    • [ ] parse octals like 0o01234567, 0o755
    • [ ] parse binaries like 0b11010110
    • [ ] parse dates like 1979-05-27T00:32:00-07:00, 1979-05-27 as javascript's date object
    • [ ] allow for various delimiters like ;, |, \t...
    • [ ] allow escape character like "

Should you use it ?

  • :baby: Not fully unit-tested YET...
  • Not benchmarked YET, especially against HUGE csv files, so just make your tests before using it :)
  • Not meant to replace fully-fledged CSV parsers like https://github.com/Keyang/node-csvtojson.
  • markty-CSV just gives you an array of csv values line by line: the rest is up to you !!

Hey !! But I need to convert my CSV to JSON !

Well, markty-CSV will just parse CSV for you and push every values into an array. Now, if you want to convert it to JSON, we got you covered with this nice short snippet:

function MatrixToJSON(matrix,from,to){
  let jsonResult = []; from = from||0;  
  matrix.map((a,i) => {
    let obj = Object.assign({}, ...matrix[0].map((h, index) => ({[h]: matrix[i][index]})))
    jsonResult.push(obj)
  })
  return to ? jsonResult.splice(from,to) : jsonResult.splice(from)
}


// then later in your code:
var someCSV = 'a,b,c\n1,2,3\n4,5,6';
var parsedToArray = marktycsv(someCSV)
var convertToJson = MatrixToJSON(parsedToArray, 1)

// > convertToJson should look like:
// [
//   { "a":"1", "b":"2", "c":"3" },
//   { "a":"4", "b":"5", "c":"6" }
// ]

Benchmarks

| Test | Observations | markty-CSV | node-csvtojson | 5 liner gist | |:-------------|:-------------|-----------:|--------------------:|------------------:| | gzipped size | | 307 b | 46.899 b | 147 b |