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

wareki-converter

v0.2.0

Published

Zero-dependency, ultra-lightweight Japanese era (wareki) ↔ Western calendar converter

Readme

wareki-converter

npm version license bundle size

Zero-dependency, ultra-lightweight converter between the Japanese era calendar (wareki) and the Western calendar.

Features

  • Tiny — < 2 KB (ESM, minified). dayjs + locale + plugin is ~7 KB.
  • Zero dependencies
  • Bidirectional — Western to wareki and wareki to Western
  • Multiple formats — standard, kansuji (Chinese numerals), and short
  • Flexible input — accepts Date objects and date strings (YYYY-MM-DD, YYYY/M/D)
  • TypeScript — written in TypeScript with full type definitions
  • ESM & CJS — works in any environment

Install

npm install wareki-converter

Quick Start

import { toWareki, toWestern } from "wareki-converter";

// Western → Wareki
const result = toWareki("2024-03-08");
result.standard(); // "令和6年3月8日"
result.kansuji();  // "令和六年三月八日"
result.short();    // "R6.3.8"

// Wareki → Western
toWestern("令和6年3月8日"); // Date(2024, 2, 8)

Usage

toWareki — Western to Wareki

Accepts a Date object or a date string.

import { toWareki } from "wareki-converter";

// Date object
const result = toWareki(new Date(2024, 2, 8));

// Date string (hyphen or slash separator)
const result = toWareki("2024-03-08");
const result = toWareki("2024/3/8");

The returned object provides three output formats:

| Method | Output | Description | | ------------ | ------------------ | ------------------------ | | standard() | "令和6年3月8日" | Arabic numerals (default)| | kansuji() | "令和六年三月八日" | Chinese numerals | | short() | "R6.3.8" | Abbreviated |

The first year of an era is displayed as 元年 (gannen) instead of 1年:

toWareki("2019-05-01").standard(); // "令和元年5月1日"
toWareki("2019-05-01").kansuji();  // "令和元年五月一日"
toWareki("2019-05-01").short();    // "R1.5.1"

toWestern — Wareki to Western

Parses any of the three formats and returns a Date.

import { toWestern } from "wareki-converter";

toWestern("令和6年3月8日");   // Date(2024, 2, 8)
toWestern("令和六年三月八日"); // Date(2024, 2, 8)
toWestern("R6.3.8");         // Date(2024, 2, 8)

API Reference

toWareki(input: Date | string): WarekiResult

Converts a Western date to wareki.

| Parameter | Type | Description | | --------- | ---------------- | -------------------------------------------- | | input | Date \| string | Date object or string in YYYY-MM-DD / YYYY/M/D format |

Returns a WarekiResult object with standard(), kansuji(), and short() methods.

Throws Error if the date is before the Meiji era (1868-09-08) or if the string format is invalid.

toWestern(wareki: string): Date

Parses a wareki string and returns a Date.

| Parameter | Type | Description | | --------- | -------- | ----------------------------------------------- | | wareki | string | Wareki string in standard, kansuji, or short format |

Throws Error for invalid or unparseable input.

Supported Eras

| Era | Abbreviation | Start | End | | ------ | ------------ | ---------- | ---------- | | 明治 | M | 1868-09-08 | 1912-07-29 | | 大正 | T | 1912-07-30 | 1926-12-24 | | 昭和 | S | 1926-12-25 | 1989-01-07 | | 平成 | H | 1989-01-08 | 2019-04-30 | | 令和 | R | 2019-05-01 | — |

License

MIT