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

srv-to-csv

v0.4.3

Published

Convert XLS, XLSX, and ODT to CSV

Downloads

3

Readme

CSV Conversion Server NPM version Build Status Dependency Status Coverage percentage

Converts an XLSX, XLS, TSV, or CSV file to CSV. It bases changes on content, not file ext. This is handy for Chalk & Wire files as they export TSV or TSV labeled XLS.

Built in is a header/meta data remover. For Chalk & Wire, and other, files with meta-data rows placed in the top describing the file, this will remove them by parsing for a sudden change on content column length. presently this change is 2 + columns.

Example

Below is an example of a csv file with 4 rows of meta data/headers, not referring to the column headers.

content,example
date,"Monday, june 5th, 2015"
other field,other value,
some field,some val, another val
Col Header 1,Col Header 2,Col Header 3,Col Header 4,Col Header 5
content a1,content a2,content a3,content a4
content b1,content b2,content b3,content b4,content b5
content c1,content c2,content c3,content c4
content d1,content d2,content d3,content d4,content d5
content e1,content e2,content e3,content e4,content e5
content f1,content f2,content f3,content f4,content f5

The above will output to:

Col Header 1,Col Header 2,Col Header 3,Col Header 4,Col Header 5
content a1,content a2,content a3,content a4
content b1,content b2,content b3,content b4,content b5
content c1,content c2,content c3,content c4
content d1,content d2,content d3,content d4,content d5
content e1,content e2,content e3,content e4,content e5
content f1,content f2,content f3,content f4,content f5

This happens because the sudden change in column numbers from 3 (@ row 4) to 5 (@ row 6). Because the change is greater than 1 column, it is registered as headers and drops the above.

This behavior is default and cannot be disabled yet.

Installation

There are two ways to install: as a module or a microserver.

1. As submodule

npm install --save srv-to-csv

2. As microservice

git clone http://github.com/uci-soe/to-csv
cd to-csv
npm start

Usage (to be written)

This can be used as a module or a server. To use as a module, install through NPM (still determining how to do this exactly) and require as normal

var toCSV = require('to-csv');

var fileXLSX = "test/samples/MS-Spring-2015.xlsx";
var fileXLS = "test/samples/MS-Spring-2015.xls"; // this file is a TSV file labeled *.xls, 
                                                    //as is Chalk & Wire's normal output 
                                                    //and will produce errors when put into toCSV.xlsxToCSV 
var fileCSV = "test/samples/MS-Spring-2015.csv";

toCSV.xlsxToCSV(fileXLSX, function (err, res) {
  if (err) {
    throw err;
  }
  console.log(res); // CSV text
});


// since systems like Chalk & Wire produce TSV files with a *.xls name, 
//    this will examine the content to determine the type
toCSV.getFileType(fileXLS, function(err, type){ 
  if (err) {
    throw err;
  }
  console.log(type); // will output "tsv"
});

List of public functions

  • getFileType
    • takes filePath and callback
    • returns Q Promise
    • will return fileType, eventually
    • Gets file type based on file contents. If file type is not one normally handled by this server, it will throw an error
  • removeHeaderRows
    • takes filePath or content and callback
    • returns Q Promise
    • will return csv/tsv w/o meta headers, eventually
    • Finds if there are meta headers and removes them. see above example in Example
  • xlsxToCSV
    • takes filePath or content and callback
    • returns Q Promise
    • will return csv, eventually
    • Converts well formed xls, xlsx, ots, etc files to csv
  • csvToCSV
    • takes filePath or content and callback
    • returns Q Promise
    • will return csv, eventually
    • Converts csv files to well formed csv
  • tsvToCSV
    • takes filePath or content and callback
    • returns Q Promise
    • will return csv, eventually
    • Converts tsv files to well formed csv
  • _svToCSV
    • takes filePath or content and string of delimiter and callback
    • returns Q Promise
    • will return csv, eventually
    • Converts *sv (anything separated value) files to well formed csv
  • httpHandler
    • takes request object with {files:{file:{path:"path/to/file.ext"}}} and a response object with {send: function(){...}}
    • will convert contents at request.files.file.path to string oc well formed CSV and send using response.send(csvData);

License

BSD 2-Clause Simplified. See LICENSE for full info.

Contributors