Socket
Socket
Sign inDemoInstall

unfetch

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

unfetch - npm Package Compare versions

Comparing version 4.2.0 to 5.0.0

dist/unfetch.mjs

2

dist/unfetch.js

@@ -1,2 +0,2 @@

module.exports=function(e,n){return n=n||{},new Promise(function(t,r){var s=new XMLHttpRequest,o=[],u=[],i={},a=function(){return{ok:2==(s.status/100|0),statusText:s.statusText,status:s.status,url:s.responseURL,text:function(){return Promise.resolve(s.responseText)},json:function(){return Promise.resolve(s.responseText).then(JSON.parse)},blob:function(){return Promise.resolve(new Blob([s.response]))},clone:a,headers:{keys:function(){return o},entries:function(){return u},get:function(e){return i[e.toLowerCase()]},has:function(e){return e.toLowerCase()in i}}}};for(var l in s.open(n.method||"get",e,!0),s.onload=function(){s.getAllResponseHeaders().replace(/^(.*?):[^\S\n]*([\s\S]*?)$/gm,function(e,n,t){o.push(n=n.toLowerCase()),u.push([n,t]),i[n]=i[n]?i[n]+","+t:t}),t(a())},s.onerror=r,s.withCredentials="include"==n.credentials,n.headers)s.setRequestHeader(l,n.headers[l]);s.send(n.body||null)})};
module.exports=function(e,n){return n=n||{},new Promise(function(t,r){var s=new XMLHttpRequest,o=[],u={},a=function e(){return{ok:2==(s.status/100|0),statusText:s.statusText,status:s.status,url:s.responseURL,text:function(){return Promise.resolve(s.responseText)},json:function(){return Promise.resolve(s.responseText).then(JSON.parse)},blob:function(){return Promise.resolve(new Blob([s.response]))},clone:e,headers:{keys:function(){return o},entries:function(){return o.map(function(e){return[e,s.getResponseHeader(e)]})},get:function(e){return s.getResponseHeader(e)},has:function(e){return null!=s.getResponseHeader(e)}}}};for(var i in s.open(n.method||"get",e,!0),s.onload=function(){s.getAllResponseHeaders().toLowerCase().replace(/^(.+?):/gm,function(e,n){u[n]||o.push(u[n]=n)}),t(a())},s.onerror=r,s.withCredentials="include"==n.credentials,n.headers)s.setRequestHeader(i,n.headers[i]);s.send(n.body||null)})};
//# sourceMappingURL=unfetch.js.map

@@ -1,2 +0,2 @@

