commit: b6dad2db4bbe8f0eb57ceb8f7346b5aed7210ef5
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date: Mon, 30 Oct 2023 04:11:02 +0100
Initial Commit
Diffstat:
6 files changed, 117 insertions(+), 0 deletions(-)
diff --git a/LICENSES/MIT.txt b/LICENSES/MIT.txt
@@ -0,0 +1,9 @@
+MIT License
+
+Copyright (c) <year> <copyright holders>
+
+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.
diff --git a/README.md b/README.md
@@ -0,0 +1,18 @@
+# kanaconv: Command to convert Japanese from/to Kana/Kanji/Romaji with furigana option
+
+I created this tool as I wanted to have a way to easily generate [furigana](https://en.wikipedia.org/wiki/Furigana) from Japanese text, a feature missing from [kakasi](http://kakasi.namazu.org/), which I'd recommend also checking out.
+
+## Dependencies
+- A CommonJS engine, such as NodeJS
+- [kuroshiro](https://kuroshiro.org/) `^1.2.0`
+- [kuroshiro-analyzer-mecab](https://github.com/hexenq/kuroshiro-analyzer-mecab) `^1.0.0`
+- [minimist](https://github.com/minimistjs/minimist) `^1.2.8`
+
+Mecab Analyzer was picked as Mecab is widly packaged in distros while the rest are NPM-only and rather obscure by comparison.
+Should also be noted that the only indirect hard-dependencies are mecab-async and shell-quote, this makes this software packageable in distributions the traditional way.
+
+## Copyright
+```
+Copyright © 2023 Haelwenn (lanodan) Monnier <contact+kanaconv@hacktivis.me>
+SPDX-License-Identifier: MIT
+```
diff --git a/kanaconv.1 b/kanaconv.1
@@ -0,0 +1,34 @@
+.\" kanaconv: Command to convert Japanese from/to Kana/Kanji/Romaji with furigana option
+.\" Copyright © 2023 Haelwenn (lanodan) Monnier <contact+kanaconv@hacktivis.me>
+.\" SPDX-License-Identifier: MIT
+.Dd 2023-10-30
+.Dt KANACONV 1
+.Os
+.Sh NAME
+.Nm kanaconv
+.Nd Convert Japanese from/to Kana/Kanji/Romaji with furigana option
+.Sh SYNOPSIS
+.Nm
+.Op Fl m|--mode Ns = Ns Ar mode
+.Op Fl t|--to Ns = Ns Ar target
+.Sh DESCRIPTION
+.Nm
+converts Japanese text in standard input line-wise acording to the passed
+options or their respective defaults.
+.Sh OPTIONS
+.Bl -tag -width Ds
+.It Fl m Ar mode , Fl -mode Ns = Ns Ar mode
+Conversion mode,
+.Ar mode
+must be one of: normal, spaced, okurigana, furigana (default).
+.It Fl t Ar target , Fl -to Ns = Ns Ar target
+Target syllabary,
+.Ar target
+must be one of: hiragana, katakana, romaji (default).
+.El
+.Sh EXIT STATUS
+.Ex -std
+.Sh SEE ALSO
+.Xr kakasi 1
+.Sh AUTHORS
+.An Haelwenn (lanodan) Monnier Aq Mt contact+kanaconv@hacktivis.me
diff --git a/kanaconv.cjs b/kanaconv.cjs
@@ -0,0 +1,31 @@
+#!/usr/bin/env node
+// Copyright © 2023 Haelwenn (lanodan) Monnier <contact+kanaconv@hacktivis.me>
+// SPDX-License-Identifier: MIT
+
+const {argv, stdin, stdout} = require('node:process');
+const readline = require('node:readline');
+const rl = readline.createInterface({input : stdin, output : stdout});
+
+const Kuroshiro = require('kuroshiro');
+const KuromojiAnalyzer = require('kuroshiro-analyzer-mecab');
+const kuroshiro = new Kuroshiro();
+
+let args = require('minimist')(argv.slice(2));
+
+let mode = args['mode'] || args['m'] || 'furigana';
+let to = args['to'] || args['t'] || 'romaji';
+
+kuroshiro.init(new KuromojiAnalyzer());
+
+function
+convert(line)
+{
+ kuroshiro.convert(
+ line,
+ {mode: mode, to: to}
+ ).then((res) => {
+ console.log(res);
+ });
+};
+
+rl.on('line', convert);
diff --git a/package.json b/package.json
@@ -0,0 +1,23 @@
+{
+ "name": "kanaconv",
+ "description": "Command to convert Japanese from/to Kana/Kanji/Romaji with furigana option",
+ "keywords": ["utils", "command-line", "japanese", "romaji", "furigana"],
+ "homepage": "https://hacktivis.me/git/kanaconv",
+ "license": "MIT",
+ "version": "0.1.0",
+ "bin": {
+ "kanaconv": "./kanaconv.cjs"
+ },
+ "man": "./kanaconv.1",
+ "repository": {
+ "type": "git",
+ "url": "https://hacktivis.me/git/kanaconv.git"
+ },
+ "scripts": {
+ "lint": "reuse lint --quiet && mandoc -Tlint -Wunsupp,error,warning ./kanaconv.1"
+ },
+ "dependencies": {
+ "kuroshiro": "^1.2.0",
+ "kuroshiro-analyzer-mecab": "^1.0.0"
+ }
+}
diff --git a/package.json.license b/package.json.license
@@ -0,0 +1,2 @@
+Copyright © 2023 Haelwenn (lanodan) Monnier <contact+kanaconv@hacktivis.me>
+SPDX-License-Identifier: MIT