resolve-accept-language 3.1.11 → 3.1.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/{lib → dist}/cjs/directives.js +1 -1
- package/dist/cjs/index.js +1 -0
- package/{lib → dist}/cjs/locales.js +1 -1
- package/{lib → dist}/esm/directives.js +1 -1
- package/dist/esm/index.js +1 -0
- package/{lib → dist}/esm/locales.js +1 -1
- package/package.json +33 -38
- package/lib/cjs/index.js +0 -1
- package/lib/esm/index.js +0 -1
- /package/{lib → dist}/cjs/directives.d.ts +0 -0
- /package/{lib → dist}/cjs/index.d.ts +0 -0
- /package/{lib → dist}/cjs/locales.d.ts +0 -0
- /package/{lib → dist}/cjs/package.json +0 -0
- /package/{lib → dist}/esm/directives.d.ts +0 -0
- /package/{lib → dist}/esm/index.d.ts +0 -0
- /package/{lib → dist}/esm/locales.d.ts +0 -0
package/LICENSE
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var __assign=this&&this.__assign||function(){return __assign=Object.assign||function(e){for(var r,t=1,a=arguments.length;t<a;t++)for(var i in r=arguments[t])Object.prototype.hasOwnProperty.call(r,i)&&(e[i]=r[i]);return e},__assign.apply(this,arguments)},__read=this&&this.__read||function(e,r){var t="function"==typeof Symbol&&e[Symbol.iterator];if(!t)return e;var a,i,n=t.call(e),o=[];try{for(;(void 0===r||r-- >0)&&!(a=n.next()).done;)o.push(a.value)}catch(e){i={error:e}}finally{try{a&&!a.done&&(t=n.return)&&t.call(n)}finally{if(i)throw i.error}}return o},__spreadArray=this&&this.__spreadArray||function(e,r,t){if(t||2===arguments.length)for(var a,i=0,n=r.length;i<n;i++)!a&&i in r||(a||(a=Array.prototype.slice.call(r,0,i)),a[i]=r[i]);return e.concat(a||Array.prototype.slice.call(r))};Object.defineProperty(exports,"__esModule",{value:!0}),exports.getDirectives=void 0;var getDirective=function(e){var r=e.match(/^(([a-z]{2})(-([a-z]{2}|419))?)(;q=((1(\.0{0,3})?)|(0(\.\d{0,3})?)))?$/i);if(r){var t=r[2],a=r[4],i=r[6],n=t.toLowerCase(),o=a?a.toUpperCase():void 0;if("419"!==o||"es"===n){var s=void 0===i?1:Number(i);return{languageCode:n,countryCode:o,locale:o?"".concat(n,"-").concat(o):void 0,quality:s}}}},getDirectives=function(e){var r=[],t=0;e.split(",").forEach(
|
|
1
|
+
"use strict";var __assign=this&&this.__assign||function(){return __assign=Object.assign||function(e){for(var r,t=1,a=arguments.length;t<a;t++)for(var i in r=arguments[t])Object.prototype.hasOwnProperty.call(r,i)&&(e[i]=r[i]);return e},__assign.apply(this,arguments)},__read=this&&this.__read||function(e,r){var t="function"==typeof Symbol&&e[Symbol.iterator];if(!t)return e;var a,i,n=t.call(e),o=[];try{for(;(void 0===r||r-- >0)&&!(a=n.next()).done;)o.push(a.value)}catch(e){i={error:e}}finally{try{a&&!a.done&&(t=n.return)&&t.call(n)}finally{if(i)throw i.error}}return o},__spreadArray=this&&this.__spreadArray||function(e,r,t){if(t||2===arguments.length)for(var a,i=0,n=r.length;i<n;i++)!a&&i in r||(a||(a=Array.prototype.slice.call(r,0,i)),a[i]=r[i]);return e.concat(a||Array.prototype.slice.call(r))};Object.defineProperty(exports,"__esModule",{value:!0}),exports.getDirectives=void 0;var getDirective=function(e){var r=e.match(/^(([a-z]{2})(-([a-z]{2}|419))?)(;q=((1(\.0{0,3})?)|(0(\.\d{0,3})?)))?$/i);if(r){var t=r[2],a=r[4],i=r[6],n=t.toLowerCase(),o=a?a.toUpperCase():void 0;if("419"!==o||"es"===n){var s=void 0===i?1:Number(i);return{languageCode:n,countryCode:o,locale:o?"".concat(n,"-").concat(o):void 0,quality:s}}}},getDirectives=function(e){var r=[],t=0;e.split(",").forEach(function(e){var a=getDirective(e.trim());a&&(r.some(function(e){return e.languageCode===a.languageCode&&e.locale===a.locale})||(r.push(__assign(__assign({},a),{headerPosition:t})),t++))});var a=r.findIndex(function(e){return"es-419"===e.locale});if(-1!==a){var i=r[a],n=["es-AR","es-CL","es-CO","es-CR","es-HN","es-MX","es-PE","es-US","es-UY","es-VE"].map(function(e){return __assign(__assign({},i),{locale:e})});r.splice.apply(r,__spreadArray([a,1],__read(n),!1))}return r.sort(function(e,r){var t=r.quality-e.quality;return t||e.headerPosition-r.headerPosition})};exports.getDirectives=getDirectives;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var __read=this&&this.__read||function(e,r){var a="function"==typeof Symbol&&e[Symbol.iterator];if(!a)return e;var t,o,l=a.call(e),n=[];try{for(;(void 0===r||r-- >0)&&!(t=l.next()).done;)n.push(t.value)}catch(e){o={error:e}}finally{try{t&&!t.done&&(a=l.return)&&a.call(l)}finally{if(o)throw o.error}}return n},__spreadArray=this&&this.__spreadArray||function(e,r,a){if(a||2===arguments.length)for(var t,o=0,l=r.length;o<l;o++)!t&&o in r||(t||(t=Array.prototype.slice.call(r,0,o)),t[o]=r[o]);return e.concat(t||Array.prototype.slice.call(r))},__values=this&&this.__values||function(e){var r="function"==typeof Symbol&&Symbol.iterator,a=r&&e[r],t=0;if(a)return a.call(e);if(e&&"number"==typeof e.length)return{next:function(){return e&&t>=e.length&&(e=void 0),{value:e&&e[t++],done:!e}}};throw new TypeError(r?"Object is not iterable.":"Symbol.iterator is not defined.")};Object.defineProperty(exports,"__esModule",{value:!0}),exports.resolveAcceptLanguage=exports.MATCH_TYPES=void 0;var directives_1=require("./directives"),locales_1=require("./locales");exports.MATCH_TYPES={locale:"locale",languageSpecificLocale:"languageSpecificLocale",language:"language",relatedLocale:"relatedLocale",languageCountry:"languageCountry",country:"country",defaultLocale:"defaultLocale"};var resolveAcceptLanguage=function(e,r,a,t){if(r.forEach(function(e){if(!(0,locales_1.isLocale)(e,!1))throw new Error("Invalid locale identifier '".concat(e,"'. A valid locale should follow the BCP 47 'language-country' format."))}),!(0,locales_1.isLocale)(a,!1))throw new Error("Invalid default locale identifier '".concat(a,"'. A valid locale should follow the BCP 47 'language-country' format."));if(!r.some(function(e){return e.toLowerCase()===a.toLowerCase()}))throw new Error("The default locale '".concat(a,"' must be included in the locales array because it is used as a fallback when no match is found."));var o=new locales_1.Locale(a),l=new Set(__spreadArray([o.identifier],__read(r.map(function(e){return new locales_1.Locale(e).identifier})),!1)),n=function(){var r,a,n,c,i,u,f,d,s,y,v,h,g=new locales_1.LocaleList(l),_=(0,directives_1.getDirectives)(e),p=_.filter(function(e){return g.languages.has(e.languageCode)}),C=function(e){var r,a,t=e.locale,o=e.languageCode;if(void 0!==t)return g.locales.has(t)?{value:{match:t,matchType:exports.MATCH_TYPES.locale}}:"continue";var l=_.find(function(e){return e.languageCode===o&&void 0!==e.locale&&g.locales.has(e.locale)});if(l)return{value:{match:l.locale,matchType:exports.MATCH_TYPES.languageSpecificLocale}};try{for(var n=(r=void 0,__values(g.objects)),c=n.next();!c.done;c=n.next()){var i=c.value;if(i.languageCode===o)return{value:{match:i.identifier,matchType:exports.MATCH_TYPES.language}}}}catch(e){r={error:e}}finally{try{c&&!c.done&&(a=n.return)&&a.call(n)}finally{if(r)throw r.error}}};try{for(var m=__values(p),x=m.next();!x.done;x=m.next()){var T=C(A=x.value);if("object"==typeof T)return T.value}}catch(e){r={error:e}}finally{try{x&&!x.done&&(a=m.return)&&a.call(m)}finally{if(r)throw r.error}}try{for(var w=__values(p),L=w.next();!L.done;L=w.next()){var A=L.value;try{for(var S=(i=void 0,__values(g.objects)),b=S.next();!b.done;b=S.next()){if((B=b.value).languageCode===A.languageCode)return{match:B.identifier,matchType:exports.MATCH_TYPES.relatedLocale}}}catch(e){i={error:e}}finally{try{b&&!b.done&&(u=S.return)&&u.call(S)}finally{if(i)throw i.error}}}}catch(e){n={error:e}}finally{try{L&&!L.done&&(c=w.return)&&c.call(w)}finally{if(n)throw n.error}}var E=g.objects.filter(function(e){return e.languageCode===o.languageCode&&e.identifier!==o.identifier}).map(function(e){return e.countryCode});if(E.length>0)try{for(var P=__values(_),M=P.next();!M.done;M=P.next()){if(void 0!==(A=M.value).locale&&void 0!==A.countryCode&&E.includes(A.countryCode))return{match:"".concat(o.languageCode,"-").concat(A.countryCode),matchType:exports.MATCH_TYPES.languageCountry}}}catch(e){f={error:e}}finally{try{M&&!M.done&&(d=P.return)&&d.call(P)}finally{if(f)throw f.error}}if(null==t?void 0:t.matchCountry)try{for(var H=__values(_),Y=H.next();!Y.done;Y=H.next()){A=Y.value;try{for(var j=(v=void 0,__values(g.objects)),q=j.next();!q.done;q=j.next()){var B;if((B=q.value).countryCode===A.countryCode)return{match:B.identifier,matchType:exports.MATCH_TYPES.country}}}catch(e){v={error:e}}finally{try{q&&!q.done&&(h=j.return)&&h.call(j)}finally{if(v)throw v.error}}}}catch(e){s={error:e}}finally{try{Y&&!Y.done&&(y=H.return)&&y.call(H)}finally{if(s)throw s.error}}return{match:o.identifier,matchType:exports.MATCH_TYPES.defaultLocale}}();return(null==t?void 0:t.returnMatchType)?n:n.match};exports.resolveAcceptLanguage=resolveAcceptLanguage;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var __read=this&&this.__read||function(e,o){var t="function"==typeof Symbol&&e[Symbol.iterator];if(!t)return e;var a,r,i=t.call(e),s=[];try{for(;(void 0===o||o-- >0)&&!(a=i.next()).done;)s.push(a.value)}catch(e){r={error:e}}finally{try{a&&!a.done&&(t=i.return)&&t.call(i)}finally{if(r)throw r.error}}return s};Object.defineProperty(exports,"__esModule",{value:!0}),exports.isLocale=exports.LocaleList=exports.Locale=void 0;var Locale=function(e){if(!(0,exports.isLocale)(e,!1))throw new Error("invalid locale identifier '".concat(e,"'"));var o=__read(e.split("-"),2),t=o[0],a=o[1];this.languageCode=t.toLowerCase(),this.countryCode=a.toUpperCase(),this.identifier="".concat(this.languageCode,"-").concat(this.countryCode)};exports.Locale=Locale;var LocaleList=function(e){var o=this;this.languages=new Set,this.countries=new Set,this.locales=new Set,this.objects=[],e.forEach(
|
|
1
|
+
"use strict";var __read=this&&this.__read||function(e,o){var t="function"==typeof Symbol&&e[Symbol.iterator];if(!t)return e;var a,r,i=t.call(e),s=[];try{for(;(void 0===o||o-- >0)&&!(a=i.next()).done;)s.push(a.value)}catch(e){r={error:e}}finally{try{a&&!a.done&&(t=i.return)&&t.call(i)}finally{if(r)throw r.error}}return s};Object.defineProperty(exports,"__esModule",{value:!0}),exports.isLocale=exports.LocaleList=exports.Locale=void 0;var Locale=function(e){if(!(0,exports.isLocale)(e,!1))throw new Error("invalid locale identifier '".concat(e,"'"));var o=__read(e.split("-"),2),t=o[0],a=o[1];this.languageCode=t.toLowerCase(),this.countryCode=a.toUpperCase(),this.identifier="".concat(this.languageCode,"-").concat(this.countryCode)};exports.Locale=Locale;var LocaleList=function(e){var o=this;this.languages=new Set,this.countries=new Set,this.locales=new Set,this.objects=[],e.forEach(function(e){var t=new Locale(e);o.objects.push(t),o.locales.add(t.identifier),o.languages.add(t.languageCode),o.countries.add(t.countryCode)})};exports.LocaleList=LocaleList;var isLocale=function(e,o){return void 0===o&&(o=!0),new RegExp("^[a-z]{2}-[A-Z]{2}$",o?"":"i").test(e)};exports.isLocale=isLocale;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var __assign=this&&this.__assign||function(){return __assign=Object.assign||function(r){for(var e,a=1,t=arguments.length;a<t;a++)for(var n in e=arguments[a])Object.prototype.hasOwnProperty.call(e,n)&&(r[n]=e[n]);return r},__assign.apply(this,arguments)},__read=this&&this.__read||function(r,e){var a="function"==typeof Symbol&&r[Symbol.iterator];if(!a)return r;var t,n,i=a.call(r),o=[];try{for(;(void 0===e||e-- >0)&&!(t=i.next()).done;)o.push(t.value)}catch(r){n={error:r}}finally{try{t&&!t.done&&(a=i.return)&&a.call(i)}finally{if(n)throw n.error}}return o},__spreadArray=this&&this.__spreadArray||function(r,e,a){if(a||2===arguments.length)for(var t,n=0,i=e.length;n<i;n++)!t&&n in e||(t||(t=Array.prototype.slice.call(e,0,n)),t[n]=e[n]);return r.concat(t||Array.prototype.slice.call(e))},getDirective=function(r){var e=r.match(/^(([a-z]{2})(-([a-z]{2}|419))?)(;q=((1(\.0{0,3})?)|(0(\.\d{0,3})?)))?$/i);if(e){var a=e[2],t=e[4],n=e[6],i=a.toLowerCase(),o=t?t.toUpperCase():void 0;if("419"!==o||"es"===i){var s=void 0===n?1:Number(n);return{languageCode:i,countryCode:o,locale:o?"".concat(i,"-").concat(o):void 0,quality:s}}}};export var getDirectives=function(r){var e=[],a=0;r.split(",").forEach(
|
|
1
|
+
var __assign=this&&this.__assign||function(){return __assign=Object.assign||function(r){for(var e,a=1,t=arguments.length;a<t;a++)for(var n in e=arguments[a])Object.prototype.hasOwnProperty.call(e,n)&&(r[n]=e[n]);return r},__assign.apply(this,arguments)},__read=this&&this.__read||function(r,e){var a="function"==typeof Symbol&&r[Symbol.iterator];if(!a)return r;var t,n,i=a.call(r),o=[];try{for(;(void 0===e||e-- >0)&&!(t=i.next()).done;)o.push(t.value)}catch(r){n={error:r}}finally{try{t&&!t.done&&(a=i.return)&&a.call(i)}finally{if(n)throw n.error}}return o},__spreadArray=this&&this.__spreadArray||function(r,e,a){if(a||2===arguments.length)for(var t,n=0,i=e.length;n<i;n++)!t&&n in e||(t||(t=Array.prototype.slice.call(e,0,n)),t[n]=e[n]);return r.concat(t||Array.prototype.slice.call(e))},getDirective=function(r){var e=r.match(/^(([a-z]{2})(-([a-z]{2}|419))?)(;q=((1(\.0{0,3})?)|(0(\.\d{0,3})?)))?$/i);if(e){var a=e[2],t=e[4],n=e[6],i=a.toLowerCase(),o=t?t.toUpperCase():void 0;if("419"!==o||"es"===i){var s=void 0===n?1:Number(n);return{languageCode:i,countryCode:o,locale:o?"".concat(i,"-").concat(o):void 0,quality:s}}}};export var getDirectives=function(r){var e=[],a=0;r.split(",").forEach(function(r){var t=getDirective(r.trim());t&&(e.some(function(r){return r.languageCode===t.languageCode&&r.locale===t.locale})||(e.push(__assign(__assign({},t),{headerPosition:a})),a++))});var t=e.findIndex(function(r){return"es-419"===r.locale});if(-1!==t){var n=e[t],i=["es-AR","es-CL","es-CO","es-CR","es-HN","es-MX","es-PE","es-US","es-UY","es-VE"].map(function(r){return __assign(__assign({},n),{locale:r})});e.splice.apply(e,__spreadArray([t,1],__read(i),!1))}return e.sort(function(r,e){var a=e.quality-r.quality;return a||r.headerPosition-e.headerPosition})};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var __read=this&&this.__read||function(e,r){var a="function"==typeof Symbol&&e[Symbol.iterator];if(!a)return e;var t,o,n=a.call(e),l=[];try{for(;(void 0===r||r-- >0)&&!(t=n.next()).done;)l.push(t.value)}catch(e){o={error:e}}finally{try{t&&!t.done&&(a=n.return)&&a.call(n)}finally{if(o)throw o.error}}return l},__spreadArray=this&&this.__spreadArray||function(e,r,a){if(a||2===arguments.length)for(var t,o=0,n=r.length;o<n;o++)!t&&o in r||(t||(t=Array.prototype.slice.call(r,0,o)),t[o]=r[o]);return e.concat(t||Array.prototype.slice.call(r))},__values=this&&this.__values||function(e){var r="function"==typeof Symbol&&Symbol.iterator,a=r&&e[r],t=0;if(a)return a.call(e);if(e&&"number"==typeof e.length)return{next:function(){return e&&t>=e.length&&(e=void 0),{value:e&&e[t++],done:!e}}};throw new TypeError(r?"Object is not iterable.":"Symbol.iterator is not defined.")};import{getDirectives}from"./directives.js";import{Locale,LocaleList,isLocale}from"./locales.js";export var MATCH_TYPES={locale:"locale",languageSpecificLocale:"languageSpecificLocale",language:"language",relatedLocale:"relatedLocale",languageCountry:"languageCountry",country:"country",defaultLocale:"defaultLocale"};export var resolveAcceptLanguage=function(e,r,a,t){if(r.forEach(function(e){if(!isLocale(e,!1))throw new Error("Invalid locale identifier '".concat(e,"'. A valid locale should follow the BCP 47 'language-country' format."))}),!isLocale(a,!1))throw new Error("Invalid default locale identifier '".concat(a,"'. A valid locale should follow the BCP 47 'language-country' format."));if(!r.some(function(e){return e.toLowerCase()===a.toLowerCase()}))throw new Error("The default locale '".concat(a,"' must be included in the locales array because it is used as a fallback when no match is found."));var o=new Locale(a),n=new Set(__spreadArray([o.identifier],__read(r.map(function(e){return new Locale(e).identifier})),!1)),l=function(){var r,a,l,i,c,u,f,d,y,v,h,s,g=new LocaleList(n),_=getDirectives(e),m=_.filter(function(e){return g.languages.has(e.languageCode)}),p=function(e){var r,a,t=e.locale,o=e.languageCode;if(void 0!==t)return g.locales.has(t)?{value:{match:t,matchType:MATCH_TYPES.locale}}:"continue";var n=_.find(function(e){return e.languageCode===o&&void 0!==e.locale&&g.locales.has(e.locale)});if(n)return{value:{match:n.locale,matchType:MATCH_TYPES.languageSpecificLocale}};try{for(var l=(r=void 0,__values(g.objects)),i=l.next();!i.done;i=l.next()){var c=i.value;if(c.languageCode===o)return{value:{match:c.identifier,matchType:MATCH_TYPES.language}}}}catch(e){r={error:e}}finally{try{i&&!i.done&&(a=l.return)&&a.call(l)}finally{if(r)throw r.error}}};try{for(var C=__values(m),T=C.next();!T.done;T=C.next()){var w=p(S=T.value);if("object"==typeof w)return w.value}}catch(e){r={error:e}}finally{try{T&&!T.done&&(a=C.return)&&a.call(C)}finally{if(r)throw r.error}}try{for(var L=__values(m),x=L.next();!x.done;x=L.next()){var S=x.value;try{for(var b=(c=void 0,__values(g.objects)),A=b.next();!A.done;A=b.next()){if((D=A.value).languageCode===S.languageCode)return{match:D.identifier,matchType:MATCH_TYPES.relatedLocale}}}catch(e){c={error:e}}finally{try{A&&!A.done&&(u=b.return)&&u.call(b)}finally{if(c)throw c.error}}}}catch(e){l={error:e}}finally{try{x&&!x.done&&(i=L.return)&&i.call(L)}finally{if(l)throw l.error}}var E=g.objects.filter(function(e){return e.languageCode===o.languageCode&&e.identifier!==o.identifier}).map(function(e){return e.countryCode});if(E.length>0)try{for(var P=__values(_),M=P.next();!M.done;M=P.next()){if(void 0!==(S=M.value).locale&&void 0!==S.countryCode&&E.includes(S.countryCode))return{match:"".concat(o.languageCode,"-").concat(S.countryCode),matchType:MATCH_TYPES.languageCountry}}}catch(e){f={error:e}}finally{try{M&&!M.done&&(d=P.return)&&d.call(P)}finally{if(f)throw f.error}}if(null==t?void 0:t.matchCountry)try{for(var j=__values(_),H=j.next();!H.done;H=j.next()){S=H.value;try{for(var Y=(h=void 0,__values(g.objects)),B=Y.next();!B.done;B=Y.next()){var D;if((D=B.value).countryCode===S.countryCode)return{match:D.identifier,matchType:MATCH_TYPES.country}}}catch(e){h={error:e}}finally{try{B&&!B.done&&(s=Y.return)&&s.call(Y)}finally{if(h)throw h.error}}}}catch(e){y={error:e}}finally{try{H&&!H.done&&(v=j.return)&&v.call(j)}finally{if(y)throw y.error}}return{match:o.identifier,matchType:MATCH_TYPES.defaultLocale}}();return(null==t?void 0:t.returnMatchType)?l:l.match};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var __read=this&&this.__read||function(e,t){var o="function"==typeof Symbol&&e[Symbol.iterator];if(!o)return e;var a,r,i=o.call(e),n=[];try{for(;(void 0===t||t-- >0)&&!(a=i.next()).done;)n.push(a.value)}catch(e){r={error:e}}finally{try{a&&!a.done&&(o=i.return)&&o.call(i)}finally{if(r)throw r.error}}return n},Locale=function(e){if(!isLocale(e,!1))throw new Error("invalid locale identifier '".concat(e,"'"));var t=__read(e.split("-"),2),o=t[0],a=t[1];this.languageCode=o.toLowerCase(),this.countryCode=a.toUpperCase(),this.identifier="".concat(this.languageCode,"-").concat(this.countryCode)};export{Locale};var LocaleList=function(e){var t=this;this.languages=new Set,this.countries=new Set,this.locales=new Set,this.objects=[],e.forEach(
|
|
1
|
+
var __read=this&&this.__read||function(e,t){var o="function"==typeof Symbol&&e[Symbol.iterator];if(!o)return e;var a,r,i=o.call(e),n=[];try{for(;(void 0===t||t-- >0)&&!(a=i.next()).done;)n.push(a.value)}catch(e){r={error:e}}finally{try{a&&!a.done&&(o=i.return)&&o.call(i)}finally{if(r)throw r.error}}return n},Locale=function(e){if(!isLocale(e,!1))throw new Error("invalid locale identifier '".concat(e,"'"));var t=__read(e.split("-"),2),o=t[0],a=t[1];this.languageCode=o.toLowerCase(),this.countryCode=a.toUpperCase(),this.identifier="".concat(this.languageCode,"-").concat(this.countryCode)};export{Locale};var LocaleList=function(e){var t=this;this.languages=new Set,this.countries=new Set,this.locales=new Set,this.objects=[],e.forEach(function(e){var o=new Locale(e);t.objects.push(o),t.locales.add(o.identifier),t.languages.add(o.languageCode),t.countries.add(o.countryCode)})};export{LocaleList};export var isLocale=function(e,t){return void 0===t&&(t=!0),new RegExp("^[a-z]{2}-[A-Z]{2}$",t?"":"i").test(e)};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "resolve-accept-language",
|
|
3
|
-
"version": "3.1.
|
|
3
|
+
"version": "3.1.12",
|
|
4
4
|
"description": "Resolve the preferred locale based on the value of an `Accept-Language` HTTP header.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"accept-language",
|
|
@@ -26,23 +26,23 @@
|
|
|
26
26
|
"exports": {
|
|
27
27
|
".": {
|
|
28
28
|
"import": {
|
|
29
|
-
"types": "./
|
|
30
|
-
"default": "./
|
|
29
|
+
"types": "./dist/esm/index.d.ts",
|
|
30
|
+
"default": "./dist/esm/index.js"
|
|
31
31
|
},
|
|
32
32
|
"require": {
|
|
33
|
-
"types": "./
|
|
34
|
-
"default": "./
|
|
33
|
+
"types": "./dist/cjs/index.d.ts",
|
|
34
|
+
"default": "./dist/cjs/index.js"
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
37
|
},
|
|
38
|
-
"main": "
|
|
39
|
-
"module": "
|
|
40
|
-
"types": "
|
|
38
|
+
"main": "dist/cjs/index.js",
|
|
39
|
+
"module": "dist/esm/index.js",
|
|
40
|
+
"types": "dist/esm/index.d.ts",
|
|
41
41
|
"files": [
|
|
42
|
-
"
|
|
42
|
+
"dist"
|
|
43
43
|
],
|
|
44
44
|
"scripts": {
|
|
45
|
-
"build": "npm run check-nvm-node-version && npm run prettier-write && npm run eslint-fix && rm -Rf ./
|
|
45
|
+
"build": "npm run check-nvm-node-version && npm run prettier-write && npm run eslint-fix && rm -Rf ./dist && tsc -p tsconfig.cjs.json && tsc -p tsconfig.esm.json && echo '{ \"type\": \"commonjs\" }' > dist/cjs/package.json && tsc -p src/build-scripts/tsconfig.json && node dist/build-scripts/build.js && npm run test",
|
|
46
46
|
"check-nvm-node-version": "check-node-version --node $(node -p \"'>=' + require('fs').readFileSync('.nvmrc', 'utf-8').trim()\")",
|
|
47
47
|
"depcheck": "depcheck",
|
|
48
48
|
"eslint-fix": "eslint --fix",
|
|
@@ -50,42 +50,37 @@
|
|
|
50
50
|
"prettier-write": "prettier --write .",
|
|
51
51
|
"release": "dotenv -- release-it --only-version",
|
|
52
52
|
"test": "jest --coverage",
|
|
53
|
-
"test-node-version": "node -e \"var resolveAcceptLanguage = require('./
|
|
53
|
+
"test-node-version": "node -e \"var resolveAcceptLanguage = require('./dist/cjs/index.js').resolveAcceptLanguage; var result = resolveAcceptLanguage('fr-CA;q=0.01,en-CA;q=0.1,en-US;q=0.001', ['en-US', 'fr-CA'], 'en-US'); console.log(result === 'fr-CA' ? 'success' : 'failure');\""
|
|
54
54
|
},
|
|
55
55
|
"devDependencies": {
|
|
56
|
-
"@
|
|
57
|
-
"@
|
|
58
|
-
"@types/
|
|
59
|
-
"
|
|
60
|
-
"
|
|
61
|
-
"@typescript-eslint/parser": "8.27.0",
|
|
62
|
-
"check-node-version": "^4.2.1",
|
|
63
|
-
"depcheck": "^1.4.7",
|
|
56
|
+
"@release-it/conventional-changelog": "10.0.1",
|
|
57
|
+
"@types/jest": "30.0.0",
|
|
58
|
+
"@types/node": "24.0.15",
|
|
59
|
+
"check-node-version": "4.2.1",
|
|
60
|
+
"depcheck": "1.4.7",
|
|
64
61
|
"dotenv-cli": "8.0.0",
|
|
65
|
-
"eslint": "9.
|
|
66
|
-
"eslint-config-prettier": "10.1.
|
|
67
|
-
"eslint-import-resolver-
|
|
68
|
-
"eslint-import-resolver-typescript": "4.2.2",
|
|
62
|
+
"eslint": "9.31.0",
|
|
63
|
+
"eslint-config-prettier": "10.1.8",
|
|
64
|
+
"eslint-import-resolver-typescript": "4.4.4",
|
|
69
65
|
"eslint-plugin-compat": "^6.0.2",
|
|
70
|
-
"eslint-plugin-import-x": "
|
|
71
|
-
"eslint-plugin-jest": "
|
|
72
|
-
"eslint-plugin-
|
|
73
|
-
"eslint-plugin-json-files": "4.4.2",
|
|
66
|
+
"eslint-plugin-import-x": "4.16.1",
|
|
67
|
+
"eslint-plugin-jest": "29.0.1",
|
|
68
|
+
"eslint-plugin-json-files": "5.1.0",
|
|
74
69
|
"eslint-plugin-prefer-arrow-functions": "3.6.2",
|
|
75
|
-
"eslint-plugin-prettier": "5.
|
|
70
|
+
"eslint-plugin-prettier": "5.5.3",
|
|
76
71
|
"eslint-plugin-tsdoc": "0.4.0",
|
|
77
|
-
"eslint-plugin-unicorn": "
|
|
78
|
-
"
|
|
79
|
-
"
|
|
80
|
-
"
|
|
72
|
+
"eslint-plugin-unicorn": "60.0.0",
|
|
73
|
+
"husky": "9.1.7",
|
|
74
|
+
"jest": "30.0.4",
|
|
75
|
+
"jiti": "2.4.2",
|
|
81
76
|
"jsonc-eslint-parser": "2.4.0",
|
|
82
|
-
"prettier": "3.
|
|
77
|
+
"prettier": "3.6.2",
|
|
83
78
|
"prettier-plugin-organize-imports": "4.1.0",
|
|
84
|
-
"
|
|
85
|
-
"
|
|
86
|
-
"
|
|
87
|
-
"
|
|
88
|
-
"typescript": "
|
|
79
|
+
"release-it": "19.0.4",
|
|
80
|
+
"terser": "5.43.1",
|
|
81
|
+
"ts-jest": "29.4.0",
|
|
82
|
+
"typescript": "5.8.3",
|
|
83
|
+
"typescript-eslint": "8.38.0"
|
|
89
84
|
},
|
|
90
85
|
"engines": {
|
|
91
86
|
"node": ">=4.0.0"
|
package/lib/cjs/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";var __read=this&&this.__read||function(e,r){var a="function"==typeof Symbol&&e[Symbol.iterator];if(!a)return e;var t,o,n=a.call(e),l=[];try{for(;(void 0===r||r-- >0)&&!(t=n.next()).done;)l.push(t.value)}catch(e){o={error:e}}finally{try{t&&!t.done&&(a=n.return)&&a.call(n)}finally{if(o)throw o.error}}return l},__spreadArray=this&&this.__spreadArray||function(e,r,a){if(a||2===arguments.length)for(var t,o=0,n=r.length;o<n;o++)!t&&o in r||(t||(t=Array.prototype.slice.call(r,0,o)),t[o]=r[o]);return e.concat(t||Array.prototype.slice.call(r))},__values=this&&this.__values||function(e){var r="function"==typeof Symbol&&Symbol.iterator,a=r&&e[r],t=0;if(a)return a.call(e);if(e&&"number"==typeof e.length)return{next:function(){return e&&t>=e.length&&(e=void 0),{value:e&&e[t++],done:!e}}};throw new TypeError(r?"Object is not iterable.":"Symbol.iterator is not defined.")};Object.defineProperty(exports,"__esModule",{value:!0}),exports.resolveAcceptLanguage=exports.MATCH_TYPES=void 0;var directives_1=require("./directives"),locales_1=require("./locales");exports.MATCH_TYPES={locale:"locale",languageSpecificLocale:"languageSpecificLocale",language:"language",relatedLocale:"relatedLocale",languageCountry:"languageCountry",country:"country",defaultLocale:"defaultLocale"};var resolveAcceptLanguage=function(e,r,a,t){if(r.forEach((function(e){if(!(0,locales_1.isLocale)(e,!1))throw new Error("Invalid locale identifier '".concat(e,"'. A valid locale should follow the BCP 47 'language-country' format."))})),!(0,locales_1.isLocale)(a,!1))throw new Error("Invalid default locale identifier '".concat(a,"'. A valid locale should follow the BCP 47 'language-country' format."));if(!r.some((function(e){return e.toLowerCase()===a.toLowerCase()})))throw new Error("The default locale '".concat(a,"' must be included in the locales array because it is used as a fallback when no match is found."));var o=new locales_1.Locale(a),n=new Set(__spreadArray([o.identifier],__read(r.map((function(e){return new locales_1.Locale(e).identifier}))),!1)),l=function(){var r,a,l,c,i,u,f,d,s=new locales_1.LocaleList(n),v=(0,directives_1.getDirectives)(e),y=v.filter((function(e){return s.languages.has(e.languageCode)})),g=function(e){var r=e.locale,a=e.languageCode;if(void 0!==r)return s.locales.has(r)?{value:{match:r,matchType:exports.MATCH_TYPES.locale}}:"continue";var t=v.find((function(e){return e.languageCode===a&&void 0!==e.locale&&s.locales.has(e.locale)}));if(t)return{value:{match:t.locale,matchType:exports.MATCH_TYPES.languageSpecificLocale}};var o=s.objects.find((function(e){return e.languageCode===a}));return o?{value:{match:o.identifier,matchType:exports.MATCH_TYPES.language}}:void 0};try{for(var h=__values(y),p=h.next();!p.done;p=h.next()){var _=g(P=p.value);if("object"==typeof _)return _.value}}catch(e){r={error:e}}finally{try{p&&!p.done&&(a=h.return)&&a.call(h)}finally{if(r)throw r.error}}var C=function(e){var r=s.objects.find((function(r){return r.languageCode===e.languageCode}));if(r)return{value:{match:r.identifier,matchType:exports.MATCH_TYPES.relatedLocale}}};try{for(var m=__values(y),T=m.next();!T.done;T=m.next()){var w=C(P=T.value);if("object"==typeof w)return w.value}}catch(e){l={error:e}}finally{try{T&&!T.done&&(c=m.return)&&c.call(m)}finally{if(l)throw l.error}}var x=s.objects.filter((function(e){return e.languageCode===o.languageCode&&e.identifier!==o.identifier})).map((function(e){return e.countryCode}));if(x.length>0)try{for(var L=__values(v),A=L.next();!A.done;A=L.next()){if(void 0!==(P=A.value).locale&&void 0!==P.countryCode&&x.includes(P.countryCode))return{match:"".concat(o.languageCode,"-").concat(P.countryCode),matchType:exports.MATCH_TYPES.languageCountry}}}catch(e){i={error:e}}finally{try{A&&!A.done&&(u=L.return)&&u.call(L)}finally{if(i)throw i.error}}if(null==t?void 0:t.matchCountry){var b=function(e){var r=s.objects.find((function(r){return r.countryCode===e.countryCode}));if(r)return{value:{match:r.identifier,matchType:exports.MATCH_TYPES.country}}};try{for(var S=__values(v),E=S.next();!E.done;E=S.next()){var P,M=b(P=E.value);if("object"==typeof M)return M.value}}catch(e){f={error:e}}finally{try{E&&!E.done&&(d=S.return)&&d.call(S)}finally{if(f)throw f.error}}}return{match:o.identifier,matchType:exports.MATCH_TYPES.defaultLocale}}();return(null==t?void 0:t.returnMatchType)?l:l.match};exports.resolveAcceptLanguage=resolveAcceptLanguage;
|
package/lib/esm/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
var __read=this&&this.__read||function(e,r){var a="function"==typeof Symbol&&e[Symbol.iterator];if(!a)return e;var t,n,o=a.call(e),l=[];try{for(;(void 0===r||r-- >0)&&!(t=o.next()).done;)l.push(t.value)}catch(e){n={error:e}}finally{try{t&&!t.done&&(a=o.return)&&a.call(o)}finally{if(n)throw n.error}}return l},__spreadArray=this&&this.__spreadArray||function(e,r,a){if(a||2===arguments.length)for(var t,n=0,o=r.length;n<o;n++)!t&&n in r||(t||(t=Array.prototype.slice.call(r,0,n)),t[n]=r[n]);return e.concat(t||Array.prototype.slice.call(r))},__values=this&&this.__values||function(e){var r="function"==typeof Symbol&&Symbol.iterator,a=r&&e[r],t=0;if(a)return a.call(e);if(e&&"number"==typeof e.length)return{next:function(){return e&&t>=e.length&&(e=void 0),{value:e&&e[t++],done:!e}}};throw new TypeError(r?"Object is not iterable.":"Symbol.iterator is not defined.")};import{getDirectives}from"./directives.js";import{Locale,LocaleList,isLocale}from"./locales.js";export var MATCH_TYPES={locale:"locale",languageSpecificLocale:"languageSpecificLocale",language:"language",relatedLocale:"relatedLocale",languageCountry:"languageCountry",country:"country",defaultLocale:"defaultLocale"};export var resolveAcceptLanguage=function(e,r,a,t){if(r.forEach((function(e){if(!isLocale(e,!1))throw new Error("Invalid locale identifier '".concat(e,"'. A valid locale should follow the BCP 47 'language-country' format."))})),!isLocale(a,!1))throw new Error("Invalid default locale identifier '".concat(a,"'. A valid locale should follow the BCP 47 'language-country' format."));if(!r.some((function(e){return e.toLowerCase()===a.toLowerCase()})))throw new Error("The default locale '".concat(a,"' must be included in the locales array because it is used as a fallback when no match is found."));var n=new Locale(a),o=new Set(__spreadArray([n.identifier],__read(r.map((function(e){return new Locale(e).identifier}))),!1)),l=function(){var r,a,l,i,c,u,f,d,y=new LocaleList(o),v=getDirectives(e),h=v.filter((function(e){return y.languages.has(e.languageCode)})),s=function(e){var r=e.locale,a=e.languageCode;if(void 0!==r)return y.locales.has(r)?{value:{match:r,matchType:MATCH_TYPES.locale}}:"continue";var t=v.find((function(e){return e.languageCode===a&&void 0!==e.locale&&y.locales.has(e.locale)}));if(t)return{value:{match:t.locale,matchType:MATCH_TYPES.languageSpecificLocale}};var n=y.objects.find((function(e){return e.languageCode===a}));return n?{value:{match:n.identifier,matchType:MATCH_TYPES.language}}:void 0};try{for(var g=__values(h),m=g.next();!m.done;m=g.next()){var p=s(j=m.value);if("object"==typeof p)return p.value}}catch(e){r={error:e}}finally{try{m&&!m.done&&(a=g.return)&&a.call(g)}finally{if(r)throw r.error}}var _=function(e){var r=y.objects.find((function(r){return r.languageCode===e.languageCode}));if(r)return{value:{match:r.identifier,matchType:MATCH_TYPES.relatedLocale}}};try{for(var C=__values(h),T=C.next();!T.done;T=C.next()){var w=_(j=T.value);if("object"==typeof w)return w.value}}catch(e){l={error:e}}finally{try{T&&!T.done&&(i=C.return)&&i.call(C)}finally{if(l)throw l.error}}var L=y.objects.filter((function(e){return e.languageCode===n.languageCode&&e.identifier!==n.identifier})).map((function(e){return e.countryCode}));if(L.length>0)try{for(var b=__values(v),S=b.next();!S.done;S=b.next()){if(void 0!==(j=S.value).locale&&void 0!==j.countryCode&&L.includes(j.countryCode))return{match:"".concat(n.languageCode,"-").concat(j.countryCode),matchType:MATCH_TYPES.languageCountry}}}catch(e){c={error:e}}finally{try{S&&!S.done&&(u=b.return)&&u.call(b)}finally{if(c)throw c.error}}if(null==t?void 0:t.matchCountry){var A=function(e){var r=y.objects.find((function(r){return r.countryCode===e.countryCode}));if(r)return{value:{match:r.identifier,matchType:MATCH_TYPES.country}}};try{for(var E=__values(v),x=E.next();!x.done;x=E.next()){var j,P=A(j=x.value);if("object"==typeof P)return P.value}}catch(e){f={error:e}}finally{try{x&&!x.done&&(d=E.return)&&d.call(E)}finally{if(f)throw f.error}}}return{match:n.identifier,matchType:MATCH_TYPES.defaultLocale}}();return(null==t?void 0:t.returnMatchType)?l:l.match};
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|