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

typeahead-tagbox

v1.1.5

Published

A typeahead tagbox with zero dependencies!

Downloads

9

Readme

typeahead-tagbox

Converts an <input> to a typeahead tagbox. Demos

Basic Usage

Javascript:

typeaheadTagbox({
    data: [
        {"id":1,"text":"Duisburg"},
        {"id":2,"text":"Lagonegro"},
        {"id":3,"text":"Coquimbo"},
        {"id":4,"text":"Kungälv"},
        {"id":5,"text":"Brandenburg"},
        {"id":6,"text":"Salt Lake City"},
        {"id":7,"text":"Pomarolo"},
        {"id":8,"text":"Hanau"},
        {"id":9,"text":"Kampenhout"},
        {"id":10,"text":"Matamata"}
    ]
});

HTML:

<input type="text" name="tags" class="typeahead-tagbox">

Options

Basic

Name | default | type | Comment --- | --- | --- | --- caseSensitive | false | Boolean | If the typeahead should check the text case sensitive or not data | [] | Array | required - The data which should be searched dropdownItemTemplate | "{{text}}" | String | The template for the dropdown item. Possible variables: {{text}}, {{id}}, and any additional key you add to the data objects idKey | "id" | String | Key of the data objects, by which the data should be sorted. Can be the same es textKey, but make sure you have no duplicates then inputPlaceholder | "add..." | String | String for the input placeholder minLength | 2 | Integer | Number of chars to be typed befor the search starts selector | ".typeahead-tagbox" | String | Selector for the to be transformed input element tagDeleteButtonContent | "x" | String | Content of the delete button. May be an image tag or svg icon for example tagTemplate | "{{text}}" | String | The template for the tags. Possible variables: {{text}}, {{id}}, and any additional key you add to the data objects textKey | "text" | String | Key of the data objects, which should be displayed in the dropdown and tag

Classes

Name | default | type | Comment --- | --- | --- | --- dropdownClass | "typeahead-dropdown" | String | The class for the dropdown element dropdownItemClass | "typeahead-dropdown-item" | String | The class for the dropdown item element dropdownSelectedClass | "selected" | String | Class to be added when a dropdown is selected by keyboard arows highlightClass | "typeahead-highlight" | String | Class to be wrapped around the matching substring inputClass | "typeahead-input" | String | Class for the actual input field tagClass | "typeahead-tag" | String | Class for the tags tagRemovingClass | "removing" | String | Class added to the tag befor removing it via keyboard backspace typeaheadClass | "typeahead" | String | Class added to the wrapper of the typeahead

Callbacks

Name | default | type | Comment --- | --- | --- | --- onAddTag | undefined | undefined / null / Function | Callback to be executed when a tag is added. Parameters: tag which was just added, taglist current list of tags, including the new one onClickDropdownOption | undefined | undefined / null / Function | Callback to be extecuted when an dropdown option is clicked. Parameters: option which was just clicked. Executed before onAddTag. onOpenDropdown | undefined | undefined / null / Function | Callback to be executed when the dropdown is opened to display search results. Parameters: value of the input, optionlist which is displayed in the dropdown onRemoveTag | undefined | undefined / null / Function | Callback to be executed when a tag is removed. Parameters: tag which was removed, taglist without the just removed tag

Examples

Custom data & dropdown item

typeaheadTagbox({
    data: [
        { 
            username: 'jackson', 
            age: 43, 
            id: '5c678gh32', 
            image: 'jackson-avatar.jpg' 
        },
        { 
            username: 'ferdinand', 
            age: 23, 
            id: '5c6jh76a2', 
            image: 'ferdinand-avatar.jpg' 
        },
        /* more data */
    ],
    textKey: 'username'
    dropdownItemTemplate: '<img src="uploads/{{image}}"><strong>{{text}}</strong>({{age}})'
});