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 🙏

© 2026 – Pkg Stats / Ryan Hefner

popover-autocomplete

v1.0.1

Published

An autocomplete library supporting top-layer display using the Popover API.

Readme

popover-autocomplete

An autocomplete library supporting top-layer display using the Popover API.

How to use

Import autocomplete library to your project

<script src="cdn url"></script>

or

// ES6 modules
import Autocomplete from 'popover-autocomplete'

Prepare search data.
This supports an array of strings or an array of objects.

<body>
  <input class="autocomplete-input">

  <script>
    const items = ['suggest11', 'suggest12', 'suggest21', 'suggest22']
  </script>
<body>

Create new instance of Autocomplete with target input element.

const items = ['suggest11', 'suggest12', 'suggest21', 'suggest22']
const inputElement = document.querySelector('.autocomplete-input')

new Autocomplete({
  inputElement: inputElement,
  onSearch: (term, onResult) => {
    const results = items.filter((item) => item.includes(term))
    onResult(results)
  },
  onSelect: (result) => inputElement.value = result.value
})

Options

inputElement (required)

The input element to attach the autocomplete functionality to. example:

inputElement: document.querySelector('.autocomplete-input')

onSearch (required)

Callback function for searching. Accepts term and onResult as arguments. Uses term to search and calls onResult with the results.

The search function to get results can be freely customized.

example:

onSearch: (term, onResult) => {
  const results = items.filter((item) => item.includes(term))
  onResult(results)
}

onSelect (required)

Callback function executed when an item is selected.

example:

onSelect: (result) => inputElement.value = result.value

result is a dataset property.
If you used an array of strings as data, the result can be retrieved from value.
If you used an array of objects as data, the result can be retrieved from the property name of the data.

onRender (optional)

Function to customize rendering of each item.

example:

onRender: (item) => `result: ${item.value}`

defaults to render only search result.

minLength (optional)

Minimum number of characters required to start the search. Defaults to 3.

example:

minLength: 4

Styles

This library does not provide CSS.
However, each generated HTML element has a predefined class attribute. To apply styles, you can specify the following classes in your CSS.

| Class Attribute | Description | |-----------------------------------------|-----------------------------------------| | popover-autocomplete-container | The main container for the autocomplete | | popover-autocomplete-item | An individual suggestion item | | popover-autocomplete-item-highlighted | The highlighted suggestion item |

Run Tests

E2E test

This project uses Playwright for testing. Follow the steps below to execute the tests.

1. Start the server

Before running the tests, need to start the local server.

npm run server

2. Run the tests

Once the server is running, you can execute the tests with the following command:

npm run test

Package test

This project has an environment that allows you to test the operation of the package through npm.

1. Create the package

Run following command on the root directory.

npm pack

This command generates a .tgz package file.

2. Install package

Move to the package-test-project directory.

cd tests/package-test-project

Install package.

npm install ../../popover-autocomplete-[version].tgz

3. Build

Compile files for distribution.

npx vite build

3. Start the test server

On the package-test-project directory, run

npx vite

After starting the server, open http://localhost:5173 in your browser to test and confirm the package works as expected.