d3/d3-fetch

Name: d3-fetch

Owner: D3

Description: Convenient parsing for Fetch.

Created: 2016-10-22 15:23:51.0

Updated: 2018-01-11 13:11:59.0

Pushed: 2017-11-28 22:06:44.0

Homepage: null

Size: 7

Language: JavaScript

GitHub Committers

UserMost Recent Commit# Commits
David Bruant2018-01-29 13:54:41.01
Mike Bostock2018-02-26 19:24:16.018

Other Committers

UserEmailMost Recent Commit# Commits

README

d3-fetch

This module provides convenient parsing on top of Fetch. For example, to load a text file:

ext("/path/to/file.txt").then(function(text) {
nsole.log(text); // Hello, world!

To load and parse a CSV file:

sv("/path/to/file.csv").then(function(data) {
nsole.log(data); // [{"Hello": "world"}, ?]

This module has built-in support for parsing JSON, CSV, and TSV. You can parse additional formats by using text directly. This module is intended to replace d3-request.

Installing

If you use NPM, npm install d3-fetch. Otherwise, download the latest release. You can also load directly from d3js.org as a standalone library. AMD, CommonJS, and vanilla environments are supported. In vanilla, a d3 global is exported:

ipt src="https://d3js.org/d3-dsv.v1.min.js"></script>
ipt src="https://d3js.org/d3-fetch.v0.min.js"></script>
ipt>

sv("/path/to/file.csv").then(function(data) {
nsole.log(data); // [{"Hello": "world"}, ?]


ript>

Try d3-fetch in your browser.

API Reference

# d3.blob(url) <>

Fetches the binary file at the specified url as a Blob.

# d3.buffer(url) <>

Fetches the binary file at the specified url as an ArrayBuffer.

# d3.csv(url[, row]) <>

Fetches the CSV file at the specified url. An optional row conversion function may be specified to map and filter row objects to a more-specific representation; see dsv.parse for details. For example:

tion row(d) {
turn {
year: new Date(+d.Year, 0, 1), // convert "Year" column to Date
make: d.Make,
model: d.Model,
length: +d.Length // convert "Length" column to number


# d3.image(url[, anonymous]) <>

Fetches the image at the specified url. If anonymous is true, the cross-origin request is anonymous.

# d3.json(url) <>

Fetches the JSON file at the specified url.

# d3.text(url) <>

Fetches the text file at the specified url.

# d3.tsv(url[, row]) <>

Fetches the TSV file at the specified url. An optional row conversion function may be specified to map and filter row objects to a more-specific representation; see dsv.parse for details. For example:

tion row(d) {
turn {
year: new Date(+d.Year, 0, 1), // convert "Year" column to Date
make: d.Make,
model: d.Model,
length: +d.Length // convert "Length" column to number



This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.