Skip to content

Repository files navigation

hiragana-romazi-parser

ひらがなに対する複数のローマ字入力を判定する、DOM非依存のTypeScriptライブラリです。

インストール

npm install hiragana-romazi-parser

使用例

import { 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 check

npm testはビルド後、Node.js標準テストランナーでParserの動作を検証します。公開用JavaScriptと型定義はsrc/からdist/へ自動生成されます。 npm run checkはBiomeでコードのlintとフォーマットを確認し、npm run check:fixで安全な修正と整形を適用します。

変換データの出典とライセンス

本ライブラリのローマ字変換データは、WhiteFox-Lugh/RomanTypeParserJsonData/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.

About

タイピングゲームでローマ字の複数入力に対応するライブラリ

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages