iv-npm 1.6.71 → 1.6.73
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.
package/package.json
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { TreeList } from '../types/index.js';
|
|
2
|
+
export { divide, minus, plus, round, strip, times } from 'number-precision';
|
|
2
3
|
|
|
3
4
|
declare function arrToTree(list: any[], parentMark: string, childrenMark: string): any;
|
|
4
5
|
interface TreeList {
|
|
@@ -18,6 +19,33 @@ declare function findTree<T extends {
|
|
|
18
19
|
children?: T[];
|
|
19
20
|
}>(id: string, list: T[], idName?: any): any;
|
|
20
21
|
|
|
22
|
+
/**
|
|
23
|
+
* @description 计算两个数字的百分百比
|
|
24
|
+
* @param {Number} complete 分子
|
|
25
|
+
* @param {Number} need 分母
|
|
26
|
+
* @return {Number} complete / need
|
|
27
|
+
*/
|
|
28
|
+
declare const formatPercentage: (complete: number, need: number) => number;
|
|
29
|
+
/**
|
|
30
|
+
* @description 计算数组之和
|
|
31
|
+
* @param {Number[]} number[]
|
|
32
|
+
* @return {Number}
|
|
33
|
+
*/
|
|
34
|
+
declare const arraySum: (arr: number[]) => number;
|
|
35
|
+
/**
|
|
36
|
+
* @description 计算数组某个字段之和
|
|
37
|
+
* @param {object[]} object[]
|
|
38
|
+
* @return {Number}
|
|
39
|
+
*/
|
|
40
|
+
declare const arraySumByKey: (arr: any[], key: string) => any;
|
|
41
|
+
/**
|
|
42
|
+
* @description 对比两个数组某个字段之和是否相同
|
|
43
|
+
* @param {object[]} object1[]
|
|
44
|
+
* @param {object[]} object2[]
|
|
45
|
+
* @return {Number}
|
|
46
|
+
*/
|
|
47
|
+
declare const isArraySumCompared: (arr1: any[], arr2: any[], key1: string, key2?: string) => boolean;
|
|
48
|
+
|
|
21
49
|
/**
|
|
22
50
|
* 检查对象是否为普通对象(使用“{}”或“new Object”创建)
|
|
23
51
|
* */
|
|
@@ -100,4 +128,4 @@ declare function getAmountByUnit(amount: number): string;
|
|
|
100
128
|
* */
|
|
101
129
|
declare const amountToFixed: (_v?: number | string) => string | 0;
|
|
102
130
|
|
|
103
|
-
export { LineIDEnum, ProjectStausEnum, SignStatusEnum, amountToFixed, apiConfiger, arrToTree, assign, buildURL as buildUrl, dateFormat, filterOptionHeadle, findTree, formatType, getAmountByUnit, hostConfiger, isDate, isObject, isPlainObject, isURLSearchParams, onChangeTail, tranListToTreeData, yearMonthDayFormat, yearMonthFormat };
|
|
131
|
+
export { LineIDEnum, ProjectStausEnum, SignStatusEnum, amountToFixed, apiConfiger, arrToTree, arraySum, arraySumByKey, assign, buildURL as buildUrl, dateFormat, filterOptionHeadle, findTree, formatPercentage, formatType, getAmountByUnit, hostConfiger, isArraySumCompared, isDate, isObject, isPlainObject, isURLSearchParams, onChangeTail, tranListToTreeData, yearMonthDayFormat, yearMonthFormat };
|
|
@@ -45,6 +45,48 @@ function findTree(id, list, idName) {
|
|
|
45
45
|
return result;
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
+
// utils/arr/digitalComp.ts
|
|
49
|
+
import { strip, plus, minus, times, divide, round } from "number-precision";
|
|
50
|
+
var isKeyInObject = (object, key) => {
|
|
51
|
+
return Object.prototype.hasOwnProperty.call(object, key);
|
|
52
|
+
};
|
|
53
|
+
var formatPercentage = (complete, need) => {
|
|
54
|
+
if (!need || !complete)
|
|
55
|
+
return 0;
|
|
56
|
+
const result = times(divide(complete / need), 100);
|
|
57
|
+
return Number.isNaN(result) ? 0 : result;
|
|
58
|
+
};
|
|
59
|
+
var arraySum = (arr) => {
|
|
60
|
+
const len = arr.length;
|
|
61
|
+
if (len === 0)
|
|
62
|
+
return 0;
|
|
63
|
+
if (len === 1)
|
|
64
|
+
return arr[0];
|
|
65
|
+
return plus(...arr);
|
|
66
|
+
};
|
|
67
|
+
var arraySumByKey = (arr, key) => {
|
|
68
|
+
const len = arr.length;
|
|
69
|
+
if (len === 0)
|
|
70
|
+
return 0;
|
|
71
|
+
if (len === 1) {
|
|
72
|
+
if (!isKeyInObject(arr[0], key))
|
|
73
|
+
throw new Error(`could not find it '${key}' in arraySumByKey function`);
|
|
74
|
+
return arr[0][key] ?? 0;
|
|
75
|
+
}
|
|
76
|
+
const tempArr = [];
|
|
77
|
+
arr.forEach((_e) => {
|
|
78
|
+
if (!isKeyInObject(_e, key))
|
|
79
|
+
throw new Error(`could not find it '${key}' in arraySumByKey function`);
|
|
80
|
+
tempArr.push(_e[key] ?? 0);
|
|
81
|
+
});
|
|
82
|
+
return arraySum(tempArr);
|
|
83
|
+
};
|
|
84
|
+
var isArraySumCompared = (arr1, arr2, key1, key2) => {
|
|
85
|
+
const k1 = key1;
|
|
86
|
+
const k2 = key2 ?? key1;
|
|
87
|
+
return arraySumByKey(arr1, k1) === arraySumByKey(arr2, k2);
|
|
88
|
+
};
|
|
89
|
+
|
|
48
90
|
// utils/obj/judge.ts
|
|
49
91
|
function isPlainObject(obj) {
|
|
50
92
|
let proto, Ctor;
|
|
@@ -413,18 +455,28 @@ export {
|
|
|
413
455
|
amountToFixed,
|
|
414
456
|
apiConfiger,
|
|
415
457
|
arrToTree,
|
|
458
|
+
arraySum,
|
|
459
|
+
arraySumByKey,
|
|
416
460
|
assign,
|
|
417
461
|
buildURL as buildUrl,
|
|
418
462
|
dateFormat,
|
|
463
|
+
divide,
|
|
419
464
|
filterOptionHeadle,
|
|
420
465
|
findTree,
|
|
466
|
+
formatPercentage,
|
|
421
467
|
getAmountByUnit,
|
|
422
468
|
hostConfiger,
|
|
469
|
+
isArraySumCompared,
|
|
423
470
|
isDate,
|
|
424
471
|
isObject,
|
|
425
472
|
isPlainObject,
|
|
426
473
|
isURLSearchParams,
|
|
474
|
+
minus,
|
|
427
475
|
onChangeTail,
|
|
476
|
+
plus,
|
|
477
|
+
round,
|
|
478
|
+
strip,
|
|
479
|
+
times,
|
|
428
480
|
tranListToTreeData,
|
|
429
481
|
yearMonthDayFormat,
|
|
430
482
|
yearMonthFormat
|