中文 | Online trial / documentation | Update log | Feedback error / missing | Gitee | QQ Group: 958278438 | Message Board
Before starting the documentation, let's take a look at some use cases to see what cnchar can do
Chinese character typing game | Typing and playing the piano | Idiom Solitaire | Address Book Sort | name | input method | Xie Houyu | Speech Recognition and Synthesis | Simplified and Traditional Conversion
Thank you for your support for cnchar. Since the cnchar lexicon comes from the Internet, although it has been modified and expanded by myself, it is still inevitable that there are errors and gaps. I hope you can feedback the errors and gaps found in use I (or amend and submit it by myself, and it will be merged into cnchar after reviewing without error)
I want to report errors or omissions
Use npm to install:
npm i cnchar
import cnchar from 'cnchar';
'汉字'.spell();
'汉字'.stroke();
Use the script tag to use:
<script src="https://fastly.jsdelivr.net/npm/cnchar/cnchar.min.js"></script>
<script>
'汉字'.spell();
'汉字'.stroke();
</script>
- Get Chinese Pinyin, support initial letter, capitalization, array division, optional polyphonic word and other functions
- Support polyphonic words, pinyin tone
- Obtain Chinese characters stroke number , stroke order , and detailed stroke names
- Support visualization drawing Chinese strokes, a variety of drawing modes are optional
- Support speech synthesis and speech recognition
- Support Chinese character grouping and Chinese character interpretation
- Support Simplified characters , Traditional characters , Mars script mutual conversion
- Support find all Chinese characters of a certain pinyin, traditional characters, polyphonic characters
- Support find all Chinese characters with the specified number of strokes, traditional Chinese characters
- Support Search by stroke order Chinese characters
- Support search pinyin information, including initials, finals, tones, tonal positions, etc.
- Support traditional characters pinyin, number of strokes and all the above functions, to achieve the same functions as simplified characters
- Support idiom query function, you can query idioms according to Chinese characters, pinyin (tone), and the number of strokes
- Support Xiehouyu query function, support fuzzy query
- Support Radicals query function
- Support randomly generated Pinyin, Chinese characters, words, idioms, Xiehouyu, Chinese names
- Support Chinese character code query, Chinese character information query
- Support Pinyin input method, Wubi input method, support associative input
- Support custom plug-in, independent and simple access method, fully use all functions of cnchar
- Support custom pinyin strokes and other data, more flexible to use
- For some large dictionaries, support offline use, custom deployment
- Provide Chinese character tools to facilitate developers to operate Pinyin and Chinese characters more conveniently and efficiently.
- Small size, min version is only 75 kb, zip version is 50 kb (contains a large number of Chinese pinyin dictionaries)
- Multi-terminal available, can be used for browser, nodejs, applet/minigame, ReactNative/Weex/Uniapp/Electron, webpack..., supports all environments where js can run
- typescript, the main library and all plug-in libraries are developed using typescript
- Rich configuration, divided into plug-ins according to functions, available on demand
- Support IE9 and above
Taking into account different needs, the functions of cnchar are split into the following multiple plug-in libraries, which are convenient for developers to use on demand:
Name | Description | Features | Supported Versions | Node Support | Mini Programs |
---|---|---|---|---|---|
cnchar | The main js library, the other three libraries depend on this library | Contains functions such as simplified Chinese pinyin, polyphonic characters, pitch, number of strokes, etc. | -- | Yes | Yes |
cnchar-poly | Polysyllabic Thesaurus | Contains the function of identifying polysyllabic words | -- | Yes | Yes |
cnchar-order | Stroke Order Library | Contains functions to identify stroke order, stroke name, stroke shape, etc. | -- | Yes | Yes |
cnchar-trad | Traditional font library | Support traditional, Mars, Simplified conversion, support traditional Pinyin strokes and polyphonic characters full function | -- | Yes | Yes |
cnchar-draw | Drawing stroke library | Supports visual drawing of Chinese characters, this library can be used without cnchar, this library is only available in browser environment | 2.1+ | No | Partial |
cnchar-idiom | Idiom library | Support idiom query and other functions | 2.2+ | Yes | Yes |
cnchar-xhy | Xie Houyu Library | Support Xie Houyu query and other functions | 2.2+ | Yes | Yes |
cnchar-radical | Radical Library | Supports querying Chinese radicals | 2.2.5+ | Yes | Yes |
cnchar-words | Chinese character group thesaurus | Supports querying phrases based on single or multiple Chinese characters | 3.1.0+ | Yes | Yes |
cnchar-explain | Chinese character interpretation library | Support to query the meaning of Chinese characters | 3.1.0+ | Yes | Yes |
cnchar-voice | Speech Recognition and Speech Synthesis | Supports Chinese Pronunciation and Synthesis | 3.1.0+ | No | Partial |
cnchar-data | Offline dictionary library | To support offline use and custom deployment of some plug-in libraries | 3.1.0+ | Yes | Yes |
cnchar-input | Input Method Support | Support Pinyin and Wubi Input Method Results | 3.2.0+ | Yes | Yes |
cnchar-code | Chinese character encoding library | Chinese character encoding query | 3.2.0+ | Yes | Yes |
cnchar-info | Chinese character information query | Used to query Chinese character information | 3.2.0+ | Yes | Yes |
cnchar-name | Chinese name information | Used to generate names randomly | 3.2.0+ | Yes | Yes |
Detailed API documentation is not maintained in this readme from v3.2.4, go to Online Documentation
Install the basic library:
npm i cnchar
Install additional function library:
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
Of course, you can also install several of them on demand, and the plug-in library can also be installed and used independently from cnchar, but some warehouse functions strongly depend on cnchar, such as cnchar-poly cnchar-order cnchar-trad
Or you can use the full functionality by installing cnchar-all
, this library references all the above plugin libraries
npm i cnchar-all
If jsdelivr is down, you can use unpkg (https://unpkg.com/cnchar/cnchar.min.js)
<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 src="https://fastly.jsdelivr.net/npm/cnchar-order/cnchar.order.min.js"></script>
<script src="https://fastly.jsdelivr.net/npm/cnchar-trad/cnchar.trad.min.js"></script>
<script src="https://fastly.jsdelivr.net/npm/cnchar-draw/cnchar.draw.min.js"></script>
<script src="https://fastly.jsdelivr.net/npm/cnchar-idiom/cnchar.idiom.min.js"></script>
<script src="https://fastly.jsdelivr.net/npm/cnchar-xhy/cnchar.xhy.min.js"></script>
<script src="https://fastly.jsdelivr.net/npm/cnchar-radical/cnchar.radical.min.js"></script>
<script src="https://fastly.jsdelivr.net/npm/cnchar-words/cnchar.words.min.js"></script>
<script src="https://fastly.jsdelivr.net/npm/cnchar-explain/cnchar.explain.min.js"></script>
<script src="https://fastly.jsdelivr.net/npm/cnchar-voice/cnchar.voice.min.js"></script>
<script src="https://fastly.jsdelivr.net/npm/cnchar-random/cnchar.random.min.js"></script>
<script src="https://fastly.jsdelivr.net/npm/cnchar-code/cnchar.code.min.js"></script>
<script src="https://fastly.jsdelivr.net/npm/cnchar-input/cnchar.input.min.js"></script>
<script src="https://fastly.jsdelivr.net/npm/cnchar-info/cnchar.info.min.js"></script>
<script src="https://fastly.jsdelivr.net/npm/cnchar-name/cnchar.name.min.js"></script>
Or use the following cdn, which contains the above eleven libraries
<script src="https://fastly.jsdelivr.net/npm/cnchar-all/cnchar.all.min.js"></script>
After npm installs several libraries:
// Please ensure that the cnchar base library is introduced first, and the order of the other libraries does not matter
import cnchar from 'cnchar';
import 'cnchar-poly';
// ... For other plugins, please refer to Chapter 2 2. Overview of functions and plugins
// Please use the plugin as needed
console.log('汉字'.spell()); // Called by prototype
console.log(cnchar.spell('汉字')); // cnchar api call
In the browser environment, a cnchar object will be defined on the window object
In the non-browser environment, you need to use the cnchar.use()
method to load the function library:
// Please ensure that the cnchar base library is introduced first, and the order of the other libraries does not matter
var cnchar = require('cnchar');
var poly = require('cnchar-poly');
// ... For other plugins, please refer to Chapter 2 2. Overview of functions and plugins
// Please use the plugin as needed
// Note: cnchar-draw, cnchar-voice are not available in non-browser environments
cnchar.use(poly);
console.log('汉字'.spell()); // Called by prototype
console.log(cnchar.spell('汉字')); // cnchar api call
Other usage methods are consistent with the browser environment
The native browser environment requires the use of script tags to import js files:
<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>
<!--... For other plugins, please refer to Chapter 2 2. Overview of functions and plugins-->
<script>
console.log('汉字'.spell()); // Called by prototype
console.log(cnchar.spell('汉字')); // cnchar api call
</script>
Acknowledgements
The cnchar-draw
library function is based on hanzi-writer, thanks very much!
Contributors