pinyin-pro Documentation

repository·main·Indexed 26 days ago

https://github.com/zh-lx/pinyin-pro

A professional JavaScript library for Chinese character to Pinyin conversion, designed for high accuracy and performance. It supports polyphone recognition, Pinyin matching, HTML ruby tag generation, and format conversion. The library is compatible with Node.js and browser environments and can be extended with supplementary dictionaries from the @pinyin-pro/data package, including datasets from the Modern Chinese Dictionary (7th Edition) and jieba.

Tokens
19.8K
Snippets
71
Records
150
Agent score
85%

What's inside pinyin-pro

  1. Overview of available dictionary data packages

    main

    The @pinyin-pro/data package provides several dictionary datasets to extend the capabilities of pinyin-pro:

    • modern.json: Pinyin collection from the Modern Chinese Dictionary (7th Edition) (approx. 0.6 MB gzipped).
    • complete.json: Pinyin collection from the jieba Chinese segmentation library (approx. 3.99 MB gzipped).
    • chars.json: Supplementary dictionary for rare/uncommon characters (approx. 0.1 KB gzipped).
  2. Compare pinyin-pro performance and accuracy

    main
    pinyin-pro is a professional JavaScript library for converting Chinese to Pinyin. It is designed for high accuracy, lightweight size, and excellent performance. Compared to competitors like pinyin and @napi-rs/pinyin, pinyin-pro offers higher accuracy (99.846%) and significantly faster performance for large datasets. It is compatible with both Browser and Node.js environments.
  3. Explore pinyin-pro features

    main

    pinyin-pro is a professional Chinese pinyin conversion library designed for high accuracy and performance. Key capabilities include:

    • Chinese Pinyin conversion: Converting Chinese characters to pinyin.
    • Segmentation: Segmenting Chinese text.
    • Pinyin matching: Matching Chinese text with pinyin.
    • HTML string support: Handling pinyin within HTML strings.

    The library utilizes algorithms like AC automata, greedy algorithms, and hash function optimization to ensure excellent performance, backed by a massive processed Chinese pinyin database for high recognition accuracy.

  4. Import pinyin-pro in different environments

    main

    Depending on your runtime or build system, use one of the following methods to import the library.

    ESM (Modern JavaScript/TypeScript):

    import { pinyin } from 'pinyin-pro';

    CommonJS (Node.js):

    const { pinyin } = require('pinyin-pro');

    Browser (Script Tag): Include the script from a CDN. The library will be available under the global pinyinPro object.

    <script src="https://cdn.jsdelivr.net/gh/zh-lx/pinyin-pro@latest/dist/pinyin-pro.js"></script>
    <script>
      var { pinyin } = pinyinPro;
      pinyin('汉语拼音'); // 'hàn yǔ pīn yīn'
    </script>