New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

next-biz-date

Package Overview
Dependencies
Maintainers
1
Versions
26
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

next-biz-date - npm Package Compare versions

Comparing version 1.0.0 to 1.0.1

57

main.js
(() => {
const moment = require("moment");
/**
* Find a business date by shifting a base date by a provided offset in the provided direction. It leverages the findBizDate() function.
* @param {String} baseDate String of YYYY-MM-DD format or Moment object
* @param {Array} holidaysArray Array of strings of YYYY-MM-DD format
* @param {Int} offset
* @param {String} direction with content of "FORWARD" or "BACKWARDS"
* @returns {main=>#1.findBizDate.mCandidateDate|moment}
*/
/**
* Find a business date by shifting a base date by a provided offset in the provided direction. It leverages the findBizDate() function.
* @param {String} baseDate String of YYYY-MM-DD format or Moment object
* @param {Array} holidaysArray Array of strings of YYYY-MM-DD format
* @param {Int} offset
* @param {String} direction with content of "FORWARD" or "BACKWARDS"
* @returns {main=>#1.findBizDate.mCandidateDate|moment}
*/
function findNextBizDate(baseDate, holidaysArray, offset, direction) {

@@ -55,22 +55,9 @@ if (!offset) {

if (holidaysArray === undefined || holidaysArray.length === undefined || holidaysArray.length === 0) {
console.warn("Holidays Array is Empty");
return mCandidateDate;
}
//SCAN the HolyDays array and use recursion
let initial, increment, exitCondition;
if (direction === "FORWARD") {
initial = 0;
increment = 1;
exitCondition = (value) => {
return value < holidaysArray.length;
};
} else {
initial = holidaysArray.length - 1;
increment = -1;
exitCondition = (value) => {
return value >= 0;
};
}
for (var i = initial; exitCondition(i); i += increment) {
let directionLogic = getDirectionLogic(direction, holidaysArray);
for (var i = directionLogic.initial; directionLogic.exitCondition(i); i += directionLogic.increment) {
let item = holidaysArray[i];

@@ -95,5 +82,23 @@ const mHoliday = moment(item);

}
function getDirectionLogic(direction, holidaysArray) {
let result = {};
if (direction === "FORWARD") {
result.initial = 0;
result.increment = 1;
result.exitCondition = (value) => {
return value < holidaysArray.length;
};
} else {
result.initial = holidaysArray.length - 1;
result.increment = -1;
result.exitCondition = (value) => {
return value >= 0;
};
}
return result;
}
exports.FindBizDate = findBizDate;
exports.FindNextBizDate = findNextBizDate;
})();
{
"name": "next-biz-date",
"version": "1.0.0",
"version": "1.0.1",
"description": "returns the next future business date based on a reference date and a number of days to look into the future and given array of holidays",

@@ -5,0 +5,0 @@ "main": "main.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