
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
string-sort
Advanced tools
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]
Sort and return an array with the supplied options. This function really just wraps Array.sort(), calculating the transform table beforehand.
Similar to sort() but works on a collection (an array of objects) using the specified key as the sorter.
Return a string transformation table.
This is mainly used internally by transform() and untransform().
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.
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.
An object of the default options to use if unspecified.
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 |
FAQs
Simple library to sort a string based on character priority
The npm package string-sort receives a total of 16 weekly downloads. As such, string-sort popularity was classified as not popular.
We found that string-sort demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.