logo

kanaconv

Command to convert Japanese from/to Kana/Kanji/Romaji with furigana option

kanaconv.cjs (779B)


  1. #!/usr/bin/env node
  2. // Copyright © 2023 Haelwenn (lanodan) Monnier <contact+kanaconv@hacktivis.me>
  3. // SPDX-License-Identifier: MIT
  4. const {argv, stdin, stdout} = require('node:process');
  5. const readline = require('node:readline');
  6. const rl = readline.createInterface({input : stdin, output : stdout});
  7. const Kuroshiro = require('kuroshiro');
  8. const KuromojiAnalyzer = require('kuroshiro-analyzer-mecab');
  9. const kuroshiro = new Kuroshiro();
  10. let args = require('minimist')(argv.slice(2));
  11. let mode = args['mode'] || args['m'] || 'furigana';
  12. let to = args['to'] || args['t'] || 'romaji';
  13. kuroshiro.init(new KuromojiAnalyzer());
  14. function
  15. convert(line)
  16. {
  17. kuroshiro.convert(
  18. line,
  19. {mode: mode, to: to}
  20. ).then((res) => {
  21. console.log(res);
  22. });
  23. };
  24. rl.on('line', convert);