@yelon/util 12.0.13 → 12.0.17

Sign up to get free protection for your applications and to get access to all the features.
Files changed (231) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +2 -2
  3. package/array/array-type.service.d.ts +68 -68
  4. package/array/array.service.d.ts +75 -75
  5. package/array/index.d.ts +2 -2
  6. package/array/yelon-util-array.d.ts +4 -4
  7. package/array/yelon-util-array.metadata.json +1 -1
  8. package/browser/browser.d.ts +4 -4
  9. package/browser/cookie.service.d.ts +64 -64
  10. package/browser/copy.d.ts +6 -6
  11. package/browser/index.d.ts +5 -5
  12. package/browser/is-empty.d.ts +6 -6
  13. package/browser/scroll.service.d.ts +34 -34
  14. package/browser/style.d.ts +21 -21
  15. package/bundles/browser.umd.js +275 -275
  16. package/bundles/yelon-util-array.umd.js +606 -606
  17. package/bundles/yelon-util-array.umd.js.map +1 -1
  18. package/bundles/yelon-util-config.umd.js +366 -366
  19. package/bundles/yelon-util-date-time.umd.js +216 -216
  20. package/bundles/yelon-util-decorator.umd.js +437 -437
  21. package/bundles/yelon-util-form.umd.js +116 -116
  22. package/bundles/yelon-util-format.umd.js +726 -726
  23. package/bundles/yelon-util-math.umd.js +83 -83
  24. package/bundles/yelon-util-other.umd.js +652 -656
  25. package/bundles/yelon-util-other.umd.js.map +1 -1
  26. package/bundles/yelon-util-pipes-currency.umd.js +83 -83
  27. package/bundles/yelon-util-pipes-filter.umd.js +353 -353
  28. package/bundles/yelon-util-pipes-format.umd.js +47 -47
  29. package/bundles/yelon-util-pipes.umd.js +7 -7
  30. package/bundles/yelon-util-token.umd.js +30 -30
  31. package/bundles/yelon-util.umd.js +7 -7
  32. package/config/abc/date-picker.type.d.ts +52 -52
  33. package/config/abc/error-collect.type.d.ts +10 -10
  34. package/config/abc/image.type.d.ts +15 -15
  35. package/config/abc/index.d.ts +16 -16
  36. package/config/abc/loading.type.d.ts +31 -31
  37. package/config/abc/lodop.type.d.ts +33 -33
  38. package/config/abc/media.type.d.ts +11 -11
  39. package/config/abc/onboarding.type.d.ts +4 -4
  40. package/config/abc/page-header.type.d.ts +39 -39
  41. package/config/abc/pdf.type.d.ts +35 -35
  42. package/config/abc/qr.type.d.ts +25 -25
  43. package/config/abc/se.type.d.ts +32 -32
  44. package/config/abc/sg.type.d.ts +10 -10
  45. package/config/abc/st.type.d.ts +427 -431
  46. package/config/abc/sv.type.d.ts +14 -14
  47. package/config/abc/xlsx.type.d.ts +12 -12
  48. package/config/abc/zip.type.d.ts +10 -10
  49. package/config/acl/acl.type.d.ts +32 -32
  50. package/config/auth/auth.type.d.ts +55 -55
  51. package/config/bis/bis.type.d.ts +7 -7
  52. package/config/cache/cache.type.d.ts +40 -40
  53. package/config/chart/chart.type.d.ts +33 -33
  54. package/config/config.service.d.ts +10 -10
  55. package/config/config.types.d.ts +49 -49
  56. package/config/index.d.ts +14 -14
  57. package/config/mock/mock.type.d.ts +18 -18
  58. package/config/sf/sf.type.d.ts +127 -127
  59. package/config/stomp/stomp.type.d.ts +2 -2
  60. package/config/theme/http.type.d.ts +14 -14
  61. package/config/theme/i18n.type.d.ts +8 -8
  62. package/config/theme/index.d.ts +3 -3
  63. package/config/theme/responsive.type.d.ts +12 -12
  64. package/config/util/array.type.d.ts +22 -22
  65. package/config/util/currency.type.d.ts +39 -39
  66. package/config/yelon-util-config.d.ts +4 -4
  67. package/date-time/index.d.ts +2 -2
  68. package/date-time/picker.d.ts +68 -68
  69. package/date-time/time.d.ts +26 -26
  70. package/date-time/yelon-util-date-time.d.ts +4 -4
  71. package/decorator/convert.d.ts +24 -24
  72. package/decorator/index.d.ts +2 -2
  73. package/decorator/yelon-util-decorator.d.ts +4 -4
  74. package/decorator/zone-outside.d.ts +35 -35
  75. package/esm2015/array/array-type.service.js +1 -1
  76. package/esm2015/array/array.service.js +250 -250
  77. package/esm2015/array/index.js +2 -2
  78. package/esm2015/array/yelon-util-array.js +4 -4
  79. package/esm2015/browser/browser.js +4 -4
  80. package/esm2015/browser/cookie.service.js +103 -103
  81. package/esm2015/browser/copy.js +26 -26
  82. package/esm2015/browser/index.js +5 -5
  83. package/esm2015/browser/is-empty.js +18 -18
  84. package/esm2015/browser/scroll.service.js +88 -88
  85. package/esm2015/browser/style.js +37 -37
  86. package/esm2015/config/abc/date-picker.type.js +1 -1
  87. package/esm2015/config/abc/error-collect.type.js +1 -1
  88. package/esm2015/config/abc/image.type.js +1 -1
  89. package/esm2015/config/abc/index.js +16 -16
  90. package/esm2015/config/abc/loading.type.js +1 -1
  91. package/esm2015/config/abc/lodop.type.js +1 -1
  92. package/esm2015/config/abc/media.type.js +1 -1
  93. package/esm2015/config/abc/onboarding.type.js +1 -1
  94. package/esm2015/config/abc/page-header.type.js +1 -1
  95. package/esm2015/config/abc/pdf.type.js +1 -1
  96. package/esm2015/config/abc/qr.type.js +1 -1
  97. package/esm2015/config/abc/se.type.js +1 -1
  98. package/esm2015/config/abc/sg.type.js +1 -1
  99. package/esm2015/config/abc/st.type.js +2 -2
  100. package/esm2015/config/abc/sv.type.js +2 -2
  101. package/esm2015/config/abc/xlsx.type.js +1 -1
  102. package/esm2015/config/abc/zip.type.js +1 -1
  103. package/esm2015/config/acl/acl.type.js +1 -1
  104. package/esm2015/config/auth/auth.type.js +1 -1
  105. package/esm2015/config/bis/bis.type.js +1 -1
  106. package/esm2015/config/cache/cache.type.js +1 -1
  107. package/esm2015/config/chart/chart.type.js +1 -1
  108. package/esm2015/config/config.service.js +33 -33
  109. package/esm2015/config/config.types.js +8 -8
  110. package/esm2015/config/index.js +14 -14
  111. package/esm2015/config/mock/mock.type.js +1 -1
  112. package/esm2015/config/sf/sf.type.js +1 -1
  113. package/esm2015/config/stomp/stomp.type.js +1 -1
  114. package/esm2015/config/theme/http.type.js +1 -1
  115. package/esm2015/config/theme/i18n.type.js +1 -1
  116. package/esm2015/config/theme/index.js +3 -3
  117. package/esm2015/config/theme/responsive.type.js +1 -1
  118. package/esm2015/config/util/array.type.js +1 -1
  119. package/esm2015/config/util/currency.type.js +1 -1
  120. package/esm2015/config/yelon-util-config.js +4 -4
  121. package/esm2015/date-time/index.js +2 -2
  122. package/esm2015/date-time/picker.js +115 -115
  123. package/esm2015/date-time/time.js +83 -83
  124. package/esm2015/date-time/yelon-util-date-time.js +4 -4
  125. package/esm2015/decorator/convert.js +55 -55
  126. package/esm2015/decorator/index.js +2 -2
  127. package/esm2015/decorator/yelon-util-decorator.js +4 -4
  128. package/esm2015/decorator/zone-outside.js +54 -54
  129. package/esm2015/form/index.js +2 -2
  130. package/esm2015/form/match-control.js +29 -29
  131. package/esm2015/form/validators.js +80 -80
  132. package/esm2015/form/yelon-util-form.js +4 -4
  133. package/esm2015/format/currency.service.js +224 -224
  134. package/esm2015/format/currency.types.js +7 -7
  135. package/esm2015/format/index.js +4 -4
  136. package/esm2015/format/string.js +75 -75
  137. package/esm2015/format/validate.js +93 -93
  138. package/esm2015/format/yelon-util-format.js +4 -4
  139. package/esm2015/index.js +11 -11
  140. package/esm2015/math/in-range.js +24 -24
  141. package/esm2015/math/index.js +2 -2
  142. package/esm2015/math/round.js +52 -52
  143. package/esm2015/math/yelon-util-math.js +4 -4
  144. package/esm2015/other/assert.js +66 -66
  145. package/esm2015/other/deep.js +76 -76
  146. package/esm2015/other/index.js +4 -4
  147. package/esm2015/other/lazy.service.js +118 -118
  148. package/esm2015/other/logger.js +33 -36
  149. package/esm2015/other/yelon-util-other.js +4 -4
  150. package/esm2015/pipes/currency/cny.pipe.js +21 -21
  151. package/esm2015/pipes/currency/index.js +3 -3
  152. package/esm2015/pipes/currency/mega.pipe.js +25 -25
  153. package/esm2015/pipes/currency/module.js +13 -13
  154. package/esm2015/pipes/currency/price.pipe.js +25 -25
  155. package/esm2015/pipes/currency/yelon-util-pipes-currency.js +5 -5
  156. package/esm2015/pipes/filter/filter.pipe.js +14 -14
  157. package/esm2015/pipes/filter/index.js +2 -2
  158. package/esm2015/pipes/filter/module.js +11 -11
  159. package/esm2015/pipes/filter/yelon-util-pipes-filter.js +4 -4
  160. package/esm2015/pipes/format/index.js +2 -2
  161. package/esm2015/pipes/format/mask.pipe.js +29 -29
  162. package/esm2015/pipes/format/module.js +11 -11
  163. package/esm2015/pipes/format/yelon-util-pipes-format.js +4 -4
  164. package/esm2015/pipes/index.js +3 -3
  165. package/esm2015/pipes/yelon-util-pipes.js +4 -4
  166. package/esm2015/token/index.js +2 -2
  167. package/esm2015/token/page-visibility.js +15 -15
  168. package/esm2015/token/window.js +16 -16
  169. package/esm2015/token/yelon-util-token.js +4 -4
  170. package/esm2015/yelon-util.js +4 -4
  171. package/fesm2015/browser.js +257 -257
  172. package/fesm2015/yelon-util-array.js +246 -246
  173. package/fesm2015/yelon-util-array.js.map +1 -1
  174. package/fesm2015/yelon-util-config.js +36 -36
  175. package/fesm2015/yelon-util-date-time.js +196 -196
  176. package/fesm2015/yelon-util-decorator.js +107 -107
  177. package/fesm2015/yelon-util-form.js +108 -108
  178. package/fesm2015/yelon-util-format.js +390 -390
  179. package/fesm2015/yelon-util-math.js +75 -75
  180. package/fesm2015/yelon-util-other.js +281 -284
  181. package/fesm2015/yelon-util-other.js.map +1 -1
  182. package/fesm2015/yelon-util-pipes-currency.js +72 -72
  183. package/fesm2015/yelon-util-pipes-filter.js +22 -22
  184. package/fesm2015/yelon-util-pipes-format.js +36 -36
  185. package/fesm2015/yelon-util-pipes.js +2 -2
  186. package/fesm2015/yelon-util-token.js +25 -25
  187. package/fesm2015/yelon-util.js +2 -2
  188. package/form/index.d.ts +2 -2
  189. package/form/match-control.d.ts +15 -15
  190. package/form/validators.d.ts +62 -62
  191. package/form/yelon-util-form.d.ts +4 -4
  192. package/format/currency.service.d.ts +34 -34
  193. package/format/currency.types.d.ts +77 -77
  194. package/format/index.d.ts +4 -4
  195. package/format/string.d.ts +44 -44
  196. package/format/validate.d.ts +72 -72
  197. package/format/yelon-util-format.d.ts +4 -4
  198. package/index.d.ts +11 -11
  199. package/math/in-range.d.ts +14 -14
  200. package/math/index.d.ts +2 -2
  201. package/math/round.d.ts +33 -33
  202. package/math/yelon-util-math.d.ts +4 -4
  203. package/other/assert.d.ts +36 -36
  204. package/other/deep.d.ts +33 -33
  205. package/other/index.d.ts +4 -4
  206. package/other/lazy.service.d.ts +22 -22
  207. package/other/logger.d.ts +5 -6
  208. package/other/yelon-util-other.d.ts +4 -4
  209. package/other/yelon-util-other.metadata.json +1 -1
  210. package/package.json +1 -1
  211. package/pipes/currency/cny.pipe.d.ts +12 -12
  212. package/pipes/currency/index.d.ts +3 -3
  213. package/pipes/currency/mega.pipe.d.ts +13 -13
  214. package/pipes/currency/module.d.ts +2 -2
  215. package/pipes/currency/price.pipe.d.ts +16 -16
  216. package/pipes/currency/yelon-util-pipes-currency.d.ts +5 -5
  217. package/pipes/filter/filter.pipe.d.ts +10 -10
  218. package/pipes/filter/index.d.ts +2 -2
  219. package/pipes/filter/module.d.ts +2 -2
  220. package/pipes/filter/yelon-util-pipes-filter.d.ts +4 -4
  221. package/pipes/format/index.d.ts +2 -2
  222. package/pipes/format/mask.pipe.d.ts +24 -24
  223. package/pipes/format/module.d.ts +2 -2
  224. package/pipes/format/yelon-util-pipes-format.d.ts +4 -4
  225. package/pipes/index.d.ts +3 -3
  226. package/pipes/yelon-util-pipes.d.ts +4 -4
  227. package/token/index.d.ts +2 -2
  228. package/token/page-visibility.d.ts +8 -8
  229. package/token/window.d.ts +7 -7
  230. package/token/yelon-util-token.d.ts +4 -4
  231. package/yelon-util.d.ts +4 -4
