The excellent and well-tested js-naturalsort has almost everything I want, but it doesn't work with underscore.js and CouchDB because it does a binary compare rather than generate sort keys. This takes one value and returns a sort key in the form of an array, rather than simply comparing two values. The results may be slightly different but it will hopefully work well enough to be useful.
The binary comparison from js-naturalsort has been added as
naturalsort.compare(value1, value2), along with the tests, which can be run with
The sort key function has been added as
naturalsort.key(value). It currently only handles converting a single positive integer string to a number.
This is run through the tests from js-naturalsort. 13 tests fail with
_.sortBy(arr, naturalsort.key). 17 tests fail when using what amounts to a plain sort().
The authors and contributors of the original js-naturalsort:
Licensed under the terms of the MIT License, available in LICENSE.md.