Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
codler committed Oct 9, 2018
0 parents commit 31f67b1
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Fetch-register

_Fetch just works_

Add [`fetch`](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API) globally on any js environment.

## Usage

Add once in beginning of your project

```js
require("fetch-register");
```
14 changes: 14 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const 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;
}
13 changes: 13 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "fetch-register",
"version": "1.0.0",
"description": "Fetch just works",
"main": "index.js",
"scripts": {},
"keywords": [
"fetch"
],
"author": "Han Lin Yap (http://yap.nu)",
"license": "ISC",
"dependencies": {
"node-fetch": "^2.2.0"
}
}

0 comments on commit 31f67b1

Please sign in to comment.