本文へ移動

Hikidashi引き出し

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

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

目次

リファレンス · 漢数字

parseEnglishNumber関数

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

The value of a number written in words, or null when it is not one.

Digits are allowed inside it - "5 man", "20 thousand" - since that is how somebody actually types a magnitude they know the name of. Anything the table does not hold makes the whole thing null rather than a partial reading: "five cats" is not five, and answering as though it were would be a confident wrong answer to a question nobody asked.

インポート

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

ほかのエクスポート元: @johnmorrisdotca/hikidashi

定義

function parseEnglishNumber(text: string): number | null

引数

名前型説明
textstring

A number in English words ("five hundred", "twenty-five", "1.2 million"), or with a Japanese magnitude in romaji ("5 man", "3 oku"); digits may stand for any part.

戻り値

number | null

The value; null when any word is not a number word ("five cats"), when there is nothing to read, or when the value is past 9,007,199,254,740,991 either way.

例

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

console.log(parseEnglishNumber("five hundred"), parseEnglishNumber("twenty-five thousand"), parseEnglishNumber("5 man"));
console.log(parseEnglishNumber("1.2 million"), parseEnglishNumber("five cats"));
500 25000 50000
1200000 null

出力(このページを作ったときに実行した結果)

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

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