| 1 | // https://d3js.org/d3-fetch/ v3.0.1 Copyright 2016-2021 Mike Bostock
|
|---|
| 2 | (function (global, factory) {
|
|---|
| 3 | typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('d3-dsv')) :
|
|---|
| 4 | typeof define === 'function' && define.amd ? define(['exports', 'd3-dsv'], factory) :
|
|---|
| 5 | (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.d3 = global.d3 || {}, global.d3));
|
|---|
| 6 | }(this, (function (exports, d3Dsv) { 'use strict';
|
|---|
| 7 |
|
|---|
| 8 | function responseBlob(response) {
|
|---|
| 9 | if (!response.ok) throw new Error(response.status + " " + response.statusText);
|
|---|
| 10 | return response.blob();
|
|---|
| 11 | }
|
|---|
| 12 |
|
|---|
| 13 | function blob(input, init) {
|
|---|
| 14 | return fetch(input, init).then(responseBlob);
|
|---|
| 15 | }
|
|---|
| 16 |
|
|---|
| 17 | function responseArrayBuffer(response) {
|
|---|
| 18 | if (!response.ok) throw new Error(response.status + " " + response.statusText);
|
|---|
| 19 | return response.arrayBuffer();
|
|---|
| 20 | }
|
|---|
| 21 |
|
|---|
| 22 | function buffer(input, init) {
|
|---|
| 23 | return fetch(input, init).then(responseArrayBuffer);
|
|---|
| 24 | }
|
|---|
| 25 |
|
|---|
| 26 | function responseText(response) {
|
|---|
| 27 | if (!response.ok) throw new Error(response.status + " " + response.statusText);
|
|---|
| 28 | return response.text();
|
|---|
| 29 | }
|
|---|
| 30 |
|
|---|
| 31 | function text(input, init) {
|
|---|
| 32 | return fetch(input, init).then(responseText);
|
|---|
| 33 | }
|
|---|
| 34 |
|
|---|
| 35 | function dsvParse(parse) {
|
|---|
| 36 | return function(input, init, row) {
|
|---|
| 37 | if (arguments.length === 2 && typeof init === "function") row = init, init = undefined;
|
|---|
| 38 | return text(input, init).then(function(response) {
|
|---|
| 39 | return parse(response, row);
|
|---|
| 40 | });
|
|---|
| 41 | };
|
|---|
| 42 | }
|
|---|
| 43 |
|
|---|
| 44 | function dsv(delimiter, input, init, row) {
|
|---|
| 45 | if (arguments.length === 3 && typeof init === "function") row = init, init = undefined;
|
|---|
| 46 | var format = d3Dsv.dsvFormat(delimiter);
|
|---|
| 47 | return text(input, init).then(function(response) {
|
|---|
| 48 | return format.parse(response, row);
|
|---|
| 49 | });
|
|---|
| 50 | }
|
|---|
| 51 |
|
|---|
| 52 | var csv = dsvParse(d3Dsv.csvParse);
|
|---|
| 53 | var tsv = dsvParse(d3Dsv.tsvParse);
|
|---|
| 54 |
|
|---|
| 55 | function image(input, init) {
|
|---|
| 56 | return new Promise(function(resolve, reject) {
|
|---|
| 57 | var image = new Image;
|
|---|
| 58 | for (var key in init) image[key] = init[key];
|
|---|
| 59 | image.onerror = reject;
|
|---|
| 60 | image.onload = function() { resolve(image); };
|
|---|
| 61 | image.src = input;
|
|---|
| 62 | });
|
|---|
| 63 | }
|
|---|
| 64 |
|
|---|
| 65 | function responseJson(response) {
|
|---|
| 66 | if (!response.ok) throw new Error(response.status + " " + response.statusText);
|
|---|
| 67 | if (response.status === 204 || response.status === 205) return;
|
|---|
| 68 | return response.json();
|
|---|
| 69 | }
|
|---|
| 70 |
|
|---|
| 71 | function json(input, init) {
|
|---|
| 72 | return fetch(input, init).then(responseJson);
|
|---|
| 73 | }
|
|---|
| 74 |
|
|---|
| 75 | function parser(type) {
|
|---|
| 76 | return (input, init) => text(input, init)
|
|---|
| 77 | .then(text => (new DOMParser).parseFromString(text, type));
|
|---|
| 78 | }
|
|---|
| 79 |
|
|---|
| 80 | var xml = parser("application/xml");
|
|---|
| 81 |
|
|---|
| 82 | var html = parser("text/html");
|
|---|
| 83 |
|
|---|
| 84 | var svg = parser("image/svg+xml");
|
|---|
| 85 |
|
|---|
| 86 | exports.blob = blob;
|
|---|
| 87 | exports.buffer = buffer;
|
|---|
| 88 | exports.csv = csv;
|
|---|
| 89 | exports.dsv = dsv;
|
|---|
| 90 | exports.html = html;
|
|---|
| 91 | exports.image = image;
|
|---|
| 92 | exports.json = json;
|
|---|
| 93 | exports.svg = svg;
|
|---|
| 94 | exports.text = text;
|
|---|
| 95 | exports.tsv = tsv;
|
|---|
| 96 | exports.xml = xml;
|
|---|
| 97 |
|
|---|
| 98 | Object.defineProperty(exports, '__esModule', { value: true });
|
|---|
| 99 |
|
|---|
| 100 | })));
|
|---|