Skip to content

Latest commit

 

History

History
88 lines (70 loc) · 2.76 KB

README_EN.md

File metadata and controls

88 lines (70 loc) · 2.76 KB

[English Document] [中文文档]

pinyin4js

Build Status codebeat badge Downloads Version License

A opensource javascript library for converting chinese to pinyin
Thanks for JPinyin
Demo Online: https://npm.runkit.com/pinyin4js

Features

  • Zero-dependency
  • Fork & Package yourself easily
  • Support Traditional and Simplified Chinese
  • Support multiple pinyin style
  • Support Node and Browser

How to use

  • INSTALL

Brower

    <script src="./dist/pinyin4js.js"></script>

Node

    npm install pinyin4js
  • USE

Node

    //[email protected] or latest
    import pinyin4js from 'pinyin4js';

    // more detail methods in test
    // WITH_TONE_NUMBER--数字代表声调,WITHOUT_TONE--不带声调,WITH_TONE_MARK--带声调

    // output: xià#mén#nǐ#hǎo#dà#shà#xià#mén
    console.log(pinyin4js.convertToPinyinString('厦门你好大厦厦门', '#', pinyin4js.WITH_TONE_MARK))

    //首字母风格
    // output: xmnhdsxm
    console.log(pinyin4js.convertToPinyinString('厦门你好大厦厦门', '', pinyin4js.FIRST_LETTER))
    // or
    console.log(pinyin4js.getShortPinyin('厦门你好大厦厦门'))

Browers

    // <script src="./dist/pinyin4js.js"></script>

    // output: xià#mén#nǐ#hǎo#dà#shà#xià#mén
    console.log(PinyinHelper.convertToPinyinString('厦门你好大厦厦门', '#', PinyinFormat.WITH_TONE_MARK))

    //首字母风格
    // output: xmnhdsxm
    console.log(PinyinHelper.convertToPinyinString('厦门你好大厦厦门', '', PinyinFormat.FIRST_LETTER))
    // or
    console.log(PinyinHelper.getShortPinyin('厦门你好大厦厦门'))

How to Dev

  • Init
    git clone https://github.com/superbiger/pinyin4js.git
    cd pinyin4js
    npm install
    npm run build
  • Build Browser
    npm run build
    npm run build-browser
  • Test
    npm run test