Parses the Accept-Language
header's value in an array of language directives.
const acceptLanguageValue = 'pt-BR, en;q=0.9, fr;q=0.8, it;q=0.7, *;q=0.5'
getPreferredLanguages(acceptLanguageValue)
/* will output:
[
{ quality: 1, locale: 'pt-BR' },
{ quality: 0.9, locale: 'en' },
{ quality: 0.8, locale: 'fr' },
{ quality: 0.7, locale: 'it' },
{ quality: 0.5, locale: '*' }
]
*/
// by default, returns a wildcard language if no value has been provided
getPreferredLanguages() // outputs [ { quality: 1, locale: '*' } ]
MIT