async-g-i-s
Advanced tools
Comparing version 1.0.0 to 1.1.0
48
index.js
@@ -16,3 +16,3 @@ const cheerio = require('cheerio'); | ||
* @param {[String]} filterOutDomains Not looking for these domains | ||
* @returns {Promise<[Result]>} Array of results | ||
* @returns {Promise<[Object]>} Array of results | ||
*/ | ||
@@ -25,5 +25,3 @@ async function gis(searchTerm, queryStringAddition = "", filterOutDomains = ['gstatic.com']) { | ||
const url = `${baseURL}?tbm=isch&q=${searchTerm}${queryStringAddition}` | ||
const body = await fetch(url, { | ||
const body = await fetch(`${baseURL}?tbm=isch&q=${searchTerm}${queryStringAddition}`, { | ||
headers: { | ||
@@ -57,13 +55,17 @@ 'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36' | ||
while ((result = regex.exec(content)) !== null) { | ||
while ((result = regex.exec(content)) !== null) | ||
if (result.length > 3) { | ||
const ref = new Result(result[1], +result[2], +result[3]); | ||
const ref = { | ||
url: result[1], | ||
height: +result[2], | ||
width: +result[3] | ||
} | ||
if (filterOutDomains.every(skipDomain => ref.url.indexOf(skipDomain) === -1)) | ||
if (filterOutDomains.every(skipDomain => !ref.url.includes(skipDomain))) | ||
results.push(ref); | ||
} | ||
} | ||
return results; | ||
@@ -78,32 +80,2 @@ | ||
/** | ||
* Image search result class | ||
*/ | ||
class Result { | ||
/** | ||
* Image search result | ||
* @param {String} url Image URL | ||
* @param {Number} height | ||
* @param {Number} width | ||
*/ | ||
constructor(url, height, width) { | ||
/** | ||
* Image URL | ||
*/ | ||
this.url = url; | ||
/** | ||
* Image height | ||
*/ | ||
this.height = height; | ||
/** | ||
* Image width | ||
*/ | ||
this.width = width; | ||
} | ||
} | ||
module.exports = gis; |
{ | ||
"name": "async-g-i-s", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "Async Google Image Search", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "node ./tests/test" | ||
"test": "node test" | ||
}, | ||
"types": "index.d.ts", | ||
"repository": { | ||
@@ -13,3 +14,7 @@ "type": "git", | ||
}, | ||
"keywords": [], | ||
"keywords": [ | ||
"google", | ||
"image", | ||
"search" | ||
], | ||
"author": "Akif9748", | ||
@@ -16,0 +21,0 @@ "license": "MIT", |
@@ -0,0 +0,0 @@ # async-g-i-s |
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
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
6857
6
72