@@ -1,116 +1,116 @@
1
- import { addDays, addSeconds, differenceInCalendarDays, format } from 'date-fns';
2
- // TODO: timezone process
3
- export class DateTimePickerUtil {
4
- /**
5
- * Current local time
6
- *
7
- * 当前本地时间
8
- */
9
- get now() {
10
- return new Date();
11
- }
12
- /**
13
- * Current local date (not including time part)
14
- *
15
- * 当前本地日期(不包含时间部分)
16
- */
17
- get date() {
18
- return this.removeTime(this.now);
19
- }
20
- /**
21
- * Remove the time part of the date
22
- *
23
- * 移除日期的时间部分
24
- */
25
- removeTime(d) {
26
- return new Date(d.toDateString());
27
- }
28
- /**
29
- * Format date-time
30
- *
31
- * 格式化日期
32
- */
33
- format(d, formatString = 'yyyy-MM-dd HH:mm:ss') {
34
- return format(d, formatString);
35
- }
36
- genTick(count) {
37
- return new Array(count).fill(0).map((_, idx) => idx);
38
- }
39
- /**
40
- * Calculate the number of days between two dates, `0` means the same day
41
- *
42
- * 计算两个日期相差天数,`0` 表示同一天
43
- */
44
- getDiffDays(dateLeft, dateRight) {
45
- return differenceInCalendarDays(dateLeft, typeof dateRight === 'number' ? addDays(this.date, dateRight) : dateRight || this.date);
46
- }
47
- /**
48
- * Disabled Before date (Default: today), Generally serves `nzDisabledDate`
49
- *
50
- * 禁用之前日期(默认:今天),一般服务于 `nzDisabledDate`
51
- */
52
- disabledBeforeDate(options) {
53
- return (d) => this.getDiffDays(d, options === null || options === void 0 ? void 0 : options.offsetDays) < 0;
54
- }
55
- /**
56
- * Disabled After date (Default: today), Generally serves `nzDisabledDate`
57
- *
58
- * 禁用之后日期(默认:今天),一般服务于 `nzDisabledDate`
59
- */
60
- disabledAfterDate(options) {
61
- return (d) => this.getDiffDays(d, options === null || options === void 0 ? void 0 : options.offsetDays) > 0;
62
- }
63
- baseDisabledTime(type, offsetSeconds) {
64
- const tick24 = this.genTick(24);
65
- const tick60 = this.genTick(60);
66
- return (current) => {
67
- const cur = current;
68
- if (cur == null) {
69
- return {};
70
- }
71
- const now = addSeconds(this.now, offsetSeconds || 0);
72
- const nowHours = now.getHours();
73
- const nowMinutes = now.getMinutes();
74
- const curHours = cur.getHours();
75
- const isToday = this.getDiffDays(this.removeTime(cur)) === 0;
76
- return {
77
- nzDisabledHours: () => {
78
- if (!isToday)
79
- return [];
80
- return type === 'before' ? tick24.slice(0, nowHours) : tick24.slice(nowHours + 1);
81
- },
82
- nzDisabledMinutes: () => {
83
- if (isToday && curHours === nowHours) {
84
- return type === 'before' ? tick60.slice(0, nowMinutes) : tick60.slice(nowMinutes + 1);
85
- }
86
- return [];
87
- },
88
- nzDisabledSeconds: () => {
89
- if (isToday && curHours === nowHours && cur.getMinutes() === nowMinutes) {
90
- const nowSeconds = now.getSeconds();
91
- return type === 'before' ? tick60.slice(0, nowSeconds) : tick60.slice(nowSeconds + 1);
92
- }
93
- return [];
94
- }
95
- };
96
- };
97
- }
98
- /**
99
- * Disabled Before time (Default: now), Generally serves `nzDisabledTime`
100
- *
101
- * 禁用之前时间(默认:现在),一般服务于 `nzDisabledTime`
102
- */
103
- disabledBeforeTime(options) {
104
- return this.baseDisabledTime('before', options === null || options === void 0 ? void 0 : options.offsetSeconds);
105
- }
106
- /**
107
- * Disabled After time (Default: now), Generally serves `nzDisabledTime`
108
- *
109
- * 禁用之后时间(默认:现在),一般服务于 `nzDisabledTime`
110
- */
111
- disabledAfterTime(options) {
112
- return this.baseDisabledTime('after', options === null || options === void 0 ? void 0 : options.offsetSeconds);
113
- }
114
- }
115
- export const dateTimePickerUtil = new DateTimePickerUtil();
1
+ import { addDays, addSeconds, differenceInCalendarDays, format } from 'date-fns';
2
+ // TODO: timezone process
3
+ export class DateTimePickerUtil {
4
+ /**
5
+ * Current local time
6
+ *
7
+ * 当前本地时间
8
+ */
9
+ get now() {
10
+ return new Date();
11
+ }
12
+ /**
13
+ * Current local date (not including time part)
14
+ *
15
+ * 当前本地日期(不包含时间部分)
16
+ */
17
+ get date() {
18
+ return this.removeTime(this.now);
19
+ }
20
+ /**
21
+ * Remove the time part of the date
22
+ *
23
+ * 移除日期的时间部分
24
+ */
25
+ removeTime(d) {
26
+ return new Date(d.toDateString());
27
+ }
28
+ /**
29
+ * Format date-time
30
+ *
31
+ * 格式化日期
32
+ */
33
+ format(d, formatString = 'yyyy-MM-dd HH:mm:ss') {
34
+ return format(d, formatString);
35
+ }
36
+ genTick(count) {
37
+ return new Array(count).fill(0).map((_, idx) => idx);
38
+ }
39
+ /**
40
+ * Calculate the number of days between two dates, `0` means the same day
41
+ *
42
+ * 计算两个日期相差天数,`0` 表示同一天
43
+ */
44
+ getDiffDays(dateLeft, dateRight) {
45
+ return differenceInCalendarDays(dateLeft, typeof dateRight === 'number' ? addDays(this.date, dateRight) : dateRight || this.date);
46
+ }
47
+ /**
48
+ * Disabled Before date (Default: today), Generally serves `nzDisabledDate`
49
+ *
50
+ * 禁用之前日期(默认:今天),一般服务于 `nzDisabledDate`
51
+ */
52
+ disabledBeforeDate(options) {
53
+ return (d) => this.getDiffDays(d, options === null || options === void 0 ? void 0 : options.offsetDays) < 0;
54
+ }
55
+ /**
56
+ * Disabled After date (Default: today), Generally serves `nzDisabledDate`
57
+ *
58
+ * 禁用之后日期(默认:今天),一般服务于 `nzDisabledDate`
59
+ */
60
+ disabledAfterDate(options) {
61
+ return (d) => this.getDiffDays(d, options === null || options === void 0 ? void 0 : options.offsetDays) > 0;
62
+ }
63
+ baseDisabledTime(type, offsetSeconds) {
64
+ const tick24 = this.genTick(24);
65
+ const tick60 = this.genTick(60);
66
+ return (current) => {
67
+ const cur = current;
68
+ if (cur == null) {
69
+ return {};
70
+ }
71
+ const now = addSeconds(this.now, offsetSeconds || 0);
72
+ const nowHours = now.getHours();
73
+ const nowMinutes = now.getMinutes();
74
+ const curHours = cur.getHours();
75
+ const isToday = this.getDiffDays(this.removeTime(cur)) === 0;
76
+ return {
77
+ nzDisabledHours: () => {
78
+ if (!isToday)
79
+ return [];
80
+ return type === 'before' ? tick24.slice(0, nowHours) : tick24.slice(nowHours + 1);
81
+ },
82
+ nzDisabledMinutes: () => {
83
+ if (isToday && curHours === nowHours) {
84
+ return type === 'before' ? tick60.slice(0, nowMinutes) : tick60.slice(nowMinutes + 1);
85
+ }
86
+ return [];
87
+ },
88
+ nzDisabledSeconds: () => {
89
+ if (isToday && curHours === nowHours && cur.getMinutes() === nowMinutes) {
90
+ const nowSeconds = now.getSeconds();
91
+ return type === 'before' ? tick60.slice(0, nowSeconds) : tick60.slice(nowSeconds + 1);
92
+ }
93
+ return [];
94
+ }
95
+ };
96
+ };
97
+ }
98
+ /**
99
+ * Disabled Before time (Default: now), Generally serves `nzDisabledTime`
100
+ *
101
+ * 禁用之前时间(默认:现在),一般服务于 `nzDisabledTime`
102
+ */
103
+ disabledBeforeTime(options) {
104
+ return this.baseDisabledTime('before', options === null || options === void 0 ? void 0 : options.offsetSeconds);
105
+ }
106
+ /**
107
+ * Disabled After time (Default: now), Generally serves `nzDisabledTime`
108
+ *
109
+ * 禁用之后时间(默认:现在),一般服务于 `nzDisabledTime`
110
+ */
111
+ disabledAfterTime(options) {
112
+ return this.baseDisabledTime('after', options === null || options === void 0 ? void 0 : options.offsetSeconds);
113
+ }
114
+ }
115
+ export const dateTimePickerUtil = new DateTimePickerUtil();
116
116
  //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicGlja2VyLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vLi4vLi4vcGFja2FnZXMvdXRpbC9kYXRlLXRpbWUvcGlja2VyLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLE9BQU8sRUFBRSxPQUFPLEVBQUUsVUFBVSxFQUFFLHdCQUF3QixFQUFFLE1BQU0sRUFBRSxNQUFNLFVBQVUsQ0FBQztBQUtqRix5QkFBeUI7QUFDekIsTUFBTSxPQUFPLGtCQUFrQjtJQUM3Qjs7OztPQUlHO0lBQ0gsSUFBSSxHQUFHO1FBQ0wsT0FBTyxJQUFJLElBQUksRUFBRSxDQUFDO0lBQ3BCLENBQUM7SUFDRDs7OztPQUlHO0lBQ0gsSUFBSSxJQUFJO1FBQ04sT0FBTyxJQUFJLENBQUMsVUFBVSxDQUFDLElBQUksQ0FBQyxHQUFHLENBQUMsQ0FBQztJQUNuQyxDQUFDO0lBQ0Q7Ozs7T0FJRztJQUNILFVBQVUsQ0FBQyxDQUFPO1FBQ2hCLE9BQU8sSUFBSSxJQUFJLENBQUMsQ0FBQyxDQUFDLFlBQVksRUFBRSxDQUFDLENBQUM7SUFDcEMsQ0FBQztJQUNEOzs7O09BSUc7SUFDSCxNQUFNLENBQ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IG5vdyksIEdlbmVyYWxseSBzZXJ2ZXMgYG56RGlzYWJsZWRUaW1lYFxuICAgKlxuICAgKiDnpoHnlKjkuYvlkI7ml7bpl7TvvIjpu5jorqTvvJrnjrDlnKjvvInvvIzkuIDoiKzmnI3liqHkuo4gYG56RGlzYWJsZWRUaW1lYFxuICAgKi9cbiAgZGlzYWJsZWRBZnRlclRpbWUob3B0aW9ucz86IHsgb2Zmc2V0U2Vjb25kcz86IG51bWJlciB9KTogRGlzYWJsZWRUaW1lRm4ge1xuICAgIHJldHVybiB0aGlzLmJhc2VEaXNhYmxlZFRpbWUoJ2FmdGVyJywgb3B0aW9ucz8ub2Zmc2V0U2Vjb25kcyk7XG4gIH1cbn1cblxuZXhwb3J0IGNvbnN0IGRhdGVUaW1lUGlja2VyVXRpbCA9IG5ldyBEYXRlVGltZVBpY2tlclV0aWwoKTtcbiJdfQ==
