Introduction
公式データを正とし、利用者が誤判定リスクを背負わないことを最優先にした設計。
What is @liha-labs/holiday?
@liha-labs/holiday は、日本の祝日データを扱うための TypeScript ライブラリです。 春分・秋分などの計算ロジックは持たず、公式データの結果だけを返します。
Design goals
- official-first祝日判定は公式データ準拠
- strict input日付文字列は YYYY-MM-DD / YYYY-MM を厳密検証
- runtime-lightランタイム依存ゼロ
- portablefetch差し替えで Node / Browser 対応
Non-goals
- 祝日計算独自アルゴリズムで祝日を算出しない
- 曖昧な日付変換YYYY-MM-DD 以外の文字列は受け付けない
- データの自動補完存在しない年を推測して生成しない
Features
運用をシンプルに保ちながら、実利用に必要な機能を提供します。
Compatibility
Quick Start
最小限の導入で、公式データ準拠の祝日判定をすぐ利用できます。
Install
標準として pnpm を推奨します。
$ pnpm add @liha-labs/holidayBasic Lookup
祝日名と詳細(曜日付き)を取得します。
import { holidayName, getHoliday } from '@liha-labs/holiday'
const name = await holidayName('2026-01-01')
const detail = await getHoliday('2026-01-01')List APIs
月・範囲で一覧取得できます。
import { listMonth, listRange } from '@liha-labs/holiday'
const january = await listMonth('2026-01')
const spring = await listRange('2026-03-01', '2026-05-31')Strict Input
文字列入力は厳密に検証されます。
import { holidayName } from '@liha-labs/holiday'
await holidayName('2026-01-01') // OK
await holidayName('2026-1-1') // Error: YYYY-MM-DD のみ許可
await holidayName('2026-02-30') // Error: 暦上不正Usage
実運用で使う主要パターンを、実装仕様に沿って整理。
Top-level Functions
最小コードで使うならトップレベル関数が最短です。
import { holidayName, isHoliday, getHoliday } from '@liha-labs/holiday'
await holidayName('2026-01-01')
await isHoliday('2026-01-02')
await getHoliday('2026-01-01')createClient(options)
remote base URL / fetch 実装 / キャッシュ戦略を差し替える場合はクライアントを生成します。
import { createClient } from '@liha-labs/holiday'
const client = createClient({
remoteBaseUrl: 'https://raw.githubusercontent.com/liha-labs/holiday/main',
fetch: globalThis.fetch,
cache: 'memory',
})
await client.listYear(2023)Date Input Rules
import { listMonth, holidayName } from '@liha-labs/holiday'
await holidayName(new Date())
await holidayName('2026-01-01')
await listMonth('2026-01')
// 以下は例外
await holidayName('2026/01/01')
await holidayName('2026-1-1')Range and All
import { listRange, listAll, info } from '@liha-labs/holiday'
const selected = await listRange('2026-01-01', '2026-12-31')
const all = await listAll()
const meta = info()
console.log(meta.fullRange)Full Entry
@liha-labs/holiday/full は全期間同梱で、remote 取得を使いません。
import { listYear, createClient } from '@liha-labs/holiday/full'
await listYear(1960)
const fullClient = createClient()
await fullClient.listAll()API Reference
実装済みAPIと返り値仕様。
createClient(options?)
HolidayClient インスタンスを生成します。
createClient(options?: ClientOptions): HolidayClientTop-level Functions
holidayName(input): Promise<string | null>isHoliday(input): Promise<boolean>getHoliday(input): Promise<HolidayDetail | null>listYear(year): Promise<HolidayDetail[]>listMonth(ym): Promise<HolidayDetail[]>listRange(start, end): Promise<HolidayDetail[]>listAll(): Promise<HolidayDetail[]>info(): InfoCore Types
{ date: "YYYY-MM-DD"; name: string }Holiday & { weekday: 0 | 1 | 2 | 3 | 4 | 5 | 6 }generatedAt, bundledYears, fullRange, source, remote を返しま す。
ClientOptions
string年別JSON取得先のベースURL。
typeof globalThis.fetch取得時に使う fetch 実装。
"memory" | "none"memory は年ごとに Promise をメモ化し、同時多重fetchを抑止します。
Behavior Notes
YYYY-MM-DD(または listMonth の YYYY-MM)以外は例外。getFullYear/getMonth/getDate で正規化。new Date(y, m - 1, d).getDay() でランタイム算出。Examples
実装済みAPIのみを使ったサンプル。
Basic Lookup
祝日名と詳細(weekday付き)を取得します。
import { holidayName, getHoliday } from '@liha-labs/holiday'
const name = await holidayName('2026-01-01')
const detail = await getHoliday('2026-01-01')Date Input
Date オブジェクトはローカル日付として解釈されます。
import { isHoliday } from '@liha-labs/holiday'
const today = new Date()
const result = await isHoliday(today)Custom Client
取得先URLやキャッシュ戦略を差し替える例です。
import { createClient } from '@liha-labs/holiday'
const client = createClient({
remoteBaseUrl: 'https://raw.githubusercontent.com/liha-labs/holiday/main',
cache: 'memory',
fetch: globalThis.fetch,
})
const holidays = await client.listYear(2023)Full Entry
@liha-labs/holiday/full は remote 取得を使わず、同じAPIで返します。
import { listAll, listYear } from '@liha-labs/holiday/full'
await listYear(1968)
await listAll()