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

node-jsonp-client

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-jsonp-client - npm Package Compare versions

Comparing version 1.0.1 to 1.0.2

38

index.js

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

const { VM } = require('vm2');
const request = require('./lib/request');
const { VM } = require('vm2')
const fetch = require('node-fetch')
module.exports = async function jsonpClient(url) {
const resBody = await request(url);
const callbackNameReg = /^([$\w_][\d\w_$]+)\(/;
const jsonpStartReg = /^\(/;
const jsonpEndReg = /\);?$/m;
const isJsonpStart = jsonpStartReg.test(resBody);
const isJsonpEnd = jsonpEndReg.test(resBody);
let jsonp = resBody;
let callbackName = '';
const resBody = await fetch(url).then(res => res.text())
const callbackNameReg = /^([$\w_][\d\w_$]+)\(/
const jsonpStartReg = /^\(/
const jsonpEndReg = /\);?$/m
const isJsonpStart = jsonpStartReg.test(resBody)
const isJsonpEnd = jsonpEndReg.test(resBody)
let jsonp = resBody
let callbackName = ''
if (callbackNameReg.test(resBody) && isJsonpEnd) {
callbackName = jsonp.match(callbackNameReg)[1];
callbackName = jsonp.match(callbackNameReg)[1]
} else if (isJsonpStart && isJsonpEnd) {
callbackName = 'jsonp_' + Date.now().toString();
jsonp = callbackName + jsonp;
callbackName = 'jsonp_' + Date.now().toString()
jsonp = callbackName + jsonp
} else {
return resBody;
return resBody
}

@@ -26,10 +26,10 @@ const vm = new VM({

try {
return JSON.stringify(data);
return JSON.stringify(data)
} catch (error) {
return data.toString();
return data.toString()
}
}
}
});
return vm.run(jsonp);
};
})
return vm.run(jsonp)
}
{
"name": "node-jsonp-client",
"version": "1.0.1",
"version": "1.0.2",
"description": "a simple jsonp client for Node.js",

@@ -13,4 +13,7 @@ "main": "index.js",

},
"keywords": ["jsonp", "jsonp client for Node.js"],
"author": "meltifa",
"keywords": [
"jsonp",
"jsonp client for Node.js"
],
"author": "meltifa@gmail.com",
"license": "MIT",

@@ -21,4 +24,12 @@ "engines": {

"dependencies": {
"node-fetch": "^2.6.0",
"vm2": "^3.6.10"
},
"bugs": {
"url": "https://github.com/meltifa/node-jsonp-client/issues"
},
"homepage": "https://github.com/meltifa/node-jsonp-client#readme",
"directories": {
"lib": "lib"
}
}
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