anu-verzum 1.5.0 → 1.6.0

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
@@ -4,6 +4,7 @@
4
4
 
5
5
  <h3>@author: <strong>Anubis-programmer</strong></h3>
6
6
  <h3>@license: <strong>MIT</strong></h3>
7
+ <h3>@version: <strong>1.6.0</strong></h3>
7
8
 
8
9
  <br>
9
10
 
@@ -17,7 +17,7 @@ class Component {
17
17
  this.state = this.state || {};
18
18
  }
19
19
  setState(partialState = {}) {
20
- let partialStateObject = this.state;
20
+ let partialStateObject = {};
21
21
  let partialStateCallback;
22
22
  if (typeof partialState === 'object') {
23
23
  partialStateObject = {
@@ -49,6 +49,16 @@ const IntlProvider = ({
49
49
  return undefined;
50
50
  }
51
51
  };
52
+ const interpolateValues = (text, values) => {
53
+ let result = text;
54
+ Object.keys(values).forEach(key => {
55
+ const variablePattern = `{${key}}`;
56
+ if (result.indexOf(variablePattern) > -1) {
57
+ result = result.replace(new RegExp(`\\{${key}\\}`, 'g'), String(values[key]));
58
+ }
59
+ });
60
+ return result;
61
+ };
52
62
  const FormattedMessage = ({
53
63
  id,
54
64
  values,
@@ -58,7 +68,7 @@ const FormattedMessage = ({
58
68
  messages
59
69
  }
60
70
  }) => {
61
- let textValue = '';
71
+ let textValue;
62
72
  try {
63
73
  if (messages && messages[id]) {
64
74
  textValue = messages[id];
@@ -71,12 +81,7 @@ const FormattedMessage = ({
71
81
  throw new Error('No text or fallback value to return.');
72
82
  } else {
73
83
  if (values && typeof values === 'object' && values !== null) {
74
- Object.keys(values).forEach(key => {
75
- const variablePattern = `{${key}}`;
76
- if (textValue.indexOf(variablePattern) > -1) {
77
- textValue = textValue.replace(variablePattern, String(values[key]));
78
- }
79
- });
84
+ textValue = interpolateValues(textValue, values);
80
85
  }
81
86
  return (0, _elements.createElement)(_elements.TEXT_ELEMENT, {
82
87
  nodeValue: textValue
@@ -104,12 +109,7 @@ const formatMessage = (id, values, defaultMessage) => {
104
109
  console.error(err);
105
110
  }
106
111
  if (values && typeof values === 'object' && values !== null) {
107
- Object.keys(values).forEach(key => {
108
- const variablePattern = `{${key}}`;
109
- if (textValue.indexOf(variablePattern) > -1) {
110
- textValue = textValue.replace(variablePattern, String(values[key]));
111
- }
112
- });
112
+ textValue = interpolateValues(textValue, values);
113
113
  }
114
114
  return textValue;
115
115
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "anu-verzum",
3
- "version": "1.5.0",
3
+ "version": "1.6.0",
4
4
  "description": "A \"React-like\" UI library that supports JSX syntax, Redux-like state management, array-rendering, i18n, routing and many more.",
5
5
  "keywords": [
6
6
  "anu-verzum",