Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

asset-depreciation-calculator

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

asset-depreciation-calculator - npm Package Compare versions

Comparing version 0.0.5 to 0.0.6

1

dist/index.d.ts

@@ -14,3 +14,4 @@ declare type DepreciationResult = {

};
export declare const toFixedTwo: (num: number) => number;
declare const calculateDepreciation: ({ purchaseAmount, purchaseDate, totalDepreciationYears, }: DepreciationInputs) => DepreciationResult[];
export default calculateDepreciation;

20

dist/index.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.toFixedTwo = void 0;
const MONTHS_IN_YEAR = 12;

@@ -20,6 +21,12 @@ const MINIMUM_PURCHASE_AMOUNT = 800;

};
// Format a float to maximum 2 decimal places.
// 1.1111 => 1.11
// 1.5555 => 1.56
// 1.9999 => 2
// Checkout the unit test for more examples.
const toFixedTwo = (num) => Math.round((num + Number.EPSILON) * 100) / 100;
exports.toFixedTwo = toFixedTwo;
const calculate = (purchaseAmount, totalDepreciationYears, previousEndAmount, monthsLeft = MONTHS_IN_YEAR) => {
const depreciationAmount = toFixedTwo((purchaseAmount / totalDepreciationYears / MONTHS_IN_YEAR) * monthsLeft);
const newEndAmount = toFixedTwo(previousEndAmount - depreciationAmount);
const depreciationAmount = exports.toFixedTwo((purchaseAmount / totalDepreciationYears / MONTHS_IN_YEAR) * monthsLeft);
const newEndAmount = exports.toFixedTwo(previousEndAmount - depreciationAmount);
// Because of the rounding, even if the calculation is correct, sometimes there is €0.01 left over.

@@ -30,3 +37,3 @@ // For example, if total is 3.1, divided by 3 it would be 1.33 / 1.33 / 1.33.

depreciationAmount: previousEndAmount,
percentage: toFixedTwo((previousEndAmount / purchaseAmount) * 100),
percentage: exports.toFixedTwo((previousEndAmount / purchaseAmount) * 100),
startAmount: previousEndAmount,

@@ -38,3 +45,3 @@ endAmount: 0,

depreciationAmount,
percentage: toFixedTwo((depreciationAmount / purchaseAmount) * 100),
percentage: exports.toFixedTwo((depreciationAmount / purchaseAmount) * 100),
startAmount: previousEndAmount,

@@ -53,3 +60,3 @@ endAmount: newEndAmount,

let monthsLeftInLastYear = 0;
// If the price of the good is less than MINIMUM_NET_AMOUNT, the year is set to 0 automatically.
// If the price of the good is less than MINIMUM_PURCHASE_AMOUNT, the year is set to 0 automatically.
if (purchaseAmount < MINIMUM_PURCHASE_AMOUNT) {

@@ -76,4 +83,3 @@ return [{

}
// Future years
if (index > 0) {
else { // Future years
const result = calculate(purchaseAmount, totalDepreciationYears, endAmount);

@@ -80,0 +86,0 @@ results.push(Object.assign({ year: purchaseYear + index, depreciationMonths: MONTHS_IN_YEAR }, result));

{
"name": "asset-depreciation-calculator",
"version": "0.0.5",
"version": "0.0.6",
"description": "Asset Depreciation Calculator",

@@ -5,0 +5,0 @@ "keywords": [

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc