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://blog.wxianfeng.com/trackbacks?article_id=298

Comments

  1. Avatar
    Italy - Greece about {{count}} years ago:

    all the time i used to read smaller articles or reviews which as
    well clear their motive,and that is also happening with this piece of writing
    which I am reaing at this place.

  2. Avatar
    Passenger ships Ancona Patras over {{count}} years ago:

    always i used to rea smaller articles or reviews that also clear their motive,
    and that is also happening with this post which I am reading here.

  3. Avatar
    Passenger ships Ancona Patras over {{count}} years ago:

    aways i sed too read smaller articles or reviews that also clear
    their motive, and that is also happening with thijs post
    which I am reading here.

  4. Avatar
    creehack about {{count}} years ago:

    What’s up, I wish for to subscribe for this weblog to
    get hottest updates, therefore where can i do it please help out.

  5. Avatar
    creehack about {{count}} years ago:

    What’s up, I ish for to subscribe forr this weblog to get hottest
    updates, therefore where can i do it please help out.

  6. Avatar
    Φθηνά ferries about {{count}} years ago:

    If you are going for finest contents like I do, just go to see this website all
    tthe time as it presents feature contents, thanks

  7. Avatar
    Φθηνά ferries about {{count}} years ago:

    If you are going for finest contents like I do, just go to see this
    website all the time as it presents feature contents, thanks

  8. Avatar
    Diego about {{count}} years ago:

    When the cards are equivalent subsequently it’s a wrap and gambler has the choice
    to accumulate original profits.

  9. Avatar
    Diego about {{count}} years ago:

    When the cards are equivalent subsequently it’s a
    wrap and gambler has the choice to accumulate original profits.

  10. Avatar
    Dinkes.Pamekasankab.Go.id about {{count}} years ago:

    I every time used too read post in news papers but now as I am a user
    of net thus from now I am using net for articles or reviews, thanks to web.

  11. Avatar
    cheap creamation about {{count}} years ago:

    Excellent blog here! Also your website rather a lot up very fast!
    What web host are you the use of? Can I am getting your affiliate hyperlink to your host?
    I wish my web site loaded up as fast as yours lol

  12. Avatar
    cheap creamation about {{count}} years ago:

    Excellent blog here! Also your website rather a lot up very fast!
    What web host are you the use of? Can I am getting your affiliate hyperlink
    to your host? I wish my web site loaded up as fast as yours lol

  13. Avatar
    vps cheap over {{count}} years ago:

    You really make it appear so easy together with
    your presentation but I find this topic to be actually something which I feel I might never understand.
    It sort of feels too complicated and very large for me.
    I am taking a look ahead for your next submit, I will try to get the dangle of it!

  14. Avatar
    vps cheap over {{count}} years ago:

    You really make it appear so easy together with your presentation but I find this topic to be actually something which I feel I might never understand.
    It sort of feels too complicated and very large for me.
    I am taking a look ahead for your next submit, I will try to get the dangle
    of it!

  15. Avatar
    Bari - Patras almost {{count}} years ago:

    I visited many websites except the audio quality for aaudio songs existing att this site is genuinely excellent.

  16. Avatar
    Berita BTS over {{count}} years ago:

    Excellent, what a webpage it is! This weblog presents useful facts to us, keep it up.

  17. Avatar
    Berita BTS over {{count}} years ago:

    Excellent, what a webpage it is! This weblog presents useful facts to us, keep it up.

  18. Avatar
    вулкан казино 19 over {{count}} years ago:

    Сохраню как “Избранное”, я оцениваю позитивно ваш авторский ресурс!

  19. Avatar
    вулкан казино 19 over {{count}} years ago:

    Сохраню как “Избранное”, я оцениваю позитивно ваш авторский ресурс!

  20. Avatar
    download over {{count}} years ago:

    wonderful put up, very informative. I’m wondering why the other
    specialists of this sector don’t realize this.

    You should continue your writing. I’m confident, you’ve a great readers’ base already!

  21. Avatar
    download over {{count}} years ago:

    wonderful put up, very informative. I’m wondering
    why the other specialists of this sector don’t realize this.
    You should continue your writing. I’m confident, you’ve a great readers’ base already!

  22. Avatar
    wildesgluecksspiel.de over {{count}} years ago:

    Mit eine Menge Websites Bereitstellung der Möglichkeit von Online-Slots heute, es werden wesentlicher zu
    vielleicht erhalten vertraut mit Wegen bis identifizieren schöne Art der Slots.

  23. Avatar
    wildesgluecksspiel.de over {{count}} years ago:

    Mit eine Menge Websites Bereitstellung der Möglichkeit
    von Online-Slots heute, es werden wesentlicher zu vielleicht erhalten vertraut mit Wegen bis identifizieren schöne Art der
    Slots.

  24. Avatar
    https://agendomino99.id over {{count}} years ago:

    Ԍreat blog you have hеrе.. Ӏt’s difficult tօ fid excellent writing likke yours these dаys.
    Ι seriously aρpreciate individuals ⅼike
    you! Take care!!

  25. Avatar
    https://agendomino99.id over {{count}} years ago:

    Great bllog you һave һere.. It’s difficult to find excellent writing
    like үours tһeѕe days. I serioսsly apрreciate individuals ⅼike ʏоu!

    Tаke care!!

  26. Avatar
    masadepanjudi.wordpress.com over {{count}} years ago:

    With havin so much content do you ever run into any issues of plagorism or copyright
    violation? My website has a lot of exclusive content I’ve either authored myself or outsourced but it looks like a lot of it is popping it up all over the internet without my
    agreement. Do you know any techniques to help
    prevent content from being stolen? I’d really appreciate it.

  27. Avatar
    masadepanjudi.wordpress.com over {{count}} years ago:

    With havin so much content do you ever run into any issues
    of plagorism or copyright violation? My website has a lot of exclusive content I’ve
    either authored myself or outsourced but it looks like a lot of it is popping
    it up all over the internet without my agreement.
    Do you know any techniques to help prevent content from being stolen?
    I’d really appreciate it.

  28. Avatar
    http://27.124.27.102 over {{count}} years ago:

    Ithink this іs oone оf the most ѕignificant info foг me.
    And і’m glad reading your article. But want t᧐
    remark oon sⲟme ցeneral tһings, Thhe site stylpe іѕ wonderful,
    the articles iѕ rеally ɡreat : Ɗ. Good job, cheers

  29. Avatar
    http://27.124.27.102 over {{count}} years ago:

    I thiunk thіs is onne of the moѕt sіgnificant info for me.
    And i’m glad reading yourr article. Buut ԝant to remark on ѕome gendral tһings,
    The site style iѕ wonderful, tһe articles is
    reaⅼly great : D. Gߋod job, cheers

  30. Avatar
    judi kartu over {{count}} years ago:

    Good informɑtion. Lucky mme I rann across yolur site by cgance (stumbleupon).

    І’ve book marked іt for later!

  31. Avatar
    judi kartu over {{count}} years ago:

    Goodd іnformation. Lucky mе I гɑn aсross your site Ƅy chance (stumbleupon).
    І’ѵe book marked іt foг later!

  32. Avatar
    www.threadless.Com about {{count}} years ago:

    I am really grateful to the holder of this site who has shared this
    wonderful article at here.

  33. Avatar
    www.threadless.Com about {{count}} years ago:

    I am really grateful to the holder of this site who has shared this wonderful
    article at here.

  34. Avatar
    Berry about {{count}} years ago:

    What’s up to every single one, it’s actually a nice for me
    to pay a visit this site, it consists of helpful Information.

  35. Avatar
    Berry about {{count}} years ago:

    What’s up to every single one, it’s actually a nice for me
    to pay a visit this site, it consists of helpful Information.

Leave a comment