@yelon/util 15.2.0 → 15.2.1
Sign up to get free protection for your applications and to get access to all the features.
- package/LICENSE +21 -21
- package/README.md +22 -22
- package/array/array-type.service.d.ts +68 -68
- package/array/array.service.d.ts +78 -78
- package/array/index.d.ts +2 -2
- package/browser/cookie.service.d.ts +67 -67
- package/browser/copy.d.ts +6 -6
- package/browser/index.d.ts +5 -5
- package/browser/is-empty.d.ts +6 -6
- package/browser/scroll.service.d.ts +37 -37
- package/browser/style.d.ts +21 -21
- package/config/abc/date-picker.type.d.ts +52 -52
- package/config/abc/error-collect.type.d.ts +10 -10
- package/config/abc/exception.type.d.ts +9 -9
- package/config/abc/image.type.d.ts +15 -15
- package/config/abc/index.d.ts +17 -17
- package/config/abc/loading.type.d.ts +31 -31
- package/config/abc/lodop.type.d.ts +33 -33
- package/config/abc/media.type.d.ts +11 -11
- package/config/abc/onboarding.type.d.ts +4 -4
- package/config/abc/page-header.type.d.ts +39 -39
- package/config/abc/pdf.type.d.ts +35 -35
- package/config/abc/qr.type.d.ts +25 -25
- package/config/abc/se.type.d.ts +32 -32
- package/config/abc/sg.type.d.ts +10 -10
- package/config/abc/st.type.d.ts +465 -465
- package/config/abc/sv.type.d.ts +14 -14
- package/config/abc/xlsx.type.d.ts +12 -12
- package/config/abc/zip.type.d.ts +10 -10
- package/config/acl/acl.type.d.ts +32 -32
- package/config/auth/auth.type.d.ts +55 -55
- package/config/bis/bis.type.d.ts +7 -7
- package/config/cache/cache.type.d.ts +40 -40
- package/config/chart/chart.type.d.ts +33 -33
- package/config/config.service.d.ts +13 -13
- package/config/config.types.d.ts +48 -48
- package/config/index.d.ts +14 -14
- package/config/mock/mock.type.d.ts +18 -18
- package/config/sf/sf.type.d.ts +133 -133
- package/config/socket/socket.type.d.ts +4 -4
- package/config/theme/http.type.d.ts +14 -14
- package/config/theme/i18n.type.d.ts +14 -14
- package/config/theme/index.d.ts +3 -3
- package/config/theme/responsive.type.d.ts +12 -12
- package/config/util/array.type.d.ts +22 -22
- package/config/util/currency.type.d.ts +39 -39
- package/date-time/index.d.ts +2 -2
- package/date-time/picker.d.ts +68 -68
- package/date-time/time.d.ts +29 -29
- package/decorator/convert.d.ts +24 -24
- package/decorator/index.d.ts +2 -2
- package/decorator/zone-outside.d.ts +35 -35
- package/esm2020/array/array-type.service.mjs +1 -1
- package/esm2020/array/array.mjs +4 -4
- package/esm2020/array/array.service.mjs +276 -276
- package/esm2020/array/index.mjs +2 -2
- package/esm2020/browser/browser.mjs +4 -4
- package/esm2020/browser/cookie.service.mjs +102 -102
- package/esm2020/browser/copy.mjs +27 -27
- package/esm2020/browser/index.mjs +5 -5
- package/esm2020/browser/is-empty.mjs +18 -18
- package/esm2020/browser/scroll.service.mjs +87 -87
- package/esm2020/browser/style.mjs +37 -37
- package/esm2020/config/abc/date-picker.type.mjs +1 -1
- package/esm2020/config/abc/error-collect.type.mjs +1 -1
- package/esm2020/config/abc/exception.type.mjs +1 -1
- package/esm2020/config/abc/image.type.mjs +1 -1
- package/esm2020/config/abc/index.mjs +17 -17
- package/esm2020/config/abc/loading.type.mjs +1 -1
- package/esm2020/config/abc/lodop.type.mjs +1 -1
- package/esm2020/config/abc/media.type.mjs +1 -1
- package/esm2020/config/abc/onboarding.type.mjs +1 -1
- package/esm2020/config/abc/page-header.type.mjs +1 -1
- package/esm2020/config/abc/pdf.type.mjs +1 -1
- package/esm2020/config/abc/qr.type.mjs +1 -1
- package/esm2020/config/abc/se.type.mjs +1 -1
- package/esm2020/config/abc/sg.type.mjs +1 -1
- package/esm2020/config/abc/st.type.mjs +1 -1
- package/esm2020/config/abc/sv.type.mjs +2 -2
- package/esm2020/config/abc/xlsx.type.mjs +1 -1
- package/esm2020/config/abc/zip.type.mjs +1 -1
- package/esm2020/config/acl/acl.type.mjs +1 -1
- package/esm2020/config/auth/auth.type.mjs +1 -1
- package/esm2020/config/bis/bis.type.mjs +1 -1
- package/esm2020/config/cache/cache.type.mjs +1 -1
- package/esm2020/config/chart/chart.type.mjs +1 -1
- package/esm2020/config/config.mjs +4 -4
- package/esm2020/config/config.service.mjs +36 -36
- package/esm2020/config/config.types.mjs +8 -8
- package/esm2020/config/index.mjs +14 -14
- package/esm2020/config/mock/mock.type.mjs +1 -1
- package/esm2020/config/sf/sf.type.mjs +1 -1
- package/esm2020/config/socket/socket.type.mjs +1 -1
- package/esm2020/config/theme/http.type.mjs +1 -1
- package/esm2020/config/theme/i18n.type.mjs +1 -1
- package/esm2020/config/theme/index.mjs +3 -3
- package/esm2020/config/theme/responsive.type.mjs +1 -1
- package/esm2020/config/util/array.type.mjs +1 -1
- package/esm2020/config/util/currency.type.mjs +1 -1
- package/esm2020/date-time/date-time.mjs +4 -4
- package/esm2020/date-time/index.mjs +2 -2
- package/esm2020/date-time/picker.mjs +115 -115
- package/esm2020/date-time/time.mjs +88 -88
- package/esm2020/decorator/convert.mjs +57 -57
- package/esm2020/decorator/decorator.mjs +4 -4
- package/esm2020/decorator/index.mjs +2 -2
- package/esm2020/decorator/zone-outside.mjs +56 -56
- package/esm2020/form/form.mjs +4 -4
- package/esm2020/form/index.mjs +2 -2
- package/esm2020/form/match-control.mjs +29 -29
- package/esm2020/form/validators.mjs +80 -80
- package/esm2020/format/currency.service.mjs +237 -237
- package/esm2020/format/currency.types.mjs +7 -7
- package/esm2020/format/format.mjs +4 -4
- package/esm2020/format/index.mjs +4 -4
- package/esm2020/format/string.mjs +84 -84
- package/esm2020/format/validate.mjs +93 -93
- package/esm2020/index.mjs +11 -11
- package/esm2020/math/in-range.mjs +24 -24
- package/esm2020/math/index.mjs +2 -2
- package/esm2020/math/math.mjs +4 -4
- package/esm2020/math/round.mjs +52 -52
- package/esm2020/other/assert.mjs +66 -66
- package/esm2020/other/deep.mjs +77 -77
- package/esm2020/other/favicon.mjs +28 -28
- package/esm2020/other/index.mjs +7 -7
- package/esm2020/other/lazy.service.mjs +131 -131
- package/esm2020/other/logger.mjs +32 -32
- package/esm2020/other/other.mjs +4 -4
- package/esm2020/other/path-to-regexp.service.mjs +238 -238
- package/esm2020/other/resize.mjs +3 -3
- package/esm2020/pipes/currency/cny.pipe.mjs +22 -22
- package/esm2020/pipes/currency/index.mjs +4 -4
- package/esm2020/pipes/currency/mega.pipe.mjs +28 -28
- package/esm2020/pipes/currency/module.mjs +18 -18
- package/esm2020/pipes/currency/pipe-currency.mjs +4 -4
- package/esm2020/pipes/currency/price.pipe.mjs +26 -26
- package/esm2020/pipes/filter/filter.pipe.mjs +18 -18
- package/esm2020/pipes/filter/index.mjs +2 -2
- package/esm2020/pipes/filter/module.mjs +16 -16
- package/esm2020/pipes/filter/pipe-filter.mjs +4 -4
- package/esm2020/pipes/format/index.mjs +2 -2
- package/esm2020/pipes/format/mask.pipe.mjs +33 -33
- package/esm2020/pipes/format/module.mjs +16 -16
- package/esm2020/pipes/format/pipe-format.mjs +4 -4
- package/esm2020/pipes/index.mjs +3 -3
- package/esm2020/pipes/pipes.mjs +4 -4
- package/esm2020/token/index.mjs +2 -2
- package/esm2020/token/page-visibility.mjs +14 -14
- package/esm2020/token/token.mjs +4 -4
- package/esm2020/token/window.mjs +16 -16
- package/esm2020/yelon-util.mjs +4 -4
- package/fesm2015/array.mjs +254 -254
- package/fesm2015/browser.mjs +283 -283
- package/fesm2015/config.mjs +56 -56
- package/fesm2015/date-time.mjs +207 -207
- package/fesm2015/decorator.mjs +121 -121
- package/fesm2015/form.mjs +118 -118
- package/fesm2015/format.mjs +413 -413
- package/fesm2015/math.mjs +85 -85
- package/fesm2015/other.mjs +589 -589
- package/fesm2015/pipe-currency.mjs +96 -96
- package/fesm2015/pipe-filter.mjs +40 -40
- package/fesm2015/pipe-format.mjs +55 -55
- package/fesm2015/pipes.mjs +8 -8
- package/fesm2015/token.mjs +37 -37
- package/fesm2015/yelon-util.mjs +16 -16
- package/fesm2020/array.mjs +284 -284
- package/fesm2020/browser.mjs +279 -279
- package/fesm2020/config.mjs +54 -54
- package/fesm2020/date-time.mjs +211 -211
- package/fesm2020/decorator.mjs +121 -121
- package/fesm2020/form.mjs +118 -118
- package/fesm2020/format.mjs +431 -431
- package/fesm2020/math.mjs +85 -85
- package/fesm2020/other.mjs +586 -586
- package/fesm2020/pipe-currency.mjs +94 -94
- package/fesm2020/pipe-filter.mjs +40 -40
- package/fesm2020/pipe-format.mjs +55 -55
- package/fesm2020/pipes.mjs +8 -8
- package/fesm2020/token.mjs +37 -37
- package/fesm2020/yelon-util.mjs +16 -16
- package/form/index.d.ts +2 -2
- package/form/match-control.d.ts +15 -15
- package/form/validators.d.ts +62 -62
- package/format/currency.service.d.ts +37 -37
- package/format/currency.types.d.ts +77 -77
- package/format/index.d.ts +4 -4
- package/format/string.d.ts +44 -44
- package/format/validate.d.ts +72 -72
- package/index.d.ts +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/other/assert.d.ts +36 -36
- package/other/deep.d.ts +35 -35
- package/other/favicon.d.ts +2 -2
- package/other/index.d.ts +7 -7
- package/other/lazy.service.d.ts +48 -48
- package/other/logger.d.ts +5 -5
- package/other/path-to-regexp.service.d.ts +26 -26
- package/other/resize.d.ts +1 -1
- package/package.json +157 -157
- package/pipes/currency/cny.pipe.d.ts +15 -15
- package/pipes/currency/index.d.ts +4 -4
- package/pipes/currency/mega.pipe.d.ts +16 -16
- package/pipes/currency/module.d.ts +9 -9
- package/pipes/currency/price.pipe.d.ts +19 -19
- package/pipes/filter/filter.pipe.d.ts +13 -13
- package/pipes/filter/index.d.ts +2 -2
- package/pipes/filter/module.d.ts +7 -7
- package/pipes/format/index.d.ts +2 -2
- package/pipes/format/mask.pipe.d.ts +27 -27
- package/pipes/format/module.d.ts +7 -7
- package/pipes/index.d.ts +3 -3
- package/token/index.d.ts +2 -2
- package/token/page-visibility.d.ts +8 -8
- package/token/window.d.ts +7 -7
@@ -1,85 +1,85 @@
|
|
1
|
-
import { deepGet } from '@yelon/util/other';
|
2
|
-
/**
|
3
|
-
* String formatting
|
4
|
-
*
|
5
|
-
* 字符串格式化
|
6
|
-
* ```
|
7
|
-
* format('this is ${name}', { name: 'asdf' })
|
8
|
-
* // output: this is asdf
|
9
|
-
* format('this is ${user.name}', { user: { name: 'asdf' } }, true)
|
10
|
-
* // output: this is asdf
|
11
|
-
* ```
|
12
|
-
*/
|
13
|
-
export function format(str, obj, needDeepGet = false) {
|
14
|
-
return (str || '').replace(/\${([^}]+)}/g, (_work, key) => needDeepGet ? deepGet(obj, key.split('.'), '') : (obj || {})[key] || '');
|
15
|
-
}
|
16
|
-
/**
|
17
|
-
* Format mask
|
18
|
-
*
|
19
|
-
* 格式化掩码
|
20
|
-
*
|
21
|
-
* | 字符 | 描述 |
|
22
|
-
* | --- | --- |
|
23
|
-
* | `0` | 任意数字,若该位置字符不符合,则默认为 `0` 填充 |
|
24
|
-
* | `9` | 任意数字 |
|
25
|
-
* | `#` | 任意字符 |
|
26
|
-
* | `U` | 转换大写 |
|
27
|
-
* | `L` | 转换小写 |
|
28
|
-
* | `*` | 转换为 `*` 字符 |
|
29
|
-
*
|
30
|
-
* ```ts
|
31
|
-
* formatMask('123', '(###)') => (123)
|
32
|
-
* formatMask('15900000000', '999****9999') => 159****0000
|
33
|
-
* ```
|
34
|
-
*/
|
35
|
-
export function formatMask(value, option) {
|
36
|
-
if (!value) {
|
37
|
-
return '';
|
38
|
-
}
|
39
|
-
const opt = {
|
40
|
-
...(typeof option === 'string' ? { mask: option } : option)
|
41
|
-
};
|
42
|
-
const tokens = {
|
43
|
-
'0': { pattern: /\d/, default: '0' },
|
44
|
-
'9': { pattern: /\d/ },
|
45
|
-
'#': { pattern: /[a-zA-Z0-9]/ },
|
46
|
-
U: {
|
47
|
-
pattern: /[a-zA-Z]/,
|
48
|
-
transform: char => char.toLocaleUpperCase()
|
49
|
-
},
|
50
|
-
L: {
|
51
|
-
pattern: /[a-zA-Z]/,
|
52
|
-
transform: char => char.toLocaleLowerCase()
|
53
|
-
},
|
54
|
-
'*': {
|
55
|
-
pattern: /.*/,
|
56
|
-
transform: _ => `*`
|
57
|
-
},
|
58
|
-
...opt.tokens
|
59
|
-
};
|
60
|
-
const splitValue = value.split('');
|
61
|
-
return opt.mask
|
62
|
-
.split('')
|
63
|
-
.reduce((res, cur) => {
|
64
|
-
const token = tokens[cur];
|
65
|
-
if (!token) {
|
66
|
-
res.push(cur);
|
67
|
-
return res;
|
68
|
-
}
|
69
|
-
const value = splitValue.shift() ?? '';
|
70
|
-
if (!token.pattern.test(value)) {
|
71
|
-
if (token.default)
|
72
|
-
res.push(token.default);
|
73
|
-
return res;
|
74
|
-
}
|
75
|
-
if (typeof token.transform === 'function') {
|
76
|
-
res.push(token.transform(value));
|
77
|
-
}
|
78
|
-
else {
|
79
|
-
res.push(value);
|
80
|
-
}
|
81
|
-
return res;
|
82
|
-
}, [])
|
83
|
-
.join('');
|
84
|
-
}
|
1
|
+
import { deepGet } from '@yelon/util/other';
|
2
|
+
/**
|
3
|
+
* String formatting
|
4
|
+
*
|
5
|
+
* 字符串格式化
|
6
|
+
* ```
|
7
|
+
* format('this is ${name}', { name: 'asdf' })
|
8
|
+
* // output: this is asdf
|
9
|
+
* format('this is ${user.name}', { user: { name: 'asdf' } }, true)
|
10
|
+
* // output: this is asdf
|
11
|
+
* ```
|
12
|
+
*/
|
13
|
+
export function format(str, obj, needDeepGet = false) {
|
14
|
+
return (str || '').replace(/\${([^}]+)}/g, (_work, key) => needDeepGet ? deepGet(obj, key.split('.'), '') : (obj || {})[key] || '');
|
15
|
+
}
|
16
|
+
/**
|
17
|
+
* Format mask
|
18
|
+
*
|
19
|
+
* 格式化掩码
|
20
|
+
*
|
21
|
+
* | 字符 | 描述 |
|
22
|
+
* | --- | --- |
|
23
|
+
* | `0` | 任意数字,若该位置字符不符合,则默认为 `0` 填充 |
|
24
|
+
* | `9` | 任意数字 |
|
25
|
+
* | `#` | 任意字符 |
|
26
|
+
* | `U` | 转换大写 |
|
27
|
+
* | `L` | 转换小写 |
|
28
|
+
* | `*` | 转换为 `*` 字符 |
|
29
|
+
*
|
30
|
+
* ```ts
|
31
|
+
* formatMask('123', '(###)') => (123)
|
32
|
+
* formatMask('15900000000', '999****9999') => 159****0000
|
33
|
+
* ```
|
34
|
+
*/
|
35
|
+
export function formatMask(value, option) {
|
36
|
+
if (!value) {
|
37
|
+
return '';
|
38
|
+
}
|
39
|
+
const opt = {
|
40
|
+
...(typeof option === 'string' ? { mask: option } : option)
|
41
|
+
};
|
42
|
+
const tokens = {
|
43
|
+
'0': { pattern: /\d/, default: '0' },
|
44
|
+
'9': { pattern: /\d/ },
|
45
|
+
'#': { pattern: /[a-zA-Z0-9]/ },
|
46
|
+
U: {
|
47
|
+
pattern: /[a-zA-Z]/,
|
48
|
+
transform: char => char.toLocaleUpperCase()
|
49
|
+
},
|
50
|
+
L: {
|
51
|
+
pattern: /[a-zA-Z]/,
|
52
|
+
transform: char => char.toLocaleLowerCase()
|
53
|
+
},
|
54
|
+
'*': {
|
55
|
+
pattern: /.*/,
|
56
|
+
transform: _ => `*`
|
57
|
+
},
|
58
|
+
...opt.tokens
|
59
|
+
};
|
60
|
+
const splitValue = value.split('');
|
61
|
+
return opt.mask
|
62
|
+
.split('')
|
63
|
+
.reduce((res, cur) => {
|
64
|
+
const token = tokens[cur];
|
65
|
+
if (!token) {
|
66
|
+
res.push(cur);
|
67
|
+
return res;
|
68
|
+
}
|
69
|
+
const value = splitValue.shift() ?? '';
|
70
|
+
if (!token.pattern.test(value)) {
|
71
|
+
if (token.default)
|
72
|
+
res.push(token.default);
|
73
|
+
return res;
|
74
|
+
}
|
75
|
+
if (typeof token.transform === 'function') {
|
76
|
+
res.push(token.transform(value));
|
77
|
+
}
|
78
|
+
else {
|
79
|
+
res.push(value);
|
80
|
+
}
|
81
|
+
return res;
|
82
|
+
}, [])
|
83
|
+
.join('');
|
84
|
+
}
|
85
85
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic3RyaW5nLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vL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4uLm9wdC50b2tlbnNcbiAgfTtcblxuICBjb25zdCBzcGxpdFZhbHVlID0gdmFsdWUuc3BsaXQoJycpO1xuICByZXR1cm4gb3B0Lm1hc2tcbiAgICAuc3BsaXQoJycpXG4gICAgLnJlZHVjZSgocmVzLCBjdXIpID0+IHtcbiAgICAgIGNvbnN0IHRva2VuID0gdG9rZW5zW2N1cl07XG4gICAgICBpZiAoIXRva2VuKSB7XG4gICAgICAgIHJlcy5wdXNoKGN1cik7XG4gICAgICAgIHJldHVybiByZXM7XG4gICAgICB9XG5cbiAgICAgIGNvbnN0IHZhbHVlID0gc3BsaXRWYWx1ZS5zaGlmdCgpID8/ICcnO1xuICAgICAgaWYgKCF0b2tlbi5wYXR0ZXJuLnRlc3QodmFsdWUpKSB7XG4gICAgICAgIGlmICh0b2tlbi5kZWZhdWx0KSByZXMucHVzaCh0b2tlbi5kZWZhdWx0KTtcbiAgICAgICAgcmV0dXJuIHJlcztcbiAgICAgIH1cblxuICAgICAgaWYgKHR5cGVvZiB0b2tlbi50cmFuc2Zvcm0gPT09ICdmdW5jdGlvbicpIHtcbiAgICAgICAgcmVzLnB1c2godG9rZW4udHJhbnNmb3JtKHZhbHVlKSk7XG4gICAgICB9IGVsc2Uge1xuICAgICAgICByZXMucHVzaCh2YWx1ZSk7XG4gICAgICB9XG4gICAgICByZXR1cm4gcmVzO1xuICAgIH0sIFtdIGFzIHN0cmluZ1tdKVxuICAgIC5qb2luKCcnKTtcbn1cbiJdfQ==
|
@@ -1,94 +1,94 @@
|
|
1
|
-
export const REGEX_STR = {
|
2
|
-
num: `(([-+]?\\d+\\.\\d+)|([-+]?\\d+)|([-+]?\\.\\d+))(?:[eE]([-+]?\\d+))?`,
|
3
|
-
idCard: `(^\\d{15}$)|(^\\d{17}(?:[0-9]|X)$)`,
|
4
|
-
mobile: `^(0|\\+?86|17951)?1[0-9]{10}$`,
|
5
|
-
url: `(((^https?:(?:\/\/)?)(?:[-;:&=\\+\\$,\\w]+@)?[A-Za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[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,})?$)`,
|
7
|
-
color: `(?:#|0x)(?:[a-f0-9]{3}|[a-f0-9]{6})\\b|(?:rgb|hsl)a?\\([^\\)]*\\)`,
|
8
|
-
chinese: `[\u4e00-\u9fa5]+`
|
9
|
-
};
|
10
|
-
function genRegex(str, flags) {
|
11
|
-
return new RegExp(`^${str}$`, flags);
|
12
|
-
}
|
13
|
-
export const REGEX = {
|
14
|
-
num: genRegex(REGEX_STR.num),
|
15
|
-
idCard: genRegex(REGEX_STR.idCard, 'i'),
|
16
|
-
mobile: genRegex(REGEX_STR.mobile),
|
17
|
-
url: genRegex(REGEX_STR.url),
|
18
|
-
ip: genRegex(REGEX_STR.ip),
|
19
|
-
color: genRegex(REGEX_STR.color),
|
20
|
-
chinese: genRegex(REGEX_STR.chinese)
|
21
|
-
};
|
22
|
-
/**
|
23
|
-
* Wheter is number
|
24
|
-
*
|
25
|
-
* 是否为数字
|
26
|
-
*/
|
27
|
-
export function isNum(value) {
|
28
|
-
return REGEX.num.test(value.toString());
|
29
|
-
}
|
30
|
-
/**
|
31
|
-
* Wheter is integer
|
32
|
-
*
|
33
|
-
* 是否为整数
|
34
|
-
*/
|
35
|
-
export function isInt(value) {
|
36
|
-
return isNum(value) && parseInt(value.toString(), 10).toString() === value.toString();
|
37
|
-
}
|
38
|
-
/**
|
39
|
-
* Wheter is decimal
|
40
|
-
*
|
41
|
-
* 是否为小数点数值
|
42
|
-
*/
|
43
|
-
export function isDecimal(value) {
|
44
|
-
return isNum(value) && !isInt(value);
|
45
|
-
}
|
46
|
-
/**
|
47
|
-
* Wheter is People's Republic of China identity card
|
48
|
-
*
|
49
|
-
* 是否为中华人民共和国居民身份证
|
50
|
-
*/
|
51
|
-
export function isIdCard(value) {
|
52
|
-
return REGEX.idCard.test(value);
|
53
|
-
}
|
54
|
-
/**
|
55
|
-
* Wheter is china mobile (China)
|
56
|
-
*
|
57
|
-
* 是否为手机号(中国)
|
58
|
-
*/
|
59
|
-
export function isMobile(value) {
|
60
|
-
return REGEX.mobile.test(value);
|
61
|
-
}
|
62
|
-
/**
|
63
|
-
* Wheter is url address
|
64
|
-
*
|
65
|
-
* 是否URL地址
|
66
|
-
*/
|
67
|
-
export function isUrl(url) {
|
68
|
-
return REGEX.url.test(url);
|
69
|
-
}
|
70
|
-
/**
|
71
|
-
* Wheter is IPv4 address (Support v4, v6)
|
72
|
-
*
|
73
|
-
* 是否IP4地址(支持v4、v6)
|
74
|
-
*/
|
75
|
-
export function isIp(ip) {
|
76
|
-
return REGEX.ip.test(ip);
|
77
|
-
}
|
78
|
-
/**
|
79
|
-
* Wheter is color
|
80
|
-
*
|
81
|
-
* 是否颜色代码值
|
82
|
-
*/
|
83
|
-
export function isColor(color) {
|
84
|
-
return REGEX.color.test(color);
|
85
|
-
}
|
86
|
-
/**
|
87
|
-
* Wheter is chinese
|
88
|
-
*
|
89
|
-
* 是否中文
|
90
|
-
*/
|
91
|
-
export function isChinese(value) {
|
92
|
-
return REGEX.chinese.test(value);
|
93
|
-
}
|
1
|
+
export const REGEX_STR = {
|
2
|
+
num: `(([-+]?\\d+\\.\\d+)|([-+]?\\d+)|([-+]?\\.\\d+))(?:[eE]([-+]?\\d+))?`,
|
3
|
+
idCard: `(^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-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,})?$)`,
|
7
|
+
color: `(?:#|0x)(?:[a-f0-9]{3}|[a-f0-9]{6})\\b|(?:rgb|hsl)a?\\([^\\)]*\\)`,
|
8
|
+
chinese: `[\u4e00-\u9fa5]+`
|
9
|
+
};
|
10
|
+
function genRegex(str, flags) {
|
11
|
+
return new RegExp(`^${str}$`, flags);
|
12
|
+
}
|
13
|
+
export const REGEX = {
|
14
|
+
num: genRegex(REGEX_STR.num),
|
15
|
+
idCard: genRegex(REGEX_STR.idCard, 'i'),
|
16
|
+
mobile: genRegex(REGEX_STR.mobile),
|
17
|
+
url: genRegex(REGEX_STR.url),
|
18
|
+
ip: genRegex(REGEX_STR.ip),
|
19
|
+
color: genRegex(REGEX_STR.color),
|
20
|
+
chinese: genRegex(REGEX_STR.chinese)
|
21
|
+
};
|
22
|
+
/**
|
23
|
+
* Wheter is number
|
24
|
+
*
|
25
|
+
* 是否为数字
|
26
|
+
*/
|
27
|
+
export function isNum(value) {
|
28
|
+
return REGEX.num.test(value.toString());
|
29
|
+
}
|
30
|
+
/**
|
31
|
+
* Wheter is integer
|
32
|
+
*
|
33
|
+
* 是否为整数
|
34
|
+
*/
|
35
|
+
export function isInt(value) {
|
36
|
+
return isNum(value) && parseInt(value.toString(), 10).toString() === value.toString();
|
37
|
+
}
|
38
|
+
/**
|
39
|
+
* Wheter is decimal
|
40
|
+
*
|
41
|
+
* 是否为小数点数值
|
42
|
+
*/
|
43
|
+
export function isDecimal(value) {
|
44
|
+
return isNum(value) && !isInt(value);
|
45
|
+
}
|
46
|
+
/**
|
47
|
+
* Wheter is People's Republic of China identity card
|
48
|
+
*
|
49
|
+
* 是否为中华人民共和国居民身份证
|
50
|
+
*/
|
51
|
+
export function isIdCard(value) {
|
52
|
+
return REGEX.idCard.test(value);
|
53
|
+
}
|
54
|
+
/**
|
55
|
+
* Wheter is china mobile (China)
|
56
|
+
*
|
57
|
+
* 是否为手机号(中国)
|
58
|
+
*/
|
59
|
+
export function isMobile(value) {
|
60
|
+
return REGEX.mobile.test(value);
|
61
|
+
}
|
62
|
+
/**
|
63
|
+
* Wheter is url address
|
64
|
+
*
|
65
|
+
* 是否URL地址
|
66
|
+
*/
|
67
|
+
export function isUrl(url) {
|
68
|
+
return REGEX.url.test(url);
|
69
|
+
}
|
70
|
+
/**
|
71
|
+
* Wheter is IPv4 address (Support v4, v6)
|
72
|
+
*
|
73
|
+
* 是否IP4地址(支持v4、v6)
|
74
|
+
*/
|
75
|
+
export function isIp(ip) {
|
76
|
+
return REGEX.ip.test(ip);
|
77
|
+
}
|
78
|
+
/**
|
79
|
+
* Wheter is color
|
80
|
+
*
|
81
|
+
* 是否颜色代码值
|
82
|
+
*/
|
83
|
+
export function isColor(color) {
|
84
|
+
return REGEX.color.test(color);
|
85
|
+
}
|
86
|
+
/**
|
87
|
+
* Wheter is chinese
|
88
|
+
*
|
89
|
+
* 是否中文
|
90
|
+
*/
|
91
|
+
export function isChinese(value) {
|
92
|
+
return REGEX.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KlxuICog5piv5ZCmSVA05Zyw5Z2A77yI5pSv5oyBdjTjgIF2Nu+8iVxuICovXG5leHBvcnQgZnVuY3Rpb24gaXNJcChpcDogc3RyaW5nKTogYm9vbGVhbiB7XG4gIHJldHVybiBSRUdFWC5pcC50ZXN0KGlwKTtcbn1cblxuLyoqXG4gKiBXaGV0ZXIgaXMgY29sb3JcbiAqXG4gKiDmmK/lkKbpopzoibLku6PnoIHlgLxcbiAqL1xuZXhwb3J0IGZ1bmN0aW9uIGlzQ29sb3IoY29sb3I6IHN0cmluZyk6IGJvb2xlYW4ge1xuICByZXR1cm4gUkVHRVguY29sb3IudGVzdChjb2xvcik7XG59XG5cbi8qKlxuICogV2hldGVyIGlzIGNoaW5lc2VcbiAqXG4gKiDmmK/lkKbkuK3mlodcbiAqL1xuZXhwb3J0IGZ1bmN0aW9uIGlzQ2hpbmVzZSh2YWx1ZTogc3RyaW5nKTogYm9vbGVhbiB7XG4gIHJldHVybiBSRUdFWC5jaGluZXNlLnRlc3QodmFsdWUpO1xufVxuIl19
|
package/esm2020/index.mjs
CHANGED
@@ -1,12 +1,12 @@
|
|
1
|
-
export * from '@yelon/util/array';
|
2
|
-
export * from '@yelon/util/browser';
|
3
|
-
export * from '@yelon/util/config';
|
4
|
-
export * from '@yelon/util/date-time';
|
5
|
-
export * from '@yelon/util/form';
|
6
|
-
export * from '@yelon/util/format';
|
7
|
-
export * from '@yelon/util/math';
|
8
|
-
export * from '@yelon/util/decorator';
|
9
|
-
export * from '@yelon/util/other';
|
10
|
-
export * from '@yelon/util/pipes';
|
11
|
-
export * from '@yelon/util/token';
|
1
|
+
export * from '@yelon/util/array';
|
2
|
+
export * from '@yelon/util/browser';
|
3
|
+
export * from '@yelon/util/config';
|
4
|
+
export * from '@yelon/util/date-time';
|
5
|
+
export * from '@yelon/util/form';
|
6
|
+
export * from '@yelon/util/format';
|
7
|
+
export * from '@yelon/util/math';
|
8
|
+
export * from '@yelon/util/decorator';
|
9
|
+
export * from '@yelon/util/other';
|
10
|
+
export * from '@yelon/util/pipes';
|
11
|
+
export * from '@yelon/util/token';
|
12
12
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi9wYWNrYWdlcy91dGlsL2luZGV4LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLGNBQWMsbUJBQW1CLENBQUM7QUFDbEMsY0FBYyxxQkFBcUIsQ0FBQztBQUNwQyxjQUFjLG9CQUFvQixDQUFDO0FBQ25DLGNBQWMsdUJBQXVCLENBQUM7QUFDdEMsY0FBYyxrQkFBa0IsQ0FBQztBQUNqQyxjQUFjLG9CQUFvQixDQUFDO0FBQ25DLGNBQWMsa0JBQWtCLENBQUM7QUFDakMsY0FBYyx1QkFBdUIsQ0FBQztBQUN0QyxjQUFjLG1CQUFtQixDQUFDO0FBQ2xDLGNBQWMsbUJBQW1CLENBQUM7QUFDbEMsY0FBYyxtQkFBbUIsQ0FBQyIsInNvdXJjZXNDb250ZW50IjpbImV4cG9ydCAqIGZyb20gJ0B5ZWxvbi91dGlsL2FycmF5JztcbmV4cG9ydCAqIGZyb20gJ0B5ZWxvbi91dGlsL2Jyb3dzZXInO1xuZXhwb3J0ICogZnJvbSAnQHllbG9uL3V0aWwvY29uZmlnJztcbmV4cG9ydCAqIGZyb20gJ0B5ZWxvbi91dGlsL2RhdGUtdGltZSc7XG5leHBvcnQgKiBmcm9tICdAeWVsb24vdXRpbC9mb3JtJztcbmV4cG9ydCAqIGZyb20gJ0B5ZWxvbi91dGlsL2Zvcm1hdCc7XG5leHBvcnQgKiBmcm9tICdAeWVsb24vdXRpbC9tYXRoJztcbmV4cG9ydCAqIGZyb20gJ0B5ZWxvbi91dGlsL2RlY29yYXRvcic7XG5leHBvcnQgKiBmcm9tICdAeWVsb24vdXRpbC9vdGhlcic7XG5leHBvcnQgKiBmcm9tICdAeWVsb24vdXRpbC9waXBlcyc7XG5leHBvcnQgKiBmcm9tICdAeWVsb24vdXRpbC90b2tlbic7XG4iXX0=
|
@@ -1,25 +1,25 @@
|
|
1
|
-
import { assertNumber } from '@yelon/util/other';
|
2
|
-
/**
|
3
|
-
* Checks if `value` is between `start` and `end` to, but not including `end`. If `end` is not specified, it's set to start with `start` then set to `0`. If `start` is greater than `end` the params are swapped to support negative ranges.
|
4
|
-
*
|
5
|
-
* 检查 `value` 是否在 `start` 与 `end` 之间,但不包括 `end`。 如果 `end` 没有指定,那么 `start` 设置为 `0`。 如果 `start` 大于 `end`,那么参数会交换以便支持负范围。
|
6
|
-
* ```ts
|
7
|
-
* inRange(3, 2, 4); // true
|
8
|
-
* inRange(4, 8); // true
|
9
|
-
* inRange(4, 2); // false
|
10
|
-
* inRange(2, 2); // false
|
11
|
-
* inRange(1.2, 2); // true
|
12
|
-
* inRange(-3, -2, -6); // true
|
13
|
-
* ```
|
14
|
-
*/
|
15
|
-
export function inRange(value, start, end) {
|
16
|
-
if (end === undefined) {
|
17
|
-
end = start;
|
18
|
-
start = 0;
|
19
|
-
}
|
20
|
-
assertNumber(value);
|
21
|
-
assertNumber(start);
|
22
|
-
assertNumber(end);
|
23
|
-
return value >= Math.min(start, end) && value < Math.max(start, end);
|
24
|
-
}
|
1
|
+
import { assertNumber } from '@yelon/util/other';
|
2
|
+
/**
|
3
|
+
* Checks if `value` is between `start` and `end` to, but not including `end`. If `end` is not specified, it's set to start with `start` then set to `0`. If `start` is greater than `end` the params are swapped to support negative ranges.
|
4
|
+
*
|
5
|
+
* 检查 `value` 是否在 `start` 与 `end` 之间,但不包括 `end`。 如果 `end` 没有指定,那么 `start` 设置为 `0`。 如果 `start` 大于 `end`,那么参数会交换以便支持负范围。
|
6
|
+
* ```ts
|
7
|
+
* inRange(3, 2, 4); // true
|
8
|
+
* inRange(4, 8); // true
|
9
|
+
* inRange(4, 2); // false
|
10
|
+
* inRange(2, 2); // false
|
11
|
+
* inRange(1.2, 2); // true
|
12
|
+
* inRange(-3, -2, -6); // true
|
13
|
+
* ```
|
14
|
+
*/
|
15
|
+
export function inRange(value, start, end) {
|
16
|
+
if (end === undefined) {
|
17
|
+
end = start;
|
18
|
+
start = 0;
|
19
|
+
}
|
20
|
+
assertNumber(value);
|
21
|
+
assertNumber(start);
|
22
|
+
assertNumber(end);
|
23
|
+
return value >= Math.min(start, end) && value < Math.max(start, end);
|
24
|
+
}
|
25
25
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW4tcmFuZ2UuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi8uLi9wYWNrYWdlcy91dGlsL21hdGgvaW4tcmFuZ2UudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxFQUFFLFlBQVksRUFBRSxNQUFNLG1CQUFtQixDQUFDO0FBRWpEOzs7Ozs7Ozs7Ozs7R0FZRztBQUNILE1BQU0sVUFBVSxPQUFPLENBQUMsS0FBYSxFQUFFLEtBQWEsRUFBRSxHQUFZO0lBQ2hFLElBQUksR0FBRyxLQUFLLFNBQVMsRUFBRTtRQUNyQixHQUFHLEdBQUcsS0FBSyxDQUFDO1FBQ1osS0FBSyxHQUFHLENBQUMsQ0FBQztLQUNYO0lBQ0QsWUFBWSxDQUFDLEtBQUssQ0FBQyxDQUFDO0lBQ3BCLFlBQVksQ0FBQyxLQUFLLENBQUMsQ0FBQztJQUNwQixZQUFZLENBQUMsR0FBRyxDQUFDLENBQUM7SUFDbEIsT0FBTyxLQUFLLElBQUksSUFBSSxDQUFDLEdBQUcsQ0FBQyxLQUFLLEVBQUUsR0FBRyxDQUFDLElBQUksS0FBSyxHQUFHLElBQUksQ0FBQyxHQUFHLENBQUMsS0FBSyxFQUFFLEdBQUcsQ0FBQyxDQUFDO0FBQ3ZFLENBQUMiLCJzb3VyY2VzQ29udGVudCI6WyJpbXBvcnQgeyBh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AoZW5kID09PSB1bmRlZmluZWQpIHtcbiAgICBlbmQgPSBzdGFydDtcbiAgICBzdGFydCA9IDA7XG4gIH1cbiAgYXNzZXJ0TnVtYmVyKHZhbHVlKTtcbiAgYXNzZXJ0TnVtYmVyKHN0YXJ0KTtcbiAgYXNzZXJ0TnVtYmVyKGVuZCk7XG4gIHJldHVybiB2YWx1ZSA+PSBNYXRoLm1pbihzdGFydCwgZW5kKSAmJiB2YWx1ZSA8IE1hdGgubWF4KHN0YXJ0LCBlbmQpO1xufVxuIl19
|
package/esm2020/math/index.mjs
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
export * from './in-range';
|
2
|
-
export * from './round';
|
1
|
+
export * from './in-range';
|
2
|
+
export * from './round';
|
3
3
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi8uLi9wYWNrYWdlcy91dGlsL21hdGgvaW5kZXgudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsY0FBYyxZQUFZLENBQUM7QUFDM0IsY0FBYyxTQUFTLENBQUMiLCJzb3VyY2VzQ29udGVudCI6WyJleHBvcnQgKiBmcm9tICcuL2luLXJhbmdlJztcbmV4cG9ydCAqIGZyb20gJy4vcm91bmQnO1xuIl19
|
package/esm2020/math/math.mjs
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
/**
|
2
|
-
* Generated bundle index. Do not edit.
|
3
|
-
*/
|
4
|
-
export * from './index';
|
1
|
+
/**
|
2
|
+
* Generated bundle index. Do not edit.
|
3
|
+
*/
|
4
|
+
export * from './index';
|
5
5
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibWF0aC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uLy4uL3BhY2thZ2VzL3V0aWwvbWF0aC9tYXRoLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBOztHQUVHO0FBRUgsY0FBYyxTQUFTLENBQUMiLCJzb3VyY2VzQ29udGVudCI6WyIvKipcbiAqIEdlbmVyYXRlZCBidW5kbGUgaW5kZXguIERvIG5vdCBlZGl0LlxuICovXG5cbmV4cG9ydCAqIGZyb20gJy4vaW5kZXgnO1xuIl19
|
package/esm2020/math/round.mjs
CHANGED
@@ -1,53 +1,53 @@
|
|
1
|
-
/**
|
2
|
-
* Computes `number` rounded up to `precision`.
|
3
|
-
*
|
4
|
-
* 根据 `precision`(精度) 向上舍入 `number`。
|
5
|
-
* ```ts
|
6
|
-
* ceil(4.006); // 5
|
7
|
-
* ceil(6.004, 2); // 6.01
|
8
|
-
* ceil(6040, -2); // 6100
|
9
|
-
* ```
|
10
|
-
*/
|
11
|
-
export function ceil(number, precision = 0) {
|
12
|
-
return createRound(number, precision, 'ceil');
|
13
|
-
}
|
14
|
-
/**
|
15
|
-
* Computes `number` rounded down to `precision`.
|
16
|
-
*
|
17
|
-
* 根据 `precision`(精度) 向下舍入 `number`。
|
18
|
-
* ```ts
|
19
|
-
* floor(4.006); // 4
|
20
|
-
* floor(0.046, 2); // 0.04
|
21
|
-
* floor(4060, -2); // 4000
|
22
|
-
* ```
|
23
|
-
*/
|
24
|
-
export function floor(number, precision = 0) {
|
25
|
-
return createRound(number, precision, 'floor');
|
26
|
-
}
|
27
|
-
/**
|
28
|
-
* Computes `number` rounded to `precision`.
|
29
|
-
*
|
30
|
-
* 根据 `precision`(精度) 四舍五入 `number`。
|
31
|
-
* ```ts
|
32
|
-
* round(4.006); // 4
|
33
|
-
* round(4.006, 2); // 4.01
|
34
|
-
* round(4060, -2); // 4100
|
35
|
-
* ```
|
36
|
-
*/
|
37
|
-
export function round(number, precision = 0) {
|
38
|
-
return createRound(number, precision, 'round');
|
39
|
-
}
|
40
|
-
function createRound(number, precision, methodName) {
|
41
|
-
const func = Math[methodName];
|
42
|
-
precision = precision == null ? 0 : Math.min(precision, 292);
|
43
|
-
if (!precision) {
|
44
|
-
return func(number);
|
45
|
-
}
|
46
|
-
// Shift with exponential notation to avoid floating-point issues.
|
47
|
-
// See [MDN](https://mdn.io/round#Examples) for more details.
|
48
|
-
let pair = `${number}e`.split('e');
|
49
|
-
const value = func(Number(`${pair[0]}e${Number(pair[1]) + precision}`));
|
50
|
-
pair = `${value}e`.split('e');
|
51
|
-
return Number(`${pair[0]}e${Number(pair[1]) - precision}`);
|
52
|
-
}
|
1
|
+
/**
|
2
|
+
* Computes `number` rounded up to `precision`.
|
3
|
+
*
|
4
|
+
* 根据 `precision`(精度) 向上舍入 `number`。
|
5
|
+
* ```ts
|
6
|
+
* ceil(4.006); // 5
|
7
|
+
* ceil(6.004, 2); // 6.01
|
8
|
+
* ceil(6040, -2); // 6100
|
9
|
+
* ```
|
10
|
+
*/
|
11
|
+
export function ceil(number, precision = 0) {
|
12
|
+
return createRound(number, precision, 'ceil');
|
13
|
+
}
|
14
|
+
/**
|
15
|
+
* Computes `number` rounded down to `precision`.
|
16
|
+
*
|
17
|
+
* 根据 `precision`(精度) 向下舍入 `number`。
|
18
|
+
* ```ts
|
19
|
+
* floor(4.006); // 4
|
20
|
+
* floor(0.046, 2); // 0.04
|
21
|
+
* floor(4060, -2); // 4000
|
22
|
+
* ```
|
23
|
+
*/
|
24
|
+
export function floor(number, precision = 0) {
|
25
|
+
return createRound(number, precision, 'floor');
|
26
|
+
}
|
27
|
+
/**
|
28
|
+
* Computes `number` rounded to `precision`.
|
29
|
+
*
|
30
|
+
* 根据 `precision`(精度) 四舍五入 `number`。
|
31
|
+
* ```ts
|
32
|
+
* round(4.006); // 4
|
33
|
+
* round(4.006, 2); // 4.01
|
34
|
+
* round(4060, -2); // 4100
|
35
|
+
* ```
|
36
|
+
*/
|
37
|
+
export function round(number, precision = 0) {
|
38
|
+
return createRound(number, precision, 'round');
|
39
|
+
}
|
40
|
+
function createRound(number, precision, methodName) {
|
41
|
+
const func = Math[methodName];
|
42
|
+
precision = precision == null ? 0 : Math.min(precision, 292);
|
43
|
+
if (!precision) {
|
44
|
+
return func(number);
|
45
|
+
}
|
46
|
+
// Shift with exponential notation to avoid floating-point issues.
|
47
|
+
// See [MDN](https://mdn.io/round#Examples) for more details.
|
48
|
+
let pair = `${number}e`.split('e');
|
49
|
+
const value = func(Number(`${pair[0]}e${Number(pair[1]) + precision}`));
|
50
|
+
pair = `${value}e`.split('e');
|
51
|
+
return Number(`${pair[0]}e${Number(pair[1]) - precision}`);
|
52
|
+
}
|
53
53
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicm91bmQuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi8uLi9wYWNrYWdlcy91dGlsL21hdGgvcm91bmQudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUE7Ozs7Ozs7OztHQVNHO0FBQ0gsTUFBTSxVQUFVLElBQUksQ0FBQyxNQUFjLEVBQUUsWUFBb0IsQ0FBQztJQUN4RCxPQUFPLFdBQVcsQ0FBQyxNQUFNLEVBQUUsU0FBUyxFQUFFLE1BQU0sQ0FBQyxDQUFDO0FBQ2hELENBQUM7QUFFRDs7Ozs7Ozs7O0dBU0c7QUFDSCxNQUFNLFVBQVUsS0FBSyxDQUFDLE1BQWMsRUFBRSxZQUFvQixDQUFDO0lBQ3pELE9BQU8sV0FBVyxDQUFDLE1BQU0sRUFBRSxTQUFTLEVBQUUsT0FBTyxDQUFDLENBQUM7QUFDakQsQ0FBQztBQUVEOzs7Ozs7Ozs7R0FTRztBQUNILE1BQU0sVUFBVSxLQUFLLENBQUMsTUFBYyxFQUFFLFlBQW9CLENBQUM7SUFDekQsT0FBTyxXQUFXLENBQUMsTUFBTSxFQUFFLFNBQVMsRUFBRSxPQUFPLENBQUMsQ0FBQztBQUNqRCxDQUFDO0FBRUQsU0FBUyxXQUFXLENBQUMsTUF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