Skip to the content

Hikidashi引き出し

Era dates (和暦) and kanji numerals both ways, the dictionary forms of a conjugated word, a reading shared out over its kanji, words pulled from pasted text, and how hard a sentence is to read.

Hikidashi (引き出し) is a drawer: each tool is pulled out when it is wanted. About the name

Contents

Reference · Kanji numerals

parseEnglishNumberfunction

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 it

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

Also exported from: @johnmorrisdotca/hikidashi

Definition

function parseEnglishNumber(text: string): number | null

Parameters

NameTypeDescription
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.

Returns

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.

Examples

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

What it prints (run when this page was built)

View sourceEdit on GitHubMade from the source of @johnmorrisdotca/hikidashi 1.1.0.