Socket
Socket
Sign inDemoInstall

elara-google-search

Package Overview
Dependencies
36
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.0.2 to 1.0.3

14

index.js

@@ -0,1 +1,2 @@

const sendError = (msg) => {return {status: false, message: msg}};
module.exports = class Google{

@@ -7,8 +8,12 @@ constructor(key, cx){

async search(search){
if(!search) return {status: false, message: `You didn't provide anything to search for!`};
try{
if(!search) return sendError(`You didn't provide anything to search for!`);
if(!this.key) return sendError(`You didn't provide an api key!`);
if(!this.cx) return sendError(`You didn't provide an CX ID!`);
let {get} = require('superagent');
let res = await get(`https://www.googleapis.com/customsearch/v1?key=${this.key}&q=${encodeURIComponent(search)}&cx=${this.cx}`);
if(res.status === 200){
if(!res.body) return sendError(`I was unable to fetch the information.`);
let links = [];
if(res.body.items.length === 0) return {status: false, message: `Nothing for that. :(`};
if(res.body.items.length === 0) return sendError(`Nothing for that. :(`)
for await (const i of res.body.items){

@@ -19,5 +24,8 @@ links.push(i.link);

}else{
return {status: false, message: `I was unable to find a search for that.`};
return sendError(`I was unable to find a search for that.`);
}
}catch(err){
return sendError(err.message);
}
}
};
{
"name": "elara-google-search",
"version": "1.0.2",
"version": "1.0.3",
"description": "Returns the google search results, requires an api key & cx ID",

@@ -5,0 +5,0 @@ "main": "index.js",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc