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 🙏

© 2026 – Pkg Stats / Ryan Hefner

string-sort

v1.2.0

Published

Simple library to sort a string based on character priority

Readme

string-sort

Simple library to sort an array based on string character priority.

This module performs a Schwartzian Transform on strings to return a 'transformed' version, sorts by that then resolves back to the original value. The upshot of this is that you can change the default string comparator behaviour so you can bias what characters are worth in the sort order. This is especially useful when wanting to sort by numbers above alpha characters or reorder the behaviour of punctuation.

var ss = require('string-sort');

// For whatever reason we hate the letter 'c', send it to the bottom of the sort order
ss.sort(['a', 'b', 'c', 'd', 'e', 'f'], {charOrder: 'abdef'}); 
// => ['a', 'b', 'd', 'e', 'f', 'c']

// Sort so that numbers sort before alpha characters
ss.sort(['a', 'b', 'c', '1', '5', '9'], {charOrder: '0123456789abcdefghijklmnopqrstuvwxyz'}); 
// => ['1', '5', '9', 'a', 'b', 'c]

API

stringSort.sort(array, [options])

Sort and return an array with the supplied options. This function really just wraps Array.sort(), calculating the transform table beforehand.

stringSort.sortBy(collection, key, [options])

Similar to sort() but works on a collection (an array of objects) using the specified key as the sorter.

stringSort.transformTable(charOrder)

Return a string transformation table. This is mainly used internally by transform() and untransform().

stringSort.transform(str, [options])

Return the translated, sort compatible version of an input string. This function is very slow as it needs to parse the options structure and reconstruct the table each time. Use sort() for larger arrays.

stringSort.untransform(str, [options])

Return the untranslated, version of a translated string. This function is very slow as it needs to parse the options structure and reconstruct the table each time. Use sort() for larger arrays.

stringSort.defaults

An object of the default options to use if unspecified.

Options

The following are the default options used by the functions.

| Option | Type | Default | Description | |------------------|------------|--------------------------------------------|----------------------------------------------------------------------------------------------------------------------| | charOrder | string | abcdefghijklmnopqrstuvwxyz0123456789:/-_ | The ascending character values when comparing strings. Anything not in this string will get its value via fallback | | fallback(char) | function | c => 999 | Function that is expected to return the fallback values if the char does not exist in charOrder |