@@ -1,84 +1,84 @@
1
- import { addDays, endOfDay, endOfMonth, endOfWeek, endOfYear, parse, parseISO, startOfDay, startOfMonth, startOfWeek, startOfYear, subMonths, subWeeks, subYears } from 'date-fns';
2
- /**
3
- * Get the time range, return `[ Date, Date]` for the start and end dates
4
- *
5
- * 获取时间范围
6
- *
7
- * @param type 类型,带 `-` 表示过去一个时间,若指定 `number` 表示天数
8
- * @param time 开始时间
9
- */
10
- export function getTimeDistance(type, time) {
11
- time = time
12
- ? typeof time === 'string'
13
- ? parse(time, 'yyyy-MM-dd HH:mm:ss', new Date())
14
- : new Date(time)
15
- : new Date();
16
- const options = { weekStartsOn: 1 };
17
- let res;
18
- switch (type) {
19
- case 'today':
20
- res = [time, time];
21
- break;
22
- case '-today':
23
- res = [addDays(time, -1), time];
24
- break;
25
- case 'yesterday':
26
- res = [addDays(time, -1), addDays(time, -1)];
27
- break;
28
- case 'week':
29
- res = [startOfWeek(time, options), endOfWeek(time, options)];
30
- break;
31
- case '-week':
32
- res = [startOfWeek(subWeeks(time, 1), options), endOfWeek(subWeeks(time, 1), options)];
33
- break;
34
- case 'month':
35
- res = [startOfMonth(time), endOfMonth(time)];
36
- break;
37
- case '-month':
38
- res = [startOfMonth(subMonths(time, 1)), endOfMonth(subMonths(time, 1))];
39
- break;
40
- case 'year':
41
- res = [startOfYear(time), endOfYear(time)];
42
- break;
43
- case '-year':
44
- res = [startOfYear(subYears(time, 1)), endOfYear(subYears(time, 1))];
45
- break;
46
- default:
47
- res = type > 0 ? [time, addDays(time, type)] : [addDays(time, type), time];
48
- break;
49
- }
50
- return fixEndTimeOfRange(res);
51
- }
52
- /**
53
- * fix time is the most, big value
54
- */
55
- export function fixEndTimeOfRange(dates) {
56
- return [startOfDay(dates[0]), endOfDay(dates[1])];
57
- }
58
- /**
59
- * Return the date parsed from string using the given format string
60
- * - If the argument is a number, it is treated as a timestamp.
61
- *
62
- * @param formatString If parsing fails try to parse the date by pressing `formatString`
63
- * @param defaultValue If parsing fails returned default value, default: `new Date(NaN)`
64
- */
65
- export function toDate(value, options) {
66
- if (typeof options === 'string')
67
- options = { formatString: options };
68
- const { formatString, defaultValue } = Object.assign({ formatString: 'yyyy-MM-dd HH:mm:ss', defaultValue: new Date(NaN) }, options);
69
- if (value == null) {
70
- return defaultValue;
71
- }
72
- if (value instanceof Date) {
73
- return value;
74
- }
75
- if (typeof value === 'number' || (typeof value === 'string' && /[0-9]{10,13}/.test(value))) {
76
- return new Date(+value);
77
- }
78
- let tryDate = parseISO(value);
79
- if (isNaN(tryDate)) {
80
- tryDate = parse(value, formatString, new Date());
81
- }
82
- return isNaN(tryDate) ? defaultValue : tryDate;
83
- }
1
+ import { addDays, endOfDay, endOfMonth, endOfWeek, endOfYear, parse, parseISO, startOfDay, startOfMonth, startOfWeek, startOfYear, subMonths, subWeeks, subYears } from 'date-fns';
2
+ /**
3
+ * Get the time range, return `[ Date, Date]` for the start and end dates
4
+ *
5
+ * 获取时间范围
6
+ *
7
+ * @param type 类型,带 `-` 表示过去一个时间,若指定 `number` 表示天数
8
+ * @param time 开始时间
9
+ */
10
+ export function getTimeDistance(type, time) {
11
+ time = time
12
+ ? typeof time === 'string'
13
+ ? parse(time, 'yyyy-MM-dd HH:mm:ss', new Date())
14
+ : new Date(time)
15
+ : new Date();
16
+ const options = { weekStartsOn: 1 };
17
+ let res;
18
+ switch (type) {
19
+ case 'today':
20
+ res = [time, time];
21
+ break;
22
+ case '-today':
23
+ res = [addDays(time, -1), time];
24
+ break;
25
+ case 'yesterday':
26
+ res = [addDays(time, -1), addDays(time, -1)];
27
+ break;
28
+ case 'week':
29
+ res = [startOfWeek(time, options), endOfWeek(time, options)];
30
+ break;
31
+ case '-week':
32
+ res = [startOfWeek(subWeeks(time, 1), options), endOfWeek(subWeeks(time, 1), options)];
33
+ break;
34
+ case 'month':
35
+ res = [startOfMonth(time), endOfMonth(time)];
36
+ break;
37
+ case '-month':
38
+ res = [startOfMonth(subMonths(time, 1)), endOfMonth(subMonths(time, 1))];
39
+ break;
40
+ case 'year':
41
+ res = [startOfYear(time), endOfYear(time)];
42
+ break;
43
+ case '-year':
44
+ res = [startOfYear(subYears(time, 1)), endOfYear(subYears(time, 1))];
45
+ break;
46
+ default:
47
+ res = type > 0 ? [time, addDays(time, type)] : [addDays(time, type), time];
48
+ break;
49
+ }
50
+ return fixEndTimeOfRange(res);
51
+ }
52
+ /**
53
+ * fix time is the most, big value
54
+ */
55
+ export function fixEndTimeOfRange(dates) {
56
+ return [startOfDay(dates[0]), endOfDay(dates[1])];
57
+ }
58
+ /**
59
+ * Return the date parsed from string using the given format string
60
+ * - If the argument is a number, it is treated as a timestamp.
61
+ *
62
+ * @param formatString If parsing fails try to parse the date by pressing `formatString`
63
+ * @param defaultValue If parsing fails returned default value, default: `new Date(NaN)`
64
+ */
65
+ export function toDate(value, options) {
66
+ if (typeof options === 'string')
67
+ options = { formatString: options };
68
+ const { formatString, defaultValue } = Object.assign({ formatString: 'yyyy-MM-dd HH:mm:ss', defaultValue: new Date(NaN) }, options);
69
+ if (value == null) {
70
+ return defaultValue;
71
+ }
72
+ if (value instanceof Date) {
73
+ return value;
74
+ }
75
+ if (typeof value === 'number' || (typeof value === 'string' && /[0-9]{10,13}/.test(value))) {
76
+ return new Date(+value);
77
+ }
78
+ let tryDate = parseISO(value);
79
+ if (isNaN(tryDate)) {
80
+ tryDate = parse(value, formatString, new Date());
81
+ }
82
+ return isNaN(tryDate) ? defaultValue : tryDate;
83
+ }
84
84
  //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGltZS5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uLy4uL3BhY2thZ2VzL3V0aWwvZGF0ZS10aW1lL3RpbWUudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxFQUNMLE9BQU8sRUFDUCxRQUFRLEVBQ1IsVUFBVSxFQUNWLFNBQVMsRUFDVCxTQUFTLEVBQ1QsS0FBSyxFQUNMLFFBQVEsRUFDUixVQUFVLEVBQ1YsWUFBWSxFQUNaLFdBQVcsRUFDWCxXQUFXLEVBQ1gsU0FBUyxFQUNULFFBQVEsRUFDUixRQUFRLEVBQ1QsTUFBTSxVQUFVLENBQUM7QUFJbEI7Ozs7Ozs7R0FPRztBQUNILE1BQU0sVUFBVSxlQUFlLENBQzdCLElBQTBHLEVBQzFHLElBQTZCO0lBRTdCLElBQUksR0FBRyxJQUFJO1FBQ1QsQ0FBQyxDQUFDLE9BQU8sSUFBSSxLQUFLLFFBQVE7WUFDeEIsQ0FBQyxDQUFDLEtBQUssQ0FBQyxJQUFJLEVBQUUscUJBQXFCLEVBQUUsSUFBSSxJQUFJLEVBQUUsQ0FBQztZQUNoRCxDQUFDLENBQUMsSUFBSSxJQUFJLENBQUMsSUFBSSxDQUFDO1FBQ2xCLENBQUMsQ0FBQyxJQUFJLElBQUksRUFBRSxDQUFDO0lBQ2YsTUFBTSxPQUFPLEdBQXdCLEVBQUUsWUFBWSxFQUFFLENBQUMsRUFBRSxDQUFDO0lBR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RyeURhdGU7XG59XG4iXX0=
