@leonsilicon/mozillazg-pinyin-data
v0.0.1
Published
Mapping of Chinese characters to pinyin (with tone numbers) derived from mozillazg/pinyin-data, distributed as JSON.
Maintainers
Readme
@leonsilicon/mozillazg-pinyin-data
Mapping of Chinese characters to pinyin readings, with tone numbers (e.g. yi1) instead of diacritics. The data is derived from mozillazg/pinyin-data and converted at build time using pinyin-tone2.
Install
npm install @leonsilicon/mozillazg-pinyin-dataUsage
The package exposes a single subpath, /pinyin. Internally it re-exports pinyin.json using an import attribute, so consumers can use a plain default import:
import pinyin from "@leonsilicon/mozillazg-pinyin-data/pinyin";
pinyin["一"]; // ["yi1", "yi2", "yi4"]
pinyin["略"]; // ["lve4"]
pinyin["〇"]; // ["ling2", "yuan2", "xing1"]TypeScript:
import pinyin from "@leonsilicon/mozillazg-pinyin-data/pinyin";
// pinyin is typed as Record<string, string[]>Tone numbers
- Tones 1–4 are appended as a single digit (
a→a1,a2,a3,a4). - The neutral tone is written as
5(e.g.ma5). üis written asv(e.g.lüè→lve4).ê(used in a handful of interjections like 欸) is written ase^(e.g.ế→e^2).- Syllabic-consonant interjections (
ḿ ǹ ňg …from characters like 呒, 嗯) are written with the tone digit directly on the base letter (m2,n4,ng3, …).
Rebuild the data
The JSON file is regenerated from data/pinyin.txt:
bun run buildThis writes pinyin.json at the repository root.
License
MIT. The underlying character→pinyin mapping is from mozillazg/pinyin-data (MIT).