!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):e.unfetch=n()}(this,function(){return function(e,n){return n=n||{},new Promise(function(t,o){var r=new XMLHttpRequest,s=[],u=[],i={},f=function(){return{ok:2==(r.status/100|0),statusText:r.statusText,status:r.status,url:r.responseURL,text:function(){return Promise.resolve(r.responseText)},json:function(){return Promise.resolve(r.responseText).then(JSON.parse)},blob:function(){return Promise.resolve(new Blob([r.response]))},clone:f,headers:{keys:function(){return s},entries:function(){return u},get:function(e){return i[e.toLowerCase()]},has:function(e){return e.toLowerCase()in i}}}};for(var a in r.open(n.method||"get",e,!0),r.onload=function(){r.getAllResponseHeaders().replace(/^(.*?):[^\S\n]*([\s\S]*?)$/gm,function(e,n,t){s.push(n=n.toLowerCase()),u.push([n,t]),i[n]=i[n]?i[n]+","+t:t}),t(f())},r.onerror=o,r.withCredentials="include"==n.credentials,n.headers)r.setRequestHeader(a,n.headers[a]);r.send(n.body||null)})}});
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e||self).unfetch=n()}(this,function(){return function(e,n){return n=n||{},new Promise(function(t,o){var r=new XMLHttpRequest,s=[],u={},i=function e(){return{ok:2==(r.status/100|0),statusText:r.statusText,status:r.status,url:r.responseURL,text:function(){return Promise.resolve(r.responseText)},json:function(){return Promise.resolve(r.responseText).then(JSON.parse)},blob:function(){return Promise.resolve(new Blob([r.response]))},clone:e,headers:{keys:function(){return s},entries:function(){return s.map(function(e){return[e,r.getResponseHeader(e)]})},get:function(e){return r.getResponseHeader(e)},has:function(e){return null!=r.getResponseHeader(e)}}}};for(var f in r.open(n.method||"get",e,!0),r.onload=function(){r.getAllResponseHeaders().toLowerCase().replace(/^(.+?):/gm,function(e,n){u[n]||s.push(u[n]=n)}),t(i())},r.onerror=o,r.withCredentials="include"==n.credentials,n.headers)r.setRequestHeader(f,n.headers[f]);r.send(n.body||null)})}});
//# sourceMappingURL=unfetch.umd.js.map
{
"name": "unfetch",
"version": "4.2.0",
"version": "5.0.0",
"description": "Bare minimum fetch polyfill in 500 bytes",
"unpkg": "polyfill/index.js",
"main": "dist/unfetch.js",
"module": "dist/unfetch.module.js",
"jsnext:main": "dist/unfetch.module.js",
"umd:main": "dist/unfetch.umd.js",
"unpkg": "./polyfill/index.js",
"main": "./dist/unfetch.js",
"module": "./dist/unfetch.mjs",
"jsnext:main": "./dist/unfetch.mjs",
"umd:main": "./dist/unfetch.umd.js",
"scripts": {
"test": "eslint src test && jest",
"build": "microbundle src/index.mjs && microbundle -f cjs polyfill/polyfill.mjs -o polyfill/index.js --no-sourcemap && cp dist/unfetch.module.js dist/unfetch.es.js",
"test": "eslint && tsc -p . --noEmit && NODE_OPTIONS=--experimental-vm-modules jest",
"build": "microbundle src/index.mjs -f cjs,esm,umd && microbundle polyfill/polyfill.mjs -o polyfill/index.js -f cjs --no-sourcemap",
"prepare": "npm run -s build",
"release": "cross-var npm run build -s && cross-var git commit -am $npm_package_version && cross-var git tag $npm_package_version && git push && git push --tags && npm publish"
},
"exports": {
".": {
"import": "./index.mjs",
"default": "./index.js"
},
"./polyfill": {
"default": "./polyfill/index.js"
},
"./package.json": "./package.json",
"./*": "./*"
},
"workspaces": [
"./packages/isomorphic-unfetch"
],
"repository": "developit/unfetch",

@@ -38,12 +52,18 @@ "keywords": [

"jest": {
"testURL": "http://localhost/",
"testEnvironmentOptions": {
"url": "http://localhost/"
},
"testMatch": [
"<rootDir>/test/**/*.?(m)js?(x)"
"<rootDir>/test/**/*.test.?(m)[jt]s?(x)"
],
"setupFiles": [
"<rootDir>/test/_setup.js"
],
"moduleFileExtensions": [
"mjs",
"js"
"js",
"ts"
],
"transform": {
"^.+\\.m?jsx?$": "babel-jest"
"^.+\\.m?[jt]sx?$": "babel-jest"
}

@@ -55,3 +75,4 @@ },

"presets": [
"env"
"@babel/preset-env",
"@babel/preset-typescript"
]

@@ -62,9 +83,14 @@ }

"devDependencies": {
"babel-preset-env": "^1.7.0",
"@babel/core": "^7.20.7",
"@babel/preset-env": "^7.20.2",
"@babel/preset-typescript": "^7.18.6",
"@types/jest": "^29.2.5",
"@types/node": "^18.11.18",
"cross-var": "^1.1.0",
"eslint": "^3.13.1",
"eslint-config-developit": "^1.1.1",
"jest": "^23.6.0",
"microbundle": "^0.10.1"
"eslint": "^8.30.0",
"eslint-config-developit": "^1.2.0",
"jest": "^29.3.1",
"microbundle": "^0.15.1",
"typescript": "^4.9.4"
}
}

