Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

use-intl

Package Overview
Dependencies
Maintainers
1
Versions
240
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

use-intl - npm Package Compare versions

Comparing version 1.3.1 to 1.3.2

LICENSE

6

dist/use-intl.cjs.development.js

@@ -358,5 +358,7 @@ 'use strict';

throw new Error("development" !== "production" ? "Unable to format " + [namespace, key].join('.') : undefined);
}
} // Limit the function signature to return strings or React elements
return formattedMessage;
return React.isValidElement(formattedMessage) || // Arrays of React elements
Array.isArray(formattedMessage) || typeof formattedMessage === 'string' ? formattedMessage : String(formattedMessage);
} catch (error) {

@@ -363,0 +365,0 @@ return getFallbackFromError(exports.IntlErrorCode.FORMATTING_ERROR, error.message);

@@ -1,2 +0,2 @@

"use strict";function r(r){return r&&"object"==typeof r&&"default"in r?r.default:r}Object.defineProperty(exports,"__esModule",{value:!0});var t=require("react"),e=r(t),n=r(require("intl-messageformat"));function o(){return(o=Object.assign||function(r){for(var t=1;t<arguments.length;t++){var e=arguments[t];for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(r[n]=e[n])}return r}).apply(this,arguments)}function u(r){return(u=Object.setPrototypeOf?Object.getPrototypeOf:function(r){return r.__proto__||Object.getPrototypeOf(r)})(r)}function a(r,t){return(a=Object.setPrototypeOf||function(r,t){return r.__proto__=t,r})(r,t)}function i(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],(function(){}))),!0}catch(r){return!1}}function c(r,t,e){return(c=i()?Reflect.construct:function(r,t,e){var n=[null];n.push.apply(n,t);var o=new(Function.bind.apply(r,n));return e&&a(o,e.prototype),o}).apply(null,arguments)}function f(r){var t="function"==typeof Map?new Map:void 0;return(f=function(r){if(null===r||-1===Function.toString.call(r).indexOf("[native code]"))return r;if("function"!=typeof r)throw new TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(r))return t.get(r);t.set(r,e)}function e(){return c(r,arguments,u(this).constructor)}return e.prototype=Object.create(r.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),a(e,r)})(r)}var l,s=t.createContext(void 0);function p(r){return[r.namespace,r.key].filter((function(r){return null!=r})).join(".")}(l=exports.IntlErrorCode||(exports.IntlErrorCode={})).MISSING_MESSAGE="MISSING_MESSAGE",l.MISSING_FORMAT="MISSING_FORMAT",l.INSUFFICIENT_PATH="INSUFFICIENT_PATH",l.INVALID_MESSAGE="INVALID_MESSAGE",l.FORMATTING_ERROR="FORMATTING_ERROR";var v=function(r){var t,e;function n(t,e){var n,o=t;return e&&(o+=": "+e),(n=r.call(this,o)||this).code=t,e&&(n.originalMessage=e),n}return e=r,(t=n).prototype=Object.create(e.prototype),t.prototype.constructor=t,t.__proto__=e,n}(f(Error));function d(){var r=t.useContext(s);if(!r)throw new Error(void 0);return r}function I(r,t,e){if(!r)throw new Error(void 0);var n=r;return t.split(".").forEach((function(r){var t=n[r];if(null==r||null==t)throw new Error(void 0);n=t})),n}function E(){return new Date}exports.IntlError=v,exports.IntlProvider=function(r){var t=r.children,n=r.onError,u=void 0===n?console.error:n,a=r.getMessageFallback,i=void 0===a?p:a,c=function(r,t){if(null==r)return{};var e,n,o={},u=Object.keys(r);for(n=0;n<u.length;n++)t.indexOf(e=u[n])>=0||(o[e]=r[e]);return o}(r,["children","onError","getMessageFallback"]);return e.createElement(s.Provider,{value:o({},c,{onError:u,getMessageFallback:i})},t)},exports.useIntl=function(){var r=d(),t=r.formats,e=r.locale,n=r.now,u=r.onError,a=r.timeZone;function i(r,t,e,n){var o;try{o=function(r,t){var e;if("string"==typeof t){if(!(e=null==r?void 0:r[t])){var n=new v(exports.IntlErrorCode.MISSING_FORMAT,void 0);throw u(n),n}}else e=t;return e}(e,t)}catch(t){return String(r)}try{return n(o)}catch(t){return u(new v(exports.IntlErrorCode.FORMATTING_ERROR,t.message)),String(r)}}return{formatDateTime:function(r,n){return i(r,n,null==t?void 0:t.dateTime,(function(t){var n;return!a||null!=(n=t)&&n.timeZone||(t=o({},t,{timeZone:a})),new Intl.DateTimeFormat(e,t).format(r)}))},formatNumber:function(r,n){return i(r,n,null==t?void 0:t.number,(function(t){return new Intl.NumberFormat(e,t).format(r)}))},formatRelativeTime:function(r,t){try{if(!t){if(!n)throw new Error(void 0);t=n}var o=r instanceof Date?r:new Date(r),a=t instanceof Date?t:new Date(t),i=function(r){var t,e,n=Math.abs(r);return n<60?(e="second",t=Math.round(r)):n<3600?(e="minute",t=Math.round(r/60)):n<86400?(e="hour",t=Math.round(r/3600)):n<604800?(e="day",t=Math.round(r/86400)):n<2628e3?(e="week",t=Math.round(r/604800)):n<31536e3?(e="month",t=Math.round(r/2628e3)):(e="year",t=Math.round(r/31536e3)),{value:t,unit:e}}((o.getTime()-a.getTime())/1e3),c=i.unit,f=i.value;return new Intl.RelativeTimeFormat(e,{numeric:"auto"}).format(f,c)}catch(t){return u(new v(exports.IntlErrorCode.FORMATTING_ERROR,t.message)),String(r)}}}},exports.useNow=function(r){var e=null==r?void 0:r.updateInterval,n=d().now,o=t.useState(n||E()),u=o[0],a=o[1];return t.useEffect((function(){if(e){var r=setInterval((function(){a(E())}),e);return function(){clearInterval(r)}}}),[n,e]),u},exports.useTranslations=function(r){var e=d(),u=e.formats,a=e.getMessageFallback,i=e.locale,c=e.messages,f=e.onError,l=t.useRef({}),s=t.useMemo((function(){try{var t=r?I(c,r):c;if(!t)throw new Error(void 0);return t}catch(r){var e=new v(exports.IntlErrorCode.MISSING_MESSAGE,r.message);return f(e),e}}),[c,r,f]);return t.useCallback((function(e,c,p){var d,E=l.current;function m(t,n){var o=new v(t,n);return f(o),a({error:o,key:e,namespace:r})}if(s instanceof v)return a({error:s,key:e,namespace:r});var y,h=s;if(null!=(d=E[i])&&d[e])y=E[i][e];else{var M;try{M=I(h,e)}catch(r){return m(exports.IntlErrorCode.MISSING_MESSAGE,r.message)}if("object"==typeof M)return m(exports.IntlErrorCode.INSUFFICIENT_PATH,void 0);try{y=new n(M,i,function(r){return o({},r,{date:null==r?void 0:r.dateTime,time:null==r?void 0:r.dateTime})}(o({},u,p)))}catch(r){return m(exports.IntlErrorCode.INVALID_MESSAGE,r.message)}E[i]||(E[i]={}),E[i][e]=y}try{var S=y.format(function(r){if(!r)return r;var e={};return Object.keys(r).forEach((function(n){var o=r[n];e[n]="function"==typeof o?function(r){var e=o(r);return t.isValidElement(e)?t.cloneElement(e,{key:e.key||n+String(r)}):e}:o})),e}(c));if(null==S)throw new Error(void 0);return S}catch(r){return m(exports.IntlErrorCode.FORMATTING_ERROR,r.message)}}),[a,u,i,s,r,f])};
"use strict";function r(r){return r&&"object"==typeof r&&"default"in r?r.default:r}Object.defineProperty(exports,"__esModule",{value:!0});var t=require("react"),e=r(t),n=r(require("intl-messageformat"));function o(){return(o=Object.assign||function(r){for(var t=1;t<arguments.length;t++){var e=arguments[t];for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(r[n]=e[n])}return r}).apply(this,arguments)}function u(r){return(u=Object.setPrototypeOf?Object.getPrototypeOf:function(r){return r.__proto__||Object.getPrototypeOf(r)})(r)}function a(r,t){return(a=Object.setPrototypeOf||function(r,t){return r.__proto__=t,r})(r,t)}function i(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],(function(){}))),!0}catch(r){return!1}}function c(r,t,e){return(c=i()?Reflect.construct:function(r,t,e){var n=[null];n.push.apply(n,t);var o=new(Function.bind.apply(r,n));return e&&a(o,e.prototype),o}).apply(null,arguments)}function f(r){var t="function"==typeof Map?new Map:void 0;return(f=function(r){if(null===r||-1===Function.toString.call(r).indexOf("[native code]"))return r;if("function"!=typeof r)throw new TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(r))return t.get(r);t.set(r,e)}function e(){return c(r,arguments,u(this).constructor)}return e.prototype=Object.create(r.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),a(e,r)})(r)}var l,s=t.createContext(void 0);function p(r){return[r.namespace,r.key].filter((function(r){return null!=r})).join(".")}(l=exports.IntlErrorCode||(exports.IntlErrorCode={})).MISSING_MESSAGE="MISSING_MESSAGE",l.MISSING_FORMAT="MISSING_FORMAT",l.INSUFFICIENT_PATH="INSUFFICIENT_PATH",l.INVALID_MESSAGE="INVALID_MESSAGE",l.FORMATTING_ERROR="FORMATTING_ERROR";var v=function(r){var t,e;function n(t,e){var n,o=t;return e&&(o+=": "+e),(n=r.call(this,o)||this).code=t,e&&(n.originalMessage=e),n}return e=r,(t=n).prototype=Object.create(e.prototype),t.prototype.constructor=t,t.__proto__=e,n}(f(Error));function d(){var r=t.useContext(s);if(!r)throw new Error(void 0);return r}function E(r,t,e){if(!r)throw new Error(void 0);var n=r;return t.split(".").forEach((function(r){var t=n[r];if(null==r||null==t)throw new Error(void 0);n=t})),n}function I(){return new Date}exports.IntlError=v,exports.IntlProvider=function(r){var t=r.children,n=r.onError,u=void 0===n?console.error:n,a=r.getMessageFallback,i=void 0===a?p:a,c=function(r,t){if(null==r)return{};var e,n,o={},u=Object.keys(r);for(n=0;n<u.length;n++)t.indexOf(e=u[n])>=0||(o[e]=r[e]);return o}(r,["children","onError","getMessageFallback"]);return e.createElement(s.Provider,{value:o({},c,{onError:u,getMessageFallback:i})},t)},exports.useIntl=function(){var r=d(),t=r.formats,e=r.locale,n=r.now,u=r.onError,a=r.timeZone;function i(r,t,e,n){var o;try{o=function(r,t){var e;if("string"==typeof t){if(!(e=null==r?void 0:r[t])){var n=new v(exports.IntlErrorCode.MISSING_FORMAT,void 0);throw u(n),n}}else e=t;return e}(e,t)}catch(t){return String(r)}try{return n(o)}catch(t){return u(new v(exports.IntlErrorCode.FORMATTING_ERROR,t.message)),String(r)}}return{formatDateTime:function(r,n){return i(r,n,null==t?void 0:t.dateTime,(function(t){var n;return!a||null!=(n=t)&&n.timeZone||(t=o({},t,{timeZone:a})),new Intl.DateTimeFormat(e,t).format(r)}))},formatNumber:function(r,n){return i(r,n,null==t?void 0:t.number,(function(t){return new Intl.NumberFormat(e,t).format(r)}))},formatRelativeTime:function(r,t){try{if(!t){if(!n)throw new Error(void 0);t=n}var o=r instanceof Date?r:new Date(r),a=t instanceof Date?t:new Date(t),i=function(r){var t,e,n=Math.abs(r);return n<60?(e="second",t=Math.round(r)):n<3600?(e="minute",t=Math.round(r/60)):n<86400?(e="hour",t=Math.round(r/3600)):n<604800?(e="day",t=Math.round(r/86400)):n<2628e3?(e="week",t=Math.round(r/604800)):n<31536e3?(e="month",t=Math.round(r/2628e3)):(e="year",t=Math.round(r/31536e3)),{value:t,unit:e}}((o.getTime()-a.getTime())/1e3),c=i.unit,f=i.value;return new Intl.RelativeTimeFormat(e,{numeric:"auto"}).format(f,c)}catch(t){return u(new v(exports.IntlErrorCode.FORMATTING_ERROR,t.message)),String(r)}}}},exports.useNow=function(r){var e=null==r?void 0:r.updateInterval,n=d().now,o=t.useState(n||I()),u=o[0],a=o[1];return t.useEffect((function(){if(e){var r=setInterval((function(){a(I())}),e);return function(){clearInterval(r)}}}),[n,e]),u},exports.useTranslations=function(r){var e=d(),u=e.formats,a=e.getMessageFallback,i=e.locale,c=e.messages,f=e.onError,l=t.useRef({}),s=t.useMemo((function(){try{var t=r?E(c,r):c;if(!t)throw new Error(void 0);return t}catch(r){var e=new v(exports.IntlErrorCode.MISSING_MESSAGE,r.message);return f(e),e}}),[c,r,f]);return t.useCallback((function(e,c,p){var d,I=l.current;function m(t,n){var o=new v(t,n);return f(o),a({error:o,key:e,namespace:r})}if(s instanceof v)return a({error:s,key:e,namespace:r});var y,h=s;if(null!=(d=I[i])&&d[e])y=I[i][e];else{var S;try{S=E(h,e)}catch(r){return m(exports.IntlErrorCode.MISSING_MESSAGE,r.message)}if("object"==typeof S)return m(exports.IntlErrorCode.INSUFFICIENT_PATH,void 0);try{y=new n(S,i,function(r){return o({},r,{date:null==r?void 0:r.dateTime,time:null==r?void 0:r.dateTime})}(o({},u,p)))}catch(r){return m(exports.IntlErrorCode.INVALID_MESSAGE,r.message)}I[i]||(I[i]={}),I[i][e]=y}try{var M=y.format(function(r){if(!r)return r;var e={};return Object.keys(r).forEach((function(n){var o=r[n];e[n]="function"==typeof o?function(r){var e=o(r);return t.isValidElement(e)?t.cloneElement(e,{key:e.key||n+String(r)}):e}:o})),e}(c));if(null==M)throw new Error(void 0);return t.isValidElement(M)||Array.isArray(M)||"string"==typeof M?M:String(M)}catch(r){return m(exports.IntlErrorCode.FORMATTING_ERROR,r.message)}}),[a,u,i,s,r,f])};
//# sourceMappingURL=use-intl.cjs.production.min.js.map

