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

asset-depreciation-calculator

Package Overview
Dependencies
Maintainers
6
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 1.1.0 to 1.2.0

37

dist/index.js

@@ -23,9 +23,10 @@ "use strict";

exports.assertDepreciationYears = assertDepreciationYears;
const calculate = (purchaseAmount, totalDepreciationYears, previousEndAmount, monthsLeft = MONTHS_IN_YEAR) => {
const calculate = (purchaseAmount, totalDepreciationYears, previousEndAmount, monthsLeft, isLastPart) => {
const depreciationAmount = Math.round((purchaseAmount / totalDepreciationYears / MONTHS_IN_YEAR) * monthsLeft);
const newEndAmount = previousEndAmount - depreciationAmount;
// Because of the rounding, even if the calculation is correct, sometimes there is €0.01 left over.
// Because of the rounding, even if the calculation is correct, sometimes there is €0.01 left over in the last part.
// For example, if total is 31, divided by 3 it would be 10 / 10 / 10.
// Also, there's a case, such as 29, where it returns negative result.
if (newEndAmount <= 1) {
// Therefore, we explicitly depreciate the previous year’s end amount in the last part.
if (isLastPart) {
return {

@@ -53,3 +54,2 @@ depreciationAmount: previousEndAmount,

let endAmount = purchaseAmount;
let monthsLeftInLastYear = 0;
if (totalDepreciationYears === 0) {

@@ -65,22 +65,13 @@ return [{

}
for (let index = 0; index < totalDepreciationYears; index++) {
// Current year
if (index === 0) {
const monthsLeftInFirstYear = MONTHS_IN_YEAR - purchaseMonth + 1;
const result = calculate(purchaseAmount, totalDepreciationYears, endAmount, monthsLeftInFirstYear);
results.push(Object.assign({ year: purchaseYear, depreciationMonths: monthsLeftInFirstYear }, result));
endAmount = result.endAmount;
// If item is purchased in Jan, monthsLeftInLastYear is 0
// If item is purchased in Dec, monthsLeftInLastYear is 11
monthsLeftInLastYear = MONTHS_IN_YEAR - monthsLeftInFirstYear;
}
else { // Future years
const result = calculate(purchaseAmount, totalDepreciationYears, endAmount);
results.push(Object.assign({ year: purchaseYear + index, depreciationMonths: MONTHS_IN_YEAR }, result));
endAmount = result.endAmount;
}
const parts = purchaseMonth > 1 ? totalDepreciationYears + 1 : totalDepreciationYears;
const monthsInEachYear = Array(parts).fill(MONTHS_IN_YEAR);
// Months in fisrt year
monthsInEachYear[0] = MONTHS_IN_YEAR - purchaseMonth + 1;
// Months in last year
monthsInEachYear[monthsInEachYear.length - 1] = purchaseMonth > 1 ? purchaseMonth - 1 : MONTHS_IN_YEAR;
for (let index = 0; index < parts; index++) {
const result = calculate(purchaseAmount, totalDepreciationYears, endAmount, monthsInEachYear[index], index === parts - 1);
results.push(Object.assign({ year: purchaseYear + index, depreciationMonths: monthsInEachYear[index] }, result));
endAmount = result.endAmount;
}
if (monthsLeftInLastYear > 0) {
results.push(Object.assign({ year: purchaseYear + totalDepreciationYears, depreciationMonths: monthsLeftInLastYear }, calculate(purchaseAmount, totalDepreciationYears, endAmount, monthsLeftInLastYear)));
}
return results;

@@ -87,0 +78,0 @@ };

{
"name": "asset-depreciation-calculator",
"version": "1.1.0",
"version": "1.2.0",
"description": "Asset Depreciation Calculator",

@@ -27,3 +27,3 @@ "keywords": [

"@types/mocha": "^8.2.2",
"@typescript-eslint/eslint-plugin": "^4.22.1",
"@typescript-eslint/eslint-plugin": "^4.33.0",
"@typescript-eslint/parser": "^4.22.1",

@@ -30,0 +30,0 @@ "expect": "^26.6.2",

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