-
Notifications
You must be signed in to change notification settings - Fork 839
/
pinyin
executable file
·38 lines (31 loc) · 1.11 KB
/
pinyin
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/usr/bin/env node
var commander = require('commander');
commander.
version(require('../package').version).
usage('[options] 汉字').
option('-v, --version', 'output the version number').
option('-s, --style <style>', 'pinyin styles: [NORMAL,TONE,TONE2,INITIALS,FIRST_LETTER]').
option('-S, --segment', 'segmentation word to phrases').
option('-h, --heteronym', 'output heteronym pinyins').
option('-g, --group', 'output group by phrases').
option('-p, --separator <separator>', 'separator between words').
parse(process.argv);
if (commander.list) {
process.exit()
}
// output help and exit if no args found
if (commander.args.length === 0) {
commander.help();
}
var pinyin = require("../");
var options = {
style: pinyin["STYLE_" + (commander.style || "TONE").toUpperCase()],
heteronym: commander.heteronym || false,
group: commander.group || false,
segment: commander.segment || false,
};
var separator = commander.separator === undefined ? ' ' : commander.separator;
var words = commander.args.join(" ");
var py = pinyin(words, options).join(separator);
console.log(py);
// vim:ft=javascript