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.7 to 0.0.9

1

dist/index.d.ts

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

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

27

dist/index.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.toFixedTwo = exports.assertDepreciationYears = exports.assertPurchaseDate = exports.assertPurchaseAmount = void 0;
exports.assertDepreciationYears = exports.assertPurchaseDate = exports.assertPurchaseAmount = void 0;
const MONTHS_IN_YEAR = 12;
const MINIMUM_PURCHASE_AMOUNT = 800;
const MINIMUM_PURCHASE_AMOUNT = 80000;
const assertPurchaseAmount = (amount) => {
if (isNaN(amount) || amount < 0) {
if (isNaN(amount) || amount < 0 || amount % 1 !== 0) { // Check if amount is integer, not float.
throw new TypeError('`purchaseAmount` is invalid.');

@@ -24,18 +24,11 @@ }

exports.assertDepreciationYears = assertDepreciationYears;
// 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 = exports.toFixedTwo((purchaseAmount / totalDepreciationYears / MONTHS_IN_YEAR) * monthsLeft);
const newEndAmount = exports.toFixedTwo(previousEndAmount - depreciationAmount);
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.
// For example, if total is 3.1, divided by 3 it would be 1.33 / 1.33 / 1.33.
if (newEndAmount === 0.01) {
// For example, if total is 31, divided by 3 it would be 10 / 10 / 10.
if (newEndAmount === 1) {
return {
depreciationAmount: previousEndAmount,
percentage: exports.toFixedTwo((previousEndAmount / purchaseAmount) * 100),
percentage: previousEndAmount / purchaseAmount,
startAmount: previousEndAmount,

@@ -47,3 +40,3 @@ endAmount: 0,

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

@@ -68,3 +61,3 @@ endAmount: newEndAmount,

depreciationAmount: purchaseAmount,
percentage: 100,
percentage: 1,
startAmount: purchaseAmount,

@@ -71,0 +64,0 @@ endAmount: 0,

{
"name": "asset-depreciation-calculator",
"version": "0.0.7",
"version": "0.0.9",
"description": "Asset Depreciation Calculator",

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

@@ -17,4 +17,4 @@ # asset-depreciation-calculator

calculateDepreciation({
purchaseAmount: 20000,
purchaseDate: new Date("2016-08-01"),
purchaseAmount: 2000000,
purchaseDate: new Date("2016-01-01"),
totalDepreciationYears: 5,

@@ -24,41 +24,34 @@ })

// year: 2016,
// depreciationMonths: 5,
// depreciationAmount: 1666.67,
// percentage: 8.33,
// startAmount: 20000,
// endAmount: 18333.33,
// depreciationMonths: 12,
// depreciationAmount: 400000,
// percentage: 0.2,
// startAmount: 2000000,
// endAmount: 1600000,
// }, {
// year: 2017,
// depreciationMonths: 12,
// depreciationAmount: 4000,
// percentage: 20,
// startAmount: 18333.33,
// endAmount: 14333.33,
// depreciationAmount: 400000,
// percentage: 0.2,
// startAmount: 1600000,
// endAmount: 1200000,
// }, {
// year: 2018,
// depreciationMonths: 12,
// depreciationAmount: 4000,
// percentage: 20,
// startAmount: 14333.33,
// endAmount: 10333.33,
// depreciationAmount: 400000,
// percentage: 0.2,
// startAmount: 1200000,
// endAmount: 800000,
// }, {
// year: 2019,
// depreciationMonths: 12,
// depreciationAmount: 4000,
// percentage: 20,
// startAmount: 10333.33,
// endAmount: 6333.33,
// depreciationAmount: 400000,
// percentage: 0.2,
// startAmount: 800000,
// endAmount: 400000,
// }, {
// year: 2020,
// depreciationMonths: 12,
// depreciationAmount: 4000,
// percentage: 20,
// startAmount: 6333.33,
// endAmount: 2333.33,
// }, {
// year: 2021,
// depreciationMonths: 7,
// depreciationAmount: 2333.33,
// percentage: 11.67,
// startAmount: 2333.33,
// depreciationAmount: 400000,
// percentage: 0.2,
// startAmount: 400000,
// endAmount: 0,

@@ -74,4 +67,6 @@ // }]

Type: `number`
The purchase amount in cents.
Type: `number`.
#### purchaseDate

@@ -78,0 +73,0 @@

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