Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
Antoni Kepinski committed May 17, 2020
0 parents commit fcea04c
Show file tree
Hide file tree
Showing 9 changed files with 184 additions and 0 deletions.
13 changes: 13 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# editorconfig.org

root = true

[*]
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
indent_style = tab

[*.md]
trim_trailing_whitespace = false
48 changes: 48 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Sketch temporary file
~*.sketch

# Generated files
dist/

# Logs
logs
*.log

# Runtime data
pids
*.pid
*.seed

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like nyc and istanbul
.nyc_output
coverage

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directory
# Commenting this out is preferred by some people, see
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git-
node_modules

# Users Environment Variables
.lock-wscript

# OS files
.DS_Store

# Babel-compiled files
lib

# Ignore package manager lock files
package-lock.json
yarn.lock

# Ignore IDE
.idea
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package-lock=false
5 changes: 5 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
language: node_js

node_js:
- "lts/*" # Latest LTS
- "node" # Latest Stable
21 changes: 21 additions & 0 deletions esm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
'use strict';

import fetch from 'node-fetch';

if (!global.fetch) {
global.fetch = fetch;
}

if (!global.Headers) {
global.Headers = fetch.Headers;
}

if (!global.Request) {
global.Request = fetch.Request;
}

if (!global.Response) {
global.Response = fetch.Response;
}

export default fetch;
3 changes: 3 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import fetch from 'node-fetch';

export = fetch;
21 changes: 21 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
'use strict';

const fetch = require('node-fetch');

if (!global.fetch) {
global.fetch = fetch;
}

if (!global.Headers) {
global.Headers = fetch.Headers;
}

if (!global.Request) {
global.Request = fetch.Request;
}

if (!global.Response) {
global.Response = fetch.Response;
}

module.exports = fetch;
63 changes: 63 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
{
"name": "@node-fetch/universal",
"version": "1.0.0",
"description": "Universal node-fetch wrapper",
"main": "index.js",
"module": "esm.js",
"browser": "esm.js",
"sideEffects": false,
"exports": {
"import": "esm.js",
"require": "index.js"
},
"files": [
"index.js",
"esm.js",
"*.d.ts"
],
"engines": {
"node": ">=10"
},
"scripts": {
"test": "xo && ava"
},
"repository": {
"type": "git",
"url": "https://github.com/node-fetch/universal.git"
},
"keywords": [
"fetch",
"http",
"promise",
"node-fetch",
"universal",
"isomorphic",
"cross-fetch",
"isomorphic-fetch",
"browser-fetch"
],
"author": "Antoni Kepinski <[email protected]> (https://kepinski.me)",
"license": "MIT",
"bugs": {
"url": "https://github.com/node-fetch/universal/issues"
},
"homepage": "https://github.com/node-fetch/universal",
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/node-fetch"
},
"devDependencies": {
"ava": "^3.8.2",
"node-fetch": "^3.0.0-beta.5",
"xo": "^0.30.0"
},
"peerDependencies": {
"node-fetch": ">=3.0.0-beta.5"
},
"xo": {
"envs": [
"node",
"browser"
]
}
}
9 changes: 9 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const test = require('ava');
const fetch = require('.');

test('main', async t => {
const response = await fetch('https://httpbin.org/json');
const {slideshow} = await response.json();

t.is(slideshow.title, 'Sample Slide Show');
});

0 comments on commit fcea04c

Please sign in to comment.