node-jsonp-client
Advanced tools
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" | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 2 instances in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
1
1
1
3109
2
5
35
+ Addednode-fetch@^2.6.0
+ Addednode-fetch@2.7.0(transitive)
+ Addedtr46@0.0.3(transitive)
+ Addedwebidl-conversions@3.0.1(transitive)
+ Addedwhatwg-url@5.0.0(transitive)