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

brazilianholiday

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

brazilianholiday - npm Package Compare versions

Comparing version 1.0.7 to 1.0.8

2

package.json
{
"name": "brazilianholiday",
"version": "1.0.7",
"version": "1.0.8",
"description": "Biblioteca para feriados brasileiros no âmbito nacional e estadual",

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

@@ -36,3 +36,3 @@ # Brazilian Holiday

console.log(brazilianHolidays.isHoliday(date));
console.log(brazilianHoliday.isHoliday(date));

@@ -42,5 +42,4 @@ /*

holiday: true,
date: '01/01/2023',
description: 'Confraternização Universal',
state: false
date: '01/01/2024'
}

@@ -51,10 +50,9 @@ */

console.log(brazilianHolidays.isHoliday(date, 'AC'));
console.log(brazilianHoliday.isHoliday(date, 'AC'));
/*
{
holiday: true,
date: '20/01/2023',
description: 'Dia do Católico',
state: true
{
holiday: true,
description: 'Dia do Católico',
date: '20/01/2024'
}

@@ -68,3 +66,3 @@ */

* 1.0.6
* 1.0.8 [ESTÁVEL]
* FEAT: function isHoliday

@@ -98,3 +96,3 @@

## License:
## Licença:

@@ -101,0 +99,0 @@ MIT © Otávio Silva 2023

@@ -233,7 +233,2 @@ {

{
"date": "EXCEPTION",
"description": "Dia do Comércio",
"note": "3º segunda-feira de outubro"
},
{
"date": "20/11",

@@ -240,0 +235,0 @@ "description": "Dia da Consciência Negra"

@@ -8,7 +8,8 @@ const {moveable, national, state} = require('./holidays.json')

function validate({day, month, year}){
function validate(date){
if(day.length != 2 || month.length != 2 || year.length != 4){
let regex = /^(\d{2})\/(\d{2})\/(\d{4})$/.test(date);
if (!regex)
return false;
}

@@ -19,51 +20,96 @@ return true;

function formatDate(date){
let splitDate = date.split('/');
let dateFormated = new Date(`${splitDate[2]}-${splitDate[1]}-${splitDate[0]}T03:00:00`);
const resultValidate = validate(date);
let dayNumber = dateFormated.getDate();
let monthNumber = dateFormated.getMonth() + 1;
if (!resultValidate){
throw new UserException('Invalid format, please use DD/MM/YYYY');
}
let dateSplited = date.split('/');
let dateFormated = new Date(`${dateSplited[2]}-${dateSplited[1]}-${dateSplited[0]}T03:00:00`)
let day = dateFormated.getDate();
let month = dateFormated.getMonth() + 1;
let year = dateFormated.getFullYear();
return {
day: day < 10 ? `0${day}` : day.toString(),
month: month < 10 ? `0${month}` : month.toString(),
year: year.toString()
}
}
let day = dayNumber < 10 ? `0${dayNumber}` : dayNumber.toString();
let month = monthNumber < 10 ? `0${monthNumber}` : monthNumber.toString();
function formatResponse({responseNational, responseState, responseMoveable}, date){
let formatValid = validate({day, month, year: splitDate.pop().toString()})
if (!formatValid || dayNumber > 31 || monthNumber > 12){
throw new UserException('Invalid format, please use DD/MM/YYYY format');
let holiday = false, description = false;
if (responseNational.holiday){
holiday = true,
description = responseNational.description;
}else if(responseMoveable.holiday){
holiday = true,
description = responseMoveable.description;
}else if(responseState.holiday){
holiday = true,
description = responseState.description;
}
return {
dayMonth: `${day}/${month}`,
year: splitDate.pop()
};
holiday,
description,
date
}
}
function isNational(date){
let holiday = national.find(element => element.date == date.dayMonth);
function isMoveable(date){
let dayMonth = `${date.day}/${date.month}`;
let yearFinded = moveable.find(element => element.year == date.year);
if (!holiday && yearFinded){
holiday = yearFinded.holidays.find(element => element.date == date.dayMonth);
if (!yearFinded){
return {
holiday: false,
description: false,
date
}
}
let holiday = yearFinded.holidays.find(element => element.date == dayMonth);
return {
holiday: holiday ? true : false,
date,
description: holiday ? holiday.description : false
description: holiday ? holiday.description : false,
date
}
}
function isNational(date){
let dayMonth = `${date.day}/${date.month}`;
let holiday = national.find(element => element.date == dayMonth);
return {
holiday: holiday ? true : false,
description: holiday ? holiday.description : false,
date
}
}
function isState(date, uf){
if (uf == null){
return {
holiday: false,
description: false,
date
}
}
let ufFinded = state.find(element=> element.uf == uf);
if (!ufFinded){
throw new UserException('Invalid UF');
}
let holiday = null;
let holiday = null;
if (ufFinded && ufFinded.holidays.length > 0){
holiday = ufFinded.holidays.find(element => element.date == date.dayMonth);
let dayMonth = `${date.day}/${date.month}`;
holiday = ufFinded.holidays.find(element => element.date == dayMonth);
}

@@ -73,6 +119,5 @@

holiday: holiday ? true : false,
date,
description: holiday ? holiday.description : false
description: holiday ? holiday.description : false,
date
}
}

@@ -84,11 +129,10 @@

let dateFormated = formatDate(date);
let responseNational = isNational(dateFormated);
let responseState = uf == null ? false : isState(dateFormated, uf);
let responseState = isState(dateFormated, uf);
let responseMoveable = isMoveable(dateFormated);
return {
holiday: responseNational.holiday || (responseState && responseState.holiday) ? true : false,
date,
description: responseNational.holiday ? responseNational.description : (responseState.holiday ? responseState.description : false),
state: responseNational.holiday ? false : (responseState.holiday ? true : false)
}
const response = formatResponse({responseNational, responseState, responseMoveable}, date);
return response;
}catch(e){

@@ -99,3 +143,2 @@ return {

}
}

@@ -102,0 +145,0 @@

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