npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

br-holiday

v2.0.0

Published

A lightweight TypeScript library for checking Brazilian holidays

Downloads

212

Readme

br-holiday

A lightweight TypeScript library for checking Brazilian holidays. Simple, fast, and memory-safe.

Features

  • 🚀 Lightweight: Simple functions, no classes or singletons
  • 📦 Zero Runtime Dependencies: Only uses native fetch API
  • 🗓️ Smart Data Strategy: Static data for current/next year, API fallback for others
  • 🔍 TypeScript Support: Full type definitions included
  • 💾 Memory Safe: No global state, caches, or timers

Installation

npm install br-holiday

Usage

import { getHolidays, isHoliday } from 'br-holiday';

// Get all holidays for a year
const holidays2024 = await getHolidays(2024);
console.log(holidays2024);
// [
//   { date: '2024-01-01', name: 'Confraternização mundial', type: 'national' },
//   { date: '2024-02-13', name: 'Carnaval', type: 'national' },
//   ...
// ]

// Check if a specific date is a holiday
await isHoliday('2024-01-01');                    // true
await isHoliday(new Date('2024-01-01'));          // true
await isHoliday('2024-01-01T00:00:00.000Z');     // true
await isHoliday('2024-01-02');                    // false

API

getHolidays(year: number): Promise<Holiday[]>

Retrieves all holidays for a specific year.

Parameters:

  • year: Year to get holidays for (1900-2100)

Returns: Promise resolving to an array of Holiday objects

Example:

const holidays = await getHolidays(2024);

isHoliday(date: string | Date): Promise<boolean>

Checks if a specific date is a Brazilian holiday.

Parameters:

  • date: Date to check. Accepts:
    • Date object
    • ISO string (e.g., "2024-01-01T00:00:00.000Z")
    • Date string in YYYY-MM-DD format (e.g., "2024-01-01")

Returns: Promise resolving to true if the date is a holiday, false otherwise

Example:

const isNewYear = await isHoliday('2024-01-01'); // true

Types

interface Holiday {
  date: string;  // YYYY-MM-DD format
  name: string;  // Holiday name in Portuguese
  type: string;  // Holiday type (e.g., 'national')
}

How It Works

  1. Static Data: The library includes pre-built holiday data for the current year and next year, providing instant responses without API calls.

  2. API Fallback: For other years, it fetches data from the Brasil API.

  3. No Caching: Each function call is independent. If you need caching, implement it in your application layer.

Error Handling

The library throws descriptive errors for invalid inputs:

try {
  await isHoliday('invalid-date');
} catch (error) {
  // InvalidDateError: Invalid date format. Use Date object, ISO string, or YYYY-MM-DD format
}

try {
  await getHolidays(1800);
} catch (error) {
  // InvalidYearError: Year must be between 1900 and 2100, got 1800
}

Development

# Install dependencies
npm install

# Build the library
npm run build

# Generate static holiday data
npm run build:static

License

MIT

Contributing

Contributions are welcome! Please open an issue or pull request.