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

ark-autocomplete

v0.0.1

Published

A lightweight, customizable, and easy-to-use autocomplete library for JavaScript with smart filtering, keyboard navigation, and event handling

Readme

Ark Autocomplete

A lightweight, customizable, and easy-to-use autocomplete library for JavaScript.

Features

  • 🔍 Smart Filtering: Customizable filtering function for precise search results
  • 🎨 Customizable Templates: Flexible item rendering with template functions
  • ⌨️ Keyboard Navigation: Intuitive arrow key and Enter key support
  • 📱 Responsive Design: Automatically positions dropdown based on input element
  • Debounced Input: Optimized performance with built-in debouncing
  • 🎯 Event Handling: Comprehensive event system for selection and change tracking
  • 🔧 Easy Integration: Simple setup with extensive configuration options

Installation

Include the library directly in your HTML:

<script src="path/to/ark-autocomplete.js"></script>

Quick Start

// Basic usage with array of strings
ark_autocomplete({
  target: '#my-input',
  data: ['Apple', 'Banana', 'Cherry', 'Date', 'Elderberry']
});

// Advanced usage with objects
ark_autocomplete({
  target: '#customer-search',
  data: customers,
  filter: searchTerm => customers.filter(
    customer => customer.name.toLowerCase().includes(searchTerm.toLowerCase())
  ),
  display: 'name',
  value: 'id'
});

Configuration Options

| Option | Type | Default | Description | |--------|------|---------|-------------| | target | String/Element | null | CSS selector or DOM element to attach autocomplete | | data | Array | [] | Data source for autocomplete | | filter | Function | Basic string matching | Custom filtering function | | item_templ | Function | <strong>${item}</strong> | Function to render each item | | compare | Function | Value comparison | Function to compare selected item with input | | value | String | '' | Property name for value field (when using objects) | | display | String | '' | Property name for display field (when using objects) |

API Methods

Instance Methods

const autocomplete = ark_autocomplete({ /* options */ });

// Subscribe to events
autocomplete.on('selected', (inputElement, selectedItem) => {
  console.log('Item selected:', selectedItem);
});

// Programmatically select an item
autocomplete.select(item);

// Get current value
const value = autocomplete.get_value();

// Unsubscribe from events
autocomplete.off('selected', callbackFunction);

Events

  • selected: Triggered when an item is selected
  • changed: Triggered when the value changes

Examples

Basic String Array

ark_autocomplete({
  target: '#fruit-search',
  data: ['Apple', 'Apricot', 'Avocado', 'Banana', 'Blueberry']
});

Custom Object Array

const users = [
  { id: 1, name: 'John Doe', email: '[email protected]' },
  { id: 2, name: 'Jane Smith', email: '[email protected]' }
];

ark_autocomplete({
  target: '#user-search',
  data: users,
  filter: searchTerm => users.filter(
    user => user.name.toLowerCase().includes(searchTerm.toLowerCase()) ||
            user.email.toLowerCase().includes(searchTerm.toLowerCase())
  ),
  item_templ: user => `
    <div>
      <strong>${user.name}</strong>
      <br>
      <small>${user.email}</small>
    </div>
  `,
  display: 'name',
  value: 'id'
});

Custom Filter Function

ark_autocomplete({
  target: '#custom-filter',
  data: products,
  filter: searchTerm => {
    // Your custom filtering logic
    return products.filter(product => 
      product.name.includes(searchTerm) || 
      product.category.includes(searchTerm) ||
      product.tags.some(tag => tag.includes(searchTerm))
    );
  }
});

Styling

The autocomplete dropdown uses the following CSS classes that you can customize:

  • .autocomplete-items - The dropdown container
  • .autocomplete-items div - Individual items
  • .autocomplete-items div:hover - Hover state
  • .autocomplete-active - Currently selected item with keyboard

Override these styles in your CSS to match your application's design.

Browser Compatibility

Works in all modern browsers that support:

  • ES6+ JavaScript features
  • CSS Flexbox
  • DOM Events

License

Copyright (c) 2015-2028 Immanuel R

Author

Immanuel R

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Support

For support, bug reports, or feature requests, please open an issue on the GitHub repository.