Reference
Everything
import { … } from "@johnmorrisdotca/hikidashi";
6.4 kB minified and gzipped, with everything it imports (measured with esbuild)
Hikidashi 引き出し: a drawer of small Japanese text tools. 和暦 era years and dates both ways; kanji
numerals both ways, read aloud and in formal 大字; the dictionary forms a conjugated verb or adjective
could come from; a word's reading shared out over its kanji, and a かん字テスト made from it; Japanese
words and kanji pulled out of pasted text; and how hard a sentence is to read. Pure functions, no
dictionary or data of their own, and no dependencies. Each drawer is also an entry of its own, so a
page imports only the one it needs: @johnmorrisdotca/hikidashi/wareki, /numerals, /deinflect,
/align, /extract and /difficulty.
Exports
| Name | Kind | What it is |
|---|---|---|
ALIGN_LIMITS | constant | What segmentWord will work on: a word of up to 64 characters and a reading of up to 256. |
buildKanjiTest | function | The test: words to write in kanji, then different words to read. |
Deinflection | type | One answer of dictionaryForms: a dictionary form the written word could come from, and the kind of word it would have to be for that to be true. |
dictionaryForms | function | Every dictionary form written could be a conjugation of, with the kind of word it would have to be. |
eraOnDate | function | The era year a day is in, from YYYY-MM-DD or a Date. |
EraYear | type | An era year that parsed or was found, and the Western year it names: what parseEraYear, eraYearOf, eraYearsOf and eraOnDate give. |
eraYearOf | function | The era year a Western year is usually written as: the newest era's, so 1989 is 平成1 and 2019 is 令和1. |
eraYearsOf | function | Every era year that falls in a Western year, the newest era first. |
EXTRACT_LIMITS | constant | What a paste is held to: read to 20,000 characters and then cut, words of up to 8 characters, and at most 4,000 candidates asked of a dictionary. |
extractFromText | function | The words and kanji a paste comes to: the words known lists, longest match first, and every kanji in the text. |
ExtractInput | type | What to read, and the dictionary to read it against: the argument of extractFromText. |
ExtractResult | type | The words found, then the kanji, each once, in the order they first appear; and what the paste held. |
followsAsVerbStem | function | Whether following opens with an ending that only a verb's stem takes (ます, ました, ません, ましょう, まして, たい, なさい), so that the word before it is being written as a stem. |
formatEraYearJapanese | function | The era year as it is written in Japanese: 平成3年. |
formatEraYearRomaji | function | The era year as it is written in Latin letters: Heisei 3. |
hiraganaToKatakana | function | Hiragana written as katakana: ひらがな to ヒラガナ. |
JAPANESE_ERAS | constant | The five modern eras, oldest first: 明治, 大正, 昭和, 平成 and 令和. |
JapaneseEra | type | An era, as it is written, said and counted: one row of JAPANESE_ERAS. |
kanjiAsWord | function | A kanji on its own, as a word a test can ask. |
kanjiCost | function | The cost of one kanji. |
KanjiDifficultySource | type | What your dictionary knows about a kanji, which kanjiCost turns into a cost. |
kanjiIn | function | Every kanji in the text, once each, in the order they appear. |
KanjiTest | type | A test: words to write in kanji from their readings, then different words to read. |
KanjiTestQuestion | type | One question of a test: the word, its reading, and the word cut into its segments, ready to be drawn as squares with the okurigana in brackets. |
katakanaToHiragana | function | Katakana written as hiragana: カタカナ to かたかな. |
KnownWords | type | The words your dictionary confirmed, each with the kinds of word it is. |
LARGEST_JAPANESE_NUMBER | constant | The largest number this module will answer for: 9,007,199,254,740,991, JavaScript's largest safe integer. |
LONGEST_ENDING | constant | The longest ending, in characters, that any rule strips, so a caller matching words in running text knows how far past a dictionary word to look for its conjugation. |
parseEnglishNumber | function | The value of a number written in words, or null when it is not one. |
parseEraYear | function | The era year a text names, or null when it does not name one. |
parseJapaneseNumber | function | The value of a number written in Japanese, or null when it is not one. |
readJapaneseNumber | function | The number said aloud, in hiragana, with the sound changes a learner has to know: 300 is さんびゃく, 600 ろっぴゃく, 800 はっぴゃく, 3,000 さんぜん, 8,000 はっせん, and 一兆 いっちょう. |
ReadWord | type | A word and its reading in hiragana: what buildKanjiTest takes a list of, and what kanjiAsWord makes. |
sanitizePastedText | function | The text as it will be read: control and invisible characters (and line and paragraph separators) turned into spaces, then cut to EXTRACT_LIMITS.characters. |
SEGMENT_KINDS | constant | What a run of a word is: kanji with their part of the reading, kana inside the word, or the kana that end it (okurigana). |
SegmentKind | type | One kind of run: "kanji", "kana" or "okurigana", the values of SEGMENT_KINDS. |
segmentWord | function | A word cut into its kanji and its kana, each kanji run with its share of the reading. |
sentenceDifficulty | function | The sentence's score, lowest first: its length in characters plus three times its hardest kanji. |
UNKNOWN_KANJI_COST | constant | What a kanji costs when nothing is known about it: 20, the most any kanji costs. |
VERSION | constant | The package's version, the same as its package.json. |
westernYearFor | function | The Western year an era year falls in, or null when the era never had that year. |
WORD_CLASSES | constant | The kinds of word a conjugated form can come from, each named by itself: godan and ichidan verbs, iAdjective, and the two irregular verbs suru (する) and kuru (来る). |
wordCandidates | function | Every substring the dictionary might know, so one question can be asked about the whole paste: look all of them up at once, and pass the ones found as known. |
WordClass | type | One kind of word: "godan", "ichidan", "iAdjective", "suru" or "kuru", the values of WORD_CLASSES. |
wordClassesOf | function | The kinds of word a dictionary entry is, from the parts of speech it lists, so a conjugated form is only taken for a verb or an adjective the dictionary says is one. |
WordSegment | type | One run of a word, and its share of the reading in hiragana: what segmentWord cuts a word into. |
writeJapaneseNumber | function | The number as Japanese writes it, in kanji. |