本文へ移動

Hikidashi引き出し

和暦と漢数字の相互変換、活用した語の辞書形、漢字への読みの割り当て、貼り付けた文からの単語の抽出、文の難しさ。日本語のテキストを扱う小さな道具を集めた引き出しです。

「引き出し」という名前は、道具が一つずつしまってあり、必要なときに取り出して使える、という意味です。 名前について(英語)

目次

リファレンス

和暦

import { … } from "@johnmorrisdotca/hikidashi/wareki";

最小化と gzip 圧縮をしたサイズは 1.3 kB(読み込むものをすべて含み、esbuild で計測)

リファレンスの説明と例は英語です。見出しと目次は日本語です。

和暦: Japanese era years, and the Western years and dates they name, both ways.

Working out what 平成3年 is means knowing where the era started and subtracting one, which is exactly the arithmetic nobody wants to do in their head while reading a form, a coin or somebody's birth year. This goes from an era year to a Western year (parseEraYear), from a Western year or a date to the era year it falls in (eraYearOf, eraYearsOf, eraOnDate), and writes the answer (formatEraYearJapanese).

Five eras, back to 明治. Not because the earlier ones do not exist, since there are two hundred and more, but because 1868 is where the modern calendar begins, and a date before it is a history question rather than a reading one. Every date here is in the Gregorian calendar.

An era changes partway through a Western year, so a year can belong to two of them: 1989 is 昭和64 until 7 January and 平成1 from the 8th. eraYearsOf answers with both; eraOnDate says which one a day is in.

エクスポート

名前種類概要
eraOnDate関数The era year a day is in, from YYYY-MM-DD or a Date.
EraYear型An era year that parsed or was found, and the Western year it names: what parseEraYear, eraYearOf, eraYearsOf and eraOnDate give.
eraYearOf関数The era year a Western year is usually written as: the newest era's, so 1989 is 平成1 and 2019 is 令和1.
eraYearsOf関数Every era year that falls in a Western year, the newest era first.
formatEraYearJapanese関数The era year as it is written in Japanese: 平成3年.
formatEraYearRomaji関数The era year as it is written in Latin letters: Heisei 3.
JAPANESE_ERAS定数The five modern eras, oldest first: 明治, 大正, 昭和, 平成 and 令和.
JapaneseEra型An era, as it is written, said and counted: one row of JAPANESE_ERAS.
parseEraYear関数The era year a text names, or null when it does not name one.
westernYearFor関数The Western year an era year falls in, or null when the era never had that year.

ソースを見るGitHub で編集@johnmorrisdotca/hikidashi 1.1.0 のソースから作成しました。

この日本語は、まだ日本語を母語とする方の確認を受けていません。訂正を歓迎します。