@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/es/timezones.js DELETED
@@ -1,112 +0,0 @@
1
- import _slicedToArray from 'babel-runtime/helpers/slicedToArray';
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
- var i = 0,
13
- parts = string.split('.'),
14
- _parts = _slicedToArray(parts, 1),
15
- whole = _parts[0],
16
- fractional = parts[1] || '',
17
- multiplier = 1,
18
- num = void 0,
19
- out = 0,
20
- sign = 1;
21
-
22
- // handle negative numbers
23
- if (string.charCodeAt(0) === 45) {
24
- i = 1;
25
- sign = -1;
26
- }
27
-
28
- // handle digits before the decimal
29
- for (i; i < whole.length; i++) {
30
- num = charCodeToInt(whole.charCodeAt(i));
31
- out = 60 * out + num;
32
- }
33
-
34
- // handle digits after the decimal
35
- for (i = 0; i < fractional.length; i++) {
36
- multiplier = multiplier / 60;
37
- num = charCodeToInt(fractional.charCodeAt(i));
38
- out += num * multiplier;
39
- }
40
-
41
- return out * sign;
42
- }
43
-
44
- function arrayToInt(array) {
45
- for (var i = 0; i < array.length; i++) {
46
- array[i] = unpackBase60(array[i]);
47
- }
48
- }
49
-
50
- function intToUntil(array, length) {
51
- for (var i = 0; i < length; i++) {
52
- array[i] = Math.round((array[i - 1] || 0) + array[i] * 60000); // minutes to milliseconds
53
- }
54
-
55
- array[length - 1] = Infinity;
56
- }
57
-
58
- function mapIndices(source, indices) {
59
- var out = [],
60
- i = void 0;
61
-
62
- for (i = 0; i < indices.length; i++) {
63
- out[i] = source[indices[i]];
64
- }
65
-
66
- return out;
67
- }
68
-
69
- function unpack(string) {
70
- if (string) {
71
- var data = string.split('|'),
72
- offsets = data[0].split(' '),
73
- indices = data[1].split(''),
74
- untils = data[2].split(' ');
75
-
76
- arrayToInt(offsets);
77
- arrayToInt(indices);
78
- arrayToInt(untils);
79
-
80
- intToUntil(untils, indices.length);
81
-
82
- return {
83
- offsets: mapIndices(offsets, indices),
84
- untils: untils
85
- };
86
- }
87
- }
88
-
89
- var utcOffset = function utcOffset(timestamp, tzData) {
90
- var target = +timestamp,
91
- i = void 0;
92
- var untils = tzData.untils,
93
- offsets = tzData.offsets;
94
-
95
-
96
- for (i = 0; i < untils.length; i++) {
97
- var diff = target + offsets[i] * 60000; //minutes to milliseconds
98
- if (diff < untils[i]) {
99
- return offsets[i];
100
- }
101
- }
102
- };
103
-
104
- var getTimezoneOffset = function getTimezoneOffset(timestamp, tzData) {
105
- var offset = utcOffset(timestamp, tzData);
106
- if (Math.abs(offset) < 16) {
107
- offset = offset / 60;
108
- }
109
- return -offset;
110
- };
111
-
112
- export { unpack, getTimezoneOffset };
@@ -1,68 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = NewDateFormat;
7
-
8
- var _react = require('react');
9
-
10
- var _react2 = _interopRequireDefault(_react);
11
-
12
- var _propTypes = require('prop-types');
13
-
14
- var _propTypes2 = _interopRequireDefault(_propTypes);
15
-
16
- var _utils = require('../utils');
17
-
18
- var _FormatText = require('./FormatText');
19
-
20
- var _FormatText2 = _interopRequireDefault(_FormatText);
21
-
22
- var _I18NContext = require('../I18NContext');
23
-
24
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
25
-
26
- function NewDateFormat(props, context) {
27
- var currentTime = new Date();
28
- var to = props.to,
29
- today = props.today,
30
- yesterday = props.yesterday,
31
- tomorrow = props.tomorrow,
32
- others = props.others,
33
- ago = props.ago,
34
- later = props.later,
35
- format = props.format,
36
- titleFormat = props.titleFormat,
37
- titleString = props.titleString,
38
- className = props.className,
39
- displayType = props.displayType,
40
- calculateFrom = props.calculateFrom;
41
-
42
- calculateFrom = calculateFrom === undefined ? currentTime : calculateFrom;
43
- var tzData = context.tzData;
44
-
45
- var formatResponse = (0, _utils.getFormatedDate)(to, today, yesterday, tomorrow, others, ago, later, format, titleFormat, titleString, calculateFrom, tzData);
46
- var isI18nValue = formatResponse.isFormatText;
47
- if (isI18nValue) {
48
- var i18nText = formatResponse.i18nText,
49
- values = formatResponse.values,
50
- _title = formatResponse.title;
51
-
52
- return _react2.default.createElement(_FormatText2.default, {
53
- i18NKey: i18nText,
54
- values: values,
55
- className: className,
56
- 'data-title': _title
57
- });
58
- }
59
- var title = formatResponse.title,
60
- formatedDate = formatResponse.formatedDate;
61
-
62
- return _react2.default.createElement(
63
- 'span',
64
- { className: className, 'data-title': title },
65
- formatedDate
66
- );
67
- }
68
- NewDateFormat.contextType = _I18NContext.I18NContext;