react-localize
Advanced tools
Comparing version 4.0.0-beta.2 to 5.0.0
@@ -10,2 +10,6 @@ # Change Log | ||
## 2019-05-01 5.0.0 | ||
### Added | ||
- Added `useLocalize` hook. | ||
## 2018-06-19 4.0.0-beta.2 | ||
@@ -12,0 +16,0 @@ ### Added |
@@ -7,3 +7,3 @@ (function (global, factory) { | ||
React = React && React.hasOwnProperty('default') ? React['default'] : React; | ||
var React__default = 'default' in React ? React['default'] : React; | ||
PropTypes = PropTypes && PropTypes.hasOwnProperty('default') ? PropTypes['default'] : PropTypes; | ||
@@ -122,3 +122,3 @@ | ||
var _react2 = _interopRequireDefault(React); | ||
var _react2 = _interopRequireDefault(React__default); | ||
@@ -238,3 +238,3 @@ | ||
return Provider; | ||
}(React.Component); | ||
}(React__default.Component); | ||
@@ -301,3 +301,3 @@ Provider.childContextTypes = (_Provider$childContex = {}, _Provider$childContex[contextProp] = _propTypes2.default.object.isRequired, _Provider$childContex); | ||
return Consumer; | ||
}(React.Component); | ||
}(React__default.Component); | ||
@@ -326,3 +326,3 @@ Consumer.contextTypes = (_Consumer$contextType = {}, _Consumer$contextType[contextProp] = _propTypes2.default.object, _Consumer$contextType); | ||
var _react2 = _interopRequireDefault(React); | ||
var _react2 = _interopRequireDefault(React__default); | ||
@@ -473,2 +473,11 @@ | ||
var useLocalize = function useLocalize() { | ||
if (!React.useContext) { | ||
console.warn('This feature is only available in React >= 16.8'); | ||
return {}; | ||
} | ||
return React.useContext(Localize); | ||
}; | ||
var LocalizationProvider = function (_React$Component) { | ||
@@ -540,3 +549,3 @@ inherits(LocalizationProvider, _React$Component); | ||
return React.createElement( | ||
return React__default.createElement( | ||
Localize.Provider, | ||
@@ -549,3 +558,3 @@ { value: { localize: localize, xLocale: xLocale, debug: debug } }, | ||
return LocalizationProvider; | ||
}(React.Component); | ||
}(React__default.Component); | ||
@@ -576,3 +585,3 @@ LocalizationProvider.propTypes = { | ||
var withLocalization$$1 = function withLocalization$$1(props) { | ||
return React.createElement( | ||
return React__default.createElement( | ||
LocalizationConsumer, | ||
@@ -582,3 +591,3 @@ null, | ||
var localize = _ref.localize; | ||
return React.createElement(Component, _extends({}, props, { | ||
return React__default.createElement(Component, _extends({}, props, { | ||
localize: localize | ||
@@ -594,2 +603,3 @@ })); | ||
exports.useLocalize = useLocalize; | ||
exports.LocalizationProvider = LocalizationProvider; | ||
@@ -596,0 +606,0 @@ exports.LocalizationConsumer = LocalizationConsumer; |
@@ -1,1 +0,1 @@ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("react"),require("prop-types")):"function"==typeof define&&define.amd?define(["exports","react","prop-types"],t):t(e.ReactLocalize={},e.React,e.PropTypes)}(this,function(e,d,o){"use strict";d=d&&d.hasOwnProperty("default")?d.default:d,o=o&&o.hasOwnProperty("default")?o.default:o;var t="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function n(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}function r(e,t){return e(t={exports:{}},t.exports),t.exports}var i="__global_unique_id__",a=function(){return t[i]=(t[i]||0)+1};function u(e){return function(){return e}}var c=function(){};c.thatReturns=u,c.thatReturnsFalse=u(!1),c.thatReturnsTrue=u(!0),c.thatReturnsNull=u(null),c.thatReturnsThis=function(){return this},c.thatReturnsArgument=function(e){return e};var h=c,l=r(function(e,t){t.__esModule=!0;n(d);var u=n(o),c=n(a);n(h);function n(e){return e&&e.__esModule?e:{default:e}}function l(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function s(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function f(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}var p=1073741823;t.default=function(e,a){var t,n,o="__create-react-context-"+(0,c.default)()+"__",r=function(u){function c(){var e,t,n,o;l(this,c);for(var r=arguments.length,i=Array(r),a=0;a<r;a++)i[a]=arguments[a];return(e=t=s(this,u.call.apply(u,[this].concat(i)))).emitter=(n=t.props.value,o=[],{on:function(e){o.push(e)},off:function(t){o=o.filter(function(e){return e!==t})},get:function(){return n},set:function(e,t){n=e,o.forEach(function(e){return e(n,t)})}}),s(t,e)}return f(c,u),c.prototype.getChildContext=function(){var e;return(e={})[o]=this.emitter,e},c.prototype.componentWillReceiveProps=function(e){if(this.props.value!==e.value){var t=this.props.value,n=e.value,o=void 0;((r=t)===(i=n)?0!==r||1/r==1/i:r!=r&&i!=i)?o=0:(o="function"==typeof a?a(t,n):p,0!=(o|=0)&&this.emitter.set(e.value,o))}var r,i},c.prototype.render=function(){return this.props.children},c}(d.Component);r.childContextTypes=((t={})[o]=u.default.object.isRequired,t);var i=function(i){function a(){var e,n;l(this,a);for(var t=arguments.length,o=Array(t),r=0;r<t;r++)o[r]=arguments[r];return(e=n=s(this,i.call.apply(i,[this].concat(o)))).state={value:n.getValue()},n.onUpdate=function(e,t){0!=((0|n.observedBits)&t)&&n.setState({value:n.getValue()})},s(n,e)}return f(a,i),a.prototype.componentWillReceiveProps=function(e){var t=e.observedBits;this.observedBits=null==t?p:t},a.prototype.componentDidMount=function(){this.context[o]&&this.context[o].on(this.onUpdate);var e=this.props.observedBits;this.observedBits=null==e?p:e},a.prototype.componentWillUnmount=function(){this.context[o]&&this.context[o].off(this.onUpdate)},a.prototype.getValue=function(){return this.context[o]?this.context[o].get():e},a.prototype.render=function(){return(Array.isArray(e=this.props.children)?e[0]:e)(this.state.value);var e},a}(d.Component);return i.contextTypes=((n={})[o]=u.default.object,n),{Provider:r,Consumer:i}},e.exports=t.default});n(l);var s=n(r(function(e,t){t.__esModule=!0;var n=r(d),o=r(l);function r(e){return e&&e.__esModule?e:{default:e}}t.default=n.default.createContext||o.default,e.exports=t.default}));function f(e){e+="";var i=Array.prototype.slice.call(arguments,1);return i.length&&(e=e.replace(/(%?)(%([jds]))/g,function(e,t,n,o){var r=i.shift();switch(o){case"s":r=""+r;break;case"d":r=+r;break;case"j":r=JSON.stringify(r)}return t?(i.unshift(r),e):r})),i.length&&(e+=" "+i.join(" ")),""+(e=e.replace(/%{2,2}/g,"%"))}var p=function(){function o(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,o.key,o)}}return function(e,t,n){return t&&o(e.prototype,t),n&&o(e,n),e}}(),y=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var o in n)Object.prototype.hasOwnProperty.call(n,o)&&(e[o]=n[o])}return e},v=function(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t},b=s({localize:function(e){return e},debug:!0,xLocale:!1}),g=function(e){function l(){var e,t,c;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,l);for(var n=arguments.length,o=Array(n),r=0;r<n;r++)o[r]=arguments[r];return(t=c=v(this,(e=l.__proto__||Object.getPrototypeOf(l)).call.apply(e,[this].concat(o))))._localize=function(e,t){var n=c.props,o=n.localize,r=n.xLocale,i=n.messages,a=n.debug,u=o;return"function"!=typeof o&&(u=function(e,t){return a&&console.warn("Unable to localize "+t+", not connected to react-localize"),t}),o!==l.defaultProps.localize?u(i,e,t,r,a):i&&e?i[e]?r?"XXXXXX":u(i,e,t):(a&&console.warn("Unable to localize missing messages or key in arguments for "+e),e):(a&&console.warn("Unable to localize missing messages or key in arguments."),null)},v(c,t)}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}(l,d.Component),p(l,[{key:"render",value:function(){var e=this.props;return d.createElement(b.Provider,{value:{localize:this._localize,xLocale:e.xLocale,debug:e.debug}},this.props.children)}}]),l}();g.defaultProps={debug:!1,localize:function(e,t){var n=2<arguments.length&&void 0!==arguments[2]?arguments[2]:null;return n?f(e[t],n):f(e[t])},xLocale:!1};var _=b.Consumer;e.LocalizationProvider=g,e.LocalizationConsumer=_,e.withLocalization=function(n){var e=function(t){return d.createElement(_,null,function(e){return d.createElement(n,y({},t,{localize:e.localize}))})};return e.displayName="withLocalization("+n.name+")",e},Object.defineProperty(e,"__esModule",{value:!0})}); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("react"),require("prop-types")):"function"==typeof define&&define.amd?define(["exports","react","prop-types"],t):t(e.ReactLocalize={},e.React,e.PropTypes)}(this,function(e,t,o){"use strict";var b="default"in t?t.default:t;o=o&&o.hasOwnProperty("default")?o.default:o;var n="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function r(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}function i(e,t){return e(t={exports:{}},t.exports),t.exports}function a(){return n[u]=(n[u]||0)+1}var u="__global_unique_id__";function l(e){return function(){return e}}function c(){}c.thatReturns=l,c.thatReturnsFalse=l(!1),c.thatReturnsTrue=l(!0),c.thatReturnsNull=l(null),c.thatReturnsThis=function(){return this},c.thatReturnsArgument=function(e){return e};var s=c,f=i(function(e,t){t.__esModule=!0;n(b);var f=n(o),p=n(a);n(s);function n(e){return e&&e.__esModule?e:{default:e}}function d(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function h(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function y(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}var v=1073741823;t.default=function(e,r){var t,n,i,o="__create-react-context-"+(0,p.default)()+"__",a=(y(u,i=b.Component),u.prototype.getChildContext=function(){var e;return(e={})[o]=this.emitter,e},u.prototype.componentWillReceiveProps=function(e){if(this.props.value!==e.value){var t=this.props.value,n=e.value,o=void 0;!function(e,t){return e===t?0!==e||1/e==1/t:e!=e&&t!=t}(t,n)?(o="function"==typeof r?r(t,n):v,0!=(o|=0)&&this.emitter.set(e.value,o)):o=0}},u.prototype.render=function(){return this.props.children},u);function u(){var e,t;d(this,u);for(var n=arguments.length,o=Array(n),r=0;r<n;r++)o[r]=arguments[r];return(e=t=h(this,i.call.apply(i,[this].concat(o)))).emitter=function(n){var o=[];return{on:function(e){o.push(e)},off:function(t){o=o.filter(function(e){return e!==t})},get:function(){return n},set:function(e,t){n=e,o.forEach(function(e){return e(n,t)})}}}(t.props.value),h(t,e)}a.childContextTypes=((t={})[o]=f.default.object.isRequired,t);var l,c=(y(s,l=b.Component),s.prototype.componentWillReceiveProps=function(e){var t=e.observedBits;this.observedBits=null==t?v:t},s.prototype.componentDidMount=function(){this.context[o]&&this.context[o].on(this.onUpdate);var e=this.props.observedBits;this.observedBits=null==e?v:e},s.prototype.componentWillUnmount=function(){this.context[o]&&this.context[o].off(this.onUpdate)},s.prototype.getValue=function(){return this.context[o]?this.context[o].get():e},s.prototype.render=function(){return function(e){return Array.isArray(e)?e[0]:e}(this.props.children)(this.state.value)},s);function s(){var e,n;d(this,s);for(var t=arguments.length,o=Array(t),r=0;r<t;r++)o[r]=arguments[r];return(e=n=h(this,l.call.apply(l,[this].concat(o)))).state={value:n.getValue()},n.onUpdate=function(e,t){0!=((0|n.observedBits)&t)&&n.setState({value:n.getValue()})},h(n,e)}return c.contextTypes=((n={})[o]=f.default.object,n),{Provider:a,Consumer:c}},e.exports=t.default});r(f);var p=r(i(function(e,t){t.__esModule=!0;var n=r(b),o=r(f);function r(e){return e&&e.__esModule?e:{default:e}}t.default=n.default.createContext||o.default,e.exports=t.default}));function d(e){e+="";var i=Array.prototype.slice.call(arguments,1);return i.length&&(e=e.replace(/(%?)(%([jds]))/g,function(e,t,n,o){var r=i.shift();switch(o){case"s":r=""+r;break;case"d":r=+r;break;case"j":r=JSON.stringify(r)}return t?(i.unshift(r),e):r})),i.length&&(e+=" "+i.join(" ")),""+(e=e.replace(/%{2,2}/g,"%"))}var h=function(e,t,n){return t&&y(e.prototype,t),n&&y(e,n),e};function y(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,o.key,o)}}function v(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}var g=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var o in n)Object.prototype.hasOwnProperty.call(n,o)&&(e[o]=n[o])}return e},_=p({localize:function(e){return e},debug:!0,xLocale:!1}),m=(function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}(w,b.Component),h(w,[{key:"render",value:function(){var e=this.props;return b.createElement(_.Provider,{value:{localize:this._localize,xLocale:e.xLocale,debug:e.debug}},this.props.children)}}]),w);function w(){var e,t,l;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,w);for(var n=arguments.length,o=Array(n),r=0;r<n;r++)o[r]=arguments[r];return(t=l=v(this,(e=w.__proto__||Object.getPrototypeOf(w)).call.apply(e,[this].concat(o))))._localize=function(e,t){var n=l.props,o=n.localize,r=n.xLocale,i=n.messages,a=n.debug,u=o;return"function"!=typeof o&&(u=function(e,t){return a&&console.warn("Unable to localize "+t+", not connected to react-localize"),t}),o!==w.defaultProps.localize?u(i,e,t,r,a):i&&e?i[e]?r?"XXXXXX":u(i,e,t):(a&&console.warn("Unable to localize missing messages or key in arguments for "+e),e):(a&&console.warn("Unable to localize missing messages or key in arguments."),null)},v(l,t)}m.defaultProps={debug:!1,localize:function(e,t){var n=2<arguments.length&&void 0!==arguments[2]?arguments[2]:null;return n?d(e[t],n):d(e[t])},xLocale:!1};var x=_.Consumer;e.useLocalize=function(){return t.useContext?t.useContext(_):(console.warn("This feature is only available in React >= 16.8"),{})},e.LocalizationProvider=m,e.LocalizationConsumer=x,e.withLocalization=function(n){function e(t){return b.createElement(x,null,function(e){return b.createElement(n,g({},t,{localize:e.localize}))})}return e.displayName="withLocalization("+n.name+")",e},Object.defineProperty(e,"__esModule",{value:!0})}); |
@@ -1,4 +0,4 @@ | ||
import { LocalizationProvider, LocalizationConsumer } from './react-localize'; | ||
import { useLocalize, LocalizationProvider, LocalizationConsumer } from './react-localize'; | ||
import withLocalization from './withLocalization'; | ||
export { LocalizationProvider, LocalizationConsumer, withLocalization }; | ||
export { useLocalize, LocalizationProvider, LocalizationConsumer, withLocalization }; |
@@ -9,3 +9,3 @@ var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
import React from 'react'; | ||
import React, { useContext } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
@@ -25,2 +25,11 @@ import createReactContext from 'create-react-context'; | ||
export var useLocalize = function useLocalize() { | ||
if (!useContext) { | ||
console.warn('This feature is only available in React >= 16.8'); | ||
return {}; | ||
} | ||
return useContext(Localize); | ||
}; | ||
export var LocalizationProvider = function (_React$Component) { | ||
@@ -27,0 +36,0 @@ _inherits(LocalizationProvider, _React$Component); |
'use strict'; | ||
exports.__esModule = true; | ||
exports.withLocalization = exports.LocalizationConsumer = exports.LocalizationProvider = undefined; | ||
exports.withLocalization = exports.LocalizationConsumer = exports.LocalizationProvider = exports.useLocalize = undefined; | ||
@@ -14,4 +14,5 @@ var _reactLocalize = require('./react-localize'); | ||
exports.useLocalize = _reactLocalize.useLocalize; | ||
exports.LocalizationProvider = _reactLocalize.LocalizationProvider; | ||
exports.LocalizationConsumer = _reactLocalize.LocalizationConsumer; | ||
exports.withLocalization = _withLocalization2.default; |
'use strict'; | ||
exports.__esModule = true; | ||
exports.LocalizationConsumer = exports.LocalizationProvider = undefined; | ||
exports.LocalizationConsumer = exports.LocalizationProvider = exports.useLocalize = undefined; | ||
@@ -32,2 +32,11 @@ var _react = require('react'); | ||
const useLocalize = exports.useLocalize = () => { | ||
if (!_react.useContext) { | ||
console.warn('This feature is only available in React >= 16.8'); | ||
return {}; | ||
} | ||
return (0, _react.useContext)(Localize); | ||
}; | ||
class LocalizationProvider extends _react2.default.Component { | ||
@@ -34,0 +43,0 @@ constructor(...args) { |
{ | ||
"name": "react-localize", | ||
"version": "4.0.0-beta.2", | ||
"version": "5.0.0", | ||
"description": "A simple context wrapper and text localization component for localizing strings", | ||
@@ -20,3 +20,3 @@ "main": "lib/index.js", | ||
"prepublish": "in-publish && yarn run test && yarn run build || not-in-publish", | ||
"test": "jest --coverage && cat ./coverage/lcov.info | node_modules/.bin/coveralls" | ||
"test": "jest --coverage" | ||
}, | ||
@@ -59,3 +59,4 @@ "repository": { | ||
"jest": "^22.4.3", | ||
"prop-types": "15.5", | ||
"jest-dom": "3.1.4", | ||
"prop-types": "~15.6.2", | ||
"react": "^16.3.0", | ||
@@ -65,3 +66,3 @@ "react-dom": "^16.3.0", | ||
"rollup": "^0.45.1", | ||
"rollup-plugin-babel": "^2.7.1", | ||
"rollup-plugin-babel": "^3.0.5", | ||
"rollup-plugin-commonjs": "^8.2.6", | ||
@@ -73,2 +74,3 @@ "rollup-plugin-node-resolve": "^3.0.0", | ||
"jest": { | ||
"testURL": "http://localhost/", | ||
"coverageDirectory": "./coverage/", | ||
@@ -75,0 +77,0 @@ "collectCoverage": true |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
46479
789
2
25
1