@@ -1,5 +1,5 @@
1
- /**
2
- * Generated bundle index. Do not edit.
3
- */
4
- export * from './index';
1
+ /**
2
+ * Generated bundle index. Do not edit.
3
+ */
4
+ export * from './index';
5
5
  //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoieWVsb24tdXRpbC1kYXRlLXRpbWUuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi8uLi9wYWNrYWdlcy91dGlsL2RhdGUtdGltZS95ZWxvbi11dGlsLWRhdGUtdGltZS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQTs7R0FFRztBQUVILGNBQWMsU0FBUyxDQUFDIiwic291cmNlc0NvbnRlbnQiOlsiLyoqXG4gKiBHZW5lcmF0ZWQgYnVuZGxlIGluZGV4LiBEbyBub3QgZWRpdC5cbiAqL1xuXG5leHBvcnQgKiBmcm9tICcuL2luZGV4JztcbiJdfQ==
@@ -1,56 +1,56 @@
1
- import { warn } from '@yelon/util/other';
2
- function propDecoratorFactory(name, fallback, defaultValue) {
3
- function propDecorator(target, propName, originalDescriptor) {
4
- const privatePropName = `$$__${propName}`;
5
- if (Object.prototype.hasOwnProperty.call(target, privatePropName)) {
6
- warn(`The prop "${privatePropName}" is already exist, it will be overrided by ${name} decorator.`);
7
- }
8
- Object.defineProperty(target, privatePropName, {
9
- configurable: true,
10
- writable: true
11
- });
12
- return {
13
- get() {
14
- return originalDescriptor && originalDescriptor.get
15
- ? originalDescriptor.get.bind(this)()
16
- : this[privatePropName];
17
- },
18
- set(value) {
19
- if (originalDescriptor && originalDescriptor.set) {
20
- originalDescriptor.set.bind(this)(fallback(value, defaultValue));
21
- }
22
- this[privatePropName] = fallback(value, defaultValue);
23
- }
24
- };
25
- }
26
- return propDecorator;
27
- }
28
- export function toBoolean(value, defaultValue = false) {
29
- return value == null ? defaultValue : `${value}` !== 'false';
30
- }
31
- /**
32
- * Input decorator that handle a prop to do get/set automatically with toBoolean
33
- *
34
- * ```ts
35
- * {AT}Input() {AT}InputBoolean() visible: boolean = false;
36
- * {AT}Input() {AT}InputBoolean(null) visible: boolean = false;
37
- * ```
38
- */
39
- export function InputBoolean(defaultValue = false) {
40
- return propDecoratorFactory('InputBoolean', toBoolean, defaultValue);
41
- }
42
- export function toNumber(value, fallbackValue = 0) {
43
- return !isNaN(parseFloat(value)) && !isNaN(Number(value)) ? Number(value) : fallbackValue;
44
- }
45
- /**
46
- * Input decorator that handle a prop to do get/set automatically with toNumber
47
- *
48
- * ```ts
49
- * {AT}Input() {AT}InputNumber() visible: number = 1;
50
- * {AT}Input() {AT}InputNumber(null) visible: number = 2;
51
- * ```
52
- */
53
- export function InputNumber(defaultValue = 0) {
54
- return propDecoratorFactory('InputNumber', toNumber, defaultValue);
55
- }
1
+ import { warn } from '@yelon/util/other';
2
+ function propDecoratorFactory(name, fallback, defaultValue) {
3
+ function propDecorator(target, propName, originalDescriptor) {
4
+ const privatePropName = `$$__${propName}`;
5
+ if (Object.prototype.hasOwnProperty.call(target, privatePropName)) {
6
+ warn(`The prop "${privatePropName}" is already exist, it will be overrided by ${name} decorator.`);
7
+ }
8
+ Object.defineProperty(target, privatePropName, {
9
+ configurable: true,
10
+ writable: true
11
+ });
12
+ return {
13
+ get() {
14
+ return originalDescriptor && originalDescriptor.get
15
+ ? originalDescriptor.get.bind(this)()
16
+ : this[privatePropName];
17
+ },
18
+ set(value) {
19
+ if (originalDescriptor && originalDescriptor.set) {
20
+ originalDescriptor.set.bind(this)(fallback(value, defaultValue));
21
+ }
22
+ this[privatePropName] = fallback(value, defaultValue);
23
+ }
24
+ };
25
+ }
26
+ return propDecorator;
27
+ }
28
+ export function toBoolean(value, defaultValue = false) {
29
+ return value == null ? defaultValue : `${value}` !== 'false';
30
+ }
31
+ /**
32
+ * Input decorator that handle a prop to do get/set automatically with toBoolean
33
+ *
34
+ * ```ts
35
+ * {AT}Input() {AT}InputBoolean() visible: boolean = false;
36
+ * {AT}Input() {AT}InputBoolean(null) visible: boolean = false;
37
+ * ```
38
+ */
39
+ export function InputBoolean(defaultValue = false) {
40
+ return propDecoratorFactory('InputBoolean', toBoolean, defaultValue);
41
+ }
42
+ export function toNumber(value, fallbackValue = 0) {
43
+ return !isNaN(parseFloat(value)) && !isNaN(Number(value)) ? Number(value) : fallbackValue;
44
+ }
45
+ /**
46
+ * Input decorator that handle a prop to do get/set automatically with toNumber
47
+ *
48
+ * ```ts
49
+ * {AT}Input() {AT}InputNumber() visible: number = 1;
50
+ * {AT}Input() {AT}InputNumber(null) visible: number = 2;
51
+ * ```
52
+ */
53
+ export function InputNumber(defaultValue = 0) {
54
+ return propDecoratorFactory('InputNumber', toNumber, defaultValue);
55
+ }
56
56
  //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY29udmVydC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uLy4uL3BhY2thZ2VzL3V0aWwvZGVjb3JhdG9yL2NvbnZlcnQudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBRUEsT0FBTyxFQUFFLElBQUksRUFBRSxNQUFNLG1CQUFtQixDQUFDO0FBS3pDLFNBQVMsb0JBQW9CLENBQzNCLElBQVksRUFDWixRQUFzQyxFQUN0QyxZQUF1QjtJQUV2QixTQUFTLGFBQWEsQ0FDcEIsTUFBaUIsRUFDakIsUUFBZ0IsRUFDaEIsa0JBQXVEO1FBRXZELE1BQU0sZUFBZSxHQUFHLE9BQU8sUUFBUSxFQUFFLENBQUM7UUFFMUMsSUFBSSxNQUFNLENBQUMsU0FBUyxDQUFDLGNBQWMsQ0FBQyxJQUFJLENBQUMsTUFBTSxFQUFFLGVBQWUsQ0FBQyxFQUFFO1lBQ2pFLElBQUksQ0FBQyxhQUFhLGVBQWUsK0NBQStDLElBQUksYUFBYSxDQUFDLENBQUM7U0FDcEc7UUFFRCxNQUFNL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5leHBvcnQgZnVuY3Rpb24gdG9OdW1iZXIodmFsdWU6IHVua25vd24pOiBudW1iZXI7XG5leHBvcnQgZnVuY3Rpb24gdG9OdW1iZXI8RD4odmFsdWU6IHVua25vd24sIGZhbGxiYWNrOiBEKTogbnVtYmVyIHwgRDtcbmV4cG9ydCBmdW5jdGlvbiB0b051bWJlcih2YWx1ZTogdW5rbm93biwgZmFsbGJhY2tWYWx1ZTogbnVtYmVyID0gMCk6IG51bWJlciB7XG4gIHJldHVybiAhaXNOYU4ocGFyc2VGbG9hdCh2YWx1ZSBhcyBOelNhZmVBbnkpKSAmJiAhaXNOYU4oTnVtYmVyKHZhbHVlKSkgPyBOdW1iZXIodmFsdWUpIDogZmFsbGJhY2tWYWx1ZTtcbn1cblxuLyoqXG4gKiBJbnB1dCBkZWNvcmF0b3IgdGhhdCBoYW5kbGUgYSBwcm9wIHRvIGRvIGdldC9zZXQgYXV0b21hdGljYWxseSB3aXRoIHRvTnVtYmVyXG4gKlxuICogYGBgdHNcbiAqIHtBVH1JbnB1dCgpIHtBVH1JbnB1dE51bWJlcigpIHZpc2libGU6IG51bWJlciA9IDE7XG4gKiB7QVR9SW5wdXQoKSB7QVR9SW5wdXROdW1iZXIobnVsbCkgdmlzaWJsZTogbnVtYmVyID0gMjtcbiAqIGBgYFxuICovXG5leHBvcnQgZnVuY3Rpb24gSW5wdXROdW1iZXIoZGVmYXVsdFZhbHVlOiBudW1iZXIgfCBudWxsID0gMCk6IE56U2FmZUFueSB7XG4gIHJldHVybiBwcm9wRGVjb3JhdG9yRmFjdG9yeSgnSW5wdXROdW1iZXInLCB0b051bWJlciwgZGVmYXVsdFZhbHVlKTtcbn1cbiJdfQ==
