[English Document] [中文文档]
A opensource javascript library for converting chinese to pinyin
Thanks for JPinyin
Demo Online: https://npm.runkit.com/pinyin4js
- Zero-dependency
- Fork & Package yourself easily
- Support Traditional and Simplified Chinese
- Support multiple pinyin style
- Support Node and Browser
- INSTALL
Brower
<script src="./dist/pinyin4js.js"></script>
Node
npm install pinyin4js
- USE
//[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('厦门你好大厦厦门'))
// <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('厦门你好大厦厦门'))
- 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