New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

node-duckduckgo

Package Overview
Dependencies
Maintainers
1
Versions
32
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-duckduckgo - npm Package Compare versions

Comparing version 1.3.0 to 1.22.5

lib/duckIt.d.ts

29

lib/index.d.ts

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

import * as request from 'request';
import { RequestCallback, RequestResponse } from 'request';
import { allowedFormat, IFormatter, JsonFormatter } from './formatHelper';
import { SafeSearchValues, StdOptionValues } from './optionHelper';
export { JsonFormatter, RequestCallback, RequestResponse };
export declare const safeSearch_strict = 1;
export declare const safeSearch_moderate = -1;
export declare const safeSearch_off = -2;
export declare class Requester {
private appName;
private _baseUrl;
private _formatter;
private _noRedirect;
private _noHtml;
private _skipDisambig;
private _safeSearch;
constructor(appName?: string);
requestP(search: string): Promise<RequestResponse>;
request(search: string, callBack?: RequestCallback): request.Request;
private buildQueryOptions;
format: allowedFormat;
readonly formatter: IFormatter;
no_redirect: StdOptionValues;
no_html: StdOptionValues;
skip_disambig: StdOptionValues;
safe_search: SafeSearchValues;
}
import { duckIt, ParentalFilter, SearchOption } from './duckIt';
export { ParentalFilter, SearchOption, duckIt };
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const request = require("request");
const formatHelper_1 = require("./formatHelper");
exports.JsonFormatter = formatHelper_1.JsonFormatter;
const optionHelper_1 = require("./optionHelper");
const queryBuilder_1 = require("./queryBuilder");
exports.safeSearch_strict = 1;
exports.safeSearch_moderate = -1;
exports.safeSearch_off = -2;
// tslint:disable-next-line:min-class-cohesion
class Requester {
constructor(appName = 'node-duckduckgo') {
this.appName = appName;
this._baseUrl = 'https://api.duckduckgo.com/';
// tslint:disable-next-line:variable-name
this._formatter = formatHelper_1.getFormatter('json');
this._noRedirect = new optionHelper_1.OptionHelper('no_redirect');
this._noHtml = new optionHelper_1.OptionHelper('no_html');
this._skipDisambig = new optionHelper_1.OptionHelper('skip_disambig');
this._safeSearch = new optionHelper_1.OptionHelper('kp', exports.safeSearch_strict);
}
requestP(search) {
return new Promise((resolve, reject) => {
const cb = (error, response, body) => {
if (error !== undefined && error !== null) {
reject(error);
}
resolve(response);
};
this.request(search, cb);
});
}
request(search, callBack) {
const builder = queryBuilder_1.getBuilder();
builder.q(search);
builder.t(this.appName);
this._formatter.buildQueryParam(builder);
this.buildQueryOptions(builder);
const queryString = builder.toString();
return request(`${this._baseUrl}?${queryString}`, callBack);
}
buildQueryOptions(builder) {
this._noRedirect.buildQueryParam(builder);
this._noHtml.buildQueryParam(builder);
this._skipDisambig.buildQueryParam(builder);
this._safeSearch.buildQueryParam(builder);
}
set format(format) {
this._formatter = formatHelper_1.getFormatter(format);
}
get format() {
return this._formatter.getFormat();
}
get formatter() {
return this._formatter;
}
set no_redirect(value) {
this._noRedirect.option = value;
}
get no_redirect() {
return this._noRedirect.option;
}
set no_html(value) {
this._noHtml.option = value;
}
get no_html() {
return this._noHtml.option;
}
set skip_disambig(value) {
this._skipDisambig.option = value;
}
get skip_disambig() {
return this._skipDisambig.option;
}
set safe_search(value) {
this._safeSearch.option = value;
}
get safe_search() {
return this._safeSearch.option;
}
}
exports.Requester = Requester;
//# sourceMappingURL=index.js.map
const duckIt_1 = require("./duckIt");
exports.duckIt = duckIt_1.duckIt;
//# sourceMappingURL=index.js.map
{
"name": "node-duckduckgo",
"version": "1.3.0",
"version": "1.22.5",
"description": "DuckDuckGo client for node",

@@ -15,4 +15,5 @@ "main": "lib/index.js",

"scripts": {
"test": "gulp test",
"lint": "gulp lib:lint"
"lib": "nss-run lib",
"test": "nss-run test",
"lint": "nss-run lib:lint"
},

@@ -42,29 +43,36 @@ "repository": {

"devDependencies": {
"@types/chai": "^4.0.1",
"@types/jsonstream": "^0.8.28",
"@types/chai": "4.2.7",
"@types/mocha": "^5.2.5",
"@types/request": "^2.0.0",
"JSONStream": "^1.3.0",
"chai": "^4.1.0",
"del": "^4.0.0",
"gulp": "^3.9.1",
"gulp-istanbul": "^1.1.1",
"gulp-mocha": "^6.0.0",
"gulp-sourcemaps": "^2.6.0",
"gulp-tslint": "^8.1.1",
"gulp-typescript": "^5.0.1",
"gulp-use-tsconfig": "^1.1.3",
"mocha": "^6.0.2",
"remap-istanbul": "^0.13.0",
"ts-node": "^8.0.3",
"tslint": "^5.14.0",
"tslint-clean-code": "^0.2.7",
"typescript": "^3.3.3333",
"yarn": "^1.7.0"
"chai": "^4.2.0",
"del": "^5.1.0",
"mocha": "6.2.2",
"nss-run": "^0.3.0",
"shelljs": "^0.8.3",
"ts-node": "8.5.4",
"tslint": "5.20.1",
"tslint-clean-code": "^0.2.10",
"typescript": "3.7.4"
},
"dependencies": {
"any-promise": "^1.3.0",
"query-string-builder": "0.0.1",
"request": "^2.79.0"
"axios": "^0.19.0"
},
"nyc": {
"include": [
"src/**/*.ts",
"src/**/*.js"
],
"extension": [
".ts",
".js"
],
"require": [
"ts-node/register"
],
"reporter": [
"text-summary",
"html"
],
"sourceMap": true,
"instrument": true
}
}
Yet another node lib for requesting [Duck Duck Go](https://duckduckgo.com/).
This one has been written in typescript (2.x or above) and can be used by javascript (es6 or above) software or by typescript software.
This one has been written in typescript (2.x or above) and can be used by javascript (es2018 or above) software or by typescript software.
## Examples
* TypeScript:
```javascript
import { Requester } from '../../lib/';
// Result as default JSON
async function get() {
try {
const requester = new Requester('node-duckduckgo-example');
const response = await requester.requestP('bart simpsons');
console.log(response.toJSON());
const result = await duckIt('bart simpsons');
console.log(result.data.AbstractText);
} catch (err) {

@@ -21,93 +17,30 @@ console.error('oups', err);

```
* Javascript:
```javascript
const { Requester } = require('../../lib/');
async function get() {
try {
const requester = new Requester('node-duckduckgo-example');
const response = await requester.requestP('bart simpsons');
console.log(response.toJSON());
} catch (err) {
console.error('oups', err);
}
}
```
You can also use "old style" with callback:
* TypeScript:
```javascript
import { Requester } from "node-duckduckgo";
const requester = new Requester("node-duckduckgo-example");
requester.request("bart simpsons", (err, response, body) => {
if (err) {
console.log(err);
return;
}
console.log(body);
});
```
* Javascript:
```javascript
const { Requester } = require("node-duckduckgo");
const requester = new Requester("node-duckduckgo-example");
requester.request("bart simpsons", (err, response, body) => {
if (err) {
console.log(err);
return;
}
console.log(body);
});
```
## API
* The requester object takes an application name in parameter:
* duckIt uses [axios](https://github.com/axios/axios) and return an AxiosResponse:
```javascript
const requester = new Requester(<YOUR APP NAME>);
const result = await duckIt('bart simpsons');
```
* If needed, configure the requester options:
```javascript
requester.no_html = 1;
requester.no_redirect = 1;
requester.safe_search = safeSearch_off; // safeSearch_moderate or safeSearch_strict, default: safeSearch_strict;
```
* duckIt can be called with an options object, eahc item is optional:
* appName: an application name, default node-duckduckgo
* format: received format data, possible values: 'json' or 'xml', default 'json'
* parentalFilter: parental filter activated or not, possible values 'Activated', 'Moderate' and 'Deactivated', default: 'Activated'
* noRedirect: boolean, true to skip HTTP redirects
* noHtml: boolean, true to remove HTML from text
* skipDisambig: boolean, true to skip disambiguation
(for information about this options see [Duck Duck GO API documentation](https://api.duckduckgo.com/api)
* Execute your request and get your result
This lib is backed by [Request](https://www.npmjs.com/package/request). Results can be got by either by async call, callback or by stream:
```javascript
async function get() {
try {
const requester = new Requester('node-duckduckgo-example');
const response = await requester.requestP('bart simpsons');
console.log(response.toJSON());
} catch (err) {
console.error('oups', err);
}
}
example:
```javascript
const result = await duckIt('bart simpsons', { noHtml: true, parentalFilter: 'Moderate' });
```
```javascript
requester.request("bart simpsons", (err, response, body) => {
if (err) {
console.log(err);
return;
}
console.log(body);
});
```
```javascript
requester.request("bart simpsons")
.on("data", (data) => {
console.log(data.toString());
})
.on("error", (err) => {
console.log(err);
});
```
Response format is the [Duck Duck GO response](https://api.duckduckgo.com/api)
## Usage
node-duckduckgo is open sources (MIT license) but it doe grant you to use Duck Duck Go. [Please read this page](https://api.duckduckgo.com/api) before any usage.
## 2.x
This major release offers a completly different interface than 1.x. You may continue to use 1.X but
as it won't evolve anymore, your advise to migrate to 2.X.
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