pax_global_header00006660000000000000000000000064137325740330014521gustar00rootroot0000000000000052 comment=fc5e0d0d0b180e5b4c70b2ae7f738c50a9a51b25 isomorphic-fetch-3.0.0/000077500000000000000000000000001373257403300147645ustar00rootroot00000000000000isomorphic-fetch-3.0.0/.editorconfig000066400000000000000000000002061373257403300174370ustar00rootroot00000000000000root=true [*] end_of_line = lf insert_final_newline = true [*.js] indent_style = tab [*.json] indent_style = space indent_size = 2 isomorphic-fetch-3.0.0/.gitignore000066400000000000000000000000421373257403300167500ustar00rootroot00000000000000/node_modules/ /bower_components/ isomorphic-fetch-3.0.0/.jshintrc000066400000000000000000000001201373257403300166020ustar00rootroot00000000000000{ "node": true, "browser": true, "predef": ["describe", "it", "before"] } isomorphic-fetch-3.0.0/.travis.yml000066400000000000000000000000561373257403300170760ustar00rootroot00000000000000sudo: false language: node_js node_js: - 14 isomorphic-fetch-3.0.0/LICENSE000066400000000000000000000020671373257403300157760ustar00rootroot00000000000000The 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-3.0.0/README.md000066400000000000000000000040551373257403300162470ustar00rootroot00000000000000isomorphic-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. For [ease-of-maintenance and backward-compatibility reasons][why polyfill], this library will always be a polyfill. As a "safe" alternative, which does not modify the global, consider [fetch-ponyfill][]. [why polyfill]: https://github.com/matthew-andrews/isomorphic-fetch/issues/31#issuecomment-149668361 [fetch-ponyfill]: https://github.com/qubyte/fetch-ponyfill ## Why Use Isomorphic Fetch The Fetch API is currently [not implemented consistently](http://caniuse.com/#search=fetch) across browsers. This module will enable you to use `fetch` in your Node code in a cross-browser compliant fashion. The Fetch API is part of the Web platform API defined by the standards bodies WHATWG and W3C. ## Installation ### NPM ```sh npm install --save isomorphic-fetch ``` ### Bower ```sh bower install --save isomorphic-fetch ``` ## Usage ```js 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)**. ## Alternatives - [cross-fetch](https://github.com/lquixada/cross-fetch#why-not-isomorphic-fetch) - Using [node-fetch](https://github.com/node-fetch/node-fetch) and the [Fetch polyfill](https://github.com/github/fetch) directly (or from [polyfill.io](https://polyfill.io), or relying on [the browser's implementation of the Fetch API](https://caniuse.com/fetch)). isomorphic-fetch-3.0.0/bower.json000066400000000000000000000001731373257403300167760ustar00rootroot00000000000000{ "name": "isomorphic-fetch", "main": ["fetch-bower.js"], "dependencies": { "fetch": "github/fetch#^3.4.1" } } isomorphic-fetch-3.0.0/fetch-bower.js000066400000000000000000000000431373257403300175240ustar00rootroot00000000000000module.exports = require('fetch'); isomorphic-fetch-3.0.0/fetch-npm-browserify.js000066400000000000000000000003511373257403300213730ustar00rootroot00000000000000// 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-3.0.0/fetch-npm-node.js000066400000000000000000000005551373257403300201330ustar00rootroot00000000000000"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-3.0.0/package.json000066400000000000000000000017531373257403300172600ustar00rootroot00000000000000{ "name": "isomorphic-fetch", "version": "3.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": "^2.6.1", "whatwg-fetch": "^3.4.1" }, "devDependencies": { "chai": "^4.2.0", "jshint": "^2.5.11", "lintspaces-cli": "^0.7.1", "mocha": "^8.1.3", "nock": "^13.0.4" } } isomorphic-fetch-3.0.0/test/000077500000000000000000000000001373257403300157435ustar00rootroot00000000000000isomorphic-fetch-3.0.0/test/api.test.js000066400000000000000000000021741373257403300200340ustar00rootroot00000000000000/*global fetch*/ "use strict"; 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); }); });