search-web-api 1.0.76 → 1.0.78
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +0 -3
- package/bun.lock +644 -0
- package/package.json +5 -2
- package/src/search/__tests__/public-searxng.test.ts +37 -17
- package/src/sources/academic/arxiv.ts +3 -0
- package/src/sources/academic/core.ts +3 -0
- package/src/sources/academic/crossref.ts +3 -0
- package/src/sources/academic/doaj.ts +3 -0
- package/src/sources/academic/google_scholar.ts +3 -0
- package/src/sources/academic/openalex.ts +3 -0
- package/src/sources/academic/pubmed.ts +3 -0
- package/src/sources/academic/semantic_scholar.ts +3 -0
- package/src/sources/academic/wikidata.ts +3 -0
- package/src/sources/general/baidu.ts +3 -0
- package/src/sources/general/bing.ts +3 -0
- package/src/sources/general/brave.ts +3 -0
- package/src/sources/general/duckduckgo.ts +3 -0
- package/src/sources/general/google.ts +3 -0
- package/src/sources/general/mojeek.ts +3 -0
- package/src/sources/general/qwant.ts +3 -0
- package/src/sources/general/startpage.ts +3 -0
- package/src/sources/general/yahoo.ts +3 -0
- package/src/sources/general/yandex.ts +3 -0
- package/src/sources/images/bing_images.ts +3 -0
- package/src/sources/images/deviantart.ts +3 -0
- package/src/sources/images/flickr.ts +3 -0
- package/src/sources/images/google_images.ts +3 -0
- package/src/sources/images/imgur.ts +3 -0
- package/src/sources/images/openclipart.ts +3 -0
- package/src/sources/images/pixabay.ts +3 -0
- package/src/sources/images/unsplash.ts +3 -0
- package/src/sources/images/wallhaven.ts +3 -0
- package/src/sources/it/crates.ts +3 -0
- package/src/sources/it/dockerhub.ts +3 -0
- package/src/sources/it/github.ts +3 -0
- package/src/sources/it/gitlab.ts +3 -0
- package/src/sources/it/npm.ts +3 -0
- package/src/sources/it/packagist.ts +3 -0
- package/src/sources/it/pypi.ts +3 -0
- package/src/sources/it/rubygems.ts +3 -0
- package/src/sources/it/stackoverflow.ts +3 -0
- package/src/sources/maps/apple_maps.ts +3 -0
- package/src/sources/maps/openstreetmap.ts +3 -0
- package/src/sources/maps/photon.ts +3 -0
- package/src/sources/news/bing_news.ts +3 -0
- package/src/sources/news/google_news.ts +3 -0
- package/src/sources/news/hackernews.ts +3 -0
- package/src/sources/news/yahoo_news.ts +3 -0
- package/src/sources/shopping/ebay.ts +3 -0
- package/src/sources/social/mastodon.ts +3 -0
- package/src/sources/social/medium.ts +3 -0
- package/src/sources/social/reddit.ts +3 -0
- package/src/sources/social/soundcloud.ts +3 -0
- package/src/sources/social/twitter.ts +3 -0
- package/src/sources/specialized/annas_archive.ts +3 -0
- package/src/sources/specialized/archive.ts +3 -0
- package/src/sources/specialized/genius.ts +3 -0
- package/src/sources/specialized/goodreads.ts +3 -0
- package/src/sources/specialized/imdb.ts +3 -0
- package/src/sources/specialized/openlibrary.ts +3 -0
- package/src/sources/specialized/wikipedia.ts +3 -0
- package/src/sources/specialized/wttr.ts +3 -0
- package/src/sources/torrents/1337x.ts +3 -0
- package/src/sources/torrents/eztv.ts +3 -0
- package/src/sources/torrents/kickass.ts +3 -0
- package/src/sources/torrents/nyaa.ts +3 -0
- package/src/sources/torrents/solidtorrents.ts +3 -0
- package/src/sources/torrents/thepiratebay.ts +3 -0
- package/src/sources/torrents/yts.ts +3 -0
- package/src/sources/videos/bing_videos.ts +3 -0
- package/src/sources/videos/dailymotion.ts +3 -0
- package/src/sources/videos/invidious.ts +3 -0
- package/src/sources/videos/peertube.ts +3 -0
- package/src/sources/videos/vimeo.ts +3 -0
- package/src/sources/videos/youtube.ts +3 -0
- package/src/suggest-next-words/autocomplete-ai.ts +41 -38
- package/src/types/search-engine-interface.ts +2 -2
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "search-web-api",
|
|
3
3
|
"description": "70+ search engines across 10 categories and Scrape Extract API",
|
|
4
4
|
"type": "module",
|
|
5
|
-
"version": "1.0.
|
|
5
|
+
"version": "1.0.78",
|
|
6
6
|
"author": "vtempest",
|
|
7
7
|
"license": "rights.institute/PROSPER",
|
|
8
8
|
"repository": {
|
|
@@ -12,10 +12,12 @@
|
|
|
12
12
|
},
|
|
13
13
|
"exports": {
|
|
14
14
|
".": {
|
|
15
|
+
"types": "./src/search.ts",
|
|
15
16
|
"import": "./src/search.ts",
|
|
16
17
|
"require": "./src/search.ts"
|
|
17
18
|
},
|
|
18
19
|
"./*": {
|
|
20
|
+
"types": "./src/*.ts",
|
|
19
21
|
"import": "./src/*",
|
|
20
22
|
"require": "./src/*"
|
|
21
23
|
}
|
|
@@ -23,7 +25,8 @@
|
|
|
23
25
|
"scripts": {
|
|
24
26
|
"dev": "bun --watch demo/index.ts",
|
|
25
27
|
"start": "bun demo/index.ts",
|
|
26
|
-
"test": "vitest run"
|
|
28
|
+
"test": "vitest run",
|
|
29
|
+
"test:coverage": "vitest run --coverage"
|
|
27
30
|
},
|
|
28
31
|
"dependencies": {
|
|
29
32
|
"@huggingface/transformers": "^3.8.1",
|
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @fileoverview Unit tests for SearXNG search functionality
|
|
3
3
|
*/
|
|
4
|
+
import { beforeEach, describe, expect, it, vi, type MockedFunction } from "vitest";
|
|
4
5
|
import { searchWeb, searchSearxng } from "../public-searxng";
|
|
5
6
|
import grab from "grab-url";
|
|
6
7
|
|
|
7
8
|
// Mock grab-url
|
|
8
|
-
|
|
9
|
-
const mockGrab = grab as
|
|
9
|
+
vi.mock("grab-url");
|
|
10
|
+
const mockGrab = grab as MockedFunction<typeof grab>;
|
|
10
11
|
|
|
11
12
|
describe("searchWeb", () => {
|
|
12
13
|
beforeEach(() => {
|
|
13
|
-
|
|
14
|
+
vi.clearAllMocks();
|
|
14
15
|
});
|
|
15
16
|
|
|
16
17
|
describe("Private SearXNG instance (JSON)", () => {
|
|
@@ -223,7 +224,7 @@ describe("searchWeb", () => {
|
|
|
223
224
|
infoboxes: [],
|
|
224
225
|
};
|
|
225
226
|
|
|
226
|
-
const consoleSpy =
|
|
227
|
+
const consoleSpy = vi.spyOn(console, "warn").mockImplementation(() => {});
|
|
227
228
|
mockGrab.mockResolvedValueOnce(mockResults);
|
|
228
229
|
|
|
229
230
|
const result = await searchWeb("test", {
|
|
@@ -316,15 +317,13 @@ describe("searchWeb", () => {
|
|
|
316
317
|
</article>
|
|
317
318
|
`;
|
|
318
319
|
|
|
319
|
-
const consoleSpy =
|
|
320
|
+
const consoleSpy = vi.spyOn(console, "warn").mockImplementation(() => {});
|
|
320
321
|
mockGrab.mockResolvedValueOnce(mockHtml);
|
|
321
322
|
|
|
322
323
|
await searchWeb("test", { privateSearxng: false });
|
|
323
324
|
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
expect.any(String)
|
|
327
|
-
);
|
|
325
|
+
// The public-scrape path logs a single formatted message.
|
|
326
|
+
expect(consoleSpy).toHaveBeenCalledWith(expect.stringContaining("domain-only"));
|
|
328
327
|
consoleSpy.mockRestore();
|
|
329
328
|
});
|
|
330
329
|
});
|
|
@@ -491,15 +490,16 @@ describe("searchWeb", () => {
|
|
|
491
490
|
|
|
492
491
|
describe("searchSearxng", () => {
|
|
493
492
|
beforeEach(() => {
|
|
494
|
-
|
|
493
|
+
vi.clearAllMocks();
|
|
495
494
|
});
|
|
496
495
|
|
|
497
|
-
it("should adapt options
|
|
498
|
-
mockGrab.mockResolvedValueOnce(
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
496
|
+
it("should adapt its options onto the underlying search request", async () => {
|
|
497
|
+
mockGrab.mockResolvedValueOnce(`
|
|
498
|
+
<article class="result">
|
|
499
|
+
<h3><a href="https://example.com/article">Test</a></h3>
|
|
500
|
+
<p class="content">Content</p>
|
|
501
|
+
</article>
|
|
502
|
+
`);
|
|
503
503
|
|
|
504
504
|
const result = await searchSearxng("test query", {
|
|
505
505
|
categories: ["news"],
|
|
@@ -507,10 +507,30 @@ describe("searchSearxng", () => {
|
|
|
507
507
|
language: "fr",
|
|
508
508
|
});
|
|
509
509
|
|
|
510
|
+
// searchSearxng maps categories[0] -> category, pageno -> page, language -> lang.
|
|
511
|
+
expect(mockGrab).toHaveBeenCalledWith(
|
|
512
|
+
expect.any(String),
|
|
513
|
+
expect.objectContaining({ category_news: 1, pageno: 2, language: "fr" })
|
|
514
|
+
);
|
|
510
515
|
expect(result).toHaveProperty("results");
|
|
511
516
|
expect(result).toHaveProperty("suggestions");
|
|
512
517
|
expect(result.results).toHaveLength(1);
|
|
513
|
-
|
|
518
|
+
});
|
|
519
|
+
|
|
520
|
+
it("defaults category, page and language when no options are given", async () => {
|
|
521
|
+
mockGrab.mockResolvedValueOnce(`
|
|
522
|
+
<article class="result">
|
|
523
|
+
<h3><a href="https://example.com/article">Test</a></h3>
|
|
524
|
+
<p class="content">Content</p>
|
|
525
|
+
</article>
|
|
526
|
+
`);
|
|
527
|
+
|
|
528
|
+
await searchSearxng("test query");
|
|
529
|
+
|
|
530
|
+
expect(mockGrab).toHaveBeenCalledWith(
|
|
531
|
+
expect.any(String),
|
|
532
|
+
expect.objectContaining({ category_general: 1, pageno: 1, language: "en-US" })
|
|
533
|
+
);
|
|
514
534
|
});
|
|
515
535
|
|
|
516
536
|
it("should handle array results from searchWeb", async () => {
|
package/src/sources/it/crates.ts
CHANGED
package/src/sources/it/github.ts
CHANGED
package/src/sources/it/gitlab.ts
CHANGED
package/src/sources/it/npm.ts
CHANGED
package/src/sources/it/pypi.ts
CHANGED