本文へ移動

Hikidashi引き出し

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

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

目次

リファレンス

漢数字

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

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

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

漢数字: numbers, in both directions between the two ways of writing them.

一億二千万 is a number a learner meets in a news headline and cannot read, and 120,000,000 is a number they can read and cannot write. Japanese counts in ten-thousands rather than thousands (万, 億, 兆, each one 10,000 times the last), which is why 120 million is "twelve thousand ten-thousands" and why reading one off a page is a different skill from reading the digits. That grouping is the whole of this module.

  • parseJapaneseNumber reads 一億二千万, 1億2000万, 2万5千 or 120000000 and gives 120000000, or null.
  • writeJapaneseNumber writes it back, and with formal the way a contract or a banknote does: 壱万.
  • readJapaneseNumber says it aloud in hiragana, with the sound changes (さんびゃく, はっぴゃく).
  • parseEnglishNumber reads "five hundred", "twenty-five" and the magnitudes in romaji ("5 man").

Whole numbers from 0 to 9,007,199,254,740,991 only: past that JavaScript stops counting exactly, and a number the runtime cannot hold is worse than one that is not offered.

エクスポート

名前種類概要
LARGEST_JAPANESE_NUMBER定数The largest number this module will answer for: 9,007,199,254,740,991, JavaScript's largest safe integer.
parseEnglishNumber関数The value of a number written in words, or null when it is not one.
parseJapaneseNumber関数The value of a number written in Japanese, or null when it is not one.
readJapaneseNumber関数The number said aloud, in hiragana, with the sound changes a learner has to know: 300 is さんびゃく, 600 ろっぴゃく, 800 はっぴゃく, 3,000 さんぜん, 8,000 はっせん, and 一兆 いっちょう.
writeJapaneseNumber関数The number as Japanese writes it, in kanji.

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

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