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

angular-dsv

v1.1.0

Published

delimter-seperated-values

Downloads

5

Readme

angular-dsv Bower version

delimter-seperated-values

A angularjs service for reading tabular data from text files; for example tab-delimited and comma-delimited. angular-dsv combines the convenience of the d3 csv/tsv module with angular's $http service. angular-dsv is RFC4180-compliant and dependent only on angular itself.

Install

  1. bower install angular-dsv or bower install Hypercubed/angular-dsv
  2. Include the angular-dsv.js into your app. By default at bower_components/angular-dsv/angular-dsv.js.
  3. Add hc.dsv as a module dependency to your app.

Usage

dsv(delimiter)

The dsv service takes a single argument and returns a new $http-like service for handling text files of delimiter-seperated values. dsv.tsv and dsv.csv are shortcuts for dsv('\t') and dsv(',') respectively.

dsv.tsv(config[, accessor])

The dsv.tsv service is an example of 'delimiter'-seperated value interface for tab-delimited tables. It is service which takes two arguments: a configuration object like that expected by angular's $http, and an optional accessor function for transforming each row of the tabular data file. Like $http dsv.tsv returns a promise:

  dsv.tsv({method: 'GET', url: '/someUrl'}, function(d) { return {key: d.key, value: +d.value}; })
    .then(function(response) {
      console.log(response.data);
      // this callback will be called asynchronously
      // when the response is available
    })
    .catch(function(err) {
      // called asynchronously if an error occurs
      // or server returns response with an error status.
    });

The data value is array of objects representing the parsed rows returned from the specified url. The first row of the returned data is used as column names; these column names become the attributes on the returned objects. For example if the http request returns:

Year  Make     Model  Length
1997  Ford     E350   2.34
2000  Mercury  Cougar 2.38

The resulting JavaScript array is:

[
  {"Year": "1997", "Make": "Ford", "Model": "E350", "Length": "2.34"},
  {"Year": "2000", "Make": "Mercury", "Model": "Cougar", "Length": "2.38"}
]

dsv.tsv.get(url[, config][, accessor])

Like $http dsv.tsv provides a shortcut method for HTTP GET:

dsv.tsv.get('/someUrl', accessorFunction).then(successCallback);

dsv.tsv.getRows(url[, config][, accessor])

Similar to the dsv.tsv.get shortcut except the returned value is an array of arrays and the header line is treated as a standard row. For example if the http request returns:

Year  Make     Model  Length
1997  Ford     E350   2.34
2000  Mercury  Cougar 2.38

The resulting JavaScript array is:

[
  ["Year", "Make", "Model", "Length"],
  ["1997", "Ford", "E350", "2.34"],
  ["2000", "Mercury", "Cougar", "2.38"]
]

dsv.csv

Like dsv.tsv except for comma-seperated-values.

Testing

Install npm and bower dependencies:

	npm install
	bower install
	npm test

Acknowledgments

Previously portions of this code were taken from mbostock's d3 csv/tsv module. Now using d3-dsv.

License

MIT