@zohodesk/i18n 1.0.0-beta.2 → 1.0.0-beta.21

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 (67) hide show
  1. package/README.md +80 -0
  2. package/es/I18NContext.js +1 -2
  3. package/es/components/DateTimeDiffFormat.js +192 -184
  4. package/es/components/FormatText.js +4 -25
  5. package/es/components/HOCI18N.js +33 -45
  6. package/es/components/I18N.js +46 -63
  7. package/es/components/I18NProvider.js +54 -84
  8. package/es/components/PluralFormat.js +29 -48
  9. package/es/components/UserTimeDiffFormat.js +65 -70
  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.js +250 -385
  19. package/lib/I18NContext.js +6 -6
  20. package/lib/components/DateTimeDiffFormat.js +167 -123
  21. package/lib/components/FormatText.js +32 -22
  22. package/lib/components/HOCI18N.js +47 -23
  23. package/lib/components/I18N.js +60 -36
  24. package/lib/components/I18NProvider.js +76 -69
  25. package/lib/components/PluralFormat.js +42 -32
  26. package/lib/components/UserTimeDiffFormat.js +81 -54
  27. package/lib/components/__tests__/DateTimeDiffFormat.spec.js +815 -629
  28. package/lib/components/__tests__/FormatText.spec.js +23 -25
  29. package/lib/components/__tests__/HOCI18N.spec.js +26 -34
  30. package/lib/components/__tests__/I18N.spec.js +21 -26
  31. package/lib/components/__tests__/I18NProvider.spec.js +43 -51
  32. package/lib/components/__tests__/PluralFormat.spec.js +24 -28
  33. package/lib/components/__tests__/UserTimeDiffFormat.spec.js +1256 -1039
  34. package/lib/index.js +73 -119
  35. package/lib/utils.js +222 -329
  36. package/package.json +2 -2
  37. package/src/I18NContext.js +3 -0
  38. package/src/components/DateTimeDiffFormat.js +256 -0
  39. package/src/components/FormatText.js +14 -0
  40. package/src/components/HOCI18N.js +37 -0
  41. package/src/components/I18N.js +72 -0
  42. package/src/components/I18NProvider.js +110 -0
  43. package/src/components/PluralFormat.js +37 -0
  44. package/src/components/UserTimeDiffFormat.js +97 -0
  45. package/src/components/__tests__/DateTimeDiffFormat.spec.js +618 -0
  46. package/src/components/__tests__/FormatText.spec.js +27 -0
  47. package/src/components/__tests__/HOCI18N.spec.js +33 -0
  48. package/src/components/__tests__/I18N.spec.js +30 -0
  49. package/src/components/__tests__/I18NProvider.spec.js +65 -0
  50. package/src/components/__tests__/PluralFormat.spec.js +28 -0
  51. package/src/components/__tests__/UserTimeDiffFormat.spec.js +1076 -0
  52. package/src/components/__tests__/__snapshots__/DateTimeDiffFormat.spec.js.snap +258 -0
  53. package/src/components/__tests__/__snapshots__/FormatText.spec.js.snap +17 -0
  54. package/src/components/__tests__/__snapshots__/HOCI18N.spec.js.snap +15 -0
  55. package/src/components/__tests__/__snapshots__/I18N.spec.js.snap +17 -0
  56. package/src/components/__tests__/__snapshots__/I18NProvider.spec.js.snap +13 -0
  57. package/src/components/__tests__/__snapshots__/PluralFormat.spec.js.snap +17 -0
  58. package/src/components/__tests__/__snapshots__/UserTimeDiffFormat.spec.js.snap +366 -0
  59. package/src/index.js +33 -0
  60. package/src/utils.js +527 -0
  61. package/.DS_Store +0 -0
  62. package/es/components/NewDateFormat.js +0 -50
  63. package/es/offset.js +0 -629
  64. package/es/timezones.js +0 -112
  65. package/lib/components/NewDateFormat.js +0 -68
  66. package/lib/offset.js +0 -634
  67. package/lib/timezones.js +0 -120
package/lib/timezones.js DELETED
@@ -1,120 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
-
7
- 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"); } }; }();
8
-
9
- function charCodeToInt(charCode) {
10
- if (charCode > 96) {
11
- return charCode - 87;
12
- } else if (charCode > 64) {
13
- return charCode - 29;
14
- }
15
- return charCode - 48;
16
- }
17
-
18
- function unpackBase60(string) {
19
- var i = 0,
20
- parts = string.split('.'),
21
- _parts = _slicedToArray(parts, 1),
22
- whole = _parts[0],
23
- fractional = parts[1] || '',
24
- multiplier = 1,
25
- num = void 0,
26
- out = 0,
27
- sign = 1;
28
-
29
- // handle negative numbers
30
- if (string.charCodeAt(0) === 45) {
31
- i = 1;
32
- sign = -1;
33
- }
34
-
35
- // handle digits before the decimal
36
- for (i; i < whole.length; i++) {
37
- num = charCodeToInt(whole.charCodeAt(i));
38
- out = 60 * out + num;
39
- }
40
-
41
- // handle digits after the decimal
42
- for (i = 0; i < fractional.length; i++) {
43
- multiplier = multiplier / 60;
44
- num = charCodeToInt(fractional.charCodeAt(i));
45
- out += num * multiplier;
46
- }
47
-
48
- return out * sign;
49
- }
50
-
51
- function arrayToInt(array) {
52
- for (var i = 0; i < array.length; i++) {
53
- array[i] = unpackBase60(array[i]);
54
- }
55
- }
56
-
57
- function intToUntil(array, length) {
58
- for (var i = 0; i < length; i++) {
59
- array[i] = Math.round((array[i - 1] || 0) + array[i] * 60000); // minutes to milliseconds
60
- }
61
-
62
- array[length - 1] = Infinity;
63
- }
64
-
65
- function mapIndices(source, indices) {
66
- var out = [],
67
- i = void 0;
68
-
69
- for (i = 0; i < indices.length; i++) {
70
- out[i] = source[indices[i]];
71
- }
72
-
73
- return out;
74
- }
75
-
76
- function unpack(string) {
77
- if (string) {
78
- var data = string.split('|'),
79
- offsets = data[0].split(' '),
80
- indices = data[1].split(''),
81
- untils = data[2].split(' ');
82
-
83
- arrayToInt(offsets);
84
- arrayToInt(indices);
85
- arrayToInt(untils);
86
-
87
- intToUntil(untils, indices.length);
88
-
89
- return {
90
- offsets: mapIndices(offsets, indices),
91
- untils: untils
92
- };
93
- }
94
- }
95
-
96
- var utcOffset = function utcOffset(timestamp, tzData) {
97
- var target = +timestamp,
98
- i = void 0;
99
- var untils = tzData.untils,
100
- offsets = tzData.offsets;
101
-
102
-
103
- for (i = 0; i < untils.length; i++) {
104
- var diff = target + offsets[i] * 60000; //minutes to milliseconds
105
- if (diff < untils[i]) {
106
- return offsets[i];
107
- }
108
- }
109
- };
110
-
111
- var getTimezoneOffset = function getTimezoneOffset(timestamp, tzData) {
112
- var offset = utcOffset(timestamp, tzData);
113
- if (Math.abs(offset) < 16) {
114
- offset = offset / 60;
115
- }
116
- return -offset;
117
- };
118
-
119
- exports.unpack = unpack;
120
- exports.getTimezoneOffset = getTimezoneOffset;