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

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 +120 -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 +60 -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 +85 -72
  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 +44 -33
  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/src/timezones.js DELETED
@@ -1,113 +0,0 @@
1
- import { offsetMap } from './offset';
2
- function charCodeToInt(charCode) {
3
- if (charCode > 96) {
4
- return charCode - 87;
5
- } else if (charCode > 64) {
6
- return charCode - 29;
7
- }
8
- return charCode - 48;
9
- }
10
-
11
- function unpackBase60(string) {
12
- let i = 0,
13
- parts = string.split('.'),
14
- [whole] = parts,
15
- fractional = parts[1] || '',
16
- multiplier = 1,
17
- num,
18
- out = 0,
19
- sign = 1;
20
-
21
- // handle negative numbers
22
- if (string.charCodeAt(0) === 45) {
23
- i = 1;
24
- sign = -1;
25
- }
26
-
27
- // handle digits before the decimal
28
- for (i; i < whole.length; i++) {
29
- num = charCodeToInt(whole.charCodeAt(i));
30
- out = 60 * out + num;
31
- }
32
-
33
- // handle digits after the decimal
34
- for (i = 0; i < fractional.length; i++) {
35
- multiplier = multiplier / 60;
36
- num = charCodeToInt(fractional.charCodeAt(i));
37
- out += num * multiplier;
38
- }
39
-
40
- return out * sign;
41
- }
42
-
43
- function arrayToInt(array) {
44
- for (let i = 0; i < array.length; i++) {
45
- array[i] = unpackBase60(array[i]);
46
- }
47
- }
48
-
49
- function intToUntil(array, length) {
50
- for (let i = 0; i < length; i++) {
51
- array[i] = Math.round((array[i - 1] || 0) + array[i] * 60000); // minutes to milliseconds
52
- }
53
-
54
- array[length - 1] = Infinity;
55
- }
56
-
57
- function mapIndices(source, indices) {
58
- let out = [],
59
- i;
60
-
61
- for (i = 0; i < indices.length; i++) {
62
- out[i] = source[indices[i]];
63
- }
64
-
65
- return out;
66
- }
67
-
68
- function unpack(string) {
69
- if (string) {
70
- let data = string.split('|'),
71
- offsets = data[0].split(' '),
72
- indices = data[1].split(''),
73
- untils = data[2].split(' ');
74
-
75
- arrayToInt(offsets);
76
- arrayToInt(indices);
77
- arrayToInt(untils);
78
-
79
- intToUntil(untils, indices.length);
80
-
81
- return {
82
- offsets: mapIndices(offsets, indices),
83
- untils
84
- };
85
- }
86
- }
87
-
88
- const utcOffset = (timestamp, tzData) => {
89
- let target = +timestamp,
90
- i;
91
- let { untils, offsets } = tzData;
92
-
93
- for (i = 0; i < untils.length; i++) {
94
- let diff = target + offsets[i] * 60000; //minutes to milliseconds
95
- if (diff < untils[i]) {
96
- return offsets[i];
97
- }
98
- }
99
- };
100
-
101
- const getTimezoneOffset = function(timestamp, tzData) {
102
- if (typeof tzData === 'object') {
103
- let offset = utcOffset(timestamp, tzData);
104
- if (Math.abs(offset) < 16) {
105
- offset = offset / 60;
106
- }
107
- return -offset;
108
- } else {
109
- return offsetMap[tzData] || -new Date().getTimezoneOffset();
110
- }
111
- };
112
-
113
- export { unpack, getTimezoneOffset };