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

type-ahead

v2.1.0

Published

A lightweight and extensible type ahead library

Downloads

188

Readme

type-ahead.js

A lightweight and extensible type ahead library. Browserify compatible.

Demo

Check out http://marcojetson.github.io/type-ahead.js/

Install

Browserify via NPM

To use type-ahead with Browserify, install it into your project via npm:

npm install type-ahead

Once installed, include the library using require:

var TypeAhead = require('type-ahead')

Manually

You can also include the standalone library by downloading it here (or minified), and including it in your HTML page:

<script type="text/javascript" src="type-ahead.js"></script>

Usage

Simple usage

new TypeAhead(document.getElementById('my-control'), [
	'Asia', 'Africa', 'Europe', 'North America', 'South America', 'Oceania'
]);

AJAX

var t = new TypeAhead(document.getElementById('my-control'));

t.getCandidates = function (callback) {
	$.getJSON('/suggest?q=' + this.query, function () {
		callback(response);
	});
};

Example is using jQuery for simplicity

Min length and limit

var opts = {
	minLength: 1,
	limit:false
}

var t = new TypeAhead(document.getElementById('my-control'), [
	'Asia', 'Africa', 'Europe', 'North America', 'South America', 'Oceania'
], opts);

Use objects instead of strings

var t = new TypeAhead(document.getElementById('my-control'), [
	{name: 'Asia'},
	{name: 'Africa'},
	{name: 'Europe'},
	{name: 'North America'},
	{name: 'South America'},
	{name: 'Oceania'}
]);

t.getItemValue = function (item) {
    return item.name;
};

Fulltext Search

type-ahead by default searches for the desired string at index 0 of each string in your search list. To enable full-text search, or the desired string at any index, enable the fulltext flag in the options:

var opts = {
	fulltext:true
};
var t = new TypeAhead(document.getElementById('my-control'), [
	'Asia', 'Africa', 'Europe', 'North America', 'South America', 'Oceania'
], opts);

Dynamically update list

Once you've created the TypeAhead instance, you can update the items in the autocomplete list via:

var t = new TypeAhead(document.getElementById('my-control'), [
	'Asia', 'Africa', 'Europe', 'North America', 'South America', 'Oceania'
]);

t.update([
	'Asia', 'Europe', 'South America', 'Oceania'
])

Callback

If you want to run code after autocomplete updates the input (e.g. to update a model), simply add a callback function into the opts parameter:

var opts = {
	callback:function(newValue){
		console.log(newValue);
		// Do code here
	}
};

var t = new TypeAhead(document.getElementById('my-control'), [
	'Asia', 'Africa', 'Europe', 'North America', 'South America', 'Oceania'
], opts);

Contributing

Found an issue? Have a feature request? Open a Github Issue and/or fork this repo.

License

Changelog

All notable changes to this project will be documented in this file.

This project adheres to Semantic Versioning and Keep A Changelog.

v2.1.0 - 13-10-2015

| Type | Link | Description | | ---- | ---- | ----------- | | Added | https://github.com/marcojetson/type-ahead.js/pull/13 | Fulltext Searching |

v2.0.0 - 09-09-2015

| Type | Link | Description | | ---- | ---- | ----------- | | Changed | https://github.com/marcojetson/type-ahead.js/pull/11#issuecomment-138800307 | Callback API. Now uses opts.onMouseDown and opts.onKeyDown |

v1.1.0 - 01-09-2015

| Type | Link | Description | | ---- | ---- | ----------- | | Added | https://github.com/marcojetson/type-ahead.js/issues/5 | Callback option. Now uses opts.callback |

v1.0.0 - 01-09-2015

| Type | Link | Description | | ---- | ---- | ----------- | | N/A | https://github.com/marcojetson/type-ahead.js/issues/3 | Initial NPM release |