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

@afosto/instant-search-client

v1.0.9

Published

The Afosto InstantSearch client

Downloads

786

Readme

Don't want to implement your own UI? You can also try our Afosto instant search widget.

Installation

Basic

# Install with Yarn
yarn add @afosto/instant-search-client instantsearch.js

# Install with NPM
npm install @afosto/instant-search-client instantsearch.js

React

# Install with Yarn
yarn add @afosto/instant-search-client react-instantsearch-dom

# Install with NPM
npm install @afosto/instant-search-client react-instantsearch-dom

Browser

This library supports the last two versions of major browsers (Chrome, Edge, Firefox, Safari).

<script src="https://cdn.jsdelivr.net/npm/@afosto/instant-search-client@latest/dist/afosto-instant-search.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/instantsearch.js@4/dist/instantsearch.production.min.js"></script>

Getting started

To use the client you will need an Afosto search engine. Don't have one yet? Sign up on Afosto.com and follow the guides in our documentation.

First you initialize the Afosto search client with your search engine key. This search engine key can be found in the Afosto app.

ES6

import { afostoInstantSearch } from '@afosto/instant-search-client';

const client = afostoInstantSearch('my-search-engine-key');

CJS

const { afostoInstantSearch } = require('@afosto/instant-search-client');

const client = afostoInstantSearch('my-search-engine-key');

Browser

const client = afostoInstantSearch('my-search-engine-key');

Usage

Note: This library is a client for InstantSearch.js it does not contain any UI components by itself. You can use it with the InstantSearch.js library as shown below:

Basic

const client = afostoInstantSearch('my-search-engine-key');
const search = instantsearch({
  indexName: 'my-index',
  searchClient: client,
});

search.start();

For more information check the InstantSearch.js documentation.

Basic with settings

const client = afostoInstantSearch('my-search-engine-key');

async function initSearch() {
  const settings = await client.getSettings();
  const [firstIndex] = settings.indexes || [];
  
  const search = instantsearch({
    indexName: firstIndex.alias,
    searchClient: client,
  });
  
  // Do something with the settings.
  // For example render filters dynamically.

  search.start(); 
}

initSearch();

React

You can use the initialized Afosto client with the React InstantSearch library.

import { afostoInstantSearch } from '@afosto/instant-search-client';
import { InstantSearch, SearchBox, Hits } from 'react-instantsearch-hooks-web';

const searchClient = afostoInstantSearch('my-search-engine-key');

const App = () => (
  <InstantSearch searchClient={searchClient} indexName="my-index">
    <SearchBox />
    <Hits />
  </InstantSearch>
);

For more information check the React InstantSearch documentation.

Compatibility

  • InstantSearch.js v4
  • Node >= 14

License

This project is licensed under the terms of the MIT license.