use-intl 3.4.0 → 3.4.2

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.
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var initializeConfig = require('./initializeConfig-c503e215.js');
6
- var createFormatter = require('./createFormatter-56ef3976.js');
6
+ var createFormatter = require('./createFormatter-ee823546.js');
7
7
  require('intl-messageformat');
8
8
  require('react');
9
9
 
@@ -428,7 +428,15 @@ function createFormatter(_ref) {
428
428
  const unit = typeof nowOrOptions === 'number' || nowOrOptions instanceof Date || (nowOrOptions === null || nowOrOptions === void 0 ? void 0 : nowOrOptions.unit) === undefined ? resolveRelativeTimeUnit(seconds) : nowOrOptions.unit;
429
429
  const value = calculateRelativeTimeValue(seconds, unit);
430
430
  return new Intl.RelativeTimeFormat(locale, {
431
- numeric: 'auto'
431
+ // `numeric: 'auto'` can theoretically produce output like "yesterday",
432
+ // but it only works with integers. E.g. -1 day will produce "yesterday",
433
+ // but -1.1 days will produce "-1.1 days". Rounding before formatting is
434
+ // not desired, as the given dates might cross a threshold were the
435
+ // output isn't correct anymore. Example: 2024-01-08T23:00:00.000Z and
436
+ // 2024-01-08T01:00:00.000Z would produce "yesterday", which is not the
437
+ // case. By using `always` we can ensure correct output. The only exception
438
+ // is the formatting of times <1 second as "now".
439
+ numeric: unit === 'second' ? 'auto' : 'always'
432
440
  }).format(value, unit);
433
441
  } catch (error) {
434
442
  onError(new initializeConfig.IntlError(initializeConfig.IntlErrorCode.FORMATTING_ERROR, error.message));
@@ -4,7 +4,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var initializeConfig = require('./initializeConfig-c503e215.js');
6
6
  var core = require('./core.js');
7
- var createFormatter = require('./createFormatter-56ef3976.js');
7
+ var createFormatter = require('./createFormatter-ee823546.js');
8
8
  var _IntlProvider = require('./_IntlProvider.js');
9
9
  var react = require('./react.js');
10
10
  var _useLocale = require('./_useLocale-321e619f.js');
@@ -5,7 +5,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
5
5
  var _IntlProvider = require('./_IntlProvider.js');
6
6
  var _useLocale = require('./_useLocale-321e619f.js');
7
7
  var React = require('react');
8
- var createFormatter = require('./createFormatter-56ef3976.js');
8
+ var createFormatter = require('./createFormatter-ee823546.js');
9
9
  var initializeConfig = require('./initializeConfig-c503e215.js');
10
10
  require('./IntlContext-b5cc6be8.js');
11
11
  require('intl-messageformat');
@@ -0,0 +1 @@
1
+ import{createContext as r}from"react";var o=r(void 0);export{o as I};
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),t=require("./initializeConfig-17849dd5.js"),a=require("./IntlContext-381f3ce4.js");function r(e){return e&&e.__esModule?e:{default:e}}var n=r(e);exports.IntlProvider=function(r){let{children:o,defaultTranslationValues:s,formats:l,getMessageFallback:i,locale:u,messages:c,now:f,onError:d,timeZone:m}=r;const[g]=e.useState((()=>new Map)),v=e.useMemo((()=>({...t.initializeConfig({locale:u,defaultTranslationValues:s,formats:l,getMessageFallback:i,messages:c,now:f,onError:d,timeZone:m}),messageFormatCache:g})),[s,l,i,u,g,c,f,d,m]);return n.default.createElement(a.IntlContext.Provider,{value:v},o)};
1
+ import e,{useState as a,useMemo as o}from"react";import{i as t}from"./initializeConfig-8268c3a9.js";import{I as r}from"./IntlContext-b1dc6cbd.js";function s(s){let{children:n,defaultTranslationValues:l,formats:i,getMessageFallback:m,locale:c,messages:f,now:g,onError:u,timeZone:p}=s;const[d]=a((()=>new Map)),w=o((()=>({...t({locale:c,defaultTranslationValues:l,formats:i,getMessageFallback:m,messages:f,now:g,onError:u,timeZone:p}),messageFormatCache:d})),[l,i,m,c,d,f,g,u,p]);return e.createElement(r.Provider,{value:w},n)}export{s as IntlProvider};
@@ -0,0 +1 @@
1
+ import{useContext as o}from"react";import{I as r}from"./IntlContext-b1dc6cbd.js";function t(){const t=o(r);if(!t)throw new Error("No intl context found. Have you configured the provider?");return t}function n(){return t().locale}export{t as a,n as u};
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("./_useLocale-89b32eb9.js");require("react"),require("./IntlContext-381f3ce4.js"),exports.useLocale=e.useLocale;
1
+ export{u as useLocale}from"./_useLocale-65297b4e.js";import"react";import"./IntlContext-b1dc6cbd.js";
package/dist/esm/core.js CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("./initializeConfig-17849dd5.js"),r=require("./createFormatter-022b2d85.js");require("intl-messageformat"),require("react"),exports.IntlError=e.IntlError,exports.IntlErrorCode=e.IntlErrorCode,exports.initializeConfig=e.initializeConfig,exports.createFormatter=r.createFormatter,exports.createTranslator=function(a){let{getMessageFallback:t=e.defaultGetMessageFallback,messages:s,namespace:o,onError:n=e.defaultOnError,...l}=a;return function(e,a){let{getMessageFallback:t,messages:s,namespace:o,onError:n,...l}=e;return s=s[a],o=r.resolveNamespace(o,a),r.createBaseTranslator({...l,onError:n,getMessageFallback:t,messages:s,namespace:o})}({...l,onError:n,getMessageFallback:t,messages:{"!":s},namespace:o?"!.".concat(o):"!"},"!")};
1
+ import{b as e,d as r}from"./initializeConfig-8268c3a9.js";export{I as IntlError,a as IntlErrorCode,i as initializeConfig}from"./initializeConfig-8268c3a9.js";import{r as s,a as t}from"./createFormatter-7ab5b371.js";export{c as createFormatter}from"./createFormatter-7ab5b371.js";import"intl-messageformat";import"react";function o(a){let{getMessageFallback:o=e,messages:n,namespace:i,onError:m=r,...c}=a;return function(e,a){let{getMessageFallback:r,messages:o,namespace:n,onError:i,...m}=e;return o=o[a],n=s(n,a),t({...m,onError:i,getMessageFallback:r,messages:o,namespace:n})}({...c,onError:m,getMessageFallback:o,messages:{"!":n},namespace:i?"!.".concat(i):"!"},"!")}export{o as createTranslator};
@@ -0,0 +1 @@
1
+ import e from"intl-messageformat";import{isValidElement as t,cloneElement as n}from"react";import{I as r,a as o,j as a,d as s,b as i}from"./initializeConfig-8268c3a9.js";function c(e,t){return e?Object.keys(e).reduce(((n,r)=>(n[r]={timeZone:t,...e[r]},n)),{}):e}function u(e,t,n){const r=a(n,t);if(!e)throw new Error("No messages available at `".concat(n,"`."));let o=e;return t.split(".").forEach((e=>{const t=o[e];if(null==e||null==t)throw new Error("Could not resolve `".concat(r,"` in messages."));o=t})),o}function m(m){const l=function(e){let{messages:t,namespace:n,onError:a=s}=e;try{if(!t)throw new Error("No messages were configured on the provider.");const e=n?u(t,n):t;if(!e)throw new Error("No messages for namespace `".concat(n,"` found."));return e}catch(e){const t=new r(o.MISSING_MESSAGE,e.message);return a(t),t}}({messages:m.messages,namespace:m.namespace,onError:m.onError});return function(s){let{defaultTranslationValues:m,formats:l,getMessageFallback:f=i,locale:d,messageFormatCache:g,messagesOrError:p,namespace:h,onError:y,timeZone:w}=s;function v(e,t,n){const o=new r(t,n);return y(o),f({error:o,key:e,namespace:h})}function E(s,i,y){if(p instanceof r)return f({error:p,key:s,namespace:h});const E=p;let I;try{I=u(E,s,h)}catch(e){return v(s,o.MISSING_MESSAGE,e.message)}const S=a(d,h,s,String(I));let T;if(null!=g&&g.has(S))T=g.get(S);else{if("object"==typeof I){let e,t;return Array.isArray(I)?(e=o.INVALID_MESSAGE,t="Message at `".concat(a(h,s),"` resolved to an array, but only strings are supported. See https://next-intl-docs.vercel.app/docs/usage/messages#arrays-of-messages")):(e=o.INSUFFICIENT_PATH,t="Message at `".concat(a(h,s),"` resolved to an object, but only strings are supported. Use a `.` to retrieve nested messages. See https://next-intl-docs.vercel.app/docs/usage/messages#structuring-messages")),v(s,e,t)}const t=function(e,t){if(t)return;const n=e.replace(/'([{}])/gi,"$1");return/<|{/.test(n)?void 0:n}(I,i);if(t)return t;try{T=new e(I,d,function(t,n){const r=n?{...t,dateTime:c(t.dateTime,n)}:t,o=e.formats.date,a=n?c(o,n):o,s=e.formats.time,i=n?c(s,n):s;return{...r,date:{...a,...null==r?void 0:r.dateTime},time:{...i,...null==r?void 0:r.dateTime}}}({...l,...y},w))}catch(e){return v(s,o.INVALID_MESSAGE,e.message)}null==g||g.set(S,T)}try{const e=T.format(function(e){if(0===Object.keys(e).length)return;const r={};return Object.keys(e).forEach((o=>{let a=0;const s=e[o];let i;i="function"==typeof s?e=>{const r=s(e);return t(r)?n(r,{key:o+a++}):r}:s,r[o]=i})),r}({...m,...i}));if(null==e)throw new Error("Unable to format `".concat(s,"` in ").concat(h?"namespace `".concat(h,"`"):"messages"));return t(e)||Array.isArray(e)||"string"==typeof e?e:String(e)}catch(e){return v(s,o.FORMATTING_ERROR,e.message)}}function I(e,t,n){const r=E(e,t,n);return"string"!=typeof r?v(e,o.INVALID_MESSAGE,"The message `".concat(e,"` in ").concat(h?"namespace `".concat(h,"`"):"messages"," didn't resolve to a string. If you want to format rich text, use `t.rich` instead.")):r}return I.rich=E,I.markup=(e,t,n)=>{const a=E(e,t,n);if("string"!=typeof a){const t=new r(o.FORMATTING_ERROR,"`t.markup` only accepts functions for formatting that receive and return strings.\n\nE.g. t.markup('markup', {b: (chunks) => `<b>${chunks}</b>`})");return y(t),f({error:t,key:e,namespace:h})}return a},I.raw=e=>{if(p instanceof r)return f({error:p,key:e,namespace:h});const t=p;try{return u(t,e,h)}catch(t){return v(e,o.MISSING_MESSAGE,t.message)}},I}({...m,messagesOrError:l})}function l(e,t){return e===t?void 0:e.slice((t+".").length)}const f=60,d=60*f,g=24*d,p=7*g,h=g*(365/12),y=3*h,w=365*g,v={second:1,seconds:1,minute:f,minutes:f,hour:d,hours:d,day:g,days:g,week:p,weeks:p,month:h,months:h,quarter:y,quarters:y,year:w,years:w};function E(e){let{formats:t,locale:n,now:a,onError:i=s,timeZone:c}=e;function u(e,t,n,a){let s;try{s=function(e,t){let n;if("string"==typeof t){const a=t;if(n=null==e?void 0:e[a],!n){const e=new r(o.MISSING_FORMAT,"Format `".concat(a,"` is not available. You can configure it on the provider or provide custom options."));throw i(e),e}}else n=t;return n}(n,t)}catch(t){return String(e)}try{return a(s)}catch(t){return i(new r(o.FORMATTING_ERROR,t.message)),String(e)}}function m(e){return e instanceof Date||"number"==typeof e?new Date(e):void 0!==(null==e?void 0:e.now)?new Date(e.now):a||(i(new r(o.ENVIRONMENT_FALLBACK,"The `now` parameter wasn't provided and there is no global default configured. Consider adding a global default to avoid markup mismatches caused by environment differences. Learn more: https://next-intl-docs.vercel.app/docs/configuration#now")),new Date)}return{dateTime:function(e,a){return u(e,a,null==t?void 0:t.dateTime,(t=>{var a;return null!==(a=t)&&void 0!==a&&a.timeZone||(c?t={...t,timeZone:c}:i(new r(o.ENVIRONMENT_FALLBACK,"The `timeZone` parameter wasn't provided and there is no global default configured. Consider adding a global default to avoid markup mismatches caused by environment differences. Learn more: https://next-intl-docs.vercel.app/docs/configuration#time-zone"))),new Intl.DateTimeFormat(n,t).format(e)}))},number:function(e,r){return u(e,r,null==t?void 0:t.number,(t=>new Intl.NumberFormat(n,t).format(e)))},relativeTime:function(e,t){try{const r=new Date(e),o=m(t),a=(r.getTime()-o.getTime())/1e3,s="number"==typeof t||t instanceof Date||void 0===(null==t?void 0:t.unit)?function(e){const t=Math.abs(e);return t<f?"second":t<d?"minute":t<g?"hour":t<p?"day":t<h?"week":t<w?"month":"year"}(a):t.unit,i=function(e,t){return Math.round(e/v[t])}(a,s);return new Intl.RelativeTimeFormat(n,{numeric:"second"===s?"auto":"always"}).format(i,s)}catch(t){return i(new r(o.FORMATTING_ERROR,t.message)),String(e)}},list:function(e,r){return u(e,r,null==t?void 0:t.list,(t=>new Intl.ListFormat(n,t).format(e)))}}}export{m as a,E as c,l as r};
package/dist/esm/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("./initializeConfig-17849dd5.js"),r=require("./core.js"),t=require("./createFormatter-022b2d85.js"),s=require("./_IntlProvider.js"),o=require("./react.js"),i=require("./_useLocale-89b32eb9.js");require("intl-messageformat"),require("react"),require("./IntlContext-381f3ce4.js"),exports.IntlError=e.IntlError,exports.IntlErrorCode=e.IntlErrorCode,exports.initializeConfig=e.initializeConfig,exports.createTranslator=r.createTranslator,exports.createFormatter=t.createFormatter,exports.IntlProvider=s.IntlProvider,exports.useFormatter=o.useFormatter,exports.useMessages=o.useMessages,exports.useNow=o.useNow,exports.useTimeZone=o.useTimeZone,exports.useTranslations=o.useTranslations,exports.useLocale=i.useLocale;
1
+ export{I as IntlError,a as IntlErrorCode,i as initializeConfig}from"./initializeConfig-8268c3a9.js";export{createTranslator}from"./core.js";export{c as createFormatter}from"./createFormatter-7ab5b371.js";export{IntlProvider}from"./_IntlProvider.js";export{useFormatter,useMessages,useNow,useTimeZone,useTranslations}from"./react.js";export{u as useLocale}from"./_useLocale-65297b4e.js";import"intl-messageformat";import"react";import"./IntlContext-b1dc6cbd.js";
@@ -0,0 +1 @@
1
+ function n(n,e,t){return(e=function(n){var e=function(n,e){if("object"!=typeof n||null===n)return n;var t=n[Symbol.toPrimitive];if(void 0!==t){var o=t.call(n,e||"default");if("object"!=typeof o)return o;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(n)}(n,"string");return"symbol"==typeof e?e:String(e)}(e))in n?Object.defineProperty(n,e,{value:t,enumerable:!0,configurable:!0,writable:!0}):n[e]=t,n}let e=function(n){return n.MISSING_MESSAGE="MISSING_MESSAGE",n.MISSING_FORMAT="MISSING_FORMAT",n.ENVIRONMENT_FALLBACK="ENVIRONMENT_FALLBACK",n.INSUFFICIENT_PATH="INSUFFICIENT_PATH",n.INVALID_MESSAGE="INVALID_MESSAGE",n.INVALID_KEY="INVALID_KEY",n.FORMATTING_ERROR="FORMATTING_ERROR",n}({});class t extends Error{constructor(e,t){let o=e;t&&(o+=": "+t),super(o),n(this,"code",void 0),n(this,"originalMessage",void 0),this.code=e,t&&(this.originalMessage=t)}}function o(){for(var n=arguments.length,e=new Array(n),t=0;t<n;t++)e[t]=arguments[t];return e.filter(Boolean).join(".")}function r(n){return o(n.namespace,n.key)}function a(n){console.error(n)}function s(n,e,t){Object.entries(n).forEach((n=>{let[r,a]=n;if(r.includes(".")){let n=r;t&&(n+=" (at ".concat(t,")")),e.push(n)}null!=a&&"object"==typeof a&&s(a,e,o(t,r))}))}function i(n,o){const r=[];s(n,r),r.length>0&&o(new t(e.INVALID_KEY,'Namespace keys can not contain the character "." as this is used to express nesting. Please remove it or replace it with another character.\n\nInvalid '.concat(1===r.length?"key":"keys",": ").concat(r.join(", "),'\n\nIf you\'re migrating from a flat structure, you can convert your messages as follows:\n\nimport {set} from "lodash";\n\nconst input = {\n "one.one": "1.1",\n "one.two": "1.2",\n "two.one.one": "2.1.1"\n};\n\nconst output = Object.entries(input).reduce(\n (acc, [key, value]) => set(acc, key, value),\n {}\n);\n\n// Output:\n//\n// {\n// "one": {\n// "one": "1.1",\n// "two": "1.2"\n// },\n// "two": {\n// "one": {\n// "one": "2.1.1"\n// }\n// }\n// }\n')))}function c(n){let{getMessageFallback:e,messages:t,onError:o,...s}=n;const c=o||a,u=e||r;return t&&i(t,c),{...s,messages:t,onError:c,getMessageFallback:u}}export{t as I,e as a,r as b,a as d,c as i,o as j};
package/dist/esm/react.js CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("./_IntlProvider.js"),t=require("./_useLocale-89b32eb9.js"),r=require("react"),o=require("./createFormatter-022b2d85.js"),n=require("./initializeConfig-17849dd5.js");require("./IntlContext-381f3ce4.js"),require("intl-messageformat");let s=!1;const a="undefined"==typeof window;function u(){return new Date}exports.IntlProvider=e.IntlProvider,exports.useLocale=t.useLocale,exports.useFormatter=function(){const{formats:e,locale:n,now:s,onError:a,timeZone:u}=t.useIntlContext();return r.useMemo((()=>o.createFormatter({formats:e,locale:n,now:s,onError:a,timeZone:u})),[e,s,n,a,u])},exports.useMessages=function(){const e=t.useIntlContext();if(!e.messages)throw new Error("No messages found. Have you configured them correctly? See https://next-intl-docs.vercel.app/docs/configuration#messages");return e.messages},exports.useNow=function(e){const o=null==e?void 0:e.updateInterval,{now:n}=t.useIntlContext(),[s,a]=r.useState(n||u());return r.useEffect((()=>{if(!o)return;const e=setInterval((()=>{a(u())}),o);return()=>{clearInterval(e)}}),[n,o]),s},exports.useTimeZone=function(){return t.useIntlContext().timeZone},exports.useTranslations=function(e){return function(e,u,i){const{defaultTranslationValues:l,formats:c,getMessageFallback:m,locale:f,messageFormatCache:d,onError:g,timeZone:p}=t.useIntlContext();return e=e[i],u=o.resolveNamespace(u,i),p||s||!a||(s=!0,g(new n.IntlError(n.IntlErrorCode.ENVIRONMENT_FALLBACK,"There is no `timeZone` configured, this can lead to markup mismatches caused by environment differences. Consider adding a global default: https://next-intl-docs.vercel.app/docs/configuration#time-zone"))),r.useMemo((()=>o.createBaseTranslator({messageFormatCache:d,getMessageFallback:m,messages:e,defaultTranslationValues:l,namespace:u,onError:g,formats:c,locale:f,timeZone:p})),[d,m,e,u,g,l,c,f,p])}({"!":t.useIntlContext().messages},e?"!.".concat(e):"!","!")};
1
+ export{IntlProvider}from"./_IntlProvider.js";import{a as e}from"./_useLocale-65297b4e.js";export{u as useLocale}from"./_useLocale-65297b4e.js";import{useMemo as o,useState as t,useEffect as n}from"react";import{r,a,c as s}from"./createFormatter-7ab5b371.js";import{I as i,a as c}from"./initializeConfig-8268c3a9.js";import"./IntlContext-b1dc6cbd.js";import"intl-messageformat";let l=!1;const m="undefined"==typeof window;function f(t){return function(t,n,s){const{defaultTranslationValues:u,formats:f,getMessageFallback:d,locale:g,messageFormatCache:p,onError:v,timeZone:h}=e();return t=t[s],n=r(n,s),h||l||!m||(l=!0,v(new i(c.ENVIRONMENT_FALLBACK,"There is no `timeZone` configured, this can lead to markup mismatches caused by environment differences. Consider adding a global default: https://next-intl-docs.vercel.app/docs/configuration#time-zone"))),o((()=>a({messageFormatCache:p,getMessageFallback:d,messages:t,defaultTranslationValues:u,namespace:n,onError:v,formats:f,locale:g,timeZone:h})),[p,d,t,n,v,u,f,g,h])}({"!":e().messages},t?"!.".concat(t):"!","!")}function d(){return new Date}function g(o){const r=null==o?void 0:o.updateInterval,{now:a}=e(),[s,i]=t(a||d());return n((()=>{if(!r)return;const e=setInterval((()=>{i(d())}),r);return()=>{clearInterval(e)}}),[a,r]),s}function p(){return e().timeZone}function v(){const o=e();if(!o.messages)throw new Error("No messages found. Have you configured them correctly? See https://next-intl-docs.vercel.app/docs/configuration#messages");return o.messages}function h(){const{formats:t,locale:n,now:r,onError:a,timeZone:i}=e();return o((()=>s({formats:t,locale:n,now:r,onError:a,timeZone:i})),[t,r,n,a,i])}export{h as useFormatter,v as useMessages,g as useNow,p as useTimeZone,f as useTranslations};
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("./createFormatter-ee86e24b.js"),r=require("./initializeConfig-63bc7f90.js");require("intl-messageformat"),require("react"),exports.IntlError=e.IntlError,exports.IntlErrorCode=e.IntlErrorCode,exports.createFormatter=e.createFormatter,exports.initializeConfig=r.initializeConfig,exports.createTranslator=function(a){let{getMessageFallback:t=r.defaultGetMessageFallback,messages:s,namespace:o,onError:n=r.defaultOnError,...l}=a;return function(r,a){let{getMessageFallback:t,messages:s,namespace:o,onError:n,...l}=r;return s=s[a],o=e.resolveNamespace(o,a),e.createBaseTranslator({...l,onError:n,getMessageFallback:t,messages:s,namespace:o})}({...l,onError:n,getMessageFallback:t,messages:{"!":s},namespace:o?"!.".concat(o):"!"},"!")};
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("./createFormatter-af98f3a0.js"),r=require("./initializeConfig-63bc7f90.js");require("intl-messageformat"),require("react"),exports.IntlError=e.IntlError,exports.IntlErrorCode=e.IntlErrorCode,exports.createFormatter=e.createFormatter,exports.initializeConfig=r.initializeConfig,exports.createTranslator=function(a){let{getMessageFallback:t=r.defaultGetMessageFallback,messages:s,namespace:o,onError:n=r.defaultOnError,...l}=a;return function(r,a){let{getMessageFallback:t,messages:s,namespace:o,onError:n,...l}=r;return s=s[a],o=e.resolveNamespace(o,a),e.createBaseTranslator({...l,onError:n,getMessageFallback:t,messages:s,namespace:o})}({...l,onError:n,getMessageFallback:t,messages:{"!":s},namespace:o?"!.".concat(o):"!"},"!")};
@@ -1 +1 @@
1
- "use strict";var e=require("intl-messageformat"),t=require("react"),r=require("./initializeConfig-63bc7f90.js");function n(e){return e&&e.__esModule?e:{default:e}}var o=n(e);function i(e,t,r){return(t=function(e){var t=function(e,t){if("object"!=typeof e||null===e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==typeof t?t:String(t)}(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}let a=function(e){return e.MISSING_MESSAGE="MISSING_MESSAGE",e.MISSING_FORMAT="MISSING_FORMAT",e.ENVIRONMENT_FALLBACK="ENVIRONMENT_FALLBACK",e.INSUFFICIENT_PATH="INSUFFICIENT_PATH",e.INVALID_MESSAGE="INVALID_MESSAGE",e.INVALID_KEY="INVALID_KEY",e.FORMATTING_ERROR="FORMATTING_ERROR",e}({});class s extends Error{constructor(e,t){let r=e;t&&(r+=": "+t),super(r),i(this,"code",void 0),i(this,"originalMessage",void 0),this.code=e,t&&(this.originalMessage=t)}}function u(e,t){return e?Object.keys(e).reduce(((r,n)=>(r[n]={timeZone:t,...e[n]},r)),{}):e}function c(e,t,n){const o=r.joinPath(n,t);if(!e)throw new Error(o);let i=e;return t.split(".").forEach((e=>{const t=i[e];if(null==e||null==t)throw new Error(o);i=t})),i}const l=60,f=60*l,m=24*f,E=7*m,d=m*(365/12),I=3*d,S=365*m,g={second:1,seconds:1,minute:l,minutes:l,hour:f,hours:f,day:m,days:m,week:E,weeks:E,month:d,months:d,quarter:I,quarters:I,year:S,years:S};exports.IntlError=s,exports.IntlErrorCode=a,exports.createBaseTranslator=function(e){const n=function(e){let{messages:t,namespace:n,onError:o=r.defaultOnError}=e;try{if(!t)throw new Error(void 0);const e=n?c(t,n):t;if(!e)throw new Error(n);return e}catch(e){const t=new s(a.MISSING_MESSAGE,e.message);return o(t),t}}({messages:e.messages,namespace:e.namespace,onError:e.onError});return function(e){let{defaultTranslationValues:n,formats:i,getMessageFallback:l=r.defaultGetMessageFallback,locale:f,messageFormatCache:m,messagesOrError:E,namespace:d,onError:I,timeZone:S}=e;function g(e,t,r){const n=new s(t,r);return I(n),l({error:n,key:e,namespace:d})}function N(e,I,N){if(E instanceof s)return l({error:E,key:e,namespace:d});const y=E;let A;try{A=c(y,e,d)}catch(t){return g(e,a.MISSING_MESSAGE,t.message)}const T=r.joinPath(f,d,e,String(A));let w;if(null!=m&&m.has(T))w=m.get(T);else{if("object"==typeof A){let t,r;return t=Array.isArray(A)?a.INVALID_MESSAGE:a.INSUFFICIENT_PATH,g(e,t,r)}const t=function(e,t){if(t)return;const r=e.replace(/'([{}])/gi,"$1");return/<|{/.test(r)?void 0:r}(A,I);if(t)return t;try{w=new o.default(A,f,function(e,t){const r=t?{...e,dateTime:u(e.dateTime,t)}:e,n=o.default.formats.date,i=t?u(n,t):n,a=o.default.formats.time,s=t?u(a,t):a;return{...r,date:{...i,...null==r?void 0:r.dateTime},time:{...s,...null==r?void 0:r.dateTime}}}({...i,...N},S))}catch(t){return g(e,a.INVALID_MESSAGE,t.message)}null==m||m.set(T,w)}try{const e=w.format(function(e){if(0===Object.keys(e).length)return;const r={};return Object.keys(e).forEach((n=>{let o=0;const i=e[n];let a;a="function"==typeof i?e=>{const r=i(e);return t.isValidElement(r)?t.cloneElement(r,{key:n+o++}):r}:i,r[n]=a})),r}({...n,...I}));if(null==e)throw new Error(void 0);return t.isValidElement(e)||Array.isArray(e)||"string"==typeof e?e:String(e)}catch(t){return g(e,a.FORMATTING_ERROR,t.message)}}function y(e,t,r){const n=N(e,t,r);return"string"!=typeof n?g(e,a.INVALID_MESSAGE,void 0):n}return y.rich=N,y.markup=(e,t,r)=>{const n=N(e,t,r);if("string"!=typeof n){const t=new s(a.FORMATTING_ERROR,void 0);return I(t),l({error:t,key:e,namespace:d})}return n},y.raw=e=>{if(E instanceof s)return l({error:E,key:e,namespace:d});const t=E;try{return c(t,e,d)}catch(t){return g(e,a.MISSING_MESSAGE,t.message)}},y}({...e,messagesOrError:n})},exports.createFormatter=function(e){let{formats:t,locale:n,now:o,onError:i=r.defaultOnError,timeZone:u}=e;function c(e,t,r,n){let o;try{o=function(e,t){let r;if("string"==typeof t){if(r=null==e?void 0:e[t],!r){const e=new s(a.MISSING_FORMAT,void 0);throw i(e),e}}else r=t;return r}(r,t)}catch(t){return String(e)}try{return n(o)}catch(t){return i(new s(a.FORMATTING_ERROR,t.message)),String(e)}}function I(e){return e instanceof Date||"number"==typeof e?new Date(e):void 0!==(null==e?void 0:e.now)?new Date(e.now):o||(i(new s(a.ENVIRONMENT_FALLBACK,void 0)),new Date)}return{dateTime:function(e,r){return c(e,r,null==t?void 0:t.dateTime,(t=>{var r;return null!==(r=t)&&void 0!==r&&r.timeZone||(u?t={...t,timeZone:u}:i(new s(a.ENVIRONMENT_FALLBACK,void 0))),new Intl.DateTimeFormat(n,t).format(e)}))},number:function(e,r){return c(e,r,null==t?void 0:t.number,(t=>new Intl.NumberFormat(n,t).format(e)))},relativeTime:function(e,t){try{const r=new Date(e),o=I(t),i=(r.getTime()-o.getTime())/1e3,a="number"==typeof t||t instanceof Date||void 0===(null==t?void 0:t.unit)?function(e){const t=Math.abs(e);return t<l?"second":t<f?"minute":t<m?"hour":t<E?"day":t<d?"week":t<S?"month":"year"}(i):t.unit,s=function(e,t){return Math.round(e/g[t])}(i,a);return new Intl.RelativeTimeFormat(n,{numeric:"auto"}).format(s,a)}catch(t){return i(new s(a.FORMATTING_ERROR,t.message)),String(e)}},list:function(e,r){return c(e,r,null==t?void 0:t.list,(t=>new Intl.ListFormat(n,t).format(e)))}}},exports.resolveNamespace=function(e,t){return e===t?void 0:e.slice((t+".").length)};
1
+ "use strict";var e=require("intl-messageformat"),t=require("react"),r=require("./initializeConfig-63bc7f90.js");function n(e){return e&&e.__esModule?e:{default:e}}var o=n(e);function i(e,t,r){return(t=function(e){var t=function(e,t){if("object"!=typeof e||null===e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==typeof t?t:String(t)}(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}let a=function(e){return e.MISSING_MESSAGE="MISSING_MESSAGE",e.MISSING_FORMAT="MISSING_FORMAT",e.ENVIRONMENT_FALLBACK="ENVIRONMENT_FALLBACK",e.INSUFFICIENT_PATH="INSUFFICIENT_PATH",e.INVALID_MESSAGE="INVALID_MESSAGE",e.INVALID_KEY="INVALID_KEY",e.FORMATTING_ERROR="FORMATTING_ERROR",e}({});class s extends Error{constructor(e,t){let r=e;t&&(r+=": "+t),super(r),i(this,"code",void 0),i(this,"originalMessage",void 0),this.code=e,t&&(this.originalMessage=t)}}function u(e,t){return e?Object.keys(e).reduce(((r,n)=>(r[n]={timeZone:t,...e[n]},r)),{}):e}function c(e,t,n){const o=r.joinPath(n,t);if(!e)throw new Error(o);let i=e;return t.split(".").forEach((e=>{const t=i[e];if(null==e||null==t)throw new Error(o);i=t})),i}const l=60,f=60*l,m=24*f,E=7*m,d=m*(365/12),I=3*d,S=365*m,g={second:1,seconds:1,minute:l,minutes:l,hour:f,hours:f,day:m,days:m,week:E,weeks:E,month:d,months:d,quarter:I,quarters:I,year:S,years:S};exports.IntlError=s,exports.IntlErrorCode=a,exports.createBaseTranslator=function(e){const n=function(e){let{messages:t,namespace:n,onError:o=r.defaultOnError}=e;try{if(!t)throw new Error(void 0);const e=n?c(t,n):t;if(!e)throw new Error(n);return e}catch(e){const t=new s(a.MISSING_MESSAGE,e.message);return o(t),t}}({messages:e.messages,namespace:e.namespace,onError:e.onError});return function(e){let{defaultTranslationValues:n,formats:i,getMessageFallback:l=r.defaultGetMessageFallback,locale:f,messageFormatCache:m,messagesOrError:E,namespace:d,onError:I,timeZone:S}=e;function g(e,t,r){const n=new s(t,r);return I(n),l({error:n,key:e,namespace:d})}function y(e,I,y){if(E instanceof s)return l({error:E,key:e,namespace:d});const N=E;let A;try{A=c(N,e,d)}catch(t){return g(e,a.MISSING_MESSAGE,t.message)}const w=r.joinPath(f,d,e,String(A));let T;if(null!=m&&m.has(w))T=m.get(w);else{if("object"==typeof A){let t,r;return t=Array.isArray(A)?a.INVALID_MESSAGE:a.INSUFFICIENT_PATH,g(e,t,r)}const t=function(e,t){if(t)return;const r=e.replace(/'([{}])/gi,"$1");return/<|{/.test(r)?void 0:r}(A,I);if(t)return t;try{T=new o.default(A,f,function(e,t){const r=t?{...e,dateTime:u(e.dateTime,t)}:e,n=o.default.formats.date,i=t?u(n,t):n,a=o.default.formats.time,s=t?u(a,t):a;return{...r,date:{...i,...null==r?void 0:r.dateTime},time:{...s,...null==r?void 0:r.dateTime}}}({...i,...y},S))}catch(t){return g(e,a.INVALID_MESSAGE,t.message)}null==m||m.set(w,T)}try{const e=T.format(function(e){if(0===Object.keys(e).length)return;const r={};return Object.keys(e).forEach((n=>{let o=0;const i=e[n];let a;a="function"==typeof i?e=>{const r=i(e);return t.isValidElement(r)?t.cloneElement(r,{key:n+o++}):r}:i,r[n]=a})),r}({...n,...I}));if(null==e)throw new Error(void 0);return t.isValidElement(e)||Array.isArray(e)||"string"==typeof e?e:String(e)}catch(t){return g(e,a.FORMATTING_ERROR,t.message)}}function N(e,t,r){const n=y(e,t,r);return"string"!=typeof n?g(e,a.INVALID_MESSAGE,void 0):n}return N.rich=y,N.markup=(e,t,r)=>{const n=y(e,t,r);if("string"!=typeof n){const t=new s(a.FORMATTING_ERROR,void 0);return I(t),l({error:t,key:e,namespace:d})}return n},N.raw=e=>{if(E instanceof s)return l({error:E,key:e,namespace:d});const t=E;try{return c(t,e,d)}catch(t){return g(e,a.MISSING_MESSAGE,t.message)}},N}({...e,messagesOrError:n})},exports.createFormatter=function(e){let{formats:t,locale:n,now:o,onError:i=r.defaultOnError,timeZone:u}=e;function c(e,t,r,n){let o;try{o=function(e,t){let r;if("string"==typeof t){if(r=null==e?void 0:e[t],!r){const e=new s(a.MISSING_FORMAT,void 0);throw i(e),e}}else r=t;return r}(r,t)}catch(t){return String(e)}try{return n(o)}catch(t){return i(new s(a.FORMATTING_ERROR,t.message)),String(e)}}function I(e){return e instanceof Date||"number"==typeof e?new Date(e):void 0!==(null==e?void 0:e.now)?new Date(e.now):o||(i(new s(a.ENVIRONMENT_FALLBACK,void 0)),new Date)}return{dateTime:function(e,r){return c(e,r,null==t?void 0:t.dateTime,(t=>{var r;return null!==(r=t)&&void 0!==r&&r.timeZone||(u?t={...t,timeZone:u}:i(new s(a.ENVIRONMENT_FALLBACK,void 0))),new Intl.DateTimeFormat(n,t).format(e)}))},number:function(e,r){return c(e,r,null==t?void 0:t.number,(t=>new Intl.NumberFormat(n,t).format(e)))},relativeTime:function(e,t){try{const r=new Date(e),o=I(t),i=(r.getTime()-o.getTime())/1e3,a="number"==typeof t||t instanceof Date||void 0===(null==t?void 0:t.unit)?function(e){const t=Math.abs(e);return t<l?"second":t<f?"minute":t<m?"hour":t<E?"day":t<d?"week":t<S?"month":"year"}(i):t.unit,s=function(e,t){return Math.round(e/g[t])}(i,a);return new Intl.RelativeTimeFormat(n,{numeric:"second"===a?"auto":"always"}).format(s,a)}catch(t){return i(new s(a.FORMATTING_ERROR,t.message)),String(e)}},list:function(e,r){return c(e,r,null==t?void 0:t.list,(t=>new Intl.ListFormat(n,t).format(e)))}}},exports.resolveNamespace=function(e,t){return e===t?void 0:e.slice((t+".").length)};
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("./createFormatter-ee86e24b.js"),r=require("./core.js"),t=require("./initializeConfig-63bc7f90.js"),s=require("./_IntlProvider.js"),o=require("./react.js"),i=require("./_useLocale-8e23751a.js");require("intl-messageformat"),require("react"),require("./IntlContext-381f3ce4.js"),exports.IntlError=e.IntlError,exports.IntlErrorCode=e.IntlErrorCode,exports.createFormatter=e.createFormatter,exports.createTranslator=r.createTranslator,exports.initializeConfig=t.initializeConfig,exports.IntlProvider=s.IntlProvider,exports.useFormatter=o.useFormatter,exports.useMessages=o.useMessages,exports.useNow=o.useNow,exports.useTimeZone=o.useTimeZone,exports.useTranslations=o.useTranslations,exports.useLocale=i.useLocale;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("./createFormatter-af98f3a0.js"),r=require("./core.js"),t=require("./initializeConfig-63bc7f90.js"),s=require("./_IntlProvider.js"),o=require("./react.js"),i=require("./_useLocale-8e23751a.js");require("intl-messageformat"),require("react"),require("./IntlContext-381f3ce4.js"),exports.IntlError=e.IntlError,exports.IntlErrorCode=e.IntlErrorCode,exports.createFormatter=e.createFormatter,exports.createTranslator=r.createTranslator,exports.initializeConfig=t.initializeConfig,exports.IntlProvider=s.IntlProvider,exports.useFormatter=o.useFormatter,exports.useMessages=o.useMessages,exports.useNow=o.useNow,exports.useTimeZone=o.useTimeZone,exports.useTranslations=o.useTranslations,exports.useLocale=i.useLocale;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("./_IntlProvider.js"),t=require("./_useLocale-8e23751a.js"),r=require("react"),o=require("./createFormatter-ee86e24b.js");require("./initializeConfig-63bc7f90.js"),require("./IntlContext-381f3ce4.js"),require("intl-messageformat");let n=!1;const s="undefined"==typeof window;function a(){return new Date}exports.IntlProvider=e.IntlProvider,exports.useLocale=t.useLocale,exports.useFormatter=function(){const{formats:e,locale:n,now:s,onError:a,timeZone:u}=t.useIntlContext();return r.useMemo((()=>o.createFormatter({formats:e,locale:n,now:s,onError:a,timeZone:u})),[e,s,n,a,u])},exports.useMessages=function(){const e=t.useIntlContext();if(!e.messages)throw new Error(void 0);return e.messages},exports.useNow=function(e){const o=null==e?void 0:e.updateInterval,{now:n}=t.useIntlContext(),[s,u]=r.useState(n||a());return r.useEffect((()=>{if(!o)return;const e=setInterval((()=>{u(a())}),o);return()=>{clearInterval(e)}}),[n,o]),s},exports.useTimeZone=function(){return t.useIntlContext().timeZone},exports.useTranslations=function(e){return function(e,a,u){const{defaultTranslationValues:l,formats:i,getMessageFallback:c,locale:m,messageFormatCache:f,onError:I,timeZone:d}=t.useIntlContext();return e=e[u],a=o.resolveNamespace(a,u),d||n||!s||(n=!0,I(new o.IntlError(o.IntlErrorCode.ENVIRONMENT_FALLBACK,void 0))),r.useMemo((()=>o.createBaseTranslator({messageFormatCache:f,getMessageFallback:c,messages:e,defaultTranslationValues:l,namespace:a,onError:I,formats:i,locale:m,timeZone:d})),[f,c,e,a,I,l,i,m,d])}({"!":t.useIntlContext().messages},e?"!.".concat(e):"!","!")};
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("./_IntlProvider.js"),t=require("./_useLocale-8e23751a.js"),r=require("react"),o=require("./createFormatter-af98f3a0.js");require("./initializeConfig-63bc7f90.js"),require("./IntlContext-381f3ce4.js"),require("intl-messageformat");let n=!1;const s="undefined"==typeof window;function a(){return new Date}exports.IntlProvider=e.IntlProvider,exports.useLocale=t.useLocale,exports.useFormatter=function(){const{formats:e,locale:n,now:s,onError:a,timeZone:u}=t.useIntlContext();return r.useMemo((()=>o.createFormatter({formats:e,locale:n,now:s,onError:a,timeZone:u})),[e,s,n,a,u])},exports.useMessages=function(){const e=t.useIntlContext();if(!e.messages)throw new Error(void 0);return e.messages},exports.useNow=function(e){const o=null==e?void 0:e.updateInterval,{now:n}=t.useIntlContext(),[s,u]=r.useState(n||a());return r.useEffect((()=>{if(!o)return;const e=setInterval((()=>{u(a())}),o);return()=>{clearInterval(e)}}),[n,o]),s},exports.useTimeZone=function(){return t.useIntlContext().timeZone},exports.useTranslations=function(e){return function(e,a,u){const{defaultTranslationValues:l,formats:i,getMessageFallback:c,locale:m,messageFormatCache:f,onError:I,timeZone:d}=t.useIntlContext();return e=e[u],a=o.resolveNamespace(a,u),d||n||!s||(n=!0,I(new o.IntlError(o.IntlErrorCode.ENVIRONMENT_FALLBACK,void 0))),r.useMemo((()=>o.createBaseTranslator({messageFormatCache:f,getMessageFallback:c,messages:e,defaultTranslationValues:l,namespace:a,onError:I,formats:i,locale:m,timeZone:d})),[f,c,e,a,I,l,i,m,d])}({"!":t.useIntlContext().messages},e?"!.".concat(e):"!","!")};
@@ -1,7 +1,8 @@
1
+ import type AbstractIntlMessages from './AbstractIntlMessages';
1
2
  import Formats from './Formats';
2
3
  import IntlError from './IntlError';
3
4
  import TimeZone from './TimeZone';
4
- import { AbstractIntlMessages, RichTranslationValues } from '.';
5
+ import type { RichTranslationValues } from './TranslationValues';
5
6
  /**
6
7
  * Should be used for entry points that configure the library.
7
8
  */
@@ -1,11 +1,10 @@
1
1
  import IntlConfig from './IntlConfig';
2
- import { defaultOnError } from './defaults';
3
2
  /**
4
3
  * Enhances the incoming props with defaults.
5
4
  */
6
- export default function initializeConfig<Props extends IntlConfig>({ getMessageFallback, messages, onError, ...rest }: Props): Omit<Props, "messages" | "onError" | "getMessageFallback"> & {
5
+ export default function initializeConfig<Props extends IntlConfig>({ getMessageFallback, messages, onError, ...rest }: Props): Omit<Props, "onError" | "getMessageFallback" | "messages"> & {
7
6
  messages: import("./AbstractIntlMessages").default | undefined;
8
- onError: typeof defaultOnError;
7
+ onError: (error: import("./IntlError").default) => void;
9
8
  getMessageFallback: (info: {
10
9
  error: import("./IntlError").default;
11
10
  key: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "use-intl",
3
- "version": "3.4.0",
3
+ "version": "3.4.2",
4
4
  "sideEffects": false,
5
5
  "author": "Jan Amann <jan@amann.work>",
6
6
  "description": "Minimal, but complete solution for managing internationalization in React apps.",
@@ -13,7 +13,9 @@
13
13
  "scripts": {
14
14
  "build": "rm -rf dist && rollup -c",
15
15
  "test": "TZ=Europe/Berlin vitest",
16
- "lint": "eslint src test && tsc --noEmit",
16
+ "lint": "pnpm run lint:source && pnpm run lint:package",
17
+ "lint:source": "eslint src test && tsc --noEmit",
18
+ "lint:package": "publint && attw --pack",
17
19
  "prepublishOnly": "CI=true turbo test && turbo lint && turbo build",
18
20
  "size": "size-limit"
19
21
  },
@@ -68,6 +70,7 @@
68
70
  "react": "^16.8.0 || ^17.0.0 || ^18.0.0"
69
71
  },
70
72
  "devDependencies": {
73
+ "@arethetypeswrong/cli": "^0.13.5",
71
74
  "@size-limit/preset-big-lib": "^8.2.6",
72
75
  "@testing-library/react": "^13.0.0",
73
76
  "@types/node": "^20.1.2",
@@ -76,6 +79,7 @@
76
79
  "date-fns": "^2.16.1",
77
80
  "eslint": "^8.54.0",
78
81
  "eslint-config-molindo": "^7.0.0",
82
+ "publint": "^0.2.7",
79
83
  "react": "^18.2.0",
80
84
  "react-dom": "^18.2.0",
81
85
  "rollup": "^3.28.1",
@@ -86,8 +90,8 @@
86
90
  "size-limit": [
87
91
  {
88
92
  "path": "dist/production/index.js",
89
- "limit": "12.385 kB"
93
+ "limit": "12.4 kB"
90
94
  }
91
95
  ],
92
- "gitHead": "7f87617f8db3f4750a048f16f61aaa1af85e8979"
96
+ "gitHead": "2ea59f67b13eea745f11fa27a6d57ec25ed6ac71"
93
97
  }
@@ -1 +0,0 @@
1
- "use strict";var t=require("react").createContext(void 0);exports.IntlContext=t;
@@ -1 +0,0 @@
1
- "use strict";var t=require("react"),e=require("./IntlContext-381f3ce4.js");function r(){const r=t.useContext(e.IntlContext);if(!r)throw new Error("No intl context found. Have you configured the provider?");return r}exports.useIntlContext=r,exports.useLocale=function(){return r().locale};
@@ -1 +0,0 @@
1
- "use strict";var e=require("intl-messageformat"),r=require("react"),t=require("./initializeConfig-17849dd5.js");function n(e){return e&&e.__esModule?e:{default:e}}var o=n(e);function a(e,r){return e?Object.keys(e).reduce(((t,n)=>(t[n]={timeZone:r,...e[n]},t)),{}):e}function s(e,r,n){const o=t.joinPath(n,r);if(!e)throw new Error("No messages available at `".concat(n,"`."));let a=e;return r.split(".").forEach((e=>{const r=a[e];if(null==e||null==r)throw new Error("Could not resolve `".concat(o,"` in messages."));a=r})),a}const i=60,c=60*i,u=24*c,l=7*u,m=u*(365/12),d=3*m,f=365*u,g={second:1,seconds:1,minute:i,minutes:i,hour:c,hours:c,day:u,days:u,week:l,weeks:l,month:m,months:m,quarter:d,quarters:d,year:f,years:f};exports.createBaseTranslator=function(e){const n=function(e){let{messages:r,namespace:n,onError:o=t.defaultOnError}=e;try{if(!r)throw new Error("No messages were configured on the provider.");const e=n?s(r,n):r;if(!e)throw new Error("No messages for namespace `".concat(n,"` found."));return e}catch(e){const r=new t.IntlError(t.IntlErrorCode.MISSING_MESSAGE,e.message);return o(r),r}}({messages:e.messages,namespace:e.namespace,onError:e.onError});return function(e){let{defaultTranslationValues:n,formats:i,getMessageFallback:c=t.defaultGetMessageFallback,locale:u,messageFormatCache:l,messagesOrError:m,namespace:d,onError:f,timeZone:g}=e;function E(e,r,n){const o=new t.IntlError(r,n);return f(o),c({error:o,key:e,namespace:d})}function p(e,f,p){if(m instanceof t.IntlError)return c({error:m,key:e,namespace:d});const I=m;let h;try{h=s(I,e,d)}catch(r){return E(e,t.IntlErrorCode.MISSING_MESSAGE,r.message)}const y=t.joinPath(u,d,e,String(h));let w;if(null!=l&&l.has(y))w=l.get(y);else{if("object"==typeof h){let r,n;return Array.isArray(h)?(r=t.IntlErrorCode.INVALID_MESSAGE,n="Message at `".concat(t.joinPath(d,e),"` resolved to an array, but only strings are supported. See https://next-intl-docs.vercel.app/docs/usage/messages#arrays-of-messages")):(r=t.IntlErrorCode.INSUFFICIENT_PATH,n="Message at `".concat(t.joinPath(d,e),"` resolved to an object, but only strings are supported. Use a `.` to retrieve nested messages. See https://next-intl-docs.vercel.app/docs/usage/messages#structuring-messages")),E(e,r,n)}const r=function(e,r){if(r)return;const t=e.replace(/'([{}])/gi,"$1");return/<|{/.test(t)?void 0:t}(h,f);if(r)return r;try{w=new o.default(h,u,function(e,r){const t=r?{...e,dateTime:a(e.dateTime,r)}:e,n=o.default.formats.date,s=r?a(n,r):n,i=o.default.formats.time,c=r?a(i,r):i;return{...t,date:{...s,...null==t?void 0:t.dateTime},time:{...c,...null==t?void 0:t.dateTime}}}({...i,...p},g))}catch(r){return E(e,t.IntlErrorCode.INVALID_MESSAGE,r.message)}null==l||l.set(y,w)}try{const t=w.format(function(e){if(0===Object.keys(e).length)return;const t={};return Object.keys(e).forEach((n=>{let o=0;const a=e[n];let s;s="function"==typeof a?e=>{const t=a(e);return r.isValidElement(t)?r.cloneElement(t,{key:n+o++}):t}:a,t[n]=s})),t}({...n,...f}));if(null==t)throw new Error("Unable to format `".concat(e,"` in ").concat(d?"namespace `".concat(d,"`"):"messages"));return r.isValidElement(t)||Array.isArray(t)||"string"==typeof t?t:String(t)}catch(r){return E(e,t.IntlErrorCode.FORMATTING_ERROR,r.message)}}function I(e,r,n){const o=p(e,r,n);return"string"!=typeof o?E(e,t.IntlErrorCode.INVALID_MESSAGE,"The message `".concat(e,"` in ").concat(d?"namespace `".concat(d,"`"):"messages"," didn't resolve to a string. If you want to format rich text, use `t.rich` instead.")):o}return I.rich=p,I.markup=(e,r,n)=>{const o=p(e,r,n);if("string"!=typeof o){const r=new t.IntlError(t.IntlErrorCode.FORMATTING_ERROR,"`t.markup` only accepts functions for formatting that receive and return strings.\n\nE.g. t.markup('markup', {b: (chunks) => `<b>${chunks}</b>`})");return f(r),c({error:r,key:e,namespace:d})}return o},I.raw=e=>{if(m instanceof t.IntlError)return c({error:m,key:e,namespace:d});const r=m;try{return s(r,e,d)}catch(r){return E(e,t.IntlErrorCode.MISSING_MESSAGE,r.message)}},I}({...e,messagesOrError:n})},exports.createFormatter=function(e){let{formats:r,locale:n,now:o,onError:a=t.defaultOnError,timeZone:s}=e;function d(e,r,n,o){let s;try{s=function(e,r){let n;if("string"==typeof r){const o=r;if(n=null==e?void 0:e[o],!n){const e=new t.IntlError(t.IntlErrorCode.MISSING_FORMAT,"Format `".concat(o,"` is not available. You can configure it on the provider or provide custom options."));throw a(e),e}}else n=r;return n}(n,r)}catch(r){return String(e)}try{return o(s)}catch(r){return a(new t.IntlError(t.IntlErrorCode.FORMATTING_ERROR,r.message)),String(e)}}function E(e){return e instanceof Date||"number"==typeof e?new Date(e):void 0!==(null==e?void 0:e.now)?new Date(e.now):o||(a(new t.IntlError(t.IntlErrorCode.ENVIRONMENT_FALLBACK,"The `now` parameter wasn't provided and there is no global default configured. Consider adding a global default to avoid markup mismatches caused by environment differences. Learn more: https://next-intl-docs.vercel.app/docs/configuration#now")),new Date)}return{dateTime:function(e,o){return d(e,o,null==r?void 0:r.dateTime,(r=>{var o;return null!==(o=r)&&void 0!==o&&o.timeZone||(s?r={...r,timeZone:s}:a(new t.IntlError(t.IntlErrorCode.ENVIRONMENT_FALLBACK,"The `timeZone` parameter wasn't provided and there is no global default configured. Consider adding a global default to avoid markup mismatches caused by environment differences. Learn more: https://next-intl-docs.vercel.app/docs/configuration#time-zone"))),new Intl.DateTimeFormat(n,r).format(e)}))},number:function(e,t){return d(e,t,null==r?void 0:r.number,(r=>new Intl.NumberFormat(n,r).format(e)))},relativeTime:function(e,r){try{const t=new Date(e),o=E(r),a=(t.getTime()-o.getTime())/1e3,s="number"==typeof r||r instanceof Date||void 0===(null==r?void 0:r.unit)?function(e){const r=Math.abs(e);return r<i?"second":r<c?"minute":r<u?"hour":r<l?"day":r<m?"week":r<f?"month":"year"}(a):r.unit,d=function(e,r){return Math.round(e/g[r])}(a,s);return new Intl.RelativeTimeFormat(n,{numeric:"auto"}).format(d,s)}catch(r){return a(new t.IntlError(t.IntlErrorCode.FORMATTING_ERROR,r.message)),String(e)}},list:function(e,t){return d(e,t,null==r?void 0:r.list,(r=>new Intl.ListFormat(n,r).format(e)))}}},exports.resolveNamespace=function(e,r){return e===r?void 0:e.slice((r+".").length)};
@@ -1 +0,0 @@
1
- "use strict";function e(e,n,t){return(n=function(e){var n=function(e,n){if("object"!=typeof e||null===e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var r=t.call(e,n||"default");if("object"!=typeof r)return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===n?String:Number)(e)}(e,"string");return"symbol"==typeof n?n:String(n)}(n))in e?Object.defineProperty(e,n,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[n]=t,e}let n=function(e){return e.MISSING_MESSAGE="MISSING_MESSAGE",e.MISSING_FORMAT="MISSING_FORMAT",e.ENVIRONMENT_FALLBACK="ENVIRONMENT_FALLBACK",e.INSUFFICIENT_PATH="INSUFFICIENT_PATH",e.INVALID_MESSAGE="INVALID_MESSAGE",e.INVALID_KEY="INVALID_KEY",e.FORMATTING_ERROR="FORMATTING_ERROR",e}({});class t extends Error{constructor(n,t){let r=n;t&&(r+=": "+t),super(r),e(this,"code",void 0),e(this,"originalMessage",void 0),this.code=n,t&&(this.originalMessage=t)}}function r(){for(var e=arguments.length,n=new Array(e),t=0;t<e;t++)n[t]=arguments[t];return n.filter(Boolean).join(".")}function o(e){return r(e.namespace,e.key)}function i(e){console.error(e)}function s(e,n,t){Object.entries(e).forEach((e=>{let[o,i]=e;if(o.includes(".")){let e=o;t&&(e+=" (at ".concat(t,")")),n.push(e)}null!=i&&"object"==typeof i&&s(i,n,r(t,o))}))}function a(e,r){const o=[];s(e,o),o.length>0&&r(new t(n.INVALID_KEY,'Namespace keys can not contain the character "." as this is used to express nesting. Please remove it or replace it with another character.\n\nInvalid '.concat(1===o.length?"key":"keys",": ").concat(o.join(", "),'\n\nIf you\'re migrating from a flat structure, you can convert your messages as follows:\n\nimport {set} from "lodash";\n\nconst input = {\n "one.one": "1.1",\n "one.two": "1.2",\n "two.one.one": "2.1.1"\n};\n\nconst output = Object.entries(input).reduce(\n (acc, [key, value]) => set(acc, key, value),\n {}\n);\n\n// Output:\n//\n// {\n// "one": {\n// "one": "1.1",\n// "two": "1.2"\n// },\n// "two": {\n// "one": {\n// "one": "2.1.1"\n// }\n// }\n// }\n')))}exports.IntlError=t,exports.IntlErrorCode=n,exports.defaultGetMessageFallback=o,exports.defaultOnError=i,exports.initializeConfig=function(e){let{getMessageFallback:n,messages:t,onError:r,...s}=e;const c=r||i,u=n||o;return t&&a(t,c),{...s,messages:t,onError:c,getMessageFallback:u}},exports.joinPath=r;