@nexim/financial-calculate 1.0.0-alpha.1 → 1.0.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/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](https://github.com/the-nexim/nanolib/compare/@nexim/financial-calculate@1.0.0-alpha.2...@nexim/financial-calculate@1.0.0) (2025-04-20)
7
+
8
+ **Note:** Version bump only for package @nexim/financial-calculate
9
+
10
+ ## [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)
11
+
12
+ ### Features
13
+
14
+ * **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
15
+
6
16
  ## [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)
7
17
 
8
18
  **Note:** Version bump only for package @nexim/financial-calculate
package/README.md CHANGED
@@ -19,20 +19,6 @@ npm install @nexim/financial-calculate
19
19
  yarn add @nexim/financial-calculate
20
20
  ```
21
21
 
22
- ## API
22
+ ## Documentation
23
23
 
24
- ### calculateDiscountedPrice
25
-
26
- Calculate the price after applying a discount.
27
-
28
- ```ts
29
- calculateDiscountedPrice(100, 10, 1); // returns 90.0
30
- ```
31
-
32
- ### calculateDiscountAmount
33
-
34
- Calculate the discount amount from the original price.
35
-
36
- ```ts
37
- calculateDiscountAmount(100, 10, 1); // returns 10.0
38
- ```
24
+ Read full documentation [here](./docs/README.md).
package/dist/main.cjs CHANGED
@@ -1,4 +1,4 @@
1
- /* @nexim/financial-calculate v1.0.0-alpha.1 */
1
+ /* @nexim/financial-calculate v1.0.0 */
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.1");
32
+ __dev_mode__: import_package_tracer.packageTracer.add("@nexim/financial-calculate", "1.0.0");
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,14 @@ function calculateDiscountAmount(price, discount, decimal = 2) {
39
41
  const discountAmount = price * discount / 100;
40
42
  return parseFloat(discountAmount.toFixed(decimal));
41
43
  }
42
- /*! For license information please see main.cjs.LEGAL.txt */
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
+ }
43
54
  //# 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 * ```\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"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;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;",
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 * ```ts\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 * ```ts\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 *\n * @example\n * ```ts\n * calculatePercentageProfit(100, 80); // Returns 20.00\n * calculatePercentageProfit(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 *\n * @example\n * ```ts\n * calculatePercentageDiscount(100, 80); // Returns 20.00\n * calculatePercentageDiscount(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,oBAA6B;AAC7B,4BAA8B;AAE9B,aAAc,qCAAc,IAAI,8BAAkB,OAAmB;AAErE,IAAM,aAAS,4BAAa,4BAAgB;AAcrC,SAAS,yBAAyB,OAAe,UAAkB,UAAU,GAAW;AAC7F,SAAO,gBAAgB,4BAA4B,EAAE,OAAO,UAAU,QAAQ,CAAC;AAE/E,QAAM,kBAAkB,SAAS,IAAI,WAAW;AAChD,SAAO,WAAW,gBAAgB,QAAQ,OAAO,CAAC;AACpD;AAcO,SAAS,wBAAwB,OAAe,UAAkB,UAAU,GAAW;AAC5F,SAAO,gBAAgB,2BAA2B,EAAE,OAAO,UAAU,QAAQ,CAAC;AAE9E,QAAM,iBAAkB,QAAQ,WAAY;AAC5C,SAAO,WAAW,eAAe,QAAQ,OAAO,CAAC;AACnD;AAeO,SAAS,0BAA0B,aAAqB,WAAmB,UAAU,GAAW;AACrG,SAAO,gBAAgB,6BAA6B,EAAE,aAAa,WAAW,QAAQ,CAAC;AAEvF,QAAM,cAAe,cAAc,aAAa,YAAa;AAC7D,SAAO,WAAW,WAAW,QAAQ,OAAO,CAAC;AAC/C;AAeO,SAAS,4BAA4B,aAAqB,WAAmB,UAAU,GAAW;AACvG,SAAO,gBAAgB,+BAA+B,EAAE,aAAa,WAAW,QAAQ,CAAC;AAEzF,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,7 @@
6
6
  * @param decimal - The number of decimal places to round to (default is 2).
7
7
  *
8
8
  * @example
9
- * ```
9
+ * ```ts
10
10
  * calculateDiscountedPrice(100, 10, 1); // returns 90.0
11
11
  * ```
12
12
  */
@@ -19,9 +19,37 @@ export declare function calculateDiscountedPrice(price: number, discount: number
19
19
  * @param decimal - The number of decimal places to round to (default is 2).
20
20
  *
21
21
  * @example
22
- * ```
22
+ * ```ts
23
23
  * calculateDiscountAmount(100, 10, 1); // returns 10.0
24
24
  * ```
25
25
  */
26
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
+ *
34
+ * @example
35
+ * ```ts
36
+ * calculatePercentageProfit(100, 80); // Returns 20.00
37
+ * calculatePercentageProfit(100, 80, 1, false); // Returns 25.0
38
+ * ```
39
+ */
40
+ export declare function calculatePercentageProfit(marketPrice: number, salePrice: number, decimal?: number): number;
41
+ /**
42
+ * Calculates the discount percentage between the market price and the sale price for discount.
43
+ *
44
+ * @param marketPrice - The original market price of the item.
45
+ * @param salePrice - The sale price of the item.
46
+ * @param decimal - The number of decimal places to round the result to(optional with default value = 2).
47
+ *
48
+ * @example
49
+ * ```ts
50
+ * calculatePercentageDiscount(100, 80); // Returns 20.00
51
+ * calculatePercentageDiscount(100, 80, 1, false); // Returns 25.0
52
+ * ```
53
+ */
54
+ export declare function calculatePercentageDiscount(marketPrice: number, salePrice: number, decimal?: number): number;
27
55
  //# sourceMappingURL=main.d.ts.map
@@ -1 +1 @@
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"}
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;;;;;;;;;;;;GAYG;AACH,wBAAgB,yBAAyB,CAAC,WAAW,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,OAAO,SAAI,GAAG,MAAM,CAKrG;AAED;;;;;;;;;;;;GAYG;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.1 */
1
+ /* @nexim/financial-calculate v1.0.0 */
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.1");
6
+ __dev_mode__: packageTracer.add("@nexim/financial-calculate", "1.0.0");
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,20 @@ 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
- /*! For license information please see main.mjs.LEGAL.txt */
23
34
  //# 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 * ```\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"],
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;",
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 * ```ts\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 * ```ts\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 *\n * @example\n * ```ts\n * calculatePercentageProfit(100, 80); // Returns 20.00\n * calculatePercentageProfit(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 *\n * @example\n * ```ts\n * calculatePercentageDiscount(100, 80); // Returns 20.00\n * calculatePercentageDiscount(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,SAAS,oBAAoB;AAC7B,SAAS,qBAAqB;AAE9B,aAAc,eAAc,IAAI,8BAAkB,OAAmB;AAErE,IAAM,SAAS,aAAa,4BAAgB;AAcrC,SAAS,yBAAyB,OAAe,UAAkB,UAAU,GAAW;AAC7F,SAAO,gBAAgB,4BAA4B,EAAE,OAAO,UAAU,QAAQ,CAAC;AAE/E,QAAM,kBAAkB,SAAS,IAAI,WAAW;AAChD,SAAO,WAAW,gBAAgB,QAAQ,OAAO,CAAC;AACpD;AAcO,SAAS,wBAAwB,OAAe,UAAkB,UAAU,GAAW;AAC5F,SAAO,gBAAgB,2BAA2B,EAAE,OAAO,UAAU,QAAQ,CAAC;AAE9E,QAAM,iBAAkB,QAAQ,WAAY;AAC5C,SAAO,WAAW,eAAe,QAAQ,OAAO,CAAC;AACnD;AAeO,SAAS,0BAA0B,aAAqB,WAAmB,UAAU,GAAW;AACrG,SAAO,gBAAgB,6BAA6B,EAAE,aAAa,WAAW,QAAQ,CAAC;AAEvF,QAAM,cAAe,cAAc,aAAa,YAAa;AAC7D,SAAO,WAAW,WAAW,QAAQ,OAAO,CAAC;AAC/C;AAeO,SAAS,4BAA4B,aAAqB,WAAmB,UAAU,GAAW;AACvG,SAAO,gBAAgB,+BAA+B,EAAE,aAAa,WAAW,QAAQ,CAAC;AAEzF,QAAM,cAAe,cAAc,aAAa,cAAe;AAC/D,SAAO,WAAW,WAAW,QAAQ,OAAO,CAAC;AAC/C;",
6
6
  "names": []
7
7
  }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=main.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"main.test.d.ts","sourceRoot":"","sources":["../src/main.test.js"],"names":[],"mappings":""}
