pax_global_header00006660000000000000000000000064126230420200014501gustar00rootroot0000000000000052 comment=43437dc5b381e391b73522d71cea23fc72675154 isomorphic-fetch-2.2.1/000077500000000000000000000000001262304202000147465ustar00rootroot00000000000000isomorphic-fetch-2.2.1/.editorconfig000066400000000000000000000002061262304202000174210ustar00rootroot00000000000000root=true [*] end_of_line = lf insert_final_newline = true [*.js] indent_style = tab [*.json] indent_style = space indent_size = 2 isomorphic-fetch-2.2.1/.gitignore000066400000000000000000000000421262304202000167320ustar00rootroot00000000000000/node_modules/ /bower_components/ isomorphic-fetch-2.2.1/.jshintrc000066400000000000000000000001201262304202000165640ustar00rootroot00000000000000{ "node": true, "browser": true, "predef": ["describe", "it", "before"] } isomorphic-fetch-2.2.1/.travis.yml000066400000000000000000000006541262304202000170640ustar00rootroot00000000000000sudo: false language: node_js node_js: - "0.10" before_deploy: - npm-prepublish --verbose deploy: provider: npm email: matt@mattandre.ws api_key: secure: eEeb1aG7phF4X5z+CQ3yzTdXtHf71Dk4ec6v5iAjRYNh/s6GLxfZS7c4qocZI8YXW3YmmsJR5zGZ2l88k2iqTtlBn0Mrp6ytwIa/jO00kDpR8V11eW9i47KRQq25eA1YW+SrLM5V/fh+s9u3VU7jhbax5eeViqVdwORI85kZrZE= on: all_branches: true tags: true repo: matthew-andrews/isomorphic-fetch isomorphic-fetch-2.2.1/LICENSE000066400000000000000000000020671262304202000157600ustar00rootroot00000000000000The MIT License (MIT) Copyright (c) 2015 Matt Andrews Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. isomorphic-fetch-2.2.1/README.md000066400000000000000000000023021262304202000162220ustar00rootroot00000000000000isomorphic-fetch [![Build Status](https://travis-ci.org/matthew-andrews/isomorphic-fetch.svg?branch=master)](https://travis-ci.org/matthew-andrews/isomorphic-fetch) ================ Fetch for node and Browserify. Built on top of [GitHub's WHATWG Fetch polyfill](https://github.com/github/fetch). ## Warnings - This adds `fetch` as a global so that its API is consistent between client and server. - You must bring your own ES6 Promise compatible polyfill, I suggest [es6-promise](https://github.com/jakearchibald/es6-promise). ## Installation ### NPM ```sh npm install --save isomorphic-fetch es6-promise ``` ### Bower ```sh bower install --save isomorphic-fetch es6-promise ``` ## Usage ```js require('es6-promise').polyfill(); require('isomorphic-fetch'); fetch('//offline-news-api.herokuapp.com/stories') .then(function(response) { if (response.status >= 400) { throw new Error("Bad response from server"); } return response.json(); }) .then(function(stories) { console.log(stories); }); ``` ## License All open source code released by FT Labs is licenced under the MIT licence. Based on [the fine work by](https://github.com/github/fetch/pull/31) **[jxck](https://github.com/Jxck)**. isomorphic-fetch-2.2.1/bower.json000066400000000000000000000001751262304202000167620ustar00rootroot00000000000000{ "name": "isomorphic-fetch", "main": ["fetch-bower.js"], "dependencies": { "fetch": "github/fetch#>=0.10.0" } } isomorphic-fetch-2.2.1/fetch-bower.js000066400000000000000000000000431262304202000175060ustar00rootroot00000000000000module.exports = require('fetch'); isomorphic-fetch-2.2.1/fetch-npm-browserify.js000066400000000000000000000003511262304202000213550ustar00rootroot00000000000000// the whatwg-fetch polyfill installs the fetch() function // on the global object (window or self) // // Return that as the export for use in Webpack, Browserify etc. require('whatwg-fetch'); module.exports = self.fetch.bind(self); isomorphic-fetch-2.2.1/fetch-npm-node.js000066400000000000000000000005551262304202000201150ustar00rootroot00000000000000"use strict"; var realFetch = require('node-fetch'); module.exports = function(url, options) { if (/^\/\//.test(url)) { url = 'https:' + url; } return realFetch.call(this, url, options); }; if (!global.fetch) { global.fetch = module.exports; global.Response = realFetch.Response; global.Headers = realFetch.Headers; global.Request = realFetch.Request; } isomorphic-fetch-2.2.1/package.json000066400000000000000000000020521262304202000172330ustar00rootroot00000000000000{ "name": "isomorphic-fetch", "version": "0.0.0", "description": "Isomorphic WHATWG Fetch API, for Node & Browserify", "browser": "fetch-npm-browserify.js", "main": "fetch-npm-node.js", "scripts": { "files": "find . -name '*.js' ! -path './node_modules/*' ! -path './bower_components/*'", "test": "jshint `npm run -s files` && lintspaces -i js-comments -e .editorconfig `npm run -s files` && mocha" }, "repository": { "type": "git", "url": "https://github.com/matthew-andrews/isomorphic-fetch.git" }, "author": "Matt Andrews ", "license": "MIT", "bugs": { "url": "https://github.com/matthew-andrews/isomorphic-fetch/issues" }, "homepage": "https://github.com/matthew-andrews/isomorphic-fetch/issues", "dependencies": { "node-fetch": "^1.0.1", "whatwg-fetch": ">=0.10.0" }, "devDependencies": { "chai": "^1.10.0", "es6-promise": "^2.0.1", "jshint": "^2.5.11", "lintspaces-cli": "0.0.4", "mocha": "^2.1.0", "nock": "^0.56.0", "npm-prepublish": "^1.0.2" } } isomorphic-fetch-2.2.1/test/000077500000000000000000000000001262304202000157255ustar00rootroot00000000000000isomorphic-fetch-2.2.1/test/api.test.js000066400000000000000000000022371262304202000200160ustar00rootroot00000000000000/*global fetch*/ "use strict"; require('es6-promise').polyfill(); require('../fetch-npm-node'); var expect = require('chai').expect; var nock = require('nock'); var good = 'hello world. 你好世界。'; var bad = 'good bye cruel world. 再见残酷的世界。'; function responseToText(response) { if (response.status >= 400) throw new Error("Bad server response"); return response.text(); } describe('fetch', function() { before(function() { nock('https://mattandre.ws') .get('/succeed.txt') .reply(200, good); nock('https://mattandre.ws') .get('/fail.txt') .reply(404, bad); }); it('should be defined', function() { expect(fetch).to.be.a('function'); }); it('should facilitate the making of requests', function(done) { fetch('//mattandre.ws/succeed.txt') .then(responseToText) .then(function(data) { expect(data).to.equal(good); done(); }) .catch(done); }); it('should do the right thing with bad requests', function(done) { fetch('//mattandre.ws/fail.txt') .then(responseToText) .catch(function(err) { expect(err.toString()).to.equal("Error: Bad server response"); done(); }) .catch(done); }); });