@8ms/helpers 1.6.1 → 1.6.2
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/number/getDivide.d.ts +7 -5
- package/number/getDivide.js +9 -5
- package/package.json +1 -1
package/number/getDivide.d.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
* Shorthand function to divide number, but fallback if the divisor is 0.
|
|
3
|
-
*/
|
|
4
|
-
declare const getDivide: ({ defaultValue, divisor, numerator }: {
|
|
1
|
+
type GetDivide = {
|
|
5
2
|
defaultValue?: number;
|
|
3
|
+
dp?: number;
|
|
6
4
|
divisor: any;
|
|
7
5
|
numerator: any;
|
|
8
|
-
}
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* Shorthand function to divide number, but fallback if the divisor is 0.
|
|
9
|
+
*/
|
|
10
|
+
declare const getDivide: (props: GetDivide) => number;
|
|
9
11
|
export default getDivide;
|
package/number/getDivide.js
CHANGED
|
@@ -4,19 +4,23 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const getNumber_1 = __importDefault(require("./getNumber"));
|
|
7
|
+
const getDecimal_1 = __importDefault(require("./getDecimal"));
|
|
7
8
|
/**
|
|
8
9
|
* Shorthand function to divide number, but fallback if the divisor is 0.
|
|
9
10
|
*/
|
|
10
|
-
const getDivide = (
|
|
11
|
+
const getDivide = (props) => {
|
|
11
12
|
const numeratorInt = (0, getNumber_1.default)({
|
|
12
|
-
input: numerator
|
|
13
|
+
input: props.numerator
|
|
13
14
|
});
|
|
14
15
|
const divisorInt = (0, getNumber_1.default)({
|
|
15
|
-
input: divisor
|
|
16
|
+
input: props.divisor
|
|
16
17
|
});
|
|
17
18
|
if (0 === divisorInt) {
|
|
18
|
-
return defaultValue;
|
|
19
|
+
return props.defaultValue || 0;
|
|
19
20
|
}
|
|
20
|
-
return
|
|
21
|
+
return (0, getDecimal_1.default)({
|
|
22
|
+
dp: props?.dp,
|
|
23
|
+
input: numeratorInt / divisorInt
|
|
24
|
+
});
|
|
21
25
|
};
|
|
22
26
|
exports.default = getDivide;
|