Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
brave-search
Advanced tools
A TypeScript library for interacting with the Brave Search API, including web search, local POI search, and automatic summarization features.
A fully typed Brave Search API wrapper, providing easy access to web search, local POI search, and automatic polling for web search summary feature.
Install the package using npm:
npm install brave-search
If you prefer to use the jsr registry, you can add the package using the following commands:
npx jsr add @tyr/brave-search
Import the package in your project:
import { BraveSearch } from "brave-search";
If you are using the jsr registry, import the package as follows:
import { BraveSearch } from "@tyr/brave-search/";
Obtain a Brave Search API key from Brave Search API Dashboard.
Install the package using one of the methods above.
Initialize the BraveSearch
class:
const BRAVE_API_KEY = "your-api-key-here";
const braveSearch = new BraveSearch(BRAVE_API_KEY);
Perform a web search using the webSearch
method. Your IDE will provide type hints for the parameters and return types.
const webSearchResults = await braveSearch.webSearch("TypeScript tutorial", {
count: 5,
safesearch: "off",
search_lang: "en",
country: "US",
text_decorations: false,
});
console.log(webSearchResults);
Get a summarized answer for a query using the getSummarizedAnswer
method. This method returns an object containing summary
and webSearch
promises.
const { summary, webSearch } = braveSearch.getSummarizedAnswer(
"How many stars there are in our galaxy?",
{
count: 5, // Number of search results to return
safesearch: "off", // Optional: Filter for adult content (default is "moderate")
search_lang: "en", // Optional: Language of the search results (default is "en")
country: "US", // Optional: Country for the search results (default is "us")
text_decorations: false, // Optional: Whether to include text decorations (default is true)
spellcheck: false, // Optional: Whether to enable spellcheck (default is true)
extra_snippets: true, // Optional: Whether to include extra snippets (default is false)
},
);
// Wait for the web search results (almost immediately)
const webSearchResponse = await webSearch;
console.log("Web Search Response:", JSON.stringify(webSearchResponse, null, 2));
// Wait for the summarized answer (can take up to couple of seconds)
const summarizedAnswer = await summary;
console.log("Summarized Answer:", JSON.stringify(summarizedAnswer, null, 2));
Search for local points of interest using the localPoiSearch
method.
const poiResults = await braveSearch.localPoiSearch(["poi_id1", "poi_id2"]);
console.log(poiResults);
Get descriptions for local points of interest using the localDescriptionsSearch
method.
const descriptionResults = await braveSearch.localDescriptionsSearch(["poi_id1", "poi_id2"]);
console.log(descriptionResults);
The library supports various search options as defined in the Brave Search API documentation. For a complete list of options and their descriptions, please refer to the Brave Search API Documentation.
summary
option and getSummarizedAnswer
method are only available with the Brave "Data for AI pro" plan.For detailed API reference, please refer to the Brave Search API Documentation.
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the GNU General Public License v3.0 - see the LICENSE file for details.
This library is not officially associated with Brave Software. It is a third-party implementation of the Brave Search API.
FAQs
A fully typed Brave Search API wrapper, providing easy access to web search, local POI search, and automatic polling for web search summary feature.
The npm package brave-search receives a total of 22 weekly downloads. As such, brave-search popularity was classified as not popular.
We found that brave-search demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.