Giter VIP home page Giter VIP logo

npm-pinyin-separate's Introduction

pinyin-separate

dependencies Status devDependencies Status License: MIT npm total downloads

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 - Remove lib/ directory
  • npm test - Run tests with linting
  • npm test:only - Run tests without linting
  • npm test:watch - Re-run tests on file changes
  • npm test:prod - Run tests with minified code
  • npm run test:examples - Test examples with node
  • npm run lint - Run ESlint with airbnb-config
  • npm run build - Babel will transpile ES6 => ES5 and minify the code, Browserify will create a bundle in dist/ 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

npm-pinyin-separate's People

Contributors

connum avatar dependabot[bot] avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

longjiang

npm-pinyin-separate's Issues

Wrong separation of "ne" syllable

Hi!
Great solution! But it still has some problem
e.g. a phrase like "wohenhaonine?" it will split into wo hen hao nine
leaving the last "ne" unseparated.
I believe the problems is in this regex:
.replace(new RegExp(`([${vowels}])([^${vowels}nr])`, 'gi'), '$1 $2')
Sorry, I can't make a pull request because I'm not a javascript coder but I'm porting your code to dart and have found this problem.
So, my proposed solution is to add one more match group like this:
.replace(new RegExp(`([${vowels}])(([^${vowels}nr])|(ne))`, 'gi'), '$1 $2')

Not sure if it will not break anything, but as long as I tested it in dart, it works ok

Cheers!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.