parseEraYearfunction
The era year a text names, or null when it does not name one.
元年, "first year", is spelled out rather than numbered on anything official, so it is read as the 1 it means. Everything else is a plain number, half-width or full, with or without the 年 that usually follows it. Latin names may be spelled with a long-vowel macron (Shōwa) or without.
Import it
import { parseEraYear } from "@johnmorrisdotca/hikidashi/wareki";
Also exported from: @johnmorrisdotca/hikidashi
Definition
function parseEraYear(raw: string): EraYear | null
Parameters
| Name | Type | Description |
|---|---|---|
raw | string | What somebody typed: 令和6年, 平成3年, 昭和元年, "Heisei 3", "Shōwa 64". |
Returns
EraYear | null
The era, the year within it and its Western year; null when the text does not name an era year, or names one the era never reached (昭和65年). Null is a refusal, never a guess.
Examples
import { parseEraYear } from "@johnmorrisdotca/hikidashi/wareki";
console.log(parseEraYear("令和6年")?.westernYear);
console.log(parseEraYear("Heisei 3")?.westernYear, parseEraYear("昭和元年")?.westernYear);
console.log(parseEraYear("昭和65年"), parseEraYear("令和"));2024
1991 1926
null nullWhat it prints (run when this page was built)