Node.js 汉字转拼音

Posted by wxianfeng Fri, 30 Aug 2013 17:06:00 GMT

之前写了一个 ruby 汉字转拼音的 gem , 项目需要, 把它翻译成了 nodejs module.

安装

npm install hanzi_to_pinyin

使用

var hanzi_to_pinyin = require("hanzi_to_pinyin");
hanzi_to_pinyin.hanzi_to_pinyin("测试");

命令行bin

>hanzi_to_pinyin "测试"
=>ce;shi

例子

assert.equal(hanzi_to_pinyin.hanzi_to_pinyin("ab你好c"),'ab;ni;hao;c');
assert.equal(hanzi_to_pinyin.hanzi_to_pinyin("我们"),"wo;men");
assert.equal(hanzi_to_pinyin.hanzi_to_pinyin("yyf"),"yyf");
assert.equal(hanzi_to_pinyin.hanzi_to_pinyin("拗Smith"),"ao,niu;Smith");
assert.equal(hanzi_to_pinyin.hanzi_to_pinyin("测试1"),"ce;shi;1");
assert.equal(hanzi_to_pinyin.hanzi_to_pinyin("测_试-"),"ce;_;shi;-");
assert.equal(hanzi_to_pinyin.hanzi_to_pinyin("2"),"2");

源码

nodejs

ruby

This entry was posted on Fri, 30 Aug 2013 17:06:00 GMT and Posted in . You can follow any any response to this entry through the Atom feed. You can leave a comment or a trackback from your own site.

Tags ,


Trackbacks

Use the following link to trackback from your own site:
http://wxianfeng.com/trackbacks?article_id=298

Comments

Leave a comment