Cnchar is a versatile Hanzi toolkit designed to handle pinyin, stroke order, radicals, idioms, and voice synthesis. It is built for high portability and runs in almost any JavaScript environment.
Key Advantages
Installation
Installing via npm
To get started, install the core library:
npm i cnchar
You can then add optional plugins based on your needs:
npm i cnchar-poly cnchar-order cnchar-trad cnchar-draw cnchar-idiom cnchar-xhy cnchar-radical cnchar-words cnchar-explain cnchar-voice cnchar-random cnchar-code cnchar-input cnchar-info cnchar-name
Alternatively, install the entire suite at once:
npm i cnchar-all
Using a CDN
To include the core library:
<script src="https://fastly.jsdelivr.net/npm/cnchar/cnchar.min.js"></script>
To add specific plugins:
<script src="https://fastly.jsdelivr.net/npm/cnchar-poly/cnchar.poly.min.js"></script>
<script src="https://fastly.jsdelivr.net/npm/cnchar-order/cnchar.order.min.js"></script>
Or use the all-in-one package:
<script src="https://fastly.jsdelivr.net/npm/cnchar-all/cnchar.all.min.js"></script>
Implementation
Modern Environments (Webpack/Vite)
import cnchar from 'cnchar';
import 'cnchar-poly'; // Import additional plugins as required
console.log('汉字'.spell()); // Using the prototype method
console.log(cnchar.spell('汉字')); // Using the API call
Node.js
var cnchar = require('cnchar');
var poly = require('cnchar-poly');
cnchar.use(poly);
console.log('汉字'.spell());
console.log(cnchar.spell('汉字'));
Direct Browser Integration
<script src="https://fastly.jsdelivr.net/npm/cnchar/cnchar.min.js"></script>
<script src="https://fastly.jsdelivr.net/npm/cnchar-poly/cnchar.poly.min.js"></script>
<script>
console.log('汉字'.spell());
console.log(cnchar.spell('汉字'));
</script>
Core Capabilities
Pinyin Processing – Retrieve pinyin for Chinese characters with support for first-letter extraction, case sensitivity, array output, and polyphone (multi-pronunciation) detection. It also manages tone marks and multi-syllable words.
Stroke Data – Access stroke counts, stroke order, and official stroke names. When used in a browser, the library can visually render stroke-order animations.
Character Conversion & Lookup – Convert text between Simplified, Traditional, and "Martian" (stylized/leet-speak) Chinese. You can also search for characters by pinyin, stroke count, or specific stroke order.
Extended Features
Earth Copilot: Query Geospatial Data Using Natural Language
Windows-Use: Enabling LLMs to Control the Windows GUI Without Vision Models
Google Analytics MCP Server: Query GA4 Data With Gemini CLI
Easy Agents: Automate Operations with Natural Language and MCP
Alger Music Player: Play Grayed-Out NetEase Songs with Desktop Lyrics
LLM Bridge: A Unified API Schema for OpenAI, Claude, and Gemini
Apple Doc MCP: SwiftUI & UIKit Documentation for Cursor & Claude
MemoryOS: Equip AI Agents with Persistent Recall via a Memory Hierarchy
SelfyAI: Build Your Own AI Agent as a Virtual World Asset
HunyuanVideo-Avatar: Emotion-Controlled Multi-Person Video Generation
Deep Search Lighting: Lightweight Web Search for LLMs
Spacedrive: An Open-Source Cross-Platform File Manager