npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

searxng

v0.0.5

Published

A TypeScript service to interact with the SearXNG search engine API, enabling customizable searches and result retrieval.

Downloads

722

Readme

SearXNG Service

A TypeScript service to interact with the SearXNG search engine API. This service allows you to perform searches and retrieve results in various formats with customizable parameters.

Table of Contents

Installation

npm install searxng

Usage

First, import and instantiate the SearxngService with your configuration:

import { SearxngService, type SearxngServiceConfig } from 'searxng';

const config: SearxngServiceConfig = {
  baseURL: 'https://your-searxng-instance.com',
  defaultSearchParams: {
    format: 'json',
    lang: 'auto',
  },
  defaultRequestHeaders: {
    'Content-Type': 'application/json',
  },
};

const searxngService = new SearxngService(config);

Types

SearxngCategory

export type SearxngCategory =
  | 'general'
  | 'translate'
  | 'web'
  | 'wikimedia'
  | 'images'
  | 'videos'
  | 'news'
  | 'map'
  | 'music'
  | 'lyrics'
  | 'radio'
  | 'it'
  | 'packages'
  | 'q&a'
  | 'repos'
  | 'software_wikis'
  | 'science'
  | 'scientific_publications'
  | 'wikimedia'
  | 'files'
  | 'apps'
  | 'social_media';

SearxngEngine

export type SearxngEngine =
  | '1337x'
  | '9gag'
  // Other engines here
  | 'zlibrary';

SearxngLocale

export type SearxngLocale =
  | 'af'
  | 'ar'
  | 'bg'
  // Other locales here
  | 'zh-Hant-TW';

SearxngPlugin

export type SearxngPlugin =
  | 'Hash_plugin'
  | 'Self_Information'
  // Other plugins here
  | 'Tor_check_plugin';

SearxngSearchParameters

export interface SearxngSearchParameters {
  categories?: SearxngCategory[];
  engines?: SearxngEngine[];
  lang?: 'auto' | SearxngLocale;
  pageno?: number;
  time_range?: 'day' | 'month' | 'year';
  format?: 'json' | 'csv' | 'rss';
  results_on_new_tab?: 0 | 1;
  image_proxy?: boolean;
  autocomplete?: 'google' | 'dbpedia' | 'duckduckgo' | 'mwmbl' | 'startpage' | 'wikipedia' | 'stract' | 'swisscows' | 'qwant';
  safesearch?: 0 | 1 | 2;
  theme?: 'simple';
  enabled_plugins?: SearxngPlugin[];
  disabled_plugins?: SearxngPlugin[];
  enabled_engines?: SearxngEngine[];
  disabled_engines?: SearxngEngine[];
}

SearxngSearchResult

export interface SearxngSearchResult {
  url: string;
  title: string;
  content?: string;
  engine: SearxngEngine;
  parsed_url: string[];
  template: 'default.html' | 'videos.html' | 'images.html';
  engines: SearxngEngine[];
  positions: number[];
  publishedDate?: Date | null;
  thumbnail?: null | string;
  is_onion?: boolean;
  score: number;
  category: SearxngCategory;
  length?: null | string;
  duration?: null | string;
  iframe_src?: string;
  source?: string;
  metadata?: string;
  resolution?: null | string;
  img_src?: string;
  thumbnail_src?: string;
  img_format?: 'jpeg' | 'Culture Snaxx' | 'png';
}

SearxngSearchResults

export interface SearxngSearchResults {
  query: string;
  number_of_results: number;
  results: SearxngSearchResult[];
  answers: string[];
  corrections: string[];
  infoboxes: Array<{
    infobox: string;
    content: string;
    engine: string;
    engines: string[];
  }>;
  suggestions: string[];
  unresponsive_engines: string[];
}

Configuration

export interface SearxngServiceConfig {
  baseURL: string;
  defaultSearchParams?: Partial<SearxngSearchParameters>;
  defaultRequestHeaders?: Record<string, string>;
}

Methods

search

Perform a search with the given input query and optional parameters.

async search(
  input: string,
  params?: Partial<SearxngSearchParameters>,
): Promise<SearxngSearchResults>
  • input (string): The search query string.
  • params (Partial, optional): Optional additional query parameters.

Returns a promise that resolves to SearxngSearchResults.

Examples

Basic Search

import { SearxngService, type SearxngServiceConfig } from 'searxng';

const config: SearxngServiceConfig = {
  baseURL: 'https://your-searxng-instance.com',
  defaultSearchParams: {
    format: 'json',
    lang: 'auto',
  },
  defaultRequestHeaders: {
    'Content-Type': 'application/json',
  },
};

const searxngService = new SearxngService(config);

async function performSearch() {
  try {
    const results = await searxngService.search('example query');
    console.log(results);
  } catch (error) {
    console.error('Search failed:', error);
  }
}

performSearch();

Search with Parameters

import { SearxngService, type SearxngServiceConfig } from 'searxng';

const config: SearxngServiceConfig = {
  baseURL: 'https://your-searxng-instance.com'
};

const searxngService = new SearxngService(config);

async function performSearchWithParams() {
  const searchParams = {
    categories: ['general', 'web'],
    engines: ['google', 'bing'],
    lang: 'en',
    pageno: 2,
    time_range: 'month',
    format: 'json',
  };

  try {
    const results = await searxngService.search('example query', searchParams);
    console.log(results);
  } catch (error) {
    console.error('Search failed:', error);
  }
}

performSearchWithParams();