{"name":"d3-request","version":"0.2.2","description":"A convenient alternative to XMLHttpRequest.","keywords":["d3","request","ajax","XMLHttpRequest"],"homepage":"https://github.com/d3/d3-request","license":"BSD-3-Clause","author":{"name":"Mike Bostock","url":"http://bost.ocks.org/mike"},"main":"build/d3-request.js","jsnext:main":"index.js","repository":{"type":"git","url":"git+https://github.com/d3/d3-request.git"},"scripts":{"pretest":"mkdir -p build && node -e 'process.stdout.write(\"var version = \\\"\" + require(\"./package.json\").version + \"\\\"; export * from \\\"../index\\\"; export {version};\");' > build/bundle.js && rollup -f umd -g d3-arrays:d3_arrays,d3-dispatch:d3_dispatch,d3-dsv:d3_dsv -u d3-request -n d3_request -o build/d3-request.js -- build/bundle.js","test":"faucet `find test -name '*-test.js'`","prepublish":"npm run test && uglifyjs build/d3-request.js -c -m -o build/d3-request.min.js && rm -f build/d3-request.zip && zip -j build/d3-request.zip -- LICENSE README.md build/d3-request.js build/d3-request.min.js"},"dependencies":{"d3-arrays":"~0.3.1","d3-dispatch":"~0.2.4","d3-dsv":"~0.1.9"},"devDependencies":{"faucet":"0.0","rollup":"0.20.5","tape":"4","uglify-js":"2"},"gitHead":"96bb718391fe51b970e447d4acbcea41f00421d8","bugs":{"url":"https://github.com/d3/d3-request/issues"},"_id":"d3-request@0.2.2","_shasum":"21df54f93ed612e09031b792d70dacbb19ef30d9","_from":".","_npmVersion":"3.3.9","_nodeVersion":"5.0.0","_npmUser":{"name":"mbostock","email":"mbostock@gmail.com"},"maintainers":[{"name":"mbostock","email":"mike@ocks.org"}],"dist":{"shasum":"21df54f93ed612e09031b792d70dacbb19ef30d9","tarball":"http://registry-npm.ywwl.com/d3-request/download/d3-request-0.2.2.tgz","integrity":"sha512-NDQjKJiu68O56U8ePmkgVl0MVR4koa3jzYtbaMnrhGmrugja4zIc7qVrCG/ZAjQFWYiL21J3nCh3q7j/3dgOew==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCleeanK2DRYB0a6KB3lPgfSHcIUSoqB/kxkSoGh3oT/gIgT+fOIqv6DgLsoa6RF36O/iMsTzgN7xP8DfIElvGcbEs="}],"size":8192,"noattachment":false,"key":"/d3-request/-/d3-request-0.2.2.tgz"},"directories":{},"readme":"# d3-request\n\nThis module provides a convenient alternative to XMLHttpRequest. For example, to load a text file:\n\n```js\nd3.text(\"/path/to/file.txt\", function(error, text) {\n  if (error) throw error;\n  console.log(text); // Hello, world!\n});\n```\n\nTo load and parse a CSV file:\n\n```js\nd3.csv(\"/path/to/file.csv\", function(error, data) {\n  if (error) throw error;\n  console.log(data); // [{\"Hello\": \"world\"}, …]\n});\n```\n\nTo post some query parameters:\n\n```js\nd3.request(\"/path/to/resource\")\n    .header(\"X-Requested-With\", \"XMLHttpRequest\")\n    .header(\"Content-Type\", \"application/x-www-form-urlencoded\")\n    .post(\"a=2&b=3\", callback);\n```\n\nThis module has built-in support for parsing [JSON](#json), [CSV](#csv) and [TSV](#tsv); in browsers, but not in Node, [HTML](#html) and [XML](#xml) are also supported. You can parse additional formats by using [request](#request) or [text](#text) directly.\n\n## Installing\n\nIf you use NPM, `npm install d3-request`. Otherwise, download the [latest release](https://github.com/d3/d3-request/releases/latest). You can also load directly from [d3js.org](https://d3js.org), either as a [standalone library](https://d3js.org/d3-request.v1.min.js) or as part of [D3 4.0](https://github.com/d3/d3). AMD, CommonJS, and vanilla environments are supported. In vanilla, a `d3` global is exported:\n\n```html\n<script src=\"https://d3js.org/d3-collection.v1.min.js\"></script>\n<script src=\"https://d3js.org/d3-dispatch.v1.min.js\"></script>\n<script src=\"https://d3js.org/d3-dsv.v1.min.js\"></script>\n<script src=\"https://d3js.org/d3-request.v1.min.js\"></script>\n<script>\n\nd3.csv(\"/path/to/file.csv\", callback);\n\n</script>\n```\n\n[Try d3-request in your browser.](https://tonicdev.com/npm/d3-request)\n\n## API Reference\n\n<a name=\"request\" href=\"#request\">#</a> d3.<b>request</b>(<i>url</i>[, <i>callback</i>]) [<>](https://github.com/d3/d3-request/blob/master/src/request.js#L4 \"Source\")\n\nReturns a new *request* for specified *url*. If no *callback* is specified, the returned *request* is not yet [sent](#request_send) and can be further configured. If a *callback* is specified, it is equivalent to calling [*request*.get](#request_get) immediately after construction:\n\n```js\nd3.request(url)\n    .get(callback);\n```\n\nIf you wish to specify a request header or a mime type, you must *not* specify a callback to the constructor. Use [*request*.header](#request_header) or [*request*.mimeType](#request_mimeType) followed by [*request*.get](#request_get) instead. See [d3.json](#json), [d3.csv](#csv), [d3.tsv](#tsv), [d3.html](#html) and [d3.xml](#xml) for content-specific convenience constructors.\n\n<a name=\"request_header\" href=\"#request_header\">#</a> <i>request</i>.<b>header</b>(<i>name</i>[, <i>value</i>]) [<>](https://github.com/d3/d3-request/blob/master/src/request.js#L51 \"Source\")\n\nIf *value* is specified, sets the request header with the specified *name* to the specified value and returns this request instance. If *value* is null, removes the request header with the specified *name* instead. If *value* is not specified, returns the current value of the request header with the specified *name*. Header names are case-insensitive.\n\nRequest headers can only be modified before the request is [sent](#request_send). Therefore, you cannot pass a callback to the [request constructor](#request) if you wish to specify a header; use [*request*.get](#request_get) or similar instead. For example:\n\n```js\nd3.request(url)\n    .header(\"Accept-Language\", \"en-US\")\n    .header(\"X-Requested-With\", \"XMLHttpRequest\")\n    .get(callback);\n```\n\nNote: this library does not set the X-Requested-With header to `XMLHttpRequest` by default. Some servers require this header to mitigate unwanted requests, but the presence of the header triggers CORS preflight checks; if necessary, set this header before sending the request.\n\n<a name=\"request_mimeType\" href=\"#request_mimeType\">#</a> <i>request</i>.<b>mimeType</b>([<i>type</i>]) [<>](https://github.com/d3/d3-request/blob/master/src/request.js#L60 \"Source\")\n\nIf *type* is specified, sets the request mime type to the specified value and returns this request instance. If *type* is null, clears the current mime type (if any) instead. If *type* is not specified, returns the current mime type, which defaults to null. The mime type is used to both set the [\"Accept\" request header](http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html) and for [overrideMimeType](http://www.w3.org/TR/XMLHttpRequest/#the-overridemimetype%28%29-method), where supported.\n\nThe request mime type can only be modified before the request is [sent](#request_send). Therefore, you cannot pass a callback to the [request constructor](#request) if you wish to override the mime type; use [*request*.get](#request_get) or similar instead. For example:\n\n```js\nd3.request(url)\n    .mimeType(\"text/csv\")\n    .get(callback);\n```\n\n<a name=\"request_user\" href=\"#request_user\">#</a> <i>request</i>.<b>user</b>([<i>value</i>]) [<>](https://github.com/d3/d3-request/blob/master/src/request.js#L80 \"Source\")\n\nIf *value* is specified, sets the user name for authentication to the specified string and returns this request instance. If *value* is not specified, returns the current user name, which defaults to null.\n\n<a name=\"request_password\" href=\"#request_password\">#</a> <i>request</i>.<b>password</b>([<i>value</i>]) [<>](https://github.com/d3/d3-request/blob/master/src/request.js#L84 \"Source\")\n\nIf *value* is specified, sets the password for authentication to the specified string and returns this request instance. If *value* is not specified, returns the current password, which defaults to null.\n\n<a name=\"request_timeout\" href=\"#request_timeout\">#</a> <i>request</i>.<b>timeout</b>([<i>timeout</i>]) [<>](https://github.com/d3/d3-request/blob/master/src/request.js#L74 \"Source\")\n\nIf *timeout* is specified, sets the [timeout](http://www.w3.org/TR/XMLHttpRequest/#the-timeout-attribute) attribute of the request to the specified number of milliseconds and returns this request instance. If *timeout* is not specified, returns the current response timeout, which defaults to 0.\n\n<a name=\"request_responseType\" href=\"#request_responseType\">#</a> <i>request</i>.<b>responseType</b>([<i>type</i>]) [<>](https://github.com/d3/d3-request/blob/master/src/request.js#L68 \"Source\")\n\nIf *type* is specified, sets the [response type](http://www.w3.org/TR/XMLHttpRequest/#the-responsetype-attribute) attribute of the request and returns this request instance. Typical values are: `​` (the empty string), `arraybuffer`, `blob`, `document`, and `text`. If *type* is not specified, returns the current response type, which defaults to `​`.\n\n<a name=\"request_response\" href=\"#request_response\">#</a> <i>request</i>.<b>response</b>(<i>value</i>) [<>](https://github.com/d3/d3-request/blob/master/src/request.js#L90 \"Source\")\n\nSets the response value function to the specified function and returns this request instance. The response value function is used to map the response XMLHttpRequest object to a useful data value. See the convenience methods [json](#json) and [text](#text) for examples.\n\n<a name=\"request_get\" href=\"#request_get\">#</a> <i>request</i>.<b>get</b>([<i>data</i>][, <i>callback</i>]) [<>](https://github.com/d3/d3-request/blob/master/src/request.js#L96 \"Source\")\n\nEquivalent to [*request*.send](#request_send) with the GET method:\n\n```js\nrequest.send(\"GET\", data, callback);\n```\n\n<a name=\"request_post\" href=\"#request_post\">#</a> <i>request</i>.<b>post</b>([<i>data</i>][, <i>callback</i>]) [<>](https://github.com/d3/d3-request/blob/master/src/request.js#L101 \"Source\")\n\nEquivalent to [*request*.send](#request_send) with the POST method:\n\n```js\nrequest.send(\"POST\", data, callback);\n```\n\n<a name=\"request_send\" href=\"#request_send\">#</a> <i>request</i>.<b>send</b>(<i>method</i>[, <i>data</i>][, <i>callback</i>]) [<>](https://github.com/d3/d3-request/blob/master/src/request.js#L106 \"Source\")\n\nIssues this request using the specified *method* (such as `GET` or `POST`), optionally posting the specified *data* in the request body, and returns this request instance. If a *callback* is specified, the callback will be invoked asynchronously when the request succeeds or fails. The callback is invoked with two arguments: the error, if any, and the [response value](#request_response). The response value is undefined if an error occurs. This is equivalent to:\n\n```js\nrequest\n    .on(\"error\", function(error) { callback(error); })\n    .on(\"load\", function(xhr) { callback(null, xhr); })\n    .send(method, data);\n```\n\nIf no *callback* is specified, then \"load\" and \"error\" listeners should be registered via [*request*.on](#request_on).\n\n<a name=\"request_abort\" href=\"#request_abort\">#</a> <i>request</i>.<b>abort</b>() [<>](https://github.com/d3/d3-request/blob/master/src/request.js#L121 \"Source\")\n\nAborts this request, if it is currently in-flight, and returns this request instance. See [XMLHttpRequest’s abort](http://www.w3.org/TR/XMLHttpRequest/#the-abort%28%29-method).\n\n<a name=\"request_on\" href=\"#request_on\">#</a> <i>request</i>.<b>on</b>(<i>type</i>[, <i>listener</i>]) [<>](https://github.com/d3/d3-request/blob/master/src/request.js#L126 \"Source\")\n\nIf *listener* is specified, sets the event *listener* for the specified *type* and returns this request instance. If an event listener was already registered for the same type, the existing listener is removed before the new listener is added. If *listener* is null, removes the current event *listener* for the specified *type* (if any) instead. If *listener* is not specified, returns the currently-assigned listener for the specified type, if any.\n\nThe type must be one of the following:\n\n* `beforesend` - to allow custom headers and the like to be set before the request is [sent](#request_send).\n* `progress` - to monitor the [progress of the request](http://www.w3.org/TR/progress-events/).\n* `load` - when the request completes successfully.\n* `error` - when the request completes unsuccessfully; this includes 4xx and 5xx response codes.\n\nTo register multiple listeners for the same *type*, the type may be followed by an optional name, such as `load.foo` and `load.bar`. See [d3-dispatch](https://github.com/d3/d3-dispatch) for details.\n\n<a name=\"csv\" href=\"#csv\">#</a> d3.<b>csv</b>(<i>url</i>[[, <i>row</i>], <i>callback</i>]) [<>](https://github.com/d3/d3-request/blob/master/src/csv.js \"Source\")\n\nReturns a new [*request*](#request) for the [CSV](https://github.com/d3/d3-dsv#csvParse) file at the specified *url* with the default mime type `text/csv`. If no *callback* is specified, this is equivalent to:\n\n```js\nd3.request(url)\n    .mimeType(\"text/csv\")\n    .response(function(xhr) { return d3.csvParse(xhr.responseText, row); });\n```\n\nIf a *callback* is specified, a [GET](#request_get) request is sent, making it equivalent to:\n\n```js\nd3.request(url)\n    .mimeType(\"text/csv\")\n    .response(function(xhr) { return d3.csvParse(xhr.responseText, row); })\n    .get(callback);\n```\n\nAn optional *row* conversion function may be specified to map and filter row objects to a more-specific representation; see [*dsv*.parse](https://github.com/d3/d3-dsv#dsv_parse) for details. For example:\n\n```js\nfunction row(d) {\n  return {\n    year: new Date(+d.Year, 0, 1), // convert \"Year\" column to Date\n    make: d.Make,\n    model: d.Model,\n    length: +d.Length // convert \"Length\" column to number\n  };\n}\n```\n\nThe returned *request* exposes an additional *request*.row method as an alternative to passing the *row* conversion function to d3.csv, allowing you to configure the request before sending it. For example, this:\n\n```js\nd3.csv(url, row, callback);\n```\n\nIs equivalent to this:\n\n```js\nd3.csv(url)\n    .row(row)\n    .get(callback);\n```\n\n<a name=\"html\" href=\"#html\">#</a> d3.<b>html</b>(<i>url</i>[, <i>callback</i>]) [<>](https://github.com/d3/d3-request/blob/master/src/html.js \"Source\")\n\nReturns a new [*request*](#request) for the HTML file at the specified *url* with the default mime type `text/html`. The HTML file is returned as a [document fragment](https://developer.mozilla.org/en-US/docs/DOM/range.createContextualFragment). If no *callback* is specified, this is equivalent to:\n\n```js\nd3.request(url)\n    .mimeType(\"text/html\")\n    .response(function(xhr) { return document.createRange().createContextualFragment(xhr.responseText); });\n```\n\nIf a *callback* is specified, a [GET](#request_get) request is sent, making it equivalent to:\n\n```js\nd3.request(url)\n    .mimeType(\"text/html\")\n    .response(function(xhr) { return document.createRange().createContextualFragment(xhr.responseText); })\n    .get(callback);\n```\n\nHTML parsing requires a global document and relies on [DOM Ranges](https://dom.spec.whatwg.org/#ranges), which are [not supported by JSDOM](https://github.com/tmpvar/jsdom/issues/317) as of version 8.3; thus, this method is supported in browsers but not in Node.\n\n<a name=\"json\" href=\"#json\">#</a> d3.<b>json</b>(<i>url</i>[, <i>callback</i>]) [<>](https://github.com/d3/d3-request/blob/master/src/json.js \"Source\")\n\nReturns a new [*request*](#request) to [get](#request_get) the [JSON](http://json.org) file at the specified *url* with the default mime type `application/json`. If no *callback* is specified, this is equivalent to:\n\n```js\nd3.request(url)\n    .mimeType(\"application/json\")\n    .response(function(xhr) { return JSON.parse(xhr.responseText); });\n```\n\nIf a *callback* is specified, a [GET](#request_get) request is sent, making it equivalent to:\n\n```js\nd3.request(url)\n    .mimeType(\"application/json\")\n    .response(function(xhr) { return JSON.parse(xhr.responseText); })\n    .get(callback);\n```\n\n<a name=\"text\" href=\"#text\">#</a> d3.<b>text</b>(<i>url</i>[, <i>callback</i>]) [<>](https://github.com/d3/d3-request/blob/master/src/text.js \"Source\")\n\nReturns a new [*request*](#request) to [get](#request_get) the text file at the specified *url* with the default mime type `text/plain`. If no *callback* is specified, this is equivalent to:\n\n```js\nd3.request(url)\n    .mimeType(\"text/plain\")\n    .response(function(xhr) { return xhr.responseText; });\n```\n\nIf a *callback* is specified, a [GET](#request_get) request is sent, making it equivalent to:\n\n```js\nd3.request(url)\n    .mimeType(\"text/plain\")\n    .response(function(xhr) { return xhr.responseText; })\n    .get(callback);\n```\n\n<a name=\"tsv\" href=\"#tsv\">#</a> d3.<b>tsv</b>(<i>url</i>[[, <i>row</i>], <i>callback</i>]) [<>](https://github.com/d3/d3-request/blob/master/src/tsv.js \"Source\")\n\nReturns a new [*request*](#request) for a [TSV](https://github.com/d3/d3-dsv#tsvParse) file at the specified *url* with the default mime type `text/tab-separated-values`. If no *callback* is specified, this is equivalent to:\n\n```js\nd3.request(url)\n    .mimeType(\"text/tab-separated-values\")\n    .response(function(xhr) { return d3.tsvParse(xhr.responseText, row); });\n```\n\nIf a *callback* is specified, a [GET](#request_get) request is sent, making it equivalent to:\n\n```js\nd3.request(url)\n    .mimeType(\"text/tab-separated-values\")\n    .response(function(xhr) { return d3.tsvParse(xhr.responseText, row); })\n    .get(callback);\n```\n\nAn optional *row* conversion function may be specified to map and filter row objects to a more-specific representation; see [*dsv*.parse](https://github.com/d3/d3-dsv#dsv_parse) for details. For example:\n\n```js\nfunction row(d) {\n  return {\n    year: new Date(+d.Year, 0, 1), // convert \"Year\" column to Date\n    make: d.Make,\n    model: d.Model,\n    length: +d.Length // convert \"Length\" column to number\n  };\n}\n```\n\nThe returned *request* exposes an additional *request*.row method as an alternative to passing the *row* conversion function to d3.tsv, allowing you to configure the request before sending it. For example, this:\n\n```js\nd3.tsv(url, row, callback);\n```\n\nIs equivalent to this:\n\n```js\nd3.tsv(url)\n    .row(row)\n    .get(callback);\n```\n\n<a name=\"xml\" href=\"#xml\">#</a> d3.<b>xml</b>(<i>url</i>[, <i>callback</i>]) [<>](https://github.com/d3/d3-request/blob/master/src/xml.js \"Source\")\n\nReturns a new [*request*](#request) to [get](#request_get) the XML file at the specified *url* with the default mime type `application/xml`. If no *callback* is specified, this is equivalent to:\n\n```js\nd3.request(url)\n    .mimeType(\"application/xml\")\n    .response(function(xhr) { return xhr.responseXML; });\n```\n\nIf a *callback* is specified, a [GET](#request_get) request is sent, making it equivalent to:\n\n```js\nd3.request(url)\n    .mimeType(\"application/xml\")\n    .response(function(xhr) { return xhr.responseXML; })\n    .get(callback);\n```\n\nXML parsing relies on [*xhr*.responseXML](https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/responseXML) which is not supported by [node-XMLHttpRequest](https://github.com/driverdan/node-XMLHttpRequest/issues/8) as of version 1.8; thus, this method is supported in browsers but not in Node.\n","publish_time":1448730357083,"_cnpm_publish_time":1448730357083,"dist-tags":{"latest":"1.0.6"}}