@jsdev_ninja/core 0.13.57 → 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.
@@ -1,4 +1,6 @@
1
1
  export * from "./entities";
2
2
  export * from "./utils";
3
3
  export { FirebaseAPI } from "./firebase-api";
4
+ export * from "./utils/math/math";
5
+ export * from "./utils/storeCalculator/storeCalculator";
4
6
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../lib/index.tsx"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,SAAS,CAAC;AACxB,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC"}
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,3 +1,5 @@
1
1
  export * from "./entities";
2
2
  export * from "./utils";
3
3
  export { FirebaseAPI } from "./firebase-api";
4
+ export * from "./utils/math/math";
5
+ export * from "./utils/storeCalculator/storeCalculator";
@@ -0,0 +1,4 @@
1
+ export declare const math: {
2
+ round: (value: number, digits?: number) => number;
3
+ };
4
+ //# sourceMappingURL=math.d.ts.map
@@ -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,6 @@
1
+ export const math = {
2
+ round: (value, digits = 2) => {
3
+ const p = 10 ** digits;
4
+ return Math.round((value + Number.EPSILON) * p) / p;
5
+ }
6
+ };
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=math.test.d.ts.map
@@ -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,5 @@
1
+ export declare const storeCalculator: {
2
+ calcSalePriceFromMargin: (margin: number, purchasePrice: number) => number;
3
+ calcMarginFromSalePrice: (salePrice: number, purchasePrice: number) => number;
4
+ };
5
+ //# sourceMappingURL=storeCalculator.d.ts.map
@@ -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,2 @@
1
+ export {};
2
+ //# sourceMappingURL=storeCalculator.test.d.ts.map
@@ -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
+ });