@adyen/adyen-web
Version:
[](https://www.npmjs.com/package/@adyen/adyen-web)
3 lines (2 loc) • 1.44 kB
JavaScript
import{DEFAULT_LOCALE as t,LOCALE_NAME_MIN_LENGTH as n,LOCALE_NAME_MAX_LENGTH as e}from"./constants.js";const r=t=>t.toLowerCase().substring(0,2),o=t=>Boolean(t)&&t.length>=n&&t.length<=e;function l(t,n){return t&&"string"==typeof t&&n.find(n=>r(n)===r(t))||null}function s(t){const n=t.replace("_","-");if(/^([a-z]{2})(-)([A-Z]{2})$/.test(n))return n;const[e,r]=n.split("-");if(!e||!r)return null;const o=[e.toLowerCase(),r.toUpperCase()].join("-");return 5===o.length?o:null}function u(n,e){if(!o(n))return t;const r=s(n);return r&&e.includes(r)?r:l(r||n,e)||t}function c(t={}){return Object.keys(t).reduce((n,e)=>{if(!o(e))return n;return n[s(e)||r(e)]=t[e],n},{})}const a=(t,n)=>t.replace(/%{(\w+)}/g,(t,e)=>n[e]||""),i=(t,n,e={})=>{const{values:r={},count:o=0}=e,l=`${n}__plural`,s=t=>`${n}__${t}`;return Object.prototype.hasOwnProperty.call(t,s(o))?a(t[s(o)],r):Object.prototype.hasOwnProperty.call(t,l)&&o>1?a(t[l],r):Object.prototype.hasOwnProperty.call(t,n)?a(t[n],r):null},p=(t,n)=>{const e=t.split(/%#(.*?)%#/gm);if(n.length!==Math.floor(e.length/2))throw Error("The number of functions provided does not match the number of elements in the translation string.");return e.map((t,e)=>{const r=Math.floor(e/2);return e%2==0?t:n[r](t)})};export{c as formatCustomTranslations,s as formatLocaleToLanguageCountryLocale,i as getTranslation,p as interpolateElement,l as matchLocale,u as parseLocale};
//# sourceMappingURL=utils.js.map