package/docs/README.md ADDED
@@ -0,0 +1,10 @@
1
+ # @nexim/financial-calculate
2
+
3
+ ## Functions
4
+
5
+ | Function | Description |
6
+ | ----------------------------------------------------------------------- | -------------------------------------------------------------------------------------------- |
7
+ | [calculateDiscountAmount](functions/calculateDiscountAmount.md) | Calculate the discount amount from the original price. |
8
+ | [calculateDiscountedPrice](functions/calculateDiscountedPrice.md) | Calculate the price after applying a discount. |
9
+ | [calculatePercentageDiscount](functions/calculatePercentageDiscount.md) | Calculates the discount percentage between the market price and the sale price for discount. |
10
+ | [calculatePercentageProfit](functions/calculatePercentageProfit.md) | Calculates the discount percentage between the market price and the sale price for profit. |
@@ -0,0 +1,25 @@
1
+ [@nexim/financial-calculate](../README.md) / calculateDiscountAmount
2
+
3
+ # Function: calculateDiscountAmount()
4
+
5
+ > **calculateDiscountAmount**(`price`: `number`, `discount`: `number`, `decimal`: `number`): `number`
6
+
7
+ Calculate the discount amount from the original price.
8
+
9
+ ## Parameters
10
+
11
+ | Parameter | Type | Default value | Description |
12
+ | ---------- | -------- | ------------- | -------------------------------------------------------- |
13
+ | `price` | `number` | `undefined` | The original price. |
14
+ | `discount` | `number` | `undefined` | The discount percentage. |
15
+ | `decimal` | `number` | `2` | The number of decimal places to round to (default is 2). |
16
+
17
+ ## Returns
18
+
19
+ `number`
20
+
21
+ ## Example
22
+
23
+ ```ts
24
+ calculateDiscountAmount(100, 10, 1); // returns 10.0
25
+ ```
@@ -0,0 +1,25 @@
1
+ [@nexim/financial-calculate](../README.md) / calculateDiscountedPrice
2
+
3
+ # Function: calculateDiscountedPrice()
4
+
5
+ > **calculateDiscountedPrice**(`price`: `number`, `discount`: `number`, `decimal`: `number`): `number`
6
+
7
+ Calculate the price after applying a discount.
8
+
9
+ ## Parameters
10
+
11
+ | Parameter | Type | Default value | Description |
12
+ | ---------- | -------- | ------------- | -------------------------------------------------------- |
13
+ | `price` | `number` | `undefined` | The original price. |
14
+ | `discount` | `number` | `undefined` | The discount percentage to apply. |
15
+ | `decimal` | `number` | `2` | The number of decimal places to round to (default is 2). |
16
+
17
+ ## Returns
18
+
19
+ `number`
20
+
21
+ ## Example
22
+
23
+ ```ts
24
+ calculateDiscountedPrice(100, 10, 1); // returns 90.0
25
+ ```
@@ -0,0 +1,26 @@
1
+ [@nexim/financial-calculate](../README.md) / calculatePercentageDiscount
2
+
3
+ # Function: calculatePercentageDiscount()
4
+
5
+ > **calculatePercentageDiscount**(`marketPrice`: `number`, `salePrice`: `number`, `decimal`: `number`): `number`
6
+
7
+ Calculates the discount percentage between the market price and the sale price for discount.
8
+
9
+ ## Parameters
10
+
11
+ | Parameter | Type | Default value | Description |
12
+ | ------------- | -------- | ------------- | ------------------------------------------------------------------------------------- |
13
+ | `marketPrice` | `number` | `undefined` | The original market price of the item. |
14
+ | `salePrice` | `number` | `undefined` | The sale price of the item. |
15
+ | `decimal` | `number` | `2` | The number of decimal places to round the result to(optional with default value = 2). |
16
+
17
+ ## Returns
18
+
19
+ `number`
20
+
21
+ ## Example
22
+
23
+ ```ts
24
+ calculatePercentageDiscount(100, 80); // Returns 20.00
25
+ calculatePercentageDiscount(100, 80, 1, false); // Returns 25.0
26
+ ```
@@ -0,0 +1,26 @@
1
+ [@nexim/financial-calculate](../README.md) / calculatePercentageProfit
2
+
3
+ # Function: calculatePercentageProfit()
4
+
5
+ > **calculatePercentageProfit**(`marketPrice`: `number`, `salePrice`: `number`, `decimal`: `number`): `number`
6
+
7
+ Calculates the discount percentage between the market price and the sale price for profit.
8
+
9
+ ## Parameters
10
+
11
+ | Parameter | Type | Default value | Description |
12
+ | ------------- | -------- | ------------- | ------------------------------------------------------------------------------------- |
13
+ | `marketPrice` | `number` | `undefined` | The original market price of the item. |
14
+ | `salePrice` | `number` | `undefined` | The sale price of the item. |
15
+ | `decimal` | `number` | `2` | The number of decimal places to round the result to(optional with default value = 2). |
16
+
17
+ ## Returns
18
+
19
+ `number`
20
+
21
+ ## Example
22
+
23
+ ```ts
24
+ calculatePercentageProfit(100, 80); // Returns 20.00
25
+ calculatePercentageProfit(100, 80, 1, false); // Returns 25.0
26
+ ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nexim/financial-calculate",
3
- "version": "1.0.0-alpha.1",
3
+ "version": "1.0.0",
4
4
  "description": "Provides a set of utils to handle common financial operations.",
5
5
  "keywords": [
6
6
  "financial",
@@ -40,20 +40,24 @@
40
40
  ],
41
41
  "scripts": {
42
42
  "build": "wireit",
43
+ "doc": "wireit",
43
44
  "test": "wireit",
44
45
  "watch": "wireit"
45
46
  },
46
47
  "dependencies": {
47
- "@alwatr/logger": "^5.0.0",
48
- "@alwatr/package-tracer": "^5.0.0"
48
+ "@alwatr/logger": "^5.5.2",
49
+ "@alwatr/package-tracer": "^5.5.2"
49
50
  },
50
51
  "devDependencies": {
51
- "@alwatr/nano-build": "^5.0.0",
52
- "@alwatr/type-helper": "^5.0.0",
52
+ "@alwatr/nano-build": "^5.5.2",
53
+ "@alwatr/type-helper": "^5.4.0",
53
54
  "@nexim/typescript-config": "^2.0.0",
54
55
  "ava": "^6.2.0",
55
- "typescript": "^5.7.2",
56
- "wireit": "^0.14.9"
56
+ "typedoc": "^0.28.3",
57
+ "typedoc-plugin-markdown": "^4.6.2",
58
+ "typedoc-plugin-no-inherit": "^1.6.1",
59
+ "typescript": "^5.8.3",
60
+ "wireit": "^0.14.12"
57
61
  },
58
62
  "publishConfig": {
59
63
  "access": "public"
@@ -100,7 +104,10 @@
100
104
  "watch:es": {
101
105
  "command": "nano-build --preset=module -- --watch",
102
106
  "service": true
107
+ },
108
+ "doc": {
109
+ "command": "typedoc"
103
110
  }
104
111
  },
105
- "gitHead": "67de35829cde30ef70d87361d7f104762f6ccfd5"
112
+ "gitHead": "c70cf0dac578a3386bc942657a89a67d20b56ba8"
106
113
  }
package/src/main.test.js CHANGED
@@ -1,39 +1,33 @@
1
+ import {
2
+ calculateDiscountAmount,
3
+ calculateDiscountedPrice,
4
+ calculatePercentageDiscount,
5
+ calculatePercentageProfit,
6
+ } from '@nexim/financial-calculate';
1
7
  import test from 'ava';
2
8
 
3
- import {calculateDiscountAmount, calculateDiscountedPrice} from '@nexim/financial-calculate';
4
-
5
- test('calculate discount from price with: 3, 4 input', (test) => {
9
+ test('calculate discount from price', (test) => {
6
10
  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) => {
11
+ test.is(calculateDiscountAmount(100, 10), 10);
18
12
  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
13
  test.is(calculateDiscountAmount(15034, 73), 10974.82);
14
+ test.is(calculateDiscountAmount(54205, 1332, 5), 722010.6);
27
15
  });
28
16
 
29
- test('calculate price from discount with: 15034, 73 input', (test) => {
17
+ test('calculate price from discount', (test) => {
18
+ test.is(calculateDiscountedPrice(3, 4), 2.88);
19
+ test.is(calculateDiscountedPrice(100, 10), 90);
30
20
  test.is(calculateDiscountedPrice(15034, 73), 4059.18);
21
+ test.is(calculateDiscountedPrice(587, 629), -3105.23);
22
+ test.is(calculateDiscountedPrice(54205, 1332, 5), -667805.6);
31
23
  });
32
24
 
33
- test('calculate discount from price with: 54205, 1332, 5 input', (test) => {
34
- test.is(calculateDiscountAmount(54205, 1332, 5), 722010.6);
25
+ test('calculate discount percentage for profit and discount', (test) => {
26
+ test.is(calculatePercentageProfit(100, 80), 25);
27
+ test.is(calculatePercentageProfit(100, 53), 88.68);
35
28
  });
36
29
 
37
- test('calculate price from discount with: 54205, 1332, 5 input', (test) => {
38
- test.is(calculateDiscountedPrice(54205, 1332, 5), -667805.6);
30
+ test('calculate discount percentage for profit', (test) => {
31
+ test.is(calculatePercentageDiscount(100, 80, 1), 20);
32
+ test.is(calculatePercentageDiscount(100, 53), 47);
39
33
  });
File without changes
File without changes