react-restyle-components 0.2.75 → 0.2.76
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/lib/index.d.ts +1 -0
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +1 -0
- package/lib/package.json +1 -1
- package/lib/src/core-utils/calculation/calculation.util.d.ts +27 -0
- package/lib/src/core-utils/calculation/calculation.util.d.ts.map +1 -0
- package/lib/src/core-utils/calculation/calculation.util.js +89 -0
- package/lib/src/core-utils/index.d.ts +1 -0
- package/lib/src/core-utils/index.d.ts.map +1 -1
- package/lib/src/core-utils/index.js +1 -0
- package/package.json +1 -1
package/lib/index.d.ts
CHANGED
package/lib/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAEA,cAAc,uBAAuB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAEA,cAAc,uBAAuB,CAAC;AACtC,cAAc,kBAAkB,CAAC"}
|
package/lib/index.js
CHANGED
package/lib/package.json
CHANGED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
type Amounts = {
|
|
2
|
+
grossAmount: number;
|
|
3
|
+
netAmount: number;
|
|
4
|
+
discountedAmount: number;
|
|
5
|
+
discountPercent: number;
|
|
6
|
+
};
|
|
7
|
+
type AmountKey = 'grossAmount' | 'netAmount' | 'discountedAmount' | 'discountPercent';
|
|
8
|
+
type AmountMode = 'gross-net' | 'gross-discountPercent' | 'net-discountPercent' | 'gross-discounted' | 'net-discounted';
|
|
9
|
+
/**
|
|
10
|
+
* Calculates all amount fields based on the last changed key.
|
|
11
|
+
* @param amounts The amounts object.
|
|
12
|
+
* @param changedKey The key that was last changed.
|
|
13
|
+
*/
|
|
14
|
+
export declare function calculateAmount(amounts: Amounts, changedKey: AmountKey): {
|
|
15
|
+
grossAmount: number;
|
|
16
|
+
netAmount: number;
|
|
17
|
+
discountedAmount: number;
|
|
18
|
+
discountPercent: number;
|
|
19
|
+
};
|
|
20
|
+
export declare const calculateAmountByKey: (amounts: Amounts, mode: AmountMode) => {
|
|
21
|
+
grossAmount: number;
|
|
22
|
+
netAmount: number;
|
|
23
|
+
discountedAmount: number;
|
|
24
|
+
discountPercent: number;
|
|
25
|
+
};
|
|
26
|
+
export {};
|
|
27
|
+
//# sourceMappingURL=calculation.util.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"calculation.util.d.ts","sourceRoot":"","sources":["../../../../src/core-utils/calculation/calculation.util.ts"],"names":[],"mappings":"AAAA,KAAK,OAAO,GAAG;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,gBAAgB,EAAE,MAAM,CAAC;IACzB,eAAe,EAAE,MAAM,CAAC;CACzB,CAAC;AAEF,KAAK,SAAS,GACV,aAAa,GACb,WAAW,GACX,kBAAkB,GAClB,iBAAiB,CAAC;AAEtB,KAAK,UAAU,GACX,WAAW,GACX,uBAAuB,GACvB,qBAAqB,GACrB,kBAAkB,GAClB,gBAAgB,CAAC;AAqBrB;;;;GAIG;AACH,wBAAgB,eAAe,CAC7B,OAAO,EAAE,OAAO,EAChB,UAAU,EAAE,SAAS,GACpB;IACD,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,gBAAgB,EAAE,MAAM,CAAC;IACzB,eAAe,EAAE,MAAM,CAAC;CACzB,CAGA;AAED,eAAO,MAAM,oBAAoB,YACtB,OAAO,QACV,UAAU;iBAEH,MAAM;eACR,MAAM;sBACC,MAAM;qBACP,MAAM;CA+DxB,CAAC"}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Maps the changed AmountKey to the correct AmountMode.
|
|
3
|
+
* You can adjust this mapping as per your business logic.
|
|
4
|
+
*/
|
|
5
|
+
function getAmountModeByKey(key) {
|
|
6
|
+
switch (key) {
|
|
7
|
+
case 'grossAmount':
|
|
8
|
+
return 'gross-net';
|
|
9
|
+
case 'netAmount':
|
|
10
|
+
return 'gross-net';
|
|
11
|
+
case 'discountedAmount':
|
|
12
|
+
return 'gross-discounted';
|
|
13
|
+
case 'discountPercent':
|
|
14
|
+
return 'gross-discountPercent';
|
|
15
|
+
default:
|
|
16
|
+
return 'gross-net';
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Calculates all amount fields based on the last changed key.
|
|
21
|
+
* @param amounts The amounts object.
|
|
22
|
+
* @param changedKey The key that was last changed.
|
|
23
|
+
*/
|
|
24
|
+
export function calculateAmount(amounts, changedKey) {
|
|
25
|
+
const mode = getAmountModeByKey(changedKey);
|
|
26
|
+
return calculateAmountByKey(amounts, mode);
|
|
27
|
+
}
|
|
28
|
+
export const calculateAmountByKey = (amounts, mode) => {
|
|
29
|
+
const { grossAmount, netAmount, discountedAmount, discountPercent } = amounts;
|
|
30
|
+
switch (mode) {
|
|
31
|
+
case 'gross-discountPercent': {
|
|
32
|
+
const discountedAmountCalc = (grossAmount * discountPercent) / 100;
|
|
33
|
+
const netAmountCalc = grossAmount - discountedAmountCalc;
|
|
34
|
+
return {
|
|
35
|
+
grossAmount: Number(grossAmount?.toFixed(2)),
|
|
36
|
+
netAmount: Number(netAmountCalc?.toFixed(2)),
|
|
37
|
+
discountedAmount: Number(discountedAmountCalc?.toFixed(2)),
|
|
38
|
+
discountPercent: Number(discountPercent?.toFixed(2)),
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
case 'gross-net': {
|
|
42
|
+
const discountedAmountCalc = grossAmount - netAmount;
|
|
43
|
+
const discountPercentCalc = (discountedAmountCalc / grossAmount) * 100;
|
|
44
|
+
return {
|
|
45
|
+
grossAmount: Number(grossAmount?.toFixed(2)),
|
|
46
|
+
netAmount: Number(netAmount?.toFixed(2)),
|
|
47
|
+
discountedAmount: Number(discountedAmountCalc?.toFixed(2)),
|
|
48
|
+
discountPercent: Number(discountPercentCalc?.toFixed(2)),
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
case 'net-discountPercent': {
|
|
52
|
+
const grossAmountCalc = netAmount / (1 - discountPercent / 100);
|
|
53
|
+
const discountedAmountCalc = grossAmountCalc - netAmount;
|
|
54
|
+
return {
|
|
55
|
+
grossAmount: Number(grossAmountCalc?.toFixed(2)),
|
|
56
|
+
netAmount: Number(netAmount?.toFixed(2)),
|
|
57
|
+
discountedAmount: Number(discountedAmountCalc?.toFixed(2)),
|
|
58
|
+
discountPercent: Number(discountPercent?.toFixed(2)),
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
case 'gross-discounted': {
|
|
62
|
+
const netAmountCalc = grossAmount - discountedAmount;
|
|
63
|
+
const discountPercentCalc = (discountedAmount / grossAmount) * 100;
|
|
64
|
+
return {
|
|
65
|
+
grossAmount: Number(grossAmount?.toFixed(2)),
|
|
66
|
+
netAmount: Number(netAmountCalc?.toFixed(2)),
|
|
67
|
+
discountedAmount: Number(discountedAmount?.toFixed(2)),
|
|
68
|
+
discountPercent: Number(discountPercentCalc?.toFixed(2)),
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
case 'net-discounted': {
|
|
72
|
+
const grossAmountCalc = netAmount + discountedAmount;
|
|
73
|
+
const discountPercentCalc = (discountedAmount / grossAmountCalc) * 100;
|
|
74
|
+
return {
|
|
75
|
+
grossAmount: Number(grossAmountCalc?.toFixed(2)),
|
|
76
|
+
netAmount: Number(netAmount?.toFixed(2)),
|
|
77
|
+
discountedAmount: Number(discountedAmount?.toFixed(2)),
|
|
78
|
+
discountPercent: Number(discountPercentCalc?.toFixed(2)),
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
default:
|
|
82
|
+
return {
|
|
83
|
+
grossAmount,
|
|
84
|
+
netAmount,
|
|
85
|
+
discountedAmount,
|
|
86
|
+
discountPercent,
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/core-utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/core-utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gCAAgC,CAAC"}
|