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

installment-calculations

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

installment-calculations - npm Package Compare versions

Comparing version 0.0.1 to 0.0.2

54

index.js

@@ -1,2 +0,2 @@

const moment = require('moment'),
var moment = require('moment'),
WEEKLY = 'WEEKLY',

@@ -9,3 +9,3 @@ MONTHLY = 'MONTHLY';

// Find number of weekly or monthly installments between two dates.
getNumberOfInstallments(startDate, endDate, interval) {
getNumberOfInstallments: function(startDate, endDate, interval) {
if (interval === MONTHLY) {

@@ -22,3 +22,3 @@ return this.numberOfMonthsBetween(startDate, endDate) + 1;

// and the number of transactions. The return value is approximate.
calculateInstallmentAmount(savingsTarget, numberOfInstallments) {
calculateInstallmentAmount: function(savingsTarget, numberOfInstallments) {
return Math.floor(savingsTarget / numberOfInstallments);

@@ -28,5 +28,5 @@ },

// Use this when we're in charge of calculating the installmentAmount
calculateLastInstallmentAmount(savingsTarget, numberOfInstallments) {
const installmentAmount = this.calculateInstallmentAmount(savingsTarget, numberOfInstallments);
const installmentsMinusOne = numberOfInstallments - 1;
calculateLastInstallmentAmount: function(savingsTarget, numberOfInstallments) {
var installmentAmount = this.calculateInstallmentAmount(savingsTarget, numberOfInstallments);
var installmentsMinusOne = numberOfInstallments - 1;

@@ -37,5 +37,5 @@ return savingsTarget - (installmentAmount * installmentsMinusOne);

// Use this when the installmentAmount is set by the User.
calculateLastInstallmentAmountFixed(savingsTarget, installmentAmount, numberOfInstallments) {
const total = installmentAmount * numberOfInstallments;
const lastInstallmentAmount = installmentAmount - (total - savingsTarget);
calculateLastInstallmentAmountFixed: function(savingsTarget, installmentAmount, numberOfInstallments) {
var total = installmentAmount * numberOfInstallments;
var lastInstallmentAmount = installmentAmount - (total - savingsTarget);

@@ -47,3 +47,3 @@ return lastInstallmentAmount === 0 ? installmentAmount : lastInstallmentAmount;

// and amount per installment
calculateInstallmentNumber(savingsTarget, installmentAmount) {
calculateInstallmentNumber: function(savingsTarget, installmentAmount) {
return Math.ceil(savingsTarget / installmentAmount);

@@ -53,4 +53,4 @@ },

// check if installment amounts are unequal.
installmentAmountsAreUnequal(savingsTarget, numberOfInstallments) {
const installmentAmount = savingsTarget / numberOfInstallments;
installmentAmountsAreUnequal: function(savingsTarget, numberOfInstallments) {
var installmentAmount = savingsTarget / numberOfInstallments;

@@ -61,5 +61,5 @@ return installmentAmount.toString().indexOf('.') > -1 ? true : false;

// find the number of full weeks between two dates.
numberOfWeeksBetween(startDate, endDate) {
const start = moment(startDate).hours(0).minutes(0).seconds(0);
const end = moment(endDate).hours(0).minutes(0).seconds(0);
numberOfWeeksBetween: function(startDate, endDate) {
var start = moment(startDate).hours(0).minutes(0).seconds(0);
var end = moment(endDate).hours(0).minutes(0).seconds(0);

@@ -70,5 +70,5 @@ return end.diff(start, 'week');

// find the number of full months between two dates.
numberOfMonthsBetween(startDate, endDate) {
const start = moment(startDate).hours(0).minutes(0).seconds(0);
const end = moment(endDate).hours(0).minutes(0).seconds(0);
numberOfMonthsBetween: function(startDate, endDate) {
var start = moment(startDate).hours(0).minutes(0).seconds(0);
var end = moment(endDate).hours(0).minutes(0).seconds(0);

@@ -79,5 +79,5 @@ return end.diff(start, 'month');

// Get the date for the next time the date of month occurs
getNextInstanceOfDate(dayOfMonth, startDate) {
const currentDate = moment(startDate).startOf('day');
const currentDateOfMonth = currentDate.clone().date();
getNextInstanceOfDate: function(dayOfMonth, startDate) {
var currentDate = moment(startDate).startOf('day');
var currentDateOfMonth = currentDate.clone().date();

@@ -93,5 +93,5 @@ if (currentDateOfMonth > dayOfMonth || currentDateOfMonth === dayOfMonth) {

// dayOfWeek is given as an integer with 1 being Monday.
getNextInstanceOfDay(dayOfWeek, startDate) {
const fromDate = moment(startDate).startOf('day');
const currentDay = fromDate.clone().weekday();
getNextInstanceOfDay: function(dayOfWeek, startDate) {
var fromDate = moment(startDate).startOf('day');
var currentDay = fromDate.clone().weekday();

@@ -106,3 +106,3 @@ if (currentDay > dayOfWeek || currentDay === dayOfWeek) {

// Takes to date object and checks if they're the same date
isSameDay(dateA, dateB) {
isSameDay: function(dateA, dateB) {
return moment(dateA).isSame(moment(dateB), 'day');

@@ -112,7 +112,7 @@ },

// Set the time of a date to 00:00:00, return js date object.
normalizeDate(date) {
normalizeDate: function(date) {
return moment(date).startOf('day').toDate();
},
daysLeft(from, to) {
daysLeft: function(from, to) {
return moment(to).diff(moment(from), 'days');

@@ -119,0 +119,0 @@ }

{
"name": "installment-calculations",
"version": "0.0.1",
"version": "0.0.2",
"description": "Calculate payment installments (and other useful details) based on start/end dates, interval and target amount",

@@ -5,0 +5,0 @@ "main": "index.js",

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