resolve-accept-language 3.2.0 → 3.2.1

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/README.md CHANGED
@@ -2,8 +2,8 @@
2
2
 
3
3
  [![License](https://img.shields.io/npm/l/make-coverage-badge.svg?color=brightgreen)](https://opensource.org/licenses/MIT)
4
4
  [![Download Stats](https://img.shields.io/npm/dw/resolve-accept-language.svg?color=brightgreen)](https://www.npmjs.com/package/resolve-accept-language)
5
- ![Coverage](https://img.shields.io/badge/Coverage-100%25-brightgreen.svg)
6
- [![Package Size](https://deno.bundlejs.com/badge?q=resolve-accept-language@latest&treeshake=[*])](https://bundlejs.com/?q=resolve-accept-language@latest&treeshake=[*])
5
+ ![Coverage](https://img.shields.io/badge/coverage-100%25-brightgreen.svg)
6
+ ![Package Size](https://img.shields.io/badge/min%2Bgzip-2.8%20kB-brightgreen)
7
7
  ![Dependencies](https://img.shields.io/badge/dependencies-0-brightgreen.svg)
8
8
 
9
9
  Resolve the best locale based on the value of an `Accept-Language` HTTP header.
@@ -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 REGEX_DIRECTIVE=/^(([a-z]{2})(-([a-z]{2}|419))?)(;q=((1(\.0{0,3})?)|(0(\.\d{0,3})?)))?$/i,getDirective=function(e){var r=e.match(REGEX_DIRECTIVE);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.map(function(e){return e.locale}).indexOf("es-419");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;
1
+ "use strict";function _array_like_to_array(e,r){(null==r||r>e.length)&&(r=e.length);for(var t=0,a=new Array(r);t<r;t++)a[t]=e[t];return a}function _array_without_holes(e){if(Array.isArray(e))return _array_like_to_array(e)}function _iterable_to_array(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}function _non_iterable_spread(){throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function _to_consumable_array(e){return _array_without_holes(e)||_iterable_to_array(e)||_unsupported_iterable_to_array(e)||_non_iterable_spread()}function _unsupported_iterable_to_array(e,r){if(e){if("string"==typeof e)return _array_like_to_array(e,r);var t=Object.prototype.toString.call(e).slice(8,-1);return"Object"===t&&e.constructor&&(t=e.constructor.name),"Map"===t||"Set"===t?Array.from(t):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?_array_like_to_array(e,r):void 0}}Object.defineProperty(exports,"__esModule",{value:!0}),Object.defineProperty(exports,"getDirectives",{enumerable:!0,get:function(){return getDirectives}});var REGEX_DIRECTIVE=/^(([a-z]{2})(-([a-z]{2}|419))?)(;q=((1(\.0{0,3})?)|(0(\.\d{0,3})?)))?$/i,getDirective=function(e){var r=e.match(REGEX_DIRECTIVE);if(r){var t=r[2],a=r[4],o=r[6],n=t.toLowerCase(),i=a?a.toUpperCase():void 0;if("419"!==i||"es"===n){var s=void 0===o?1:Number(o);return{languageCode:n,countryCode:i,locale:i?"".concat(n,"-").concat(i):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(Object.assign(Object.assign({},a),{headerPosition:t})),t++))});var a=r.map(function(e){return e.locale}).indexOf("es-419");if(-1!==a){var o,n=r[a],i=["es-AR","es-CL","es-CO","es-CR","es-HN","es-MX","es-PE","es-US","es-UY","es-VE"].map(function(e){return Object.assign(Object.assign({},n),{locale:e})});(o=r).splice.apply(o,[a,1].concat(_to_consumable_array(i)))}return r.sort(function(e,r){var t=r.quality-e.quality;return t||e.headerPosition-r.headerPosition})};
package/dist/cjs/index.js CHANGED
@@ -1 +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=__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,_,p,C,x=new locales_1.LocaleList(l),m=(0,directives_1.getDirectives)(e),T=m.filter(function(e){return e.languageCode in x.languages});try{for(var w=__values(T),L=w.next();!L.done;L=w.next()){var A=(q=L.value).locale,S=q.languageCode;if(void 0===A){try{for(var b=(n=void 0,__values(m)),E=b.next();!E.done;E=b.next()){var P=E.value;if(P.languageCode===S&&void 0!==P.locale&&P.locale in x.locales)return{match:P.locale,matchType:exports.MATCH_TYPES.languageSpecificLocale}}}catch(e){n={error:e}}finally{try{E&&!E.done&&(c=b.return)&&c.call(b)}finally{if(n)throw n.error}}try{for(var M=(i=void 0,__values(x.objects)),H=M.next();!H.done;H=M.next()){var Y=H.value;if(Y.languageCode===S)return{match:Y.identifier,matchType:exports.MATCH_TYPES.language}}}catch(e){i={error:e}}finally{try{H&&!H.done&&(u=M.return)&&u.call(M)}finally{if(i)throw i.error}}}else if(A in x.locales)return{match:A,matchType:exports.MATCH_TYPES.locale}}}catch(e){r={error:e}}finally{try{L&&!L.done&&(a=w.return)&&a.call(w)}finally{if(r)throw r.error}}try{for(var j=__values(T),O=j.next();!O.done;O=j.next()){var q=O.value;try{for(var B=(s=void 0,__values(x.objects)),I=B.next();!I.done;I=B.next()){if((A=I.value).languageCode===q.languageCode)return{match:A.identifier,matchType:exports.MATCH_TYPES.relatedLocale}}}catch(e){s={error:e}}finally{try{I&&!I.done&&(y=B.return)&&y.call(B)}finally{if(s)throw s.error}}}}catch(e){f={error:e}}finally{try{O&&!O.done&&(d=j.return)&&d.call(j)}finally{if(f)throw f.error}}var k=x.objects.filter(function(e){return e.languageCode===o.languageCode&&e.identifier!==o.identifier}).map(function(e){return e.countryCode});if(k.length>0)try{for(var D=__values(m),z=D.next();!z.done;z=D.next()){if(void 0!==(q=z.value).locale&&void 0!==q.countryCode&&-1!==k.indexOf(q.countryCode))return{match:"".concat(o.languageCode,"-").concat(q.countryCode),matchType:exports.MATCH_TYPES.languageCountry}}}catch(e){v={error:e}}finally{try{z&&!z.done&&(h=D.return)&&h.call(D)}finally{if(v)throw v.error}}if(null==t?void 0:t.matchCountry)try{for(var F=__values(m),G=F.next();!G.done;G=F.next()){q=G.value;try{for(var J=(p=void 0,__values(x.objects)),K=J.next();!K.done;K=J.next()){if((A=K.value).countryCode===q.countryCode)return{match:A.identifier,matchType:exports.MATCH_TYPES.country}}}catch(e){p={error:e}}finally{try{K&&!K.done&&(C=J.return)&&C.call(J)}finally{if(p)throw p.error}}}}catch(e){g={error:e}}finally{try{G&&!G.done&&(_=F.return)&&_.call(F)}finally{if(g)throw g.error}}return{match:o.identifier,matchType:exports.MATCH_TYPES.defaultLocale}}();return(null==t?void 0:t.returnMatchType)?n:n.match};exports.resolveAcceptLanguage=resolveAcceptLanguage;
1
+ "use strict";function _export(e,r){for(var t in r)Object.defineProperty(e,t,{enumerable:!0,get:Object.getOwnPropertyDescriptor(r,t).get})}Object.defineProperty(exports,"__esModule",{value:!0}),_export(exports,{get MATCH_TYPES(){return MATCH_TYPES},get resolveAcceptLanguage(){return resolveAcceptLanguage}});var _directives=require("./directives.js"),_locales=require("./locales.js");function _array_like_to_array(e,r){(null==r||r>e.length)&&(r=e.length);for(var t=0,a=new Array(r);t<r;t++)a[t]=e[t];return a}function _array_without_holes(e){if(Array.isArray(e))return _array_like_to_array(e)}function _iterable_to_array(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}function _non_iterable_spread(){throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function _to_consumable_array(e){return _array_without_holes(e)||_iterable_to_array(e)||_unsupported_iterable_to_array(e)||_non_iterable_spread()}function _unsupported_iterable_to_array(e,r){if(e){if("string"==typeof e)return _array_like_to_array(e,r);var t=Object.prototype.toString.call(e).slice(8,-1);return"Object"===t&&e.constructor&&(t=e.constructor.name),"Map"===t||"Set"===t?Array.from(t):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?_array_like_to_array(e,r):void 0}}var MATCH_TYPES={locale:"locale",languageSpecificLocale:"languageSpecificLocale",language:"language",relatedLocale:"relatedLocale",languageCountry:"languageCountry",country:"country",defaultLocale:"defaultLocale"},resolveAcceptLanguage=function(e,r,t,a){if(r.forEach(function(e){if(!(0,_locales.isLocale)(e,!1))throw new Error("Invalid locale identifier '".concat(e,"'. A valid locale should follow the BCP 47 'language-country' format."))}),!(0,_locales.isLocale)(t,!1))throw new Error("Invalid default locale identifier '".concat(t,"'. A valid locale should follow the BCP 47 'language-country' format."));if(!r.some(function(e){return e.toLowerCase()===t.toLowerCase()}))throw new Error("The default locale '".concat(t,"' must be included in the locales array because it is used as a fallback when no match is found."));var o=new _locales.Locale(t),n=[o.identifier].concat(_to_consumable_array(r.map(function(e){return new _locales.Locale(e).identifier}))),l=function(){var r=new _locales.LocaleList(n),t=(0,_directives.getDirectives)(e),l=t.filter(function(e){return e.languageCode in r.languages}),i=!0,c=!1,u=void 0;try{for(var f,y=l[Symbol.iterator]();!(i=(f=y.next()).done);i=!0){var d=f.value,_=d.locale,v=d.languageCode;if(void 0===_){var s=!0,g=!1,h=void 0;try{for(var m,p=t[Symbol.iterator]();!(s=(m=p.next()).done);s=!0){var b=m.value;if(b.languageCode===v&&void 0!==b.locale&&b.locale in r.locales)return{match:b.locale,matchType:MATCH_TYPES.languageSpecificLocale}}}catch(e){g=!0,h=e}finally{try{s||null==p.return||p.return()}finally{if(g)throw h}}var C=!0,T=!1,w=void 0;try{for(var S,A=r.objects[Symbol.iterator]();!(C=(S=A.next()).done);C=!0){var L=S.value;if(L.languageCode===v)return{match:L.identifier,matchType:MATCH_TYPES.language}}}catch(e){T=!0,w=e}finally{try{C||null==A.return||A.return()}finally{if(T)throw w}}}else if(_ in r.locales)return{match:_,matchType:MATCH_TYPES.locale}}}catch(e){c=!0,u=e}finally{try{i||null==y.return||y.return()}finally{if(c)throw u}}var E=!0,P=!1,x=void 0;try{for(var M,j=l[Symbol.iterator]();!(E=(M=j.next()).done);E=!0){var H=M.value,Y=!0,O=!1,k=void 0;try{for(var I,q=r.objects[Symbol.iterator]();!(Y=(I=q.next()).done);Y=!0){var B=I.value;if(B.languageCode===H.languageCode)return{match:B.identifier,matchType:MATCH_TYPES.relatedLocale}}}catch(e){O=!0,k=e}finally{try{Y||null==q.return||q.return()}finally{if(O)throw k}}}}catch(e){P=!0,x=e}finally{try{E||null==j.return||j.return()}finally{if(P)throw x}}var D=r.objects.filter(function(e){return e.languageCode===o.languageCode&&e.identifier!==o.identifier}).map(function(e){return e.countryCode});if(D.length>0){var U=!0,$=!1,z=void 0;try{for(var F,G=t[Symbol.iterator]();!(U=(F=G.next()).done);U=!0){var J=F.value;if(void 0!==J.locale&&void 0!==J.countryCode&&-1!==D.indexOf(J.countryCode))return{match:"".concat(o.languageCode,"-").concat(J.countryCode),matchType:MATCH_TYPES.languageCountry}}}catch(e){$=!0,z=e}finally{try{U||null==G.return||G.return()}finally{if($)throw z}}}if(null==a?void 0:a.matchCountry){var K=!0,N=!1,Q=void 0;try{for(var R,V=t[Symbol.iterator]();!(K=(R=V.next()).done);K=!0){var W=R.value,X=!0,Z=!1,ee=void 0;try{for(var re,te=r.objects[Symbol.iterator]();!(X=(re=te.next()).done);X=!0){var ae=re.value;if(ae.countryCode===W.countryCode)return{match:ae.identifier,matchType:MATCH_TYPES.country}}}catch(e){Z=!0,ee=e}finally{try{X||null==te.return||te.return()}finally{if(Z)throw ee}}}}catch(e){N=!0,Q=e}finally{try{K||null==V.return||V.return()}finally{if(N)throw Q}}}return{match:o.identifier,matchType:MATCH_TYPES.defaultLocale}}();return(null==a?void 0:a.returnMatchType)?l:l.match};
@@ -1 +1 @@
1
- "use strict";var __read=this&&this.__read||function(e,t){var o="function"==typeof Symbol&&e[Symbol.iterator];if(!o)return e;var r,i,a=o.call(e),n=[];try{for(;(void 0===t||t-- >0)&&!(r=a.next()).done;)n.push(r.value)}catch(e){i={error:e}}finally{try{r&&!r.done&&(o=a.return)&&o.call(a)}finally{if(i)throw i.error}}return n},__values=this&&this.__values||function(e){var t="function"==typeof Symbol&&Symbol.iterator,o=t&&e[t],r=0;if(o)return o.call(e);if(e&&"number"==typeof e.length)return{next:function(){return e&&r>=e.length&&(e=void 0),{value:e&&e[r++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")};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 t=__read(e.split("-"),2),o=t[0],r=t[1];this.languageCode=o.toLowerCase(),this.countryCode=r.toUpperCase(),this.identifier="".concat(this.languageCode,"-").concat(this.countryCode)};exports.Locale=Locale;var LocaleList=function(e){var t,o;this.languages={},this.countries={},this.locales={},this.objects=[];try{for(var r=__values(e),i=r.next();!i.done;i=r.next()){var a=i.value,n=new Locale(a);n.identifier in this.locales||(this.objects.push(n),this.locales[n.identifier]=!0,this.languages[n.languageCode]=!0,this.countries[n.countryCode]=!0)}}catch(e){t={error:e}}finally{try{i&&!i.done&&(o=r.return)&&o.call(r)}finally{if(t)throw t.error}}};exports.LocaleList=LocaleList;var REGEX_LOCALE_CASE_NORMALIZED=/^[a-z]{2}-[A-Z]{2}$/,REGEX_LOCALE_CASE_INSENSITIVE=/^[a-z]{2}-[A-Z]{2}$/i,isLocale=function(e,t){return void 0===t&&(t=!0),(t?REGEX_LOCALE_CASE_NORMALIZED:REGEX_LOCALE_CASE_INSENSITIVE).test(e)};exports.isLocale=isLocale;
1
+ "use strict";function _export(t,e){for(var r in e)Object.defineProperty(t,r,{enumerable:!0,get:Object.getOwnPropertyDescriptor(e,r).get})}function _instanceof(t,e){return null!=e&&"undefined"!=typeof Symbol&&e[Symbol.hasInstance]?!!e[Symbol.hasInstance](t):t instanceof e}function _array_like_to_array(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,a=new Array(e);r<e;r++)a[r]=t[r];return a}function _array_with_holes(t){if(Array.isArray(t))return t}function _class_call_check(t,e){if(!_instanceof(t,e))throw new TypeError("Cannot call a class as a function")}function _iterable_to_array_limit(t,e){var r=null==t?null:"undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(null!=r){var a,n,o=[],i=!0,l=!1;try{for(r=r.call(t);!(i=(a=r.next()).done)&&(o.push(a.value),!e||o.length!==e);i=!0);}catch(t){l=!0,n=t}finally{try{i||null==r.return||r.return()}finally{if(l)throw n}}return o}}function _non_iterable_rest(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function _sliced_to_array(t,e){return _array_with_holes(t)||_iterable_to_array_limit(t,e)||_unsupported_iterable_to_array(t,e)||_non_iterable_rest()}function _unsupported_iterable_to_array(t,e){if(t){if("string"==typeof t)return _array_like_to_array(t,e);var r=Object.prototype.toString.call(t).slice(8,-1);return"Object"===r&&t.constructor&&(r=t.constructor.name),"Map"===r||"Set"===r?Array.from(r):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?_array_like_to_array(t,e):void 0}}Object.defineProperty(exports,"__esModule",{value:!0}),_export(exports,{get Locale(){return Locale},get LocaleList(){return LocaleList},get isLocale(){return isLocale}});var Locale=function t(e){if(_class_call_check(this,t),!isLocale(e,!1))throw new Error("invalid locale identifier '".concat(e,"'"));var r=_sliced_to_array(e.split("-"),2),a=r[0],n=r[1];this.languageCode=a.toLowerCase(),this.countryCode=n.toUpperCase(),this.identifier="".concat(this.languageCode,"-").concat(this.countryCode)},LocaleList=function t(e){_class_call_check(this,t),this.languages={},this.countries={},this.locales={},this.objects=[];var r=!0,a=!1,n=void 0;try{for(var o,i=e[Symbol.iterator]();!(r=(o=i.next()).done);r=!0){var l=o.value,c=new Locale(l);c.identifier in this.locales||(this.objects.push(c),this.locales[c.identifier]=!0,this.languages[c.languageCode]=!0,this.countries[c.countryCode]=!0)}}catch(t){a=!0,n=t}finally{try{r||null==i.return||i.return()}finally{if(a)throw n}}},REGEX_LOCALE_CASE_NORMALIZED=/^[a-z]{2}-[A-Z]{2}$/,REGEX_LOCALE_CASE_INSENSITIVE=/^[a-z]{2}-[A-Z]{2}$/i,isLocale=function(t){return(!(arguments.length>1&&void 0!==arguments[1])||arguments[1]?REGEX_LOCALE_CASE_NORMALIZED:REGEX_LOCALE_CASE_INSENSITIVE).test(t)};
@@ -1 +1 @@
1
- { "type": "commonjs" }
1
+ { "type": "commonjs" }
@@ -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))},REGEX_DIRECTIVE=/^(([a-z]{2})(-([a-z]{2}|419))?)(;q=((1(\.0{0,3})?)|(0(\.\d{0,3})?)))?$/i,getDirective=function(r){var e=r.match(REGEX_DIRECTIVE);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.map(function(r){return r.locale}).indexOf("es-419");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})};
1
+ function _array_like_to_array(r,e){(null==e||e>r.length)&&(e=r.length);for(var t=0,a=new Array(e);t<e;t++)a[t]=r[t];return a}function _array_without_holes(r){if(Array.isArray(r))return _array_like_to_array(r)}function _iterable_to_array(r){if("undefined"!=typeof Symbol&&null!=r[Symbol.iterator]||null!=r["@@iterator"])return Array.from(r)}function _non_iterable_spread(){throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function _to_consumable_array(r){return _array_without_holes(r)||_iterable_to_array(r)||_unsupported_iterable_to_array(r)||_non_iterable_spread()}function _unsupported_iterable_to_array(r,e){if(r){if("string"==typeof r)return _array_like_to_array(r,e);var t=Object.prototype.toString.call(r).slice(8,-1);return"Object"===t&&r.constructor&&(t=r.constructor.name),"Map"===t||"Set"===t?Array.from(t):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?_array_like_to_array(r,e):void 0}}var REGEX_DIRECTIVE=/^(([a-z]{2})(-([a-z]{2}|419))?)(;q=((1(\.0{0,3})?)|(0(\.\d{0,3})?)))?$/i,getDirective=function(r){var e=r.match(REGEX_DIRECTIVE);if(e){var t=e[2],a=e[4],o=e[6],n=t.toLowerCase(),i=a?a.toUpperCase():void 0;if("419"!==i||"es"===n){var l=void 0===o?1:Number(o);return{languageCode:n,countryCode:i,locale:i?"".concat(n,"-").concat(i):void 0,quality:l}}}};export var getDirectives=function(r){var e=[],t=0;r.split(",").forEach(function(r){var a=getDirective(r.trim());a&&(e.some(function(r){return r.languageCode===a.languageCode&&r.locale===a.locale})||(e.push(Object.assign(Object.assign({},a),{headerPosition:t})),t++))});var a=e.map(function(r){return r.locale}).indexOf("es-419");if(-1!==a){var o,n=e[a],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 Object.assign(Object.assign({},n),{locale:r})});(o=e).splice.apply(o,[a,1].concat(_to_consumable_array(i)))}return e.sort(function(r,e){var t=e.quality-r.quality;return t||r.headerPosition-e.headerPosition})};
package/dist/esm/index.js CHANGED
@@ -1 +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,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.")};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),l=__spreadArray([o.identifier],__read(r.map(function(e){return new Locale(e).identifier})),!1),n=function(){var r,a,n,i,c,u,f,d,y,v,h,s,g,_,m,C,p=new LocaleList(l),T=getDirectives(e),w=T.filter(function(e){return e.languageCode in p.languages});try{for(var L=__values(w),x=L.next();!x.done;x=L.next()){var A=(D=x.value).locale,S=D.languageCode;if(void 0===A){try{for(var b=(n=void 0,__values(T)),E=b.next();!E.done;E=b.next()){var P=E.value;if(P.languageCode===S&&void 0!==P.locale&&P.locale in p.locales)return{match:P.locale,matchType:MATCH_TYPES.languageSpecificLocale}}}catch(e){n={error:e}}finally{try{E&&!E.done&&(i=b.return)&&i.call(b)}finally{if(n)throw n.error}}try{for(var M=(c=void 0,__values(p.objects)),H=M.next();!H.done;H=M.next()){var Y=H.value;if(Y.languageCode===S)return{match:Y.identifier,matchType:MATCH_TYPES.language}}}catch(e){c={error:e}}finally{try{H&&!H.done&&(u=M.return)&&u.call(M)}finally{if(c)throw c.error}}}else if(A in p.locales)return{match:A,matchType:MATCH_TYPES.locale}}}catch(e){r={error:e}}finally{try{x&&!x.done&&(a=L.return)&&a.call(L)}finally{if(r)throw r.error}}try{for(var j=__values(w),B=j.next();!B.done;B=j.next()){var D=B.value;try{for(var I=(y=void 0,__values(p.objects)),O=I.next();!O.done;O=I.next()){if((A=O.value).languageCode===D.languageCode)return{match:A.identifier,matchType:MATCH_TYPES.relatedLocale}}}catch(e){y={error:e}}finally{try{O&&!O.done&&(v=I.return)&&v.call(I)}finally{if(y)throw y.error}}}}catch(e){f={error:e}}finally{try{B&&!B.done&&(d=j.return)&&d.call(j)}finally{if(f)throw f.error}}var k=p.objects.filter(function(e){return e.languageCode===o.languageCode&&e.identifier!==o.identifier}).map(function(e){return e.countryCode});if(k.length>0)try{for(var q=__values(T),z=q.next();!z.done;z=q.next()){if(void 0!==(D=z.value).locale&&void 0!==D.countryCode&&-1!==k.indexOf(D.countryCode))return{match:"".concat(o.languageCode,"-").concat(D.countryCode),matchType:MATCH_TYPES.languageCountry}}}catch(e){h={error:e}}finally{try{z&&!z.done&&(s=q.return)&&s.call(q)}finally{if(h)throw h.error}}if(null==t?void 0:t.matchCountry)try{for(var F=__values(T),G=F.next();!G.done;G=F.next()){D=G.value;try{for(var J=(m=void 0,__values(p.objects)),K=J.next();!K.done;K=J.next()){if((A=K.value).countryCode===D.countryCode)return{match:A.identifier,matchType:MATCH_TYPES.country}}}catch(e){m={error:e}}finally{try{K&&!K.done&&(C=J.return)&&C.call(J)}finally{if(m)throw m.error}}}}catch(e){g={error:e}}finally{try{G&&!G.done&&(_=F.return)&&_.call(F)}finally{if(g)throw g.error}}return{match:o.identifier,matchType:MATCH_TYPES.defaultLocale}}();return(null==t?void 0:t.returnMatchType)?n:n.match};
1
+ function _array_like_to_array(r,e){(null==e||e>r.length)&&(e=r.length);for(var a=0,t=new Array(e);a<e;a++)t[a]=r[a];return t}function _array_without_holes(r){if(Array.isArray(r))return _array_like_to_array(r)}function _iterable_to_array(r){if("undefined"!=typeof Symbol&&null!=r[Symbol.iterator]||null!=r["@@iterator"])return Array.from(r)}function _non_iterable_spread(){throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function _to_consumable_array(r){return _array_without_holes(r)||_iterable_to_array(r)||_unsupported_iterable_to_array(r)||_non_iterable_spread()}function _unsupported_iterable_to_array(r,e){if(r){if("string"==typeof r)return _array_like_to_array(r,e);var a=Object.prototype.toString.call(r).slice(8,-1);return"Object"===a&&r.constructor&&(a=r.constructor.name),"Map"===a||"Set"===a?Array.from(a):"Arguments"===a||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(a)?_array_like_to_array(r,e):void 0}}import{getDirectives}from"./directives.js";import{isLocale,Locale,LocaleList}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(r,e,a,t){if(e.forEach(function(r){if(!isLocale(r,!1))throw new Error("Invalid locale identifier '".concat(r,"'. 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(!e.some(function(r){return r.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=[o.identifier].concat(_to_consumable_array(e.map(function(r){return new Locale(r).identifier}))),l=function(){var e=new LocaleList(n),a=getDirectives(r),l=a.filter(function(r){return r.languageCode in e.languages}),i=!0,c=!1,u=void 0;try{for(var f,y=l[Symbol.iterator]();!(i=(f=y.next()).done);i=!0){var d=f.value,v=d.locale,_=d.languageCode;if(void 0===v){var h=!0,g=!1,s=void 0;try{for(var m,p=a[Symbol.iterator]();!(h=(m=p.next()).done);h=!0){var b=m.value;if(b.languageCode===_&&void 0!==b.locale&&b.locale in e.locales)return{match:b.locale,matchType:MATCH_TYPES.languageSpecificLocale}}}catch(r){g=!0,s=r}finally{try{h||null==p.return||p.return()}finally{if(g)throw s}}var C=!0,w=!1,T=void 0;try{for(var S,L=e.objects[Symbol.iterator]();!(C=(S=L.next()).done);C=!0){var A=S.value;if(A.languageCode===_)return{match:A.identifier,matchType:MATCH_TYPES.language}}}catch(r){w=!0,T=r}finally{try{C||null==L.return||L.return()}finally{if(w)throw T}}}else if(v in e.locales)return{match:v,matchType:MATCH_TYPES.locale}}}catch(r){c=!0,u=r}finally{try{i||null==y.return||y.return()}finally{if(c)throw u}}var E=!0,x=!1,M=void 0;try{for(var P,j=l[Symbol.iterator]();!(E=(P=j.next()).done);E=!0){var H=P.value,Y=!0,k=!1,I=void 0;try{for(var O,B=e.objects[Symbol.iterator]();!(Y=(O=B.next()).done);Y=!0){var D=O.value;if(D.languageCode===H.languageCode)return{match:D.identifier,matchType:MATCH_TYPES.relatedLocale}}}catch(r){k=!0,I=r}finally{try{Y||null==B.return||B.return()}finally{if(k)throw I}}}}catch(r){x=!0,M=r}finally{try{E||null==j.return||j.return()}finally{if(x)throw M}}var U=e.objects.filter(function(r){return r.languageCode===o.languageCode&&r.identifier!==o.identifier}).map(function(r){return r.countryCode});if(U.length>0){var $=!0,q=!1,z=void 0;try{for(var F,G=a[Symbol.iterator]();!($=(F=G.next()).done);$=!0){var J=F.value;if(void 0!==J.locale&&void 0!==J.countryCode&&-1!==U.indexOf(J.countryCode))return{match:"".concat(o.languageCode,"-").concat(J.countryCode),matchType:MATCH_TYPES.languageCountry}}}catch(r){q=!0,z=r}finally{try{$||null==G.return||G.return()}finally{if(q)throw z}}}if(null==t?void 0:t.matchCountry){var K=!0,N=!1,Q=void 0;try{for(var R,V=a[Symbol.iterator]();!(K=(R=V.next()).done);K=!0){var W=R.value,X=!0,Z=!1,rr=void 0;try{for(var er,ar=e.objects[Symbol.iterator]();!(X=(er=ar.next()).done);X=!0){var tr=er.value;if(tr.countryCode===W.countryCode)return{match:tr.identifier,matchType:MATCH_TYPES.country}}}catch(r){Z=!0,rr=r}finally{try{X||null==ar.return||ar.return()}finally{if(Z)throw rr}}}}catch(r){N=!0,Q=r}finally{try{K||null==V.return||V.return()}finally{if(N)throw Q}}}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 r="function"==typeof Symbol&&e[Symbol.iterator];if(!r)return e;var o,i,n=r.call(e),a=[];try{for(;(void 0===t||t-- >0)&&!(o=n.next()).done;)a.push(o.value)}catch(e){i={error:e}}finally{try{o&&!o.done&&(r=n.return)&&r.call(n)}finally{if(i)throw i.error}}return a},__values=this&&this.__values||function(e){var t="function"==typeof Symbol&&Symbol.iterator,r=t&&e[t],o=0;if(r)return r.call(e);if(e&&"number"==typeof e.length)return{next:function(){return e&&o>=e.length&&(e=void 0),{value:e&&e[o++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")},Locale=function(e){if(!isLocale(e,!1))throw new Error("invalid locale identifier '".concat(e,"'"));var t=__read(e.split("-"),2),r=t[0],o=t[1];this.languageCode=r.toLowerCase(),this.countryCode=o.toUpperCase(),this.identifier="".concat(this.languageCode,"-").concat(this.countryCode)};export{Locale};var LocaleList=function(e){var t,r;this.languages={},this.countries={},this.locales={},this.objects=[];try{for(var o=__values(e),i=o.next();!i.done;i=o.next()){var n=i.value,a=new Locale(n);a.identifier in this.locales||(this.objects.push(a),this.locales[a.identifier]=!0,this.languages[a.languageCode]=!0,this.countries[a.countryCode]=!0)}}catch(e){t={error:e}}finally{try{i&&!i.done&&(r=o.return)&&r.call(o)}finally{if(t)throw t.error}}};export{LocaleList};var REGEX_LOCALE_CASE_NORMALIZED=/^[a-z]{2}-[A-Z]{2}$/,REGEX_LOCALE_CASE_INSENSITIVE=/^[a-z]{2}-[A-Z]{2}$/i;export var isLocale=function(e,t){return void 0===t&&(t=!0),(t?REGEX_LOCALE_CASE_NORMALIZED:REGEX_LOCALE_CASE_INSENSITIVE).test(e)};
1
+ function _array_like_to_array(t,r){(null==r||r>t.length)&&(r=t.length);for(var e=0,a=new Array(r);e<r;e++)a[e]=t[e];return a}function _array_with_holes(t){if(Array.isArray(t))return t}function _class_call_check(t,r){if(!(t instanceof r))throw new TypeError("Cannot call a class as a function")}function _iterable_to_array_limit(t,r){var e=null==t?null:"undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(null!=e){var a,n,o=[],i=!0,l=!1;try{for(e=e.call(t);!(i=(a=e.next()).done)&&(o.push(a.value),!r||o.length!==r);i=!0);}catch(t){l=!0,n=t}finally{try{i||null==e.return||e.return()}finally{if(l)throw n}}return o}}function _non_iterable_rest(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function _sliced_to_array(t,r){return _array_with_holes(t)||_iterable_to_array_limit(t,r)||_unsupported_iterable_to_array(t,r)||_non_iterable_rest()}function _unsupported_iterable_to_array(t,r){if(t){if("string"==typeof t)return _array_like_to_array(t,r);var e=Object.prototype.toString.call(t).slice(8,-1);return"Object"===e&&t.constructor&&(e=t.constructor.name),"Map"===e||"Set"===e?Array.from(e):"Arguments"===e||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(e)?_array_like_to_array(t,r):void 0}}export var Locale=function t(r){"use strict";if(_class_call_check(this,t),!isLocale(r,!1))throw new Error("invalid locale identifier '".concat(r,"'"));var e=_sliced_to_array(r.split("-"),2),a=e[0],n=e[1];this.languageCode=a.toLowerCase(),this.countryCode=n.toUpperCase(),this.identifier="".concat(this.languageCode,"-").concat(this.countryCode)};export var LocaleList=function t(r){"use strict";_class_call_check(this,t),this.languages={},this.countries={},this.locales={},this.objects=[];var e=!0,a=!1,n=void 0;try{for(var o,i=r[Symbol.iterator]();!(e=(o=i.next()).done);e=!0){var l=o.value,c=new Locale(l);c.identifier in this.locales||(this.objects.push(c),this.locales[c.identifier]=!0,this.languages[c.languageCode]=!0,this.countries[c.countryCode]=!0)}}catch(t){a=!0,n=t}finally{try{e||null==i.return||i.return()}finally{if(a)throw n}}};var REGEX_LOCALE_CASE_NORMALIZED=/^[a-z]{2}-[A-Z]{2}$/,REGEX_LOCALE_CASE_INSENSITIVE=/^[a-z]{2}-[A-Z]{2}$/i;export var isLocale=function(t){return(!(arguments.length>1&&void 0!==arguments[1])||arguments[1]?REGEX_LOCALE_CASE_NORMALIZED:REGEX_LOCALE_CASE_INSENSITIVE).test(t)};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "resolve-accept-language",
3
- "version": "3.2.0",
3
+ "version": "3.2.1",
4
4
  "description": "Resolve the preferred locale based on the value of an `Accept-Language` HTTP header.",
5
5
  "keywords": [
6
6
  "accept-language",
@@ -43,7 +43,7 @@
43
43
  "dist"
44
44
  ],
45
45
  "scripts": {
46
- "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
+ "build": "npm run check-nvm-node-version && npm run prettier-write && npm run eslint-fix && rm -Rf ./dist && tsc && npx tsx src/build-scripts/build.ts && npm run test",
47
47
  "check-nvm-node-version": "check-node-version --node $(node -p \"'>=' + require('fs').readFileSync('.nvmrc', 'utf-8').trim()\")",
48
48
  "depcheck": "depcheck",
49
49
  "eslint-fix": "eslint --fix",
@@ -57,34 +57,34 @@
57
57
  },
58
58
  "devDependencies": {
59
59
  "@release-it/conventional-changelog": "10.0.6",
60
+ "@swc/core": "1.15.24",
60
61
  "@types/jest": "30.0.0",
61
- "@types/node": "25.5.0",
62
+ "@types/node": "25.5.2",
62
63
  "check-node-version": "4.2.1",
63
64
  "depcheck": "1.4.7",
64
65
  "dotenv-cli": "11.0.0",
65
- "eslint": "10.0.3",
66
+ "eslint": "10.2.0",
66
67
  "eslint-config-prettier": "10.1.8",
67
68
  "eslint-import-resolver-typescript": "4.4.4",
68
- "eslint-plugin-es-x": "9.5.0",
69
+ "eslint-plugin-es-x": "9.6.0",
69
70
  "eslint-plugin-import-x": "4.16.2",
70
- "eslint-plugin-jest": "29.15.0",
71
- "eslint-plugin-package-json": "0.91.0",
71
+ "eslint-plugin-jest": "29.15.1",
72
+ "eslint-plugin-package-json": "0.91.1",
72
73
  "eslint-plugin-prefer-arrow-functions": "3.9.1",
73
74
  "eslint-plugin-prettier": "5.5.5",
74
75
  "eslint-plugin-tsdoc": "0.5.2",
75
- "eslint-plugin-unicorn": "63.0.0",
76
+ "eslint-plugin-unicorn": "64.0.0",
76
77
  "husky": "9.1.7",
77
78
  "jest": "30.3.0",
78
79
  "jiti": "2.6.1",
79
80
  "jsonc-eslint-parser": "3.1.0",
80
- "npm-check-updates": "19.6.3",
81
+ "npm-check-updates": "20.0.0",
81
82
  "prettier": "3.8.1",
82
- "prettier-plugin-organize-imports": "4.3.0",
83
83
  "release-it": "19.2.4",
84
- "terser": "5.46.0",
85
- "ts-jest": "29.4.6",
86
- "typescript": "5.9.3",
87
- "typescript-eslint": "8.57.0"
84
+ "terser": "5.46.1",
85
+ "ts-jest": "29.4.9",
86
+ "typescript": "6.0.2",
87
+ "typescript-eslint": "8.58.0"
88
88
  },
89
89
  "engines": {
90
90
  "node": ">=4.0.0"