@zohodesk/i18n 1.0.0-beta.3 → 1.0.0-beta.30

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.
Files changed (60) hide show
  1. package/README.md +116 -2
  2. package/es/I18NContext.js +1 -2
  3. package/es/components/DateTimeDiffFormat.js +192 -200
  4. package/es/components/FormatText.js +4 -25
  5. package/es/components/HOCI18N.js +33 -45
  6. package/es/components/I18N.js +48 -63
  7. package/es/components/I18NProvider.js +59 -85
  8. package/es/components/PluralFormat.js +29 -48
  9. package/es/components/UserTimeDiffFormat.js +65 -74
  10. package/es/components/__tests__/DateTimeDiffFormat.spec.js +868 -657
  11. package/es/components/__tests__/FormatText.spec.js +20 -17
  12. package/es/components/__tests__/HOCI18N.spec.js +18 -22
  13. package/es/components/__tests__/I18N.spec.js +20 -19
  14. package/es/components/__tests__/I18NProvider.spec.js +36 -45
  15. package/es/components/__tests__/PluralFormat.spec.js +20 -17
  16. package/es/components/__tests__/UserTimeDiffFormat.spec.js +1343 -1095
  17. package/es/index.js +2 -6
  18. package/es/utils/__tests__/jsxTranslations.spec.js +174 -0
  19. package/es/utils/index.js +592 -0
  20. package/es/utils/jsxTranslations.js +193 -0
  21. package/lib/I18NContext.js +6 -6
  22. package/lib/components/DateTimeDiffFormat.js +151 -123
  23. package/lib/components/FormatText.js +32 -22
  24. package/lib/components/HOCI18N.js +47 -23
  25. package/lib/components/I18N.js +62 -36
  26. package/lib/components/I18NProvider.js +82 -70
  27. package/lib/components/PluralFormat.js +42 -32
  28. package/lib/components/UserTimeDiffFormat.js +79 -56
  29. package/lib/components/__tests__/DateTimeDiffFormat.spec.js +815 -629
  30. package/lib/components/__tests__/FormatText.spec.js +23 -25
  31. package/lib/components/__tests__/HOCI18N.spec.js +26 -34
  32. package/lib/components/__tests__/I18N.spec.js +21 -26
  33. package/lib/components/__tests__/I18NProvider.spec.js +43 -51
  34. package/lib/components/__tests__/PluralFormat.spec.js +24 -28
  35. package/lib/components/__tests__/UserTimeDiffFormat.spec.js +1256 -1039
  36. package/lib/index.js +85 -110
  37. package/lib/utils/__tests__/jsxTranslations.spec.js +183 -0
  38. package/lib/utils/index.js +658 -0
  39. package/lib/utils/jsxTranslations.js +242 -0
  40. package/package.json +3 -2
  41. package/src/components/DateTimeDiffFormat.js +86 -55
  42. package/src/components/I18N.js +2 -0
  43. package/src/components/I18NProvider.js +34 -25
  44. package/src/components/UserTimeDiffFormat.js +24 -18
  45. package/src/index.js +7 -9
  46. package/src/utils/__tests__/jsxTranslations.spec.js +213 -0
  47. package/src/utils/index.js +632 -0
  48. package/src/utils/jsxTranslations.js +180 -0
  49. package/es/components/NewDateFormat.js +0 -50
  50. package/es/offset.js +0 -629
  51. package/es/timezones.js +0 -118
  52. package/es/utils.js +0 -621
  53. package/lib/components/NewDateFormat.js +0 -68
  54. package/lib/offset.js +0 -634
  55. package/lib/timezones.js +0 -129
  56. package/lib/utils.js +0 -651
  57. package/src/components/NewDateFormat.js +0 -60
  58. package/src/offset.js +0 -629
  59. package/src/timezones.js +0 -113
  60. package/src/utils.js +0 -648
package/lib/timezones.js DELETED
@@ -1,129 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.getTimezoneOffset = exports.unpack = undefined;
7
-
8
- var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
9
-
10
- var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();
11
-
12
- var _offset = require('./offset');
13
-
14
- function charCodeToInt(charCode) {
15
- if (charCode > 96) {
16
- return charCode - 87;
17
- } else if (charCode > 64) {
18
- return charCode - 29;
19
- }
20
- return charCode - 48;
21
- }
22
-
23
- function unpackBase60(string) {
24
- var i = 0,
25
- parts = string.split('.'),
26
- _parts = _slicedToArray(parts, 1),
27
- whole = _parts[0],
28
- fractional = parts[1] || '',
29
- multiplier = 1,
30
- num = void 0,
31
- out = 0,
32
- sign = 1;
33
-
34
- // handle negative numbers
35
- if (string.charCodeAt(0) === 45) {
36
- i = 1;
37
- sign = -1;
38
- }
39
-
40
- // handle digits before the decimal
41
- for (i; i < whole.length; i++) {
42
- num = charCodeToInt(whole.charCodeAt(i));
43
- out = 60 * out + num;
44
- }
45
-
46
- // handle digits after the decimal
47
- for (i = 0; i < fractional.length; i++) {
48
- multiplier = multiplier / 60;
49
- num = charCodeToInt(fractional.charCodeAt(i));
50
- out += num * multiplier;
51
- }
52
-
53
- return out * sign;
54
- }
55
-
56
- function arrayToInt(array) {
57
- for (var i = 0; i < array.length; i++) {
58
- array[i] = unpackBase60(array[i]);
59
- }
60
- }
61
-
62
- function intToUntil(array, length) {
63
- for (var i = 0; i < length; i++) {
64
- array[i] = Math.round((array[i - 1] || 0) + array[i] * 60000); // minutes to milliseconds
65
- }
66
-
67
- array[length - 1] = Infinity;
68
- }
69
-
70
- function mapIndices(source, indices) {
71
- var out = [],
72
- i = void 0;
73
-
74
- for (i = 0; i < indices.length; i++) {
75
- out[i] = source[indices[i]];
76
- }
77
-
78
- return out;
79
- }
80
-
81
- function unpack(string) {
82
- if (string) {
83
- var data = string.split('|'),
84
- offsets = data[0].split(' '),
85
- indices = data[1].split(''),
86
- untils = data[2].split(' ');
87
-
88
- arrayToInt(offsets);
89
- arrayToInt(indices);
90
- arrayToInt(untils);
91
-
92
- intToUntil(untils, indices.length);
93
-
94
- return {
95
- offsets: mapIndices(offsets, indices),
96
- untils: untils
97
- };
98
- }
99
- }
100
-
101
- var utcOffset = function utcOffset(timestamp, tzData) {
102
- var target = +timestamp,
103
- i = void 0;
104
- var untils = tzData.untils,
105
- offsets = tzData.offsets;
106
-
107
-
108
- for (i = 0; i < untils.length; i++) {
109
- var diff = target + offsets[i] * 60000; //minutes to milliseconds
110
- if (diff < untils[i]) {
111
- return offsets[i];
112
- }
113
- }
114
- };
115
-
116
- var getTimezoneOffset = function getTimezoneOffset(timestamp, tzData) {
117
- if ((typeof tzData === 'undefined' ? 'undefined' : _typeof(tzData)) === 'object') {
118
- var offset = utcOffset(timestamp, tzData);
119
- if (Math.abs(offset) < 16) {
120
- offset = offset / 60;
121
- }
122
- return -offset;
123
- } else {
124
- return _offset.offsetMap[tzData] || -new Date().getTimezoneOffset();
125
- }
126
- };
127
-
128
- exports.unpack = unpack;
129
- exports.getTimezoneOffset = getTimezoneOffset;