b12-archive / natural-sort

Sorting with support for numbers, dates, unicode and more.
MIT License
11 stars 5 forks source link

Handle version numbers: #4

Open Wilfred opened 8 years ago

Wilfred commented 8 years ago
var naturalSort = require("natural-sort")

var x = ['0.16', '0.2'];
x.sort(naturalSort());

This leaves x unchanged. I was hoping natural-sort would handle strings that look something like versions.

ArmorDarks commented 8 years ago

Hi

To sort those versions, you need to specify correct semantic versions, otherwise lib thinks that you're trying to sort fractions, and as fractions, they are already properly sorted.

In other way, just try:

var naturalSort = require("natural-sort")

var x = ['0.16.0', '0.2.0'];
x.sort(naturalSort());
tomek-he-him commented 8 years ago

@ArmorDarks many thanks for your help here!

We’re working on a test suite to have this properly covered. The readme is a bit newer than what was released with 1.0.0, so please don’t rely on it yet. Sorry for the non-responsiveness and for the confusion – urgent stuff forced me to switch to other things before I finished off the streak with this lib.

Should be ready by the end of the week.