$ account zh-lx
zh-lx/pinyin-pro is a high-performance JavaScript/TypeScript library for converting Chinese characters (Hanzi) to Pinyin. It is used both in browsers and Node.js environments, supporting a wide range of output formats (tone marks, tone numbers, initials, finals, etc.) and advanced features like surname detection, tone sandhi, polyphonic character handling, word segmentation, and fuzzy text matching. The library is organized as a monorepo with three packages: the core `pinyin-pro` library, a `@pinyin-pro/data` package containing large curated dictionaries (modern, complete, traditional, buddhist), and documentation sites in Chinese and English. Architecturally, the core employs a middleware pipeline to process input text through sequential transformations (non-Chinese handling, pattern extraction, tone type conversion, etc.). It uses an Aho-Corasick automaton for efficient phrase matching against its multi-tier dictionaries (single characters to multi-word phrases). Multiple tokenization strategies (reverse max match, max probability, min tokenization) are implemented for word segmentation. The library has been heavily optimized for performance, achieving ~99.8% accuracy in benchmarks and competitive speed with native Rust-based alternatives. Key entry points are the `pinyin()` function for basic conversion, and additional functions for matching (`match`), segmentation (`segment`), HTML ruby annotation (`html`), polyphonic listing (`polyphonic`), custom dictionary management (`customPinyin`, `addDict`), and format conversion (`convert`). External dependencies are minimal: the library runs entirely on its built-in dictionaries and does not require any runtime dependencies. The codebase is well-tested (vitest) with a dedicated CI pipeline (GitHub Actions) for quality assurance, bundle size comparison, and automated release.