node-duckduckgo
Advanced tools
Comparing version 1.2.3 to 1.3.0
@@ -1,2 +0,2 @@ | ||
import { optionType } from './optionHelper'; | ||
import { StdOptionValues } from './optionHelper'; | ||
export declare type allowedFormat = 'json' | 'xml'; | ||
@@ -11,3 +11,3 @@ export interface IFormatter { | ||
private prettify; | ||
pretty: optionType; | ||
pretty: StdOptionValues; | ||
buildQueryParam(builder: any): void; | ||
@@ -14,0 +14,0 @@ getFormat(): allowedFormat; |
import * as request from 'request'; | ||
import { RequestCallback, RequestResponse } from 'request'; | ||
import { allowedFormat, IFormatter, JsonFormatter } from './formatHelper'; | ||
import { optionType } from './optionHelper'; | ||
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 _baseUrl; | ||
private _formatter; | ||
private noRedirect; | ||
private noHtml; | ||
private skipDisambig; | ||
private _noRedirect; | ||
private _noHtml; | ||
private _skipDisambig; | ||
private _safeSearch; | ||
constructor(appName?: string); | ||
@@ -19,5 +23,6 @@ requestP(search: string): Promise<RequestResponse>; | ||
readonly formatter: IFormatter; | ||
no_redirect: optionType; | ||
no_html: optionType; | ||
skip_disambig: optionType; | ||
no_redirect: StdOptionValues; | ||
no_html: StdOptionValues; | ||
skip_disambig: StdOptionValues; | ||
safe_search: SafeSearchValues; | ||
} |
@@ -8,11 +8,16 @@ "use strict"; | ||
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/'; | ||
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._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); | ||
} | ||
@@ -37,8 +42,9 @@ requestP(search) { | ||
const queryString = builder.toString(); | ||
return request(`${this.baseUrl}?${queryString}`, callBack); | ||
return request(`${this._baseUrl}?${queryString}`, callBack); | ||
} | ||
buildQueryOptions(builder) { | ||
this.noRedirect.buildQueryParam(builder); | ||
this.noHtml.buildQueryParam(builder); | ||
this.skipDisambig.buildQueryParam(builder); | ||
this._noRedirect.buildQueryParam(builder); | ||
this._noHtml.buildQueryParam(builder); | ||
this._skipDisambig.buildQueryParam(builder); | ||
this._safeSearch.buildQueryParam(builder); | ||
} | ||
@@ -55,19 +61,25 @@ set format(format) { | ||
set no_redirect(value) { | ||
this.noRedirect.option = value; | ||
this._noRedirect.option = value; | ||
} | ||
get no_redirect() { | ||
return this.noRedirect.option; | ||
return this._noRedirect.option; | ||
} | ||
set no_html(value) { | ||
this.noHtml.option = value; | ||
this._noHtml.option = value; | ||
} | ||
get no_html() { | ||
return this.noHtml.option; | ||
return this._noHtml.option; | ||
} | ||
set skip_disambig(value) { | ||
this.skipDisambig.option = value; | ||
this._skipDisambig.option = value; | ||
} | ||
get skip_disambig() { | ||
return this.skipDisambig.option; | ||
return this._skipDisambig.option; | ||
} | ||
set safe_search(value) { | ||
this._safeSearch.option = value; | ||
} | ||
get safe_search() { | ||
return this._safeSearch.option; | ||
} | ||
} | ||
@@ -74,0 +86,0 @@ exports.Requester = Requester; |
@@ -1,8 +0,9 @@ | ||
export declare type optionType = 0 | 1 | undefined; | ||
export declare class OptionHelper { | ||
export declare class OptionHelper<OptionType> { | ||
private name; | ||
private value; | ||
constructor(name: string); | ||
option: optionType; | ||
private value?; | ||
constructor(name: string, value?: OptionType); | ||
option: OptionType; | ||
buildQueryParam(builder: any): void; | ||
} | ||
export declare type StdOptionValues = 0 | 1 | undefined; | ||
export declare type SafeSearchValues = 1 | -1 | -2; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
class OptionHelper { | ||
constructor(name) { | ||
constructor(name, value) { | ||
this.name = name; | ||
this.value = undefined; | ||
this.value = value; | ||
} | ||
@@ -8,0 +8,0 @@ set option(value) { |
{ | ||
"name": "node-duckduckgo", | ||
"version": "1.2.3", | ||
"version": "1.3.0", | ||
"description": "DuckDuckGo client for node", | ||
@@ -53,3 +53,3 @@ "main": "lib/index.js", | ||
"gulp-tslint": "^8.1.1", | ||
"gulp-typescript": "^5.0.0-alpha.3", | ||
"gulp-typescript": "^5.0.1", | ||
"gulp-use-tsconfig": "^1.1.3", | ||
@@ -59,3 +59,3 @@ "mocha": "^6.0.2", | ||
"ts-node": "^8.0.3", | ||
"tslint": "^5.11.0", | ||
"tslint": "^5.14.0", | ||
"tslint-clean-code": "^0.2.7", | ||
@@ -62,0 +62,0 @@ "typescript": "^3.3.3333", |
@@ -72,2 +72,3 @@ Yet another node lib for requesting [Duck Duck Go](https://duckduckgo.com/). | ||
requester.no_redirect = 1; | ||
requester.safe_search = safeSearch_off; // safeSearch_moderate or safeSearch_strict, default: safeSearch_strict; | ||
``` | ||
@@ -74,0 +75,0 @@ (for information about this options see [Duck Duck GO API documentation](https://api.duckduckgo.com/api) |
12010
238
113