From 8a29370532561b7f7141c333f8a7052340308add Mon Sep 17 00:00:00 2001 From: Adam Stankiewicz Date: Tue, 20 Mar 2018 16:00:37 +0100 Subject: [PATCH] Add docs about loose option --- README.md | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 599c5a2..269ab3e 100644 --- a/README.md +++ b/README.md @@ -43,7 +43,7 @@ Output will be: Output is always sorted in quality order from highest -> lowest. as per the http spec, omitting the quality value implies 1.0. -#### parser.pick(supportedLangugagesArray, acceptLanguageHeader) +#### parser.pick(supportedLangugagesArray, acceptLanguageHeader, options = {}) *Alias*: parser.pick(supportedLanguagesArray, parsedAcceptLanguageHeader) @@ -61,7 +61,22 @@ Output will be: "fr-CA" ``` -__Running tests__ +The `options` currently supports only `loose` option that allows partial matching on supported languages. For example: + + +``` +parser.pick(['fr', 'en'], 'en-GB,en-US;q=0.9,fr-CA;q=0.7,en;q=0.8'); +``` + +Would return: + +``` +"fr" +``` + +In loose mode the order of `supportedLanguagesArray` matters, as it is the first partially matching language that is returned. It means that if you want to pick more specific langauge first, you should list it first as well, for example: `['fr-CA', 'fr']`. + +### Running test ``` npm install npm test