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

aurelia-autocomplete

v3.1.0

Published

Skeleton plugin following spoonx conventions.

Downloads

91

Readme

aurelia-autocomplete

Gitter

An autocomplete component for the aurelia framework.

autocomplete

Setup

Installation

jspm install aurelia-autocomplete

Configure

Simply register autocomplete as a plugin in main.js.

Usage

simple

<auto-complete resource="language"></auto-complete>

or if you have an array with items and thus would not need to perform a request

export class Page {
  languages = [ /* languages */ ];
}
<auto-complete items.bind="languages"></auto-complete>

extended

export class MyViewModel {

  results     = [];
  attributes  = ['productName', 'barcode'];
  customLabel = product => product.name + product.barcode;
  value       = 'banana';
  productCriteria = {
    stock: {'>': 0}
  };
  defaultProduct = {
    productName: 'No product',
    productCategory   : 'none'
  };

  constructor() {
    product = this.defaultProduct;
  }

  resultsChanged(products) {
    // select the first product that has the name 'banana'. If cannot be found
    // then select the first product in the results.
    this.selected = products.find(product => product.name === 'banana') || products[0];

    // always show the no product option
    this.results = this.results.concat([this.defaultProduct]);
  }

  productSort(products) {
    products.sort((a, b) => a.price > b.price;
  }

}

  <h4>${product.productName} ${product.productCategory}</h4>

  <auto-complete
    resource="product"
    selected.bind="selected"
    value.two-way="value"
    result.two-way="value"
    attribute.bind="attributes"
    results.bind="results"
    limit="5"
    endpoint="product-api"
    sort.bind="productSort"
    criteria.bind="{}"
    label.bind="customLabel">
  </auto-complete>

Documentation

Bindables

limit = 10;

The max amount of results to return. (optional)

name = '';

The name of the element. (optional)

items;

Used when one already has a list of items to filter on. Requests is not necessary.

resource;

The string that is appended to the api endpoint. e.g. language is the resource in following url api.com/language

value = '';

The string to be used to do a contains search with. By default it will look if the name contains this value

selected;

Can be used to select default element visually

result;

The result object from the server, set when something was selected.

minInput = 0;

How many characters are required to type before starting a search.

footerLabel = 'Create';

The label to show in the footer. Using i18n? No problem, this automatically gets translated.

footerVisibility = 'never';

When to show the footer. Possible values are never, always an no-results.

footerSelected = (value) => {};

Callback that gets called with the selected value when the footer gets clicked.

debounce = 100;

Configure debounce value for user input.

populate = null;

Which relations to populate for results.

attribute = 'name';

The property to query on. Support both string and array (in case it should query on multiple fields)

({defaultBindingMode: bindingMode.twoWay}) value = null;

Used to pass the "selected" value to the user's view model

({defaultBindingMode: bindingMode.twoWay}) results = [];

The results returned from the endpoint. These can be observed and mutated.

label = result => result[this.attribute];

Used to determine the string to be shown as option label

endpoint;

Allow to overwrite the default api endpoint

placeholder;

Overwrite the default placeholder (Search). Gets translated automatically.

sort = items => items;

Sort method that takes a list and returns a sorted list. No sorting by default.

criteria = {};

Used to make the criteria more specific

Methods

Some methods might be handy to overwrite or wrap.

shouldPerformRequest()

When it returns true, a request will be performed on a search change.

findResults(query)

Overwrite the default fetch. Expects to return a Promise which resolves to a list of results

searchQuery(string)

By default aurelia autocomplete works with waterline queries. If your query language differs, you can overwrite this method to return a query your endpoint accepts.

filter(items)

Takes items and returns only the array defined in the items bindable and should returns a new array containing the desired array with results.

By default it makes sure to not return more items than the limit specifies.

itemMatches(item)

Used by the this.filter to determine if an item should be added or not.

get regex()

Returns a regex which is used for highlighting the items in the html and for determining if an item matches in the itemMatches method