@yelon/util 15.2.6 → 16.0.0
Sign up to get free protection for your applications and to get access to all the features.
- package/LICENSE +21 -21
- package/README.md +22 -22
- package/analysis/global-event.subject.d.ts +7 -7
- package/analysis/index.d.ts +1 -1
- package/array/array-type.service.d.ts +68 -68
- package/array/array.service.d.ts +78 -78
- package/array/index.d.ts +2 -2
- package/browser/cookie.service.d.ts +67 -67
- package/browser/copy.d.ts +6 -6
- package/browser/index.d.ts +5 -5
- package/browser/is-empty.d.ts +6 -6
- package/browser/scroll.service.d.ts +37 -37
- package/browser/style.d.ts +21 -21
- package/config/abc/date-picker.type.d.ts +52 -52
- package/config/abc/error-collect.type.d.ts +10 -10
- package/config/abc/exception.type.d.ts +9 -9
- package/config/abc/image.type.d.ts +15 -15
- package/config/abc/index.d.ts +17 -17
- package/config/abc/loading.type.d.ts +31 -31
- package/config/abc/lodop.type.d.ts +33 -33
- package/config/abc/media.type.d.ts +11 -11
- package/config/abc/onboarding.type.d.ts +4 -4
- package/config/abc/page-header.type.d.ts +39 -39
- package/config/abc/pdf.type.d.ts +35 -35
- package/config/abc/qr.type.d.ts +25 -25
- package/config/abc/se.type.d.ts +32 -32
- package/config/abc/sg.type.d.ts +10 -10
- package/config/abc/st.type.d.ts +465 -465
- package/config/abc/sv.type.d.ts +14 -14
- package/config/abc/xlsx.type.d.ts +12 -12
- package/config/abc/zip.type.d.ts +10 -10
- package/config/acl/acl.type.d.ts +32 -32
- package/config/auth/auth.type.d.ts +55 -55
- package/config/bis/bis.type.d.ts +7 -7
- package/config/cache/cache.type.d.ts +40 -40
- package/config/chart/chart.type.d.ts +33 -33
- package/config/config.service.d.ts +13 -13
- package/config/config.types.d.ts +48 -48
- package/config/index.d.ts +14 -14
- package/config/mock/mock.type.d.ts +18 -18
- package/config/sf/sf.type.d.ts +133 -133
- package/config/socket/socket.type.d.ts +4 -4
- package/config/theme/http.type.d.ts +14 -14
- package/config/theme/i18n.type.d.ts +14 -14
- package/config/theme/index.d.ts +3 -3
- package/config/theme/responsive.type.d.ts +12 -12
- package/config/util/array.type.d.ts +22 -22
- package/config/util/currency.type.d.ts +39 -39
- package/date-time/index.d.ts +2 -2
- package/date-time/picker.d.ts +68 -68
- package/date-time/time.d.ts +29 -29
- package/decorator/convert.d.ts +24 -24
- package/decorator/index.d.ts +2 -2
- package/decorator/zone-outside.d.ts +35 -35
- package/{esm2020 → esm2022}/analysis/analysis.mjs +4 -4
- package/esm2022/analysis/global-event.subject.mjs +18 -0
- package/{esm2020 → esm2022}/analysis/index.mjs +2 -2
- package/{esm2020 → esm2022}/array/array-type.service.mjs +1 -1
- package/{esm2020 → esm2022}/array/array.mjs +4 -4
- package/esm2022/array/array.service.mjs +278 -0
- package/{esm2020 → esm2022}/array/index.mjs +2 -2
- package/{esm2020 → esm2022}/browser/browser.mjs +4 -4
- package/esm2022/browser/cookie.service.mjs +104 -0
- package/{esm2020 → esm2022}/browser/copy.mjs +27 -27
- package/{esm2020 → esm2022}/browser/index.mjs +5 -5
- package/{esm2020 → esm2022}/browser/is-empty.mjs +18 -18
- package/esm2022/browser/scroll.service.mjs +89 -0
- package/{esm2020 → esm2022}/browser/style.mjs +37 -37
- package/{esm2020 → esm2022}/config/abc/date-picker.type.mjs +1 -1
- package/{esm2020 → esm2022}/config/abc/error-collect.type.mjs +1 -1
- package/{esm2020 → esm2022}/config/abc/exception.type.mjs +1 -1
- package/{esm2020 → esm2022}/config/abc/image.type.mjs +1 -1
- package/{esm2020 → esm2022}/config/abc/index.mjs +17 -17
- package/{esm2020 → esm2022}/config/abc/loading.type.mjs +1 -1
- package/{esm2020 → esm2022}/config/abc/lodop.type.mjs +1 -1
- package/{esm2020 → esm2022}/config/abc/media.type.mjs +1 -1
- package/{esm2020 → esm2022}/config/abc/onboarding.type.mjs +1 -1
- package/{esm2020 → esm2022}/config/abc/page-header.type.mjs +1 -1
- package/esm2022/config/abc/pdf.type.mjs +2 -0
- package/{esm2020 → esm2022}/config/abc/qr.type.mjs +1 -1
- package/{esm2020 → esm2022}/config/abc/se.type.mjs +1 -1
- package/{esm2020 → esm2022}/config/abc/sg.type.mjs +1 -1
- package/{esm2020 → esm2022}/config/abc/st.type.mjs +1 -1
- package/{esm2020 → esm2022}/config/abc/sv.type.mjs +2 -2
- package/{esm2020 → esm2022}/config/abc/xlsx.type.mjs +1 -1
- package/{esm2020 → esm2022}/config/abc/zip.type.mjs +1 -1
- package/{esm2020 → esm2022}/config/acl/acl.type.mjs +1 -1
- package/{esm2020 → esm2022}/config/auth/auth.type.mjs +1 -1
- package/{esm2020 → esm2022}/config/bis/bis.type.mjs +1 -1
- package/{esm2020 → esm2022}/config/cache/cache.type.mjs +1 -1
- package/{esm2020 → esm2022}/config/chart/chart.type.mjs +1 -1
- package/{esm2020 → esm2022}/config/config.mjs +4 -4
- package/esm2022/config/config.service.mjs +38 -0
- package/{esm2020 → esm2022}/config/config.types.mjs +8 -8
- package/{esm2020 → esm2022}/config/index.mjs +14 -14
- package/{esm2020 → esm2022}/config/mock/mock.type.mjs +1 -1
- package/{esm2020 → esm2022}/config/sf/sf.type.mjs +1 -1
- package/{esm2020 → esm2022}/config/socket/socket.type.mjs +1 -1
- package/{esm2020 → esm2022}/config/theme/http.type.mjs +1 -1
- package/{esm2020 → esm2022}/config/theme/i18n.type.mjs +1 -1
- package/{esm2020 → esm2022}/config/theme/index.mjs +3 -3
- package/{esm2020 → esm2022}/config/theme/responsive.type.mjs +1 -1
- package/{esm2020 → esm2022}/config/util/array.type.mjs +1 -1
- package/{esm2020 → esm2022}/config/util/currency.type.mjs +1 -1
- package/{esm2020 → esm2022}/date-time/date-time.mjs +4 -4
- package/{esm2020 → esm2022}/date-time/index.mjs +2 -2
- package/{esm2020 → esm2022}/date-time/picker.mjs +115 -115
- package/{esm2020 → esm2022}/date-time/time.mjs +88 -88
- package/{esm2020 → esm2022}/decorator/convert.mjs +57 -57
- package/{esm2020 → esm2022}/decorator/decorator.mjs +4 -4
- package/{esm2020 → esm2022}/decorator/index.mjs +2 -2
- package/{esm2020 → esm2022}/decorator/zone-outside.mjs +56 -56
- package/{esm2020 → esm2022}/form/form.mjs +4 -4
- package/{esm2020 → esm2022}/form/index.mjs +2 -2
- package/{esm2020 → esm2022}/form/match-control.mjs +29 -29
- package/{esm2020 → esm2022}/form/validators.mjs +80 -80
- package/esm2022/format/currency.service.mjs +239 -0
- package/{esm2020 → esm2022}/format/currency.types.mjs +7 -7
- package/{esm2020 → esm2022}/format/format.mjs +4 -4
- package/{esm2020 → esm2022}/format/index.mjs +4 -4
- package/{esm2020 → esm2022}/format/string.mjs +84 -84
- package/{esm2020 → esm2022}/format/validate.mjs +93 -93
- package/{esm2020 → esm2022}/index.mjs +12 -12
- package/{esm2020 → esm2022}/math/in-range.mjs +24 -24
- package/{esm2020 → esm2022}/math/index.mjs +2 -2
- package/{esm2020 → esm2022}/math/math.mjs +4 -4
- package/{esm2020 → esm2022}/math/round.mjs +52 -52
- package/{esm2020 → esm2022}/other/assert.mjs +66 -66
- package/{esm2020 → esm2022}/other/deep.mjs +77 -77
- package/{esm2020 → esm2022}/other/favicon.mjs +28 -28
- package/{esm2020 → esm2022}/other/index.mjs +7 -7
- package/esm2022/other/lazy.service.mjs +133 -0
- package/{esm2020 → esm2022}/other/logger.mjs +32 -32
- package/{esm2020 → esm2022}/other/other.mjs +4 -4
- package/esm2022/other/path-to-regexp.service.mjs +240 -0
- package/{esm2020 → esm2022}/other/resize.mjs +3 -3
- package/esm2022/pipes/currency/cny.pipe.mjs +24 -0
- package/{esm2020 → esm2022}/pipes/currency/index.mjs +4 -4
- package/esm2022/pipes/currency/mega.pipe.mjs +30 -0
- package/esm2022/pipes/currency/module.mjs +20 -0
- package/{esm2020 → esm2022}/pipes/currency/pipe-currency.mjs +4 -4
- package/esm2022/pipes/currency/price.pipe.mjs +28 -0
- package/esm2022/pipes/filter/filter.pipe.mjs +20 -0
- package/{esm2020 → esm2022}/pipes/filter/index.mjs +2 -2
- package/esm2022/pipes/filter/module.mjs +18 -0
- package/{esm2020 → esm2022}/pipes/filter/pipe-filter.mjs +4 -4
- package/{esm2020 → esm2022}/pipes/format/index.mjs +2 -2
- package/esm2022/pipes/format/mask.pipe.mjs +35 -0
- package/esm2022/pipes/format/module.mjs +18 -0
- package/{esm2020 → esm2022}/pipes/format/pipe-format.mjs +4 -4
- package/{esm2020 → esm2022}/pipes/index.mjs +3 -3
- package/{esm2020 → esm2022}/pipes/pipes.mjs +4 -4
- package/{esm2020 → esm2022}/token/index.mjs +2 -2
- package/{esm2020 → esm2022}/token/page-visibility.mjs +14 -14
- package/{esm2020 → esm2022}/token/token.mjs +4 -4
- package/{esm2020 → esm2022}/token/window.mjs +16 -16
- package/{esm2020 → esm2022}/yelon-util.mjs +4 -4
- package/{fesm2020 → fesm2022}/analysis.mjs +24 -24
- package/fesm2022/analysis.mjs.map +1 -0
- package/{fesm2020 → fesm2022}/array.mjs +284 -284
- package/{fesm2015 → fesm2022}/array.mjs.map +1 -1
- package/{fesm2020 → fesm2022}/browser.mjs +279 -279
- package/{fesm2020 → fesm2022}/browser.mjs.map +1 -1
- package/{fesm2020 → fesm2022}/config.mjs +54 -54
- package/{fesm2020 → fesm2022}/config.mjs.map +1 -1
- package/{fesm2020 → fesm2022}/date-time.mjs +211 -211
- package/{fesm2020 → fesm2022}/decorator.mjs +121 -121
- package/{fesm2020 → fesm2022}/form.mjs +118 -118
- package/{fesm2020 → fesm2022}/format.mjs +431 -431
- package/{fesm2020 → fesm2022}/format.mjs.map +1 -1
- package/{fesm2020 → fesm2022}/math.mjs +85 -85
- package/{fesm2020 → fesm2022}/other.mjs +586 -586
- package/{fesm2020 → fesm2022}/other.mjs.map +1 -1
- package/{fesm2020 → fesm2022}/pipe-currency.mjs +94 -94
- package/{fesm2020 → fesm2022}/pipe-currency.mjs.map +1 -1
- package/fesm2022/pipe-filter.mjs +40 -0
- package/{fesm2015 → fesm2022}/pipe-filter.mjs.map +1 -1
- package/{fesm2020 → fesm2022}/pipe-format.mjs +55 -55
- package/{fesm2015 → fesm2022}/pipe-format.mjs.map +1 -1
- package/{fesm2015 → fesm2022}/pipes.mjs +8 -8
- package/{fesm2020 → fesm2022}/token.mjs +37 -37
- package/{fesm2015 → fesm2022}/yelon-util.mjs +17 -17
- package/form/index.d.ts +2 -2
- package/form/match-control.d.ts +15 -15
- package/form/validators.d.ts +62 -62
- package/format/currency.service.d.ts +37 -37
- package/format/currency.types.d.ts +77 -77
- package/format/index.d.ts +4 -4
- package/format/string.d.ts +44 -44
- package/format/validate.d.ts +72 -72
- package/index.d.ts +12 -12
- package/math/in-range.d.ts +14 -14
- package/math/index.d.ts +2 -2
- package/math/round.d.ts +33 -33
- package/other/assert.d.ts +36 -36
- package/other/deep.d.ts +35 -35
- package/other/favicon.d.ts +2 -2
- package/other/index.d.ts +7 -7
- package/other/lazy.service.d.ts +48 -48
- package/other/logger.d.ts +5 -5
- package/other/path-to-regexp.service.d.ts +26 -26
- package/other/resize.d.ts +1 -1
- package/package.json +129 -165
- package/pipes/currency/cny.pipe.d.ts +15 -15
- package/pipes/currency/index.d.ts +4 -4
- package/pipes/currency/mega.pipe.d.ts +16 -16
- package/pipes/currency/module.d.ts +9 -9
- package/pipes/currency/price.pipe.d.ts +19 -19
- package/pipes/filter/filter.pipe.d.ts +13 -13
- package/pipes/filter/index.d.ts +2 -2
- package/pipes/filter/module.d.ts +7 -7
- package/pipes/format/index.d.ts +2 -2
- package/pipes/format/mask.pipe.d.ts +27 -27
- package/pipes/format/module.d.ts +7 -7
- package/pipes/index.d.ts +3 -3
- package/token/index.d.ts +2 -2
- package/token/page-visibility.d.ts +8 -8
- package/token/window.d.ts +7 -7
- package/esm2020/analysis/global-event.subject.mjs +0 -17
- package/esm2020/array/array.service.mjs +0 -277
- package/esm2020/browser/cookie.service.mjs +0 -103
- package/esm2020/browser/scroll.service.mjs +0 -88
- package/esm2020/config/abc/pdf.type.mjs +0 -2
- package/esm2020/config/config.service.mjs +0 -37
- package/esm2020/format/currency.service.mjs +0 -238
- package/esm2020/other/lazy.service.mjs +0 -132
- package/esm2020/other/path-to-regexp.service.mjs +0 -239
- package/esm2020/pipes/currency/cny.pipe.mjs +0 -23
- package/esm2020/pipes/currency/mega.pipe.mjs +0 -29
- package/esm2020/pipes/currency/module.mjs +0 -19
- package/esm2020/pipes/currency/price.pipe.mjs +0 -27
- package/esm2020/pipes/filter/filter.pipe.mjs +0 -19
- package/esm2020/pipes/filter/module.mjs +0 -17
- package/esm2020/pipes/format/mask.pipe.mjs +0 -34
- package/esm2020/pipes/format/module.mjs +0 -17
- package/fesm2015/analysis.mjs +0 -24
- package/fesm2015/analysis.mjs.map +0 -1
- package/fesm2015/array.mjs +0 -254
- package/fesm2015/browser.mjs +0 -283
- package/fesm2015/browser.mjs.map +0 -1
- package/fesm2015/config.mjs +0 -56
- package/fesm2015/config.mjs.map +0 -1
- package/fesm2015/date-time.mjs +0 -207
- package/fesm2015/date-time.mjs.map +0 -1
- package/fesm2015/decorator.mjs +0 -121
- package/fesm2015/decorator.mjs.map +0 -1
- package/fesm2015/form.mjs +0 -118
- package/fesm2015/format.mjs +0 -413
- package/fesm2015/format.mjs.map +0 -1
- package/fesm2015/math.mjs +0 -85
- package/fesm2015/other.mjs +0 -589
- package/fesm2015/other.mjs.map +0 -1
- package/fesm2015/pipe-currency.mjs +0 -96
- package/fesm2015/pipe-currency.mjs.map +0 -1
- package/fesm2015/pipe-filter.mjs +0 -40
- package/fesm2015/pipe-format.mjs +0 -55
- package/fesm2015/token.mjs +0 -37
- package/fesm2020/analysis.mjs.map +0 -1
- package/fesm2020/array.mjs.map +0 -1
- package/fesm2020/form.mjs.map +0 -1
- package/fesm2020/math.mjs.map +0 -1
- package/fesm2020/pipe-filter.mjs +0 -40
- package/fesm2020/pipe-filter.mjs.map +0 -1
- package/fesm2020/pipe-format.mjs.map +0 -1
- package/fesm2020/pipes.mjs +0 -8
- package/fesm2020/pipes.mjs.map +0 -1
- package/fesm2020/token.mjs.map +0 -1
- package/fesm2020/yelon-util.mjs +0 -17
- package/fesm2020/yelon-util.mjs.map +0 -1
- /package/{fesm2020 → fesm2022}/date-time.mjs.map +0 -0
- /package/{fesm2020 → fesm2022}/decorator.mjs.map +0 -0
- /package/{fesm2015 → fesm2022}/form.mjs.map +0 -0
- /package/{fesm2015 → fesm2022}/math.mjs.map +0 -0
- /package/{fesm2015 → fesm2022}/pipes.mjs.map +0 -0
- /package/{fesm2015 → fesm2022}/token.mjs.map +0 -0
- /package/{fesm2015 → fesm2022}/yelon-util.mjs.map +0 -0
@@ -1,89 +1,89 @@
|
|
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
|
-
* @param ignoreMaxTime 忽略追加结束日期的最大时间值
|
10
|
-
*/
|
11
|
-
export function getTimeDistance(type, time, options) {
|
12
|
-
time = time
|
13
|
-
? typeof time === 'string'
|
14
|
-
? parse(time, 'yyyy-MM-dd HH:mm:ss', new Date())
|
15
|
-
: new Date(time)
|
16
|
-
: new Date();
|
17
|
-
const opt = { weekStartsOn: 1 };
|
18
|
-
let res;
|
19
|
-
switch (type) {
|
20
|
-
case 'today':
|
21
|
-
res = [time, time];
|
22
|
-
break;
|
23
|
-
case '-today':
|
24
|
-
res = [addDays(time, -1), time];
|
25
|
-
break;
|
26
|
-
case 'yesterday':
|
27
|
-
res = [addDays(time, -1), addDays(time, -1)];
|
28
|
-
break;
|
29
|
-
case 'week':
|
30
|
-
res = [startOfWeek(time, opt), endOfWeek(time, opt)];
|
31
|
-
break;
|
32
|
-
case '-week':
|
33
|
-
res = [startOfWeek(subWeeks(time, 1), opt), endOfWeek(subWeeks(time, 1), opt)];
|
34
|
-
break;
|
35
|
-
case 'month':
|
36
|
-
res = [startOfMonth(time), endOfMonth(time)];
|
37
|
-
break;
|
38
|
-
case '-month':
|
39
|
-
res = [startOfMonth(subMonths(time, 1)), endOfMonth(subMonths(time, 1))];
|
40
|
-
break;
|
41
|
-
case 'year':
|
42
|
-
res = [startOfYear(time), endOfYear(time)];
|
43
|
-
break;
|
44
|
-
case '-year':
|
45
|
-
res = [startOfYear(subYears(time, 1)), endOfYear(subYears(time, 1))];
|
46
|
-
break;
|
47
|
-
default:
|
48
|
-
res = type > 0 ? [time, addDays(time, type)] : [addDays(time, type), time];
|
49
|
-
break;
|
50
|
-
}
|
51
|
-
return options?.ignoreMaxTime ? res : fixEndTimeOfRange(res);
|
52
|
-
}
|
53
|
-
/**
|
54
|
-
* fix time is the most, big value
|
55
|
-
*/
|
56
|
-
export function fixEndTimeOfRange(dates) {
|
57
|
-
return [startOfDay(dates[0]), endOfDay(dates[1])];
|
58
|
-
}
|
59
|
-
/**
|
60
|
-
* Return the date parsed from string using the given format string
|
61
|
-
* - If the argument is a number, it is treated as a timestamp.
|
62
|
-
*
|
63
|
-
* @param formatString If parsing fails try to parse the date by pressing `formatString`
|
64
|
-
* @param defaultValue If parsing fails returned default value, default: `new Date(NaN)`
|
65
|
-
*/
|
66
|
-
export function toDate(value, options) {
|
67
|
-
if (typeof options === 'string')
|
68
|
-
options = { formatString: options };
|
69
|
-
const { formatString, defaultValue } = {
|
70
|
-
formatString: 'yyyy-MM-dd HH:mm:ss',
|
71
|
-
defaultValue: new Date(NaN),
|
72
|
-
...options
|
73
|
-
};
|
74
|
-
if (value == null) {
|
75
|
-
return defaultValue;
|
76
|
-
}
|
77
|
-
if (value instanceof Date) {
|
78
|
-
return value;
|
79
|
-
}
|
80
|
-
if (typeof value === 'number' || (typeof value === 'string' && /[0-9]{10,13}/.test(value))) {
|
81
|
-
return new Date(+value);
|
82
|
-
}
|
83
|
-
let tryDate = parseISO(value);
|
84
|
-
if (isNaN(tryDate)) {
|
85
|
-
tryDate = parse(value, formatString, new Date());
|
86
|
-
}
|
87
|
-
return isNaN(tryDate) ? defaultValue : tryDate;
|
88
|
-
}
|
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
|
+
* @param ignoreMaxTime 忽略追加结束日期的最大时间值
|
10
|
+
*/
|
11
|
+
export function getTimeDistance(type, time, options) {
|
12
|
+
time = time
|
13
|
+
? typeof time === 'string'
|
14
|
+
? parse(time, 'yyyy-MM-dd HH:mm:ss', new Date())
|
15
|
+
: new Date(time)
|
16
|
+
: new Date();
|
17
|
+
const opt = { weekStartsOn: 1 };
|
18
|
+
let res;
|
19
|
+
switch (type) {
|
20
|
+
case 'today':
|
21
|
+
res = [time, time];
|
22
|
+
break;
|
23
|
+
case '-today':
|
24
|
+
res = [addDays(time, -1), time];
|
25
|
+
break;
|
26
|
+
case 'yesterday':
|
27
|
+
res = [addDays(time, -1), addDays(time, -1)];
|
28
|
+
break;
|
29
|
+
case 'week':
|
30
|
+
res = [startOfWeek(time, opt), endOfWeek(time, opt)];
|
31
|
+
break;
|
32
|
+
case '-week':
|
33
|
+
res = [startOfWeek(subWeeks(time, 1), opt), endOfWeek(subWeeks(time, 1), opt)];
|
34
|
+
break;
|
35
|
+
case 'month':
|
36
|
+
res = [startOfMonth(time), endOfMonth(time)];
|
37
|
+
break;
|
38
|
+
case '-month':
|
39
|
+
res = [startOfMonth(subMonths(time, 1)), endOfMonth(subMonths(time, 1))];
|
40
|
+
break;
|
41
|
+
case 'year':
|
42
|
+
res = [startOfYear(time), endOfYear(time)];
|
43
|
+
break;
|
44
|
+
case '-year':
|
45
|
+
res = [startOfYear(subYears(time, 1)), endOfYear(subYears(time, 1))];
|
46
|
+
break;
|
47
|
+
default:
|
48
|
+
res = type > 0 ? [time, addDays(time, type)] : [addDays(time, type), time];
|
49
|
+
break;
|
50
|
+
}
|
51
|
+
return options?.ignoreMaxTime ? res : fixEndTimeOfRange(res);
|
52
|
+
}
|
53
|
+
/**
|
54
|
+
* fix time is the most, big value
|
55
|
+
*/
|
56
|
+
export function fixEndTimeOfRange(dates) {
|
57
|
+
return [startOfDay(dates[0]), endOfDay(dates[1])];
|
58
|
+
}
|
59
|
+
/**
|
60
|
+
* Return the date parsed from string using the given format string
|
61
|
+
* - If the argument is a number, it is treated as a timestamp.
|
62
|
+
*
|
63
|
+
* @param formatString If parsing fails try to parse the date by pressing `formatString`
|
64
|
+
* @param defaultValue If parsing fails returned default value, default: `new Date(NaN)`
|
65
|
+
*/
|
66
|
+
export function toDate(value, options) {
|
67
|
+
if (typeof options === 'string')
|
68
|
+
options = { formatString: options };
|
69
|
+
const { formatString, defaultValue } = {
|
70
|
+
formatString: 'yyyy-MM-dd HH:mm:ss',
|
71
|
+
defaultValue: new Date(NaN),
|
72
|
+
...options
|
73
|
+
};
|
74
|
+
if (value == null) {
|
75
|
+
return defaultValue;
|
76
|
+
}
|
77
|
+
if (value instanceof Date) {
|
78
|
+
return value;
|
79
|
+
}
|
80
|
+
if (typeof value === 'number' || (typeof value === 'string' && /[0-9]{10,13}/.test(value))) {
|
81
|
+
return new Date(+value);
|
82
|
+
}
|
83
|
+
let tryDate = parseISO(value);
|
84
|
+
if (isNaN(tryDate)) {
|
85
|
+
tryDate = parse(value, formatString, new Date());
|
86
|
+
}
|
87
|
+
return isNaN(tryDate) ? defaultValue : tryDate;
|
88
|
+
}
|
89
89
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGltZS5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uLy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XX0=
|
@@ -1,58 +1,58 @@
|
|
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 (typeof ngDevMode === 'undefined' || ngDevMode) {
|
6
|
-
if (Object.prototype.hasOwnProperty.call(target, privatePropName)) {
|
7
|
-
warn(`The prop "${privatePropName}" is already exist, it will be overrided by ${name} decorator.`);
|
8
|
-
}
|
9
|
-
}
|
10
|
-
Object.defineProperty(target, privatePropName, {
|
11
|
-
configurable: true,
|
12
|
-
writable: true
|
13
|
-
});
|
14
|
-
return {
|
15
|
-
get() {
|
16
|
-
return originalDescriptor && originalDescriptor.get
|
17
|
-
? originalDescriptor.get.bind(this)()
|
18
|
-
: this[privatePropName];
|
19
|
-
},
|
20
|
-
set(value) {
|
21
|
-
if (originalDescriptor && originalDescriptor.set) {
|
22
|
-
originalDescriptor.set.bind(this)(fallback(value, defaultValue));
|
23
|
-
}
|
24
|
-
this[privatePropName] = fallback(value, defaultValue);
|
25
|
-
}
|
26
|
-
};
|
27
|
-
}
|
28
|
-
return propDecorator;
|
29
|
-
}
|
30
|
-
export function toBoolean(value, defaultValue = false) {
|
31
|
-
return value == null ? defaultValue : `${value}` !== 'false';
|
32
|
-
}
|
33
|
-
/**
|
34
|
-
* Input decorator that handle a prop to do get/set automatically with toBoolean
|
35
|
-
*
|
36
|
-
* ```ts
|
37
|
-
* {AT}Input() {AT}InputBoolean() visible: boolean = false;
|
38
|
-
* {AT}Input() {AT}InputBoolean(null) visible: boolean = false;
|
39
|
-
* ```
|
40
|
-
*/
|
41
|
-
export function InputBoolean(defaultValue = false) {
|
42
|
-
return propDecoratorFactory('InputBoolean', toBoolean, defaultValue);
|
43
|
-
}
|
44
|
-
export function toNumber(value, fallbackValue = 0) {
|
45
|
-
return !isNaN(parseFloat(value)) && !isNaN(Number(value)) ? Number(value) : fallbackValue;
|
46
|
-
}
|
47
|
-
/**
|
48
|
-
* Input decorator that handle a prop to do get/set automatically with toNumber
|
49
|
-
*
|
50
|
-
* ```ts
|
51
|
-
* {AT}Input() {AT}InputNumber() visible: number = 1;
|
52
|
-
* {AT}Input() {AT}InputNumber(null) visible: number = 2;
|
53
|
-
* ```
|
54
|
-
*/
|
55
|
-
export function InputNumber(defaultValue = 0) {
|
56
|
-
return propDecoratorFactory('InputNumber', toNumber, defaultValue);
|
57
|
-
}
|
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 (typeof ngDevMode === 'undefined' || ngDevMode) {
|
6
|
+
if (Object.prototype.hasOwnProperty.call(target, privatePropName)) {
|
7
|
+
warn(`The prop "${privatePropName}" is already exist, it will be overrided by ${name} decorator.`);
|
8
|
+
}
|
9
|
+
}
|
10
|
+
Object.defineProperty(target, privatePropName, {
|
11
|
+
configurable: true,
|
12
|
+
writable: true
|
13
|
+
});
|
14
|
+
return {
|
15
|
+
get() {
|
16
|
+
return originalDescriptor && originalDescriptor.get
|
17
|
+
? originalDescriptor.get.bind(this)()
|
18
|
+
: this[privatePropName];
|
19
|
+
},
|
20
|
+
set(value) {
|
21
|
+
if (originalDescriptor && originalDescriptor.set) {
|
22
|
+
originalDescriptor.set.bind(this)(fallback(value, defaultValue));
|
23
|
+
}
|
24
|
+
this[privatePropName] = fallback(value, defaultValue);
|
25
|
+
}
|
26
|
+
};
|
27
|
+
}
|
28
|
+
return propDecorator;
|
29
|
+
}
|
30
|
+
export function toBoolean(value, defaultValue = false) {
|
31
|
+
return value == null ? defaultValue : `${value}` !== 'false';
|
32
|
+
}
|
33
|
+
/**
|
34
|
+
* Input decorator that handle a prop to do get/set automatically with toBoolean
|
35
|
+
*
|
36
|
+
* ```ts
|
37
|
+
* {AT}Input() {AT}InputBoolean() visible: boolean = false;
|
38
|
+
* {AT}Input() {AT}InputBoolean(null) visible: boolean = false;
|
39
|
+
* ```
|
40
|
+
*/
|
41
|
+
export function InputBoolean(defaultValue = false) {
|
42
|
+
return propDecoratorFactory('InputBoolean', toBoolean, defaultValue);
|
43
|
+
}
|
44
|
+
export function toNumber(value, fallbackValue = 0) {
|
45
|
+
return !isNaN(parseFloat(value)) && !isNaN(Number(value)) ? Number(value) : fallbackValue;
|
46
|
+
}
|
47
|
+
/**
|
48
|
+
* Input decorator that handle a prop to do get/set automatically with toNumber
|
49
|
+
*
|
50
|
+
* ```ts
|
51
|
+
* {AT}Input() {AT}InputNumber() visible: number = 1;
|
52
|
+
* {AT}Input() {AT}InputNumber(null) visible: number = 2;
|
53
|
+
* ```
|
54
|
+
*/
|
55
|
+
export function InputNumber(defaultValue = 0) {
|
56
|
+
return propDecoratorFactory('InputNumber', toNumber, defaultValue);
|
57
|
+
}
|
58
58
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY29udmVydC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uLy4uL3BhY2thZ2VzL3V0aWwvZGVjb3JhdG9yL2NvbnZlcnQudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxFQUFFLElBQUksRUFBRSxNQUFNLG1CQUFtQixDQUFDO0FBTXpDLFNBQVMsb0JBQW9CLENBQzNCLElBQVksRUFDWixRQUFzQyxFQUN0QyxZQUF1QjtJQUV2QixTQUFTLGFBQWEsQ0FDcEIsTUFBaUIsRUFDakIsUUFBZ0IsRUFDaEIsa0JBQXVEO1FBRXZELE1BQU0sZUFBZSxHQUFHLE9BQU8sUUFBUSxFQUFFLENBQUM7UUFFMUMsSUFBSSxPQUFPLFNBQVMsS0FBSyxXQUFXLElBQUksU0FBUyxFQUFFO1lBQ2pELElBQUksTUFBTSxDQUFDLFNBQVMsQ0FBQyxjQUFjLENB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ZhY3RvcnkoJ0lucHV0TnVtYmVyJywgdG9OdW1iZXIsIGRlZmF1bHRWYWx1ZSk7XG59XG4iXX0=
|
@@ -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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZGVjb3JhdG9yLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vLi4vLi4vcGFja2FnZXMvdXRpbC9kZWNvcmF0b3IvZGVjb3JhdG9yLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBOztHQUVHO0FBRUgsY0FBYyxTQUFTLENBQUMiLCJzb3VyY2VzQ29udGVudCI6WyIvKipcbiAqIEdlbmVyYXRlZCBidW5kbGUgaW5kZXguIERvIG5vdCBlZGl0LlxuICovXG5cbmV4cG9ydCAqIGZyb20gJy4vaW5kZXgnO1xuIl19
|
@@ -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,57 +1,57 @@
|
|
1
|
-
import { warn } from '@yelon/util/other';
|
2
|
-
function makeFn(type, options) {
|
3
|
-
return (_, __, descriptor) => {
|
4
|
-
const source = descriptor.value;
|
5
|
-
descriptor.value = function (...data) {
|
6
|
-
const that = this;
|
7
|
-
const ngZone = that[options?.ngZoneName || 'ngZone'];
|
8
|
-
if (!ngZone) {
|
9
|
-
if (typeof ngDevMode === 'undefined' || ngDevMode) {
|
10
|
-
warn(`ZoneOutside: Decorator should have 'ngZone' property with 'NgZone' class.`);
|
11
|
-
}
|
12
|
-
return source.call(this, ...data);
|
13
|
-
}
|
14
|
-
let res;
|
15
|
-
ngZone[type](() => {
|
16
|
-
res = source.call(this, ...data);
|
17
|
-
});
|
18
|
-
return res;
|
19
|
-
};
|
20
|
-
return descriptor;
|
21
|
-
};
|
22
|
-
}
|
23
|
-
/**
|
24
|
-
* The decoration method runs in `runOutsideAngular`
|
25
|
-
*
|
26
|
-
* 装饰方法运行在 `runOutsideAngular` 内
|
27
|
-
*
|
28
|
-
* ```ts
|
29
|
-
* class MockClass {
|
30
|
-
* constructor(public ngZone: NgZone) {}
|
31
|
-
*
|
32
|
-
* {AT}ZoneOutside()
|
33
|
-
* runOutsideAngular(): void {}
|
34
|
-
* }
|
35
|
-
* ```
|
36
|
-
*/
|
37
|
-
export function ZoneOutside(options) {
|
38
|
-
return makeFn('runOutsideAngular', options);
|
39
|
-
}
|
40
|
-
/**
|
41
|
-
* The decoration method runs in `run`
|
42
|
-
*
|
43
|
-
* 装饰方法运行在 `run` 内
|
44
|
-
*
|
45
|
-
* ```ts
|
46
|
-
* class MockClass {
|
47
|
-
* constructor(public ngZone: NgZone) {}
|
48
|
-
*
|
49
|
-
* {AT}ZoneRun()
|
50
|
-
* run(): void {}
|
51
|
-
* }
|
52
|
-
* ```
|
53
|
-
*/
|
54
|
-
export function ZoneRun(options) {
|
55
|
-
return makeFn('run', options);
|
56
|
-
}
|
1
|
+
import { warn } from '@yelon/util/other';
|
2
|
+
function makeFn(type, options) {
|
3
|
+
return (_, __, descriptor) => {
|
4
|
+
const source = descriptor.value;
|
5
|
+
descriptor.value = function (...data) {
|
6
|
+
const that = this;
|
7
|
+
const ngZone = that[options?.ngZoneName || 'ngZone'];
|
8
|
+
if (!ngZone) {
|
9
|
+
if (typeof ngDevMode === 'undefined' || ngDevMode) {
|
10
|
+
warn(`ZoneOutside: Decorator should have 'ngZone' property with 'NgZone' class.`);
|
11
|
+
}
|
12
|
+
return source.call(this, ...data);
|
13
|
+
}
|
14
|
+
let res;
|
15
|
+
ngZone[type](() => {
|
16
|
+
res = source.call(this, ...data);
|
17
|
+
});
|
18
|
+
return res;
|
19
|
+
};
|
20
|
+
return descriptor;
|
21
|
+
};
|
22
|
+
}
|
23
|
+
/**
|
24
|
+
* The decoration method runs in `runOutsideAngular`
|
25
|
+
*
|
26
|
+
* 装饰方法运行在 `runOutsideAngular` 内
|
27
|
+
*
|
28
|
+
* ```ts
|
29
|
+
* class MockClass {
|
30
|
+
* constructor(public ngZone: NgZone) {}
|
31
|
+
*
|
32
|
+
* {AT}ZoneOutside()
|
33
|
+
* runOutsideAngular(): void {}
|
34
|
+
* }
|
35
|
+
* ```
|
36
|
+
*/
|
37
|
+
export function ZoneOutside(options) {
|
38
|
+
return makeFn('runOutsideAngular', options);
|
39
|
+
}
|
40
|
+
/**
|
41
|
+
* The decoration method runs in `run`
|
42
|
+
*
|
43
|
+
* 装饰方法运行在 `run` 内
|
44
|
+
*
|
45
|
+
* ```ts
|
46
|
+
* class MockClass {
|
47
|
+
* constructor(public ngZone: NgZone) {}
|
48
|
+
*
|
49
|
+
* {AT}ZoneRun()
|
50
|
+
* run(): void {}
|
51
|
+
* }
|
52
|
+
* ```
|
53
|
+
*/
|
54
|
+
export function ZoneRun(options) {
|
55
|
+
return makeFn('run', options);
|
56
|
+
}
|
57
57
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiem9uZ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Wm9uZU9wdGlvbnMpOiBEZWNvcmF0b3JUeXBlIHtcbiAgcmV0dXJuIG1ha2VGbigncnVuT3V0c2lkZUFuZ3VsYXInLCBvcHRpb25zKTtcbn1cblxuLyoqXG4gKiBUaGUgZGVjb3JhdGlvbiBtZXRob2QgcnVucyBpbiBgcnVuYFxuICpcbiAqIOijhemlsOaWueazlei/kOihjOWcqCBgcnVuYCDlhoVcbiAqXG4gKiBgYGB0c1xuICogY2xhc3MgTW9ja0NsYXNzIHtcbiAqICBjb25zdHJ1Y3RvcihwdWJsaWMgbmdab25lOiBOZ1pvbmUpIHt9XG4gKlxuICogIHtBVH1ab25lUnVuKClcbiAqICBydW4oKTogdm9pZCB7fVxuICogfVxuICogYGBgXG4gKi9cbmV4cG9ydCBmdW5jdGlvbiBab25lUnVuKG9wdGlvbnM/OiBab25lT3B0aW9ucyk6IERlY29yYXRvclR5cGUge1xuICByZXR1cm4gbWFrZUZuKCdydW4nLCBvcHRpb25zKTtcbn1cbiJdfQ==
|
@@ -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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZm9ybS5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uLy4uL3BhY2thZ2VzL3V0aWwvZm9ybS9mb3JtLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBOztHQUVHO0FBRUgsY0FBYyxTQUFTLENBQUMiLCJzb3VyY2VzQ29udGVudCI6WyIvKipcbiAqIEdlbmVyYXRlZCBidW5kbGUgaW5kZXguIERvIG5vdCBlZGl0LlxuICovXG5cbmV4cG9ydCAqIGZyb20gJy4vaW5kZXgnO1xuIl19
|
@@ -1,3 +1,3 @@
|
|
1
|
-
export * from './validators';
|
2
|
-
export * from './match-control';
|
1
|
+
export * from './validators';
|
2
|
+
export * from './match-control';
|
3
3
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi8uLi9wYWNrYWdlcy91dGlsL2Zvcm0vaW5kZXgudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsY0FBYyxjQUFjLENBQUM7QUFDN0IsY0FBYyxpQkFBaUIsQ0FBQyIsInNvdXJjZXNDb250ZW50IjpbImV4cG9ydCAqIGZyb20gJy4vdmFsaWRhdG9ycyc7XG5leHBvcnQgKiBmcm9tICcuL21hdGNoLWNvbnRyb2wnO1xuIl19
|
@@ -1,30 +1,30 @@
|
|
1
|
-
/**
|
2
|
-
* Match two control values
|
3
|
-
*
|
4
|
-
* 匹配两个控件值
|
5
|
-
* ```ts
|
6
|
-
* this.form = new FormGroup({
|
7
|
-
* pwd: new FormControl(''),
|
8
|
-
* repwd: new FormControl(''),
|
9
|
-
* }, {
|
10
|
-
* validators: MatchControl('pwd', 'repwd'),
|
11
|
-
* });
|
12
|
-
* ```
|
13
|
-
*/
|
14
|
-
export function MatchControl(controlName, matchingControlName) {
|
15
|
-
return (formGroup) => {
|
16
|
-
const control = formGroup.get(controlName);
|
17
|
-
const matchingControl = formGroup.get(matchingControlName);
|
18
|
-
if (matchingControl.errors && !matchingControl.errors.matchControl) {
|
19
|
-
return null;
|
20
|
-
}
|
21
|
-
if (control.value !== matchingControl.value) {
|
22
|
-
matchingControl.setErrors({ matchControl: true });
|
23
|
-
}
|
24
|
-
else {
|
25
|
-
matchingControl.setErrors(null);
|
26
|
-
}
|
27
|
-
return null;
|
28
|
-
};
|
29
|
-
}
|
1
|
+
/**
|
2
|
+
* Match two control values
|
3
|
+
*
|
4
|
+
* 匹配两个控件值
|
5
|
+
* ```ts
|
6
|
+
* this.form = new FormGroup({
|
7
|
+
* pwd: new FormControl(''),
|
8
|
+
* repwd: new FormControl(''),
|
9
|
+
* }, {
|
10
|
+
* validators: MatchControl('pwd', 'repwd'),
|
11
|
+
* });
|
12
|
+
* ```
|
13
|
+
*/
|
14
|
+
export function MatchControl(controlName, matchingControlName) {
|
15
|
+
return (formGroup) => {
|
16
|
+
const control = formGroup.get(controlName);
|
17
|
+
const matchingControl = formGroup.get(matchingControlName);
|
18
|
+
if (matchingControl.errors && !matchingControl.errors.matchControl) {
|
19
|
+
return null;
|
20
|
+
}
|
21
|
+
if (control.value !== matchingControl.value) {
|
22
|
+
matchingControl.setErrors({ matchControl: true });
|
23
|
+
}
|
24
|
+
else {
|
25
|
+
matchingControl.setErrors(null);
|
26
|
+
}
|
27
|
+
return null;
|
28
|
+
};
|
29
|
+
}
|
30
30
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibWF0Y2gtY29udHJvbC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uLy4uL3BhY2thZ2VzL3V0aWwvZm9ybS9tYXRjaC1jb250cm9sLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUVBOzs7Ozs7Ozs7Ozs7R0FZRztBQUNILE1BQU0sVUFBVSxZQUFZLENBQUMsV0FBbUIsRUFBRSxtQkFBMkI7SUFDM0UsT0FBTyxDQUFDLFNBQTBCLEVBQUUsRUFBRTtRQUNwQyxNQUFNLE9BQU8sR0FBRyxTQUFTLENBQUMsR0FBRyxDQUFDLFdBQVcsQ0FBRSxDQUFDO1FBQzVDLE1BQU0sZUFBZSxHQUFHLFNBQVMsQ0FBQyxHQUFHLENBQUMsbUJBQW1CLENBQUUsQ0FBQztRQUM1RCxJQUFJLGVBQWUsQ0FBQyxNQUFNLElBQUksQ0FBQyxlQUFlLENBQUMsTUFBTSxDQUFDLFlBQVksRUFBRT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