qmwts 1.1.65 → 1.1.66
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
declare const _default: {
|
|
2
|
-
ifNaN(
|
|
3
|
-
isNumber(...
|
|
4
|
-
thousandths(
|
|
5
|
-
summation(
|
|
6
|
-
isBetween(
|
|
7
|
-
isInside(
|
|
2
|
+
ifNaN(value: any, substitute: any): any;
|
|
3
|
+
isNumber(...values: any[]): boolean;
|
|
4
|
+
thousandths(value: any, fixed?: number): string;
|
|
5
|
+
summation(...values: any[]): number;
|
|
6
|
+
isBetween(value: number, min: number, max: number): boolean;
|
|
7
|
+
isInside(value: number, min: number, max: number): boolean;
|
|
8
|
+
extractNumbers(value: any): string;
|
|
8
9
|
};
|
|
9
10
|
export default _default;
|
|
@@ -2,42 +2,62 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.default = {
|
|
4
4
|
// 判断是否数字
|
|
5
|
-
ifNaN(
|
|
6
|
-
return this.isNumber(
|
|
5
|
+
ifNaN(value, substitute) {
|
|
6
|
+
return this.isNumber(value) ? +value : substitute;
|
|
7
7
|
},
|
|
8
|
-
isNumber(...
|
|
9
|
-
for (let i =
|
|
10
|
-
const e = String(
|
|
11
|
-
if (e === '' || !isFinite(+e) || isNaN(+e))
|
|
8
|
+
isNumber(...values) {
|
|
9
|
+
for (let i = values.length - 1; i >= 0; i--) {
|
|
10
|
+
const e = String(values[i]).trim();
|
|
11
|
+
if (e === '' || !Number.isFinite(+e) || Number.isNaN(+e))
|
|
12
12
|
return false;
|
|
13
13
|
}
|
|
14
14
|
return true;
|
|
15
15
|
},
|
|
16
16
|
// 增加千分位分隔符
|
|
17
|
-
thousandths(
|
|
18
|
-
if (!this.isNumber(
|
|
17
|
+
thousandths(value, fixed = 2) {
|
|
18
|
+
if (!this.isNumber(value))
|
|
19
19
|
return '';
|
|
20
|
-
|
|
20
|
+
value = new Intl.NumberFormat('en-US', {
|
|
21
21
|
minimumFractionDigits: fixed,
|
|
22
22
|
maximumFractionDigits: fixed,
|
|
23
|
-
}).format(
|
|
24
|
-
if (+
|
|
23
|
+
}).format(value);
|
|
24
|
+
if (+value === 0) // -0转为0
|
|
25
25
|
return (0).toFixed(fixed);
|
|
26
|
-
return
|
|
26
|
+
return value;
|
|
27
27
|
},
|
|
28
|
-
summation(
|
|
28
|
+
summation(...values) {
|
|
29
29
|
let sum = 0;
|
|
30
|
-
|
|
31
|
-
|
|
30
|
+
const values0 = values.flat(Infinity);
|
|
31
|
+
for (let i = values0.length - 1; i >= 0; i--) {
|
|
32
|
+
const e = +values0[i];
|
|
32
33
|
if (this.isNumber(e))
|
|
33
34
|
sum += e;
|
|
34
35
|
}
|
|
35
36
|
return sum;
|
|
36
37
|
},
|
|
37
|
-
isBetween(
|
|
38
|
-
return
|
|
38
|
+
isBetween(value, min, max) {
|
|
39
|
+
return value >= Math.min(min, max) && value <= Math.max(max, min);
|
|
39
40
|
},
|
|
40
|
-
isInside(
|
|
41
|
-
return
|
|
41
|
+
isInside(value, min, max) {
|
|
42
|
+
return value > Math.min(min, max) && value < Math.max(max, min);
|
|
43
|
+
},
|
|
44
|
+
extractNumbers(value) {
|
|
45
|
+
const v = String(value);
|
|
46
|
+
let result = '';
|
|
47
|
+
let hasDot = false;
|
|
48
|
+
for (let i = 0; i < v.length; i++) {
|
|
49
|
+
const ch = v[i];
|
|
50
|
+
if (/[0-9]/.test(ch)) {
|
|
51
|
+
result += ch;
|
|
52
|
+
}
|
|
53
|
+
else if (ch === '-' && result === '') { // 负号只能在最前
|
|
54
|
+
result += ch;
|
|
55
|
+
}
|
|
56
|
+
else if (ch === '.' && !hasDot) { // 只能有一个小数点
|
|
57
|
+
result += ch;
|
|
58
|
+
hasDot = true;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return result;
|
|
42
62
|
}
|
|
43
63
|
};
|