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

idb-suggester

v0.2.24

Published

a simple suggester, using indexedDB.

Downloads

12

Readme

Synopsis

Une barre de recherche proposant des entités stockées dans IndexedDB. Un second composant permet de charger l'index à partir d'une liste d'entités.

npm install idb-suggester ou yarn add idb-suggester npm run storybook ou yarn storybook

DEMO

DEMO

Créer un index dans IDB.

L'index contient une liste d'entités et un index permettant des recherches par préfix sur celle-ci. A la création, la liste des attributs dont la valeur doit être utilisée pour créer l'index doit-être fournit :

const fields = [{ name: '<field_name>', tokenize: true, language: 'French' }];

Si l'attribut tokenize est renseigner à true, la valeur du champs est tokenizer, sa racine est extraite avec l'algorithme snowball et le langage préciser, pour permettre une recherche par mot clef plutôt que par préfixe.

import { createWorker, BULK_INSERT_MESSAGES } from 'idb-suggester';

function workerCallback(args) {
  const { message, step } = args;
  switch (message) {
    case BULK_INSERT_MESSAGES.complete: {
         console.log('Step finished ', step);
      break;
    }
    case BULK_INSERT_MESSAGES.finished:
      console.log('Chargement fini');
      break;
    case BULK_INSERT_MESSAGES.error:
        break;
    default:
  }
}



const idbName = '<MY_STORE_NAME>'; // Nom de la base IDB.
const fields = [{ name: '<field_name>' }, ...]; // description des attributs à indéxer.
const data = [...]; // un tableau contenant la liste d'entité

const bulkTask = createWorker(workerCallback); // créer un web worker pour le chargement.
bulkTask(idbName, fields, data, false/true);// lance la procédure de chargement.

Un composant <StoreManager /> prêt à l'emploi est fournit pour intégrer la tâche d'alimentation de l'index.

Utiliser un Index

import { Suggester } from '../suggester';
import React, { useState, useEffect } from 'react';
import { createStore, SEARCH_TYPES } from '../store-index';
import 'idb-suggester/themes/css/default-theme.css';

// intégration dans un composant react.

const IDB_INDEX_NAME = 'name';
const IDB_VERSION = 1;
const IDB_ENTITIES_FIELDS = [...];

function App() {
  const [store, setStore] = useState(undefined);
  useEffect(function () {
    async function init() {
      setStore(await createStore(IDB_INDEX_NAME, IDB_VERSION, IDB_ENTITIES_FIELDS));
    }
  });

  return (
    <div style={{ width: '380px' }}>
      <Suggester
        store={store}
        className="custom-css-className"
        displayPath="path"
        placeHolder="Searching something..."
        optionComponent={CustomOptionComponent}
        onSelect={function (item, all, query) {
          console.log('onSelect select option', item, all, query);
        }}
        searchType={SEARCH_TYPES.prefix}
      />
    </div>
  );
}

Suggester Props

| Property | Type | Default | Description | | :---------------- | :-------------- | :------------------------------------- | :--------------------------------------------------------------------------------- | | optionComponent | store object | required | un index valide chargé avec la fonction createStore | | optionComponent | React component | React component | composant de rendu des suggestions dans le panel | | searchIcon | React component | undefined | icône de recherche | | how | number | 15 | nombre maximum de suggestions proposées | | placeHolder | string | React component | placeHolder du champ input | | language | string | React component | langage utilisé pour la lemmatisation pour les index de type SEARCH_TYPES.tokenize | | className | string | React component | classe css additionnelle pour surcharger les styles | | onChange | function | (query,suggestions)=>null | function invoquée en cas de modification de la recherche | | onSelect | function | (selection, suggestions,query)=>null | function invoquée en cas de sélection d'un item du panel |