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

fg-auto-complete

v0.2.6

Published

A very small auto-complete component.

Downloads

14

Readme

Auto-complete

Filament Group

A lightweight auto-complete that can be populated via JSON or by DOM element text.

Build status

Dependencies

  1. jQuery or Shoestring
  2. Menu

Setup

Use the following includes to setup the init on enhance:

<script src="lib/shoestring-dev.js"></script>
<script src="lib/menu.js"></script>
<script src="src/core.js"></script>
<!-- optional if you're not using a DOM source for data -->
<script src="src/dom.js"></script>
<script src="src/init.js"></script>
<link rel="stylesheet" href="/lib/menu.css">

Typically the enhancement is triggered on DOM ready and when subsequent markup is added to the page:

$( function(){ $(document).trigger("enhance"); } );

Options

  • data-best-match, if the input has this attribute, on blur, the first match in the current suggested matches will be used to populate the input.

Examples:

See the demo page for examples.

Custom Comparison Logic

The existing comparison (which is just a substring check) might be too simple. In this case you can replace the compareDataItem definition on the AutoComplete prototype to get the desired custom comparison functionality. For example if you wanted to consult another part of the DOM (eg an input) for information that might inform the filtering of auto complete data you might do the following:

// data : String, a data item from the auto-complete data source (DOM or Ajax Req)
// val : String, the value of the auto-complete input
w.componentNamespace.AutoComplete.prototype.compareDataItem = function(data, val){
  // get the extra constraint information from the DOM
  var otherConstraint = $( ".some-input").val();
  
  // check if the value from the other input is a substring of the auto-complete data
  // check if the value from the autocomplete input is a substring of the auto-complete data
  // return true if both constraints are satsified
  return data.indexOf(otherConstraint) > -1 && data.indexOf(val) > -1;
}

As long this definition is executed after the auto-complete library is loaded/executed then this new method definition will determine the logic that plugin uses to filter the incomeing auto-complete data.

NOTE that the component namespace is often defined per-project. If you have defined that to be something other than componentNamespace which is the default, you'll need to substitute that here.

AUTO-complete

Just a bit of fun:

We define a class of languages AUTO, such that L is in AUTO if there exists a Turing machine M and an oracle O where M can write its input on the oracle tape and respond directly with the oracle's answer in a single query and L is decided by M.

Lemma 1. The language decided by the auto-complete component is in AUTO.

Clear from the implementation of the component. ∎

Lemma 2. All languages in AUTO can be reduced in polynomial time to the language decided by auto-complete.

Follows directly from the observation that the component takes as one of its parameters the "URL" for the oracle which it will consult. As a result we can always simulate the Turing machine for another language in AUTO by taking both the input and the URL for the oracle used in the implementation of the corresponding Turing machine which ensures that it will always have "the right oracle" to answer queries in a single round for any language in AUTO. ∎

Theorem. The language decided by the auto-complete component is AUTO-complete

By Lemma's 1 and 2. ∎