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

holiday-check

v1.0.3

Published

A CLI tool to find out if a date is a holiday using the Google Calendar API.

Downloads

36

Readme

holiday-check

npm version build

Google Calendar APIを利用し、指定日付が祝休日であるかをチェックする機能を提供します。
「定期実行で平日に回しているシェルだけど祝日は処理をスキップさせたい」等のケースで使う事を想定した作りになっています。

利用方法

共通

GCPのコンソールからGoogle Calendar APIを有効化します。
その後、API実行に使用するサービスアカウントを作成し、秘密鍵をJSONタイプで保存しておきます。

CLI実行

CLIツールとして利用する場合、コマンドを実行するディレクトリ直下に事前の手順で作成した秘密鍵をkey.jsonとして配置し、下記コマンドを実行します。

# インストールしない場合
npx holiday-check

# インストールする場合
npm install -g holiday-check
holiday-check

実行時の日付が平日の場合は0が、休日の場合は1が戻り値として返却されます。
また、任意の日付をチェックする場合は第一引数にYYYY-MM-DD形式で渡すことでその日付がチェック対象となります。

環境変数で一部挙動の設定することが出来ます。
環境変数の一覧は下記の通りです。

| 変数名 | デフォルト値 | 説明 | | --------------------------------------------------------- | ------------------------------------------------- | ------------------------------------------------------------ | | NODE_HOLIDAY_CHECKER_GOOGLE_CALENDAR_ID | ja.japanese#[email protected] | 祝日として判定するGoogleカレンダーのIDを指定します。デフォルトは日本の祝日カレンダーが設定されています。複数設定する場合は;区切りとします。個人のカレンダーも利用可能です。(サービスアカウントに対象カレンダーの参照権限が付与されている前提) | | NODE_HOLIDAY_CHECKER_GOOGLE_SERVICE_ACCOUNT_KEY_JSON_PATH | key.json | サービスアカウントの鍵ファイルのパスを設定します。フルパスも指定可能です。 | | NODE_HOLIDAY_CHECKER_TIMEZONE | なし | 実行日付を取得する際にタイムゾーンを固定したい場合にAsia/Tokyoの様にタイムゾーンを設定します。指定をしない場合は実行環境のタイムゾーンに依存します。 | | HOLIDAY_WEEKDAYS | 0;6 | 休日として扱う曜日を設定します。デフォルトは土日が休日に設定されています。 |

シェルスクリプトへの組み込み例

#!/bin/bash

export NODE_HOLIDAY_CHECKER_GOOGLE_CALENDAR_ID="ja.japanese#[email protected];[email protected]"
export NODE_HOLIDAY_CHECKER_GOOGLE_SERVICE_ACCOUNT_KEY_JSON_PATH="/etc/holiday-check/key.json"
holiday-check
if [ $? = 1 ]; then
  echo "祝日のため、処理を終了します"
  exit 0
fi

ライブラリ利用

ライブラリとして利用する場合はnpm install holiday-check等でインストールの上、下記の例を参考に処理を実装してください。

// インポート
import {HolidayCheck} from "holiday-check";

...

// インスタンス化
const holidayCheck = await HolidayCheck.instance({
  // 祝日情報を取得するGoogleカレンダーのID(複数可)
  googleCalendarIdList: ['ja.japanese#[email protected]'],

  // Google APIを実行するためのサービスアカウント鍵ファイル(JSON形式)へのパス
  googleServiceAccountKeyJsonPath: 'key.json',

  // 土日を休日として扱う
  holidayWeekdays: [0, 6]
});

// 休日判定実行
const isHoliday = await holidayCheck.isHoliday('2021-01-01');

if (isHoliday) {
  console.info('休日です');
} else {
  console.info('平日です');
}