You're Invited: Meet the Socket team at BSidesSF and RSAC - April 27 - May 1.RSVP

@zodash/jsonp

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@zodash/jsonp - npm Package Compare versions

Comparing version

to
0.0.9

@@ -6,2 +6,10 @@ # Change Log

## [0.0.9](https://github.com/zcorky/zodash/compare/@zodash/jsonp@0.0.8...@zodash/jsonp@0.0.9) (2021-05-03)
**Note:** Version bump only for package @zodash/jsonp
## [0.0.8](https://github.com/zcorky/zodash/compare/@zodash/jsonp@0.0.7...@zodash/jsonp@0.0.8) (2021-03-25)

@@ -8,0 +16,0 @@

"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });

@@ -22,41 +13,39 @@ exports.jsonp = void 0;

*/
function jsonp(url, options) {
async function jsonp(url, options) {
var _a, _b;
return __awaiter(this, void 0, void 0, function* () {
const timeout = (_a = options === null || options === void 0 ? void 0 : options.timeout) !== null && _a !== void 0 ? _a : 10000;
const callbackParam = (_b = options === null || options === void 0 ? void 0 : options.callbackParam) !== null && _b !== void 0 ? _b : 'callback';
return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
try {
// @S1 prepare callback
const callbackName = (options === null || options === void 0 ? void 0 : options.callbackName)
|| `_zodash_jsonp_callvack_${uuid_1.uuid().replace(/_/g, '_')}`;
const callbackFn = (data) => {
// clear callback
delete window[callbackName];
resolve(data);
};
window[callbackName] = callbackFn;
// @S2 prepare url
const _q_index = url.indexOf('?');
const _prefix = _q_index === -1 ? url : url.slice(0, _q_index);
const _search = url.slice(_q_index);
const _url = `${_prefix}?${add_1.add(_search, {
[callbackParam]: callbackName,
})}`;
// create timer
let it = setTimeout(() => {
reject(new Error('timeout'));
}, timeout);
// @S3 load JSONP
yield load_js_1.loadJs(_url, { enableCache: false });
// clear timer
if (it) {
clearTimeout(it);
it = null;
}
const timeout = (_a = options === null || options === void 0 ? void 0 : options.timeout) !== null && _a !== void 0 ? _a : 10000;
const callbackParam = (_b = options === null || options === void 0 ? void 0 : options.callbackParam) !== null && _b !== void 0 ? _b : 'callback';
return new Promise(async (resolve, reject) => {
try {
// @S1 prepare callback
const callbackName = (options === null || options === void 0 ? void 0 : options.callbackName)
|| `_zodash_jsonp_callvack_${uuid_1.uuid().replace(/_/g, '_')}`;
const callbackFn = (data) => {
// clear callback
delete window[callbackName];
resolve(data);
};
window[callbackName] = callbackFn;
// @S2 prepare url
const _q_index = url.indexOf('?');
const _prefix = _q_index === -1 ? url : url.slice(0, _q_index);
const _search = url.slice(_q_index);
const _url = `${_prefix}?${add_1.add(_search, {
[callbackParam]: callbackName,
})}`;
// create timer
let it = setTimeout(() => {
reject(new Error('timeout'));
}, timeout);
// @S3 load JSONP
await load_js_1.loadJs(_url, { enableCache: false });
// clear timer
if (it) {
clearTimeout(it);
it = null;
}
catch (error) {
reject(error);
}
}));
}
catch (error) {
reject(error);
}
});

@@ -63,0 +52,0 @@ }

{
"name": "@zodash/jsonp",
"version": "0.0.8",
"version": "0.0.9",
"description": "A simple jsonp function",

@@ -68,6 +68,6 @@ "keywords": [

"@zcorky/query-string": "^1.0.2",
"@zodash/load-js": "^0.2.11",
"@zodash/load-js": "^0.2.12",
"@zodash/uuid": "^0.1.6"
},
"gitHead": "bd85904bdf3094ed8d65df0fa57c695c74d4dc87"
"gitHead": "904ffa5f78d9aae6d39c9946cf5c36c7a4bcb60b"
}