@@ -1,1 +0,1 @@

self.fetch||(self.fetch=function(e,n){return n=n||{},new Promise(function(t,s){var r=new XMLHttpRequest,o=[],u=[],i={},a=function(){return{ok:2==(r.status/100|0),statusText:r.statusText,status:r.status,url:r.responseURL,text:function(){return Promise.resolve(r.responseText)},json:function(){return Promise.resolve(r.responseText).then(JSON.parse)},blob:function(){return Promise.resolve(new Blob([r.response]))},clone:a,headers:{keys:function(){return o},entries:function(){return u},get:function(e){return i[e.toLowerCase()]},has:function(e){return e.toLowerCase()in i}}}};for(var c in r.open(n.method||"get",e,!0),r.onload=function(){r.getAllResponseHeaders().replace(/^(.*?):[^\S\n]*([\s\S]*?)$/gm,function(e,n,t){o.push(n=n.toLowerCase()),u.push([n,t]),i[n]=i[n]?i[n]+","+t:t}),t(a())},r.onerror=s,r.withCredentials="include"==n.credentials,n.headers)r.setRequestHeader(c,n.headers[c]);r.send(n.body||null)})});
self.fetch||(self.fetch=function(e,n){return n=n||{},new Promise(function(t,r){var s=new XMLHttpRequest,o=[],u={},a=function e(){return{ok:2==(s.status/100|0),statusText:s.statusText,status:s.status,url:s.responseURL,text:function(){return Promise.resolve(s.responseText)},json:function(){return Promise.resolve(s.responseText).then(JSON.parse)},blob:function(){return Promise.resolve(new Blob([s.response]))},clone:e,headers:{keys:function(){return o},entries:function(){return o.map(function(e){return[e,s.getResponseHeader(e)]})},get:function(e){return s.getResponseHeader(e)},has:function(e){return null!=s.getResponseHeader(e)}}}};for(var i in s.open(n.method||"get",e,!0),s.onload=function(){s.getAllResponseHeaders().toLowerCase().replace(/^(.+?):/gm,function(e,n){u[n]||o.push(u[n]=n)}),t(a())},s.onerror=r,s.withCredentials="include"==n.credentials,n.headers)s.setRequestHeader(i,n.headers[i]);s.send(n.body||null)})});
{
"name": "unfetch-polyfill",
"main": "index.js",
"module": "polyfill.module.js"
"source": "polyfill.mjs",
"main": "index.js"
}

@@ -46,3 +46,3 @@ <p align="center">

```sh
npm install --save unfetch
npm i unfetch
```

@@ -89,3 +89,3 @@

// or using CommonJS:
var fetch = require('unfetch')
const fetch = require('unfetch')

@@ -198,17 +198,15 @@ // usage:

