@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.
- package/LICENSE +21 -21
- package/README.md +2 -2
- package/array/array-type.service.d.ts +68 -68
- package/array/array.service.d.ts +75 -75
- package/array/index.d.ts +2 -2
- package/array/yelon-util-array.d.ts +4 -4
- package/array/yelon-util-array.metadata.json +1 -1
- package/browser/browser.d.ts +4 -4
- package/browser/cookie.service.d.ts +64 -64
- 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 +34 -34
- package/browser/style.d.ts +21 -21
- package/bundles/browser.umd.js +275 -275
- package/bundles/yelon-util-array.umd.js +606 -606
- package/bundles/yelon-util-array.umd.js.map +1 -1
- package/bundles/yelon-util-config.umd.js +366 -366
- package/bundles/yelon-util-date-time.umd.js +216 -216
- package/bundles/yelon-util-decorator.umd.js +437 -437
- package/bundles/yelon-util-form.umd.js +116 -116
- package/bundles/yelon-util-format.umd.js +726 -726
- package/bundles/yelon-util-math.umd.js +83 -83
- package/bundles/yelon-util-other.umd.js +652 -656
- package/bundles/yelon-util-other.umd.js.map +1 -1
- package/bundles/yelon-util-pipes-currency.umd.js +83 -83
- package/bundles/yelon-util-pipes-filter.umd.js +353 -353
- package/bundles/yelon-util-pipes-format.umd.js +47 -47
- package/bundles/yelon-util-pipes.umd.js +7 -7
- package/bundles/yelon-util-token.umd.js +30 -30
- package/bundles/yelon-util.umd.js +7 -7
- package/config/abc/date-picker.type.d.ts +52 -52
- package/config/abc/error-collect.type.d.ts +10 -10
- package/config/abc/image.type.d.ts +15 -15
- package/config/abc/index.d.ts +16 -16
- 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 +427 -431
- 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 +10 -10
- package/config/config.types.d.ts +49 -49
- package/config/index.d.ts +14 -14
- package/config/mock/mock.type.d.ts +18 -18
- package/config/sf/sf.type.d.ts +127 -127
- package/config/stomp/stomp.type.d.ts +2 -2
- package/config/theme/http.type.d.ts +14 -14
- package/config/theme/i18n.type.d.ts +8 -8
- 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/config/yelon-util-config.d.ts +4 -4
- package/date-time/index.d.ts +2 -2
- package/date-time/picker.d.ts +68 -68
- package/date-time/time.d.ts +26 -26
- package/date-time/yelon-util-date-time.d.ts +4 -4
- package/decorator/convert.d.ts +24 -24
- package/decorator/index.d.ts +2 -2
- package/decorator/yelon-util-decorator.d.ts +4 -4
- package/decorator/zone-outside.d.ts +35 -35
- package/esm2015/array/array-type.service.js +1 -1
- package/esm2015/array/array.service.js +250 -250
- package/esm2015/array/index.js +2 -2
- package/esm2015/array/yelon-util-array.js +4 -4
- package/esm2015/browser/browser.js +4 -4
- package/esm2015/browser/cookie.service.js +103 -103
- package/esm2015/browser/copy.js +26 -26
- package/esm2015/browser/index.js +5 -5
- package/esm2015/browser/is-empty.js +18 -18
- package/esm2015/browser/scroll.service.js +88 -88
- package/esm2015/browser/style.js +37 -37
- package/esm2015/config/abc/date-picker.type.js +1 -1
- package/esm2015/config/abc/error-collect.type.js +1 -1
- package/esm2015/config/abc/image.type.js +1 -1
- package/esm2015/config/abc/index.js +16 -16
- package/esm2015/config/abc/loading.type.js +1 -1
- package/esm2015/config/abc/lodop.type.js +1 -1
- package/esm2015/config/abc/media.type.js +1 -1
- package/esm2015/config/abc/onboarding.type.js +1 -1
- package/esm2015/config/abc/page-header.type.js +1 -1
- package/esm2015/config/abc/pdf.type.js +1 -1
- package/esm2015/config/abc/qr.type.js +1 -1
- package/esm2015/config/abc/se.type.js +1 -1
- package/esm2015/config/abc/sg.type.js +1 -1
- package/esm2015/config/abc/st.type.js +2 -2
- package/esm2015/config/abc/sv.type.js +2 -2
- package/esm2015/config/abc/xlsx.type.js +1 -1
- package/esm2015/config/abc/zip.type.js +1 -1
- package/esm2015/config/acl/acl.type.js +1 -1
- package/esm2015/config/auth/auth.type.js +1 -1
- package/esm2015/config/bis/bis.type.js +1 -1
- package/esm2015/config/cache/cache.type.js +1 -1
- package/esm2015/config/chart/chart.type.js +1 -1
- package/esm2015/config/config.service.js +33 -33
- package/esm2015/config/config.types.js +8 -8
- package/esm2015/config/index.js +14 -14
- package/esm2015/config/mock/mock.type.js +1 -1
- package/esm2015/config/sf/sf.type.js +1 -1
- package/esm2015/config/stomp/stomp.type.js +1 -1
- package/esm2015/config/theme/http.type.js +1 -1
- package/esm2015/config/theme/i18n.type.js +1 -1
- package/esm2015/config/theme/index.js +3 -3
- package/esm2015/config/theme/responsive.type.js +1 -1
- package/esm2015/config/util/array.type.js +1 -1
- package/esm2015/config/util/currency.type.js +1 -1
- package/esm2015/config/yelon-util-config.js +4 -4
- package/esm2015/date-time/index.js +2 -2
- package/esm2015/date-time/picker.js +115 -115
- package/esm2015/date-time/time.js +83 -83
- package/esm2015/date-time/yelon-util-date-time.js +4 -4
- package/esm2015/decorator/convert.js +55 -55
- package/esm2015/decorator/index.js +2 -2
- package/esm2015/decorator/yelon-util-decorator.js +4 -4
- package/esm2015/decorator/zone-outside.js +54 -54
- package/esm2015/form/index.js +2 -2
- package/esm2015/form/match-control.js +29 -29
- package/esm2015/form/validators.js +80 -80
- package/esm2015/form/yelon-util-form.js +4 -4
- package/esm2015/format/currency.service.js +224 -224
- package/esm2015/format/currency.types.js +7 -7
- package/esm2015/format/index.js +4 -4
- package/esm2015/format/string.js +75 -75
- package/esm2015/format/validate.js +93 -93
- package/esm2015/format/yelon-util-format.js +4 -4
- package/esm2015/index.js +11 -11
- package/esm2015/math/in-range.js +24 -24
- package/esm2015/math/index.js +2 -2
- package/esm2015/math/round.js +52 -52
- package/esm2015/math/yelon-util-math.js +4 -4
- package/esm2015/other/assert.js +66 -66
- package/esm2015/other/deep.js +76 -76
- package/esm2015/other/index.js +4 -4
- package/esm2015/other/lazy.service.js +118 -118
- package/esm2015/other/logger.js +33 -36
- package/esm2015/other/yelon-util-other.js +4 -4
- package/esm2015/pipes/currency/cny.pipe.js +21 -21
- package/esm2015/pipes/currency/index.js +3 -3
- package/esm2015/pipes/currency/mega.pipe.js +25 -25
- package/esm2015/pipes/currency/module.js +13 -13
- package/esm2015/pipes/currency/price.pipe.js +25 -25
- package/esm2015/pipes/currency/yelon-util-pipes-currency.js +5 -5
- package/esm2015/pipes/filter/filter.pipe.js +14 -14
- package/esm2015/pipes/filter/index.js +2 -2
- package/esm2015/pipes/filter/module.js +11 -11
- package/esm2015/pipes/filter/yelon-util-pipes-filter.js +4 -4
- package/esm2015/pipes/format/index.js +2 -2
- package/esm2015/pipes/format/mask.pipe.js +29 -29
- package/esm2015/pipes/format/module.js +11 -11
- package/esm2015/pipes/format/yelon-util-pipes-format.js +4 -4
- package/esm2015/pipes/index.js +3 -3
- package/esm2015/pipes/yelon-util-pipes.js +4 -4
- package/esm2015/token/index.js +2 -2
- package/esm2015/token/page-visibility.js +15 -15
- package/esm2015/token/window.js +16 -16
- package/esm2015/token/yelon-util-token.js +4 -4
- package/esm2015/yelon-util.js +4 -4
- package/fesm2015/browser.js +257 -257
- package/fesm2015/yelon-util-array.js +246 -246
- package/fesm2015/yelon-util-array.js.map +1 -1
- package/fesm2015/yelon-util-config.js +36 -36
- package/fesm2015/yelon-util-date-time.js +196 -196
- package/fesm2015/yelon-util-decorator.js +107 -107
- package/fesm2015/yelon-util-form.js +108 -108
- package/fesm2015/yelon-util-format.js +390 -390
- package/fesm2015/yelon-util-math.js +75 -75
- package/fesm2015/yelon-util-other.js +281 -284
- package/fesm2015/yelon-util-other.js.map +1 -1
- package/fesm2015/yelon-util-pipes-currency.js +72 -72
- package/fesm2015/yelon-util-pipes-filter.js +22 -22
- package/fesm2015/yelon-util-pipes-format.js +36 -36
- package/fesm2015/yelon-util-pipes.js +2 -2
- package/fesm2015/yelon-util-token.js +25 -25
- package/fesm2015/yelon-util.js +2 -2
- package/form/index.d.ts +2 -2
- package/form/match-control.d.ts +15 -15
- package/form/validators.d.ts +62 -62
- package/form/yelon-util-form.d.ts +4 -4
- package/format/currency.service.d.ts +34 -34
- 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/format/yelon-util-format.d.ts +4 -4
- package/index.d.ts +11 -11
- package/math/in-range.d.ts +14 -14
- package/math/index.d.ts +2 -2
- package/math/round.d.ts +33 -33
- package/math/yelon-util-math.d.ts +4 -4
- package/other/assert.d.ts +36 -36
- package/other/deep.d.ts +33 -33
- package/other/index.d.ts +4 -4
- package/other/lazy.service.d.ts +22 -22
- package/other/logger.d.ts +5 -6
- package/other/yelon-util-other.d.ts +4 -4
- package/other/yelon-util-other.metadata.json +1 -1
- package/package.json +1 -1
- package/pipes/currency/cny.pipe.d.ts +12 -12
- package/pipes/currency/index.d.ts +3 -3
- package/pipes/currency/mega.pipe.d.ts +13 -13
- package/pipes/currency/module.d.ts +2 -2
- package/pipes/currency/price.pipe.d.ts +16 -16
- package/pipes/currency/yelon-util-pipes-currency.d.ts +5 -5
- package/pipes/filter/filter.pipe.d.ts +10 -10
- package/pipes/filter/index.d.ts +2 -2
- package/pipes/filter/module.d.ts +2 -2
- package/pipes/filter/yelon-util-pipes-filter.d.ts +4 -4
- package/pipes/format/index.d.ts +2 -2
- package/pipes/format/mask.pipe.d.ts +24 -24
- package/pipes/format/module.d.ts +2 -2
- package/pipes/format/yelon-util-pipes-format.d.ts +4 -4
- package/pipes/index.d.ts +3 -3
- package/pipes/yelon-util-pipes.d.ts +4 -4
- package/token/index.d.ts +2 -2
- package/token/page-visibility.d.ts +8 -8
- package/token/window.d.ts +7 -7
- package/token/yelon-util-token.d.ts +4 -4
- package/yelon-util.d.ts +4 -4
@@ -1,8 +1,8 @@
|
|
1
|
-
/**
|
2
|
-
* @license ng-yunzai(devcui@outlook.com) v12.0.
|
3
|
-
* (c) 2020 devcui https://github.com/hbyunzai/yelon/
|
4
|
-
* License: MIT
|
5
|
-
*/
|
1
|
+
/**
|
2
|
+
* @license ng-yunzai(devcui@outlook.com) v12.0.17
|
3
|
+
* (c) 2020 devcui https://github.com/hbyunzai/yelon/
|
4
|
+
* License: MIT
|
5
|
+
*/
|
6
6
|
(function (global, factory) {
|
7
7
|
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@yelon/util/other'), require('@angular/common'), require('@angular/core'), require('@yelon/util/config')) :
|
8
8
|
typeof define === 'function' && define.amd ? define('@yelon/util/format', ['exports', '@yelon/util/other', '@angular/common', '@angular/core', '@yelon/util/config'], factory) :
|
@@ -30,737 +30,737 @@
|
|
30
30
|
var i0__namespace = /*#__PURE__*/_interopNamespace(i0);
|
31
31
|
var i1__namespace = /*#__PURE__*/_interopNamespace(i1);
|
32
32
|
|
33
|
-
/**
|
34
|
-
* String formatting
|
35
|
-
*
|
36
|
-
* 字符串格式化
|
37
|
-
* ```
|
38
|
-
* format('this is ${name}', { name: 'asdf' })
|
39
|
-
* // output: this is asdf
|
40
|
-
* format('this is ${user.name}', { user: { name: 'asdf' } }, true)
|
41
|
-
* // output: this is asdf
|
42
|
-
* ```
|
43
|
-
*/
|
44
|
-
function format(str, obj, needDeepGet) {
|
45
|
-
if (needDeepGet === void 0) { needDeepGet = false; }
|
46
|
-
return (str || '').replace(/\${([^}]+)}/g, function (_work, key) { return needDeepGet ? other.deepGet(obj, key.split('.'), '') : (obj || {})[key] || ''; });
|
47
|
-
}
|
48
|
-
/**
|
49
|
-
* Format mask
|
50
|
-
*
|
51
|
-
* 格式化掩码
|
52
|
-
*
|
53
|
-
* | 字符 | 描述 |
|
54
|
-
* | --- | --- |
|
55
|
-
* | `0` | 任意数字,若该位置字符不符合,则默认为 `0` 填充 |
|
56
|
-
* | `9` | 任意数字 |
|
57
|
-
* | `#` | 任意字符 |
|
58
|
-
* | `U` | 转换大写 |
|
59
|
-
* | `L` | 转换小写 |
|
60
|
-
* | `*` | 转换为 `*` 字符 |
|
61
|
-
*
|
62
|
-
* ```ts
|
63
|
-
* formatMask('123', '(###)') => (123)
|
64
|
-
* formatMask('15900000000', '999****9999') => 159****0000
|
65
|
-
* ```
|
66
|
-
*/
|
67
|
-
function formatMask(value, option) {
|
68
|
-
if (!value) {
|
69
|
-
return '';
|
70
|
-
}
|
71
|
-
var opt = Object.assign({}, (typeof option === 'string' ? { mask: option } : option));
|
72
|
-
var tokens = Object.assign({ '0': { pattern: /\d/, default: '0' }, '9': { pattern: /\d/ }, '#': { pattern: /[a-zA-Z0-9]/ }, U: {
|
73
|
-
pattern: /[a-zA-Z]/,
|
74
|
-
transform: function (char) { return char.toLocaleUpperCase(); }
|
75
|
-
}, L: {
|
76
|
-
pattern: /[a-zA-Z]/,
|
77
|
-
transform: function (char) { return char.toLocaleLowerCase(); }
|
78
|
-
}, '*': {
|
79
|
-
pattern: /.*/,
|
80
|
-
transform: function (_) { return "*"; }
|
81
|
-
} }, opt.tokens);
|
82
|
-
var splitValue = value.split('');
|
83
|
-
return opt.mask
|
84
|
-
.split('')
|
85
|
-
.reduce(function (res, cur) {
|
86
|
-
var _a;
|
87
|
-
var token = tokens[cur];
|
88
|
-
if (!token) {
|
89
|
-
res.push(cur);
|
90
|
-
return res;
|
91
|
-
}
|
92
|
-
var value = (_a = splitValue.shift()) !== null && _a !== void 0 ? _a : '';
|
93
|
-
if (!token.pattern.test(value)) {
|
94
|
-
if (token.default)
|
95
|
-
res.push(token.default);
|
96
|
-
return res;
|
97
|
-
}
|
98
|
-
if (typeof token.transform === 'function') {
|
99
|
-
res.push(token.transform(value));
|
100
|
-
}
|
101
|
-
else {
|
102
|
-
res.push(value);
|
103
|
-
}
|
104
|
-
return res;
|
105
|
-
}, [])
|
106
|
-
.join('');
|
33
|
+
/**
|
34
|
+
* String formatting
|
35
|
+
*
|
36
|
+
* 字符串格式化
|
37
|
+
* ```
|
38
|
+
* format('this is ${name}', { name: 'asdf' })
|
39
|
+
* // output: this is asdf
|
40
|
+
* format('this is ${user.name}', { user: { name: 'asdf' } }, true)
|
41
|
+
* // output: this is asdf
|
42
|
+
* ```
|
43
|
+
*/
|
44
|
+
function format(str, obj, needDeepGet) {
|
45
|
+
if (needDeepGet === void 0) { needDeepGet = false; }
|
46
|
+
return (str || '').replace(/\${([^}]+)}/g, function (_work, key) { return needDeepGet ? other.deepGet(obj, key.split('.'), '') : (obj || {})[key] || ''; });
|
47
|
+
}
|
48
|
+
/**
|
49
|
+
* Format mask
|
50
|
+
*
|
51
|
+
* 格式化掩码
|
52
|
+
*
|
53
|
+
* | 字符 | 描述 |
|
54
|
+
* | --- | --- |
|
55
|
+
* | `0` | 任意数字,若该位置字符不符合,则默认为 `0` 填充 |
|
56
|
+
* | `9` | 任意数字 |
|
57
|
+
* | `#` | 任意字符 |
|
58
|
+
* | `U` | 转换大写 |
|
59
|
+
* | `L` | 转换小写 |
|
60
|
+
* | `*` | 转换为 `*` 字符 |
|
61
|
+
*
|
62
|
+
* ```ts
|
63
|
+
* formatMask('123', '(###)') => (123)
|
64
|
+
* formatMask('15900000000', '999****9999') => 159****0000
|
65
|
+
* ```
|
66
|
+
*/
|
67
|
+
function formatMask(value, option) {
|
68
|
+
if (!value) {
|
69
|
+
return '';
|
70
|
+
}
|
71
|
+
var opt = Object.assign({}, (typeof option === 'string' ? { mask: option } : option));
|
72
|
+
var tokens = Object.assign({ '0': { pattern: /\d/, default: '0' }, '9': { pattern: /\d/ }, '#': { pattern: /[a-zA-Z0-9]/ }, U: {
|
73
|
+
pattern: /[a-zA-Z]/,
|
74
|
+
transform: function (char) { return char.toLocaleUpperCase(); }
|
75
|
+
}, L: {
|
76
|
+
pattern: /[a-zA-Z]/,
|
77
|
+
transform: function (char) { return char.toLocaleLowerCase(); }
|
78
|
+
}, '*': {
|
79
|
+
pattern: /.*/,
|
80
|
+
transform: function (_) { return "*"; }
|
81
|
+
} }, opt.tokens);
|
82
|
+
var splitValue = value.split('');
|
83
|
+
return opt.mask
|
84
|
+
.split('')
|
85
|
+
.reduce(function (res, cur) {
|
86
|
+
var _a;
|
87
|
+
var token = tokens[cur];
|
88
|
+
if (!token) {
|
89
|
+
res.push(cur);
|
90
|
+
return res;
|
91
|
+
}
|
92
|
+
var value = (_a = splitValue.shift()) !== null && _a !== void 0 ? _a : '';
|
93
|
+
if (!token.pattern.test(value)) {
|
94
|
+
if (token.default)
|
95
|
+
res.push(token.default);
|
96
|
+
return res;
|
97
|
+
}
|
98
|
+
if (typeof token.transform === 'function') {
|
99
|
+
res.push(token.transform(value));
|
100
|
+
}
|
101
|
+
else {
|
102
|
+
res.push(value);
|
103
|
+
}
|
104
|
+
return res;
|
105
|
+
}, [])
|
106
|
+
.join('');
|
107
107
|
}
|
108
108
|
|
109
|
-
var REGEX_STR = {
|
110
|
-
num: "((-?\\d+\\.\\d+)|(-?\\d+)|(-?\\.\\d+))",
|
111
|
-
idCard: "(^\\d{15}$)|(^\\d{17}(?:[0-9]|X)$)",
|
112
|
-
mobile: "^(0|\\+?86|17951)?1[0-9]{10}$",
|
113
|
-
url: "(((^https?:(?://)?)(?:[-;:&=\\+\\$,\\w]+@)?[A-Za-z0-9.-]+(?::\\d+)?|(?:www.|[-;:&=\\+\\$,\\w]+@)[A-Za-z0-9.-]+)((?:/[\\+~%\\/.\\w-_]*)?\\??(?:[-\\+=&;%@.\\w_]*)#?(?:[\\w]*))?)",
|
114
|
-
ip: "(?:^(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)(?:\\.(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)){3}$)|(?:^(?:(?:[a-fA-F\\d]{1,4}:){7}(?:[a-fA-F\\d]{1,4}|:)|(?:[a-fA-F\\d]{1,4}:){6}(?:(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)(?:\\.(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)){3}|:[a-fA-F\\d]{1,4}|:)|(?:[a-fA-F\\d]{1,4}:){5}(?::(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)(?:\\.(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)){3}|(?::[a-fA-F\\d]{1,4}){1,2}|:)|(?:[a-fA-F\\d]{1,4}:){4}(?:(?::[a-fA-F\\d]{1,4}){0,1}:(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)(?:\\.(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)){3}|(?::[a-fA-F\\d]{1,4}){1,3}|:)|(?:[a-fA-F\\d]{1,4}:){3}(?:(?::[a-fA-F\\d]{1,4}){0,2}:(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)(?:\\.(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)){3}|(?::[a-fA-F\\d]{1,4}){1,4}|:)|(?:[a-fA-F\\d]{1,4}:){2}(?:(?::[a-fA-F\\d]{1,4}){0,3}:(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)(?:\\.(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)){3}|(?::[a-fA-F\\d]{1,4}){1,5}|:)|(?:[a-fA-F\\d]{1,4}:){1}(?:(?::[a-fA-F\\d]{1,4}){0,4}:(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)(?:\\.(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)){3}|(?::[a-fA-F\\d]{1,4}){1,6}|:)|(?::(?:(?::[a-fA-F\\d]{1,4}){0,5}:(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)(?:\\.(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)){3}|(?::[a-fA-F\\d]{1,4}){1,7}|:)))(?:%[0-9a-zA-Z]{1,})?$)",
|
115
|
-
color: "(?:#|0x)(?:[a-f0-9]{3}|[a-f0-9]{6})\\b|(?:rgb|hsl)a?\\([^\\)]*\\)",
|
116
|
-
chinese: "[\u4E00-\u9FA5]+"
|
117
|
-
};
|
118
|
-
function genRegex(str, flags) {
|
119
|
-
return new RegExp("^" + str + "$", flags);
|
120
|
-
}
|
121
|
-
var REGEX = {
|
122
|
-
num: genRegex(REGEX_STR.num),
|
123
|
-
idCard: genRegex(REGEX_STR.idCard, 'i'),
|
124
|
-
mobile: genRegex(REGEX_STR.mobile),
|
125
|
-
url: genRegex(REGEX_STR.url),
|
126
|
-
ip: genRegex(REGEX_STR.ip),
|
127
|
-
color: genRegex(REGEX_STR.color),
|
128
|
-
chinese: genRegex(REGEX_STR.chinese)
|
129
|
-
};
|
130
|
-
/**
|
131
|
-
* Wheter is number
|
132
|
-
*
|
133
|
-
* 是否为数字
|
134
|
-
*/
|
135
|
-
function isNum(value) {
|
136
|
-
return REGEX.num.test(value.toString());
|
137
|
-
}
|
138
|
-
/**
|
139
|
-
* Wheter is integer
|
140
|
-
*
|
141
|
-
* 是否为整数
|
142
|
-
*/
|
143
|
-
function isInt(value) {
|
144
|
-
return isNum(value) && parseInt(value.toString(), 10).toString() === value.toString();
|
145
|
-
}
|
146
|
-
/**
|
147
|
-
* Wheter is decimal
|
148
|
-
*
|
149
|
-
* 是否为小数点数值
|
150
|
-
*/
|
151
|
-
function isDecimal(value) {
|
152
|
-
return isNum(value) && !isInt(value);
|
153
|
-
}
|
154
|
-
/**
|
155
|
-
* Wheter is People's Republic of China identity card
|
156
|
-
*
|
157
|
-
* 是否为中华人民共和国居民身份证
|
158
|
-
*/
|
159
|
-
function isIdCard(value) {
|
160
|
-
return REGEX.idCard.test(value);
|
161
|
-
}
|
162
|
-
/**
|
163
|
-
* Wheter is china mobile (China)
|
164
|
-
*
|
165
|
-
* 是否为手机号(中国)
|
166
|
-
*/
|
167
|
-
function isMobile(value) {
|
168
|
-
return REGEX.mobile.test(value);
|
169
|
-
}
|
170
|
-
/**
|
171
|
-
* Wheter is url address
|
172
|
-
*
|
173
|
-
* 是否URL地址
|
174
|
-
*/
|
175
|
-
function isUrl(url) {
|
176
|
-
return REGEX.url.test(url);
|
109
|
+
var REGEX_STR = {
|
110
|
+
num: "((-?\\d+\\.\\d+)|(-?\\d+)|(-?\\.\\d+))",
|
111
|
+
idCard: "(^\\d{15}$)|(^\\d{17}(?:[0-9]|X)$)",
|
112
|
+
mobile: "^(0|\\+?86|17951)?1[0-9]{10}$",
|
113
|
+
url: "(((^https?:(?://)?)(?:[-;:&=\\+\\$,\\w]+@)?[A-Za-z0-9.-]+(?::\\d+)?|(?:www.|[-;:&=\\+\\$,\\w]+@)[A-Za-z0-9.-]+)((?:/[\\+~%\\/.\\w-_]*)?\\??(?:[-\\+=&;%@.\\w_]*)#?(?:[\\w]*))?)",
|
114
|
+
ip: "(?:^(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)(?:\\.(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)){3}$)|(?:^(?:(?:[a-fA-F\\d]{1,4}:){7}(?:[a-fA-F\\d]{1,4}|:)|(?:[a-fA-F\\d]{1,4}:){6}(?:(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)(?:\\.(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)){3}|:[a-fA-F\\d]{1,4}|:)|(?:[a-fA-F\\d]{1,4}:){5}(?::(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)(?:\\.(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)){3}|(?::[a-fA-F\\d]{1,4}){1,2}|:)|(?:[a-fA-F\\d]{1,4}:){4}(?:(?::[a-fA-F\\d]{1,4}){0,1}:(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)(?:\\.(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)){3}|(?::[a-fA-F\\d]{1,4}){1,3}|:)|(?:[a-fA-F\\d]{1,4}:){3}(?:(?::[a-fA-F\\d]{1,4}){0,2}:(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)(?:\\.(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)){3}|(?::[a-fA-F\\d]{1,4}){1,4}|:)|(?:[a-fA-F\\d]{1,4}:){2}(?:(?::[a-fA-F\\d]{1,4}){0,3}:(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)(?:\\.(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)){3}|(?::[a-fA-F\\d]{1,4}){1,5}|:)|(?:[a-fA-F\\d]{1,4}:){1}(?:(?::[a-fA-F\\d]{1,4}){0,4}:(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)(?:\\.(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)){3}|(?::[a-fA-F\\d]{1,4}){1,6}|:)|(?::(?:(?::[a-fA-F\\d]{1,4}){0,5}:(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)(?:\\.(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)){3}|(?::[a-fA-F\\d]{1,4}){1,7}|:)))(?:%[0-9a-zA-Z]{1,})?$)",
|
115
|
+
color: "(?:#|0x)(?:[a-f0-9]{3}|[a-f0-9]{6})\\b|(?:rgb|hsl)a?\\([^\\)]*\\)",
|
116
|
+
chinese: "[\u4E00-\u9FA5]+"
|
117
|
+
};
|
118
|
+
function genRegex(str, flags) {
|
119
|
+
return new RegExp("^" + str + "$", flags);
|
120
|
+
}
|
121
|
+
var REGEX = {
|
122
|
+
num: genRegex(REGEX_STR.num),
|
123
|
+
idCard: genRegex(REGEX_STR.idCard, 'i'),
|
124
|
+
mobile: genRegex(REGEX_STR.mobile),
|
125
|
+
url: genRegex(REGEX_STR.url),
|
126
|
+
ip: genRegex(REGEX_STR.ip),
|
127
|
+
color: genRegex(REGEX_STR.color),
|
128
|
+
chinese: genRegex(REGEX_STR.chinese)
|
129
|
+
};
|
130
|
+
/**
|
131
|
+
* Wheter is number
|
132
|
+
*
|
133
|
+
* 是否为数字
|
134
|
+
*/
|
135
|
+
function isNum(value) {
|
136
|
+
return REGEX.num.test(value.toString());
|
137
|
+
}
|
138
|
+
/**
|
139
|
+
* Wheter is integer
|
140
|
+
*
|
141
|
+
* 是否为整数
|
142
|
+
*/
|
143
|
+
function isInt(value) {
|
144
|
+
return isNum(value) && parseInt(value.toString(), 10).toString() === value.toString();
|
145
|
+
}
|
146
|
+
/**
|
147
|
+
* Wheter is decimal
|
148
|
+
*
|
149
|
+
* 是否为小数点数值
|
150
|
+
*/
|
151
|
+
function isDecimal(value) {
|
152
|
+
return isNum(value) && !isInt(value);
|
153
|
+
}
|
154
|
+
/**
|
155
|
+
* Wheter is People's Republic of China identity card
|
156
|
+
*
|
157
|
+
* 是否为中华人民共和国居民身份证
|
158
|
+
*/
|
159
|
+
function isIdCard(value) {
|
160
|
+
return REGEX.idCard.test(value);
|
161
|
+
}
|
162
|
+
/**
|
163
|
+
* Wheter is china mobile (China)
|
164
|
+
*
|
165
|
+
* 是否为手机号(中国)
|
166
|
+
*/
|
167
|
+
function isMobile(value) {
|
168
|
+
return REGEX.mobile.test(value);
|
169
|
+
}
|
170
|
+
/**
|
171
|
+
* Wheter is url address
|
172
|
+
*
|
173
|
+
* 是否URL地址
|
174
|
+
*/
|
175
|
+
function isUrl(url) {
|
176
|
+
return REGEX.url.test(url);
|
177
|
+
}
|
178
|
+
/**
|
179
|
+
* Wheter is IPv4 address (Support v4, v6)
|
180
|
+
*
|
181
|
+
* 是否IP4地址(支持v4、v6)
|
182
|
+
*/
|
183
|
+
function isIp(ip) {
|
184
|
+
return REGEX.ip.test(ip);
|
185
|
+
}
|
186
|
+
/**
|
187
|
+
* Wheter is color
|
188
|
+
*
|
189
|
+
* 是否颜色代码值
|
190
|
+
*/
|
191
|
+
function isColor(color) {
|
192
|
+
return REGEX.color.test(color);
|
193
|
+
}
|
194
|
+
/**
|
195
|
+
* Wheter is chinese
|
196
|
+
*
|
197
|
+
* 是否中文
|
198
|
+
*/
|
199
|
+
function isChinese(value) {
|
200
|
+
return REGEX.chinese.test(value);
|
177
201
|
}
|
178
|
-
/**
|
179
|
-
* Wheter is IPv4 address (Support v4, v6)
|
180
|
-
*
|
181
|
-
* 是否IP4地址(支持v4、v6)
|
182
|
-
*/
|
183
|
-
function isIp(ip) {
|
184
|
-
return REGEX.ip.test(ip);
|
185
|
-
}
|
186
|
-
/**
|
187
|
-
* Wheter is color
|
188
|
-
*
|
189
|
-
* 是否颜色代码值
|
190
|
-
*/
|
191
|
-
function isColor(color) {
|
192
|
-
return REGEX.color.test(color);
|
193
|
-
}
|
194
|
-
/**
|
195
|
-
* Wheter is chinese
|
196
|
-
*
|
197
|
-
* 是否中文
|
198
|
-
*/
|
199
|
-
function isChinese(value) {
|
200
|
-
return REGEX.chinese.test(value);
|
201
|
-
}
|
202
|
-
|
203
|
-
/*! *****************************************************************************
|
204
|
-
Copyright (c) Microsoft Corporation.
|
205
|
-
|
206
|
-
Permission to use, copy, modify, and/or distribute this software for any
|
207
|
-
purpose with or without fee is hereby granted.
|
208
202
|
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
function
|
284
|
-
step(generator
|
285
|
-
}
|
286
|
-
catch (e) {
|
287
|
-
reject(e);
|
288
|
-
} }
|
289
|
-
function
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
case
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
_.
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
_.
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
}
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
return ar;
|
419
|
-
}
|
420
|
-
/** @deprecated */
|
421
|
-
function
|
422
|
-
for (var
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
for (var i = 0,
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
return
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
function
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
function
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
}
|
479
|
-
|
480
|
-
|
481
|
-
|
482
|
-
|
483
|
-
|
484
|
-
|
485
|
-
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
}
|
490
|
-
|
491
|
-
|
492
|
-
|
493
|
-
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
|
500
|
-
|
501
|
-
|
502
|
-
|
503
|
-
|
504
|
-
|
505
|
-
|
506
|
-
|
507
|
-
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
|
514
|
-
|
515
|
-
|
516
|
-
|
517
|
-
|
518
|
-
|
203
|
+
/*! *****************************************************************************
|
204
|
+
Copyright (c) Microsoft Corporation.
|
205
|
+
|
206
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
207
|
+
purpose with or without fee is hereby granted.
|
208
|
+
|
209
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
210
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
211
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
212
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
213
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
214
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
215
|
+
PERFORMANCE OF THIS SOFTWARE.
|
216
|
+
***************************************************************************** */
|
217
|
+
/* global Reflect, Promise */
|
218
|
+
var extendStatics = function (d, b) {
|
219
|
+
extendStatics = Object.setPrototypeOf ||
|
220
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
221
|
+
function (d, b) { for (var p in b)
|
222
|
+
if (Object.prototype.hasOwnProperty.call(b, p))
|
223
|
+
d[p] = b[p]; };
|
224
|
+
return extendStatics(d, b);
|
225
|
+
};
|
226
|
+
function __extends(d, b) {
|
227
|
+
if (typeof b !== "function" && b !== null)
|
228
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
229
|
+
extendStatics(d, b);
|
230
|
+
function __() { this.constructor = d; }
|
231
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
232
|
+
}
|
233
|
+
var __assign = function () {
|
234
|
+
__assign = Object.assign || function __assign(t) {
|
235
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
236
|
+
s = arguments[i];
|
237
|
+
for (var p in s)
|
238
|
+
if (Object.prototype.hasOwnProperty.call(s, p))
|
239
|
+
t[p] = s[p];
|
240
|
+
}
|
241
|
+
return t;
|
242
|
+
};
|
243
|
+
return __assign.apply(this, arguments);
|
244
|
+
};
|
245
|
+
function __rest(s, e) {
|
246
|
+
var t = {};
|
247
|
+
for (var p in s)
|
248
|
+
if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
249
|
+
t[p] = s[p];
|
250
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
251
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
252
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
253
|
+
t[p[i]] = s[p[i]];
|
254
|
+
}
|
255
|
+
return t;
|
256
|
+
}
|
257
|
+
function __decorate(decorators, target, key, desc) {
|
258
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
259
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
260
|
+
r = Reflect.decorate(decorators, target, key, desc);
|
261
|
+
else
|
262
|
+
for (var i = decorators.length - 1; i >= 0; i--)
|
263
|
+
if (d = decorators[i])
|
264
|
+
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
265
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
266
|
+
}
|
267
|
+
function __param(paramIndex, decorator) {
|
268
|
+
return function (target, key) { decorator(target, key, paramIndex); };
|
269
|
+
}
|
270
|
+
function __metadata(metadataKey, metadataValue) {
|
271
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
|
272
|
+
return Reflect.metadata(metadataKey, metadataValue);
|
273
|
+
}
|
274
|
+
function __awaiter(thisArg, _arguments, P, generator) {
|
275
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
276
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
277
|
+
function fulfilled(value) { try {
|
278
|
+
step(generator.next(value));
|
279
|
+
}
|
280
|
+
catch (e) {
|
281
|
+
reject(e);
|
282
|
+
} }
|
283
|
+
function rejected(value) { try {
|
284
|
+
step(generator["throw"](value));
|
285
|
+
}
|
286
|
+
catch (e) {
|
287
|
+
reject(e);
|
288
|
+
} }
|
289
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
290
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
291
|
+
});
|
292
|
+
}
|
293
|
+
function __generator(thisArg, body) {
|
294
|
+
var _ = { label: 0, sent: function () { if (t[0] & 1)
|
295
|
+
throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
296
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function () { return this; }), g;
|
297
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
298
|
+
function step(op) {
|
299
|
+
if (f)
|
300
|
+
throw new TypeError("Generator is already executing.");
|
301
|
+
while (_)
|
302
|
+
try {
|
303
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done)
|
304
|
+
return t;
|
305
|
+
if (y = 0, t)
|
306
|
+
op = [op[0] & 2, t.value];
|
307
|
+
switch (op[0]) {
|
308
|
+
case 0:
|
309
|
+
case 1:
|
310
|
+
t = op;
|
311
|
+
break;
|
312
|
+
case 4:
|
313
|
+
_.label++;
|
314
|
+
return { value: op[1], done: false };
|
315
|
+
case 5:
|
316
|
+
_.label++;
|
317
|
+
y = op[1];
|
318
|
+
op = [0];
|
319
|
+
continue;
|
320
|
+
case 7:
|
321
|
+
op = _.ops.pop();
|
322
|
+
_.trys.pop();
|
323
|
+
continue;
|
324
|
+
default:
|
325
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
326
|
+
_ = 0;
|
327
|
+
continue;
|
328
|
+
}
|
329
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) {
|
330
|
+
_.label = op[1];
|
331
|
+
break;
|
332
|
+
}
|
333
|
+
if (op[0] === 6 && _.label < t[1]) {
|
334
|
+
_.label = t[1];
|
335
|
+
t = op;
|
336
|
+
break;
|
337
|
+
}
|
338
|
+
if (t && _.label < t[2]) {
|
339
|
+
_.label = t[2];
|
340
|
+
_.ops.push(op);
|
341
|
+
break;
|
342
|
+
}
|
343
|
+
if (t[2])
|
344
|
+
_.ops.pop();
|
345
|
+
_.trys.pop();
|
346
|
+
continue;
|
347
|
+
}
|
348
|
+
op = body.call(thisArg, _);
|
349
|
+
}
|
350
|
+
catch (e) {
|
351
|
+
op = [6, e];
|
352
|
+
y = 0;
|
353
|
+
}
|
354
|
+
finally {
|
355
|
+
f = t = 0;
|
356
|
+
}
|
357
|
+
if (op[0] & 5)
|
358
|
+
throw op[1];
|
359
|
+
return { value: op[0] ? op[1] : void 0, done: true };
|
360
|
+
}
|
361
|
+
}
|
362
|
+
var __createBinding = Object.create ? (function (o, m, k, k2) {
|
363
|
+
if (k2 === undefined)
|
364
|
+
k2 = k;
|
365
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function () { return m[k]; } });
|
366
|
+
}) : (function (o, m, k, k2) {
|
367
|
+
if (k2 === undefined)
|
368
|
+
k2 = k;
|
369
|
+
o[k2] = m[k];
|
370
|
+
});
|
371
|
+
function __exportStar(m, o) {
|
372
|
+
for (var p in m)
|
373
|
+
if (p !== "default" && !Object.prototype.hasOwnProperty.call(o, p))
|
374
|
+
__createBinding(o, m, p);
|
375
|
+
}
|
376
|
+
function __values(o) {
|
377
|
+
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
378
|
+
if (m)
|
379
|
+
return m.call(o);
|
380
|
+
if (o && typeof o.length === "number")
|
381
|
+
return {
|
382
|
+
next: function () {
|
383
|
+
if (o && i >= o.length)
|
384
|
+
o = void 0;
|
385
|
+
return { value: o && o[i++], done: !o };
|
386
|
+
}
|
387
|
+
};
|
388
|
+
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
389
|
+
}
|
390
|
+
function __read(o, n) {
|
391
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
392
|
+
if (!m)
|
393
|
+
return o;
|
394
|
+
var i = m.call(o), r, ar = [], e;
|
395
|
+
try {
|
396
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done)
|
397
|
+
ar.push(r.value);
|
398
|
+
}
|
399
|
+
catch (error) {
|
400
|
+
e = { error: error };
|
401
|
+
}
|
402
|
+
finally {
|
403
|
+
try {
|
404
|
+
if (r && !r.done && (m = i["return"]))
|
405
|
+
m.call(i);
|
406
|
+
}
|
407
|
+
finally {
|
408
|
+
if (e)
|
409
|
+
throw e.error;
|
410
|
+
}
|
411
|
+
}
|
412
|
+
return ar;
|
413
|
+
}
|
414
|
+
/** @deprecated */
|
415
|
+
function __spread() {
|
416
|
+
for (var ar = [], i = 0; i < arguments.length; i++)
|
417
|
+
ar = ar.concat(__read(arguments[i]));
|
418
|
+
return ar;
|
419
|
+
}
|
420
|
+
/** @deprecated */
|
421
|
+
function __spreadArrays() {
|
422
|
+
for (var s = 0, i = 0, il = arguments.length; i < il; i++)
|
423
|
+
s += arguments[i].length;
|
424
|
+
for (var r = Array(s), k = 0, i = 0; i < il; i++)
|
425
|
+
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
|
426
|
+
r[k] = a[j];
|
427
|
+
return r;
|
428
|
+
}
|
429
|
+
function __spreadArray(to, from, pack) {
|
430
|
+
if (pack || arguments.length === 2)
|
431
|
+
for (var i = 0, l = from.length, ar; i < l; i++) {
|
432
|
+
if (ar || !(i in from)) {
|
433
|
+
if (!ar)
|
434
|
+
ar = Array.prototype.slice.call(from, 0, i);
|
435
|
+
ar[i] = from[i];
|
436
|
+
}
|
437
|
+
}
|
438
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
439
|
+
}
|
440
|
+
function __await(v) {
|
441
|
+
return this instanceof __await ? (this.v = v, this) : new __await(v);
|
442
|
+
}
|
443
|
+
function __asyncGenerator(thisArg, _arguments, generator) {
|
444
|
+
if (!Symbol.asyncIterator)
|
445
|
+
throw new TypeError("Symbol.asyncIterator is not defined.");
|
446
|
+
var g = generator.apply(thisArg, _arguments || []), i, q = [];
|
447
|
+
return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
|
448
|
+
function verb(n) { if (g[n])
|
449
|
+
i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
|
450
|
+
function resume(n, v) { try {
|
451
|
+
step(g[n](v));
|
452
|
+
}
|
453
|
+
catch (e) {
|
454
|
+
settle(q[0][3], e);
|
455
|
+
} }
|
456
|
+
function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
|
457
|
+
function fulfill(value) { resume("next", value); }
|
458
|
+
function reject(value) { resume("throw", value); }
|
459
|
+
function settle(f, v) { if (f(v), q.shift(), q.length)
|
460
|
+
resume(q[0][0], q[0][1]); }
|
461
|
+
}
|
462
|
+
function __asyncDelegator(o) {
|
463
|
+
var i, p;
|
464
|
+
return i = {}, verb("next"), verb("throw", function (e) { throw e; }), verb("return"), i[Symbol.iterator] = function () { return this; }, i;
|
465
|
+
function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === "return" } : f ? f(v) : v; } : f; }
|
466
|
+
}
|
467
|
+
function __asyncValues(o) {
|
468
|
+
if (!Symbol.asyncIterator)
|
469
|
+
throw new TypeError("Symbol.asyncIterator is not defined.");
|
470
|
+
var m = o[Symbol.asyncIterator], i;
|
471
|
+
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
|
472
|
+
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
|
473
|
+
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function (v) { resolve({ value: v, done: d }); }, reject); }
|
474
|
+
}
|
475
|
+
function __makeTemplateObject(cooked, raw) {
|
476
|
+
if (Object.defineProperty) {
|
477
|
+
Object.defineProperty(cooked, "raw", { value: raw });
|
478
|
+
}
|
479
|
+
else {
|
480
|
+
cooked.raw = raw;
|
481
|
+
}
|
482
|
+
return cooked;
|
483
|
+
}
|
484
|
+
;
|
485
|
+
var __setModuleDefault = Object.create ? (function (o, v) {
|
486
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
487
|
+
}) : function (o, v) {
|
488
|
+
o["default"] = v;
|
489
|
+
};
|
490
|
+
function __importStar(mod) {
|
491
|
+
if (mod && mod.__esModule)
|
492
|
+
return mod;
|
493
|
+
var result = {};
|
494
|
+
if (mod != null)
|
495
|
+
for (var k in mod)
|
496
|
+
if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k))
|
497
|
+
__createBinding(result, mod, k);
|
498
|
+
__setModuleDefault(result, mod);
|
499
|
+
return result;
|
500
|
+
}
|
501
|
+
function __importDefault(mod) {
|
502
|
+
return (mod && mod.__esModule) ? mod : { default: mod };
|
503
|
+
}
|
504
|
+
function __classPrivateFieldGet(receiver, state, kind, f) {
|
505
|
+
if (kind === "a" && !f)
|
506
|
+
throw new TypeError("Private accessor was defined without a getter");
|
507
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
|
508
|
+
throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
509
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
510
|
+
}
|
511
|
+
function __classPrivateFieldSet(receiver, state, value, kind, f) {
|
512
|
+
if (kind === "m")
|
513
|
+
throw new TypeError("Private method is not writable");
|
514
|
+
if (kind === "a" && !f)
|
515
|
+
throw new TypeError("Private accessor was defined without a setter");
|
516
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
|
517
|
+
throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
518
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
519
519
|
}
|
520
520
|
|
521
|
-
var CurrencyMega_Powers = [
|
522
|
-
{ unit: 'Q', value: Math.pow(10, 15) },
|
523
|
-
{ unit: 'T', value: Math.pow(10, 12) },
|
524
|
-
{ unit: 'B', value: Math.pow(10, 9) },
|
525
|
-
{ unit: 'M', value: Math.pow(10, 6) },
|
526
|
-
{ unit: 'K', value: 1000 }
|
521
|
+
var CurrencyMega_Powers = [
|
522
|
+
{ unit: 'Q', value: Math.pow(10, 15) },
|
523
|
+
{ unit: 'T', value: Math.pow(10, 12) },
|
524
|
+
{ unit: 'B', value: Math.pow(10, 9) },
|
525
|
+
{ unit: 'M', value: Math.pow(10, 6) },
|
526
|
+
{ unit: 'K', value: 1000 }
|
527
527
|
];
|
528
528
|
|
529
|
-
var CurrencyService = /** @class */ (function () {
|
530
|
-
function CurrencyService(cog, locale, _defaultCurrencyCode) {
|
531
|
-
if (_defaultCurrencyCode === void 0) { _defaultCurrencyCode = 'USD'; }
|
532
|
-
this.locale = locale;
|
533
|
-
this.currencyPipe = new common.CurrencyPipe(locale, _defaultCurrencyCode);
|
534
|
-
this.c = cog.merge('utilCurrency', {
|
535
|
-
startingUnit: 'yuan',
|
536
|
-
megaUnit: { Q: '京', T: '兆', B: '亿', M: '万', K: '千' },
|
537
|
-
precision: 2,
|
538
|
-
ignoreZeroPrecision: true
|
539
|
-
});
|
540
|
-
}
|
541
|
-
/**
|
542
|
-
* Format a number with commas as thousands separators
|
543
|
-
*
|
544
|
-
* 格式化货币,用逗号将数字格式化为千位分隔符
|
545
|
-
* ```ts
|
546
|
-
* 10000 => `10,000`
|
547
|
-
* 10000.567 => `10,000.57`
|
548
|
-
* ```
|
549
|
-
*/
|
550
|
-
CurrencyService.prototype.format = function (value, options) {
|
551
|
-
options = Object.assign({ startingUnit: this.c.startingUnit, precision: this.c.precision, ignoreZeroPrecision: this.c.ignoreZeroPrecision, ngCurrency: this.c.ngCurrency }, options);
|
552
|
-
var truthValue = Number(value);
|
553
|
-
if (value == null || isNaN(truthValue)) {
|
554
|
-
return '';
|
555
|
-
}
|
556
|
-
if (options.startingUnit === 'cent') {
|
557
|
-
truthValue = truthValue / 100;
|
558
|
-
}
|
559
|
-
if (options.ngCurrency != null) {
|
560
|
-
var cur = options.ngCurrency;
|
561
|
-
return this.currencyPipe.transform(truthValue, cur.currencyCode, cur.display, cur.digitsInfo, cur.locale || this.locale);
|
562
|
-
}
|
563
|
-
var res = common.formatNumber(truthValue, this.locale, "." + (options.ignoreZeroPrecision ? 1 : options.precision) + "-" + options.precision);
|
564
|
-
return options.ignoreZeroPrecision ? res.replace(/(?:\.[0]+)$/g, '') : res;
|
565
|
-
};
|
566
|
-
/**
|
567
|
-
* Large number format filter
|
568
|
-
*
|
569
|
-
* 大数据格式化
|
570
|
-
* ```ts
|
571
|
-
* 1000 => { value: '1', unit: 'K', unitI18n: '千' }
|
572
|
-
* 12456 => { value: '12.46', unit: 'K', unitI18n: '千' }
|
573
|
-
* ```
|
574
|
-
*/
|
575
|
-
CurrencyService.prototype.mega = function (value, options) {
|
576
|
-
var e_1, _a;
|
577
|
-
options = Object.assign({ precision: this.c.precision, unitI18n: this.c.megaUnit, startingUnit: this.c.startingUnit }, options);
|
578
|
-
var num = Number(value);
|
579
|
-
var res = { raw: value, value: '', unit: '', unitI18n: '' };
|
580
|
-
if (isNaN(num) || num === 0) {
|
581
|
-
res.value = value.toString();
|
582
|
-
return res;
|
583
|
-
}
|
584
|
-
if (options.startingUnit === 'cent') {
|
585
|
-
num = num / 100;
|
586
|
-
}
|
587
|
-
var abs = Math.abs(+num);
|
588
|
-
var rounder = Math.pow(10, options.precision);
|
589
|
-
var isNegative = num < 0;
|
590
|
-
try {
|
591
|
-
for (var CurrencyMega_Powers_1 = __values(CurrencyMega_Powers), CurrencyMega_Powers_1_1 = CurrencyMega_Powers_1.next(); !CurrencyMega_Powers_1_1.done; CurrencyMega_Powers_1_1 = CurrencyMega_Powers_1.next()) {
|
592
|
-
var p = CurrencyMega_Powers_1_1.value;
|
593
|
-
var reduced = abs / p.value;
|
594
|
-
reduced = Math.round(reduced * rounder) / rounder;
|
595
|
-
if (reduced >= 1) {
|
596
|
-
abs = reduced;
|
597
|
-
res.unit = p.unit;
|
598
|
-
break;
|
599
|
-
}
|
600
|
-
}
|
601
|
-
}
|
602
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
603
|
-
finally {
|
604
|
-
try {
|
605
|
-
if (CurrencyMega_Powers_1_1 && !CurrencyMega_Powers_1_1.done && (_a = CurrencyMega_Powers_1.return)) _a.call(CurrencyMega_Powers_1);
|
606
|
-
}
|
607
|
-
finally { if (e_1) throw e_1.error; }
|
608
|
-
}
|
609
|
-
res.value = (isNegative ? '-' : '') + abs;
|
610
|
-
res.unitI18n = options.unitI18n[res.unit];
|
611
|
-
return res;
|
612
|
-
};
|
613
|
-
/**
|
614
|
-
* Converted into RMB notation.
|
615
|
-
*
|
616
|
-
* 转化成人民币表示法
|
617
|
-
*/
|
618
|
-
CurrencyService.prototype.cny = function (value, options) {
|
619
|
-
var _a;
|
620
|
-
options = Object.assign({ inWords: true, minusSymbol: '负', startingUnit: this.c.startingUnit }, options);
|
621
|
-
value = Number(value);
|
622
|
-
if (isNaN(value)) {
|
623
|
-
return '';
|
624
|
-
}
|
625
|
-
if (options.startingUnit === 'cent') {
|
626
|
-
value = value / 100;
|
627
|
-
}
|
628
|
-
value = value.toString();
|
629
|
-
var integer;
|
630
|
-
var decimal;
|
631
|
-
_a = __read(value.split('.'), 2), integer = _a[0], decimal = _a[1];
|
632
|
-
var symbol = '';
|
633
|
-
if (integer.startsWith('-')) {
|
634
|
-
symbol = options.minusSymbol;
|
635
|
-
integer = integer.substr(1);
|
636
|
-
}
|
637
|
-
if (/^-?\d+$/.test(value)) {
|
638
|
-
decimal = null;
|
639
|
-
}
|
640
|
-
integer = (+integer).toString();
|
641
|
-
var inWords = options.inWords;
|
642
|
-
var unit = {
|
643
|
-
num: inWords
|
644
|
-
? ['', '壹', '贰', '叁', '肆', '伍', '陆', '柒', '捌', '玖', '点']
|
645
|
-
: ['', '一', '二', '三', '四', '五', '六', '七', '八', '九', '点'],
|
646
|
-
radice: inWords
|
647
|
-
? [
|
648
|
-
'',
|
649
|
-
'拾',
|
650
|
-
'佰',
|
651
|
-
'仟',
|
652
|
-
'万',
|
653
|
-
'拾',
|
654
|
-
'佰',
|
655
|
-
'仟',
|
656
|
-
'亿',
|
657
|
-
'拾',
|
658
|
-
'佰',
|
659
|
-
'仟',
|
660
|
-
'万亿',
|
661
|
-
'拾',
|
662
|
-
'佰',
|
663
|
-
'仟',
|
664
|
-
'兆',
|
665
|
-
'拾',
|
666
|
-
'佰',
|
667
|
-
'仟'
|
668
|
-
]
|
669
|
-
: [
|
670
|
-
'',
|
671
|
-
'十',
|
672
|
-
'百',
|
673
|
-
'千',
|
674
|
-
'万',
|
675
|
-
'十',
|
676
|
-
'百',
|
677
|
-
'千',
|
678
|
-
'亿',
|
679
|
-
'十',
|
680
|
-
'百',
|
681
|
-
'千',
|
682
|
-
'万亿',
|
683
|
-
'十',
|
684
|
-
'百',
|
685
|
-
'千',
|
686
|
-
'兆',
|
687
|
-
'十',
|
688
|
-
'百',
|
689
|
-
'千'
|
690
|
-
],
|
691
|
-
dec: ['角', '分', '厘', '毫']
|
692
|
-
};
|
693
|
-
if (inWords) {
|
694
|
-
value = (+value).toFixed(5).toString();
|
695
|
-
}
|
696
|
-
var integerRes = '';
|
697
|
-
var integerCount = integer.length;
|
698
|
-
if (integer === '0' || integerCount === 0) {
|
699
|
-
integerRes = '零';
|
700
|
-
}
|
701
|
-
else {
|
702
|
-
var cnDesc = '';
|
703
|
-
for (var i = 0; i < integerCount; i++) {
|
704
|
-
var n = +integer[i];
|
705
|
-
var j = integerCount - i - 1;
|
706
|
-
var isZero = i > 1 && n !== 0 && integer[i - 1] === '0';
|
707
|
-
var cnZero = isZero ? '零' : '';
|
708
|
-
var isEmpptyUnit = (n === 0 && j % 4 !== 0) || integer.substr(i - 3, 4) === '0000';
|
709
|
-
var descMark = cnDesc;
|
710
|
-
var cnNum = unit.num[n];
|
711
|
-
cnDesc = isEmpptyUnit ? '' : unit.radice[j];
|
712
|
-
// 第一位是一十
|
713
|
-
if (i === 0 && cnNum === '一' && cnDesc === '十')
|
714
|
-
cnNum = '';
|
715
|
-
var isChangeEr = n > 1 &&
|
716
|
-
cnNum === '二' && // 去除首位
|
717
|
-
['', '十', '百'].indexOf(cnDesc) === -1 && // 不读两\两十\两百
|
718
|
-
descMark !== '十'; // 不读十两
|
719
|
-
if (isChangeEr)
|
720
|
-
cnNum = '两';
|
721
|
-
integerRes += cnZero + cnNum + cnDesc;
|
722
|
-
}
|
723
|
-
}
|
724
|
-
// 小数部分拼接
|
725
|
-
var decimalRes = '';
|
726
|
-
var decimalCount = decimal ? decimal.toString().length : 0;
|
727
|
-
if (decimal === null) {
|
728
|
-
decimalRes = inWords ? '整' : '';
|
729
|
-
}
|
730
|
-
else if (decimal === '0') {
|
731
|
-
decimalRes = '零';
|
732
|
-
}
|
733
|
-
else {
|
734
|
-
for (var i = 0; i < decimalCount; i++) {
|
735
|
-
if (inWords && i > unit.dec.length - 1)
|
736
|
-
break;
|
737
|
-
var n = decimal[i];
|
738
|
-
var cnZero = n === '0' ? '零' : '';
|
739
|
-
var cnNum = unit.num[+n];
|
740
|
-
var cnDesc = inWords ? unit.dec[i] : '';
|
741
|
-
decimalRes += cnZero + cnNum + cnDesc;
|
742
|
-
}
|
743
|
-
}
|
744
|
-
var ret = symbol +
|
745
|
-
(inWords
|
746
|
-
? integerRes + (decimalRes === '零' ? '元整' : "\u5143" + decimalRes)
|
747
|
-
: integerRes + (decimalRes === '' ? '' : "\u70B9" + decimalRes));
|
748
|
-
return ret;
|
749
|
-
};
|
750
|
-
return CurrencyService;
|
751
|
-
}());
|
752
|
-
CurrencyService.ɵprov = i0__namespace.ɵɵdefineInjectable({ factory: function CurrencyService_Factory() { return new CurrencyService(i0__namespace.ɵɵinject(i1__namespace.YunzaiConfigService), i0__namespace.ɵɵinject(i0__namespace.LOCALE_ID), i0__namespace.ɵɵinject(i0__namespace.DEFAULT_CURRENCY_CODE)); }, token: CurrencyService, providedIn: "root" });
|
753
|
-
CurrencyService.decorators = [
|
754
|
-
{ type: i0.Injectable, args: [{ providedIn: 'root' },] }
|
755
|
-
];
|
756
|
-
CurrencyService.ctorParameters = function () { return [
|
757
|
-
{ type: i1.YunzaiConfigService },
|
758
|
-
{ type: String, decorators: [{ type: i0.Inject, args: [i0.LOCALE_ID,] }] },
|
759
|
-
{ type: String, decorators: [{ type: i0.Inject, args: [i0.DEFAULT_CURRENCY_CODE,] }] }
|
529
|
+
var CurrencyService = /** @class */ (function () {
|
530
|
+
function CurrencyService(cog, locale, _defaultCurrencyCode) {
|
531
|
+
if (_defaultCurrencyCode === void 0) { _defaultCurrencyCode = 'USD'; }
|
532
|
+
this.locale = locale;
|
533
|
+
this.currencyPipe = new common.CurrencyPipe(locale, _defaultCurrencyCode);
|
534
|
+
this.c = cog.merge('utilCurrency', {
|
535
|
+
startingUnit: 'yuan',
|
536
|
+
megaUnit: { Q: '京', T: '兆', B: '亿', M: '万', K: '千' },
|
537
|
+
precision: 2,
|
538
|
+
ignoreZeroPrecision: true
|
539
|
+
});
|
540
|
+
}
|
541
|
+
/**
|
542
|
+
* Format a number with commas as thousands separators
|
543
|
+
*
|
544
|
+
* 格式化货币,用逗号将数字格式化为千位分隔符
|
545
|
+
* ```ts
|
546
|
+
* 10000 => `10,000`
|
547
|
+
* 10000.567 => `10,000.57`
|
548
|
+
* ```
|
549
|
+
*/
|
550
|
+
CurrencyService.prototype.format = function (value, options) {
|
551
|
+
options = Object.assign({ startingUnit: this.c.startingUnit, precision: this.c.precision, ignoreZeroPrecision: this.c.ignoreZeroPrecision, ngCurrency: this.c.ngCurrency }, options);
|
552
|
+
var truthValue = Number(value);
|
553
|
+
if (value == null || isNaN(truthValue)) {
|
554
|
+
return '';
|
555
|
+
}
|
556
|
+
if (options.startingUnit === 'cent') {
|
557
|
+
truthValue = truthValue / 100;
|
558
|
+
}
|
559
|
+
if (options.ngCurrency != null) {
|
560
|
+
var cur = options.ngCurrency;
|
561
|
+
return this.currencyPipe.transform(truthValue, cur.currencyCode, cur.display, cur.digitsInfo, cur.locale || this.locale);
|
562
|
+
}
|
563
|
+
var res = common.formatNumber(truthValue, this.locale, "." + (options.ignoreZeroPrecision ? 1 : options.precision) + "-" + options.precision);
|
564
|
+
return options.ignoreZeroPrecision ? res.replace(/(?:\.[0]+)$/g, '') : res;
|
565
|
+
};
|
566
|
+
/**
|
567
|
+
* Large number format filter
|
568
|
+
*
|
569
|
+
* 大数据格式化
|
570
|
+
* ```ts
|
571
|
+
* 1000 => { value: '1', unit: 'K', unitI18n: '千' }
|
572
|
+
* 12456 => { value: '12.46', unit: 'K', unitI18n: '千' }
|
573
|
+
* ```
|
574
|
+
*/
|
575
|
+
CurrencyService.prototype.mega = function (value, options) {
|
576
|
+
var e_1, _a;
|
577
|
+
options = Object.assign({ precision: this.c.precision, unitI18n: this.c.megaUnit, startingUnit: this.c.startingUnit }, options);
|
578
|
+
var num = Number(value);
|
579
|
+
var res = { raw: value, value: '', unit: '', unitI18n: '' };
|
580
|
+
if (isNaN(num) || num === 0) {
|
581
|
+
res.value = value.toString();
|
582
|
+
return res;
|
583
|
+
}
|
584
|
+
if (options.startingUnit === 'cent') {
|
585
|
+
num = num / 100;
|
586
|
+
}
|
587
|
+
var abs = Math.abs(+num);
|
588
|
+
var rounder = Math.pow(10, options.precision);
|
589
|
+
var isNegative = num < 0;
|
590
|
+
try {
|
591
|
+
for (var CurrencyMega_Powers_1 = __values(CurrencyMega_Powers), CurrencyMega_Powers_1_1 = CurrencyMega_Powers_1.next(); !CurrencyMega_Powers_1_1.done; CurrencyMega_Powers_1_1 = CurrencyMega_Powers_1.next()) {
|
592
|
+
var p = CurrencyMega_Powers_1_1.value;
|
593
|
+
var reduced = abs / p.value;
|
594
|
+
reduced = Math.round(reduced * rounder) / rounder;
|
595
|
+
if (reduced >= 1) {
|
596
|
+
abs = reduced;
|
597
|
+
res.unit = p.unit;
|
598
|
+
break;
|
599
|
+
}
|
600
|
+
}
|
601
|
+
}
|
602
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
603
|
+
finally {
|
604
|
+
try {
|
605
|
+
if (CurrencyMega_Powers_1_1 && !CurrencyMega_Powers_1_1.done && (_a = CurrencyMega_Powers_1.return)) _a.call(CurrencyMega_Powers_1);
|
606
|
+
}
|
607
|
+
finally { if (e_1) throw e_1.error; }
|
608
|
+
}
|
609
|
+
res.value = (isNegative ? '-' : '') + abs;
|
610
|
+
res.unitI18n = options.unitI18n[res.unit];
|
611
|
+
return res;
|
612
|
+
};
|
613
|
+
/**
|
614
|
+
* Converted into RMB notation.
|
615
|
+
*
|
616
|
+
* 转化成人民币表示法
|
617
|
+
*/
|
618
|
+
CurrencyService.prototype.cny = function (value, options) {
|
619
|
+
var _a;
|
620
|
+
options = Object.assign({ inWords: true, minusSymbol: '负', startingUnit: this.c.startingUnit }, options);
|
621
|
+
value = Number(value);
|
622
|
+
if (isNaN(value)) {
|
623
|
+
return '';
|
624
|
+
}
|
625
|
+
if (options.startingUnit === 'cent') {
|
626
|
+
value = value / 100;
|
627
|
+
}
|
628
|
+
value = value.toString();
|
629
|
+
var integer;
|
630
|
+
var decimal;
|
631
|
+
_a = __read(value.split('.'), 2), integer = _a[0], decimal = _a[1];
|
632
|
+
var symbol = '';
|
633
|
+
if (integer.startsWith('-')) {
|
634
|
+
symbol = options.minusSymbol;
|
635
|
+
integer = integer.substr(1);
|
636
|
+
}
|
637
|
+
if (/^-?\d+$/.test(value)) {
|
638
|
+
decimal = null;
|
639
|
+
}
|
640
|
+
integer = (+integer).toString();
|
641
|
+
var inWords = options.inWords;
|
642
|
+
var unit = {
|
643
|
+
num: inWords
|
644
|
+
? ['', '壹', '贰', '叁', '肆', '伍', '陆', '柒', '捌', '玖', '点']
|
645
|
+
: ['', '一', '二', '三', '四', '五', '六', '七', '八', '九', '点'],
|
646
|
+
radice: inWords
|
647
|
+
? [
|
648
|
+
'',
|
649
|
+
'拾',
|
650
|
+
'佰',
|
651
|
+
'仟',
|
652
|
+
'万',
|
653
|
+
'拾',
|
654
|
+
'佰',
|
655
|
+
'仟',
|
656
|
+
'亿',
|
657
|
+
'拾',
|
658
|
+
'佰',
|
659
|
+
'仟',
|
660
|
+
'万亿',
|
661
|
+
'拾',
|
662
|
+
'佰',
|
663
|
+
'仟',
|
664
|
+
'兆',
|
665
|
+
'拾',
|
666
|
+
'佰',
|
667
|
+
'仟'
|
668
|
+
]
|
669
|
+
: [
|
670
|
+
'',
|
671
|
+
'十',
|
672
|
+
'百',
|
673
|
+
'千',
|
674
|
+
'万',
|
675
|
+
'十',
|
676
|
+
'百',
|
677
|
+
'千',
|
678
|
+
'亿',
|
679
|
+
'十',
|
680
|
+
'百',
|
681
|
+
'千',
|
682
|
+
'万亿',
|
683
|
+
'十',
|
684
|
+
'百',
|
685
|
+
'千',
|
686
|
+
'兆',
|
687
|
+
'十',
|
688
|
+
'百',
|
689
|
+
'千'
|
690
|
+
],
|
691
|
+
dec: ['角', '分', '厘', '毫']
|
692
|
+
};
|
693
|
+
if (inWords) {
|
694
|
+
value = (+value).toFixed(5).toString();
|
695
|
+
}
|
696
|
+
var integerRes = '';
|
697
|
+
var integerCount = integer.length;
|
698
|
+
if (integer === '0' || integerCount === 0) {
|
699
|
+
integerRes = '零';
|
700
|
+
}
|
701
|
+
else {
|
702
|
+
var cnDesc = '';
|
703
|
+
for (var i = 0; i < integerCount; i++) {
|
704
|
+
var n = +integer[i];
|
705
|
+
var j = integerCount - i - 1;
|
706
|
+
var isZero = i > 1 && n !== 0 && integer[i - 1] === '0';
|
707
|
+
var cnZero = isZero ? '零' : '';
|
708
|
+
var isEmpptyUnit = (n === 0 && j % 4 !== 0) || integer.substr(i - 3, 4) === '0000';
|
709
|
+
var descMark = cnDesc;
|
710
|
+
var cnNum = unit.num[n];
|
711
|
+
cnDesc = isEmpptyUnit ? '' : unit.radice[j];
|
712
|
+
// 第一位是一十
|
713
|
+
if (i === 0 && cnNum === '一' && cnDesc === '十')
|
714
|
+
cnNum = '';
|
715
|
+
var isChangeEr = n > 1 &&
|
716
|
+
cnNum === '二' && // 去除首位
|
717
|
+
['', '十', '百'].indexOf(cnDesc) === -1 && // 不读两\两十\两百
|
718
|
+
descMark !== '十'; // 不读十两
|
719
|
+
if (isChangeEr)
|
720
|
+
cnNum = '两';
|
721
|
+
integerRes += cnZero + cnNum + cnDesc;
|
722
|
+
}
|
723
|
+
}
|
724
|
+
// 小数部分拼接
|
725
|
+
var decimalRes = '';
|
726
|
+
var decimalCount = decimal ? decimal.toString().length : 0;
|
727
|
+
if (decimal === null) {
|
728
|
+
decimalRes = inWords ? '整' : '';
|
729
|
+
}
|
730
|
+
else if (decimal === '0') {
|
731
|
+
decimalRes = '零';
|
732
|
+
}
|
733
|
+
else {
|
734
|
+
for (var i = 0; i < decimalCount; i++) {
|
735
|
+
if (inWords && i > unit.dec.length - 1)
|
736
|
+
break;
|
737
|
+
var n = decimal[i];
|
738
|
+
var cnZero = n === '0' ? '零' : '';
|
739
|
+
var cnNum = unit.num[+n];
|
740
|
+
var cnDesc = inWords ? unit.dec[i] : '';
|
741
|
+
decimalRes += cnZero + cnNum + cnDesc;
|
742
|
+
}
|
743
|
+
}
|
744
|
+
var ret = symbol +
|
745
|
+
(inWords
|
746
|
+
? integerRes + (decimalRes === '零' ? '元整' : "\u5143" + decimalRes)
|
747
|
+
: integerRes + (decimalRes === '' ? '' : "\u70B9" + decimalRes));
|
748
|
+
return ret;
|
749
|
+
};
|
750
|
+
return CurrencyService;
|
751
|
+
}());
|
752
|
+
CurrencyService.ɵprov = i0__namespace.ɵɵdefineInjectable({ factory: function CurrencyService_Factory() { return new CurrencyService(i0__namespace.ɵɵinject(i1__namespace.YunzaiConfigService), i0__namespace.ɵɵinject(i0__namespace.LOCALE_ID), i0__namespace.ɵɵinject(i0__namespace.DEFAULT_CURRENCY_CODE)); }, token: CurrencyService, providedIn: "root" });
|
753
|
+
CurrencyService.decorators = [
|
754
|
+
{ type: i0.Injectable, args: [{ providedIn: 'root' },] }
|
755
|
+
];
|
756
|
+
CurrencyService.ctorParameters = function () { return [
|
757
|
+
{ type: i1.YunzaiConfigService },
|
758
|
+
{ type: String, decorators: [{ type: i0.Inject, args: [i0.LOCALE_ID,] }] },
|
759
|
+
{ type: String, decorators: [{ type: i0.Inject, args: [i0.DEFAULT_CURRENCY_CODE,] }] }
|
760
760
|
]; };
|
761
761
|
|
762
|
-
/**
|
763
|
-
* Generated bundle index. Do not edit.
|
762
|
+
/**
|
763
|
+
* Generated bundle index. Do not edit.
|
764
764
|
*/
|
765
765
|
|
766
766
|
exports.CurrencyMega_Powers = CurrencyMega_Powers;
|