Skip to content

Commit 92545fc

Browse files
committed
Add html, svg, xml.
Fixes #14.
1 parent d4bfe27 commit 92545fc

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

README.md

+12
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ If only one of *init* and *row* is specified, it is interpreted as the *row* con
6969

7070
See also [d3.csv](#csv) and [d3.tsv](#tsv).
7171

72+
<a name="html" href="#html">#</a> d3.<b>html</b>(<i>input</i>[, <i>init</i>]) [<>](https://github.com/d3/d3-fetch/blob/master/src/xml.js "Source")
73+
74+
Fetches the file at the specified *input* URL as [text](#text) and then [parses it](https://developer.mozilla.org/docs/Web/API/DOMParser) as HTML. If *init* is specified, it is passed along to the underlying call to [fetch](https://fetch.spec.whatwg.org/#fetch-method); see [RequestInit](https://fetch.spec.whatwg.org/#requestinit) for allowed fields.
75+
7276
<a name="image" href="#image">#</a> d3.<b>image</b>(<i>input</i>[, <i>init</i>]) [<>](https://github.com/d3/d3-fetch/blob/master/src/image.js "Source")
7377

7478
Fetches the image at the specified *input* URL. If *init* is specified, sets any additional properties on the image before loading. For example, to enable an anonymous [cross-origin request](https://developer.mozilla.org/en-US/docs/Web/HTML/CORS_enabled_image):
@@ -83,10 +87,18 @@ d3.image("https://example.com/test.png", {crossOrigin: "anonymous"}).then(functi
8387

8488
Fetches the [JSON](http://json.org) file at the specified *input* URL. If *init* is specified, it is passed along to the underlying call to [fetch](https://fetch.spec.whatwg.org/#fetch-method); see [RequestInit](https://fetch.spec.whatwg.org/#requestinit) for allowed fields.
8589

90+
<a name="svg" href="#svg">#</a> d3.<b>svg</b>(<i>input</i>[, <i>init</i>]) [<>](https://github.com/d3/d3-fetch/blob/master/src/xml.js "Source")
91+
92+
Fetches the file at the specified *input* URL as [text](#text) and then [parses it](https://developer.mozilla.org/docs/Web/API/DOMParser) as SVG. If *init* is specified, it is passed along to the underlying call to [fetch](https://fetch.spec.whatwg.org/#fetch-method); see [RequestInit](https://fetch.spec.whatwg.org/#requestinit) for allowed fields.
93+
8694
<a name="text" href="#text">#</a> d3.<b>text</b>(<i>input</i>[, <i>init</i>]) [<>](https://github.com/d3/d3-fetch/blob/master/src/text.js "Source")
8795

8896
Fetches the text file at the specified *input* URL. If *init* is specified, it is passed along to the underlying call to [fetch](https://fetch.spec.whatwg.org/#fetch-method); see [RequestInit](https://fetch.spec.whatwg.org/#requestinit) for allowed fields.
8997

9098
<a name="tsv" href="#tsv">#</a> d3.<b>tsv</b>(<i>input</i>[, <i>init</i>][, <i>row</i>]) [<>](https://github.com/d3/d3-fetch/blob/master/src/dsv.js "Source")
9199

92100
Equivalent to [d3.dsv](#dsv) with the tab character as the delimiter.
101+
102+
<a name="xml" href="#xml">#</a> d3.<b>xml</b>(<i>input</i>[, <i>init</i>]) [<>](https://github.com/d3/d3-fetch/blob/master/src/xml.js "Source")
103+
104+
Fetches the file at the specified *input* URL as [text](#text) and then [parses it](https://developer.mozilla.org/docs/Web/API/DOMParser) as XML. If *init* is specified, it is passed along to the underlying call to [fetch](https://fetch.spec.whatwg.org/#fetch-method); see [RequestInit](https://fetch.spec.whatwg.org/#requestinit) for allowed fields.

index.js

+1
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ export {default as dsv, csv, tsv} from "./src/dsv";
44
export {default as image} from "./src/image";
55
export {default as json} from "./src/json";
66
export {default as text} from "./src/text";
7+
export {default as xml, html, svg} from "./src/xml";

src/xml.js

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import text from "./text";
2+
3+
function parser(type) {
4+
return function(input, init) {
5+
return text(input, init).then(function(text) {
6+
return (new DOMParser).parseFromString(text, type);
7+
});
8+
};
9+
}
10+
11+
export default parser("application/xml");
12+
13+
export var html = parser("text/html");
14+
15+
export var svg = parser("image/svg+xml");

0 commit comments

Comments
 (0)