fetch('/users')
.then( checkStatus )
.then( r => r.json() )
.then( data => {
.then(response => {
if (response.ok) {
return response;
}
// convert non-2xx HTTP responses into errors:
const error = new Error(response.statusText);
error.response = response;
return Promise.reject(error);
})
.then(response => response.json())
.then(data => {
console.log(data);
});
function checkStatus(response) {
if (response.ok) {
return response;
} else {
var error = new Error(response.statusText);
error.response = response;
return Promise.reject(error);
}
}
```

@@ -215,0 +213,0 @@

import {
Body as NodeBody,
Headers as NodeHeaders,
Request as NodeRequest,
Response as NodeResponse,
RequestInit as NodeRequestInit
Body as NodeBody,
Headers as NodeHeaders,
Request as NodeRequest,
Response as NodeResponse,
RequestInit as NodeRequestInit,
} from "node-fetch";
declare namespace unfetch {
export type IsomorphicHeaders = Headers | NodeHeaders;
export type IsomorphicBody = Body | NodeBody;
export type IsomorphicResponse = Response | NodeResponse;
export type IsomorphicRequest = Request | NodeRequest;
export type IsomorphicRequestInit = RequestInit | NodeRequestInit;
/** @augments Headers */
export interface UnfetchHeaders {
keys: () => string[];
entries: () => [string, string][];
get: (key: string) => string | null;
has: (key: string) => boolean;
/** @deprecated not supported by unfetch */
append: never;
/** @deprecated not supported by unfetch */
delete: never;
/** @deprecated not supported by unfetch */
forEach: never;
/** @deprecated not supported by unfetch */
set: never;
/** @deprecated not supported by unfetch */
values: never;
/** @deprecated not supported by unfetch */
[Symbol.iterator]: never;
}
type UnfetchResponse = {
ok: boolean,
statusText: string,
status: number,
url: string,
text: () => Promise<string>,
json: () => Promise<any>,
blob: () => Promise<Blob>,
clone: () => UnfetchResponse,
headers: {
keys: () => string[],
entries: () => Array<[string, string]>,
get: (key: string) => string | undefined,
has: (key: string) => boolean,
}
/** @augments Response */
export interface UnfetchResponse {
ok: boolean;
statusText: string;
status: number;
url: string;
text: () => Promise<string>;
json: () => Promise<any>;
blob: () => Promise<Blob>;
clone: () => UnfetchResponse;
headers: UnfetchHeaders;
/** @deprecated not supported by unfetch */
arrayBuffer: never;
/** @deprecated not supported by unfetch */
body: never;
/** @deprecated not supported by unfetch */
bodyUsed: never;
/** @deprecated not supported by unfetch */
formData: never;
/** @deprecated not supported by unfetch */
redirected: never;
/** @deprecated not supported by unfetch */
type: never;
}
type Unfetch = (
url: string,
options?: {
method?: string,
headers?: Record<string, string>,
credentials?: 'include' | 'omit',
body?: Parameters<XMLHttpRequest["send"]>[0]
}
) => Promise<UnfetchResponse>
/** @augments RequestInit */
export interface UnfetchRequestInit {
method?: string;
headers?: Record<string, string>;
credentials?: "include" | "omit";
body?: Parameters<XMLHttpRequest["send"]>[0];
/** @deprecated not supported by unfetch */
cache?: never;
/** @deprecated not supported by unfetch */
integrity?: never;
/** @deprecated not supported by unfetch */
keepalive?: never;
/** @deprecated not supported by unfetch */
mode?: never;
/** @deprecated not supported by unfetch */
redirect?: never;
/** @deprecated not supported by unfetch */
referrer?: never;
/** @deprecated not supported by unfetch */
referrerPolicy?: never;
/** @deprecated not supported by unfetch */
signal?: never;
/** @deprecated not supported by unfetch */
window?: never;
}
export namespace Unfetch {
export type IsomorphicHeaders = Headers | NodeHeaders;
export type IsomorphicBody = Body | NodeBody;
export type IsomorphicResponse = Response | NodeResponse;
export type IsomorphicRequest = Request | NodeRequest;
export type IsomorphicRequestInit = RequestInit | NodeRequestInit;
export type Headers = UnfetchHeaders | globalThis.Headers;
export type Body = globalThis.Body;
export type Response = UnfetchResponse | globalThis.Response;
export type Request = UnfetchRequestInit | globalThis.Request;
export type RequestInit = UnfetchRequestInit | globalThis.RequestInit;
}
export interface Unfetch {
(url: string | URL, options?: UnfetchRequestInit): Promise<UnfetchResponse>;
}
declare const unfetch: Unfetch;
export default unfetch;

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc