Socket
Socket
Sign inDemoInstall

browser-fetch-json

Package Overview
Dependencies
0
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.1.0 to 0.1.1

logos.png

4

browser-fetch-json.js

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

//! browser-fetch-json v0.1.0
//! browser-fetch-json v0.1.1
//! A thin wrapper around the Fetch API just for JSON in the browser

@@ -18,3 +18,3 @@ //! MIT License -- https://github.com/center-key/browser-fetch-json

if (fetchJson.logger)
fetchJson.logger(Date.now(), options.method, url.split('?')[0]);
fetchJson.logger(new Date().toISOString(), options.method, url);
return fetch(url, options).then(toJson);

@@ -21,0 +21,0 @@ },

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

//! browser-fetch-json v0.1.0
//! browser-fetch-json v0.1.1
//! MIT License -- https://github.com/center-key/browser-fetch-json
const fetchJson={request:function(a,b,c,d){const e={method:a.toUpperCase(),credentials:'same-origin'};d=Object.assign(e,d);return d.headers=Object.assign({"Content-Type":'application/json',Accept:'application/json'},d.headers),'GET'===d.method&&c?b=b+(b.includes('?')?'&':'?')+Object.keys(c).map(function(a){return a+'='+c[a]}).join('&'):'GET'!==d.method&&c&&(d.body=JSON.stringify(c)),fetchJson.logger&&fetchJson.logger(Date.now(),d.method,b.split('?')[0]),fetch(b,d).then(function(a){return a.json()})},get:function(a,b,c){return fetchJson.request('GET',a,b,c)},post:function(a,b,c){return fetchJson.request('POST',a,b,c)},put:function(a,b,c){return fetchJson.request('PUT',a,b,c)},patch:function(a,b,c){return fetchJson.request('PATCH',a,b,c)},delete:function(a,b,c){return fetchJson.request('DELETE',a,b,c)},logger:null,enableLogger:function(a){return fetchJson.logger='function'==typeof a?a:!1===a?null:console.log,fetchJson.logger}};'object'==typeof module?module.exports=fetchJson:'object'==typeof window&&(window.fetchJson=fetchJson);
const fetchJson={request:function(a,b,c,d){const e={method:a.toUpperCase(),credentials:'same-origin'};d=Object.assign(e,d);return d.headers=Object.assign({"Content-Type":'application/json',Accept:'application/json'},d.headers),'GET'===d.method&&c?b=b+(b.includes('?')?'&':'?')+Object.keys(c).map(function(a){return a+'='+c[a]}).join('&'):'GET'!==d.method&&c&&(d.body=JSON.stringify(c)),fetchJson.logger&&fetchJson.logger(new Date().toISOString(),d.method,b),fetch(b,d).then(function(a){return a.json()})},get:function(a,b,c){return fetchJson.request('GET',a,b,c)},post:function(a,b,c){return fetchJson.request('POST',a,b,c)},put:function(a,b,c){return fetchJson.request('PUT',a,b,c)},patch:function(a,b,c){return fetchJson.request('PATCH',a,b,c)},delete:function(a,b,c){return fetchJson.request('DELETE',a,b,c)},logger:null,enableLogger:function(a){return fetchJson.logger='function'==typeof a?a:!1===a?null:console.log,fetchJson.logger}};'object'==typeof module?module.exports=fetchJson:'object'==typeof window&&(window.fetchJson=fetchJson);
{
"name": "browser-fetch-json",
"description": "A thin wrapper around the Fetch API just for JSON in the browser",
"version": "0.1.0",
"version": "0.1.1",
"license": "MIT",

@@ -6,0 +6,0 @@ "main": "browser-fetch-json.js",

# browser-fetch-json
<img src=https://centerkey.com/graphics/center-key-logo.svg align=right width=200 alt=logo>
<img src=https://raw.githubusercontent.com/center-key/browser-fetch-json/master/logos.png
align=right width=200 alt=logos>

@@ -18,3 +19,3 @@ _A thin wrapper around the Fetch API just for JSON in the browser_

### A) Include
### 1) Include
In a web page:

@@ -39,3 +40,3 @@ ```html

### B) Examples
### 2) Examples
#### HTTP GET

@@ -65,3 +66,3 @@ Fetch the NASA Astronomy Picture of the Day:

### C) Leverages the Fetch API
### 3) Leverages the Fetch API
**browser-fetch-json** uses the browser's native **[Fetch API](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API)**.

@@ -91,3 +92,3 @@

### D) Details
### 4) Details
The **browser-fetch-json** module automatically:

@@ -100,3 +101,3 @@ 1. Serializes the body payload with `JSON.stringify()`.

### E) API
### 5) API
The format for using **browser-fetch-json** is:

@@ -144,4 +145,4 @@ #### GET

### F) Legacy web browsers
To support old legacy browsers, include polyfills for
### 6) Legacy web browsers
To support really old browsers, include polyfills for
[Promise](https://github.com/taylorhakes/promise-polyfill/) and

@@ -154,3 +155,3 @@ [Fetch API](https://github.com/github/fetch):

### G) Questions or enhancements
### 7) Questions or enhancements
Feel free to submit an [issue](https://github.com/center-key/browser-fetch-json/issues).

@@ -157,0 +158,0 @@

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc