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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@sway11466/holiday-jp-npm

v0.3.0

Published

Library to judge Japanese national holidays in nodejs.

Downloads

174

Readme

holiday-jp-npm

内閣府ホームページの「国民の祝日」についてに基づいて平日や祝日を判定するライブラリです。
独自の祝日を追加することも可能です。

  • 判定ルール | 日付の種類 | 判定方法 | |------------|----------| | 平日 | 週末でも祝日でもない日 | | 週末 | 土曜日および日曜日(対象となる曜日は設定で変更可能) | | 祝日 | 内閣府ホームページの「国民の祝日」についてに記載の祝日 |

  • 判定の例 例えば2024年5月は以下のように判定します。 | 日付の種類 | 5/1(水) | 5/2(木) | 5/3(金) | 5/4(土) | 5/5(日) | 5/6(月) | 5/7(火) | |------------|---------|---------|---------|---------|---------|---------|---------| | 平日 | 〇 | 〇 | × | × | × | × | 〇 | | 週末 | × | × | × | 〇 | 〇 | × | × | | 祝日 | × | × | 〇 | 〇 | 〇 | 〇 | × |

インストール

npm install @sway11466/holiday-jp-npm

使い方

  • 初期化
    import { useHolidayJP } from '@sway11466/holiday-jp-npm'
    const holidayjp = useHolidayJP();
  • 指定日が祝日であるか判定する
    const ret = holidayjp.isHoliday(new Date(2021, 5-1, 3)); // 2021/5/3 憲法記念日
    console.log(ret); // true
  • 指定日が平日であるか判定する
    const ret = holidayjp.isWeekday(new Date(2021, 5-1, 7)); // 2021/5/7 平日
    console.log(ret); // true
  • 指定した条件に当てはまる祝日を取得する(例1)
    const holidays = holidayjp.get({ year: 2021, month: 5 });
    console.log(holidays.length);  // 3
    console.log(holidays[0].name); // 憲法記念日
    console.log(holidays[0].localDate); // 2021/5/3のDateオブジェクト
  • 指定した条件に当てはまる祝日を取得する(例2)
    const holidays = holidayjp.get({ year: 2021, name: "スポーツの日" });
    console.log(holidays.length);  // 1
    console.log(holidays[0].localDate); // 2021/7/23のDateオブジェクト(日本オリンピックによる特別対応日)
  • 独自の祝日を追加する
    import { useHolidayJP } from '@sway11466/holiday-jp-npm'
    const additional = [{ name: 'test', year: 2023, month: 3, date: 10, localDate: new Date('2023-03-10T00:00:00+09:00') }]; // 金曜日
    const holidayjp = useHolidayJP({ extends: additional });
    const cond = { year: 2023, month: 3, date: 10 };
    const holiday = holidayjp.isHoliday(cond);
    console.log(holiday); // true

説明

  • 1955年~2025年に対応しています
    • 内閣府ホームページで公開しているデータに依存しているためです
    • 対応外の日付を指定するとエラーを起こします
  • このライブラリは実行環境のタイムゾーンを考慮して日本時間での祝日判定を行います
  • 設定で以下の挙動を変更可能です
    • 対応外の日付を指定した場合のエラー発生有無
    • タイムゾーン考慮の有無
    • 週末として扱う曜日
    • 独自の祝日の追加
  • より詳細な情報はdocフォルダ内のドキュメントを参照してください