npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@edgeros/jsre-pinyin4js

v1.0.0

Published

A javascript library for converting chinese to pinyin.

Downloads

4

Readme

Overview

A opensource javascript library for converting chinese to pinyin. Features:

Zero dependency

Thesaurus can be imported and packaged flexibly You can adjust the dictionary by yourself, refer to src/dict for details; all resource calls are encapsulated by PinyinResource, and can be modified and packaged by yourself

Accurate and perfect font library Unicode code from 4E00-9FA5 range and 3007 (〇) 20903 Chinese characters, pinyin4js can convert all Chinese characters except 46 variants (there is no standard pinyin for variants).

Fast Pinyin conversion speed After testing, pinyin4js takes about 110 milliseconds for 20902 Chinese characters ranging from 4E00-9FA5.

Multi-pinyin format output support Support multiple pinyin output formats: with phonetic symbols, without phonetic symbols, numbers for phonetic symbols, and pinyin first letter output formats.

Common polyphonic word recognition Support the recognition of common polyphonic characters, including phrases, idioms, place names, etc.

Simplified Traditional Chinese Conversion

Support adding custom dictionaries Support adding user-defined dictionaries.

User can use the following code to import the pinyin4js module .

var pinyin4js = require('pinyin4js');

Support

The following shows pinyin4js module APIs avaliable for each permissions.

 |User Mode|Privilege Mode --|:--:|:--: pinyin4js.pinyinFormat|●|● pinyin4js.pinyinHelper|●|● pinyinHelper.convertToPinyinString|●|● pinyinHelper.getShortPinyin|●|● pinyinHelper.hasMultiPinyin|●|●

Pinyin4js Object

pinyin4js.pinyinFormat

  • {Object} Pinyin tone format options. Optons:
    • WITH_TONE_MARK: With tone.
    • WITHOUT_TONE: Without tone.
    • WITH_TONE_NUMBER: The number represents the tone of the voice.
    • FIRST_LETTER: Acronym style.

pinyin4js.pinyinHelper

  • {Object} This object has some methods to convert Chinese characters into pinyin.

PinyinHelper Object

pinyinHelper.convertToPinyinString(str, separator, format)

  • str {String} Chinese characters to be converted.
  • separator {String} Separator between each pinyin.
  • format {PinyinFormat} Pinyin format:
    • pinyin4js.pinyinFormat.WITH_TONE_NUMBER -- digits represent tones;
    • pinyin4js.pinyinFormat.WITHOUT_TONE -- has no tones;
    • pinyin4js.pinyinFormat.WITH_TONE_MARK -- has tones.
  • Returns: {String} Result string.

Convert the string to Pinyin in the corresponding format.

Example

const {pinyinHelper, pinyinFormat} = require('pinyin4js');

var result = pinyinHelper.convertToPinyinString('你好世界', '-', pinyinFormat.WITHOUT_TONE);
console.log('get pinyin:', result);

pinyinHelper.getShortPinyin(str)

  • str {String} Chinese characters to be converted.
  • Returns: {String} Result string.

Get the first letter of the string corresponding to Pinyin.

Example

const {pinyinHelper} = require('pinyin4js');

var result = pinyinHelper.getShortPinyin('你好世界');
console.log('get first char:', result);

pinyinHelper.hasMultiPinyin(char)

  • char {Char} Chinese character to be check.
  • Returns: {Boolean} Judeg result.

Judge whether a Chinese character is polysyllabic or not.

Example

const {pinyinHelper} = require('pinyin4js');

var result = pinyinHelper.hasMultiPinyin('长');
console.log('Whether it is polysyllabic or not:', result);