@yelon/util 12.0.17 → 12.0.18
Sign up to get free protection for your applications and to get access to all the features.
- package/LICENSE +21 -21
- 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/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 +602 -602
- 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 -652
- 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 -427
- 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 +249 -249
- 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 +1 -1
- 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 +75 -75
- package/esm2015/other/index.js +4 -4
- package/esm2015/other/lazy.service.js +117 -117
- package/esm2015/other/logger.js +32 -32
- 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 +245 -245
- 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 +280 -280
- 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 -5
- package/other/yelon-util-other.d.ts +4 -4
- 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
@@ -5,404 +5,404 @@ import { Injectable, Inject, LOCALE_ID, DEFAULT_CURRENCY_CODE } from '@angular/c
|
|
5
5
|
import * as i1 from '@yelon/util/config';
|
6
6
|
import { YunzaiConfigService } from '@yelon/util/config';
|
7
7
|
|
8
|
-
/**
|
9
|
-
* String formatting
|
10
|
-
*
|
11
|
-
* 字符串格式化
|
12
|
-
* ```
|
13
|
-
* format('this is ${name}', { name: 'asdf' })
|
14
|
-
* // output: this is asdf
|
15
|
-
* format('this is ${user.name}', { user: { name: 'asdf' } }, true)
|
16
|
-
* // output: this is asdf
|
17
|
-
* ```
|
18
|
-
*/
|
19
|
-
function format(str, obj, needDeepGet = false) {
|
20
|
-
return (str || '').replace(/\${([^}]+)}/g, (_work, key) => needDeepGet ? deepGet(obj, key.split('.'), '') : (obj || {})[key] || '');
|
21
|
-
}
|
22
|
-
/**
|
23
|
-
* Format mask
|
24
|
-
*
|
25
|
-
* 格式化掩码
|
26
|
-
*
|
27
|
-
* | 字符 | 描述 |
|
28
|
-
* | --- | --- |
|
29
|
-
* | `0` | 任意数字,若该位置字符不符合,则默认为 `0` 填充 |
|
30
|
-
* | `9` | 任意数字 |
|
31
|
-
* | `#` | 任意字符 |
|
32
|
-
* | `U` | 转换大写 |
|
33
|
-
* | `L` | 转换小写 |
|
34
|
-
* | `*` | 转换为 `*` 字符 |
|
35
|
-
*
|
36
|
-
* ```ts
|
37
|
-
* formatMask('123', '(###)') => (123)
|
38
|
-
* formatMask('15900000000', '999****9999') => 159****0000
|
39
|
-
* ```
|
40
|
-
*/
|
41
|
-
function formatMask(value, option) {
|
42
|
-
if (!value) {
|
43
|
-
return '';
|
44
|
-
}
|
45
|
-
const opt = Object.assign({}, (typeof option === 'string' ? { mask: option } : option));
|
46
|
-
const tokens = Object.assign({ '0': { pattern: /\d/, default: '0' }, '9': { pattern: /\d/ }, '#': { pattern: /[a-zA-Z0-9]/ }, U: {
|
47
|
-
pattern: /[a-zA-Z]/,
|
48
|
-
transform: char => char.toLocaleUpperCase()
|
49
|
-
}, L: {
|
50
|
-
pattern: /[a-zA-Z]/,
|
51
|
-
transform: char => char.toLocaleLowerCase()
|
52
|
-
}, '*': {
|
53
|
-
pattern: /.*/,
|
54
|
-
transform: _ => `*`
|
55
|
-
} }, opt.tokens);
|
56
|
-
const splitValue = value.split('');
|
57
|
-
return opt.mask
|
58
|
-
.split('')
|
59
|
-
.reduce((res, cur) => {
|
60
|
-
var _a;
|
61
|
-
const token = tokens[cur];
|
62
|
-
if (!token) {
|
63
|
-
res.push(cur);
|
64
|
-
return res;
|
65
|
-
}
|
66
|
-
const value = (_a = splitValue.shift()) !== null && _a !== void 0 ? _a : '';
|
67
|
-
if (!token.pattern.test(value)) {
|
68
|
-
if (token.default)
|
69
|
-
res.push(token.default);
|
70
|
-
return res;
|
71
|
-
}
|
72
|
-
if (typeof token.transform === 'function') {
|
73
|
-
res.push(token.transform(value));
|
74
|
-
}
|
75
|
-
else {
|
76
|
-
res.push(value);
|
77
|
-
}
|
78
|
-
return res;
|
79
|
-
}, [])
|
80
|
-
.join('');
|
8
|
+
/**
|
9
|
+
* String formatting
|
10
|
+
*
|
11
|
+
* 字符串格式化
|
12
|
+
* ```
|
13
|
+
* format('this is ${name}', { name: 'asdf' })
|
14
|
+
* // output: this is asdf
|
15
|
+
* format('this is ${user.name}', { user: { name: 'asdf' } }, true)
|
16
|
+
* // output: this is asdf
|
17
|
+
* ```
|
18
|
+
*/
|
19
|
+
function format(str, obj, needDeepGet = false) {
|
20
|
+
return (str || '').replace(/\${([^}]+)}/g, (_work, key) => needDeepGet ? deepGet(obj, key.split('.'), '') : (obj || {})[key] || '');
|
21
|
+
}
|
22
|
+
/**
|
23
|
+
* Format mask
|
24
|
+
*
|
25
|
+
* 格式化掩码
|
26
|
+
*
|
27
|
+
* | 字符 | 描述 |
|
28
|
+
* | --- | --- |
|
29
|
+
* | `0` | 任意数字,若该位置字符不符合,则默认为 `0` 填充 |
|
30
|
+
* | `9` | 任意数字 |
|
31
|
+
* | `#` | 任意字符 |
|
32
|
+
* | `U` | 转换大写 |
|
33
|
+
* | `L` | 转换小写 |
|
34
|
+
* | `*` | 转换为 `*` 字符 |
|
35
|
+
*
|
36
|
+
* ```ts
|
37
|
+
* formatMask('123', '(###)') => (123)
|
38
|
+
* formatMask('15900000000', '999****9999') => 159****0000
|
39
|
+
* ```
|
40
|
+
*/
|
41
|
+
function formatMask(value, option) {
|
42
|
+
if (!value) {
|
43
|
+
return '';
|
44
|
+
}
|
45
|
+
const opt = Object.assign({}, (typeof option === 'string' ? { mask: option } : option));
|
46
|
+
const tokens = Object.assign({ '0': { pattern: /\d/, default: '0' }, '9': { pattern: /\d/ }, '#': { pattern: /[a-zA-Z0-9]/ }, U: {
|
47
|
+
pattern: /[a-zA-Z]/,
|
48
|
+
transform: char => char.toLocaleUpperCase()
|
49
|
+
}, L: {
|
50
|
+
pattern: /[a-zA-Z]/,
|
51
|
+
transform: char => char.toLocaleLowerCase()
|
52
|
+
}, '*': {
|
53
|
+
pattern: /.*/,
|
54
|
+
transform: _ => `*`
|
55
|
+
} }, opt.tokens);
|
56
|
+
const splitValue = value.split('');
|
57
|
+
return opt.mask
|
58
|
+
.split('')
|
59
|
+
.reduce((res, cur) => {
|
60
|
+
var _a;
|
61
|
+
const token = tokens[cur];
|
62
|
+
if (!token) {
|
63
|
+
res.push(cur);
|
64
|
+
return res;
|
65
|
+
}
|
66
|
+
const value = (_a = splitValue.shift()) !== null && _a !== void 0 ? _a : '';
|
67
|
+
if (!token.pattern.test(value)) {
|
68
|
+
if (token.default)
|
69
|
+
res.push(token.default);
|
70
|
+
return res;
|
71
|
+
}
|
72
|
+
if (typeof token.transform === 'function') {
|
73
|
+
res.push(token.transform(value));
|
74
|
+
}
|
75
|
+
else {
|
76
|
+
res.push(value);
|
77
|
+
}
|
78
|
+
return res;
|
79
|
+
}, [])
|
80
|
+
.join('');
|
81
81
|
}
|
82
82
|
|
83
|
-
const REGEX_STR = {
|
84
|
-
num: `((-?\\d+\\.\\d+)|(-?\\d+)|(-?\\.\\d+))`,
|
85
|
-
idCard: `(^\\d{15}$)|(^\\d{17}(?:[0-9]|X)$)`,
|
86
|
-
mobile: `^(0|\\+?86|17951)?1[0-9]{10}$`,
|
87
|
-
url: `(((^https?:(?:\/\/)?)(?:[-;:&=\\+\\$,\\w]+@)?[A-Za-z0-9.-]+(?::\\d+)?|(?:www.|[-;:&=\\+\\$,\\w]+@)[A-Za-z0-9.-]+)((?:\/[\\+~%\\/.\\w-_]*)?\\??(?:[-\\+=&;%@.\\w_]*)#?(?:[\\w]*))?)`,
|
88
|
-
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,})?$)`,
|
89
|
-
color: `(?:#|0x)(?:[a-f0-9]{3}|[a-f0-9]{6})\\b|(?:rgb|hsl)a?\\([^\\)]*\\)`,
|
90
|
-
chinese: `[\u4e00-\u9fa5]+`
|
91
|
-
};
|
92
|
-
function genRegex(str, flags) {
|
93
|
-
return new RegExp(`^${str}$`, flags);
|
94
|
-
}
|
95
|
-
const REGEX = {
|
96
|
-
num: genRegex(REGEX_STR.num),
|
97
|
-
idCard: genRegex(REGEX_STR.idCard, 'i'),
|
98
|
-
mobile: genRegex(REGEX_STR.mobile),
|
99
|
-
url: genRegex(REGEX_STR.url),
|
100
|
-
ip: genRegex(REGEX_STR.ip),
|
101
|
-
color: genRegex(REGEX_STR.color),
|
102
|
-
chinese: genRegex(REGEX_STR.chinese)
|
103
|
-
};
|
104
|
-
/**
|
105
|
-
* Wheter is number
|
106
|
-
*
|
107
|
-
* 是否为数字
|
108
|
-
*/
|
109
|
-
function isNum(value) {
|
110
|
-
return REGEX.num.test(value.toString());
|
111
|
-
}
|
112
|
-
/**
|
113
|
-
* Wheter is integer
|
114
|
-
*
|
115
|
-
* 是否为整数
|
116
|
-
*/
|
117
|
-
function isInt(value) {
|
118
|
-
return isNum(value) && parseInt(value.toString(), 10).toString() === value.toString();
|
119
|
-
}
|
120
|
-
/**
|
121
|
-
* Wheter is decimal
|
122
|
-
*
|
123
|
-
* 是否为小数点数值
|
124
|
-
*/
|
125
|
-
function isDecimal(value) {
|
126
|
-
return isNum(value) && !isInt(value);
|
127
|
-
}
|
128
|
-
/**
|
129
|
-
* Wheter is People's Republic of China identity card
|
130
|
-
*
|
131
|
-
* 是否为中华人民共和国居民身份证
|
132
|
-
*/
|
133
|
-
function isIdCard(value) {
|
134
|
-
return REGEX.idCard.test(value);
|
135
|
-
}
|
136
|
-
/**
|
137
|
-
* Wheter is china mobile (China)
|
138
|
-
*
|
139
|
-
* 是否为手机号(中国)
|
140
|
-
*/
|
141
|
-
function isMobile(value) {
|
142
|
-
return REGEX.mobile.test(value);
|
143
|
-
}
|
144
|
-
/**
|
145
|
-
* Wheter is url address
|
146
|
-
*
|
147
|
-
* 是否URL地址
|
148
|
-
*/
|
149
|
-
function isUrl(url) {
|
150
|
-
return REGEX.url.test(url);
|
151
|
-
}
|
152
|
-
/**
|
153
|
-
* Wheter is IPv4 address (Support v4, v6)
|
154
|
-
*
|
155
|
-
* 是否IP4地址(支持v4、v6)
|
156
|
-
*/
|
157
|
-
function isIp(ip) {
|
158
|
-
return REGEX.ip.test(ip);
|
159
|
-
}
|
160
|
-
/**
|
161
|
-
* Wheter is color
|
162
|
-
*
|
163
|
-
* 是否颜色代码值
|
164
|
-
*/
|
165
|
-
function isColor(color) {
|
166
|
-
return REGEX.color.test(color);
|
167
|
-
}
|
168
|
-
/**
|
169
|
-
* Wheter is chinese
|
170
|
-
*
|
171
|
-
* 是否中文
|
172
|
-
*/
|
173
|
-
function isChinese(value) {
|
174
|
-
return REGEX.chinese.test(value);
|
83
|
+
const REGEX_STR = {
|
84
|
+
num: `((-?\\d+\\.\\d+)|(-?\\d+)|(-?\\.\\d+))`,
|
85
|
+
idCard: `(^\\d{15}$)|(^\\d{17}(?:[0-9]|X)$)`,
|
86
|
+
mobile: `^(0|\\+?86|17951)?1[0-9]{10}$`,
|
87
|
+
url: `(((^https?:(?:\/\/)?)(?:[-;:&=\\+\\$,\\w]+@)?[A-Za-z0-9.-]+(?::\\d+)?|(?:www.|[-;:&=\\+\\$,\\w]+@)[A-Za-z0-9.-]+)((?:\/[\\+~%\\/.\\w-_]*)?\\??(?:[-\\+=&;%@.\\w_]*)#?(?:[\\w]*))?)`,
|
88
|
+
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,})?$)`,
|
89
|
+
color: `(?:#|0x)(?:[a-f0-9]{3}|[a-f0-9]{6})\\b|(?:rgb|hsl)a?\\([^\\)]*\\)`,
|
90
|
+
chinese: `[\u4e00-\u9fa5]+`
|
91
|
+
};
|
92
|
+
function genRegex(str, flags) {
|
93
|
+
return new RegExp(`^${str}$`, flags);
|
94
|
+
}
|
95
|
+
const REGEX = {
|
96
|
+
num: genRegex(REGEX_STR.num),
|
97
|
+
idCard: genRegex(REGEX_STR.idCard, 'i'),
|
98
|
+
mobile: genRegex(REGEX_STR.mobile),
|
99
|
+
url: genRegex(REGEX_STR.url),
|
100
|
+
ip: genRegex(REGEX_STR.ip),
|
101
|
+
color: genRegex(REGEX_STR.color),
|
102
|
+
chinese: genRegex(REGEX_STR.chinese)
|
103
|
+
};
|
104
|
+
/**
|
105
|
+
* Wheter is number
|
106
|
+
*
|
107
|
+
* 是否为数字
|
108
|
+
*/
|
109
|
+
function isNum(value) {
|
110
|
+
return REGEX.num.test(value.toString());
|
111
|
+
}
|
112
|
+
/**
|
113
|
+
* Wheter is integer
|
114
|
+
*
|
115
|
+
* 是否为整数
|
116
|
+
*/
|
117
|
+
function isInt(value) {
|
118
|
+
return isNum(value) && parseInt(value.toString(), 10).toString() === value.toString();
|
119
|
+
}
|
120
|
+
/**
|
121
|
+
* Wheter is decimal
|
122
|
+
*
|
123
|
+
* 是否为小数点数值
|
124
|
+
*/
|
125
|
+
function isDecimal(value) {
|
126
|
+
return isNum(value) && !isInt(value);
|
127
|
+
}
|
128
|
+
/**
|
129
|
+
* Wheter is People's Republic of China identity card
|
130
|
+
*
|
131
|
+
* 是否为中华人民共和国居民身份证
|
132
|
+
*/
|
133
|
+
function isIdCard(value) {
|
134
|
+
return REGEX.idCard.test(value);
|
135
|
+
}
|
136
|
+
/**
|
137
|
+
* Wheter is china mobile (China)
|
138
|
+
*
|
139
|
+
* 是否为手机号(中国)
|
140
|
+
*/
|
141
|
+
function isMobile(value) {
|
142
|
+
return REGEX.mobile.test(value);
|
143
|
+
}
|
144
|
+
/**
|
145
|
+
* Wheter is url address
|
146
|
+
*
|
147
|
+
* 是否URL地址
|
148
|
+
*/
|
149
|
+
function isUrl(url) {
|
150
|
+
return REGEX.url.test(url);
|
151
|
+
}
|
152
|
+
/**
|
153
|
+
* Wheter is IPv4 address (Support v4, v6)
|
154
|
+
*
|
155
|
+
* 是否IP4地址(支持v4、v6)
|
156
|
+
*/
|
157
|
+
function isIp(ip) {
|
158
|
+
return REGEX.ip.test(ip);
|
159
|
+
}
|
160
|
+
/**
|
161
|
+
* Wheter is color
|
162
|
+
*
|
163
|
+
* 是否颜色代码值
|
164
|
+
*/
|
165
|
+
function isColor(color) {
|
166
|
+
return REGEX.color.test(color);
|
167
|
+
}
|
168
|
+
/**
|
169
|
+
* Wheter is chinese
|
170
|
+
*
|
171
|
+
* 是否中文
|
172
|
+
*/
|
173
|
+
function isChinese(value) {
|
174
|
+
return REGEX.chinese.test(value);
|
175
175
|
}
|
176
176
|
|
177
|
-
const CurrencyMega_Powers = [
|
178
|
-
{ unit: 'Q', value: Math.pow(10, 15) },
|
179
|
-
{ unit: 'T', value: Math.pow(10, 12) },
|
180
|
-
{ unit: 'B', value: Math.pow(10, 9) },
|
181
|
-
{ unit: 'M', value: Math.pow(10, 6) },
|
182
|
-
{ unit: 'K', value: 1000 }
|
177
|
+
const CurrencyMega_Powers = [
|
178
|
+
{ unit: 'Q', value: Math.pow(10, 15) },
|
179
|
+
{ unit: 'T', value: Math.pow(10, 12) },
|
180
|
+
{ unit: 'B', value: Math.pow(10, 9) },
|
181
|
+
{ unit: 'M', value: Math.pow(10, 6) },
|
182
|
+
{ unit: 'K', value: 1000 }
|
183
183
|
];
|
184
184
|
|
185
|
-
class CurrencyService {
|
186
|
-
constructor(cog, locale, _defaultCurrencyCode = 'USD') {
|
187
|
-
this.locale = locale;
|
188
|
-
this.currencyPipe = new CurrencyPipe(locale, _defaultCurrencyCode);
|
189
|
-
this.c = cog.merge('utilCurrency', {
|
190
|
-
startingUnit: 'yuan',
|
191
|
-
megaUnit: { Q: '京', T: '兆', B: '亿', M: '万', K: '千' },
|
192
|
-
precision: 2,
|
193
|
-
ignoreZeroPrecision: true
|
194
|
-
});
|
195
|
-
}
|
196
|
-
/**
|
197
|
-
* Format a number with commas as thousands separators
|
198
|
-
*
|
199
|
-
* 格式化货币,用逗号将数字格式化为千位分隔符
|
200
|
-
* ```ts
|
201
|
-
* 10000 => `10,000`
|
202
|
-
* 10000.567 => `10,000.57`
|
203
|
-
* ```
|
204
|
-
*/
|
205
|
-
format(value, options) {
|
206
|
-
options = Object.assign({ startingUnit: this.c.startingUnit, precision: this.c.precision, ignoreZeroPrecision: this.c.ignoreZeroPrecision, ngCurrency: this.c.ngCurrency }, options);
|
207
|
-
let truthValue = Number(value);
|
208
|
-
if (value == null || isNaN(truthValue)) {
|
209
|
-
return '';
|
210
|
-
}
|
211
|
-
if (options.startingUnit === 'cent') {
|
212
|
-
truthValue = truthValue / 100;
|
213
|
-
}
|
214
|
-
if (options.ngCurrency != null) {
|
215
|
-
const cur = options.ngCurrency;
|
216
|
-
return this.currencyPipe.transform(truthValue, cur.currencyCode, cur.display, cur.digitsInfo, cur.locale || this.locale);
|
217
|
-
}
|
218
|
-
const res = formatNumber(truthValue, this.locale, `.${options.ignoreZeroPrecision ? 1 : options.precision}-${options.precision}`);
|
219
|
-
return options.ignoreZeroPrecision ? res.replace(/(?:\.[0]+)$/g, '') : res;
|
220
|
-
}
|
221
|
-
/**
|
222
|
-
* Large number format filter
|
223
|
-
*
|
224
|
-
* 大数据格式化
|
225
|
-
* ```ts
|
226
|
-
* 1000 => { value: '1', unit: 'K', unitI18n: '千' }
|
227
|
-
* 12456 => { value: '12.46', unit: 'K', unitI18n: '千' }
|
228
|
-
* ```
|
229
|
-
*/
|
230
|
-
mega(value, options) {
|
231
|
-
options = Object.assign({ precision: this.c.precision, unitI18n: this.c.megaUnit, startingUnit: this.c.startingUnit }, options);
|
232
|
-
let num = Number(value);
|
233
|
-
const res = { raw: value, value: '', unit: '', unitI18n: '' };
|
234
|
-
if (isNaN(num) || num === 0) {
|
235
|
-
res.value = value.toString();
|
236
|
-
return res;
|
237
|
-
}
|
238
|
-
if (options.startingUnit === 'cent') {
|
239
|
-
num = num / 100;
|
240
|
-
}
|
241
|
-
let abs = Math.abs(+num);
|
242
|
-
const rounder = Math.pow(10, options.precision);
|
243
|
-
const isNegative = num < 0;
|
244
|
-
for (const p of CurrencyMega_Powers) {
|
245
|
-
let reduced = abs / p.value;
|
246
|
-
reduced = Math.round(reduced * rounder) / rounder;
|
247
|
-
if (reduced >= 1) {
|
248
|
-
abs = reduced;
|
249
|
-
res.unit = p.unit;
|
250
|
-
break;
|
251
|
-
}
|
252
|
-
}
|
253
|
-
res.value = (isNegative ? '-' : '') + abs;
|
254
|
-
res.unitI18n = options.unitI18n[res.unit];
|
255
|
-
return res;
|
256
|
-
}
|
257
|
-
/**
|
258
|
-
* Converted into RMB notation.
|
259
|
-
*
|
260
|
-
* 转化成人民币表示法
|
261
|
-
*/
|
262
|
-
cny(value, options) {
|
263
|
-
options = Object.assign({ inWords: true, minusSymbol: '负', startingUnit: this.c.startingUnit }, options);
|
264
|
-
value = Number(value);
|
265
|
-
if (isNaN(value)) {
|
266
|
-
return '';
|
267
|
-
}
|
268
|
-
if (options.startingUnit === 'cent') {
|
269
|
-
value = value / 100;
|
270
|
-
}
|
271
|
-
value = value.toString();
|
272
|
-
let integer;
|
273
|
-
let decimal;
|
274
|
-
[integer, decimal] = value.split('.');
|
275
|
-
let symbol = '';
|
276
|
-
if (integer.startsWith('-')) {
|
277
|
-
symbol = options.minusSymbol;
|
278
|
-
integer = integer.substr(1);
|
279
|
-
}
|
280
|
-
if (/^-?\d+$/.test(value)) {
|
281
|
-
decimal = null;
|
282
|
-
}
|
283
|
-
integer = (+integer).toString();
|
284
|
-
const inWords = options.inWords;
|
285
|
-
const unit = {
|
286
|
-
num: inWords
|
287
|
-
? ['', '壹', '贰', '叁', '肆', '伍', '陆', '柒', '捌', '玖', '点']
|
288
|
-
: ['', '一', '二', '三', '四', '五', '六', '七', '八', '九', '点'],
|
289
|
-
radice: inWords
|
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
|
-
'百',
|
316
|
-
'千',
|
317
|
-
'万',
|
318
|
-
'十',
|
319
|
-
'百',
|
320
|
-
'千',
|
321
|
-
'亿',
|
322
|
-
'十',
|
323
|
-
'百',
|
324
|
-
'千',
|
325
|
-
'万亿',
|
326
|
-
'十',
|
327
|
-
'百',
|
328
|
-
'千',
|
329
|
-
'兆',
|
330
|
-
'十',
|
331
|
-
'百',
|
332
|
-
'千'
|
333
|
-
],
|
334
|
-
dec: ['角', '分', '厘', '毫']
|
335
|
-
};
|
336
|
-
if (inWords) {
|
337
|
-
value = (+value).toFixed(5).toString();
|
338
|
-
}
|
339
|
-
let integerRes = '';
|
340
|
-
const integerCount = integer.length;
|
341
|
-
if (integer === '0' || integerCount === 0) {
|
342
|
-
integerRes = '零';
|
343
|
-
}
|
344
|
-
else {
|
345
|
-
let cnDesc = '';
|
346
|
-
for (let i = 0; i < integerCount; i++) {
|
347
|
-
const n = +integer[i];
|
348
|
-
const j = integerCount - i - 1;
|
349
|
-
const isZero = i > 1 && n !== 0 && integer[i - 1] === '0';
|
350
|
-
const cnZero = isZero ? '零' : '';
|
351
|
-
const isEmpptyUnit = (n === 0 && j % 4 !== 0) || integer.substr(i - 3, 4) === '0000';
|
352
|
-
const descMark = cnDesc;
|
353
|
-
let cnNum = unit.num[n];
|
354
|
-
cnDesc = isEmpptyUnit ? '' : unit.radice[j];
|
355
|
-
// 第一位是一十
|
356
|
-
if (i === 0 && cnNum === '一' && cnDesc === '十')
|
357
|
-
cnNum = '';
|
358
|
-
const isChangeEr = n > 1 &&
|
359
|
-
cnNum === '二' && // 去除首位
|
360
|
-
['', '十', '百'].indexOf(cnDesc) === -1 && // 不读两\两十\两百
|
361
|
-
descMark !== '十'; // 不读十两
|
362
|
-
if (isChangeEr)
|
363
|
-
cnNum = '两';
|
364
|
-
integerRes += cnZero + cnNum + cnDesc;
|
365
|
-
}
|
366
|
-
}
|
367
|
-
// 小数部分拼接
|
368
|
-
let decimalRes = '';
|
369
|
-
const decimalCount = decimal ? decimal.toString().length : 0;
|
370
|
-
if (decimal === null) {
|
371
|
-
decimalRes = inWords ? '整' : '';
|
372
|
-
}
|
373
|
-
else if (decimal === '0') {
|
374
|
-
decimalRes = '零';
|
375
|
-
}
|
376
|
-
else {
|
377
|
-
for (let i = 0; i < decimalCount; i++) {
|
378
|
-
if (inWords && i > unit.dec.length - 1)
|
379
|
-
break;
|
380
|
-
const n = decimal[i];
|
381
|
-
const cnZero = n === '0' ? '零' : '';
|
382
|
-
const cnNum = unit.num[+n];
|
383
|
-
const cnDesc = inWords ? unit.dec[i] : '';
|
384
|
-
decimalRes += cnZero + cnNum + cnDesc;
|
385
|
-
}
|
386
|
-
}
|
387
|
-
const ret = symbol +
|
388
|
-
(inWords
|
389
|
-
? integerRes + (decimalRes === '零' ? '元整' : `元${decimalRes}`)
|
390
|
-
: integerRes + (decimalRes === '' ? '' : `点${decimalRes}`));
|
391
|
-
return ret;
|
392
|
-
}
|
393
|
-
}
|
394
|
-
CurrencyService.ɵprov = i0.ɵɵdefineInjectable({ factory: function CurrencyService_Factory() { return new CurrencyService(i0.ɵɵinject(i1.YunzaiConfigService), i0.ɵɵinject(i0.LOCALE_ID), i0.ɵɵinject(i0.DEFAULT_CURRENCY_CODE)); }, token: CurrencyService, providedIn: "root" });
|
395
|
-
CurrencyService.decorators = [
|
396
|
-
{ type: Injectable, args: [{ providedIn: 'root' },] }
|
397
|
-
];
|
398
|
-
CurrencyService.ctorParameters = () => [
|
399
|
-
{ type: YunzaiConfigService },
|
400
|
-
{ type: String, decorators: [{ type: Inject, args: [LOCALE_ID,] }] },
|
401
|
-
{ type: String, decorators: [{ type: Inject, args: [DEFAULT_CURRENCY_CODE,] }] }
|
185
|
+
class CurrencyService {
|
186
|
+
constructor(cog, locale, _defaultCurrencyCode = 'USD') {
|
187
|
+
this.locale = locale;
|
188
|
+
this.currencyPipe = new CurrencyPipe(locale, _defaultCurrencyCode);
|
189
|
+
this.c = cog.merge('utilCurrency', {
|
190
|
+
startingUnit: 'yuan',
|
191
|
+
megaUnit: { Q: '京', T: '兆', B: '亿', M: '万', K: '千' },
|
192
|
+
precision: 2,
|
193
|
+
ignoreZeroPrecision: true
|
194
|
+
});
|
195
|
+
}
|
196
|
+
/**
|
197
|
+
* Format a number with commas as thousands separators
|
198
|
+
*
|
199
|
+
* 格式化货币,用逗号将数字格式化为千位分隔符
|
200
|
+
* ```ts
|
201
|
+
* 10000 => `10,000`
|
202
|
+
* 10000.567 => `10,000.57`
|
203
|
+
* ```
|
204
|
+
*/
|
205
|
+
format(value, options) {
|
206
|
+
options = Object.assign({ startingUnit: this.c.startingUnit, precision: this.c.precision, ignoreZeroPrecision: this.c.ignoreZeroPrecision, ngCurrency: this.c.ngCurrency }, options);
|
207
|
+
let truthValue = Number(value);
|
208
|
+
if (value == null || isNaN(truthValue)) {
|
209
|
+
return '';
|
210
|
+
}
|
211
|
+
if (options.startingUnit === 'cent') {
|
212
|
+
truthValue = truthValue / 100;
|
213
|
+
}
|
214
|
+
if (options.ngCurrency != null) {
|
215
|
+
const cur = options.ngCurrency;
|
216
|
+
return this.currencyPipe.transform(truthValue, cur.currencyCode, cur.display, cur.digitsInfo, cur.locale || this.locale);
|
217
|
+
}
|
218
|
+
const res = formatNumber(truthValue, this.locale, `.${options.ignoreZeroPrecision ? 1 : options.precision}-${options.precision}`);
|
219
|
+
return options.ignoreZeroPrecision ? res.replace(/(?:\.[0]+)$/g, '') : res;
|
220
|
+
}
|
221
|
+
/**
|
222
|
+
* Large number format filter
|
223
|
+
*
|
224
|
+
* 大数据格式化
|
225
|
+
* ```ts
|
226
|
+
* 1000 => { value: '1', unit: 'K', unitI18n: '千' }
|
227
|
+
* 12456 => { value: '12.46', unit: 'K', unitI18n: '千' }
|
228
|
+
* ```
|
229
|
+
*/
|
230
|
+
mega(value, options) {
|
231
|
+
options = Object.assign({ precision: this.c.precision, unitI18n: this.c.megaUnit, startingUnit: this.c.startingUnit }, options);
|
232
|
+
let num = Number(value);
|
233
|
+
const res = { raw: value, value: '', unit: '', unitI18n: '' };
|
234
|
+
if (isNaN(num) || num === 0) {
|
235
|
+
res.value = value.toString();
|
236
|
+
return res;
|
237
|
+
}
|
238
|
+
if (options.startingUnit === 'cent') {
|
239
|
+
num = num / 100;
|
240
|
+
}
|
241
|
+
let abs = Math.abs(+num);
|
242
|
+
const rounder = Math.pow(10, options.precision);
|
243
|
+
const isNegative = num < 0;
|
244
|
+
for (const p of CurrencyMega_Powers) {
|
245
|
+
let reduced = abs / p.value;
|
246
|
+
reduced = Math.round(reduced * rounder) / rounder;
|
247
|
+
if (reduced >= 1) {
|
248
|
+
abs = reduced;
|
249
|
+
res.unit = p.unit;
|
250
|
+
break;
|
251
|
+
}
|
252
|
+
}
|
253
|
+
res.value = (isNegative ? '-' : '') + abs;
|
254
|
+
res.unitI18n = options.unitI18n[res.unit];
|
255
|
+
return res;
|
256
|
+
}
|
257
|
+
/**
|
258
|
+
* Converted into RMB notation.
|
259
|
+
*
|
260
|
+
* 转化成人民币表示法
|
261
|
+
*/
|
262
|
+
cny(value, options) {
|
263
|
+
options = Object.assign({ inWords: true, minusSymbol: '负', startingUnit: this.c.startingUnit }, options);
|
264
|
+
value = Number(value);
|
265
|
+
if (isNaN(value)) {
|
266
|
+
return '';
|
267
|
+
}
|
268
|
+
if (options.startingUnit === 'cent') {
|
269
|
+
value = value / 100;
|
270
|
+
}
|
271
|
+
value = value.toString();
|
272
|
+
let integer;
|
273
|
+
let decimal;
|
274
|
+
[integer, decimal] = value.split('.');
|
275
|
+
let symbol = '';
|
276
|
+
if (integer.startsWith('-')) {
|
277
|
+
symbol = options.minusSymbol;
|
278
|
+
integer = integer.substr(1);
|
279
|
+
}
|
280
|
+
if (/^-?\d+$/.test(value)) {
|
281
|
+
decimal = null;
|
282
|
+
}
|
283
|
+
integer = (+integer).toString();
|
284
|
+
const inWords = options.inWords;
|
285
|
+
const unit = {
|
286
|
+
num: inWords
|
287
|
+
? ['', '壹', '贰', '叁', '肆', '伍', '陆', '柒', '捌', '玖', '点']
|
288
|
+
: ['', '一', '二', '三', '四', '五', '六', '七', '八', '九', '点'],
|
289
|
+
radice: inWords
|
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
|
+
'百',
|
316
|
+
'千',
|
317
|
+
'万',
|
318
|
+
'十',
|
319
|
+
'百',
|
320
|
+
'千',
|
321
|
+
'亿',
|
322
|
+
'十',
|
323
|
+
'百',
|
324
|
+
'千',
|
325
|
+
'万亿',
|
326
|
+
'十',
|
327
|
+
'百',
|
328
|
+
'千',
|
329
|
+
'兆',
|
330
|
+
'十',
|
331
|
+
'百',
|
332
|
+
'千'
|
333
|
+
],
|
334
|
+
dec: ['角', '分', '厘', '毫']
|
335
|
+
};
|
336
|
+
if (inWords) {
|
337
|
+
value = (+value).toFixed(5).toString();
|
338
|
+
}
|
339
|
+
let integerRes = '';
|
340
|
+
const integerCount = integer.length;
|
341
|
+
if (integer === '0' || integerCount === 0) {
|
342
|
+
integerRes = '零';
|
343
|
+
}
|
344
|
+
else {
|
345
|
+
let cnDesc = '';
|
346
|
+
for (let i = 0; i < integerCount; i++) {
|
347
|
+
const n = +integer[i];
|
348
|
+
const j = integerCount - i - 1;
|
349
|
+
const isZero = i > 1 && n !== 0 && integer[i - 1] === '0';
|
350
|
+
const cnZero = isZero ? '零' : '';
|
351
|
+
const isEmpptyUnit = (n === 0 && j % 4 !== 0) || integer.substr(i - 3, 4) === '0000';
|
352
|
+
const descMark = cnDesc;
|
353
|
+
let cnNum = unit.num[n];
|
354
|
+
cnDesc = isEmpptyUnit ? '' : unit.radice[j];
|
355
|
+
// 第一位是一十
|
356
|
+
if (i === 0 && cnNum === '一' && cnDesc === '十')
|
357
|
+
cnNum = '';
|
358
|
+
const isChangeEr = n > 1 &&
|
359
|
+
cnNum === '二' && // 去除首位
|
360
|
+
['', '十', '百'].indexOf(cnDesc) === -1 && // 不读两\两十\两百
|
361
|
+
descMark !== '十'; // 不读十两
|
362
|
+
if (isChangeEr)
|
363
|
+
cnNum = '两';
|
364
|
+
integerRes += cnZero + cnNum + cnDesc;
|
365
|
+
}
|
366
|
+
}
|
367
|
+
// 小数部分拼接
|
368
|
+
let decimalRes = '';
|
369
|
+
const decimalCount = decimal ? decimal.toString().length : 0;
|
370
|
+
if (decimal === null) {
|
371
|
+
decimalRes = inWords ? '整' : '';
|
372
|
+
}
|
373
|
+
else if (decimal === '0') {
|
374
|
+
decimalRes = '零';
|
375
|
+
}
|
376
|
+
else {
|
377
|
+
for (let i = 0; i < decimalCount; i++) {
|
378
|
+
if (inWords && i > unit.dec.length - 1)
|
379
|
+
break;
|
380
|
+
const n = decimal[i];
|
381
|
+
const cnZero = n === '0' ? '零' : '';
|
382
|
+
const cnNum = unit.num[+n];
|
383
|
+
const cnDesc = inWords ? unit.dec[i] : '';
|
384
|
+
decimalRes += cnZero + cnNum + cnDesc;
|
385
|
+
}
|
386
|
+
}
|
387
|
+
const ret = symbol +
|
388
|
+
(inWords
|
389
|
+
? integerRes + (decimalRes === '零' ? '元整' : `元${decimalRes}`)
|
390
|
+
: integerRes + (decimalRes === '' ? '' : `点${decimalRes}`));
|
391
|
+
return ret;
|
392
|
+
}
|
393
|
+
}
|
394
|
+
CurrencyService.ɵprov = i0.ɵɵdefineInjectable({ factory: function CurrencyService_Factory() { return new CurrencyService(i0.ɵɵinject(i1.YunzaiConfigService), i0.ɵɵinject(i0.LOCALE_ID), i0.ɵɵinject(i0.DEFAULT_CURRENCY_CODE)); }, token: CurrencyService, providedIn: "root" });
|
395
|
+
CurrencyService.decorators = [
|
396
|
+
{ type: Injectable, args: [{ providedIn: 'root' },] }
|
397
|
+
];
|
398
|
+
CurrencyService.ctorParameters = () => [
|
399
|
+
{ type: YunzaiConfigService },
|
400
|
+
{ type: String, decorators: [{ type: Inject, args: [LOCALE_ID,] }] },
|
401
|
+
{ type: String, decorators: [{ type: Inject, args: [DEFAULT_CURRENCY_CODE,] }] }
|
402
402
|
];
|
403
403
|
|
404
|
-
/**
|
405
|
-
* Generated bundle index. Do not edit.
|
404
|
+
/**
|
405
|
+
* Generated bundle index. Do not edit.
|
406
406
|
*/
|
407
407
|
|
408
408
|
export { CurrencyMega_Powers, CurrencyService, REGEX, REGEX_STR, format, formatMask, isChinese, isColor, isDecimal, isIdCard, isInt, isIp, isMobile, isNum, isUrl };
|