@utsabc/khoj
v1.0.0
Published
A TypeScript library for search engine results
Downloads
5
Maintainers
Readme
Khoj
A typed library for search and parsing search engine results as JSON
Installation
Install the package using npm:
npm install khoj
Usage
Here's a basic example of how to use Khoj:
import { search, SearchEngine, SearchOptions } from 'khoj';
const options: SearchOptions = {
query: 'TypeScript libraries',
limit: 10
};
search(options, SearchEngine.Google)
.then(results => {
console.log(results);
})
.catch(error => {
console.error('Error:', error);
});
API
search(options: SearchOptions, engine?: SearchEngine): Promise<SearchResult[]>
Parameters:
options
: SearchOptions object (required)engine
: SearchEngine enum (optional, defaults to Google)
SearchOptions
An object with the following properties:
import { SearchOptions, SearchResult, SearchEngine } from "./types";
query
: string (required) - The search querylimit
: number (optional) - Maximum number of results to returnuserAgent
: string (optional) - Custom user agent stringstart
: number (optional) - Starting position for resultsincludeSites
: string (optional) - Comma-separated list of sites to include in the searchexcludeSites
: string (optional) - Comma-separated list of sites to exclude from the searchverbose
: boolean (optional) - Logs Results if enabled
SearchEngine
An enum with the following values:
Google
(default)Bing
SearchResult
An object representing a single search result. The exact structure may vary depending on the search engine used.
Development
To set up the project for development:
Clone the repository
Install dependencies:
npm install
Build the project:
npm run build
Run tests:
npm test
License
This project is licensed under the MIT License.