Sort Japanese text.
This module was built in order to support sorting of strings containing Japanese text. It can't sort kanji though, ideally one should already have the corresponding readings at hand.
This module partially follows the specifications of JIS X 4061 as seen on Wikipedia.
The API is ready to use as-is, but is also fully customizable.
const kanasort = require('kanasort')
Sorts the specified array in-place and returns the array using the default
Japanese string comparison.
(This is just a call to Array.prototype.sort
.)
A comparison function (comparefn
)
using the default Japanese string transforms that returns:
- A negative value if a < b
- A positive value if a > b
0
if a = b.
For further customization, see the Customizable API.
Usage:
kanasort < input.txt > output.txt
Sorts standard input line by line.
The following are the transforms included by default (in order of processing):
- small to big kana (ぁ→あ)
- voiced to unvoiced (が→か)
- half-voiced to unvoiced (ぱ→は)
- katakana to hiragana (サ→さ)
- iteration mark variants (ヾ→ゝ)
- chōon to corresponding kana (かー→かあ)
- iteration mark application (こゝ→ここ)
In order, the weight priority of each:
- unvoiced < half-voiced
- unvoiced < voiced
- chōon to corresponding kana (reversed)
- small to big kana (reversed)
- iteration mark variants (reversed)
- iteration mark application (reversed)
- hiragana < katakana
Transformed matches are ordered first (and untransformed matches are ordered last) on transforms marked as 'reversed'.
JSDoc all of this so we don't have to scratch our heads.
MIT
Thanks to minodisk/sorter for supporting my private hobby project sorting needs and for being the inspiration for this module.