Skip to content

Commit 19cac73

Browse files
added esm minified version, refactored readme.md
1 parent ad59fb0 commit 19cac73

File tree

2 files changed

+26
-31
lines changed

2 files changed

+26
-31
lines changed

README.md

+25-30
Original file line numberDiff line numberDiff line change
@@ -5,39 +5,37 @@
55
[![](https://badgen.net/npm/license/safe-jsonp)](https://unpkg.com/safe-jsonp/dist/safe-jsonp.umd.js)
66

77

8-
A sandboxed JSONP implementation for browsers.
9-
10-
# Why
11-
12-
If for any reason you still have to use JSONP instead of ajax & CORS on a page with sensitive data to fetch data
13-
from third-party services, you can use this package which makes jsonp requests more secure using a temporary sandboxed
14-
iframe as a proxy. This could potentially protect from XSS attacks injected in the jsonp response,
15-
since the sandbox iframe does not have unsafe access to its parent page. At the same time, json data can be sent
16-
from iframe to the parent document as a simple json string using the window.postMessage feature.
17-
The package supports sandbox and non-sandbox mode (like typical jsonp packages), by default
18-
sandbox mode is preferred, but not required.
8+
:star: A safer JSONP implementation for browsers with extra features :star:
199

2010
# Features
21-
- :zap: **exclusive: optional sandbox mechanism for safer requests to untrusted origins (internally used iframes)**
22-
- :zap: **exclusive: ability to abort the related http request in sandbox mode- other libs can't do this at all,
23-
they just ignore the response, but related http query keeps in pending state for some time**
24-
- support Promise and callback styles
25-
- support custom Promise class
26-
- anti-caching `_rnd` query param
27-
- support query params in url string and/or options.params property
11+
- :zap: **safer requests to untrusted origins using optional sandbox mechanism\* (iframes & postMessage used inside)**
12+
- :zap: **can abort the related http requests\** (other libs just ignore the response, but related http query keeps in pending state for some time**
13+
- :heavy_check_mark: no dependencies
14+
- :heavy_check_mark: CDN friendly
15+
- supports Promise and callback styles
16+
- supports custom Promise class
17+
- supports query params in url string and/or options.params property
2818
- automatically encoding params, converting objects and arrays params to JSON strings
19+
- anti-caching `_rnd` query param
2920

21+
\* this feature works only in modern browsers (except all IE).
22+
23+
\** not available in IE, Edge has partial support.
3024
## Try It!
3125
[JSFiddle.net demo](https://jsfiddle.net/DigitalBrain/ugz5qn0r/)
3226

3327
## Installation
3428

35-
Install for node.js or browserify using `npm`:
29+
Install for node.js or browserify using npm or yarn:
3630

3731
``` bash
3832
$ npm install safe-jsonp --save
3933
```
4034

35+
``` bash
36+
$ yarn add safe-jsonp
37+
```
38+
4139
## Basic usage example
4240
Promise style:
4341
```javascript
@@ -68,22 +66,16 @@ JSONP('http://api.github.com/users/DigitalBrainJS', (err, data) => {
6866

6967
## CDN
7068
Use unpkg.com cdn to get the link to the script/module from the package:
71-
- UMD ES5 version (~15kB)
69+
- minified (production) UMD ES5 version (~7kB)
7270
```html
7371
<script src="https://unpkg.com/safe-jsonp"></script>
7472
```
75-
- minified UMD ES5 version (~7kB)
76-
```html
77-
<script src="https://unpkg.com/safe-jsonp/dist/safe-jsonp.umd.min.js"></script>
78-
```
79-
- ESM ES2015 module (~14kB)
73+
- ESM ES2015 module(~14kB)
8074
```javascript
8175
import JSONP from "https://unpkg.com/safe-jsonp/dist/safe-jsonp.esm.js"
76+
//or minified version
77+
import JSONP from "https://unpkg.com/safe-jsonp/dist/safe-jsonp.esm.min.js"
8278
```
83-
## Functional diagram
84-
Sandbox mode:
85-
86-
![Sandbox functional diagram](https://github.com/DigitalBrainJS/safe-jsonp/raw/master/public/safe-jsonp.png)
8779

8880
## More examples
8981
##### additional options:
@@ -170,7 +162,10 @@ Returns a promise or JSON instance depending on the presence of a callback argum
170162
- `parseURL(url: String): URL|Object` parse URL into components
171163
- `parseParams(paramsStr: String): Object` parse URL params string eg. `a=1&b=2` to params object `{a:1, b:2}`
172164
- `encodeParams(params: Object): String` encode params object to string
173-
165+
## Functional diagram
166+
Sandbox mode:
167+
168+
![Sandbox functional diagram](https://github.com/DigitalBrainJS/safe-jsonp/raw/master/public/safe-jsonp.png)
174169
## Contribution
175170
Feel free to fork, open issues, enhance or create pull requests.
176171
## License

gulpfile.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ const webserver = () => {
9090
};
9191

9292
const buildTask = createBuildTask(ENTRY_FILE, {exportName: EXPORT_NAME, toES5: true, minify: true});
93-
const buildTaskES = createBuildTask(ENTRY_FILE, {format: 'esm'});
93+
const buildTaskES = createBuildTask(ENTRY_FILE, {format: 'esm', minify: true});
9494
const buildTests = createBuildTask(`test/${BASE_NAME}.spec.js`, {
9595
taskTargetName: 'test',
9696
format: 'cjs',

0 commit comments

Comments
 (0)