@konplit-services/common 1.0.357 → 1.0.359

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.
@@ -12,6 +12,7 @@ export * from "./card-types";
12
12
  export * from "./disputes";
13
13
  export * from "./charges";
14
14
  export * from "./currency-types";
15
+ export * from "./money";
15
16
  export * from "./currency-formater";
16
17
  export * from "./custom-paginate";
17
18
  export * from "./extract-card-details";
@@ -28,6 +28,7 @@ __exportStar(require("./card-types"), exports);
28
28
  __exportStar(require("./disputes"), exports);
29
29
  __exportStar(require("./charges"), exports);
30
30
  __exportStar(require("./currency-types"), exports);
31
+ __exportStar(require("./money"), exports);
31
32
  __exportStar(require("./currency-formater"), exports);
32
33
  __exportStar(require("./custom-paginate"), exports);
33
34
  __exportStar(require("./extract-card-details"), exports);
@@ -0,0 +1,11 @@
1
+ import { dinero } from "dinero.js";
2
+ type SupportedCurrency = "USD" | "NGN";
3
+ export declare const createMoney: (amount: number, currency?: SupportedCurrency) => import("dinero.js").Dinero<number>;
4
+ export declare const formatMoneyToString: (money: ReturnType<typeof dinero>) => string;
5
+ export declare const formatMoneyToNumber: (money: ReturnType<typeof dinero>) => number;
6
+ export declare const sumMoney: (a: ReturnType<typeof dinero>, b: ReturnType<typeof dinero>) => import("dinero.js").Dinero<number>;
7
+ export declare const subtractMoney: (a: ReturnType<typeof dinero>, b: ReturnType<typeof dinero>) => import("dinero.js").Dinero<number>;
8
+ export declare const multiplyMoney: (a: ReturnType<typeof dinero>, factor: number) => import("dinero.js").Dinero<number>;
9
+ export declare const divideMoney: (money: ReturnType<typeof dinero>, divisor: number) => import("dinero.js").Dinero<number>;
10
+ export declare const toSmalletUnit: (naira: number | string) => number;
11
+ export {};
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.toSmalletUnit = exports.divideMoney = exports.multiplyMoney = exports.subtractMoney = exports.sumMoney = exports.formatMoneyToNumber = exports.formatMoneyToString = exports.createMoney = void 0;
4
+ const dinero_js_1 = require("dinero.js");
5
+ const currencies_1 = require("@dinero.js/currencies");
6
+ const currencyMap = {
7
+ USD: currencies_1.USD,
8
+ NGN: currencies_1.NGN,
9
+ };
10
+ const createMoney = (amount, currency = "NGN") => {
11
+ return (0, dinero_js_1.dinero)({ amount, currency: currencyMap[currency] });
12
+ };
13
+ exports.createMoney = createMoney;
14
+ const formatMoneyToString = (money) => {
15
+ return (0, dinero_js_1.toDecimal)(money);
16
+ };
17
+ exports.formatMoneyToString = formatMoneyToString;
18
+ const formatMoneyToNumber = (money) => {
19
+ return parseFloat((0, dinero_js_1.toDecimal)(money));
20
+ };
21
+ exports.formatMoneyToNumber = formatMoneyToNumber;
22
+ const sumMoney = (a, b) => {
23
+ return (0, dinero_js_1.add)(a, b);
24
+ };
25
+ exports.sumMoney = sumMoney;
26
+ const subtractMoney = (a, b) => {
27
+ return (0, dinero_js_1.subtract)(a, b);
28
+ };
29
+ exports.subtractMoney = subtractMoney;
30
+ const multiplyMoney = (a, factor) => {
31
+ return (0, dinero_js_1.multiply)(a, { amount: factor * 100, scale: 2 }); // Convert decimal to Dinero scale
32
+ };
33
+ exports.multiplyMoney = multiplyMoney;
34
+ const divideMoney = (money, divisor) => {
35
+ const decimal = parseFloat((0, exports.formatMoneyToString)(money));
36
+ const result = Math.round((decimal / divisor) * 100);
37
+ return (0, exports.createMoney)(result);
38
+ };
39
+ exports.divideMoney = divideMoney;
40
+ const toSmalletUnit = (naira) => {
41
+ if (typeof naira === "string") {
42
+ naira = parseFloat(naira);
43
+ }
44
+ return Math.round(naira * 100);
45
+ };
46
+ exports.toSmalletUnit = toSmalletUnit;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@konplit-services/common",
3
- "version": "1.0.357",
3
+ "version": "1.0.359",
4
4
  "description": "",
5
5
  "main": "./build/index.js",
6
6
  "types": "./build/index.d.ts",
@@ -21,6 +21,7 @@
21
21
  "typescript": "^4.7.4"
22
22
  },
23
23
  "dependencies": {
24
+ "@dinero.js/currencies": "^2.0.0-alpha.14",
24
25
  "@types/express": "^4.17.13",
25
26
  "@types/jsonwebtoken": "^8.5.8",
26
27
  "@types/morgan": "^1.9.9",
@@ -30,6 +31,7 @@
30
31
  "@types/swagger-ui-express": "^4.1.6",
31
32
  "axios": "^1.7.2",
32
33
  "dayjs": "^1.11.13",
34
+ "dinero.js": "^2.0.0-alpha.14",
33
35
  "express": "^4.18.1",
34
36
  "express-validator": "^6.14.2",
35
37
  "ioredis": "^5.4.1",
@@ -47,7 +49,7 @@
47
49
  "typescript": "^4.8.4"
48
50
  },
49
51
  "engines": {
50
- "node": "v20.19.0",
51
- "npm": "10.8.2"
52
+ "node": "v22.15.1",
53
+ "npm": "10.9.2"
52
54
  }
53
55
  }