Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

better-jsonp

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

better-jsonp - npm Package Compare versions

Comparing version 1.0.1 to 1.0.2

2

dist/better-jsonp.common.js
/*!
* better-jsonp v1.0.1
* better-jsonp v1.0.2
* Copyrights (c) 2018 Bowen (lbwa)

@@ -4,0 +4,0 @@ * Released under the MIT License.

/*!
* better-jsonp v1.0.1
* better-jsonp v1.0.2
* Copyrights (c) 2018 Bowen (lbwa)

@@ -9,3 +9,3 @@ * Released under the MIT License.

typeof define === 'function' && define.amd ? define(factory) :
(global.Jsonp = factory());
(global.jsonp = factory());
}(this, (function () { 'use strict';

@@ -12,0 +12,0 @@

/*!
* better-jsonp v1.0.1
* better-jsonp v1.0.2
* Copyrights (c) 2018 Bowen (lbwa)
* Released under the MIT License.
*/
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):e.Jsonp=t()}(this,function(){"use strict";function e(){}function t(e,t,n){Reflect.defineProperty(e,t,{enumerable:!1,writable:!0,value:n})}function n(e){return encodeURIComponent(e)}var i=function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")},r=function(){function e(e,t){for(var n=0;n<t.length;n++){var i=t[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,i.key,i)}}return function(t,n,i){return n&&e(t.prototype,n),i&&e(t,i),t}}(),a={timeout:6e3,prefix:"callback",callbackParams:"jsonpCallback",urlParams:{}},l=function(){function l(){i(this,l)}return r(l,[{key:"checkOptions",value:function(e){if(!e.url)throw new Error("Please check your request url.");this.options=e}},{key:"generateJsonpCallback",value:function(e){if(e.jsonpCallback)this._jsonpCallback=e.jsonpCallback;else{var t=a.prefix;this._jsonpCallback=t+Date.now()}}},{key:"defineGlobalCallback",value:function(){var e=this;return new Promise(function(t,n){window[e._jsonpCallback]=function(n){e.cleanScript(),t(n)}})}},{key:"generateTimer",value:function(t){var n=this,i=t.timeout||a.timeout;i&&(this._timer=setTimeout(function(){throw window[n._jsonpCallback]=e,n._timer=null,n.cleanScript(),new Error("JSONP request unsuccessfully (eg.timeout or wrong url).")},i))}},{key:"initState",value:function(e){t(this,"_timer",null),t(this,"_request",null),t(this,"_jsonpCallback",null),t(this,"_insertScript",null),t(this,"_target",null),this.generateJsonpCallback(e),t(this,"_globalCallback",this.defineGlobalCallback()),this.generateTimer(e)}},{key:"encodeURL",value:function(e){var t=this.options.callbackParams||a.callbackParams,i=n(this._jsonpCallback);e+=(e.indexOf("?")<0?"?":"&")+t+"="+i;var r=this.options.urlParams||a.urlParams;Object.keys(r).forEach(function(t){var i=void 0!==r[t]?r[t]:"";e+="&"+t+"="+n(i)}),this._request=e}},{key:"insertToElement",value:function(e){this._target=document.getElementsByTagName("script")[0]||document.body.lastElementChild,this._insertScript=document.createElement("script"),this._insertScript.src=e,this._target.parentNode.insertBefore(this._insertScript,this._target)}},{key:"cleanScript",value:function(){this._insertScript.parentNode&&(this._target.parentNode.removeChild(this._insertScript),this._insertScript=null),window[this._jsonpCallback]=e,this._timer&&clearTimeout(this._timer)}}]),l}();return function(e){var t=new l;return t.checkOptions(e),t.initState(e),t.encodeURL(t.options.url),t.insertToElement(t._request),t._globalCallback}});
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):e.jsonp=t()}(this,function(){"use strict";function e(){}function t(e,t,n){Reflect.defineProperty(e,t,{enumerable:!1,writable:!0,value:n})}function n(e){return encodeURIComponent(e)}var i=function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")},r=function(){function e(e,t){for(var n=0;n<t.length;n++){var i=t[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,i.key,i)}}return function(t,n,i){return n&&e(t.prototype,n),i&&e(t,i),t}}(),a={timeout:6e3,prefix:"callback",callbackParams:"jsonpCallback",urlParams:{}},l=function(){function l(){i(this,l)}return r(l,[{key:"checkOptions",value:function(e){if(!e.url)throw new Error("Please check your request url.");this.options=e}},{key:"generateJsonpCallback",value:function(e){if(e.jsonpCallback)this._jsonpCallback=e.jsonpCallback;else{var t=a.prefix;this._jsonpCallback=t+Date.now()}}},{key:"defineGlobalCallback",value:function(){var e=this;return new Promise(function(t,n){window[e._jsonpCallback]=function(n){e.cleanScript(),t(n)}})}},{key:"generateTimer",value:function(t){var n=this,i=t.timeout||a.timeout;i&&(this._timer=setTimeout(function(){throw window[n._jsonpCallback]=e,n._timer=null,n.cleanScript(),new Error("JSONP request unsuccessfully (eg.timeout or wrong url).")},i))}},{key:"initState",value:function(e){t(this,"_timer",null),t(this,"_request",null),t(this,"_jsonpCallback",null),t(this,"_insertScript",null),t(this,"_target",null),this.generateJsonpCallback(e),t(this,"_globalCallback",this.defineGlobalCallback()),this.generateTimer(e)}},{key:"encodeURL",value:function(e){var t=this.options.callbackParams||a.callbackParams,i=n(this._jsonpCallback);e+=(e.indexOf("?")<0?"?":"&")+t+"="+i;var r=this.options.urlParams||a.urlParams;Object.keys(r).forEach(function(t){var i=void 0!==r[t]?r[t]:"";e+="&"+t+"="+n(i)}),this._request=e}},{key:"insertToElement",value:function(e){this._target=document.getElementsByTagName("script")[0]||document.body.lastElementChild,this._insertScript=document.createElement("script"),this._insertScript.src=e,this._target.parentNode.insertBefore(this._insertScript,this._target)}},{key:"cleanScript",value:function(){this._insertScript.parentNode&&(this._target.parentNode.removeChild(this._insertScript),this._insertScript=null),window[this._jsonpCallback]=e,this._timer&&clearTimeout(this._timer)}}]),l}();return function(e){var t=new l;return t.checkOptions(e),t.initState(e),t.encodeURL(t.options.url),t.insertToElement(t._request),t._globalCallback}});

@@ -0,0 +0,0 @@ import { noop, defineEnumerable, euc } from '../utils/index.js'

{
"name": "better-jsonp",
"version": "1.0.1",
"version": "1.0.2",
"description": "A simple JSONP implementation",

@@ -5,0 +5,0 @@ "main": "dist/better-jsonp.common.js",

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