@jsdev_ninja/core 0.13.56 → 0.14.0
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/dist/core.cjs +1 -1
- package/dist/core.cjs.map +1 -1
- package/dist/core.es.js +350 -340
- package/dist/core.es.js.map +1 -1
- package/dist/core.umd.js +1 -1
- package/dist/core.umd.js.map +1 -1
- package/dist/lib/index.d.ts +2 -0
- package/dist/lib/index.d.ts.map +1 -1
- package/dist/lib/index.js +2 -0
- package/dist/lib/utils/index.d.ts.map +1 -1
- package/dist/lib/utils/index.js +2 -1
- package/dist/lib/utils/math/math.d.ts +4 -0
- package/dist/lib/utils/math/math.d.ts.map +1 -0
- package/dist/lib/utils/math/math.js +6 -0
- package/dist/lib/utils/math/math.test.d.ts +2 -0
- package/dist/lib/utils/math/math.test.d.ts.map +1 -0
- package/dist/lib/utils/math/math.test.js +36 -0
- package/dist/lib/utils/storeCalculator/storeCalculator.d.ts +5 -0
- package/dist/lib/utils/storeCalculator/storeCalculator.d.ts.map +1 -0
- package/dist/lib/utils/storeCalculator/storeCalculator.js +14 -0
- package/dist/lib/utils/storeCalculator/storeCalculator.test.d.ts +2 -0
- package/dist/lib/utils/storeCalculator/storeCalculator.test.d.ts.map +1 -0
- package/dist/lib/utils/storeCalculator/storeCalculator.test.js +50 -0
- package/dist/tsconfig.app.tsbuildinfo +1 -1
- package/dist/vite.config.js +1 -1
- package/package.json +1 -1
package/dist/lib/index.d.ts
CHANGED
package/dist/lib/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../lib/index.
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../lib/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,SAAS,CAAC;AACxB,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,cAAc,mBAAmB,CAAC;AAClC,cAAc,yCAAyC,CAAC"}
|
package/dist/lib/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../lib/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,SAAS,EAAoB,MAAM,aAAa,CAAC;AA8BjE,wBAAgB,WAAW,CAAC,EAC3B,IAAI,EACJ,SAAS,EACT,aAAiB,EACjB,iBAAqB,EACrB,oBAA4B,GAC5B,EAAE;IACF,IAAI,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC;IACrB,SAAS,EAAE,SAAS,EAAE,CAAC;IACvB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,oBAAoB,CAAC,EAAE,OAAO,CAAC;CAC/B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../lib/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,SAAS,EAAoB,MAAM,aAAa,CAAC;AA8BjE,wBAAgB,WAAW,CAAC,EAC3B,IAAI,EACJ,SAAS,EACT,aAAiB,EACjB,iBAAqB,EACrB,oBAA4B,GAC5B,EAAE;IACF,IAAI,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC;IACrB,SAAS,EAAE,SAAS,EAAE,CAAC;IACvB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,oBAAoB,CAAC,EAAE,OAAO,CAAC;CAC/B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA+FA"}
|
package/dist/lib/utils/index.js
CHANGED
|
@@ -52,7 +52,8 @@ export function getCartCost({ cart, discounts, deliveryPrice = 0, freeDeliveryPr
|
|
|
52
52
|
if (product.vat) {
|
|
53
53
|
let vat = 0;
|
|
54
54
|
if (isVatIncludedInPrice) {
|
|
55
|
-
const
|
|
55
|
+
const beforeVat = Number((finalPrice / (1 + CONFIG.VAT / 100)).toFixed(2));
|
|
56
|
+
const vat_amount = finalPrice - beforeVat;
|
|
56
57
|
productVatValue = Number(vat_amount.toFixed(2));
|
|
57
58
|
productVatValue = productVatValue * amount;
|
|
58
59
|
vat = Number(productVatValue.toFixed(2));
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"math.d.ts","sourceRoot":"","sources":["../../../../lib/utils/math/math.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,IAAI;mBACE,MAAM,sBAAe,MAAM;CAI7C,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"math.test.d.ts","sourceRoot":"","sources":["../../../../lib/utils/math/math.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { describe, expect, test } from "vitest";
|
|
2
|
+
import { math } from "./math";
|
|
3
|
+
describe("math", () => {
|
|
4
|
+
describe("round", () => {
|
|
5
|
+
test("round to 2 decimal places", () => {
|
|
6
|
+
expect(math.round(1.2345, 2)).toBe(1.23);
|
|
7
|
+
});
|
|
8
|
+
test("round to 0 decimal places", () => {
|
|
9
|
+
expect(math.round(1.2345, 0)).toBe(1);
|
|
10
|
+
});
|
|
11
|
+
test("round to 1 decimal places", () => {
|
|
12
|
+
expect(math.round(1.2345, 1)).toBe(1.2);
|
|
13
|
+
});
|
|
14
|
+
test("round to 3 decimal places", () => {
|
|
15
|
+
expect(math.round(1.2345, 3)).toBe(1.235);
|
|
16
|
+
});
|
|
17
|
+
test("round to 4 decimal places", () => {
|
|
18
|
+
expect(math.round(1.2345, 4)).toBe(1.2345);
|
|
19
|
+
});
|
|
20
|
+
test("round to 5 decimal places", () => {
|
|
21
|
+
expect(math.round(1.2345, 5)).toBe(1.2345);
|
|
22
|
+
});
|
|
23
|
+
test("round to 6 decimal places", () => {
|
|
24
|
+
expect(math.round(1.2345, 6)).toBe(1.2345);
|
|
25
|
+
});
|
|
26
|
+
test("round to 7 decimal places", () => {
|
|
27
|
+
expect(math.round(1.2345, 7)).toBe(1.2345);
|
|
28
|
+
});
|
|
29
|
+
test("round to 8 decimal places", () => {
|
|
30
|
+
expect(math.round(1.2345, 8)).toBe(1.2345);
|
|
31
|
+
});
|
|
32
|
+
test("round to 9 decimal places", () => {
|
|
33
|
+
expect(math.round(1.2345, 9)).toBe(1.2345);
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"storeCalculator.d.ts","sourceRoot":"","sources":["../../../../lib/utils/storeCalculator/storeCalculator.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,eAAe;sCACU,MAAM,iBAAiB,MAAM;yCAI1B,MAAM,iBAAiB,MAAM;CAIrE,CAAA"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { math } from "../math/math";
|
|
2
|
+
// default is margin not markup
|
|
3
|
+
export const storeCalculator = {
|
|
4
|
+
calcSalePriceFromMargin: (margin, purchasePrice) => {
|
|
5
|
+
if (margin <= 0 || purchasePrice <= 0 || margin >= 100)
|
|
6
|
+
return purchasePrice;
|
|
7
|
+
return math.round(purchasePrice / (1 - margin / 100));
|
|
8
|
+
},
|
|
9
|
+
calcMarginFromSalePrice: (salePrice, purchasePrice) => {
|
|
10
|
+
if (salePrice <= 0 || purchasePrice <= 0)
|
|
11
|
+
return 0;
|
|
12
|
+
return math.round(((salePrice - purchasePrice) / salePrice) * 100);
|
|
13
|
+
}
|
|
14
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"storeCalculator.test.d.ts","sourceRoot":"","sources":["../../../../lib/utils/storeCalculator/storeCalculator.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { expect, describe, test } from "vitest";
|
|
2
|
+
import { storeCalculator } from "./storeCalculator";
|
|
3
|
+
describe("storeCalculator", () => {
|
|
4
|
+
describe("calcSalePriceFromMargin", () => {
|
|
5
|
+
test("calculate correct price for margin 10% and purchase price 100", () => {
|
|
6
|
+
expect(storeCalculator.calcSalePriceFromMargin(10, 100)).toBe(111.11);
|
|
7
|
+
});
|
|
8
|
+
test("return purchase price when margin is 0", () => {
|
|
9
|
+
expect(storeCalculator.calcSalePriceFromMargin(0, 100)).toBe(100);
|
|
10
|
+
});
|
|
11
|
+
test("handles very high margin (99%) and purchase price 100", () => {
|
|
12
|
+
expect(storeCalculator.calcSalePriceFromMargin(99, 100)).toBe(10000);
|
|
13
|
+
});
|
|
14
|
+
test("return purchase price when margin is 100", () => {
|
|
15
|
+
expect(storeCalculator.calcSalePriceFromMargin(100, 100)).toBe(100);
|
|
16
|
+
});
|
|
17
|
+
test("return purchase price when purchase price is 0", () => {
|
|
18
|
+
expect(storeCalculator.calcSalePriceFromMargin(10, 0)).toBe(0);
|
|
19
|
+
});
|
|
20
|
+
test("return purchase price when purchase price is negative", () => {
|
|
21
|
+
expect(storeCalculator.calcSalePriceFromMargin(10, -100)).toBe(-100);
|
|
22
|
+
});
|
|
23
|
+
test("is reversible", () => {
|
|
24
|
+
expect(storeCalculator.calcMarginFromSalePrice(storeCalculator.calcSalePriceFromMargin(30, 100), 100)).toBe(30);
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
describe("calcMarginFromSalePrice", () => {
|
|
28
|
+
test("calculate correct margin for sale price 111.11 and purchase price 100", () => {
|
|
29
|
+
expect(storeCalculator.calcMarginFromSalePrice(111.11, 100)).toBe(10);
|
|
30
|
+
});
|
|
31
|
+
test("return 0 when sale price is 0", () => {
|
|
32
|
+
expect(storeCalculator.calcMarginFromSalePrice(0, 100)).toBe(0);
|
|
33
|
+
});
|
|
34
|
+
test("return 0 when purchase price is 0", () => {
|
|
35
|
+
expect(storeCalculator.calcMarginFromSalePrice(100, 0)).toBe(0);
|
|
36
|
+
});
|
|
37
|
+
test("return 0 when purchase price is negative", () => {
|
|
38
|
+
expect(storeCalculator.calcMarginFromSalePrice(100, -100)).toBe(0);
|
|
39
|
+
});
|
|
40
|
+
test("is reversible", () => {
|
|
41
|
+
expect(storeCalculator.calcSalePriceFromMargin(storeCalculator.calcMarginFromSalePrice(111.11, 100), 100)).toBe(111.11);
|
|
42
|
+
});
|
|
43
|
+
test("return 0 when margin is negative", () => {
|
|
44
|
+
expect(storeCalculator.calcMarginFromSalePrice(100, -100)).toBe(0);
|
|
45
|
+
});
|
|
46
|
+
test("return 0 when margin is 100", () => {
|
|
47
|
+
expect(storeCalculator.calcMarginFromSalePrice(100, 100)).toBe(0);
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
});
|