@@ -1,3 +1,3 @@
1
- export * from './convert';
2
- export * from './zone-outside';
1
+ export * from './convert';
2
+ export * from './zone-outside';
3
3
  //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi8uLi9wYWNrYWdlcy91dGlsL2RlY29yYXRvci9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxjQUFjLFdBQVcsQ0FBQztBQUMxQixjQUFjLGdCQUFnQixDQUFDIiwic291cmNlc0NvbnRlbnQiOlsiZXhwb3J0ICogZnJvbSAnLi9jb252ZXJ0JztcbmV4cG9ydCAqIGZyb20gJy4vem9uZS1vdXRzaWRlJztcbiJdfQ==
@@ -1,5 +1,5 @@
1
- /**
2
- * Generated bundle index. Do not edit.
3
- */
4
- export * from './index';
1
+ /**
2
+ * Generated bundle index. Do not edit.
3
+ */
4
+ export * from './index';
5
5
  //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoieWVsb24tdXRpbC1kZWNvcmF0b3IuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi8uLi9wYWNrYWdlcy91dGlsL2RlY29yYXRvci95ZWxvbi11dGlsLWRlY29yYXRvci50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQTs7R0FFRztBQUVILGNBQWMsU0FBUyxDQUFDIiwic291cmNlc0NvbnRlbnQiOlsiLyoqXG4gKiBHZW5lcmF0ZWQgYnVuZGxlIGluZGV4LiBEbyBub3QgZWRpdC5cbiAqL1xuXG5leHBvcnQgKiBmcm9tICcuL2luZGV4JztcbiJdfQ==