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

duck-duck-scrape

Package Overview
Dependencies
Maintainers
2
Versions
26
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

duck-duck-scrape - npm Package Compare versions

Comparing version 1.0.1 to 1.0.2

docs/fonts/OpenSans-Bold-webfont.eot

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&current=1&user=${handle}`)

2

package.json
{
"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 @@

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