@@ -353,5 +353,7 @@ import React, { createContext, useContext, useRef, useMemo, useCallback, isValidElement, cloneElement, useState, useEffect } from 'react';

throw new Error(process.env.NODE_ENV !== "production" ? "Unable to format " + [namespace, key].join('.') : undefined);
}
} // Limit the function signature to return strings or React elements
return formattedMessage;
return isValidElement(formattedMessage) || // Arrays of React elements
Array.isArray(formattedMessage) || typeof formattedMessage === 'string' ? formattedMessage : String(formattedMessage);
} catch (error) {

@@ -358,0 +360,0 @@ return getFallbackFromError(IntlErrorCode.FORMATTING_ERROR, error.message);

@@ -1,2 +0,2 @@

import { ReactNode } from 'react';
import { ReactElement, ReactNode, ReactNodeArray } from 'react';
import Formats from './Formats';

@@ -11,2 +11,2 @@ /**

*/
export default function useTranslations(namespace?: string): (key: string, values?: Record<string, string | number | boolean | Date | ((children: ReactNode) => ReactNode) | null | undefined> | undefined, formats?: Partial<Formats> | undefined) => {};
export default function useTranslations(namespace?: string): (key: string, values?: Record<string, string | number | boolean | Date | ((children: ReactNode) => ReactNode) | null | undefined> | undefined, formats?: Partial<Formats> | undefined) => string | ReactElement | ReactNodeArray;
{
"name": "use-intl",
"version": "1.3.1",
"version": "1.3.2",
"sideEffects": false,

@@ -47,3 +47,4 @@ "author": "Jan Amann <jan@amann.me>",

"node": ">=10"
}
},
"gitHead": "b5151ddcdc615a364d48acc1a0e70fe4678ab042"
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc