diginet-core-ui 1.3.78 → 1.3.79

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 (209) hide show
  1. package/components/accordion/details.js +2 -6
  2. package/components/accordion/group.js +2 -9
  3. package/components/accordion/index.js +2 -15
  4. package/components/accordion/summary.js +4 -27
  5. package/components/alert/index.js +98 -137
  6. package/components/alert/notify.js +97 -166
  7. package/components/avatar/index.js +4 -63
  8. package/components/badge/index.js +7 -34
  9. package/components/button/icon.js +120 -186
  10. package/components/button/index.js +136 -205
  11. package/components/button/more.js +0 -12
  12. package/components/button/ripple-effect.js +46 -44
  13. package/components/card/body.js +2 -7
  14. package/components/card/extra.js +2 -7
  15. package/components/card/footer.js +2 -7
  16. package/components/card/header.js +2 -7
  17. package/components/card/index.js +2 -22
  18. package/components/chart/Pie/Circle.js +0 -1
  19. package/components/chart/Pie/Sector.js +0 -17
  20. package/components/chart/Pie/Sectors.js +0 -10
  21. package/components/chart/Pie/index.js +4 -36
  22. package/components/chart/Pie-v2/Circle.js +0 -1
  23. package/components/chart/Pie-v2/Sector.js +0 -13
  24. package/components/chart/Pie-v2/Sectors.js +0 -20
  25. package/components/chart/Pie-v2/index.js +11 -38
  26. package/components/chart/bar/Axis.js +0 -12
  27. package/components/chart/bar/Bar.js +13 -35
  28. package/components/chart/bar/Grid.js +0 -18
  29. package/components/chart/bar/Labels.js +0 -18
  30. package/components/chart/bar/Points.js +0 -17
  31. package/components/chart/bar/index.js +6 -26
  32. package/components/chart/bar-v2/Axis.js +0 -12
  33. package/components/chart/bar-v2/Bar.js +15 -36
  34. package/components/chart/bar-v2/Grid.js +0 -18
  35. package/components/chart/bar-v2/Labels.js +0 -18
  36. package/components/chart/bar-v2/Points.js +0 -17
  37. package/components/chart/bar-v2/index.js +6 -26
  38. package/components/chart/line/Axis.js +4 -16
  39. package/components/chart/line/Grid.js +2 -19
  40. package/components/chart/line/Labels.js +0 -18
  41. package/components/chart/line/Path.js +23 -33
  42. package/components/chart/line/Point.js +6 -40
  43. package/components/chart/line/Title.js +0 -3
  44. package/components/chart/line/index.js +12 -35
  45. package/components/chart/line-v2/Axis.js +0 -13
  46. package/components/chart/line-v2/Grid.js +0 -18
  47. package/components/chart/line-v2/Labels.js +0 -18
  48. package/components/chart/line-v2/Path.js +23 -33
  49. package/components/chart/line-v2/Point.js +6 -35
  50. package/components/chart/line-v2/Title.js +0 -3
  51. package/components/chart/line-v2/index.js +12 -30
  52. package/components/check-text/index.js +0 -8
  53. package/components/check-text/interview-confirmation.js +0 -7
  54. package/components/check-text/interview-status.js +0 -7
  55. package/components/chip/attach.js +4 -17
  56. package/components/chip/index.js +6 -33
  57. package/components/collapse/index.js +0 -13
  58. package/components/divider/index.js +0 -8
  59. package/components/form-control/attachment/index.js +24 -202
  60. package/components/form-control/calendar/function.js +40 -94
  61. package/components/form-control/calendar/index.js +5 -30
  62. package/components/form-control/calendar/range.js +11 -28
  63. package/components/form-control/checkbox/index.js +4 -37
  64. package/components/form-control/control/index.js +3 -13
  65. package/components/form-control/date-picker/index-old.js +18 -0
  66. package/components/form-control/date-picker/index.js +23 -99
  67. package/components/form-control/date-range-picker/index.js +86 -221
  68. package/components/form-control/dropdown/index.js +72 -289
  69. package/components/form-control/dropdown-box/index.js +6 -35
  70. package/components/form-control/form/index.js +0 -2
  71. package/components/form-control/form-group/index.js +1 -6
  72. package/components/form-control/helper-text/index.js +2 -9
  73. package/components/form-control/input-base/index.js +218 -399
  74. package/components/form-control/label/index.js +2 -12
  75. package/components/form-control/money-input/index.js +43 -132
  76. package/components/form-control/number-input/index.js +15 -113
  77. package/components/form-control/number-input/index2.js +78 -119
  78. package/components/form-control/phone-input/index.js +16 -78
  79. package/components/form-control/radio/index.js +4 -23
  80. package/components/form-control/text-input/index.js +33 -256
  81. package/components/form-control/time-picker/index.js +14 -71
  82. package/components/form-control/time-picker/swiper.js +21 -73
  83. package/components/form-control/toggle/index.js +4 -19
  84. package/components/form-view/helper-text.js +2 -2
  85. package/components/form-view/index.js +0 -14
  86. package/components/form-view/input.js +2 -13
  87. package/components/form-view/label.js +0 -2
  88. package/components/grid/Col.js +2 -15
  89. package/components/grid/Container.js +2 -21
  90. package/components/grid/Row.js +2 -21
  91. package/components/grid/index.js +2 -43
  92. package/components/image/index.js +2 -22
  93. package/components/index.js +62 -31
  94. package/components/list/list-item-action.js +0 -9
  95. package/components/list/list-item-icon.js +0 -9
  96. package/components/list/list-item-text.js +0 -5
  97. package/components/list/list-item.js +0 -11
  98. package/components/list/list.js +0 -13
  99. package/components/list/sub-header.js +0 -4
  100. package/components/modal/body.js +2 -6
  101. package/components/modal/footer.js +2 -11
  102. package/components/modal/header.js +2 -12
  103. package/components/modal/index.js +2 -10
  104. package/components/modal/modal.js +11 -52
  105. package/components/others/extra/index.js +3 -10
  106. package/components/others/import/index.js +0 -7
  107. package/components/others/option-wrapper/index.js +4 -7
  108. package/components/others/scrollbar/index.js +0 -3
  109. package/components/paging/page-info.js +39 -101
  110. package/components/paging/page-selector.js +7 -35
  111. package/components/paging/page-selector2.js +35 -74
  112. package/components/paper/index.js +0 -11
  113. package/components/popover/body.js +2 -6
  114. package/components/popover/footer.js +2 -11
  115. package/components/popover/header.js +2 -7
  116. package/components/popover/index.js +39 -123
  117. package/components/popup/danger_popup.js +0 -19
  118. package/components/popup/index.js +2 -48
  119. package/components/popup/proposals_popup.js +10 -49
  120. package/components/popup/v2/index.js +0 -31
  121. package/components/progress/circular.js +19 -81
  122. package/components/progress/linear.js +4 -20
  123. package/components/rating/index.js +0 -24
  124. package/components/slider/slider-container.js +3 -40
  125. package/components/slider/slider-item.js +10 -25
  126. package/components/status/index.js +2 -16
  127. package/components/tab/tab-container.js +2 -16
  128. package/components/tab/tab-header.js +4 -24
  129. package/components/tab/tab-panel.js +4 -16
  130. package/components/tab/tab.js +4 -28
  131. package/components/tooltip/index.js +12 -97
  132. package/components/tooltip/portal.js +0 -2
  133. package/components/transfer/index.js +22 -67
  134. package/components/tree-view/index.js +62 -202
  135. package/components/typography/index.js +3 -31
  136. package/global/index.js +0 -8
  137. package/icons/basic.js +0 -48
  138. package/icons/effect.js +17 -29
  139. package/icons/general/clock/clock.js +0 -2
  140. package/icons/general/color-handler/background.js +0 -2
  141. package/icons/general/color-handler/text.js +0 -2
  142. package/icons/general/emoji/emoji.js +0 -2
  143. package/icons/general/font-properties/bold.js +0 -2
  144. package/icons/general/font-properties/font-family.js +0 -2
  145. package/icons/general/font-properties/font-size.js +0 -2
  146. package/icons/general/font-properties/italic.js +0 -2
  147. package/icons/general/font-properties/underline.js +0 -2
  148. package/icons/general/hyperlink/hyperlink.js +0 -2
  149. package/icons/general/indent/decrease.js +0 -2
  150. package/icons/general/indent/increase.js +0 -2
  151. package/icons/general/list/bullets.js +0 -2
  152. package/icons/general/list/numbering.js +0 -2
  153. package/icons/general/picture/picture.js +0 -2
  154. package/icons/general/steps/redo.js +0 -2
  155. package/icons/general/steps/undo.js +0 -2
  156. package/icons/general/text-align/center.js +0 -2
  157. package/icons/general/text-align/justify.js +0 -2
  158. package/icons/general/text-align/left.js +0 -2
  159. package/icons/general/text-align/right.js +0 -2
  160. package/icons/menu/dhr.js +2 -1
  161. package/icons/menu/index.js +2 -2
  162. package/icons/menu/v2/index.js +0 -10
  163. package/package.json +1 -1
  164. package/readme.md +11 -1
  165. package/styles/animation.js +15 -58
  166. package/styles/color-helper.js +24 -54
  167. package/styles/colors.js +17 -9
  168. package/styles/general.js +6 -2
  169. package/styles/typography.js +4 -4
  170. package/styles/utils.js +2 -2
  171. package/theme/createBreakpoints.js +7 -18
  172. package/theme/make-styles.js +2 -5
  173. package/theme/set-theme.js +3 -6
  174. package/theme/settings.js +3 -2
  175. package/theme/theme-provider.js +0 -1
  176. package/utils/array/array.js +14 -23
  177. package/utils/classNames.js +0 -5
  178. package/utils/console.js +0 -6
  179. package/utils/date.js +13 -82
  180. package/utils/error/error.js +1 -9
  181. package/utils/error/errors.js +1 -48
  182. package/utils/getFileType.js +0 -9
  183. package/utils/handleBreakpoints.js +0 -5
  184. package/utils/intersectionObserver.js +0 -5
  185. package/utils/iterator.js +0 -9
  186. package/utils/map-parent.js +3 -10
  187. package/utils/object/extend.js +0 -10
  188. package/utils/object/object.js +12 -11
  189. package/utils/parseHTML.js +0 -1
  190. package/utils/promisify.js +0 -5
  191. package/utils/randomString.js +0 -7
  192. package/utils/remove-unicode.js +0 -1
  193. package/utils/render-portal.js +1 -9
  194. package/utils/renderHTML.js +4 -6
  195. package/utils/renderIcon.js +4 -14
  196. package/utils/sb-template.js +6 -5
  197. package/utils/string/capitalize.js +0 -1
  198. package/utils/string/capitalizeSentenceCase.js +0 -2
  199. package/utils/string/string.js +0 -13
  200. package/utils/type.js +0 -21
  201. package/utils/updatePosition.js +4 -5
  202. package/utils/useDelayUnmount.js +0 -4
  203. package/utils/useElementSize.js +9 -3
  204. package/utils/useEventListener.js +12 -6
  205. package/utils/useInput.js +0 -6
  206. package/utils/useMediaQuery.js +8 -10
  207. package/utils/useOnClickOutside.js +0 -2
  208. package/utils/usePortal.js +3 -10
  209. package/utils/validate.js +6 -20
package/theme/settings.js CHANGED
@@ -19,7 +19,8 @@ const settings = {
19
19
  large: '0 4px 4px 0 rgba(0, 0, 0, 0.25)',
20
20
  small: '0 2px 2px 0 rgba(0, 0, 0, 0.25)'
21
21
  },
22
- colors: { ...color,
22
+ colors: {
23
+ ...color,
23
24
  border: colors.dark6,
24
25
  danger: colors.danger5,
25
26
  default: colors.dark,
@@ -66,9 +67,9 @@ const settings = {
66
67
  lg: 1200,
67
68
  // large
68
69
  xl: 1536 // extra-large
69
-
70
70
  }
71
71
  }),
72
+
72
73
  spacing: vl => getSpacing(vl),
73
74
  zIndex: vl => zIndex(vl),
74
75
  setZIndex: vl => setZIndex(vl)
@@ -1,5 +1,4 @@
1
1
  /** @jsxRuntime classic */
2
-
3
2
  /** @jsx jsx */
4
3
  import { memo, useEffect } from 'react';
5
4
  import { jsx, css } from '@emotion/core';
@@ -1,84 +1,81 @@
1
1
  import { isDefined } from '../type';
2
2
  import { each } from '../iterator';
3
3
  import { orderEach } from '../object/object';
4
+
4
5
  /**
5
6
  *
6
7
  * @param {Array} entity
7
8
  * @returns {Boolean}
8
9
  */
9
-
10
10
  export const isEmpty = entity => Array.isArray(entity) && !entity.length;
11
+
11
12
  /**
12
13
  *
13
14
  * @param {any} entity
14
15
  * @returns {Array} [entity]
15
16
  */
16
-
17
17
  export const wrapToArray = entity => Array.isArray(entity) ? entity : [entity];
18
+
18
19
  /**
19
20
  *
20
21
  * @param {*} value in object
21
22
  * @param {ArrayLike} object is a array-like object
22
23
  * @returns {Number} index of value, -1 if not found
23
24
  */
24
-
25
25
  export const inArray = (value, object) => {
26
26
  if (!object) return -1;
27
27
  const array = Array.isArray(object) ? object : Array.from(object);
28
28
  return array.indexOf(value);
29
29
  };
30
+
30
31
  /**
31
32
  *
32
33
  * @param {Array} a
33
34
  * @param {Array} b
34
35
  * @returns {Array} intersection array of a and b
35
36
  */
36
-
37
37
  export const intersection = (a, b) => {
38
38
  if (!Array.isArray(a) || a.length === 0 || !Array.isArray(b) || b.length === 0) return [];
39
39
  const result = [];
40
40
  each(a, (_, value) => {
41
41
  const index = inArray(value, b);
42
-
43
42
  if (index !== -1) {
44
43
  result.push(value);
45
44
  }
46
45
  });
47
46
  return result;
48
47
  };
48
+
49
49
  /**
50
50
  *
51
51
  * @param {Array} data
52
52
  * @returns {Array} array with unique values
53
53
  */
54
-
55
54
  export const uniqueValues = data => data.filter((item, position) => data.indexOf(item) === position);
55
+
56
56
  /**
57
57
  *
58
58
  * @param {Array} from
59
59
  * @param {Array} what
60
60
  * @returns {Array} without duplicate
61
61
  */
62
-
63
62
  export const removeDuplicates = function (from, what) {
64
63
  if (!Array.isArray(from) || from.length === 0) {
65
64
  return [];
66
65
  }
67
-
68
66
  if (!Array.isArray(what) || what.length === 0) {
69
67
  return from.slice();
70
68
  }
71
-
72
69
  const result = [];
73
70
  each(from, (_, value) => {
74
71
  const index = inArray(value, what);
75
-
76
72
  if (index === -1) {
77
73
  result.push(value);
78
74
  }
79
75
  });
80
76
  return result;
81
77
  };
78
+
82
79
  /**
83
80
  *
84
81
  * @param {Array} items
@@ -87,21 +84,17 @@ export const removeDuplicates = function (from, what) {
87
84
  * @param {Function} needIndexCallback
88
85
  * @returns
89
86
  */
90
-
91
87
  export const normalizeIndexes = function (items, indexParameterName, currentItem, needIndexCallback) {
92
88
  const indexedItems = {};
93
89
  let parameterIndex = 0;
94
90
  /**
95
91
  * useLegacyVisibleIndex will be process in future
96
92
  */
97
-
98
93
  const useLegacyVisibleIndex = false;
99
94
  each(items, (index, item) => {
100
95
  index = item[indexParameterName];
101
-
102
96
  if (index >= 0) {
103
97
  indexedItems[index] = indexedItems[index] || [];
104
-
105
98
  if (item === currentItem) {
106
99
  indexedItems[index].unshift(item);
107
100
  } else {
@@ -111,20 +104,17 @@ export const normalizeIndexes = function (items, indexParameterName, currentItem
111
104
  item[indexParameterName] = undefined;
112
105
  }
113
106
  });
114
-
115
107
  if (!useLegacyVisibleIndex) {
116
108
  each(items, function () {
117
109
  if (!isDefined(this[indexParameterName]) && !!needIndexCallback && needIndexCallback(this)) {
118
110
  while (indexedItems[parameterIndex]) {
119
111
  parameterIndex++;
120
112
  }
121
-
122
113
  indexedItems[parameterIndex] = [this];
123
114
  parameterIndex++;
124
115
  }
125
116
  });
126
117
  }
127
-
128
118
  parameterIndex = 0;
129
119
  orderEach(indexedItems, function (index, items) {
130
120
  each(items, function () {
@@ -132,7 +122,9 @@ export const normalizeIndexes = function (items, indexParameterName, currentItem
132
122
  this[indexParameterName] = parameterIndex++;
133
123
  }
134
124
  });
135
- }); // if (useLegacyVisibleIndex) {
125
+ });
126
+
127
+ // if (useLegacyVisibleIndex) {
136
128
  // each(items, function () {
137
129
  // if (
138
130
  // !isDefined(this[indexParameterName]) &&
@@ -149,7 +141,6 @@ export const merge = function (array1, array2) {
149
141
  for (let i = 0; i < array2.length; i++) {
150
142
  array1[array1.length] = array2[i];
151
143
  }
152
-
153
144
  return array1;
154
145
  };
155
146
  export const find = function (array, condition) {
@@ -159,7 +150,8 @@ export const find = function (array, condition) {
159
150
  }
160
151
  }
161
152
  };
162
- export const groupByFunc = (array, cb) => array.reduce((result, item) => ({ ...result,
153
+ export const groupByFunc = (array, cb) => array.reduce((result, item) => ({
154
+ ...result,
163
155
  [cb(item)]: [...(result[cb(item)] || []), item]
164
156
  }), {});
165
157
  export const groupByKey = (array, key) => array.reduce((result, item) => {
@@ -169,7 +161,6 @@ export const groupByKey = (array, key) => array.reduce((result, item) => {
169
161
  export const isEqual = (currentArray, compareArray) => {
170
162
  if (!currentArray || !compareArray) return false;
171
163
  if (currentArray.length !== compareArray.length) return false;
172
-
173
164
  for (let i = 0, j = currentArray.length; i < j; i++) {
174
165
  if (currentArray[i] instanceof Array && compareArray[i] instanceof Array) {
175
166
  if (!isEqual(currentArray[i], compareArray[i])) {
@@ -177,9 +168,9 @@ export const isEqual = (currentArray, compareArray) => {
177
168
  }
178
169
  } else if (currentArray[i] !== compareArray[i]) {
179
170
  return false;
180
- } // in future will update for object case
171
+ }
172
+ // in future will update for object case
181
173
  // else if (typeof currentArray[i] === 'object' && typeof compareArray[i] === 'object') {}
182
-
183
174
  }
184
175
 
185
176
  return true;
@@ -1,14 +1,11 @@
1
1
  const hasOwn = {}.hasOwnProperty;
2
-
3
2
  const classNames = (...args) => {
4
3
  args = args.flat();
5
4
  let classes = [];
6
-
7
5
  for (let i = 0; i < args.length; i++) {
8
6
  let arg = args[i];
9
7
  if (!arg) continue;
10
8
  let argType = typeof arg;
11
-
12
9
  if (argType === 'string' || argType === 'number') {
13
10
  classes.push(arg);
14
11
  } else if (argType === 'object') {
@@ -23,8 +20,6 @@ const classNames = (...args) => {
23
20
  }
24
21
  }
25
22
  }
26
-
27
23
  return classes.join(' ');
28
24
  };
29
-
30
25
  export default classNames;
package/utils/console.js CHANGED
@@ -1,15 +1,11 @@
1
1
  import { isFunction } from './type';
2
-
3
2
  const noop = () => {};
4
-
5
3
  const getConsoleMethod = function (method) {
6
4
  if (typeof console === 'undefined' || !isFunction(console[method])) {
7
5
  return noop;
8
6
  }
9
-
10
7
  return console[method].bind(console);
11
8
  };
12
-
13
9
  export const logger = {
14
10
  info: getConsoleMethod('info'),
15
11
  warn: getConsoleMethod('warn'),
@@ -21,11 +17,9 @@ export const debug = (() => {
21
17
  throw new Error(message);
22
18
  }
23
19
  };
24
-
25
20
  const assertParam = (parameter, message) => {
26
21
  assert(parameter !== null && parameter !== undefined, message);
27
22
  };
28
-
29
23
  return {
30
24
  assert: assert,
31
25
  assertParam: assertParam
package/utils/date.js CHANGED
@@ -3,72 +3,61 @@ import locale from '../locale';
3
3
  const language = locale.get();
4
4
  const localeName = language === 'en' ? 'en-US' : 'vi-VN';
5
5
  const units = ['year', 'month', 'day', 'hour', 'minute', 'second', 'millisecond'];
6
+
6
7
  /**
7
8
  *
8
9
  * @param {Date|String|Array} value is a date time
9
10
  * @param {String} format the input date format
10
11
  * @param {Boolean} setNow return current time if true
11
12
  */
12
-
13
13
  const getDate = (value, format = 'MM/DD/YYYY', setNow = true) => {
14
14
  if (value) {
15
15
  if (Array.isArray(value)) {
16
16
  value = value.join('/');
17
17
  }
18
-
19
18
  if (typeof value === 'string') {
20
19
  if (format.replace(/\W/g, '/') === 'DD/MM/YYYY') {
21
20
  value = value.replace(/^(\d{1,2}\/)(\d{1,2}\/)/, '$2$1');
22
21
  }
23
22
  }
24
-
25
23
  return new Date(value);
26
24
  } else if (setNow) {
27
25
  return new Date();
28
26
  }
29
27
  };
30
-
31
28
  const getMethodOfUnit = unit => {
32
29
  switch (unit.toLowerCase()) {
33
30
  case 'years':
34
31
  case 'year':
35
32
  return 'FullYear';
36
-
37
33
  case 'months':
38
34
  case 'month':
39
35
  return 'Month';
40
-
41
36
  case 'days':
42
37
  case 'day':
43
38
  return 'Date';
44
-
45
39
  case 'hours':
46
40
  case 'hour':
47
41
  return 'Hours';
48
-
49
42
  case 'minutes':
50
43
  case 'minute':
51
44
  return 'Minutes';
52
-
53
45
  case 'seconds':
54
46
  case 'second':
55
47
  return 'Seconds';
56
-
57
48
  case 'millisecond':
58
49
  return 'Milliseconds';
59
-
60
50
  default:
61
51
  return 'Date';
62
52
  }
63
53
  };
54
+
64
55
  /**
65
56
  * check 1 value is a date
66
57
  * @param {Date|String|Array|Number} value the value to check
67
58
  * @param {String} formatInput the format date to check valid date
68
59
  * @returns {Boolean} valid date
69
60
  */
70
-
71
-
72
61
  export const isValidDate = (value, formatInput) => {
73
62
  if (typeof value === 'string' || Array.isArray(value)) {
74
63
  if (String(getDate(value, formatInput)) !== 'Invalid Date') {
@@ -77,21 +66,19 @@ export const isValidDate = (value, formatInput) => {
77
66
  } else if (Object.prototype.toString.call(value) === '[object Date]' && String(value) !== 'Invalid Date') {
78
67
  return true;
79
68
  }
80
-
81
69
  return false;
82
70
  };
71
+
83
72
  /**
84
73
  * get the end of month from month and year or from a date
85
74
  * @param {Number|String|Date|Array} month the month of year (can also be validated as year) or a value with date type
86
75
  * @param {Number} year the year (can also be validated as month if arg 1 is year)
87
76
  * @returns {Number} end day
88
77
  */
89
-
90
78
  export const getEndDayOfMonth = (month, year) => {
91
79
  if (!year) {
92
80
  if (/number|string/.test(typeof month) || Array.isArray(month)) {
93
81
  month = getDate(getDate, undefined, false);
94
-
95
82
  if (String(month) !== 'Invalid Date') {
96
83
  return new Date(month.getFullYear(), month.getMonth(), 0).getDate();
97
84
  }
@@ -100,34 +87,28 @@ export const getEndDayOfMonth = (month, year) => {
100
87
  }
101
88
  } else if (!isNaN(month) && !isNaN(year)) {
102
89
  var _Date, _Date$getDate;
103
-
104
90
  return (_Date = new Date(year > 12 ? year : year - 1, month > 12 ? month : month - 1, 0)) === null || _Date === void 0 ? void 0 : (_Date$getDate = _Date.getDate) === null || _Date$getDate === void 0 ? void 0 : _Date$getDate.call(_Date);
105
91
  }
106
-
107
92
  return 'Invalid Date';
108
93
  };
94
+
109
95
  /**
110
96
  * return a date time follow the concrete format
111
97
  * @param {Date|String|Array} value is a date time
112
98
  * @param {String} formatOutput format of date
113
99
  * @param {Boolean} utc is utc time
114
100
  */
115
-
116
101
  export const formatDate = (value, formatOutput = 'DD/MM/YYYY', utc = false) => {
117
102
  if (!value) return formatOutput;
118
103
  formatOutput = formatOutput.trim();
119
-
120
104
  if (typeof value === 'string') {
121
105
  value = new Date(value);
122
-
123
106
  if (String(value) === 'Invalid Date') {
124
107
  return 'Invalid Date';
125
108
  }
126
109
  }
127
-
128
110
  const dateTime = (() => {
129
111
  var _value$toTimeString$m;
130
-
131
112
  const UTC = utc ? 'UTC' : '';
132
113
  const year = value['get' + UTC + 'FullYear']();
133
114
  const month = value['get' + UTC + 'Month']();
@@ -165,6 +146,7 @@ export const formatDate = (value, formatOutput = 'DD/MM/YYYY', utc = false) => {
165
146
  // 3
166
147
  Q: Math.ceil((month + 1) / 3),
167
148
  // 1
149
+
168
150
  // Hour + Minute + second
169
151
  H: hours,
170
152
  HH: ('0' + hours.toString()).slice(-2),
@@ -184,83 +166,65 @@ export const formatDate = (value, formatOutput = 'DD/MM/YYYY', utc = false) => {
184
166
  ZZ: timeZone
185
167
  };
186
168
  })();
187
-
188
169
  const dateTimeFormat = (options = {}) => {
189
170
  return new Intl.DateTimeFormat(localeName, options).format(value);
190
171
  };
191
-
192
172
  const getFullTime = unit => {
193
173
  const fullDate = value.toLocaleDateString(localeName); // "1/26/2020"
194
-
195
174
  const lll = dateTimeFormat({
196
175
  dateStyle: 'medium',
197
176
  timeStyle: 'short'
198
177
  });
199
-
200
178
  switch (unit) {
201
179
  case 'L':
202
180
  return fullDate.split('/').map(v => v.length > 1 ? v : '0' + v).join('/');
203
-
204
181
  case 'l':
205
182
  return fullDate;
206
-
207
183
  case 'LL':
208
184
  return dateTimeFormat({
209
185
  dateStyle: 'long'
210
186
  });
211
-
212
187
  case 'll':
213
188
  return dateTimeFormat({
214
189
  dateStyle: 'medium'
215
190
  });
216
-
217
191
  case 'LLL':
218
192
  return dateTimeFormat({
219
193
  dateStyle: 'long',
220
194
  timeStyle: 'short'
221
195
  });
222
-
223
196
  case 'lll':
224
197
  return lll;
225
-
226
198
  case 'LLLL':
227
199
  return dateTimeFormat({
228
200
  dateStyle: 'full',
229
201
  timeStyle: 'short'
230
202
  });
231
-
232
203
  case 'llll':
233
204
  return dateTime.ddd + ', ' + lll;
234
-
235
205
  case 'LT':
236
206
  return dateTimeFormat({
237
207
  date: 'none',
238
208
  timeStyle: 'short'
239
209
  });
240
-
241
210
  case 'LTS':
242
211
  return dateTimeFormat({
243
212
  date: 'none',
244
213
  timeStyle: 'medium'
245
214
  });
246
-
247
215
  default:
248
216
  return 'Invalid format';
249
217
  }
250
218
  };
251
-
252
219
  const getUnitFormat = unit => {
253
220
  if (/l/i.test(unit)) {
254
221
  return getFullTime(unit);
255
222
  }
256
-
257
223
  {
258
224
  return dateTime[unit];
259
225
  }
260
226
  };
261
-
262
227
  const arrFormat = formatOutput.split(/\W+/g);
263
-
264
228
  if (arrFormat.length) {
265
229
  arrFormat.forEach(unit => {
266
230
  formatOutput = formatOutput.replace(unit, getUnitFormat(unit));
@@ -268,15 +232,16 @@ export const formatDate = (value, formatOutput = 'DD/MM/YYYY', utc = false) => {
268
232
  return formatOutput;
269
233
  }
270
234
  };
235
+
271
236
  /**
272
237
  * return a date like moment
273
238
  * @param {Date|String|Array} value is date time
274
239
  * @param {String} formatInput format of input date value
275
240
  * @returns {Object} date
276
241
  */
277
-
278
242
  const date = (value, formatInput = 'MM/DD/YYYY') => {
279
243
  const originDate = getDate(value, formatInput);
244
+
280
245
  /**
281
246
  * compare two date time and return a period
282
247
  * @param {Date|String|Array} date is a date time
@@ -284,36 +249,28 @@ const date = (value, formatInput = 'MM/DD/YYYY') => {
284
249
  * @param {Boolean|Number} floating allow odd numbers
285
250
  * @returns {Number} distance
286
251
  */
287
-
288
252
  const diff = (compareDate, unit = 'days', floating = false) => {
289
253
  compareDate = getDate(compareDate);
290
-
291
254
  if (String(compareDate) === 'Invalid Date' || !isValidDate(originDate, formatInput)) {
292
255
  return 'Invalid Date';
293
256
  }
294
-
295
257
  let result = [];
296
-
297
258
  if (/months|years/.test(unit.toLowerCase())) {
298
259
  const originDateArr = formatDate(originDate, 'YYYY/MM/DD HH:mm:ss').split(/\W+/);
299
260
  const compareDateArr = formatDate(compareDate, 'YYYY/MM/DD HH:mm:ss').split(/\W+/);
300
261
  const endDayOfMonth = getEndDayOfMonth(originDate);
301
262
  const similarMaxTimeArr = [1, 12, endDayOfMonth, 24, 60, 60, 1000];
302
263
  let decimalTotal = 0,
303
- currentValueOfUnit = 1;
304
-
264
+ currentValueOfUnit = 1;
305
265
  for (let i = originDateArr.length - 1; i >= 0; i--) {
306
266
  result[i] = originDateArr[i] - compareDateArr[i];
307
-
308
267
  if (i > 1) {
309
268
  currentValueOfUnit *= similarMaxTimeArr[i + 1];
310
269
  decimalTotal += result[i] * currentValueOfUnit;
311
270
  }
312
271
  }
313
-
314
272
  const decimalOfMonth = decimalTotal / (endDayOfMonth * 86400000);
315
273
  result = result[0] * 12 + result[1] + decimalOfMonth;
316
-
317
274
  if (unit.toLowerCase() === 'years') {
318
275
  result = result / 12;
319
276
  }
@@ -322,29 +279,23 @@ const date = (value, formatInput = 'MM/DD/YYYY') => {
322
279
  switch (unit.toLowerCase()) {
323
280
  case 'days':
324
281
  return 86400000;
325
-
326
282
  case 'hours':
327
283
  return 3600000;
328
-
329
284
  case 'minutes':
330
285
  return 60000;
331
-
332
286
  case 'seconds':
333
287
  return 1000;
334
-
335
288
  case 'milliseconds':
336
289
  return 1;
337
-
338
290
  default:
339
291
  return 86400000 * week;
340
292
  }
341
293
  };
342
-
343
294
  result = (originDate.valueOf() - compareDate.valueOf()) / getValueOfUnit(unit === 'weeks' ? 1 : 7);
344
295
  }
345
-
346
296
  return result.toFixed(floating ? typeof floating === 'number' ? floating : 2 : 0);
347
297
  };
298
+
348
299
  /**
349
300
  * add or subtract date time
350
301
  * @param {Number} num the quantity to cal for unit
@@ -352,36 +303,29 @@ const date = (value, formatInput = 'MM/DD/YYYY') => {
352
303
  * @param {String} operator operator to cal (add/subtract)
353
304
  * @returns {Object} date
354
305
  */
355
-
356
-
357
306
  const calculation = (num, unit, operator) => {
358
307
  if (isNaN(num)) {
359
308
  return NaN;
360
- } // Example: unit === 'days' -> originDate.setDate(originDate.getDate() +/- num)
361
-
362
-
309
+ }
310
+ // Example: unit === 'days' -> originDate.setDate(originDate.getDate() +/- num)
363
311
  originDate['set' + getMethodOfUnit(unit)](originDate['get' + getMethodOfUnit(unit)]() + (operator === 'add' ? +num : -num));
364
312
  return date(originDate, formatInput);
365
313
  };
314
+
366
315
  /**
367
316
  * get the moment of time follow unit time
368
317
  * @param {String} unit the unit of time
369
318
  * @param {String} moment start|end to get start|end of the moment
370
319
  * @returns {Object} date
371
320
  */
372
-
373
-
374
321
  const timeOf = (unit, moment) => {
375
322
  let temp = 1;
376
-
377
323
  if (!units.includes(unit)) {
378
324
  unit = 'day';
379
325
  }
380
-
381
326
  units.forEach(u => {
382
327
  const method = getMethodOfUnit(u);
383
328
  const valueUnitTime = originDate['get' + method]();
384
-
385
329
  if (u === unit) {
386
330
  const addTime = moment === 'start' ? 0 : 1;
387
331
  originDate['set' + method](valueUnitTime + addTime);
@@ -393,6 +337,7 @@ const date = (value, formatInput = 'MM/DD/YYYY') => {
393
337
  });
394
338
  return date(originDate, formatInput);
395
339
  };
340
+
396
341
  /**
397
342
  *
398
343
  * @param {Date|String|Number|Array} compareDate date to calculate moment, undefined will compare with now
@@ -400,29 +345,21 @@ const date = (value, formatInput = 'MM/DD/YYYY') => {
400
345
  * @param {Boolean|Number} floating allow odd numbers
401
346
  * @returns {String} moments
402
347
  */
403
-
404
-
405
348
  const relative = (compareDate, unit, floating) => {
406
349
  compareDate = getDate(compareDate);
407
-
408
350
  if (String(compareDate) === 'Invalid Date' || !isValidDate(originDate, formatInput)) {
409
351
  return 'Invalid Date';
410
352
  }
411
-
412
353
  if (typeof unit === 'string' && /s$/.test(unit)) {
413
354
  unit = unit.replace(/s$/, '');
414
355
  }
415
-
416
356
  if (!unit || typeof unit === 'string' && !units.includes(unit)) {
417
357
  unit = units;
418
358
  }
419
-
420
359
  let num;
421
-
422
360
  if (Array.isArray(unit)) {
423
361
  for (let i = 0; i < unit.length; i++) {
424
362
  num = diff(compareDate, unit[i] + 's', floating ? typeof floating === 'number' ? floating : 2 : 1);
425
-
426
363
  if (Math.abs(num) >= 1) {
427
364
  unit = unit[i];
428
365
  break;
@@ -431,9 +368,7 @@ const date = (value, formatInput = 'MM/DD/YYYY') => {
431
368
  } else {
432
369
  num = diff(compareDate, unit + 's', floating ? typeof floating === 'number' ? floating : 2 : 1);
433
370
  }
434
-
435
371
  num = (+num).toFixed(floating ? typeof floating === 'number' ? floating : 2 : 0);
436
-
437
372
  try {
438
373
  return new Intl.RelativeTimeFormat(language, {
439
374
  numeric: "auto"
@@ -442,10 +377,8 @@ const date = (value, formatInput = 'MM/DD/YYYY') => {
442
377
  return e.message;
443
378
  }
444
379
  };
445
-
446
380
  return {
447
381
  value: originDate,
448
-
449
382
  /**
450
383
  * return a date time follow the concrete format
451
384
  * @param {String} formatOutput format of date
@@ -453,7 +386,6 @@ const date = (value, formatInput = 'MM/DD/YYYY') => {
453
386
  */
454
387
  format: (formatOutput, utc) => formatDate(originDate, formatOutput, utc),
455
388
  diff,
456
-
457
389
  /**
458
390
  * check 1 value is a date
459
391
  * @param {String} formatInput the format date to check valid date
@@ -467,5 +399,4 @@ const date = (value, formatInput = 'MM/DD/YYYY') => {
467
399
  relative
468
400
  };
469
401
  };
470
-
471
402
  export default date;