@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.
- package/README.md +116 -2
- package/es/I18NContext.js +1 -2
- package/es/components/DateTimeDiffFormat.js +192 -200
- package/es/components/FormatText.js +4 -25
- package/es/components/HOCI18N.js +33 -45
- package/es/components/I18N.js +48 -63
- package/es/components/I18NProvider.js +59 -85
- package/es/components/PluralFormat.js +29 -48
- package/es/components/UserTimeDiffFormat.js +65 -74
- package/es/components/__tests__/DateTimeDiffFormat.spec.js +868 -657
- package/es/components/__tests__/FormatText.spec.js +20 -17
- package/es/components/__tests__/HOCI18N.spec.js +18 -22
- package/es/components/__tests__/I18N.spec.js +20 -19
- package/es/components/__tests__/I18NProvider.spec.js +36 -45
- package/es/components/__tests__/PluralFormat.spec.js +20 -17
- package/es/components/__tests__/UserTimeDiffFormat.spec.js +1343 -1095
- package/es/index.js +2 -6
- package/es/utils/__tests__/jsxTranslations.spec.js +174 -0
- package/es/utils/index.js +592 -0
- package/es/utils/jsxTranslations.js +193 -0
- package/lib/I18NContext.js +6 -6
- package/lib/components/DateTimeDiffFormat.js +151 -123
- package/lib/components/FormatText.js +32 -22
- package/lib/components/HOCI18N.js +47 -23
- package/lib/components/I18N.js +62 -36
- package/lib/components/I18NProvider.js +82 -70
- package/lib/components/PluralFormat.js +42 -32
- package/lib/components/UserTimeDiffFormat.js +79 -56
- package/lib/components/__tests__/DateTimeDiffFormat.spec.js +815 -629
- package/lib/components/__tests__/FormatText.spec.js +23 -25
- package/lib/components/__tests__/HOCI18N.spec.js +26 -34
- package/lib/components/__tests__/I18N.spec.js +21 -26
- package/lib/components/__tests__/I18NProvider.spec.js +43 -51
- package/lib/components/__tests__/PluralFormat.spec.js +24 -28
- package/lib/components/__tests__/UserTimeDiffFormat.spec.js +1256 -1039
- package/lib/index.js +85 -110
- package/lib/utils/__tests__/jsxTranslations.spec.js +183 -0
- package/lib/utils/index.js +658 -0
- package/lib/utils/jsxTranslations.js +242 -0
- package/package.json +3 -2
- package/src/components/DateTimeDiffFormat.js +86 -55
- package/src/components/I18N.js +2 -0
- package/src/components/I18NProvider.js +34 -25
- package/src/components/UserTimeDiffFormat.js +24 -18
- package/src/index.js +7 -9
- package/src/utils/__tests__/jsxTranslations.spec.js +213 -0
- package/src/utils/index.js +632 -0
- package/src/utils/jsxTranslations.js +180 -0
- package/es/components/NewDateFormat.js +0 -50
- package/es/offset.js +0 -629
- package/es/timezones.js +0 -118
- package/es/utils.js +0 -621
- package/lib/components/NewDateFormat.js +0 -68
- package/lib/offset.js +0 -634
- package/lib/timezones.js +0 -129
- package/lib/utils.js +0 -651
- package/src/components/NewDateFormat.js +0 -60
- package/src/offset.js +0 -629
- package/src/timezones.js +0 -113
- package/src/utils.js +0 -648
package/es/timezones.js
DELETED
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
import _typeof from 'babel-runtime/helpers/typeof';
|
|
2
|
-
import _slicedToArray from 'babel-runtime/helpers/slicedToArray';
|
|
3
|
-
import { offsetMap } from './offset';
|
|
4
|
-
function charCodeToInt(charCode) {
|
|
5
|
-
if (charCode > 96) {
|
|
6
|
-
return charCode - 87;
|
|
7
|
-
} else if (charCode > 64) {
|
|
8
|
-
return charCode - 29;
|
|
9
|
-
}
|
|
10
|
-
return charCode - 48;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
function unpackBase60(string) {
|
|
14
|
-
var i = 0,
|
|
15
|
-
parts = string.split('.'),
|
|
16
|
-
_parts = _slicedToArray(parts, 1),
|
|
17
|
-
whole = _parts[0],
|
|
18
|
-
fractional = parts[1] || '',
|
|
19
|
-
multiplier = 1,
|
|
20
|
-
num = void 0,
|
|
21
|
-
out = 0,
|
|
22
|
-
sign = 1;
|
|
23
|
-
|
|
24
|
-
// handle negative numbers
|
|
25
|
-
if (string.charCodeAt(0) === 45) {
|
|
26
|
-
i = 1;
|
|
27
|
-
sign = -1;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
// handle digits before the decimal
|
|
31
|
-
for (i; i < whole.length; i++) {
|
|
32
|
-
num = charCodeToInt(whole.charCodeAt(i));
|
|
33
|
-
out = 60 * out + num;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
// handle digits after the decimal
|
|
37
|
-
for (i = 0; i < fractional.length; i++) {
|
|
38
|
-
multiplier = multiplier / 60;
|
|
39
|
-
num = charCodeToInt(fractional.charCodeAt(i));
|
|
40
|
-
out += num * multiplier;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
return out * sign;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
function arrayToInt(array) {
|
|
47
|
-
for (var i = 0; i < array.length; i++) {
|
|
48
|
-
array[i] = unpackBase60(array[i]);
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
function intToUntil(array, length) {
|
|
53
|
-
for (var i = 0; i < length; i++) {
|
|
54
|
-
array[i] = Math.round((array[i - 1] || 0) + array[i] * 60000); // minutes to milliseconds
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
array[length - 1] = Infinity;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
function mapIndices(source, indices) {
|
|
61
|
-
var out = [],
|
|
62
|
-
i = void 0;
|
|
63
|
-
|
|
64
|
-
for (i = 0; i < indices.length; i++) {
|
|
65
|
-
out[i] = source[indices[i]];
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
return out;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
function unpack(string) {
|
|
72
|
-
if (string) {
|
|
73
|
-
var data = string.split('|'),
|
|
74
|
-
offsets = data[0].split(' '),
|
|
75
|
-
indices = data[1].split(''),
|
|
76
|
-
untils = data[2].split(' ');
|
|
77
|
-
|
|
78
|
-
arrayToInt(offsets);
|
|
79
|
-
arrayToInt(indices);
|
|
80
|
-
arrayToInt(untils);
|
|
81
|
-
|
|
82
|
-
intToUntil(untils, indices.length);
|
|
83
|
-
|
|
84
|
-
return {
|
|
85
|
-
offsets: mapIndices(offsets, indices),
|
|
86
|
-
untils: untils
|
|
87
|
-
};
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
var utcOffset = function utcOffset(timestamp, tzData) {
|
|
92
|
-
var target = +timestamp,
|
|
93
|
-
i = void 0;
|
|
94
|
-
var untils = tzData.untils,
|
|
95
|
-
offsets = tzData.offsets;
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
for (i = 0; i < untils.length; i++) {
|
|
99
|
-
var diff = target + offsets[i] * 60000; //minutes to milliseconds
|
|
100
|
-
if (diff < untils[i]) {
|
|
101
|
-
return offsets[i];
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
};
|
|
105
|
-
|
|
106
|
-
var getTimezoneOffset = function getTimezoneOffset(timestamp, tzData) {
|
|
107
|
-
if ((typeof tzData === 'undefined' ? 'undefined' : _typeof(tzData)) === 'object') {
|
|
108
|
-
var offset = utcOffset(timestamp, tzData);
|
|
109
|
-
if (Math.abs(offset) < 16) {
|
|
110
|
-
offset = offset / 60;
|
|
111
|
-
}
|
|
112
|
-
return -offset;
|
|
113
|
-
} else {
|
|
114
|
-
return offsetMap[tzData] || -new Date().getTimezoneOffset();
|
|
115
|
-
}
|
|
116
|
-
};
|
|
117
|
-
|
|
118
|
-
export { unpack, getTimezoneOffset };
|