-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpath-source.js
More file actions
36 lines (30 loc) · 1.2 KB
/
Copy pathpath-source.js
File metadata and controls
36 lines (30 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// https://github.com/mbostock/path-source Version 0.1.3. Copyright 2017 Mike Bostock.
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('array-source')) :
typeof define === 'function' && define.amd ? define(['array-source'], factory) :
(global.sources = global.sources || {}, global.sources.path = factory(global.sources.array));
}(this, (function (array) { 'use strict';
array = array && array.hasOwnProperty('default') ? array['default'] : array;
var fetchPath = function(url) {
return fetch(url).then(function(response) {
return response.body && response.body.getReader
? response.body.getReader()
: response.arrayBuffer().then(array);
});
};
var requestPath = function(url) {
return new Promise(function(resolve, reject) {
var request = new XMLHttpRequest;
request.responseType = "arraybuffer";
request.onload = function() { resolve(array(request.response)); };
request.onerror = reject;
request.ontimeout = reject;
request.open("GET", url, true);
request.send();
});
};
function path(path) {
return (typeof fetch === "function" ? fetchPath : requestPath)(path);
}
return path;
})));