duck-duck-scrape
Advanced tools
Comparing version 1.0.1 to 1.0.2
83
index.js
@@ -6,3 +6,9 @@ const sf = require('snekfetch') | ||
const userAgent = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.140 Safari/537.36 OPR/51.0.2830.34' | ||
/** | ||
* @typedef {integer} safeSearchInt - 1 is safe, -1 is moderate, and -2 is off | ||
*/ | ||
/** | ||
* Creates a DDGScraper. | ||
* @class | ||
*/ | ||
module.exports = class DDGScraper { | ||
@@ -64,3 +70,8 @@ constructor() { | ||
} | ||
/** | ||
* Defines a spice | ||
* @function _defineSpice | ||
* @param {string} spice - The DDG spice you want to use | ||
* @returns {string} - Returns a spice | ||
*/ | ||
_defineSpice(spice) { | ||
@@ -89,3 +100,13 @@ Object.defineProperty(this.constructor.prototype, spice.name, { | ||
} | ||
/** | ||
* | ||
* @function search | ||
* @async | ||
* @param {string} query - The query string | ||
* @param {safeSearchInt} safeSearch - Level of SafeSearch. | ||
* @param {string} locale - The locale to search in | ||
* @returns { | ||
Promise | ||
} - Promise object represents an array of your results | ||
*/ | ||
async search(query, safeSearch = -2, locale = 'us-en') { | ||
@@ -104,3 +125,11 @@ const response = await sf.get(`https://duckduckgo.com/html/?q=${this._format(query)}&kr=${locale}&kp=${safeSearch}`) | ||
} | ||
/** | ||
* Autocompletes a string | ||
* @function autocomplete | ||
* @param {string} query - The query string | ||
* @async | ||
* @returns { | ||
Promise | ||
} - Promise object represents an array of your results | ||
*/ | ||
async autocomplete(query) { | ||
@@ -113,3 +142,13 @@ const response = await sf.get('https://duckduckgo.com/ac/').query({ | ||
} | ||
/** | ||
* Searches for an image | ||
* @function image | ||
* @param {string} query - The query string | ||
* @param {boolean} safe - Whether Safe Search is on or not | ||
* @param {string} locale - The locale you want to search in | ||
* @async | ||
* @returns { | ||
Promise | ||
} - Promise object represents an array of your results | ||
*/ | ||
async image(query, safe = false, locale = 'us-en') { | ||
@@ -120,3 +159,13 @@ const safeSearch = safe ? 1 : -1 | ||
} | ||
/** | ||
* Searches for a video | ||
* @function video | ||
* @param {string} query - The query string | ||
* @param {boolean} safe - Whether Safe Search is on or not | ||
* @param {string} locale - The locale you want to search in | ||
* @async | ||
* @returns { | ||
Promise | ||
} - Promise object represents an array of your results | ||
*/ | ||
async video(query, safe = false, locale = 'us-en') { | ||
@@ -127,3 +176,12 @@ const safeSearch = safe ? 1 : -1 | ||
} | ||
/** | ||
* Searches Amazon. | ||
* @function amazon | ||
* @param {string} query - The query string | ||
* @param {boolean} safe - Whether Safe Search is on or not | ||
* @async | ||
* @returns { | ||
Promise | ||
} - Promise object represents an array of your results | ||
*/ | ||
async amazon(query, safe = false) { | ||
@@ -134,3 +192,12 @@ const safeSearch = safe ? 1 : -1 | ||
} | ||
/** | ||
* Searches Twitter | ||
* @function twitter | ||
* @param {string} handle - The Twitter handle to search for | ||
* @async | ||
* @returns { | ||
Promise | ||
} - Promise object represents an array of your results | ||
*/ | ||
async twitter(handle) { | ||
@@ -137,0 +204,0 @@ const response = await sf.get(`https://duckduckgo.com/tw.js?callback=ddg_spice_twitter¤t=1&user=${handle}`) |
{ | ||
"name": "duck-duck-scrape", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "A DuckDuckGo scraper for Node.js.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -16,36 +16,6 @@ # duck-duck-scrape | ||
``` | ||
# Safe Search | ||
``` | ||
1 = Safe | ||
-1 = Moderate | ||
-2 = Off | ||
# Documentation | ||
https://suushii.github.io/duck-duck-scrape | ||
For non-search functions safe search is a boolean | ||
``` | ||
# Functions | ||
```javascript | ||
//Search | ||
ddg.search(query<String>, safe<Integer>, locale<locale string>) // returns a Promise | ||
//Autocomplete | ||
ddg.query(query<String>) // returns a Promise | ||
//Image Search (unstable, not sure why) | ||
ddg.image(query<String>, safe<Boolean>, locale<locale string>) // returns a Promise | ||
//Video Search | ||
ddg.video(query<String>, safe<Boolean>, locale<locale string>) // returns a Promise | ||
//Amazon Search | ||
ddg.amazon(query<String>, safe<Boolean>) // returns a Promise | ||
//Twitter Search | ||
ddg.twitter(handle<String>) // returns a Promise | ||
``` | ||
# Example | ||
``` javascript | ||
ddg.autocomplete("how to convert to ").then((value) => { console.log(value[0].phrase); }); // "how to convert to pdf" | ||
``` | ||
# Attribution | ||
@@ -52,0 +22,0 @@ |
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
Native code
Supply chain riskContains native code (e.g., compiled binaries or shared libraries). Including native code can obscure malicious behavior.
Found 10 instances in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Mixed license
License(Experimental) Package contains multiple licenses.
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
1051524
33
787
1
24
11