duck-duck-scrape
Advanced tools
Comparing version 2.2.1 to 2.2.2
@@ -8,2 +8,5 @@ # Changelog | ||
## [Unreleased] | ||
## [2.2.2] - 2023-02-14 | ||
### Fixed: | ||
- Updated VQD fetching | ||
## [2.2.1] - 2022-02-02 | ||
@@ -51,3 +54,3 @@ ### Fixed: | ||
[Unreleased]: https://github.com/Snazzah/duck-duck-scrape/compare/v2.2.1...HEAD | ||
[Unreleased]: https://github.com/Snazzah/duck-duck-scrape/compare/v2.2.2...HEAD | ||
[1.0.3]: https://github.com/Snazzah/duck-duck-scrape/releases/tag/v1.0.3 | ||
@@ -63,2 +66,3 @@ [2.0.0]: https://github.com/Snazzah/duck-duck-scrape/compare/v1.0.3...v2.0.0 | ||
[2.2.0]: https://github.com/Snazzah/duck-duck-scrape/compare/v2.1.5...v2.2.0 | ||
[2.2.1]: https://github.com/Snazzah/duck-duck-scrape/compare/v2.2.0...v2.2.1 | ||
[2.2.1]: https://github.com/Snazzah/duck-duck-scrape/compare/v2.2.0...v2.2.1 | ||
[2.2.2]: https://github.com/Snazzah/duck-duck-scrape/compare/v2.2.0...v2.2.2 |
{ | ||
"name": "duck-duck-scrape", | ||
"version": "2.2.1", | ||
"version": "2.2.2", | ||
"description": "Search from DuckDuckGo and use it's spice APIs.", | ||
@@ -26,14 +26,2 @@ "main": "./lib/index.js", | ||
}, | ||
"scripts": { | ||
"build": "npx rimraf lib && npx tsc", | ||
"build:prepare": "npx shx test -d ./lib || npm run build", | ||
"changelog": "ts-node scripts/changelog", | ||
"lint": "npx eslint --ext .ts ./src", | ||
"lint:fix": "npx eslint --ext .ts ./src --fix", | ||
"test": "mocha -r ts-node/register --extension ts", | ||
"gpr": "ts-node scripts/gpr", | ||
"docs": "typedoc", | ||
"prepare": "npx husky install && npm run build:prepare", | ||
"prepublishOnly": "(npx shx test -d ./lib || (echo \"lib folder does not exist\" && exit 1)) && npm run lint:fix" | ||
}, | ||
"lint-staged": { | ||
@@ -43,21 +31,37 @@ "*.ts": "eslint --fix" | ||
"dependencies": { | ||
"html-entities": "^2.3.2", | ||
"needle": "^3.0.0" | ||
"html-entities": "^2.3.3", | ||
"needle": "^3.2.0" | ||
}, | ||
"devDependencies": { | ||
"@types/needle": "^2.5.1", | ||
"@types/node": "^17.0.1", | ||
"@typescript-eslint/eslint-plugin": "^5.3.0", | ||
"@typescript-eslint/parser": "^5.3.0", | ||
"eslint": "^8.1.0", | ||
"eslint-config-prettier": "^8.3.0", | ||
"eslint-plugin-prettier": "^4.0.0", | ||
"husky": "^7.0.0", | ||
"lint-staged": "^12.0.2", | ||
"prettier": "^2.4.1", | ||
"ts-node": "^10.0.0", | ||
"typedoc": "0.21", | ||
"typescript": "4.5", | ||
"yarn": "^1.22.10" | ||
"@types/chai": "^4.3.4", | ||
"@types/chai-as-promised": "^7.1.5", | ||
"@types/mocha": "^10.0.1", | ||
"@types/needle": "^3.2.0", | ||
"@types/node": "^18.11.17", | ||
"chai": "^4.3.7", | ||
"chai-as-promised": "^7.1.1", | ||
"eslint": "^8.30.0", | ||
"eslint-config-snazzah": "^1.2.1", | ||
"husky": "^8.0.2", | ||
"lint-staged": "^13.1.0", | ||
"mocha": "^10.2.0", | ||
"nock": "^13.2.9", | ||
"nyc": "^15.1.0", | ||
"prettier": "^2.8.1", | ||
"shx": "^0.3.4", | ||
"ts-node": "^10.9.1", | ||
"typedoc": "~0.23.23", | ||
"typescript": "~4.9.4", | ||
"yarn": "^1.22.19" | ||
}, | ||
"scripts": { | ||
"build": "tsc", | ||
"build:prepare": "shx test -d ./lib || npm run build", | ||
"changelog": "ts-node scripts/changelog", | ||
"lint": "eslint .", | ||
"lint:fix": "eslint . --fix", | ||
"test": "nyc mocha -r ts-node/register --extension ts 'test/**/*.ts'", | ||
"gpr": "ts-node scripts/gpr", | ||
"docs": "typedoc" | ||
} | ||
} | ||
} |
@@ -1,9 +0,5 @@ | ||
export { DuckbarImageResult } from './types'; | ||
export { SafeSearchType, SearchTimeType, getVQD } from './util'; | ||
export * from './search/images'; | ||
export * from './search/news'; | ||
export * from './search/search'; | ||
export * from './search/images'; | ||
export * from './search/videos'; | ||
export * from './search/news'; | ||
export * from './spices/currency'; | ||
@@ -20,3 +16,5 @@ export * from './spices/dictionary/audio'; | ||
export * from './spices/stocks'; | ||
export * from './spices/thesaurus'; | ||
export * from './spices/time'; | ||
export * from './spices/thesaurus'; | ||
export { DuckbarImageResult } from './types'; | ||
export { getVQD, SafeSearchType, SearchTimeType } from './util'; |
import { decode } from 'html-entities'; | ||
import needle, { NeedleOptions } from 'needle'; | ||
import { DuckbarResponse, DuckbarImageResult } from '../types'; | ||
import { ensureJSON, getVQD, queryString } from '../util'; | ||
import { SafeSearchType } from '../util'; | ||
import { DuckbarImageResult, DuckbarResponse } from '../types'; | ||
import { ensureJSON, getVQD, queryString, SafeSearchType } from '../util'; | ||
/** The types of image sizes. */ | ||
@@ -148,7 +148,3 @@ export enum ImageSize { | ||
*/ | ||
export async function searchImages( | ||
query: string, | ||
options?: ImageSearchOptions, | ||
needleOptions?: NeedleOptions | ||
): Promise<ImageSearchResults> { | ||
export async function searchImages(query: string, options?: ImageSearchOptions, needleOptions?: NeedleOptions): Promise<ImageSearchResults> { | ||
if (!query) throw new Error('Query cannot be empty!'); | ||
@@ -161,2 +157,3 @@ if (!options) options = defaultOptions; | ||
/* istanbul ignore next */ | ||
const filters = [ | ||
@@ -180,7 +177,3 @@ options.size ? `size:${options.size}` : '', | ||
const response = await needle( | ||
'get', | ||
`https://duckduckgo.com/i.js?${queryString(queryObject)}`, | ||
needleOptions | ||
); | ||
const response = await needle('get', `https://duckduckgo.com/i.js?${queryString(queryObject)}`, needleOptions); | ||
@@ -204,8 +197,6 @@ if (response.statusCode === 403) throw new Error('A server error occurred!'); | ||
if (!(options.safeSearch! in SafeSearchType)) | ||
throw new TypeError(`${options.safeSearch} is an invalid safe search type!`); | ||
if (!(options.safeSearch! in SafeSearchType)) throw new TypeError(`${options.safeSearch} is an invalid safe search type!`); | ||
if (typeof options.safeSearch! === 'string') | ||
// @ts-ignore | ||
options.safeSearch = SafeSearchType[options.safeSearch!]; | ||
/* istanbul ignore next */ | ||
if (typeof options.safeSearch! === 'string') options.safeSearch = SafeSearchType[options.safeSearch!] as any as SafeSearchType; | ||
@@ -216,10 +207,7 @@ if (typeof options.offset !== 'number') throw new TypeError(`Search offset is not a number!`); | ||
if (!options.locale || typeof options.locale! !== 'string') | ||
throw new TypeError('Search locale must be a string!'); | ||
if (!options.locale || typeof options.locale! !== 'string') throw new TypeError('Search locale must be a string!'); | ||
if (options.size && !Object.values(ImageSize).includes(options.size)) | ||
throw new TypeError(`${options.size} is an invalid image size filter!`); | ||
if (options.size && !Object.values(ImageSize).includes(options.size)) throw new TypeError(`${options.size} is an invalid image size filter!`); | ||
if (options.type && !Object.values(ImageType).includes(options.type)) | ||
throw new TypeError(`${options.type} is an invalid image type filter!`); | ||
if (options.type && !Object.values(ImageType).includes(options.type)) throw new TypeError(`${options.type} is an invalid image type filter!`); | ||
@@ -229,4 +217,3 @@ if (options.layout && !Object.values(ImageLayout).includes(options.layout)) | ||
if (options.color && !Object.values(ImageColor).includes(options.color)) | ||
throw new TypeError(`${options.color} is an invalid color filter!`); | ||
if (options.color && !Object.values(ImageColor).includes(options.color)) throw new TypeError(`${options.color} is an invalid color filter!`); | ||
@@ -233,0 +220,0 @@ if (options.license && !Object.values(ImageLicense).includes(options.license)) |
import { decode } from 'html-entities'; | ||
import needle, { NeedleOptions } from 'needle'; | ||
import { DuckbarNewsResult, DuckbarResponse } from '../types'; | ||
import { ensureJSON, getVQD, queryString, SearchTimeType } from '../util'; | ||
import { SafeSearchType } from '../util'; | ||
import { ensureJSON, getVQD, queryString, SafeSearchType, SearchTimeType } from '../util'; | ||
@@ -68,7 +68,3 @@ /** The options for {@link searchNews}. */ | ||
*/ | ||
export async function searchNews( | ||
query: string, | ||
options?: NewsSearchOptions, | ||
needleOptions?: NeedleOptions | ||
): Promise<NewsSearchResults> { | ||
export async function searchNews(query: string, options?: NewsSearchOptions, needleOptions?: NeedleOptions): Promise<NewsSearchResults> { | ||
if (!query) throw new Error('Query cannot be empty!'); | ||
@@ -92,7 +88,3 @@ if (!options) options = defaultOptions; | ||
const response = await needle( | ||
'get', | ||
`https://duckduckgo.com/news.js?${queryString(queryObject)}`, | ||
needleOptions | ||
); | ||
const response = await needle('get', `https://duckduckgo.com/news.js?${queryString(queryObject)}`, needleOptions); | ||
@@ -122,4 +114,3 @@ if (response.statusCode === 403) throw new Error('A server error occurred!'); | ||
if (!(options.safeSearch! in SafeSearchType)) | ||
throw new TypeError(`${options.safeSearch} is an invalid safe search type!`); | ||
if (!(options.safeSearch! in SafeSearchType)) throw new TypeError(`${options.safeSearch} is an invalid safe search type!`); | ||
@@ -134,7 +125,5 @@ if (typeof options.safeSearch! === 'string') | ||
if (!options.locale || typeof options.locale! !== 'string') | ||
throw new TypeError('Search locale must be a string!'); | ||
if (!options.locale || typeof options.locale! !== 'string') throw new TypeError('Search locale must be a string!'); | ||
if (options.time && !Object.values(SearchTimeType).includes(options.time)) | ||
throw new TypeError(`${options.time} is an invalid time filter!`); | ||
if (options.time && !Object.values(SearchTimeType).includes(options.time)) throw new TypeError(`${options.time} is an invalid time filter!`); | ||
@@ -141,0 +130,0 @@ if (options.vqd && !/\d-\d+-\d+/.test(options.vqd)) throw new Error(`${options.vqd} is an invalid VQD!`); |
@@ -0,15 +1,16 @@ | ||
import { decode } from 'html-entities'; | ||
import needle, { NeedleOptions } from 'needle'; | ||
import { decode } from 'html-entities'; | ||
import { | ||
CallbackDuckbarPayload, | ||
DuckbarImageResult, | ||
CallbackNextSearch, | ||
CallbackSearchResult, | ||
DuckbarVideoResult, | ||
DuckbarImageResult, | ||
DuckbarNewsResult, | ||
DuckbarRelatedSearch, | ||
DuckbarNewsResult | ||
DuckbarVideoResult | ||
} from '../types'; | ||
import { SafeSearchType, SearchTimeType, getVQD, queryString, ensureJSON } from '../util'; | ||
import { ensureJSON, getVQD, queryString, SafeSearchType, SearchTimeType } from '../util'; | ||
import { NewsResult } from './news'; | ||
import { VideoResult } from './videos'; | ||
import { NewsResult } from './news'; | ||
@@ -47,10 +48,6 @@ /** The options for {@link search}. */ | ||
const SEARCH_REGEX = /DDG\.pageLayout\.load\('d',(\[.+\])\);DDG\.duckbar\.load\('images'/; | ||
const IMAGES_REGEX = | ||
/;DDG\.duckbar\.load\('images', ({"ads":.+"vqd":{".+":"\d-\d+-\d+"}})\);DDG\.duckbar\.load\('news/; | ||
const NEWS_REGEX = | ||
/;DDG\.duckbar\.load\('news', ({"ads":.+"vqd":{".+":"\d-\d+-\d+"}})\);DDG\.duckbar\.load\('videos/; | ||
const VIDEOS_REGEX = | ||
/;DDG\.duckbar\.load\('videos', ({"ads":.+"vqd":{".+":"\d-\d+-\d+"}})\);DDG\.duckbar\.loadModule\('related_searches/; | ||
const RELATED_SEARCHES_REGEX = | ||
/DDG\.duckbar\.loadModule\('related_searches', ({"ads":.+"vqd":{".+":"\d-\d+-\d+"}})\);DDG\.duckbar\.load\('products/; | ||
const IMAGES_REGEX = /;DDG\.duckbar\.load\('images', ({"ads":.+"vqd":{".+":"\d-\d+-\d+"}})\);DDG\.duckbar\.load\('news/; | ||
const NEWS_REGEX = /;DDG\.duckbar\.load\('news', ({"ads":.+"vqd":{".+":"\d-\d+-\d+"}})\);DDG\.duckbar\.load\('videos/; | ||
const VIDEOS_REGEX = /;DDG\.duckbar\.load\('videos', ({"ads":.+"vqd":{".+":"\d-\d+-\d+"}})\);DDG\.duckbar\.loadModule\('related_searches/; | ||
const RELATED_SEARCHES_REGEX = /DDG\.duckbar\.loadModule\('related_searches', ({"ads":.+"vqd":{".+":"\d-\d+-\d+"}})\);DDG\.duckbar\.load\('products/; | ||
@@ -122,7 +119,3 @@ /** | ||
*/ | ||
export async function search( | ||
query: string, | ||
options?: SearchOptions, | ||
needleOptions?: NeedleOptions | ||
): Promise<SearchResults> { | ||
export async function search(query: string, options?: SearchOptions, needleOptions?: NeedleOptions): Promise<SearchResults> { | ||
if (!query) throw new Error('Query cannot be empty!'); | ||
@@ -135,2 +128,3 @@ if (!options) options = defaultOptions; | ||
/* istanbul ignore next */ | ||
const queryObject: Record<string, string> = { | ||
@@ -171,14 +165,7 @@ q: query, | ||
const response = await needle( | ||
'get', | ||
`https://links.duckduckgo.com/d.js?${queryString(queryObject)}`, | ||
needleOptions | ||
); | ||
const response = await needle('get', `https://links.duckduckgo.com/d.js?${queryString(queryObject)}`, needleOptions); | ||
if ((response.body as string).includes('DDG.deep.is506')) throw new Error('A server error occurred!'); | ||
const searchResults = JSON.parse(SEARCH_REGEX.exec(response.body)![1].replace(/\t/g, ' ')) as ( | ||
| CallbackSearchResult | ||
| CallbackNextSearch | ||
)[]; | ||
const searchResults = JSON.parse(SEARCH_REGEX.exec(response.body)![1].replace(/\t/g, ' ')) as (CallbackSearchResult | CallbackNextSearch)[]; | ||
@@ -188,2 +175,3 @@ // check for no results | ||
const onlyResult = searchResults[0] as CallbackSearchResult; | ||
/* istanbul ignore next */ | ||
if ((!onlyResult.da && onlyResult.t === 'EOF') || !onlyResult.a || onlyResult.d === 'google.com search') | ||
@@ -225,5 +213,3 @@ return { | ||
if (imagesMatch) { | ||
const imagesResult = JSON.parse( | ||
imagesMatch[1].replace(/\t/g, ' ') | ||
) as CallbackDuckbarPayload<DuckbarImageResult>; | ||
const imagesResult = JSON.parse(imagesMatch[1].replace(/\t/g, ' ')) as CallbackDuckbarPayload<DuckbarImageResult>; | ||
results.images = imagesResult.results.map((i) => { | ||
@@ -238,5 +224,3 @@ i.title = decode(i.title); | ||
if (newsMatch) { | ||
const newsResult = JSON.parse( | ||
newsMatch[1].replace(/\t/g, ' ') | ||
) as CallbackDuckbarPayload<DuckbarNewsResult>; | ||
const newsResult = JSON.parse(newsMatch[1].replace(/\t/g, ' ')) as CallbackDuckbarPayload<DuckbarNewsResult>; | ||
results.news = newsResult.results.map((article) => ({ | ||
@@ -257,6 +241,5 @@ date: article.date, | ||
if (videosMatch) { | ||
const videoResult = JSON.parse( | ||
videosMatch[1].replace(/\t/g, ' ') | ||
) as CallbackDuckbarPayload<DuckbarVideoResult>; | ||
const videoResult = JSON.parse(videosMatch[1].replace(/\t/g, ' ')) as CallbackDuckbarPayload<DuckbarVideoResult>; | ||
results.videos = []; | ||
/* istanbul ignore next */ | ||
for (const video of videoResult.results) { | ||
@@ -280,5 +263,3 @@ results.videos.push({ | ||
if (relatedMatch) { | ||
const relatedResult = JSON.parse( | ||
relatedMatch[1].replace(/\t/g, ' ') | ||
) as CallbackDuckbarPayload<DuckbarRelatedSearch>; | ||
const relatedResult = JSON.parse(relatedMatch[1].replace(/\t/g, ' ')) as CallbackDuckbarPayload<DuckbarRelatedSearch>; | ||
results.related = []; | ||
@@ -301,8 +282,6 @@ for (const related of relatedResult.results) { | ||
if (!(options.safeSearch! in SafeSearchType)) | ||
throw new TypeError(`${options.safeSearch} is an invalid safe search type!`); | ||
if (!(options.safeSearch! in SafeSearchType)) throw new TypeError(`${options.safeSearch} is an invalid safe search type!`); | ||
if (typeof options.safeSearch! === 'string') | ||
// @ts-ignore | ||
options.safeSearch = SafeSearchType[options.safeSearch!]; | ||
/* istanbul ignore next */ | ||
if (typeof options.safeSearch! === 'string') options.safeSearch = SafeSearchType[options.safeSearch!] as any as SafeSearchType; | ||
@@ -314,3 +293,3 @@ if (typeof options.offset !== 'number') throw new TypeError(`Search offset is not a number!`); | ||
if ( | ||
!options.time && | ||
options.time && | ||
!Object.values(SearchTimeType).includes(options.time as SearchTimeType) && | ||
@@ -321,10 +300,7 @@ !/\d{4}-\d{2}-\d{2}..\d{4}-\d{2}-\d{2}/.test(options.time as string) | ||
if (!options.locale || typeof options.locale! !== 'string') | ||
throw new TypeError('Search locale must be a string!'); | ||
if (!options.locale || typeof options.locale! !== 'string') throw new TypeError('Search locale must be a string!'); | ||
if (!options.region || typeof options.region! !== 'string') | ||
throw new TypeError('Search region must be a string!'); | ||
if (!options.region || typeof options.region! !== 'string') throw new TypeError('Search region must be a string!'); | ||
if (!options.marketRegion || typeof options.marketRegion! !== 'string') | ||
throw new TypeError('Search market region must be a string!'); | ||
if (!options.marketRegion || typeof options.marketRegion! !== 'string') throw new TypeError('Search market region must be a string!'); | ||
@@ -363,7 +339,3 @@ if (options.vqd && !/\d-\d+-\d+/.test(options.vqd)) throw new Error(`${options.vqd} is an invalid VQD!`); | ||
*/ | ||
export async function autocomplete( | ||
query: string, | ||
region?: string, | ||
needleOptions?: NeedleOptions | ||
): Promise<AutocompleteResult[]> { | ||
export async function autocomplete(query: string, region?: string, needleOptions?: NeedleOptions): Promise<AutocompleteResult[]> { | ||
if (!query) throw new Error('Query cannot be empty!'); | ||
@@ -376,9 +348,5 @@ | ||
const response = await needle( | ||
'get', | ||
`https://duckduckgo.com/ac/?${queryString(queryObject)}`, | ||
needleOptions | ||
); | ||
const response = await needle('get', `https://duckduckgo.com/ac/?${queryString(queryObject)}`, needleOptions); | ||
return ensureJSON(response.body); | ||
} |
import { decode } from 'html-entities'; | ||
import needle, { NeedleOptions } from 'needle'; | ||
import { DuckbarResponse, DuckbarVideoResult } from '../types'; | ||
import { ensureJSON, getVQD, queryString, SearchTimeType } from '../util'; | ||
import { SafeSearchType } from '../util'; | ||
import { ensureJSON, getVQD, queryString, SafeSearchType, SearchTimeType } from '../util'; | ||
@@ -105,7 +105,3 @@ /** The types of video definition. */ | ||
*/ | ||
export async function searchVideos( | ||
query: string, | ||
options?: VideoSearchOptions, | ||
needleOptions?: NeedleOptions | ||
): Promise<VideoSearchResults> { | ||
export async function searchVideos(query: string, options?: VideoSearchOptions, needleOptions?: NeedleOptions): Promise<VideoSearchResults> { | ||
if (!query) throw new Error('Query cannot be empty!'); | ||
@@ -135,7 +131,3 @@ if (!options) options = defaultOptions; | ||
const response = await needle( | ||
'get', | ||
`https://duckduckgo.com/v.js?${queryString(queryObject)}`, | ||
needleOptions | ||
); | ||
const response = await needle('get', `https://duckduckgo.com/v.js?${queryString(queryObject)}`, needleOptions); | ||
@@ -166,4 +158,3 @@ if (response.statusCode === 403) throw new Error('A server error occurred!'); | ||
if (!(options.safeSearch! in SafeSearchType)) | ||
throw new TypeError(`${options.safeSearch} is an invalid safe search type!`); | ||
if (!(options.safeSearch! in SafeSearchType)) throw new TypeError(`${options.safeSearch} is an invalid safe search type!`); | ||
@@ -178,7 +169,5 @@ if (typeof options.safeSearch! === 'string') | ||
if (!options.locale || typeof options.locale! !== 'string') | ||
throw new TypeError('Search locale must be a string!'); | ||
if (!options.locale || typeof options.locale! !== 'string') throw new TypeError('Search locale must be a string!'); | ||
if (options.time && !Object.values(SearchTimeType).includes(options.time)) | ||
throw new TypeError(`${options.time} is an invalid time filter!`); | ||
if (options.time && !Object.values(SearchTimeType).includes(options.time)) throw new TypeError(`${options.time} is an invalid time filter!`); | ||
@@ -185,0 +174,0 @@ if (options.definition && !Object.values(VideoDefinition).includes(options.definition)) |
import needle, { NeedleOptions } from 'needle'; | ||
import { parseSpiceBody, SPICE_BASE } from '../util'; | ||
@@ -61,8 +62,3 @@ | ||
*/ | ||
export async function currency( | ||
from: string, | ||
to: string, | ||
amount = 1, | ||
needleOptions?: NeedleOptions | ||
): Promise<CurrencyResult> { | ||
export async function currency(from: string, to: string, amount = 1, needleOptions?: NeedleOptions): Promise<CurrencyResult> { | ||
if (!from) throw new Error('Currency `from` cannot be empty!'); | ||
@@ -69,0 +65,0 @@ if (!to) throw new Error('Currency `to` cannot be empty!'); |
import needle, { NeedleOptions } from 'needle'; | ||
import { SPICE_BASE } from '../../util'; | ||
@@ -35,6 +36,3 @@ | ||
*/ | ||
export async function dictionaryAudio( | ||
word: string, | ||
needleOptions?: NeedleOptions | ||
): Promise<DictionaryAudioResult[]> { | ||
export async function dictionaryAudio(word: string, needleOptions?: NeedleOptions): Promise<DictionaryAudioResult[]> { | ||
if (!word) throw new Error('Word cannot be empty!'); | ||
@@ -41,0 +39,0 @@ |
import needle, { NeedleOptions } from 'needle'; | ||
import { parseSpiceBody, SPICE_BASE } from '../../util'; | ||
@@ -84,6 +85,3 @@ | ||
*/ | ||
export async function dictionaryDefinition( | ||
word: string, | ||
needleOptions?: NeedleOptions | ||
): Promise<DictionaryDefinitionResult[]> { | ||
export async function dictionaryDefinition(word: string, needleOptions?: NeedleOptions): Promise<DictionaryDefinitionResult[]> { | ||
if (!word) throw new Error('Word cannot be empty!'); | ||
@@ -90,0 +88,0 @@ |
import needle, { NeedleOptions } from 'needle'; | ||
import { SPICE_BASE } from '../../util'; | ||
@@ -25,6 +26,3 @@ | ||
*/ | ||
export async function dictionaryHyphenation( | ||
word: string, | ||
needleOptions?: NeedleOptions | ||
): Promise<DictionaryHyphenationResult[]> { | ||
export async function dictionaryHyphenation(word: string, needleOptions?: NeedleOptions): Promise<DictionaryHyphenationResult[]> { | ||
if (!word) throw new Error('Word cannot be empty!'); | ||
@@ -31,0 +29,0 @@ |
import needle, { NeedleOptions } from 'needle'; | ||
import { SPICE_BASE } from '../../util'; | ||
@@ -28,6 +29,3 @@ | ||
*/ | ||
export async function dictionaryPronunciation( | ||
word: string, | ||
needleOptions?: NeedleOptions | ||
): Promise<DictionaryPronunciationResult[]> { | ||
export async function dictionaryPronunciation(word: string, needleOptions?: NeedleOptions): Promise<DictionaryPronunciationResult[]> { | ||
if (!word) throw new Error('Word cannot be empty!'); | ||
@@ -34,0 +32,0 @@ |
import needle, { NeedleOptions } from 'needle'; | ||
import { parseSpiceBody, SPICE_BASE } from '../util'; | ||
@@ -78,7 +79,3 @@ | ||
*/ | ||
export async function dns( | ||
domain: string, | ||
recordType = DNSRecordType.ANY, | ||
needleOptions?: NeedleOptions | ||
): Promise<DNSResult> { | ||
export async function dns(domain: string, recordType = DNSRecordType.ANY, needleOptions?: NeedleOptions): Promise<DNSResult> { | ||
if (!domain) throw new Error('Domain cannot be empty!'); | ||
@@ -85,0 +82,0 @@ |
import needle, { NeedleOptions } from 'needle'; | ||
import { parseSpiceBody, SPICE_BASE } from '../util'; | ||
@@ -3,0 +4,0 @@ |
import needle, { NeedleOptions } from 'needle'; | ||
import { parseSpiceBody, SPICE_BASE } from '../util'; | ||
@@ -3,0 +4,0 @@ |
import needle, { NeedleOptions } from 'needle'; | ||
import { parseSpiceBody, SPICE_BASE } from '../util'; | ||
@@ -142,15 +143,7 @@ | ||
*/ | ||
export async function forecast( | ||
query: string, | ||
locale = 'en', | ||
needleOptions?: NeedleOptions | ||
): Promise<ForecastResult | null> { | ||
export async function forecast(query: string, locale = 'en', needleOptions?: NeedleOptions): Promise<ForecastResult | null> { | ||
if (!query) throw new Error('Query cannot be empty!'); | ||
if (!locale) throw new Error('Locale cannot be empty!'); | ||
const response = await needle( | ||
'get', | ||
`${SPICE_BASE}/forecast/${encodeURIComponent(query)}/${locale}`, | ||
needleOptions | ||
); | ||
const response = await needle('get', `${SPICE_BASE}/forecast/${encodeURIComponent(query)}/${locale}`, needleOptions); | ||
@@ -157,0 +150,0 @@ if (response.body.toString() === 'ddg_spice_forecast();\n') return null; |
import needle, { NeedleOptions } from 'needle'; | ||
import { parseSpiceBody, SPICE_BASE } from '../util'; | ||
@@ -3,0 +4,0 @@ |
import needle, { NeedleOptions } from 'needle'; | ||
import { parseSpiceBody, SPICE_BASE } from '../util'; | ||
@@ -3,0 +4,0 @@ |
import needle, { NeedleOptions } from 'needle'; | ||
import { parseSpiceBody, SPICE_BASE } from '../util'; | ||
@@ -29,6 +30,3 @@ | ||
*/ | ||
export async function thesaurus( | ||
word: string, | ||
needleOptions?: NeedleOptions | ||
): Promise<ThesaurusResult | null> { | ||
export async function thesaurus(word: string, needleOptions?: NeedleOptions): Promise<ThesaurusResult | null> { | ||
if (!word) throw new Error('Word cannot be empty!'); | ||
@@ -35,0 +33,0 @@ |
import needle, { NeedleOptions } from 'needle'; | ||
import { parseSpiceBody, SPICE_BASE } from '../util'; | ||
@@ -3,0 +4,0 @@ |
@@ -6,3 +6,3 @@ import needle, { NeedleOptions } from 'needle'; | ||
/** @internal */ | ||
export const VQD_REGEX = /vqd='(\d+-\d+-\d+)'/; | ||
export const VQD_REGEX = /vqd='(\d+-\d+(?:-\d+)?)'/; | ||
@@ -9,0 +9,0 @@ /** The safe search values when searching DuckDuckGo. */ |
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
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
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
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
182795
80
4686
20
3
1
Updatedhtml-entities@^2.3.3
Updatedneedle@^3.2.0