feat: 2.2.1 ts引入报错问题,增加ts声明字符串扩展

This commit is contained in:
tackchen 2020-06-15 15:05:15 +08:00
parent cfe294b910
commit bff295987f
49 changed files with 872 additions and 273 deletions

122
README.md
View File

@ -31,61 +31,61 @@ cnchar 由于重建过一次仓库,所以之前的 star 清零了 (〒︿〒)
<!-- toc -->
- [前言](#前言)
- [0.快速使用](#0快速使用)
- [1.功能](#1功能)
- [2.概览](#2概览)
- [3.安装](#3安装)
- [3.1 使用 npm 安装](#31-使用-npm-安装)
- [3.2 使用 script 引入](#32-使用-script-引入)
- [4.使用](#4使用)
- [4.1 webpack浏览器环境(有window对象)](#41-webpack浏览器环境有window对象)
- [4.2 nodejs 等非浏览器环境](#42-nodejs-等非浏览器环境)
- [4.3 原生浏览器环境](#43-原生浏览器环境)
- [前言](#%E5%89%8D%E8%A8%80)
- [0.快速使用](#0%E5%BF%AB%E9%80%9F%E4%BD%BF%E7%94%A8)
- [1.功能](#1%E5%8A%9F%E8%83%BD)
- [2.概览](#2%E6%A6%82%E8%A7%88)
- [3.安装](#3%E5%AE%89%E8%A3%85)
* [3.1 使用 npm 安装](#31-%E4%BD%BF%E7%94%A8-npm-%E5%AE%89%E8%A3%85)
* [3.2 使用 script 引入](#32-%E4%BD%BF%E7%94%A8-script-%E5%BC%95%E5%85%A5)
- [4.使用](#4%E4%BD%BF%E7%94%A8)
* [4.1 webpack浏览器环境(有window对象)](#41-webpack%E6%B5%8F%E8%A7%88%E5%99%A8%E7%8E%AF%E5%A2%83%E6%9C%89window%E5%AF%B9%E8%B1%A1)
* [4.2 nodejs 等非浏览器环境](#42-nodejs-%E7%AD%89%E9%9D%9E%E6%B5%8F%E8%A7%88%E5%99%A8%E7%8E%AF%E5%A2%83)
* [4.3 原生浏览器环境](#43-%E5%8E%9F%E7%94%9F%E6%B5%8F%E8%A7%88%E5%99%A8%E7%8E%AF%E5%A2%83)
- [5.API](#5api)
- [5.1 拼音笔画基础 API: spell & stroke](#51-拼音笔画基础-api-spell--stroke)
- [5.2 可视化绘制汉字: draw](#52-可视化绘制汉字-draw)
- [5.2.1 使用](#521-使用)
- [5.2.2 参数](#522-参数)
- [5.3 繁体、简体、火星文互转: convert](#53-繁体简体火星文互转-convert)
- [5.4 笔画序列推出原汉字: orderToWord](#54-笔画序列推出原汉字-ordertoword)
- [5.5 通过拼音查询原汉字: spellToWord](#55-通过拼音查询原汉字-spelltoword)
- [5.6 通过笔画数查询原汉字: strokeToWord](#56-通过笔画数查询原汉字-stroketoword)
- [5.7 成语功能](#57-成语功能)
- [5.8 歇后语功能](#58-歇后语功能)
- [5.9 汉字、拼音工具方法](#59-汉字拼音工具方法)
- [5.9.1 查询拼音详细信息: spellInfo](#591-查询拼音详细信息-spellinfo)
- [5.9.2 拼音音调操作: transformTone](#592-拼音音调操作-transformtone)
- [5.9.3 是否是汉字: isCnChar](#593-是否是汉字-iscnchar)
- [5.9.4 比较拼音(汉字)大小: compareSpell](#594-比较拼音汉字大小-comparespell)
- [5.9.5 比较汉字笔画数大小: compareStroke](#595-比较汉字笔画数大小-comparestroke)
- [5.9.6 根据拼音排序: sortSpell](#596-根据拼音排序-sortspell)
- [5.9.7 根据笔画数排序: sortStroke](#597-根据笔画数排序-sortstroke)
- [5.10 其他 api](#510-其他-api)
- [5.10.1 .use()](#5101-use)
- [5.10.2 .type](#5102-type)
- [5.10.3 .check](#5103-check)
- [5.10.4 .version](#5104-version)
- [5.10.5 .plugins](#5105-plugins)
- [6.spell stroke 参数](#6spell-stroke-参数)
- [6.1 spell 参数](#61-spell-参数)
- [6.2 stroke 参数](#62-stroke-参数)
- [6.3 orderToWord 参数](#63-ordertoword-参数)
- [6.4 spellToWord 参数](#64-spelltoword-参数)
- [6.5 strokeToWord 参数](#65-stroketoword-参数)
- [6.6 idiom 参数](#66-idiom-参数)
- [6.7 xhy 参数](#67-xhy-参数)
- [6.8 使用实例大全:](#68-使用实例大全)
- [6.8.0 安装使用](#680-安装使用)
- [6.8.1 cnchar 基础库功能](#681-cnchar-基础库功能)
- [6.8.2 cnchar-poly 库功能](#682-cnchar-poly-库功能)
- [6.8.3 cnchar-order 库功能](#683-cnchar-order-库功能)
- [6.8.4 cnchar-trad 库功能](#684-cnchar-trad-库功能)
- [6.8.4.1 convert 字体转换](#6841-convert-字体转换)
- [6.8.4.2 spell 和 stroke 方法](#6842-spell-和-stroke-方法)
- [6.8.5 cnchar-idiom 库功能](#685-cnchar-idiom-库功能)
- [6.8.6 cnchar-xhy 库功能](#686-cnchar-xhy-库功能)
- [6.8.7 工具方法](#687-工具方法)
* [5.1 拼音笔画基础 API: spell & stroke](#51-%E6%8B%BC%E9%9F%B3%E7%AC%94%E7%94%BB%E5%9F%BA%E7%A1%80-api-spell--stroke)
* [5.2 可视化绘制汉字: draw](#52-%E5%8F%AF%E8%A7%86%E5%8C%96%E7%BB%98%E5%88%B6%E6%B1%89%E5%AD%97-draw)
+ [5.2.1 使用](#521-%E4%BD%BF%E7%94%A8)
+ [5.2.2 参数](#522-%E5%8F%82%E6%95%B0)
* [5.3 繁体、简体、火星文互转: convert](#53-%E7%B9%81%E4%BD%93%E7%AE%80%E4%BD%93%E7%81%AB%E6%98%9F%E6%96%87%E4%BA%92%E8%BD%AC-convert)
* [5.4 笔画序列推出原汉字: orderToWord](#54-%E7%AC%94%E7%94%BB%E5%BA%8F%E5%88%97%E6%8E%A8%E5%87%BA%E5%8E%9F%E6%B1%89%E5%AD%97-ordertoword)
* [5.5 通过拼音查询原汉字: spellToWord](#55-%E9%80%9A%E8%BF%87%E6%8B%BC%E9%9F%B3%E6%9F%A5%E8%AF%A2%E5%8E%9F%E6%B1%89%E5%AD%97-spelltoword)
* [5.6 通过笔画数查询原汉字: strokeToWord](#56-%E9%80%9A%E8%BF%87%E7%AC%94%E7%94%BB%E6%95%B0%E6%9F%A5%E8%AF%A2%E5%8E%9F%E6%B1%89%E5%AD%97-stroketoword)
* [5.7 成语功能](#57-%E6%88%90%E8%AF%AD%E5%8A%9F%E8%83%BD)
* [5.8 歇后语功能](#58-%E6%AD%87%E5%90%8E%E8%AF%AD%E5%8A%9F%E8%83%BD)
* [5.9 汉字、拼音工具方法](#59-%E6%B1%89%E5%AD%97%E6%8B%BC%E9%9F%B3%E5%B7%A5%E5%85%B7%E6%96%B9%E6%B3%95)
+ [5.9.1 查询拼音详细信息: spellInfo](#591-%E6%9F%A5%E8%AF%A2%E6%8B%BC%E9%9F%B3%E8%AF%A6%E7%BB%86%E4%BF%A1%E6%81%AF-spellinfo)
+ [5.9.2 拼音音调操作: transformTone](#592-%E6%8B%BC%E9%9F%B3%E9%9F%B3%E8%B0%83%E6%93%8D%E4%BD%9C-transformtone)
+ [5.9.3 是否是汉字: isCnChar](#593-%E6%98%AF%E5%90%A6%E6%98%AF%E6%B1%89%E5%AD%97-iscnchar)
+ [5.9.4 比较拼音(汉字)大小: compareSpell](#594-%E6%AF%94%E8%BE%83%E6%8B%BC%E9%9F%B3%E6%B1%89%E5%AD%97%E5%A4%A7%E5%B0%8F-comparespell)
+ [5.9.5 比较汉字笔画数大小: compareStroke](#595-%E6%AF%94%E8%BE%83%E6%B1%89%E5%AD%97%E7%AC%94%E7%94%BB%E6%95%B0%E5%A4%A7%E5%B0%8F-comparestroke)
+ [5.9.6 根据拼音排序: sortSpell](#596-%E6%A0%B9%E6%8D%AE%E6%8B%BC%E9%9F%B3%E6%8E%92%E5%BA%8F-sortspell)
+ [5.9.7 根据笔画数排序: sortStroke](#597-%E6%A0%B9%E6%8D%AE%E7%AC%94%E7%94%BB%E6%95%B0%E6%8E%92%E5%BA%8F-sortstroke)
* [5.10 其他 api](#510-%E5%85%B6%E4%BB%96-api)
+ [5.10.1 .use()](#5101-use)
+ [5.10.2 .type](#5102-type)
+ [5.10.3 .check](#5103-check)
+ [5.10.4 .version](#5104-version)
+ [5.10.5 .plugins](#5105-plugins)
- [6.spell stroke 参数](#6spell-stroke-%E5%8F%82%E6%95%B0)
* [6.1 spell 参数](#61-spell-%E5%8F%82%E6%95%B0)
* [6.2 stroke 参数](#62-stroke-%E5%8F%82%E6%95%B0)
* [6.3 orderToWord 参数](#63-ordertoword-%E5%8F%82%E6%95%B0)
* [6.4 spellToWord 参数](#64-spelltoword-%E5%8F%82%E6%95%B0)
* [6.5 strokeToWord 参数](#65-stroketoword-%E5%8F%82%E6%95%B0)
* [6.6 idiom 参数](#66-idiom-%E5%8F%82%E6%95%B0)
* [6.7 xhy 参数](#67-xhy-%E5%8F%82%E6%95%B0)
* [6.8 使用实例大全:](#68-%E4%BD%BF%E7%94%A8%E5%AE%9E%E4%BE%8B%E5%A4%A7%E5%85%A8)
+ [6.8.0 安装使用](#680-%E5%AE%89%E8%A3%85%E4%BD%BF%E7%94%A8)
+ [6.8.1 cnchar 基础库功能](#681-cnchar-%E5%9F%BA%E7%A1%80%E5%BA%93%E5%8A%9F%E8%83%BD)
+ [6.8.2 cnchar-poly 库功能](#682-cnchar-poly-%E5%BA%93%E5%8A%9F%E8%83%BD)
+ [6.8.3 cnchar-order 库功能](#683-cnchar-order-%E5%BA%93%E5%8A%9F%E8%83%BD)
+ [6.8.4 cnchar-trad 库功能](#684-cnchar-trad-%E5%BA%93%E5%8A%9F%E8%83%BD)
- [6.8.4.1 convert 字体转换](#6841-convert-%E5%AD%97%E4%BD%93%E8%BD%AC%E6%8D%A2)
- [6.8.4.2 spell 和 stroke 方法](#6842-spell-%E5%92%8C-stroke-%E6%96%B9%E6%B3%95)
+ [6.8.5 cnchar-idiom 库功能](#685-cnchar-idiom-%E5%BA%93%E5%8A%9F%E8%83%BD)
+ [6.8.6 cnchar-xhy 库功能](#686-cnchar-xhy-%E5%BA%93%E5%8A%9F%E8%83%BD)
+ [6.8.7 工具方法](#687-%E5%B7%A5%E5%85%B7%E6%96%B9%E6%B3%95)
- [6.8.7.1 spellInfo](#6871-spellinfo)
- [6.8.7.2 isCnChar](#6872-iscnchar)
- [6.8.7.3 transformTone](#6873-transformtone)
@ -93,7 +93,7 @@ cnchar 由于重建过一次仓库,所以之前的 star 清零了 (〒︿〒)
- [6.8.7.5 compareStroke](#6875-comparestroke)
- [6.8.7.6 sortSpell](#6876-sortspell)
- [6.8.7.7 sortStroke](#6877-sortstroke)
- [7.应用例子](#7应用例子)
- [7.应用例子](#7%E5%BA%94%E7%94%A8%E4%BE%8B%E5%AD%90)
<!-- tocstop -->
@ -194,7 +194,7 @@ npm i cnchar
安装附加功能库:
```
npm i cnchar-poly cnchar-order cnchar-trad cnchar-draw
npm i cnchar-poly cnchar-order cnchar-trad cnchar-draw cnchar-idiom cnchar-xhy
```
当然您也可以按需安装其中的几个,但是 `cnchar` 这个基础库是必须安装的draw、idiom、xhy三个库可以独立使用
@ -1183,11 +1183,11 @@ cnchar.transformTone('lǘ') // {spell: 'lü', tone: 2, index: 2, isTrans: false}
```js
cnchar.compareSpell('ao', 'ai') // 'more'
cnchar.compareSpell('ai', 'ai') // 'even'
cnchar.compareSpell('pín', 'pǐn', 'tone') // 'less'
cnchar.compareSpell('pin2', 'pǐn', 'tone') // 'less'
cnchar.compareSpell('频', 'pǐn', 'tone') // 'less'
cnchar.compareSpell('品', '频', 'tone') // 'more'
cnchar.compareSpell('贫', '频', 'tone') // 'even'
cnchar.compareSpell('pín', 'pǐn', true) // 'less'
cnchar.compareSpell('pin2', 'pǐn', true) // 'less'
cnchar.compareSpell('频', 'pǐn', true) // 'less'
cnchar.compareSpell('品', '频', true) // 'more'
cnchar.compareSpell('贫', '频', true) // 'even'
```
###### 6.8.7.5 compareStroke

View File

@ -1113,11 +1113,11 @@ cnchar.transformTone('lǘ') // {spell: 'lü', tone: 2, index: 2, isTrans: false}
```js
cnchar.compareSpell('ao', 'ai') // 'more'
cnchar.compareSpell('ai', 'ai') // 'even'
cnchar.compareSpell('pín', 'pǐn', 'tone') // 'less'
cnchar.compareSpell('pin2', 'pǐn', 'tone') // 'less'
cnchar.compareSpell('频', 'pǐn', 'tone') // 'less'
cnchar.compareSpell('品', '频', 'tone') // 'more'
cnchar.compareSpell('贫', '频', 'tone') // 'even'
cnchar.compareSpell('pín', 'pǐn', true) // 'less'
cnchar.compareSpell('pin2', 'pǐn', true) // 'less'
cnchar.compareSpell('频', 'pǐn', true) // 'less'
cnchar.compareSpell('品', '频', true) // 'more'
cnchar.compareSpell('贫', '频', true) // 'even'
```
###### 6.8.7.5 compareStroke

View File

@ -128,7 +128,7 @@ npm i cnchar
安装附加功能库:
```
npm i cnchar-poly cnchar-order cnchar-trad cnchar-draw
npm i cnchar-poly cnchar-order cnchar-trad cnchar-draw cnchar-idiom cnchar-xhy
```
当然您也可以按需安装其中的几个,但是 `cnchar` 这个基础库是必须安装的draw、idiom、xhy三个库可以独立使用
@ -1117,11 +1117,11 @@ cnchar.transformTone('lǘ') // {spell: 'lü', tone: 2, index: 2, isTrans: false}
```js
cnchar.compareSpell('ao', 'ai') // 'more'
cnchar.compareSpell('ai', 'ai') // 'even'
cnchar.compareSpell('pín', 'pǐn', 'tone') // 'less'
cnchar.compareSpell('pin2', 'pǐn', 'tone') // 'less'
cnchar.compareSpell('频', 'pǐn', 'tone') // 'less'
cnchar.compareSpell('品', '频', 'tone') // 'more'
cnchar.compareSpell('贫', '频', 'tone') // 'even'
cnchar.compareSpell('pín', 'pǐn', true) // 'less'
cnchar.compareSpell('pin2', 'pǐn', true) // 'less'
cnchar.compareSpell('频', 'pǐn', true) // 'less'
cnchar.compareSpell('品', '频', true) // 'more'
cnchar.compareSpell('贫', '频', true) // 'even'
```
###### 6.8.7.5 compareStroke

13
helper/all/extend.d.ts vendored Normal file
View File

@ -0,0 +1,13 @@
declare type spellArgs = 'array' | 'low' | 'up' | 'first' | 'poly' | 'tone' | 'simple' | 'trad';
declare type strokeArgs = 'letter' | 'shape' | 'count' | 'name' | 'detail' | 'array' | 'order' | 'simple' | 'trad';
interface String {
spell(...args: Array<spellArgs>): string | Array<any>;
stroke(...args: Array<strokeArgs>): number | Array<any>;
convertSimpleToTrad(): string;
convertSimpleToSpark(): string;
convertTradToSimple(): string;
convertTradToSpark(): string;
convertSparkToSimple(): string;
convertSparkToTrad(): string;
}

189
helper/all/index.d.ts vendored Normal file
View File

@ -0,0 +1,189 @@
// all库的声明文件
import './extend';
// draw
declare type DrawType = 'normal' | 'animation' | 'stroke' | 'test';
declare type TestStatusType = 'mistake' | 'correct' | 'complete';
declare class Writer {
constructor();
option: object;
el: HTMLElement;
type: DrawType;
text: Array<string>;
writer: Array<object>;
animateStart():void;
}
declare interface TestStatus {
index: number,
status: TestStatusType,
data: {
character: string;
totalMistakes: number;// 到目前为止在测验期间犯的总错误。
strokeNum?: number;// 当前笔画数。
mistakesOnStroke?: number;// 到目前为止用户绘制此笔划所犯的错误数。
strokesRemaining?: number;// 测验完成前剩余的笔画数。
drawnPath?: {
pathString: string;
points: Array<{x:number;y:number}>
};// 对象包含用户绘制的 pathString ,用于评分的分数。
}
}
declare interface DrawOption {
el?: string | HTMLElement; // 绘制的容器支持选择器或dom若是不填会在body后append一个dom作为容器
type?: DrawType; // 绘制模式默认为normal
clear?: boolean; // 绘制前是否清空容器 默认为true
style?: { // 样式类
backgroundColor?: string, // 默认为#fff
showOutline?: boolean;//: true,
showCharacter?: boolean;//: true,
currentColor?: string;//: '#b44', // 仅在stroke模式下有效
length?: number;//: 60,
padding?: number;//: 5, // 数值, 默认 20。 画布的汉字和边缘之间的填充
outlineColor?: string;//: '#ddd', // 十六进制字符, 默认 '#DDD'。
strokeColor?: string;//: '#555', // 十六进制字符, 默认 '#555'。绘制每个笔划的颜色。
radicalColor?: string;//: null, // 十六进制字符, 默认 null。 如果存在偏旁部首数据,则在笔划中绘制偏旁部首的颜色。 如果没有设置,激光将绘制与其他笔划相同的颜色。
strokeFadeDuration?: number; //400
},
line?: { // 背景线条类
lineStraight?: boolean;// : true,
lineCross?: boolean;// : true,
lineWidth?: number;// : 1,
lineColor?: string;// : '#ddd',
lineDash?: boolean;// : true,
border?: boolean;// : true,
borderWidth?: number;// : 1,
borderColor?: string;// : '#ccc',
borderDash?: boolean;// : false,
},
animation?: {
strokeAnimationSpeed?: number;// : 1, // 数值, 默认 1。 绘制每个笔划的速度必须大于0。增加此数字可以更快地绘制笔划减少绘制笔划的速度更慢。
delayBetweenStrokes?: number;// : 1000, // 数值, 默认 1000。 动画进行中每个笔画之间的间隔时间(以毫秒为单位)。
delayBetweenLoops?: number;// : 200, // 数值, 默认 2000。 循环动画时每个动画循环之间的时间(以毫秒为单位)。
autoAnimate?: boolean;// : true,
animateComplete?: Function;// : () => {},
stepByStep?: boolean;// : true,
loopAnimate?: boolean;// : false,
},
test?: {
strokeHighlightSpeed?: number;// : 20, // 数值, 默认 20。 在测验中给出提示时突出显示每个笔划的速度必须大于0。增加此数字以突出显示更快减少以突出显示更慢。
highlightColor?: number;// : '#aaf', // 十六进制字符, 默认 '#AAF'。 用于在测验中突出显示的颜色。
drawingColor?: number;// : '#333', // 十六进制字符, 默认 '#333'。 测验期间绘制的线条颜色。
drawingWidth?: number;// : 4, // 数值, 默认 4。 进行测验时绘制的线条宽度。
showHintAfterMisses?: number;// : 3, // 整数, 默认 3 中风高亮提示之前的未命中数被给予用户。 设置为 false 以禁用。 创建测验时也可以设置此项。
highlightOnComplete?: number;// : true, // 布尔值, 默认 true。 控制当用户完成绘制整个字符时,测验是否会短暂突出显示字符。 创建测验时也可以设置此项。
highlightCompleteColor?: number;// : null, // 十六进制字符, 默认 null。 在测验中突出显示字符时使用的颜色。 如果未设置则将使用highlightColor。 仅当highlightOnComplete为true时才相关。
onTestStatus?(args: TestStatus):void;// : null, // ({index, status, data})=>{}
}
}
export declare interface Draw {
(text:string, option?:DrawOption):Writer;
TYPE: {
ANIMATION: 'animation',
NORMAL: 'normal',
STROKE: 'stroke',
TEST: 'test'
},
TEST_STATUS: {
MISTAKE: 'mistake',
CORRECT: 'correct',
COMPLETE: 'complete'
}
}
// idiom
declare type idiomArg = 'char' | 'stroke' | 'spell' | 'tone';
export declare interface Idiom {
(text:string | Array<string|number>, ...idiomArgs: Array<idiomArg>):Array<string>;
}
// order
declare type orderToWordArg = 'match' | 'matchorder' | 'contain' | 'start' | 'array' | 'simple' | 'trad';
declare type orderName = '横折折撇' | '竖弯' | '横折' | '撇点' | '横斜钩' | '横' | '捺' | '横折钩' | '竖' | '竖钩' | '点' | '撇' | '撇折' | '竖折撇' | '横折折折钩' | '竖折折钩' | '提' | '弯钩' | '斜钩' | '横折折' | '横撇' | '横折提' | '横折折折' | '竖提' | '竖弯钩'
| '竖折折' | '横撇弯钩' | '卧钩' | '横折弯' | '横钩';
// xhy
declare type xhyArg = 'fuzzy' | 'answer' | 'second';
export declare interface XHY {
(text:string, ...xhyArgs: Array<xhyArg>):Array<string>;
}
declare type spellArg = 'array' | 'low' | 'up' | 'first' | 'poly' | 'tone' | 'simple' | 'trad';
declare type strokeArg = 'letter' | 'shape' | 'count' | 'name' | 'detail' | 'array' | 'order' | 'simple' | 'trad';
declare type spellToWordArg = 'poly' | 'alltone' | 'array' | 'simple' | 'trad';
declare type strokeToWordArg = 'array' | 'simple' | 'trad';
declare type pluginArg = 'order' | 'trad' | 'poly' | 'draw' | 'idiom' | 'xhy';
declare type toneType = 0 | 1 | 2 | 3 | 4;
declare type compareType = 'more' | 'less' | 'even';
declare interface spellInfoReturnStatic {
spell: string;
initial: string;
final: string;
tone: number;
index: number;
}
export declare interface CnCharStatic {
spell(sentence: string, ...args: Array<spellArg>): string | Array<any>;
stroke(sentence: string, ...args: Array<strokeArg>): number | Array<any>;
use(...plugins: Array<Function>): void;
spellToWord(spell: string, ...args: Array<spellToWordArg>): string | Array<string>;
strokeToWord(stroke: number, ...args: Array<strokeToWordArg>): string | Array<string>;
spellInfo: {
(spell: string): spellInfoReturnStatic;
tones: Array<string>;
initials: Array<string>;
};
plugins: Array<pluginArg>;
type: {
spell: object;
stroke: object;
spellToWord: object;
strokeToWord: object;
orderToWord?: object;
idiom?: object;
xhy?: object;
};
check: boolean;
readonly version: string;
transformTone(spell: string, tone?: boolean, type?: 'low' | 'up'): {
spell: string;
tone: toneType;
index: number;
isTrans: boolean;
};
isCnChar(word: string): boolean;
compareSpell(spell1: string, spell2: string, tone?: boolean): compareType;
compareStroke(stroke1: string | number, stroke2: string | number): compareType;
sortSpell(spells:Array<string> | string, ...args: Array<'tone'|'desc'>): Array<string> | string;
sortStroke(strokes:Array<string|number> | string, desc?: 'desc'): Array<string> | string;
draw: Draw;
idiom: Idiom;
orderToWord: {
(orders: string | Array<orderName>, ...args: Array<orderToWordArg>): string | Array<string>;
orders: object;
};
convert: {
simpleToSpark(sentence: string): string;
simpleToTrad(sentence: string): string;
sparkToSimple(sentence: string): string;
sparkToTrad(sentence: string): string;
tradToSimple(sentence: string): string;
tradToSpark(sentence: string): string;
};
xhy: XHY;
}
declare const cnchar: CnCharStatic;
export default cnchar;

View File

@ -67,31 +67,33 @@ function copyToNPM () {
.pipe(gulp.dest('npm/idiom'))
.pipe(gulp.dest('npm/xhy'));
gulp.src(['src/main/*.json', 'src/main/index.d.ts', 'LICENSE'])
gulp.src(['src/main/*.json', 'src/main/*.d.ts', 'LICENSE'])
.pipe(gulp.dest('npm/cnchar'));
gulp.src(['src/plugin/order/*.json', 'LICENSE'])
gulp.src(['src/plugin/order/*.json', 'src/plugin/order/*.d.ts', 'LICENSE'])
.pipe(gulp.dest('npm/order'));
gulp.src(['src/plugin/poly/*.json', 'LICENSE'])
gulp.src(['src/plugin/poly/*.json', 'src/plugin/poly/*.d.ts', 'LICENSE'])
.pipe(gulp.dest('npm/poly'));
gulp.src(['src/plugin/trad/*.json', 'LICENSE'])
gulp.src(['src/plugin/trad/*.json', 'src/plugin/trad/*.d.ts', 'LICENSE'])
.pipe(gulp.dest('npm/trad'));
gulp.src(['src/plugin/draw/*.json', 'src/plugin/draw/index.d.ts', 'LICENSE'])
gulp.src(['src/plugin/draw/*.json', 'src/plugin/draw/*.d.ts', 'LICENSE'])
.pipe(gulp.dest('npm/draw'));
gulp.src(['src/plugin/idiom/*.json', 'src/plugin/idiom/index.d.ts', 'LICENSE'])
gulp.src(['src/plugin/idiom/*.json', 'src/plugin/idiom/*.d.ts', 'LICENSE'])
.pipe(gulp.dest('npm/idiom'));
gulp.src(['src/plugin/xhy/*.json', 'src/plugin/xhy/index.d.ts', 'LICENSE'])
gulp.src(['src/plugin/xhy/*.json', 'src/plugin/xhy/*.d.ts', 'LICENSE'])
.pipe(gulp.dest('npm/xhy'));
gulp.src(['src/main/index.d.ts', 'LICENSE'])
.pipe(gulp.dest('npm/all'))
.pipe(gulp.dest('npm/hanzi-util'))
gulp.src(['src/main/*.d.ts', 'LICENSE'])
.pipe(gulp.dest('npm/hanzi-util-base'));
gulp.src(['helper/all/*.d.ts', 'LICENSE'])
.pipe(gulp.dest('npm/all'))
.pipe(gulp.dest('npm/hanzi-util'));
}
function copyLatest () {
// gulp.src(`dist/*.${version}.min.js`)

View File

@ -88,4 +88,9 @@
5. 鸟字增加默认读音
6. 彷徨读音修正
7. cnchar-draw 增加 Promise-polyfill
8. 文档增加Object.assign-polyfill
8. 文档增加Object.assign-polyfill
## 2.2.1
1. 修复ts声明文件的bug
2. ts声明文件增加字符串扩展方法
3. 修复构建npm的bug

File diff suppressed because one or more lines are too long

13
npm/all/extend.d.ts vendored Normal file
View File

@ -0,0 +1,13 @@
declare type spellArgs = 'array' | 'low' | 'up' | 'first' | 'poly' | 'tone' | 'simple' | 'trad';
declare type strokeArgs = 'letter' | 'shape' | 'count' | 'name' | 'detail' | 'array' | 'order' | 'simple' | 'trad';
interface String {
spell(...args: Array<spellArgs>): string | Array<any>;
stroke(...args: Array<strokeArgs>): number | Array<any>;
convertSimpleToTrad(): string;
convertSimpleToSpark(): string;
convertTradToSimple(): string;
convertTradToSpark(): string;
convertSparkToSimple(): string;
convertSparkToTrad(): string;
}

147
npm/all/index.d.ts vendored
View File

@ -1,3 +1,122 @@
// all库的声明文件
import './extend';
// draw
declare type DrawType = 'normal' | 'animation' | 'stroke' | 'test';
declare type TestStatusType = 'mistake' | 'correct' | 'complete';
declare class Writer {
constructor();
option: object;
el: HTMLElement;
type: DrawType;
text: Array<string>;
writer: Array<object>;
animateStart():void;
}
declare interface TestStatus {
index: number,
status: TestStatusType,
data: {
character: string;
totalMistakes: number;// 到目前为止在测验期间犯的总错误。
strokeNum?: number;// 当前笔画数。
mistakesOnStroke?: number;// 到目前为止用户绘制此笔划所犯的错误数。
strokesRemaining?: number;// 测验完成前剩余的笔画数。
drawnPath?: {
pathString: string;
points: Array<{x:number;y:number}>
};// 对象包含用户绘制的 pathString ,用于评分的分数。
}
}
declare interface DrawOption {
el?: string | HTMLElement; // 绘制的容器支持选择器或dom若是不填会在body后append一个dom作为容器
type?: DrawType; // 绘制模式默认为normal
clear?: boolean; // 绘制前是否清空容器 默认为true
style?: { // 样式类
backgroundColor?: string, // 默认为#fff
showOutline?: boolean;//: true,
showCharacter?: boolean;//: true,
currentColor?: string;//: '#b44', // 仅在stroke模式下有效
length?: number;//: 60,
padding?: number;//: 5, // 数值, 默认 20。 画布的汉字和边缘之间的填充
outlineColor?: string;//: '#ddd', // 十六进制字符, 默认 '#DDD'。
strokeColor?: string;//: '#555', // 十六进制字符, 默认 '#555'。绘制每个笔划的颜色。
radicalColor?: string;//: null, // 十六进制字符, 默认 null。 如果存在偏旁部首数据,则在笔划中绘制偏旁部首的颜色。 如果没有设置,激光将绘制与其他笔划相同的颜色。
strokeFadeDuration?: number; //400
},
line?: { // 背景线条类
lineStraight?: boolean;// : true,
lineCross?: boolean;// : true,
lineWidth?: number;// : 1,
lineColor?: string;// : '#ddd',
lineDash?: boolean;// : true,
border?: boolean;// : true,
borderWidth?: number;// : 1,
borderColor?: string;// : '#ccc',
borderDash?: boolean;// : false,
},
animation?: {
strokeAnimationSpeed?: number;// : 1, // 数值, 默认 1。 绘制每个笔划的速度必须大于0。增加此数字可以更快地绘制笔划减少绘制笔划的速度更慢。
delayBetweenStrokes?: number;// : 1000, // 数值, 默认 1000。 动画进行中每个笔画之间的间隔时间(以毫秒为单位)。
delayBetweenLoops?: number;// : 200, // 数值, 默认 2000。 循环动画时每个动画循环之间的时间(以毫秒为单位)。
autoAnimate?: boolean;// : true,
animateComplete?: Function;// : () => {},
stepByStep?: boolean;// : true,
loopAnimate?: boolean;// : false,
},
test?: {
strokeHighlightSpeed?: number;// : 20, // 数值, 默认 20。 在测验中给出提示时突出显示每个笔划的速度必须大于0。增加此数字以突出显示更快减少以突出显示更慢。
highlightColor?: number;// : '#aaf', // 十六进制字符, 默认 '#AAF'。 用于在测验中突出显示的颜色。
drawingColor?: number;// : '#333', // 十六进制字符, 默认 '#333'。 测验期间绘制的线条颜色。
drawingWidth?: number;// : 4, // 数值, 默认 4。 进行测验时绘制的线条宽度。
showHintAfterMisses?: number;// : 3, // 整数, 默认 3 中风高亮提示之前的未命中数被给予用户。 设置为 false 以禁用。 创建测验时也可以设置此项。
highlightOnComplete?: number;// : true, // 布尔值, 默认 true。 控制当用户完成绘制整个字符时,测验是否会短暂突出显示字符。 创建测验时也可以设置此项。
highlightCompleteColor?: number;// : null, // 十六进制字符, 默认 null。 在测验中突出显示字符时使用的颜色。 如果未设置则将使用highlightColor。 仅当highlightOnComplete为true时才相关。
onTestStatus?(args: TestStatus):void;// : null, // ({index, status, data})=>{}
}
}
export declare interface Draw {
(text:string, option?:DrawOption):Writer;
TYPE: {
ANIMATION: 'animation',
NORMAL: 'normal',
STROKE: 'stroke',
TEST: 'test'
},
TEST_STATUS: {
MISTAKE: 'mistake',
CORRECT: 'correct',
COMPLETE: 'complete'
}
}
// idiom
declare type idiomArg = 'char' | 'stroke' | 'spell' | 'tone';
export declare interface Idiom {
(text:string | Array<string|number>, ...idiomArgs: Array<idiomArg>):Array<string>;
}
// order
declare type orderToWordArg = 'match' | 'matchorder' | 'contain' | 'start' | 'array' | 'simple' | 'trad';
declare type orderName = '横折折撇' | '竖弯' | '横折' | '撇点' | '横斜钩' | '横' | '捺' | '横折钩' | '竖' | '竖钩' | '点' | '撇' | '撇折' | '竖折撇' | '横折折折钩' | '竖折折钩' | '提' | '弯钩' | '斜钩' | '横折折' | '横撇' | '横折提' | '横折折折' | '竖提' | '竖弯钩'
| '竖折折' | '横撇弯钩' | '卧钩' | '横折弯' | '横钩';
// xhy
declare type xhyArg = 'fuzzy' | 'answer' | 'second';
export declare interface XHY {
(text:string, ...xhyArgs: Array<xhyArg>):Array<string>;
}
declare type spellArg = 'array' | 'low' | 'up' | 'first' | 'poly' | 'tone' | 'simple' | 'trad';
declare type strokeArg = 'letter' | 'shape' | 'count' | 'name' | 'detail' | 'array' | 'order' | 'simple' | 'trad';
declare type spellToWordArg = 'poly' | 'alltone' | 'array' | 'simple' | 'trad';
@ -14,11 +133,11 @@ declare interface spellInfoReturnStatic {
index: number;
}
export declare interface CnCharStatic {
spell(sentence: string, ...args?: Array<spellArg>): string | Array<any>;
stroke(sentence: string, ...args?: Array<strokeArg>): number | Array<any>;
spell(sentence: string, ...args: Array<spellArg>): string | Array<any>;
stroke(sentence: string, ...args: Array<strokeArg>): number | Array<any>;
use(...plugins: Array<Function>): void;
spellToWord(spell: string, ...args?: Array<spellToWordArg>): string | Array<string>;
strokeToWord(stroke: number, ...args?: Array<strokeToWordArg>): string | Array<string>;
spellToWord(spell: string, ...args: Array<spellToWordArg>): string | Array<string>;
strokeToWord(stroke: number, ...args: Array<strokeToWordArg>): string | Array<string>;
spellInfo: {
(spell: string): spellInfoReturnStatic;
tones: Array<string>;
@ -45,10 +164,24 @@ export declare interface CnCharStatic {
};
isCnChar(word: string): boolean;
compareSpell(spell1: string, spell2: string, tone?: boolean): compareType;
compareStroke(stroke1: string, stroke2: string): compareType;
sortSpell(spells:Array<string> | string, ...args?: Array<'tone'|'desc'>): Array<string> | string;
compareStroke(stroke1: string | number, stroke2: string | number): compareType;
sortSpell(spells:Array<string> | string, ...args: Array<'tone'|'desc'>): Array<string> | string;
sortStroke(strokes:Array<string|number> | string, desc?: 'desc'): Array<string> | string;
draw: Draw;
idiom: Idiom;
orderToWord: {
(orders: string | Array<orderName>, ...args: Array<orderToWordArg>): string | Array<string>;
orders: object;
};
convert: {
simpleToSpark(sentence: string): string;
simpleToTrad(sentence: string): string;
sparkToSimple(sentence: string): string;
sparkToTrad(sentence: string): string;
tradToSimple(sentence: string): string;
tradToSpark(sentence: string): string;
};
xhy: XHY;
}
declare const cnchar: CnCharStatic;

View File

@ -1,18 +1,18 @@
"use strict";
var cnchar = require('cnchar');
var cnchar = require('../../main');
var order = require('cnchar-order');
var order = require('../order');
var trad = require('cnchar-trad');
var trad = require('../trad');
var poly = require('cnchar-poly');
var poly = require('../poly');
var draw = require('cnchar-draw');
var draw = require('../draw');
var idiom = require('cnchar-idiom');
var idiom = require('../idiom');
var xhy = require('cnchar-xhy');
var xhy = require('../xhy');
cnchar.use(order, trad, poly, draw, idiom, xhy);
module.exports = cnchar;

View File

@ -1,6 +1,6 @@
{
"name": "cnchar-all",
"version": "2.2.1",
"version": "2.2.2",
"description": "功能全面、多端支持的汉字拼音笔画js库支持多音字、繁体字、火星文",
"main": "index.js",
"unpkg": "cnchar.all.min.js",
@ -27,12 +27,12 @@
},
"homepage": "https://www.theajack.com/cnchar/",
"dependencies": {
"cnchar": "^2.2.0",
"cnchar-order": "^2.2.0",
"cnchar-poly": "^2.2.0",
"cnchar-trad": "^2.2.0",
"cnchar-draw": "^2.2.0",
"cnchar-idiom": "^2.2.0",
"cnchar-xhy": "^2.2.0"
"cnchar": "^2.2.1",
"cnchar-order": "^2.2.1",
"cnchar-poly": "^2.2.1",
"cnchar-trad": "^2.2.1",
"cnchar-draw": "^2.2.1",
"cnchar-idiom": "^2.2.1",
"cnchar-xhy": "^2.2.1"
}
}

View File

@ -1,10 +1,13 @@
<p>
<a href="https://github.com/theajack/cnchar" style='font-size:40px;margin-right:10px;font-weight:bold;'>cnchar</a>
<p align="center">
<img src='https://cdn.jsdelivr.net/gh/theajack/cnchar/dist/rm-logo.png' width='200px'/>
</p>
<p align="center">
<a href="https://www.github.com/theajack/cnchar"><img src="https://img.shields.io/github/stars/theajack/cnchar.svg?style=social" alt="star"></a>
<a href="https://theajack.gitee.io"><img src="https://img.shields.io/badge/author-theajack-blue.svg?style=social" alt="Author"></a>
</p>
<p>
<p align="center">
<a href="https://www.npmjs.com/package/cnchar"><img src="https://img.shields.io/npm/v/cnchar.svg" alt="Version"></a>
<a href="https://npmcharts.com/compare/cnchar?minimal=true"><img src="https://img.shields.io/npm/dm/cnchar.svg" alt="Downloads"></a>
<a href="https://cdn.jsdelivr.net/gh/theajack/cnchar/dist/cnchar.latest.min.js"><img src="https://img.shields.io/bundlephobia/minzip/cnchar.svg" alt="Size"></a>
@ -28,61 +31,61 @@ cnchar 由于重建过一次仓库,所以之前的 star 清零了 (〒︿〒)
<!-- toc -->
- [前言](#前言)
- [0.快速使用](#0快速使用)
- [1.功能](#1功能)
- [2.概览](#2概览)
- [3.安装](#3安装)
- [3.1 使用 npm 安装](#31-使用-npm-安装)
- [3.2 使用 script 引入](#32-使用-script-引入)
- [4.使用](#4使用)
- [4.1 webpack浏览器环境(有window对象)](#41-webpack浏览器环境有window对象)
- [4.2 nodejs 等非浏览器环境](#42-nodejs-等非浏览器环境)
- [4.3 原生浏览器环境](#43-原生浏览器环境)
- [前言](#%E5%89%8D%E8%A8%80)
- [0.快速使用](#0%E5%BF%AB%E9%80%9F%E4%BD%BF%E7%94%A8)
- [1.功能](#1%E5%8A%9F%E8%83%BD)
- [2.概览](#2%E6%A6%82%E8%A7%88)
- [3.安装](#3%E5%AE%89%E8%A3%85)
* [3.1 使用 npm 安装](#31-%E4%BD%BF%E7%94%A8-npm-%E5%AE%89%E8%A3%85)
* [3.2 使用 script 引入](#32-%E4%BD%BF%E7%94%A8-script-%E5%BC%95%E5%85%A5)
- [4.使用](#4%E4%BD%BF%E7%94%A8)
* [4.1 webpack浏览器环境(有window对象)](#41-webpack%E6%B5%8F%E8%A7%88%E5%99%A8%E7%8E%AF%E5%A2%83%E6%9C%89window%E5%AF%B9%E8%B1%A1)
* [4.2 nodejs 等非浏览器环境](#42-nodejs-%E7%AD%89%E9%9D%9E%E6%B5%8F%E8%A7%88%E5%99%A8%E7%8E%AF%E5%A2%83)
* [4.3 原生浏览器环境](#43-%E5%8E%9F%E7%94%9F%E6%B5%8F%E8%A7%88%E5%99%A8%E7%8E%AF%E5%A2%83)
- [5.API](#5api)
- [5.1 拼音笔画基础 API: spell & stroke](#51-拼音笔画基础-api-spell--stroke)
- [5.2 可视化绘制汉字: draw](#52-可视化绘制汉字-draw)
- [5.2.1 使用](#521-使用)
- [5.2.2 参数](#522-参数)
- [5.3 繁体、简体、火星文互转: convert](#53-繁体简体火星文互转-convert)
- [5.4 笔画序列推出原汉字: orderToWord](#54-笔画序列推出原汉字-ordertoword)
- [5.5 通过拼音查询原汉字: spellToWord](#55-通过拼音查询原汉字-spelltoword)
- [5.6 通过笔画数查询原汉字: strokeToWord](#56-通过笔画数查询原汉字-stroketoword)
- [5.7 成语功能](#57-成语功能)
- [5.8 歇后语功能](#58-歇后语功能)
- [5.9 汉字、拼音工具方法](#59-汉字拼音工具方法)
- [5.9.1 查询拼音详细信息: spellInfo](#591-查询拼音详细信息-spellinfo)
- [5.9.2 拼音音调操作: transformTone](#592-拼音音调操作-transformtone)
- [5.9.3 是否是汉字: isCnChar](#593-是否是汉字-iscnchar)
- [5.9.4 比较拼音(汉字)大小: compareSpell](#594-比较拼音汉字大小-comparespell)
- [5.9.5 比较汉字笔画数大小: compareStroke](#595-比较汉字笔画数大小-comparestroke)
- [5.9.6 根据拼音排序: sortSpell](#596-根据拼音排序-sortspell)
- [5.9.7 根据笔画数排序: sortStroke](#597-根据笔画数排序-sortstroke)
- [5.10 其他 api](#510-其他-api)
- [5.10.1 .use()](#5101-use)
- [5.10.2 .type](#5102-type)
- [5.10.3 .check](#5103-check)
- [5.10.4 .version](#5104-version)
- [5.10.5 .plugins](#5105-plugins)
- [6.spell stroke 参数](#6spell-stroke-参数)
- [6.1 spell 参数](#61-spell-参数)
- [6.2 stroke 参数](#62-stroke-参数)
- [6.3 orderToWord 参数](#63-ordertoword-参数)
- [6.4 spellToWord 参数](#64-spelltoword-参数)
- [6.5 strokeToWord 参数](#65-stroketoword-参数)
- [6.6 idiom 参数](#66-idiom-参数)
- [6.7 xhy 参数](#67-xhy-参数)
- [6.8 使用实例大全:](#68-使用实例大全)
- [6.8.0 安装使用](#680-安装使用)
- [6.8.1 cnchar 基础库功能](#681-cnchar-基础库功能)
- [6.8.2 cnchar-poly 库功能](#682-cnchar-poly-库功能)
- [6.8.3 cnchar-order 库功能](#683-cnchar-order-库功能)
- [6.8.4 cnchar-trad 库功能](#684-cnchar-trad-库功能)
- [6.8.4.1 convert 字体转换](#6841-convert-字体转换)
- [6.8.4.2 spell 和 stroke 方法](#6842-spell-和-stroke-方法)
- [6.8.5 cnchar-idiom 库功能](#685-cnchar-idiom-库功能)
- [6.8.6 cnchar-xhy 库功能](#686-cnchar-xhy-库功能)
- [6.8.7 工具方法](#687-工具方法)
* [5.1 拼音笔画基础 API: spell & stroke](#51-%E6%8B%BC%E9%9F%B3%E7%AC%94%E7%94%BB%E5%9F%BA%E7%A1%80-api-spell--stroke)
* [5.2 可视化绘制汉字: draw](#52-%E5%8F%AF%E8%A7%86%E5%8C%96%E7%BB%98%E5%88%B6%E6%B1%89%E5%AD%97-draw)
+ [5.2.1 使用](#521-%E4%BD%BF%E7%94%A8)
+ [5.2.2 参数](#522-%E5%8F%82%E6%95%B0)
* [5.3 繁体、简体、火星文互转: convert](#53-%E7%B9%81%E4%BD%93%E7%AE%80%E4%BD%93%E7%81%AB%E6%98%9F%E6%96%87%E4%BA%92%E8%BD%AC-convert)
* [5.4 笔画序列推出原汉字: orderToWord](#54-%E7%AC%94%E7%94%BB%E5%BA%8F%E5%88%97%E6%8E%A8%E5%87%BA%E5%8E%9F%E6%B1%89%E5%AD%97-ordertoword)
* [5.5 通过拼音查询原汉字: spellToWord](#55-%E9%80%9A%E8%BF%87%E6%8B%BC%E9%9F%B3%E6%9F%A5%E8%AF%A2%E5%8E%9F%E6%B1%89%E5%AD%97-spelltoword)
* [5.6 通过笔画数查询原汉字: strokeToWord](#56-%E9%80%9A%E8%BF%87%E7%AC%94%E7%94%BB%E6%95%B0%E6%9F%A5%E8%AF%A2%E5%8E%9F%E6%B1%89%E5%AD%97-stroketoword)
* [5.7 成语功能](#57-%E6%88%90%E8%AF%AD%E5%8A%9F%E8%83%BD)
* [5.8 歇后语功能](#58-%E6%AD%87%E5%90%8E%E8%AF%AD%E5%8A%9F%E8%83%BD)
* [5.9 汉字、拼音工具方法](#59-%E6%B1%89%E5%AD%97%E6%8B%BC%E9%9F%B3%E5%B7%A5%E5%85%B7%E6%96%B9%E6%B3%95)
+ [5.9.1 查询拼音详细信息: spellInfo](#591-%E6%9F%A5%E8%AF%A2%E6%8B%BC%E9%9F%B3%E8%AF%A6%E7%BB%86%E4%BF%A1%E6%81%AF-spellinfo)
+ [5.9.2 拼音音调操作: transformTone](#592-%E6%8B%BC%E9%9F%B3%E9%9F%B3%E8%B0%83%E6%93%8D%E4%BD%9C-transformtone)
+ [5.9.3 是否是汉字: isCnChar](#593-%E6%98%AF%E5%90%A6%E6%98%AF%E6%B1%89%E5%AD%97-iscnchar)
+ [5.9.4 比较拼音(汉字)大小: compareSpell](#594-%E6%AF%94%E8%BE%83%E6%8B%BC%E9%9F%B3%E6%B1%89%E5%AD%97%E5%A4%A7%E5%B0%8F-comparespell)
+ [5.9.5 比较汉字笔画数大小: compareStroke](#595-%E6%AF%94%E8%BE%83%E6%B1%89%E5%AD%97%E7%AC%94%E7%94%BB%E6%95%B0%E5%A4%A7%E5%B0%8F-comparestroke)
+ [5.9.6 根据拼音排序: sortSpell](#596-%E6%A0%B9%E6%8D%AE%E6%8B%BC%E9%9F%B3%E6%8E%92%E5%BA%8F-sortspell)
+ [5.9.7 根据笔画数排序: sortStroke](#597-%E6%A0%B9%E6%8D%AE%E7%AC%94%E7%94%BB%E6%95%B0%E6%8E%92%E5%BA%8F-sortstroke)
* [5.10 其他 api](#510-%E5%85%B6%E4%BB%96-api)
+ [5.10.1 .use()](#5101-use)
+ [5.10.2 .type](#5102-type)
+ [5.10.3 .check](#5103-check)
+ [5.10.4 .version](#5104-version)
+ [5.10.5 .plugins](#5105-plugins)
- [6.spell stroke 参数](#6spell-stroke-%E5%8F%82%E6%95%B0)
* [6.1 spell 参数](#61-spell-%E5%8F%82%E6%95%B0)
* [6.2 stroke 参数](#62-stroke-%E5%8F%82%E6%95%B0)
* [6.3 orderToWord 参数](#63-ordertoword-%E5%8F%82%E6%95%B0)
* [6.4 spellToWord 参数](#64-spelltoword-%E5%8F%82%E6%95%B0)
* [6.5 strokeToWord 参数](#65-stroketoword-%E5%8F%82%E6%95%B0)
* [6.6 idiom 参数](#66-idiom-%E5%8F%82%E6%95%B0)
* [6.7 xhy 参数](#67-xhy-%E5%8F%82%E6%95%B0)
* [6.8 使用实例大全:](#68-%E4%BD%BF%E7%94%A8%E5%AE%9E%E4%BE%8B%E5%A4%A7%E5%85%A8)
+ [6.8.0 安装使用](#680-%E5%AE%89%E8%A3%85%E4%BD%BF%E7%94%A8)
+ [6.8.1 cnchar 基础库功能](#681-cnchar-%E5%9F%BA%E7%A1%80%E5%BA%93%E5%8A%9F%E8%83%BD)
+ [6.8.2 cnchar-poly 库功能](#682-cnchar-poly-%E5%BA%93%E5%8A%9F%E8%83%BD)
+ [6.8.3 cnchar-order 库功能](#683-cnchar-order-%E5%BA%93%E5%8A%9F%E8%83%BD)
+ [6.8.4 cnchar-trad 库功能](#684-cnchar-trad-%E5%BA%93%E5%8A%9F%E8%83%BD)
- [6.8.4.1 convert 字体转换](#6841-convert-%E5%AD%97%E4%BD%93%E8%BD%AC%E6%8D%A2)
- [6.8.4.2 spell 和 stroke 方法](#6842-spell-%E5%92%8C-stroke-%E6%96%B9%E6%B3%95)
+ [6.8.5 cnchar-idiom 库功能](#685-cnchar-idiom-%E5%BA%93%E5%8A%9F%E8%83%BD)
+ [6.8.6 cnchar-xhy 库功能](#686-cnchar-xhy-%E5%BA%93%E5%8A%9F%E8%83%BD)
+ [6.8.7 工具方法](#687-%E5%B7%A5%E5%85%B7%E6%96%B9%E6%B3%95)
- [6.8.7.1 spellInfo](#6871-spellinfo)
- [6.8.7.2 isCnChar](#6872-iscnchar)
- [6.8.7.3 transformTone](#6873-transformtone)
@ -90,7 +93,7 @@ cnchar 由于重建过一次仓库,所以之前的 star 清零了 (〒︿〒)
- [6.8.7.5 compareStroke](#6875-comparestroke)
- [6.8.7.6 sortSpell](#6876-sortspell)
- [6.8.7.7 sortStroke](#6877-sortstroke)
- [7.应用例子](#7应用例子)
- [7.应用例子](#7%E5%BA%94%E7%94%A8%E4%BE%8B%E5%AD%90)
<!-- tocstop -->
@ -191,7 +194,7 @@ npm i cnchar
安装附加功能库:
```
npm i cnchar-poly cnchar-order cnchar-trad cnchar-draw
npm i cnchar-poly cnchar-order cnchar-trad cnchar-draw cnchar-idiom cnchar-xhy
```
当然您也可以按需安装其中的几个,但是 `cnchar` 这个基础库是必须安装的draw、idiom、xhy三个库可以独立使用
@ -1180,11 +1183,11 @@ cnchar.transformTone('lǘ') // {spell: 'lü', tone: 2, index: 2, isTrans: false}
```js
cnchar.compareSpell('ao', 'ai') // 'more'
cnchar.compareSpell('ai', 'ai') // 'even'
cnchar.compareSpell('pín', 'pǐn', 'tone') // 'less'
cnchar.compareSpell('pin2', 'pǐn', 'tone') // 'less'
cnchar.compareSpell('频', 'pǐn', 'tone') // 'less'
cnchar.compareSpell('品', '频', 'tone') // 'more'
cnchar.compareSpell('贫', '频', 'tone') // 'even'
cnchar.compareSpell('pín', 'pǐn', true) // 'less'
cnchar.compareSpell('pin2', 'pǐn', true) // 'less'
cnchar.compareSpell('频', 'pǐn', true) // 'less'
cnchar.compareSpell('品', '频', true) // 'more'
cnchar.compareSpell('贫', '频', true) // 'even'
```
###### 6.8.7.5 compareStroke

File diff suppressed because one or more lines are too long

8
npm/cnchar/extend.d.ts vendored Normal file
View File

@ -0,0 +1,8 @@
declare type spellArg = 'array' | 'low' | 'up' | 'first' | 'poly' | 'tone' | 'simple' | 'trad';
declare type strokeArg = 'letter' | 'shape' | 'count' | 'name' | 'detail' | 'array' | 'order' | 'simple' | 'trad';
interface String {
spell(...args: Array<spellArg>): string | Array<any>;
stroke(...args: Array<strokeArg>): number | Array<any>;
}

14
npm/cnchar/index.d.ts vendored
View File

@ -1,3 +1,5 @@
import './extend';
declare type spellArg = 'array' | 'low' | 'up' | 'first' | 'poly' | 'tone' | 'simple' | 'trad';
declare type strokeArg = 'letter' | 'shape' | 'count' | 'name' | 'detail' | 'array' | 'order' | 'simple' | 'trad';
declare type spellToWordArg = 'poly' | 'alltone' | 'array' | 'simple' | 'trad';
@ -14,11 +16,11 @@ declare interface spellInfoReturnStatic {
index: number;
}
export declare interface CnCharStatic {
spell(sentence: string, ...args?: Array<spellArg>): string | Array<any>;
stroke(sentence: string, ...args?: Array<strokeArg>): number | Array<any>;
spell(sentence: string, ...args: Array<spellArg>): string | Array<any>;
stroke(sentence: string, ...args: Array<strokeArg>): number | Array<any>;
use(...plugins: Array<Function>): void;
spellToWord(spell: string, ...args?: Array<spellToWordArg>): string | Array<string>;
strokeToWord(stroke: number, ...args?: Array<strokeToWordArg>): string | Array<string>;
spellToWord(spell: string, ...args: Array<spellToWordArg>): string | Array<string>;
strokeToWord(stroke: number, ...args: Array<strokeToWordArg>): string | Array<string>;
spellInfo: {
(spell: string): spellInfoReturnStatic;
tones: Array<string>;
@ -45,8 +47,8 @@ export declare interface CnCharStatic {
};
isCnChar(word: string): boolean;
compareSpell(spell1: string, spell2: string, tone?: boolean): compareType;
compareStroke(stroke1: string, stroke2: string): compareType;
sortSpell(spells:Array<string> | string, ...args?: Array<'tone'|'desc'>): Array<string> | string;
compareStroke(stroke1: string | number, stroke2: string | number): compareType;
sortSpell(spells:Array<string> | string, ...args: Array<'tone'|'desc'>): Array<string> | string;
sortStroke(strokes:Array<string|number> | string, desc?: 'desc'): Array<string> | string;
}

View File

@ -1,6 +1,6 @@
{
"name": "cnchar",
"version": "2.2.0",
"version": "2.2.1",
"description": "功能全面、多端支持的汉字拼音笔画js库支持多音字、繁体字、火星文",
"main": "index.js",
"scripts": {},

View File

@ -1,3 +1,3 @@
"use strict";
module.exports = '2.2.0';
module.exports = '2.2.1';

View File

@ -1,10 +1,13 @@
<h1>
<a href="https://github.com/theajack/cnchar">cnchar</a>
<p align="center">
<img src='https://cdn.jsdelivr.net/gh/theajack/cnchar/dist/rm-logo.png' width='200px'/>
</p>
<p align="center">
<a href="https://www.github.com/theajack/cnchar"><img src="https://img.shields.io/github/stars/theajack/cnchar.svg?style=social" alt="star"></a>
<a href="https://theajack.gitee.io"><img src="https://img.shields.io/badge/author-theajack-blue.svg?style=social" alt="Author"></a>
</h1>
</p>
<p>
<p align="center">
<a href="https://www.npmjs.com/package/cnchar"><img src="https://img.shields.io/npm/v/cnchar.svg" alt="Version"></a>
<a href="https://npmcharts.com/compare/cnchar?minimal=true"><img src="https://img.shields.io/npm/dm/cnchar.svg" alt="Downloads"></a>
<a href="https://cdn.jsdelivr.net/gh/theajack/cnchar/dist/cnchar.latest.min.js"><img src="https://img.shields.io/bundlephobia/minzip/cnchar.svg" alt="Size"></a>
@ -191,7 +194,7 @@ npm i cnchar
安装附加功能库:
```
npm i cnchar-poly cnchar-order cnchar-trad cnchar-draw
npm i cnchar-poly cnchar-order cnchar-trad cnchar-draw cnchar-idiom cnchar-xhy
```
当然您也可以按需安装其中的几个,但是 `cnchar` 这个基础库是必须安装的draw、idiom、xhy三个库可以独立使用
@ -1180,11 +1183,11 @@ cnchar.transformTone('lǘ') // {spell: 'lü', tone: 2, index: 2, isTrans: false}
```js
cnchar.compareSpell('ao', 'ai') // 'more'
cnchar.compareSpell('ai', 'ai') // 'even'
cnchar.compareSpell('pín', 'pǐn', 'tone') // 'less'
cnchar.compareSpell('pin2', 'pǐn', 'tone') // 'less'
cnchar.compareSpell('频', 'pǐn', 'tone') // 'less'
cnchar.compareSpell('品', '频', 'tone') // 'more'
cnchar.compareSpell('贫', '频', 'tone') // 'even'
cnchar.compareSpell('pín', 'pǐn', true) // 'less'
cnchar.compareSpell('pin2', 'pǐn', true) // 'less'
cnchar.compareSpell('频', 'pǐn', true) // 'less'
cnchar.compareSpell('品', '频', true) // 'more'
cnchar.compareSpell('贫', '频', true) // 'even'
```
###### 6.8.7.5 compareStroke

View File

@ -1,6 +1,6 @@
{
"name": "cnchar-draw",
"version": "2.2.0",
"version": "2.2.1",
"description": "功能全面、多端支持的汉字拼音笔画js库支持多音字、繁体字、火星文",
"main": "index.js",
"unpkg": "cnchar.draw.min.js",

8
npm/hanzi-util-base/extend.d.ts vendored Normal file
View File

@ -0,0 +1,8 @@
declare type spellArg = 'array' | 'low' | 'up' | 'first' | 'poly' | 'tone' | 'simple' | 'trad';
declare type strokeArg = 'letter' | 'shape' | 'count' | 'name' | 'detail' | 'array' | 'order' | 'simple' | 'trad';
interface String {
spell(...args: Array<spellArg>): string | Array<any>;
stroke(...args: Array<strokeArg>): number | Array<any>;
}

File diff suppressed because one or more lines are too long

View File

@ -1,3 +1,5 @@
import './extend';
declare type spellArg = 'array' | 'low' | 'up' | 'first' | 'poly' | 'tone' | 'simple' | 'trad';
declare type strokeArg = 'letter' | 'shape' | 'count' | 'name' | 'detail' | 'array' | 'order' | 'simple' | 'trad';
declare type spellToWordArg = 'poly' | 'alltone' | 'array' | 'simple' | 'trad';
@ -14,11 +16,11 @@ declare interface spellInfoReturnStatic {
index: number;
}
export declare interface CnCharStatic {
spell(sentence: string, ...args?: Array<spellArg>): string | Array<any>;
stroke(sentence: string, ...args?: Array<strokeArg>): number | Array<any>;
spell(sentence: string, ...args: Array<spellArg>): string | Array<any>;
stroke(sentence: string, ...args: Array<strokeArg>): number | Array<any>;
use(...plugins: Array<Function>): void;
spellToWord(spell: string, ...args?: Array<spellToWordArg>): string | Array<string>;
strokeToWord(stroke: number, ...args?: Array<strokeToWordArg>): string | Array<string>;
spellToWord(spell: string, ...args: Array<spellToWordArg>): string | Array<string>;
strokeToWord(stroke: number, ...args: Array<strokeToWordArg>): string | Array<string>;
spellInfo: {
(spell: string): spellInfoReturnStatic;
tones: Array<string>;
@ -45,8 +47,8 @@ export declare interface CnCharStatic {
};
isCnChar(word: string): boolean;
compareSpell(spell1: string, spell2: string, tone?: boolean): compareType;
compareStroke(stroke1: string, stroke2: string): compareType;
sortSpell(spells:Array<string> | string, ...args?: Array<'tone'|'desc'>): Array<string> | string;
compareStroke(stroke1: string | number, stroke2: string | number): compareType;
sortSpell(spells:Array<string> | string, ...args: Array<'tone'|'desc'>): Array<string> | string;
sortStroke(strokes:Array<string|number> | string, desc?: 'desc'): Array<string> | string;
}

View File

@ -1,6 +1,6 @@
{
"name": "hanzi-util-base",
"version": "2.2.0",
"version": "2.2.1",
"description": "功能全面、多端支持的汉字拼音笔画js库支持多音字、繁体字、火星文",
"main": "index.js",
"unpkg": "hanzi.base.min.js",
@ -27,6 +27,6 @@
},
"homepage": "https://www.theajack.com/cnchar/",
"dependencies": {
"cnchar": "^2.2.0"
"cnchar": "^2.2.1"
}
}

13
npm/hanzi-util/extend.d.ts vendored Normal file
View File

@ -0,0 +1,13 @@
declare type spellArgs = 'array' | 'low' | 'up' | 'first' | 'poly' | 'tone' | 'simple' | 'trad';
declare type strokeArgs = 'letter' | 'shape' | 'count' | 'name' | 'detail' | 'array' | 'order' | 'simple' | 'trad';
interface String {
spell(...args: Array<spellArgs>): string | Array<any>;
stroke(...args: Array<strokeArgs>): number | Array<any>;
convertSimpleToTrad(): string;
convertSimpleToSpark(): string;
convertTradToSimple(): string;
convertTradToSpark(): string;
convertSparkToSimple(): string;
convertSparkToTrad(): string;
}

File diff suppressed because one or more lines are too long

View File

@ -1,3 +1,122 @@
// all库的声明文件
import './extend';
// draw
declare type DrawType = 'normal' | 'animation' | 'stroke' | 'test';
declare type TestStatusType = 'mistake' | 'correct' | 'complete';
declare class Writer {
constructor();
option: object;
el: HTMLElement;
type: DrawType;
text: Array<string>;
writer: Array<object>;
animateStart():void;
}
declare interface TestStatus {
index: number,
status: TestStatusType,
data: {
character: string;
totalMistakes: number;// 到目前为止在测验期间犯的总错误。
strokeNum?: number;// 当前笔画数。
mistakesOnStroke?: number;// 到目前为止用户绘制此笔划所犯的错误数。
strokesRemaining?: number;// 测验完成前剩余的笔画数。
drawnPath?: {
pathString: string;
points: Array<{x:number;y:number}>
};// 对象包含用户绘制的 pathString ,用于评分的分数。
}
}
declare interface DrawOption {
el?: string | HTMLElement; // 绘制的容器支持选择器或dom若是不填会在body后append一个dom作为容器
type?: DrawType; // 绘制模式默认为normal
clear?: boolean; // 绘制前是否清空容器 默认为true
style?: { // 样式类
backgroundColor?: string, // 默认为#fff
showOutline?: boolean;//: true,
showCharacter?: boolean;//: true,
currentColor?: string;//: '#b44', // 仅在stroke模式下有效
length?: number;//: 60,
padding?: number;//: 5, // 数值, 默认 20。 画布的汉字和边缘之间的填充
outlineColor?: string;//: '#ddd', // 十六进制字符, 默认 '#DDD'。
strokeColor?: string;//: '#555', // 十六进制字符, 默认 '#555'。绘制每个笔划的颜色。
radicalColor?: string;//: null, // 十六进制字符, 默认 null。 如果存在偏旁部首数据,则在笔划中绘制偏旁部首的颜色。 如果没有设置,激光将绘制与其他笔划相同的颜色。
strokeFadeDuration?: number; //400
},
line?: { // 背景线条类
lineStraight?: boolean;// : true,
lineCross?: boolean;// : true,
lineWidth?: number;// : 1,
lineColor?: string;// : '#ddd',
lineDash?: boolean;// : true,
border?: boolean;// : true,
borderWidth?: number;// : 1,
borderColor?: string;// : '#ccc',
borderDash?: boolean;// : false,
},
animation?: {
strokeAnimationSpeed?: number;// : 1, // 数值, 默认 1。 绘制每个笔划的速度必须大于0。增加此数字可以更快地绘制笔划减少绘制笔划的速度更慢。
delayBetweenStrokes?: number;// : 1000, // 数值, 默认 1000。 动画进行中每个笔画之间的间隔时间(以毫秒为单位)。
delayBetweenLoops?: number;// : 200, // 数值, 默认 2000。 循环动画时每个动画循环之间的时间(以毫秒为单位)。
autoAnimate?: boolean;// : true,
animateComplete?: Function;// : () => {},
stepByStep?: boolean;// : true,
loopAnimate?: boolean;// : false,
},
test?: {
strokeHighlightSpeed?: number;// : 20, // 数值, 默认 20。 在测验中给出提示时突出显示每个笔划的速度必须大于0。增加此数字以突出显示更快减少以突出显示更慢。
highlightColor?: number;// : '#aaf', // 十六进制字符, 默认 '#AAF'。 用于在测验中突出显示的颜色。
drawingColor?: number;// : '#333', // 十六进制字符, 默认 '#333'。 测验期间绘制的线条颜色。
drawingWidth?: number;// : 4, // 数值, 默认 4。 进行测验时绘制的线条宽度。
showHintAfterMisses?: number;// : 3, // 整数, 默认 3 中风高亮提示之前的未命中数被给予用户。 设置为 false 以禁用。 创建测验时也可以设置此项。
highlightOnComplete?: number;// : true, // 布尔值, 默认 true。 控制当用户完成绘制整个字符时,测验是否会短暂突出显示字符。 创建测验时也可以设置此项。
highlightCompleteColor?: number;// : null, // 十六进制字符, 默认 null。 在测验中突出显示字符时使用的颜色。 如果未设置则将使用highlightColor。 仅当highlightOnComplete为true时才相关。
onTestStatus?(args: TestStatus):void;// : null, // ({index, status, data})=>{}
}
}
export declare interface Draw {
(text:string, option?:DrawOption):Writer;
TYPE: {
ANIMATION: 'animation',
NORMAL: 'normal',
STROKE: 'stroke',
TEST: 'test'
},
TEST_STATUS: {
MISTAKE: 'mistake',
CORRECT: 'correct',
COMPLETE: 'complete'
}
}
// idiom
declare type idiomArg = 'char' | 'stroke' | 'spell' | 'tone';
export declare interface Idiom {
(text:string | Array<string|number>, ...idiomArgs: Array<idiomArg>):Array<string>;
}
// order
declare type orderToWordArg = 'match' | 'matchorder' | 'contain' | 'start' | 'array' | 'simple' | 'trad';
declare type orderName = '横折折撇' | '竖弯' | '横折' | '撇点' | '横斜钩' | '横' | '捺' | '横折钩' | '竖' | '竖钩' | '点' | '撇' | '撇折' | '竖折撇' | '横折折折钩' | '竖折折钩' | '提' | '弯钩' | '斜钩' | '横折折' | '横撇' | '横折提' | '横折折折' | '竖提' | '竖弯钩'
| '竖折折' | '横撇弯钩' | '卧钩' | '横折弯' | '横钩';
// xhy
declare type xhyArg = 'fuzzy' | 'answer' | 'second';
export declare interface XHY {
(text:string, ...xhyArgs: Array<xhyArg>):Array<string>;
}
declare type spellArg = 'array' | 'low' | 'up' | 'first' | 'poly' | 'tone' | 'simple' | 'trad';
declare type strokeArg = 'letter' | 'shape' | 'count' | 'name' | 'detail' | 'array' | 'order' | 'simple' | 'trad';
declare type spellToWordArg = 'poly' | 'alltone' | 'array' | 'simple' | 'trad';
@ -14,11 +133,11 @@ declare interface spellInfoReturnStatic {
index: number;
}
export declare interface CnCharStatic {
spell(sentence: string, ...args?: Array<spellArg>): string | Array<any>;
stroke(sentence: string, ...args?: Array<strokeArg>): number | Array<any>;
spell(sentence: string, ...args: Array<spellArg>): string | Array<any>;
stroke(sentence: string, ...args: Array<strokeArg>): number | Array<any>;
use(...plugins: Array<Function>): void;
spellToWord(spell: string, ...args?: Array<spellToWordArg>): string | Array<string>;
strokeToWord(stroke: number, ...args?: Array<strokeToWordArg>): string | Array<string>;
spellToWord(spell: string, ...args: Array<spellToWordArg>): string | Array<string>;
strokeToWord(stroke: number, ...args: Array<strokeToWordArg>): string | Array<string>;
spellInfo: {
(spell: string): spellInfoReturnStatic;
tones: Array<string>;
@ -45,10 +164,24 @@ export declare interface CnCharStatic {
};
isCnChar(word: string): boolean;
compareSpell(spell1: string, spell2: string, tone?: boolean): compareType;
compareStroke(stroke1: string, stroke2: string): compareType;
sortSpell(spells:Array<string> | string, ...args?: Array<'tone'|'desc'>): Array<string> | string;
compareStroke(stroke1: string | number, stroke2: string | number): compareType;
sortSpell(spells:Array<string> | string, ...args: Array<'tone'|'desc'>): Array<string> | string;
sortStroke(strokes:Array<string|number> | string, desc?: 'desc'): Array<string> | string;
draw: Draw;
idiom: Idiom;
orderToWord: {
(orders: string | Array<orderName>, ...args: Array<orderToWordArg>): string | Array<string>;
orders: object;
};
convert: {
simpleToSpark(sentence: string): string;
simpleToTrad(sentence: string): string;
sparkToSimple(sentence: string): string;
sparkToTrad(sentence: string): string;
tradToSimple(sentence: string): string;
tradToSpark(sentence: string): string;
};
xhy: XHY;
}
declare const cnchar: CnCharStatic;

View File

@ -1,6 +1,6 @@
{
"name": "hanzi-util",
"version": "2.2.0",
"version": "2.2.1",
"description": "功能全面、多端支持的汉字拼音笔画js库支持多音字、繁体字、火星文",
"main": "index.js",
"unpkg": "hanzi.util.min.js",

View File

@ -1,10 +1,13 @@
<h1>
<a href="https://github.com/theajack/cnchar">cnchar</a>
<p align="center">
<img src='https://cdn.jsdelivr.net/gh/theajack/cnchar/dist/rm-logo.png' width='200px'/>
</p>
<p align="center">
<a href="https://www.github.com/theajack/cnchar"><img src="https://img.shields.io/github/stars/theajack/cnchar.svg?style=social" alt="star"></a>
<a href="https://theajack.gitee.io"><img src="https://img.shields.io/badge/author-theajack-blue.svg?style=social" alt="Author"></a>
</h1>
</p>
<p>
<p align="center">
<a href="https://www.npmjs.com/package/cnchar"><img src="https://img.shields.io/npm/v/cnchar.svg" alt="Version"></a>
<a href="https://npmcharts.com/compare/cnchar?minimal=true"><img src="https://img.shields.io/npm/dm/cnchar.svg" alt="Downloads"></a>
<a href="https://cdn.jsdelivr.net/gh/theajack/cnchar/dist/cnchar.latest.min.js"><img src="https://img.shields.io/bundlephobia/minzip/cnchar.svg" alt="Size"></a>
@ -191,7 +194,7 @@ npm i cnchar
安装附加功能库:
```
npm i cnchar-poly cnchar-order cnchar-trad cnchar-draw
npm i cnchar-poly cnchar-order cnchar-trad cnchar-draw cnchar-idiom cnchar-xhy
```
当然您也可以按需安装其中的几个,但是 `cnchar` 这个基础库是必须安装的draw、idiom、xhy三个库可以独立使用
@ -1180,11 +1183,11 @@ cnchar.transformTone('lǘ') // {spell: 'lü', tone: 2, index: 2, isTrans: false}
```js
cnchar.compareSpell('ao', 'ai') // 'more'
cnchar.compareSpell('ai', 'ai') // 'even'
cnchar.compareSpell('pín', 'pǐn', 'tone') // 'less'
cnchar.compareSpell('pin2', 'pǐn', 'tone') // 'less'
cnchar.compareSpell('频', 'pǐn', 'tone') // 'less'
cnchar.compareSpell('品', '频', 'tone') // 'more'
cnchar.compareSpell('贫', '频', 'tone') // 'even'
cnchar.compareSpell('pín', 'pǐn', true) // 'less'
cnchar.compareSpell('pin2', 'pǐn', true) // 'less'
cnchar.compareSpell('频', 'pǐn', true) // 'less'
cnchar.compareSpell('品', '频', true) // 'more'
cnchar.compareSpell('贫', '频', true) // 'even'
```
###### 6.8.7.5 compareStroke

View File

@ -1,7 +1,7 @@
declare type idiomArg = 'char' | 'stroke' | 'spell' | 'tone';
export declare interface Idiom {
(text:string | Array<string>, ...idiomArgs: Array<idiomArg>):Array<string>;
(text:string | Array<string|number>, ...idiomArgs: Array<idiomArg>):Array<string>;
}
declare const idiom: Idiom;

View File

@ -1,6 +1,6 @@
{
"name": "cnchar-idiom",
"version": "2.2.0",
"version": "2.2.1",
"description": "功能全面、多端支持的汉字拼音笔画js库支持多音字、繁体字、火星文",
"main": "index.js",
"unpkg": "cnchar.idiom.min.js",

View File

@ -1,10 +1,13 @@
<h1>
<a href="https://github.com/theajack/cnchar">cnchar</a>
<p align="center">
<img src='https://cdn.jsdelivr.net/gh/theajack/cnchar/dist/rm-logo.png' width='200px'/>
</p>
<p align="center">
<a href="https://www.github.com/theajack/cnchar"><img src="https://img.shields.io/github/stars/theajack/cnchar.svg?style=social" alt="star"></a>
<a href="https://theajack.gitee.io"><img src="https://img.shields.io/badge/author-theajack-blue.svg?style=social" alt="Author"></a>
</h1>
</p>
<p>
<p align="center">
<a href="https://www.npmjs.com/package/cnchar"><img src="https://img.shields.io/npm/v/cnchar.svg" alt="Version"></a>
<a href="https://npmcharts.com/compare/cnchar?minimal=true"><img src="https://img.shields.io/npm/dm/cnchar.svg" alt="Downloads"></a>
<a href="https://cdn.jsdelivr.net/gh/theajack/cnchar/dist/cnchar.latest.min.js"><img src="https://img.shields.io/bundlephobia/minzip/cnchar.svg" alt="Size"></a>
@ -191,7 +194,7 @@ npm i cnchar
安装附加功能库:
```
npm i cnchar-poly cnchar-order cnchar-trad cnchar-draw
npm i cnchar-poly cnchar-order cnchar-trad cnchar-draw cnchar-idiom cnchar-xhy
```
当然您也可以按需安装其中的几个,但是 `cnchar` 这个基础库是必须安装的draw、idiom、xhy三个库可以独立使用
@ -1180,11 +1183,11 @@ cnchar.transformTone('lǘ') // {spell: 'lü', tone: 2, index: 2, isTrans: false}
```js
cnchar.compareSpell('ao', 'ai') // 'more'
cnchar.compareSpell('ai', 'ai') // 'even'
cnchar.compareSpell('pín', 'pǐn', 'tone') // 'less'
cnchar.compareSpell('pin2', 'pǐn', 'tone') // 'less'
cnchar.compareSpell('频', 'pǐn', 'tone') // 'less'
cnchar.compareSpell('品', '频', 'tone') // 'more'
cnchar.compareSpell('贫', '频', 'tone') // 'even'
cnchar.compareSpell('pín', 'pǐn', true) // 'less'
cnchar.compareSpell('pin2', 'pǐn', true) // 'less'
cnchar.compareSpell('频', 'pǐn', true) // 'less'
cnchar.compareSpell('品', '频', true) // 'more'
cnchar.compareSpell('贫', '频', true) // 'even'
```
###### 6.8.7.5 compareStroke

14
npm/order/index.d.ts vendored
View File

@ -1,3 +1,17 @@
declare const order: Function;
declare type orderToWordArg = 'match' | 'matchorder' | 'contain' | 'start' | 'array' | 'simple' | 'trad';
declare type orderName = '横折折撇' | '竖弯' | '横折' | '撇点' | '横斜钩' | '横' | '捺' | '横折钩' | '竖' | '竖钩' | '点' | '撇' | '撇折' | '竖折撇' | '横折折折钩' | '竖折折钩' | '提' | '弯钩' | '斜钩' | '横折折' | '横撇' | '横折提' | '横折折折' | '竖提' | '竖弯钩'
| '竖折折' | '横撇弯钩' | '卧钩' | '横折弯' | '横钩';
declare module 'cnchar' {
interface CnCharStatic {
orderToWord: {
(orders: string | Array<orderName>, ...args: Array<orderToWordArg>): string | Array<string>;
orders: object;
};
}
}
export default order;

View File

@ -1,6 +1,6 @@
{
"name": "cnchar-order",
"version": "2.2.0",
"version": "2.2.1",
"description": "功能全面、多端支持的汉字拼音笔画js库支持多音字、繁体字、火星文",
"main": "index.js",
"unpkg": "cnchar.order.min.js",

View File

@ -1,10 +1,13 @@
<h1>
<a href="https://github.com/theajack/cnchar">cnchar</a>
<p align="center">
<img src='https://cdn.jsdelivr.net/gh/theajack/cnchar/dist/rm-logo.png' width='200px'/>
</p>
<p align="center">
<a href="https://www.github.com/theajack/cnchar"><img src="https://img.shields.io/github/stars/theajack/cnchar.svg?style=social" alt="star"></a>
<a href="https://theajack.gitee.io"><img src="https://img.shields.io/badge/author-theajack-blue.svg?style=social" alt="Author"></a>
</h1>
</p>
<p>
<p align="center">
<a href="https://www.npmjs.com/package/cnchar"><img src="https://img.shields.io/npm/v/cnchar.svg" alt="Version"></a>
<a href="https://npmcharts.com/compare/cnchar?minimal=true"><img src="https://img.shields.io/npm/dm/cnchar.svg" alt="Downloads"></a>
<a href="https://cdn.jsdelivr.net/gh/theajack/cnchar/dist/cnchar.latest.min.js"><img src="https://img.shields.io/bundlephobia/minzip/cnchar.svg" alt="Size"></a>
@ -191,7 +194,7 @@ npm i cnchar
安装附加功能库:
```
npm i cnchar-poly cnchar-order cnchar-trad cnchar-draw
npm i cnchar-poly cnchar-order cnchar-trad cnchar-draw cnchar-idiom cnchar-xhy
```
当然您也可以按需安装其中的几个,但是 `cnchar` 这个基础库是必须安装的draw、idiom、xhy三个库可以独立使用
@ -1180,11 +1183,11 @@ cnchar.transformTone('lǘ') // {spell: 'lü', tone: 2, index: 2, isTrans: false}
```js
cnchar.compareSpell('ao', 'ai') // 'more'
cnchar.compareSpell('ai', 'ai') // 'even'
cnchar.compareSpell('pín', 'pǐn', 'tone') // 'less'
cnchar.compareSpell('pin2', 'pǐn', 'tone') // 'less'
cnchar.compareSpell('频', 'pǐn', 'tone') // 'less'
cnchar.compareSpell('品', '频', 'tone') // 'more'
cnchar.compareSpell('贫', '频', 'tone') // 'even'
cnchar.compareSpell('pín', 'pǐn', true) // 'less'
cnchar.compareSpell('pin2', 'pǐn', true) // 'less'
cnchar.compareSpell('频', 'pǐn', true) // 'less'
cnchar.compareSpell('品', '频', true) // 'more'
cnchar.compareSpell('贫', '频', true) // 'even'
```
###### 6.8.7.5 compareStroke

View File

@ -1,6 +1,6 @@
{
"name": "cnchar-poly",
"version": "2.2.0",
"version": "2.2.1",
"description": "功能全面、多端支持的汉字拼音笔画js库支持多音字、繁体字、火星文",
"main": "index.js",
"unpkg": "cnchar.poly.min.js",

View File

@ -1,10 +1,13 @@
<h1>
<a href="https://github.com/theajack/cnchar">cnchar</a>
<p align="center">
<img src='https://cdn.jsdelivr.net/gh/theajack/cnchar/dist/rm-logo.png' width='200px'/>
</p>
<p align="center">
<a href="https://www.github.com/theajack/cnchar"><img src="https://img.shields.io/github/stars/theajack/cnchar.svg?style=social" alt="star"></a>
<a href="https://theajack.gitee.io"><img src="https://img.shields.io/badge/author-theajack-blue.svg?style=social" alt="Author"></a>
</h1>
</p>
<p>
<p align="center">
<a href="https://www.npmjs.com/package/cnchar"><img src="https://img.shields.io/npm/v/cnchar.svg" alt="Version"></a>
<a href="https://npmcharts.com/compare/cnchar?minimal=true"><img src="https://img.shields.io/npm/dm/cnchar.svg" alt="Downloads"></a>
<a href="https://cdn.jsdelivr.net/gh/theajack/cnchar/dist/cnchar.latest.min.js"><img src="https://img.shields.io/bundlephobia/minzip/cnchar.svg" alt="Size"></a>
@ -191,7 +194,7 @@ npm i cnchar
安装附加功能库:
```
npm i cnchar-poly cnchar-order cnchar-trad cnchar-draw
npm i cnchar-poly cnchar-order cnchar-trad cnchar-draw cnchar-idiom cnchar-xhy
```
当然您也可以按需安装其中的几个,但是 `cnchar` 这个基础库是必须安装的draw、idiom、xhy三个库可以独立使用
@ -1180,11 +1183,11 @@ cnchar.transformTone('lǘ') // {spell: 'lü', tone: 2, index: 2, isTrans: false}
```js
cnchar.compareSpell('ao', 'ai') // 'more'
cnchar.compareSpell('ai', 'ai') // 'even'
cnchar.compareSpell('pín', 'pǐn', 'tone') // 'less'
cnchar.compareSpell('pin2', 'pǐn', 'tone') // 'less'
cnchar.compareSpell('频', 'pǐn', 'tone') // 'less'
cnchar.compareSpell('品', '频', 'tone') // 'more'
cnchar.compareSpell('贫', '频', 'tone') // 'even'
cnchar.compareSpell('pín', 'pǐn', true) // 'less'
cnchar.compareSpell('pin2', 'pǐn', true) // 'less'
cnchar.compareSpell('频', 'pǐn', true) // 'less'
cnchar.compareSpell('品', '频', true) // 'more'
cnchar.compareSpell('贫', '频', true) // 'even'
```
###### 6.8.7.5 compareStroke

8
npm/trad/extend.d.ts vendored Normal file
View File

@ -0,0 +1,8 @@
interface String {
convertSimpleToTrad(): string;
convertSimpleToSpark(): string;
convertTradToSimple(): string;
convertTradToSpark(): string;
convertSparkToSimple(): string;
convertSparkToTrad(): string;
}

15
npm/trad/index.d.ts vendored
View File

@ -1,3 +1,18 @@
import './extend';
declare const trad: Function;
declare module 'cnchar' {
interface CnCharStatic {
convert: {
simpleToSpark(sentence: string): string;
simpleToTrad(sentence: string): string;
sparkToSimple(sentence: string): string;
sparkToTrad(sentence: string): string;
tradToSimple(sentence: string): string;
tradToSpark(sentence: string): string;
};
}
}
export default trad;

View File

@ -1,6 +1,6 @@
{
"name": "cnchar-trad",
"version": "2.2.0",
"version": "2.2.1",
"description": "功能全面、多端支持的汉字拼音笔画js库支持多音字、繁体字、火星文",
"main": "index.js",
"unpkg": "cnchar.trad.min.js",

View File

@ -1,10 +1,13 @@
<h1>
<a href="https://github.com/theajack/cnchar">cnchar</a>
<p align="center">
<img src='https://cdn.jsdelivr.net/gh/theajack/cnchar/dist/rm-logo.png' width='200px'/>
</p>
<p align="center">
<a href="https://www.github.com/theajack/cnchar"><img src="https://img.shields.io/github/stars/theajack/cnchar.svg?style=social" alt="star"></a>
<a href="https://theajack.gitee.io"><img src="https://img.shields.io/badge/author-theajack-blue.svg?style=social" alt="Author"></a>
</h1>
</p>
<p>
<p align="center">
<a href="https://www.npmjs.com/package/cnchar"><img src="https://img.shields.io/npm/v/cnchar.svg" alt="Version"></a>
<a href="https://npmcharts.com/compare/cnchar?minimal=true"><img src="https://img.shields.io/npm/dm/cnchar.svg" alt="Downloads"></a>
<a href="https://cdn.jsdelivr.net/gh/theajack/cnchar/dist/cnchar.latest.min.js"><img src="https://img.shields.io/bundlephobia/minzip/cnchar.svg" alt="Size"></a>
@ -191,7 +194,7 @@ npm i cnchar
安装附加功能库:
```
npm i cnchar-poly cnchar-order cnchar-trad cnchar-draw
npm i cnchar-poly cnchar-order cnchar-trad cnchar-draw cnchar-idiom cnchar-xhy
```
当然您也可以按需安装其中的几个,但是 `cnchar` 这个基础库是必须安装的draw、idiom、xhy三个库可以独立使用
@ -1180,11 +1183,11 @@ cnchar.transformTone('lǘ') // {spell: 'lü', tone: 2, index: 2, isTrans: false}
```js
cnchar.compareSpell('ao', 'ai') // 'more'
cnchar.compareSpell('ai', 'ai') // 'even'
cnchar.compareSpell('pín', 'pǐn', 'tone') // 'less'
cnchar.compareSpell('pin2', 'pǐn', 'tone') // 'less'
cnchar.compareSpell('频', 'pǐn', 'tone') // 'less'
cnchar.compareSpell('品', '频', 'tone') // 'more'
cnchar.compareSpell('贫', '频', 'tone') // 'even'
cnchar.compareSpell('pín', 'pǐn', true) // 'less'
cnchar.compareSpell('pin2', 'pǐn', true) // 'less'
cnchar.compareSpell('频', 'pǐn', true) // 'less'
cnchar.compareSpell('品', '频', true) // 'more'
cnchar.compareSpell('贫', '频', true) // 'even'
```
###### 6.8.7.5 compareStroke

View File

@ -1,6 +1,6 @@
{
"name": "cnchar-xhy",
"version": "2.2.0",
"version": "2.2.1",
"description": "功能全面、多端支持的汉字拼音笔画js库支持多音字、繁体字、火星文",
"main": "index.js",
"unpkg": "cnchar.xhy.min.js",

View File

@ -1,6 +1,6 @@
{
"name": "cnchar",
"version": "2.2.0",
"version": "2.2.1",
"description": "功能全面、多端支持的汉字拼音笔画js库支持多音字、繁体字、火星文",
"main": "index.html",
"author": "theajack <contact@theajack.com>",

8
src/main/extend.d.ts vendored Normal file
View File

@ -0,0 +1,8 @@
declare type spellArg = 'array' | 'low' | 'up' | 'first' | 'poly' | 'tone' | 'simple' | 'trad';
declare type strokeArg = 'letter' | 'shape' | 'count' | 'name' | 'detail' | 'array' | 'order' | 'simple' | 'trad';
interface String {
spell(...args: Array<spellArg>): string | Array<any>;
stroke(...args: Array<strokeArg>): number | Array<any>;
}

14
src/main/index.d.ts vendored
View File

@ -1,3 +1,5 @@
import './extend';
declare type spellArg = 'array' | 'low' | 'up' | 'first' | 'poly' | 'tone' | 'simple' | 'trad';
declare type strokeArg = 'letter' | 'shape' | 'count' | 'name' | 'detail' | 'array' | 'order' | 'simple' | 'trad';
declare type spellToWordArg = 'poly' | 'alltone' | 'array' | 'simple' | 'trad';
@ -14,11 +16,11 @@ declare interface spellInfoReturnStatic {
index: number;
}
export declare interface CnCharStatic {
spell(sentence: string, ...args?: Array<spellArg>): string | Array<any>;
stroke(sentence: string, ...args?: Array<strokeArg>): number | Array<any>;
spell(sentence: string, ...args: Array<spellArg>): string | Array<any>;
stroke(sentence: string, ...args: Array<strokeArg>): number | Array<any>;
use(...plugins: Array<Function>): void;
spellToWord(spell: string, ...args?: Array<spellToWordArg>): string | Array<string>;
strokeToWord(stroke: number, ...args?: Array<strokeToWordArg>): string | Array<string>;
spellToWord(spell: string, ...args: Array<spellToWordArg>): string | Array<string>;
strokeToWord(stroke: number, ...args: Array<strokeToWordArg>): string | Array<string>;
spellInfo: {
(spell: string): spellInfoReturnStatic;
tones: Array<string>;
@ -45,8 +47,8 @@ export declare interface CnCharStatic {
};
isCnChar(word: string): boolean;
compareSpell(spell1: string, spell2: string, tone?: boolean): compareType;
compareStroke(stroke1: string, stroke2: string): compareType;
sortSpell(spells:Array<string> | string, ...args?: Array<'tone'|'desc'>): Array<string> | string;
compareStroke(stroke1: string | number, stroke2: string | number): compareType;
sortSpell(spells:Array<string> | string, ...args: Array<'tone'|'desc'>): Array<string> | string;
sortStroke(strokes:Array<string|number> | string, desc?: 'desc'): Array<string> | string;
}

View File

@ -1 +1 @@
module.exports = '2.2.0';
module.exports = '2.2.1';

View File

@ -1,7 +1,7 @@
declare type idiomArg = 'char' | 'stroke' | 'spell' | 'tone';
export declare interface Idiom {
(text:string | Array<string>, ...idiomArgs: Array<idiomArg>):Array<string>;
(text:string | Array<string|number>, ...idiomArgs: Array<idiomArg>):Array<string>;
}
declare const idiom: Idiom;

8
src/plugin/trad/extend.d.ts vendored Normal file
View File

@ -0,0 +1,8 @@
interface String {
convertSimpleToTrad(): string;
convertSimpleToSpark(): string;
convertTradToSimple(): string;
convertTradToSpark(): string;
convertSparkToSimple(): string;
convertSparkToTrad(): string;
}

View File

@ -1,3 +1,5 @@
import './extend';
declare const trad: Function;
declare module 'cnchar' {