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 🙏

© 2025 – Pkg Stats / Ryan Hefner

lacona-addon-ordered

v0.5.0

Published

Add an ordering system to the lacona parser

Downloads

21

Readme

lacona-addon-ordered

Travis Coverage Status

lacona-addon-ordered provides all of the same benefits of lacona-addon-stateful but also introduces the concept of ordering.

Ordering is imposed on one particular text-based result. - a combination of the match, suggestion, and completion of a particular command. lacona-addon-ordered maintains that these two strings:

  • *open* Firefox
  • *open* Google Chrome

will sort in the same order reliably, based upon a given computation function If the string *open* Firefox Developer Edition has been entered, that will not influence the sort order of *open* Firefox, or vice-versa.

##Usage

Like lacona-addon-stateful, this stream outputs objects with three properties:

{
  event: ('insert' || 'update' || 'delete'),
  id: Number,
  data: OutputOption
}

An event will be emitted for every event coming from the lacona-addon-stateful. However, the id properties will not be the same. They will correspond to the index of an array containing all of the previously outputted events. Here is an example:

Imagine these events. The comments show the state of the data array as it should be represented after each event.

{event: 'insert', id: 0, data: 'a'} // ['a']
{event: 'insert', id, 0, data: 'b'} // ['b', 'a']
{event: 'update', id: 1, data: 'c'} // ['b', 'c']
{event: 'delete', id: 0}            // ['c']

You must be very careful to maintain your array in exactly the way specified by each event (including the order). Otherwise your representation will get out-of-sync and all future events will be invalid.

Your code should respond to events in a manner equivalent to this:

switch (obj.event) {
  case 'insert': arr.splice(obj.id, 0, obj.data); break;
  case 'update': arr.splice(obj.id, 1, obj.data); break;
  case 'delete': arr.splice(obj.id, 1); break;
}

##Limitations

Currently, the ordered.comparator function must be a function of the stateful.serializer function. That is to say, the same output from stateful.serializer must yield the same output from ordered.comparator every time.

Therefore, anything that stateful considers to be an update can, by definition, not effect the sort order.

Doing so is possible, but I do not currently see a use case for sorting an order independent of grouping.

##Example

var lacona = require('lacona');
var Stateful = require('lacona-addon-stateful');
var Ordered = require('lacona-addon-ordered');
var fulltext = require('lacona-util-fulltext');

var parser = new lacona.Parser(options);
var stateful = new Stateful({serializer: fulltext});
var ordered = new Ordered({comparator: fulltext});

src
  .pipe(parser)
  .pipe(stateful)
  .pipe(ordered)
  .pipe(process.stdout);