@nexim/financial-calculate 1.0.0-alpha.0 → 1.0.0-alpha.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/CHANGELOG.md CHANGED
@@ -3,6 +3,16 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [1.0.0-alpha.2](https://github.com/the-nexim/nanolib/compare/@nexim/financial-calculate@1.0.0-alpha.1...@nexim/financial-calculate@1.0.0-alpha.2) (2025-01-11)
7
+
8
+ ### Features
9
+
10
+ * **financial-calculating:** add `calculateDiscountParentage` method ([#33](https://github.com/the-nexim/nanolib/issues/33)) ([7e61430](https://github.com/the-nexim/nanolib/commit/7e614304c5957aa64489a0159e7e0c7caf4856e6)) by @arashagp
11
+
12
+ ## [1.0.0-alpha.1](https://github.com/the-nexim/nanolib/compare/@nexim/financial-calculate@1.0.0-alpha.0...@nexim/financial-calculate@1.0.0-alpha.1) (2025-01-09)
13
+
14
+ **Note:** Version bump only for package @nexim/financial-calculate
15
+
6
16
  ## 1.0.0-alpha.0 (2025-01-09)
7
17
 
8
18
  ### Features
package/README.md CHANGED
@@ -36,3 +36,12 @@ Calculate the discount amount from the original price.
36
36
  ```ts
37
37
  calculateDiscountAmount(100, 10, 1); // returns 10.0
38
38
  ```
39
+
40
+ ### calculateDiscountPercentage
41
+
42
+ Calculates the discount percentage between the market price and the sale price.
43
+
44
+ ```ts
45
+ calculateDiscountPercentage(100, 80); // Returns 20.00
46
+ calculateDiscountPercentage(100, 80, 1, false); // Returns 25.0
47
+ ```
package/dist/main.cjs CHANGED
@@ -1,4 +1,4 @@
1
- /* @nexim/financial-calculate v1.0.0-alpha.0 */
1
+ /* @nexim/financial-calculate v1.0.0-alpha.2 */
2
2
  "use strict";
3
3
  var __defProp = Object.defineProperty;
4
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
@@ -22,12 +22,14 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
22
22
  var main_exports = {};
23
23
  __export(main_exports, {
24
24
  calculateDiscountAmount: () => calculateDiscountAmount,
25
- calculateDiscountedPrice: () => calculateDiscountedPrice
25
+ calculateDiscountedPrice: () => calculateDiscountedPrice,
26
+ calculatePercentageDiscount: () => calculatePercentageDiscount,
27
+ calculatePercentageProfit: () => calculatePercentageProfit
26
28
  });
27
29
  module.exports = __toCommonJS(main_exports);
28
30
  var import_logger = require("@alwatr/logger");
29
31
  var import_package_tracer = require("@alwatr/package-tracer");
30
- __dev_mode__: import_package_tracer.packageTracer.add("@nexim/financial-calculate", "1.0.0-alpha.0");
32
+ __dev_mode__: import_package_tracer.packageTracer.add("@nexim/financial-calculate", "1.0.0-alpha.2");
31
33
  var logger = (0, import_logger.createLogger)("@nexim/financial-calculate");
32
34
  function calculateDiscountedPrice(price, discount, decimal = 2) {
33
35
  logger.logMethodArgs?.("calculateDiscountedPrice", { price, discount, decimal });
@@ -39,5 +41,15 @@ function calculateDiscountAmount(price, discount, decimal = 2) {
39
41
  const discountAmount = price * discount / 100;
40
42
  return parseFloat(discountAmount.toFixed(decimal));
41
43
  }
44
+ function calculatePercentageProfit(marketPrice, salePrice, decimal = 2) {
45
+ logger.logMethodArgs?.("calculatePercentageProfit", { marketPrice, salePrice, decimal });
46
+ const percentage = (marketPrice - salePrice) / salePrice * 100;
47
+ return parseFloat(percentage.toFixed(decimal));
48
+ }
49
+ function calculatePercentageDiscount(marketPrice, salePrice, decimal = 2) {
50
+ logger.logMethodArgs?.("calculatePercentageDiscount", { marketPrice, salePrice, decimal });
51
+ const percentage = (marketPrice - salePrice) / marketPrice * 100;
52
+ return parseFloat(percentage.toFixed(decimal));
53
+ }
42
54
  /*! For license information please see main.cjs.LEGAL.txt */
43
55
  //# sourceMappingURL=main.cjs.map
package/dist/main.cjs.map CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../src/main.ts"],
4
- "sourcesContent": ["import {createLogger} from '@alwatr/logger';\nimport {packageTracer} from '@alwatr/package-tracer';\n\n__dev_mode__: packageTracer.add(__package_name__, __package_version__);\n\nconst logger = createLogger(__package_name__);\n\n/**\n * Calculate the price after applying a discount.\n *\n * @param price - The original price.\n * @param discount - The discount percentage to apply.\n * @param decimal - The number of decimal places to round to (default is 2).\n *\n * @example\n * calculateDiscountedPrice(100, 10, 1); // returns 90.0\n */\nexport function calculateDiscountedPrice(price: number, discount: number, decimal = 2): number {\n logger.logMethodArgs?.('calculateDiscountedPrice', {price, discount, decimal});\n\n const discountedPrice = price * (1 - discount / 100);\n return parseFloat(discountedPrice.toFixed(decimal));\n}\n\n/**\n * Calculate the discount amount from the original price.\n *\n * @param price - The original price.\n * @param discount - The discount percentage.\n * @param decimal - The number of decimal places to round to (default is 2).\n *\n * @example\n * calculateDiscountAmount(100, 10, 1); // returns 10.0\n */\nexport function calculateDiscountAmount(price: number, discount: number, decimal = 2): number {\n logger.logMethodArgs?.('calculateDiscountAmount', {price, discount, decimal});\n\n const discountAmount = (price * discount) / 100;\n return parseFloat(discountAmount.toFixed(decimal));\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAA2B;AAC3B,4BAA4B;AAE5B,aAAc,qCAAc,IAAI,8BAAkB,eAAmB;AAErE,IAAM,aAAS,4BAAa,4BAAgB;AAYrC,SAAS,yBAAyB,OAAe,UAAkB,UAAU,GAAW;AAC7F,SAAO,gBAAgB,4BAA4B,EAAC,OAAO,UAAU,QAAO,CAAC;AAE7E,QAAM,kBAAkB,SAAS,IAAI,WAAW;AAChD,SAAO,WAAW,gBAAgB,QAAQ,OAAO,CAAC;AACpD;AAYO,SAAS,wBAAwB,OAAe,UAAkB,UAAU,GAAW;AAC5F,SAAO,gBAAgB,2BAA2B,EAAC,OAAO,UAAU,QAAO,CAAC;AAE5E,QAAM,iBAAkB,QAAQ,WAAY;AAC5C,SAAO,WAAW,eAAe,QAAQ,OAAO,CAAC;AACnD;",
4
+ "sourcesContent": ["import {createLogger} from '@alwatr/logger';\nimport {packageTracer} from '@alwatr/package-tracer';\n\n__dev_mode__: packageTracer.add(__package_name__, __package_version__);\n\nconst logger = createLogger(__package_name__);\n\n/**\n * Calculate the price after applying a discount.\n *\n * @param price - The original price.\n * @param discount - The discount percentage to apply.\n * @param decimal - The number of decimal places to round to (default is 2).\n *\n * @example\n * ```\n * calculateDiscountedPrice(100, 10, 1); // returns 90.0\n * ```\n */\nexport function calculateDiscountedPrice(price: number, discount: number, decimal = 2): number {\n logger.logMethodArgs?.('calculateDiscountedPrice', {price, discount, decimal});\n\n const discountedPrice = price * (1 - discount / 100);\n return parseFloat(discountedPrice.toFixed(decimal));\n}\n\n/**\n * Calculate the discount amount from the original price.\n *\n * @param price - The original price.\n * @param discount - The discount percentage.\n * @param decimal - The number of decimal places to round to (default is 2).\n *\n * @example\n * ```\n * calculateDiscountAmount(100, 10, 1); // returns 10.0\n * ```\n */\nexport function calculateDiscountAmount(price: number, discount: number, decimal = 2): number {\n logger.logMethodArgs?.('calculateDiscountAmount', {price, discount, decimal});\n\n const discountAmount = (price * discount) / 100;\n return parseFloat(discountAmount.toFixed(decimal));\n}\n\n/**\n * Calculates the discount percentage between the market price and the sale price for profit.\n *\n * @param marketPrice - The original market price of the item.\n * @param salePrice - The sale price of the item.\n * @param decimal - The number of decimal places to round the result to(optional with default value = 2).\n * @param upSide - Determines the denominator for the percentage calculation (optional with default value = true).\n *\n * @example\n * ```\n * calculateDiscountPercentage(100, 80); // Returns 20.00\n * calculateDiscountPercentage(100, 80, 1, false); // Returns 25.0\n * ```\n */\nexport function calculatePercentageProfit(marketPrice: number, salePrice: number, decimal = 2): number {\n logger.logMethodArgs?.('calculatePercentageProfit', {marketPrice, salePrice, decimal});\n\n const percentage = ((marketPrice - salePrice) / salePrice) * 100;\n return parseFloat(percentage.toFixed(decimal));\n}\n\n/**\n * Calculates the discount percentage between the market price and the sale price for discount.\n *\n * @param marketPrice - The original market price of the item.\n * @param salePrice - The sale price of the item.\n * @param decimal - The number of decimal places to round the result to(optional with default value = 2).\n * @param upSide - Determines the denominator for the percentage calculation (optional with default value = true).\n *\n * @example\n * ```\n * calculateDiscountPercentage(100, 80); // Returns 20.00\n * calculateDiscountPercentage(100, 80, 1, false); // Returns 25.0\n * ```\n */\nexport function calculatePercentageDiscount(marketPrice: number, salePrice: number, decimal = 2): number {\n logger.logMethodArgs?.('calculatePercentageDiscount', {marketPrice, salePrice, decimal});\n\n const percentage = ((marketPrice - salePrice) / marketPrice) * 100;\n return parseFloat(percentage.toFixed(decimal));\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAA2B;AAC3B,4BAA4B;AAE5B,aAAc,qCAAc,IAAI,8BAAkB,eAAmB;AAErE,IAAM,aAAS,4BAAa,4BAAgB;AAcrC,SAAS,yBAAyB,OAAe,UAAkB,UAAU,GAAW;AAC7F,SAAO,gBAAgB,4BAA4B,EAAC,OAAO,UAAU,QAAO,CAAC;AAE7E,QAAM,kBAAkB,SAAS,IAAI,WAAW;AAChD,SAAO,WAAW,gBAAgB,QAAQ,OAAO,CAAC;AACpD;AAcO,SAAS,wBAAwB,OAAe,UAAkB,UAAU,GAAW;AAC5F,SAAO,gBAAgB,2BAA2B,EAAC,OAAO,UAAU,QAAO,CAAC;AAE5E,QAAM,iBAAkB,QAAQ,WAAY;AAC5C,SAAO,WAAW,eAAe,QAAQ,OAAO,CAAC;AACnD;AAgBO,SAAS,0BAA0B,aAAqB,WAAmB,UAAU,GAAW;AACrG,SAAO,gBAAgB,6BAA6B,EAAC,aAAa,WAAW,QAAO,CAAC;AAErF,QAAM,cAAe,cAAc,aAAa,YAAa;AAC7D,SAAO,WAAW,WAAW,QAAQ,OAAO,CAAC;AAC/C;AAgBO,SAAS,4BAA4B,aAAqB,WAAmB,UAAU,GAAW;AACvG,SAAO,gBAAgB,+BAA+B,EAAC,aAAa,WAAW,QAAO,CAAC;AAEvF,QAAM,cAAe,cAAc,aAAa,cAAe;AAC/D,SAAO,WAAW,WAAW,QAAQ,OAAO,CAAC;AAC/C;",
6
6
  "names": []
7
7
  }
package/dist/main.d.ts CHANGED
@@ -6,7 +6,9 @@
6
6
  * @param decimal - The number of decimal places to round to (default is 2).
7
7
  *
8
8
  * @example
9
+ * ```
9
10
  * calculateDiscountedPrice(100, 10, 1); // returns 90.0
11
+ * ```
10
12
  */
11
13
  export declare function calculateDiscountedPrice(price: number, discount: number, decimal?: number): number;
12
14
  /**
@@ -17,7 +19,39 @@ export declare function calculateDiscountedPrice(price: number, discount: number
17
19
  * @param decimal - The number of decimal places to round to (default is 2).
18
20
  *
19
21
  * @example
22
+ * ```
20
23
  * calculateDiscountAmount(100, 10, 1); // returns 10.0
24
+ * ```
21
25
  */
22
26
  export declare function calculateDiscountAmount(price: number, discount: number, decimal?: number): number;
27
+ /**
28
+ * Calculates the discount percentage between the market price and the sale price for profit.
29
+ *
30
+ * @param marketPrice - The original market price of the item.
31
+ * @param salePrice - The sale price of the item.
32
+ * @param decimal - The number of decimal places to round the result to(optional with default value = 2).
33
+ * @param upSide - Determines the denominator for the percentage calculation (optional with default value = true).
34
+ *
35
+ * @example
36
+ * ```
37
+ * calculateDiscountPercentage(100, 80); // Returns 20.00
38
+ * calculateDiscountPercentage(100, 80, 1, false); // Returns 25.0
39
+ * ```
40
+ */
41
+ export declare function calculatePercentageProfit(marketPrice: number, salePrice: number, decimal?: number): number;
42
+ /**
43
+ * Calculates the discount percentage between the market price and the sale price for discount.
44
+ *
45
+ * @param marketPrice - The original market price of the item.
46
+ * @param salePrice - The sale price of the item.
47
+ * @param decimal - The number of decimal places to round the result to(optional with default value = 2).
48
+ * @param upSide - Determines the denominator for the percentage calculation (optional with default value = true).
49
+ *
50
+ * @example
51
+ * ```
52
+ * calculateDiscountPercentage(100, 80); // Returns 20.00
53
+ * calculateDiscountPercentage(100, 80, 1, false); // Returns 25.0
54
+ * ```
55
+ */
56
+ export declare function calculatePercentageDiscount(marketPrice: number, salePrice: number, decimal?: number): number;
23
57
  //# sourceMappingURL=main.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../src/main.ts"],"names":[],"mappings":"AAOA;;;;;;;;;GASG;AACH,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,SAAI,GAAG,MAAM,CAK7F;AAED;;;;;;;;;GASG;AACH,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,SAAI,GAAG,MAAM,CAK5F"}
1
+ {"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../src/main.ts"],"names":[],"mappings":"AAOA;;;;;;;;;;;GAWG;AACH,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,SAAI,GAAG,MAAM,CAK7F;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,SAAI,GAAG,MAAM,CAK5F;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,yBAAyB,CAAC,WAAW,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,OAAO,SAAI,GAAG,MAAM,CAKrG;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,2BAA2B,CAAC,WAAW,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,OAAO,SAAI,GAAG,MAAM,CAKvG"}
package/dist/main.mjs CHANGED
@@ -1,9 +1,9 @@
1
- /* @nexim/financial-calculate v1.0.0-alpha.0 */
1
+ /* @nexim/financial-calculate v1.0.0-alpha.2 */
2
2
 
3
3
  // src/main.ts
4
4
  import { createLogger } from "@alwatr/logger";
5
5
  import { packageTracer } from "@alwatr/package-tracer";
6
- __dev_mode__: packageTracer.add("@nexim/financial-calculate", "1.0.0-alpha.0");
6
+ __dev_mode__: packageTracer.add("@nexim/financial-calculate", "1.0.0-alpha.2");
7
7
  var logger = createLogger("@nexim/financial-calculate");
8
8
  function calculateDiscountedPrice(price, discount, decimal = 2) {
9
9
  logger.logMethodArgs?.("calculateDiscountedPrice", { price, discount, decimal });
@@ -15,9 +15,21 @@ function calculateDiscountAmount(price, discount, decimal = 2) {
15
15
  const discountAmount = price * discount / 100;
16
16
  return parseFloat(discountAmount.toFixed(decimal));
17
17
  }
18
+ function calculatePercentageProfit(marketPrice, salePrice, decimal = 2) {
19
+ logger.logMethodArgs?.("calculatePercentageProfit", { marketPrice, salePrice, decimal });
20
+ const percentage = (marketPrice - salePrice) / salePrice * 100;
21
+ return parseFloat(percentage.toFixed(decimal));
22
+ }
23
+ function calculatePercentageDiscount(marketPrice, salePrice, decimal = 2) {
24
+ logger.logMethodArgs?.("calculatePercentageDiscount", { marketPrice, salePrice, decimal });
25
+ const percentage = (marketPrice - salePrice) / marketPrice * 100;
26
+ return parseFloat(percentage.toFixed(decimal));
27
+ }
18
28
  export {
19
29
  calculateDiscountAmount,
20
- calculateDiscountedPrice
30
+ calculateDiscountedPrice,
31
+ calculatePercentageDiscount,
32
+ calculatePercentageProfit
21
33
  };
22
34
  /*! For license information please see main.mjs.LEGAL.txt */
23
35
  //# sourceMappingURL=main.mjs.map
package/dist/main.mjs.map CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../src/main.ts"],
4
- "sourcesContent": ["import {createLogger} from '@alwatr/logger';\nimport {packageTracer} from '@alwatr/package-tracer';\n\n__dev_mode__: packageTracer.add(__package_name__, __package_version__);\n\nconst logger = createLogger(__package_name__);\n\n/**\n * Calculate the price after applying a discount.\n *\n * @param price - The original price.\n * @param discount - The discount percentage to apply.\n * @param decimal - The number of decimal places to round to (default is 2).\n *\n * @example\n * calculateDiscountedPrice(100, 10, 1); // returns 90.0\n */\nexport function calculateDiscountedPrice(price: number, discount: number, decimal = 2): number {\n logger.logMethodArgs?.('calculateDiscountedPrice', {price, discount, decimal});\n\n const discountedPrice = price * (1 - discount / 100);\n return parseFloat(discountedPrice.toFixed(decimal));\n}\n\n/**\n * Calculate the discount amount from the original price.\n *\n * @param price - The original price.\n * @param discount - The discount percentage.\n * @param decimal - The number of decimal places to round to (default is 2).\n *\n * @example\n * calculateDiscountAmount(100, 10, 1); // returns 10.0\n */\nexport function calculateDiscountAmount(price: number, discount: number, decimal = 2): number {\n logger.logMethodArgs?.('calculateDiscountAmount', {price, discount, decimal});\n\n const discountAmount = (price * discount) / 100;\n return parseFloat(discountAmount.toFixed(decimal));\n}\n"],
5
- "mappings": ";;;AAAA,SAAQ,oBAAmB;AAC3B,SAAQ,qBAAoB;AAE5B,aAAc,eAAc,IAAI,8BAAkB,eAAmB;AAErE,IAAM,SAAS,aAAa,4BAAgB;AAYrC,SAAS,yBAAyB,OAAe,UAAkB,UAAU,GAAW;AAC7F,SAAO,gBAAgB,4BAA4B,EAAC,OAAO,UAAU,QAAO,CAAC;AAE7E,QAAM,kBAAkB,SAAS,IAAI,WAAW;AAChD,SAAO,WAAW,gBAAgB,QAAQ,OAAO,CAAC;AACpD;AAYO,SAAS,wBAAwB,OAAe,UAAkB,UAAU,GAAW;AAC5F,SAAO,gBAAgB,2BAA2B,EAAC,OAAO,UAAU,QAAO,CAAC;AAE5E,QAAM,iBAAkB,QAAQ,WAAY;AAC5C,SAAO,WAAW,eAAe,QAAQ,OAAO,CAAC;AACnD;",
4
+ "sourcesContent": ["import {createLogger} from '@alwatr/logger';\nimport {packageTracer} from '@alwatr/package-tracer';\n\n__dev_mode__: packageTracer.add(__package_name__, __package_version__);\n\nconst logger = createLogger(__package_name__);\n\n/**\n * Calculate the price after applying a discount.\n *\n * @param price - The original price.\n * @param discount - The discount percentage to apply.\n * @param decimal - The number of decimal places to round to (default is 2).\n *\n * @example\n * ```\n * calculateDiscountedPrice(100, 10, 1); // returns 90.0\n * ```\n */\nexport function calculateDiscountedPrice(price: number, discount: number, decimal = 2): number {\n logger.logMethodArgs?.('calculateDiscountedPrice', {price, discount, decimal});\n\n const discountedPrice = price * (1 - discount / 100);\n return parseFloat(discountedPrice.toFixed(decimal));\n}\n\n/**\n * Calculate the discount amount from the original price.\n *\n * @param price - The original price.\n * @param discount - The discount percentage.\n * @param decimal - The number of decimal places to round to (default is 2).\n *\n * @example\n * ```\n * calculateDiscountAmount(100, 10, 1); // returns 10.0\n * ```\n */\nexport function calculateDiscountAmount(price: number, discount: number, decimal = 2): number {\n logger.logMethodArgs?.('calculateDiscountAmount', {price, discount, decimal});\n\n const discountAmount = (price * discount) / 100;\n return parseFloat(discountAmount.toFixed(decimal));\n}\n\n/**\n * Calculates the discount percentage between the market price and the sale price for profit.\n *\n * @param marketPrice - The original market price of the item.\n * @param salePrice - The sale price of the item.\n * @param decimal - The number of decimal places to round the result to(optional with default value = 2).\n * @param upSide - Determines the denominator for the percentage calculation (optional with default value = true).\n *\n * @example\n * ```\n * calculateDiscountPercentage(100, 80); // Returns 20.00\n * calculateDiscountPercentage(100, 80, 1, false); // Returns 25.0\n * ```\n */\nexport function calculatePercentageProfit(marketPrice: number, salePrice: number, decimal = 2): number {\n logger.logMethodArgs?.('calculatePercentageProfit', {marketPrice, salePrice, decimal});\n\n const percentage = ((marketPrice - salePrice) / salePrice) * 100;\n return parseFloat(percentage.toFixed(decimal));\n}\n\n/**\n * Calculates the discount percentage between the market price and the sale price for discount.\n *\n * @param marketPrice - The original market price of the item.\n * @param salePrice - The sale price of the item.\n * @param decimal - The number of decimal places to round the result to(optional with default value = 2).\n * @param upSide - Determines the denominator for the percentage calculation (optional with default value = true).\n *\n * @example\n * ```\n * calculateDiscountPercentage(100, 80); // Returns 20.00\n * calculateDiscountPercentage(100, 80, 1, false); // Returns 25.0\n * ```\n */\nexport function calculatePercentageDiscount(marketPrice: number, salePrice: number, decimal = 2): number {\n logger.logMethodArgs?.('calculatePercentageDiscount', {marketPrice, salePrice, decimal});\n\n const percentage = ((marketPrice - salePrice) / marketPrice) * 100;\n return parseFloat(percentage.toFixed(decimal));\n}\n"],
5
+ "mappings": ";;;AAAA,SAAQ,oBAAmB;AAC3B,SAAQ,qBAAoB;AAE5B,aAAc,eAAc,IAAI,8BAAkB,eAAmB;AAErE,IAAM,SAAS,aAAa,4BAAgB;AAcrC,SAAS,yBAAyB,OAAe,UAAkB,UAAU,GAAW;AAC7F,SAAO,gBAAgB,4BAA4B,EAAC,OAAO,UAAU,QAAO,CAAC;AAE7E,QAAM,kBAAkB,SAAS,IAAI,WAAW;AAChD,SAAO,WAAW,gBAAgB,QAAQ,OAAO,CAAC;AACpD;AAcO,SAAS,wBAAwB,OAAe,UAAkB,UAAU,GAAW;AAC5F,SAAO,gBAAgB,2BAA2B,EAAC,OAAO,UAAU,QAAO,CAAC;AAE5E,QAAM,iBAAkB,QAAQ,WAAY;AAC5C,SAAO,WAAW,eAAe,QAAQ,OAAO,CAAC;AACnD;AAgBO,SAAS,0BAA0B,aAAqB,WAAmB,UAAU,GAAW;AACrG,SAAO,gBAAgB,6BAA6B,EAAC,aAAa,WAAW,QAAO,CAAC;AAErF,QAAM,cAAe,cAAc,aAAa,YAAa;AAC7D,SAAO,WAAW,WAAW,QAAQ,OAAO,CAAC;AAC/C;AAgBO,SAAS,4BAA4B,aAAqB,WAAmB,UAAU,GAAW;AACvG,SAAO,gBAAgB,+BAA+B,EAAC,aAAa,WAAW,QAAO,CAAC;AAEvF,QAAM,cAAe,cAAc,aAAa,cAAe;AAC/D,SAAO,WAAW,WAAW,QAAQ,OAAO,CAAC;AAC/C;",
6
6
  "names": []
7
7
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nexim/financial-calculate",
3
- "version": "1.0.0-alpha.0",
3
+ "version": "1.0.0-alpha.2",
4
4
  "description": "Provides a set of utils to handle common financial operations.",
5
5
  "keywords": [
6
6
  "financial",
@@ -102,5 +102,5 @@
102
102
  "service": true
103
103
  }
104
104
  },
105
- "gitHead": "1b6418040b616b080452ae547843046baca9a941"
105
+ "gitHead": "41445f8378b95ffe25437d6b2c4e4936e5090b91"
106
106
  }
package/src/main.test.js CHANGED
@@ -1,39 +1,34 @@
1
1
  import test from 'ava';
2
2
 
3
- import {calculateDiscountAmount, calculateDiscountedPrice} from '@nexim/financial-calculate';
4
-
5
- test('calculate discount from price with: 3, 4 input', (test) => {
3
+ import {
4
+ calculateDiscountAmount,
5
+ calculateDiscountedPrice,
6
+ calculatePercentageDiscount,
7
+ calculatePercentageProfit,
8
+ } from '@nexim/financial-calculate';
9
+
10
+ test('calculate discount from price', (test) => {
6
11
  test.is(calculateDiscountAmount(3, 4), 0.12);
7
- });
8
-
9
- test('calculateDiscountAmount(100, 10) returns 10.00', (t) => {
10
- t.is(calculateDiscountAmount(100, 10), 10);
11
- });
12
-
13
- test('calculate price from discount with: 3, 4 input', (test) => {
14
- test.is(calculateDiscountedPrice(3, 4), 2.88);
15
- });
16
-
17
- test('calculate discount from price with: 587, 629 input', (test) => {
12
+ test.is(calculateDiscountAmount(100, 10), 10);
18
13
  test.is(calculateDiscountAmount(587, 629), 3692.23);
19
- });
20
-
21
- test('calculate price from discount with: 587, 629 input', (test) => {
22
- test.is(calculateDiscountedPrice(587, 629), -3105.23);
23
- });
24
-
25
- test('calculate discount from price with: 15034, 73 input', (test) => {
26
14
  test.is(calculateDiscountAmount(15034, 73), 10974.82);
15
+ test.is(calculateDiscountAmount(54205, 1332, 5), 722010.6);
27
16
  });
28
17
 
29
- test('calculate price from discount with: 15034, 73 input', (test) => {
18
+ test('calculate price from discount', (test) => {
19
+ test.is(calculateDiscountedPrice(3, 4), 2.88);
20
+ test.is(calculateDiscountedPrice(100, 10), 90);
30
21
  test.is(calculateDiscountedPrice(15034, 73), 4059.18);
22
+ test.is(calculateDiscountedPrice(587, 629), -3105.23);
23
+ test.is(calculateDiscountedPrice(54205, 1332, 5), -667805.6);
31
24
  });
32
25
 
33
- test('calculate discount from price with: 54205, 1332, 5 input', (test) => {
34
- test.is(calculateDiscountAmount(54205, 1332, 5), 722010.6);
26
+ test('calculate discount percentage for profit and discount', (test) => {
27
+ test.is(calculatePercentageProfit(100, 80), 25);
28
+ test.is(calculatePercentageProfit(100, 53), 88.68);
35
29
  });
36
30
 
37
- test('calculate price from discount with: 54205, 1332, 5 input', (test) => {
38
- test.is(calculateDiscountedPrice(54205, 1332, 5), -667805.6);
31
+ test('calculate discount percentage for profit', (test) => {
32
+ test.is(calculatePercentageDiscount(100, 80, 1), 20);
33
+ test.is(calculatePercentageDiscount(100, 53), 47);
39
34
  });