tinganho / node-accept-language

BCP47 language negotiation
MIT License
85 stars 15 forks source link

Using a stable sort to keep order when equals #22

Closed micky2be closed 7 years ago

micky2be commented 7 years ago

The sort method in not stable and doesn't always keep the original order of the list pass to it. To fix that and to keep an order of priority (with equals values of q) I introduced stable as a dependency.

Extreme use case:

var acceptLanguage = require("accept-language")
acceptLanguage.languages(['en', 'ja', 'ko', 'zh-CN', 'zh-TW', 'de', 'es', 'fr', 'it']);
var lang = acceptLanguage.get('en, ja, ne, zh, zh-TW, zh-CN, af, sq, am, ar, an');
// lang === 'zh-CN'
tinganho commented 7 years ago

Could you explain the problem?

Is it that it picks zh-CN above and not for instance en that is first in the list.

Your changes introduces some failed tests.

micky2be commented 7 years ago

Yes, I believe it should go for en and not zh-CN.

What tests are failing? I run npm test on my local with success. And Travis seems happy too.

tinganho commented 7 years ago

@micky2be Thanks.