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

sort-enum

v0.1.9

Published

Utility class for sort enumeration and miscellaneous sorting-related semantics.

Downloads

3

Readme

sort-enum

Utility class for sort enumeration and miscellaneous sorting-related semantics.

No actual sorting algorithms implemented.

Installation

npm install sort-enum --save

Usage

import {Sort, SortHolder, SortHub} from 'sort-enum';

simple enum usage without hub

let a = Sort.NONE;
a = a.next(); // a is now Sort.ASC
a = a.next(); // a is now Sort.DESC
a = a.next(); // a is now Sort.NONE

simple holder usage without a hub

const s1 = new SortHolder();
assert(s1.v===Sort.NONE);
s1.next();
assert(s1.v===Sort.ASC);
s1.next();
assert(s1.v===Sort.DESC);

holder usage with a hub

SortHub basically caters to situations where, e.g. you have a table with sorted columns and you want when one column is sorted to automatically disable sorting on the others. It also allows you to ask the hub to return the 'column' that's currently enabled for sorting.

SortHolder is a utility class that under the hood uses the more flexible SortHub.add method that accepts simple getter and setter functions (see test.js for examples of that).

const hub = new SortHub();
const s1 = new SortHolder(hub, Sort.ASC);
const s2 = new SortHolder(hub);
hub.lock(); // create the hub with new SortHub(false) if you don't want to bother with locking
assert(s1===hub.returnSingleNonNoneRef());
s2.next();
assert.equal(s1.v, Sort.NONE);
assert.equal(s2.v, Sort.ASC);
assert(s2===hub.returnSingleNonNoneRef());
s2.next();
assert.equal(s1.v, Sort.NONE);
assert.equal(s2.v, Sort.DESC);
assert(s2===hub.returnSingleNonNoneRef());
s2.next();
assert.equal(s1.v, Sort.NONE);
assert.equal(s2.v, Sort.NONE);
assert(null===hub.returnSingleNonNoneRef());                   

Tests

npm test

Release History

  • 0.1.0 Initial release
  • 0.1.1 fixed typo in package.json
  • 0.1.2 conditionally requiring the babel-polyfill
  • 0.1.3 removed eval dependency
  • 0.1.4 added returnSingleNonNoneRef on SortHub
  • 0.1.5 added returnSingleNonNoneRef on SortHub
  • 0.1.6 cosmetics in README.md
  • 0.1.7 SortHolder utility class added
  • 0.1.8 support for optional locking
  • 0.1.9 cosmetics in README.md