3

This is from a node cli session:

> var a = 'foo12';
undefined
> var b = 'foo3';
undefined
> var s = [a , b];
undefined
> s.sort(function(a, b) {
... return a.localeCompare(b, 'en', { numeric: true });
... });
[ 'foo12', 'foo3' ]

This is from the Chrome console:

var a = 'foo12';
undefined
var b = 'foo3';
undefined
var s = [a,b]
undefined
s.sort(function(a,b) {return a.localeCompare(b, 'en', {numeric:true});})
["foo3", "foo12"]

I.e., the numeric: true option for natural sorting seems to be a no-op in my setup for node.

Is there a way to get node to behave better in this situation, or an explanation as to why it does not?

bcr
  • 1,328
  • 11
  • 27

1 Answers1

2

This is the best sort-of-answer I've found so far: https://github.com/joyent/node/issues/7676

TL;DR v8 doesn't concern itself with supporting localeCompare fully, but chrome uses v8-i18n to support this. Node is in the process of figuring out how to incorporate full support into Node.

bcr
  • 1,328
  • 11
  • 27