pinyin-separate
v1.2.0
Published
Separates a string containing pinyin notation (with diacritics) into an array of pinyin syllables, even if there are no spaces in between.
Downloads
14
Maintainers
Readme
pinyin-separate
Separates a string containing pinyin notation (with diacritics) into an array of pinyin syllables, even if there are no spaces in between.
This is mainly separate-pinyin-in-syllables.js turned into an npm module, but I made some fixes and extended it to allow "vv̄v́v̆v̀" in addition to "üǖǘǚǜ" as well, so I use my own fork as the base for this module.
Installation
npm install pinyin-separate
or use the files in /dist
or from the releases for direct in-browser usage.
Usage and examples
const pinyinSeparate = require('pinyin-separate').default
// or
import pinyinSeparate from 'pinyin-separate'
// or (for usage in a browser environment)
<script src="dist/pinyin-separate.min.js"></script>
// and then it's as simple as
pinyinSeparate("nĭhăoma"); // result: ['nĭ', 'hăo', 'ma']
// if the syllables in your input string are separated by
// non-breaking spaces (charcode 160), you can set the option "byNbsp"
// to true; that will simply split the string by that character
// without any further splitting/processing. This is a remnant from
// the original lib (second argument of the main function) and probably
// not very useful on its own, but I decided to keep it in for compatibility
pinyinSeparate("jiān rěn bù bá", { // non-breaking spaces!
byNbsp: true
}) // result: ['jiān', 'rěn', 'bù', 'bá']
Options
An optional options object can be passed as a second argument.
| Option Name | Default | Description |
| ------------- | ------------- | ------------- |
| byNbsp
| false
| Split input string by charcode 160 (non-breaking space) without any further processing (see explanation in the code example above) |
Development Commands
npm run clean
- Removelib/
directorynpm test
- Run tests with lintingnpm test:only
- Run tests without lintingnpm test:watch
- Re-run tests on file changesnpm test:prod
- Run tests with minified codenpm run test:examples
- Test examples with nodenpm run lint
- Run ESlint with airbnb-confignpm run build
- Babel will transpile ES6 => ES5 and minify the code, Browserify will create a bundle indist/
for in-browser usage.npm run prepublish
- Hook for npm. Do all the checks before publishing the module.
License
MIT © Connum
based on flexdinesh/npm-module-boilerplate, MIT © Dinesh Pandiyan and separate-pinyin-in-syllables.js, MIT © GitHub user pierophp