ひらがなに対する複数のローマ字入力を判定する、DOM非依存のTypeScriptライブラリです。
npm install hiragana-romazi-parserimport { Parser } from "hiragana-romazi-parser";
const parser = new Parser();
parser.start("こんにちは");
const result = parser.input("k");
console.log(result.accepted); // true
console.log(result.typedRomaji); // "k"
console.log(result.remainingRomaji); // 表示用の残りローマ字
console.log(result.finished); // 問題全体が完了したかcheck(key)は、キーが受理されたかだけをbooleanで返す簡易APIです。画面描画や統計には、詳細な状態を返すinput(key)を利用してください。
parser.check("o");
const state = parser.getState();
const stats = parser.getStats();主なAPI:
start(kana)/build(kana): 新しい問題を開始input(key): 1キーを入力し、判定結果と状態を返すcheck(key): 受理されたかをbooleanで返すgetState(): 現在の入力状態を取得getStats(): セッションの正解数、ミス数、完了問題数を取得reset(): 統計を残して現在の問題を破棄resetSession(): 問題と統計をすべて初期化
変換表にない文字を渡した場合、UnsupportedKanaErrorが文字と位置を保持して送出されます。
リポジトリを取得して依存関係をインストールした後、次を実行します。
npm run game表示されたかなをローマ字で入力します。入力中の[ ]内が残り文字です。終了はEscまたはCtrl+Cです。
ブラウザ版は次のコマンドで起動します。
npm run game:web起動後、ブラウザでhttp://127.0.0.1:4173を開いてください。
npm test
npm run build
npm run checknpm testはビルド後、Node.js標準テストランナーでParserの動作を検証します。公開用JavaScriptと型定義はsrc/からdist/へ自動生成されます。
npm run checkはBiomeでコードのlintとフォーマットを確認し、npm run check:fixで安全な修正と整形を適用します。
本ライブラリのローマ字変換データは、WhiteFox-Lugh/RomanTypeParser の
JsonData/romanTypingParseDictionary.jsonを基に、TypeScript向けに変換・修正したものです。
元データはMITライセンスで提供されています。
MIT License
Copyright (c) 2021 Whitefox
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.