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

searchasyoutype

v3.1.0

Published

Search as you type

Readme

Search As You type

A customizable search-as-you-type javascript widget.

Installation

Install with npm (preferred) by typing

    npm install searchasyoutype

or just download the package and add searchasyoutype.min.js to your project.

Usage

Basic markup:

    <form class="my-form" data-endpoint="my-json-endpoint.json">
        <input class="sayt__input" name="q" placeholder="Start typing" />
    </form>

The javascript:

    var SearchAsYouType = require('searchasyoutype');
    var el = document.querySelector('.my-form');

    new SearchAsYouType(el, { // options });

Default format of json response

{
    "linkText": "View all 360 results",
    "linkUrl": "search?q=querystring",
    "results": [
        {
            "url": "mypost.html",
            "title": "My post",
            "body": "My post body here..."
        },
        {...}
    ]
}

Options

These are the options you can provide to override default behaviour:

  • minStringLength The minimum length of the typed input that should perform a search (default: 3)
  • inputSelector The class of the input field (default: '.sayt__input')
  • resultsSelector The class of the container the results are rendered in (default: '.sayt__result-container')
  • resultClassName Class of a single result item (default: 'sayt__result')
  • resultTitleClassName Class of result title (default: 'sayt__result-title')
  • resultBodyClassName Class of result body (default: 'sayt__result-body')
  • linkClassName Class of the link that displays number of result and provides link to all results (default: 'sayt__link')
  • endpoint If you prefer not to privde endpoint through elements data-endpoint attribute
  • onBeforeFetch Called before ajax call is made. Takes queryString as argument. (default: function(queryString) {})
  • onAfterFetch: Called after ajax call has been made. Takes queryString and response json data as arguments. (default: function(queryString, data) {})
  • onAfterInsertResults Called after results are inserted in results element. (default: function() {})
  • template Use this to override default markup of results. Example below.

Template

If your response data is formatted differently (which it probably is) you can provide your own (very simple) template for the response:

    new SearchAsYouType(el, {
        template: '<% forEach(results, function(result) { %>' +
        '<a href="<%= result.url %>" class="search-widget__result">' +
        '<h3 class="search-widget__result-title"><%= result.title %></h3>' +
        '<p class="search-widget__result-body"><%= result.body %></p>' +
        '</a>' +
        '<% }); %>'
    });

The forEach function is present for looping. use <%= something %> to print and <% if (true === true) { %> <% } %> to execute javascript.

jQuery plugin

SearchAsYouType does not require jQuery but there is a jQuery plugin if you prefer.

    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
    <script src="searchasyoutype.jquery.min.js"></script>
    <script>
        $('.my-element').searchAsYouType({ // options });
    </script>

Licence

Copyright 2016 Martin Sörensson.

Released under MIT License.