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

velge

v1.0.0-alpha

Published

Nimble autocompleting tag management

Downloads

3

Readme

Build Status NPM version

Velge (ch•oose)

  1. verb - Pick out or select as being the most appropriate of two or more alternatives.
  2. noun - Nimble autocompleting tag management in javascript

Velge Example

Velge is a nimble tag management widget. It is written in pure javascript, has no dependencies, is fully tested with Mocha, and can be installed via NPM or Bower.

Some of the features:

  • Event emission for all state and ui events.
  • Fuzzy pattern matching for searching.
  • Customizable sorting, validation, normalization.
  • Keyboard shortcuts for navigation, quick submission, and removal.

The library is very lightweight and constructed in a way that allows for easy feature additions. We'd love more people to use it, request features, and contribute!

Installation

The simplest way is through NPM:

npm install velge --save

You'll then want to import the compiled .js and .css:

<link href="/node_modules/velge/dist/velge.css" rel="stylesheet" type="text/css">
<script src="/node_modules/velge/dist/velge.min.js"></script>

If you prefer to import velge directly you can import it directly through CommonJS:

var velge = require('velge');

Usage

Velge can be attached to any container. The structure isn't of any importance:

<div class='velge'></div>

Initialize velge with a selector for the container and customization options:

var container = document.getElementById('container');

var velge = new Velge(container, {
  placeholder: 'Choose'
});

Any choices that are provided at initialization will be used to pre-populate the dropdown and chosen lists.

Loading Tags

All tag matching is performed locally. As such you must load in all possible choices and an optional set of chosen values:

velge
  .add({ name: 'orange' })
  .add({ name: 'berry' })
  .add({ name: 'tangy' });

velge
  .choose({ name: 'apple' })
  .choose({ name: 'juicy' });

// Choices: 'orange', 'berry', 'tangy', 'apple', 'juicy'

Tag objects can be anything that have a "name" property. Whatever object is loaded is what will be passed to any callbacks.

It isn't always tidy to add choices and chosen separately. For convenience they can also be loaded during construction:

new Velge(element, {
  choices: [
    { name: 'macintosh' },
    { name: 'cortland' }
  ],
  chosen: [
    { name: 'jonagold' },
    { name: 'snow sweet' }
  ]
});

Persisting

The velge instance emits events for persisting changes after tags have been added, chosen, rejected, or deleted.

velge
  .on('add',    function(object) { console.log('added', object) })
  .on('choose', function(object) { console.log('chose', object) })
  .on('reject', function(object) { console.log('reject', object) })
  .on('delete', function(object) { console.log('deleted', object) });

You may prefer to save all changes at the same time, maybe via a more form-like submit action. That can be achieved by using getChosen:

var chosen = velge.getChosen();
var names  = chosen.map(function(choice) { return choice.name });

Other Events

Sometimes it is helpful to be notified of DOM level events within velge. Currently velge provides focus events which are bubbled up from the input area.

velge
  .on('focus', function(event) { console.log('has focus'); })
  .on('blur',  function(event) { console.log('lost focus'); })

Sorting

By default choices will be displayed in the order they were added. It is possible to specify a sorting behavior during construction, or afterwards:

var comparitor = function(a, b) {
  if (a.name > b.name)      { return 1;  }
  else if (a.name < b.name) { return -1; }
  else                      { return 0;  }
};

var velge = new Velge(element, {
  comparitor: comparitor
})

// Setting options will trigger an immediate re-sort
velge.setOptions({ comparitor: function(a, b) {
  if (a.createdAt > b.createdAt)      { return 1;  }
  else if (a.createdAt < b.createdAt) { return -1; }
  else                                { return 0;  }
});

Limitation Mode

While velge is designed as an interface for applying multiple "tags" to a resource it can also operate in single, limitation, mode. Under single mode only the most recent tag will be kept, all others will be unchosen.

var velge = new Velge(element, { limitation: true })

Error Handling

Because velge displays all tag additions instantly it can easily fall out of sync with the underlying collection. If, for example, an ajax request fails you can rollback the addition:

var addCallback = function(choice) {
  $.ajax({
    data: choice,
    type: "POST",
    url:  "/api/resource/1/tags"
  }).fail(function(error) {
    velge.reject(choice);
  })
};

Development

The project is built with modules from NPM. Simply run:

npm install

Once all modules are installed you're all set to test, lint, or build.

npm run test  # scripts/test
npm run lint  # scripts/lint
npm run build # scripts/build

License

MIT, see LICENSE.txt for details.