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

@hanology/era

v0.1.0

Published

GB/T XXXXX 日曆體系代碼 — parse, generate, and resolve Chinese historical calendar era codes (data bundled)

Readme

@hanology/era

GB/T XXXXX 日曆體系代碼 — parse, generate, and resolve Chinese historical calendar era codes. The GB/T registry is bundled; no separate data install needed.

Parse codes like h-CN.2.24.071.021.01 into structured records, generate canonical code strings, and resolve codes to Gregorian years with bilingual labels.

Install

npm install @hanology/era

The GB/T registry (38 dynasties, 336 rulers, 547 eras, 123 ganzhi entries) is bundled in the package. No data-only install needed.

Quick start

import {
  parseCode, generateCode, isValidCode,
  imperialCode, kinglyCode, rocCode, ganzhiCode,
  EraResolver, loadEraData,
} from '@hanology/era'

// Parse a code string
const parsed = parseCode('h-CN.2.24.071.021.01')
// → { type: 2, dynastyCode: 24, rulerCode: 7, reignCount: 1, eraCode: 2, eraInstance: 1, eraYear: 1, ... }

// Validate
isValidCode('h-CN.2.24.071.021.01')  // true
isValidCode('not-a-code')              // false

// Generate from structured data
const code = imperialCode(24, 7, 1, 2, 1, 1)  // 'h-CN.2.24.071.021.01'

// Resolve to Gregorian year + bilingual label
const resolver = new EraResolver(loadEraData())
const resolved = resolver.resolve(parsed)
// → {
//     code: 'h-CN.2.24.071.021.01',
//     label: '唐玄宗開元元年',
//     labelEn: '1st year of 開元 era, 玄宗 of 唐',
//     gregorianYear: 713
//   }

Four era types

GB/T XXXXX Part 2 defines four calendar-system types:

| Type | Name | Format | Example | |---|---|---|---| | 1 | 王公即位年次紀年 (kingly succession) | h-CN.1.{DD}.{RRR}.{YYY} | h-CN.1.04.011.001 | | 2 | 年號紀年 (imperial era name) | h-CN.2.{DD}.{RRR}.{EER}.{YY} | h-CN.2.24.071.021.01 | | 3 | 中華民國紀年 (ROC) | h-CN.3.{YY} | h-CN.3.01 | | 4 | 天干地支紀年 (ganzhi cycle) | h-CN.4.{CC}.{OO} | h-CN.4.01.50 |

Where:

  • DD — 2-digit dynasty code
  • RRR — 3-digit ruler segment (2-digit ruler + 1-digit reign)
  • YYY — 3-digit year ordinal within reign
  • EER — 3-digit era segment (2-digit era + 1-digit instance)
  • YY — 2-digit era year
  • CC — 2-digit ganzhi code (1–60)
  • OO — 2-digit cycle occurrence ordinal

Modules

| Module | What it does | |---|---| | parse.ts | parseCode(code)ParsedCode \| null; isValidCode(code) | | generate.ts | generateCode(parsed); convenience builders kinglyCode, imperialCode, rocCode, ganzhiCode | | resolve.ts | EraResolver class — code → Gregorian year + labels; reverse lookups; dynasty alias resolution | | data.ts | loadEraData() — reads the bundled GB/T registry | | types.ts | All public types (ParsedCode, ResolvedCode, EraData, entry shapes) |

Full reference: API.md. Architecture rationale: ARCHITECTURE.md. Updating the bundled data: DEVELOPMENT.md.

Source data

The bundled data/era-data.json is a snapshot of the canonical registry at hanologyorg/era-data. That repo holds the source-of-truth data plus the extraction script (scripts/extract-era-data.py) that regenerates it from the GB/T docx.

To pull a fresh snapshot into this package:

npm run sync-data

License

MIT.