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

trcsvjs

v1.0.14

Published

A csv parser that use papaparser and extend its features

Downloads

23

Readme

trcsvjs

A csv manager module for node and browser. This module wrapp papaparse library and add extra features. See papaparse page for more information: https://www.npmjs.com/package/papaparse

Include/Declare

Include in Browser

    // ....
    <script type='text/javascript' src='PATH/TO/LIB/node_modules/papaparse/papaparse.min.js?'></script>
	<script type='text/javascript' src='PATH/TO/LIB/trcsvjs.min.js?'></script>
	// Trcsvjs available
	// ....

Declare in NodeJs

    npm install trcsvjs
    //....
    var Trcsvjs = require('trcsvjs')

Creating a csv object

Library Trcsvjs implement a list of functions that allow to create a csv object

    // Create csv object from string CSV_STRING
    Trcsvjs.csvStringToJs(CSV_STRING[,config],callback) //callback(err,csv)

    // Create csv object from file getted from DOM
    Trcsvjs.getCsvFromFile(ELEMENT_FILE_FROM_DOM[,config],callback) //callback(err,csv)

    // Create csv object from csv in URL
    Trcsvjs.getCsvFromUrl(URL[,config],callback) //callback(err,csv)

    // Create empty csv object
    var csv = Trcsvjs.getEmptyCsv([config])

Config

Config use same parameters than papaparse. See papaparse page for more information: https://www.npmjs.com/package/papaparse

Usage of CSV object

After you create a csv object, you can manage it using its function. All reference to position for column and row start at 1..n

//Init csv using directly an array of array [[],[],[],[]] -> [ROW,ROW,ROW,..]
csv.initCsvFromArray(array);

//Return cell value in column "col" of row "pos"
var value = csv.getCell(pos, col);

//Return cell value in column "col" of row "pos"
var value = csv.getCell(pos, col);

//Set value of cell in column "col" of row "pos"
csv.setCell(pos, col, value);

//Return all csv converted in string
var text = csv.getCsvText(config); //use papaparse, config of papaparse

//Create a file in browser and force download (not in NodeJs)
csv.browseCsv(filename, config); //use papaparse, config of papaparse

//Return row (array[]) in position "pos"
var row = csv.getRow(pos);

//Return row converted in object from row in position "pos". To convert row in object use objspec
var obj = csv.getObjFromRow(pos, objspec);

//Return row array convertirg an object into a row. To convert object in row use objspec
var row = csv.getRowFromObj(pos, objspec);

//Insert row (array[]) at the end of file
csv.insertRow(row);

//Insert row (array[]) at position pos
csv.insertRowInPos(row, pos);

//Insert row convertif first from object
csv.insertRowFromObj(obj, objspec);
csv.insertRowInPosFromObj(obj, pos, objspec);

Object Spec

You can create easly an object from a row using an object spec. An object spec is like:

{
    "name_field_1":CONF_FIELD,
    "name_field_2":CONF_FIELD,
}

If you have a row like ['foo','bar'] and convert in object using previous spec you receive an object:

{
    "name_field_1" : 'foo',
    "name_field_2" : 'bar'
}

It also accept deep objects, for example:

{
    "a" : {
        "a1" : {
            "a11" : CONF_FIELD,
            "a12"  : CONF_FIELD
        },
        "a2" : CONF_FIELD
    },
    "b" : "CONF_FIELD
}

convert row [1,2,3,4] in:

{
    "a" : {
        "a1" : {
            "a11" : 1,
            ""a12"  : 2
        },
        "a2" : 2
    },
    "b" : "3
}

Also, if you use object spec to convert an object in array (row) the process is exactly the opposite

CONF_FIELD

Conf field is a special configuration that allow to automaticaly implement typical process to a value before converting to object/array. Valid values are:

  • '': //Do nothing, pass throught value
  • 'd': //Convert value from row in an integer and viceversa
  • 'dz': //Convert value from row in an integer and viceversa. If value of cell is empty, assign 0
  • 'f': //Convert value from row in a float and viceversa
  • 'fz': //Convert value from row in a float and viceversa. If value of cell is empty, assign 0. Also detect ',' and convert in '.'
  • 'dt': //Detect d/m/Y spanish and convert to Y-m-d
  • 'b': Convert 1/0 values from excel into true/false in JS and viceversa
  • 'sc': Implement a separated comma array. For example a value in cell like 1,2,3 is converted to [1,2,3] and viceversa