1 | # zidian 字典
|
2 | 汉字、词语、成语查询接口
|
3 |
|
4 | ### 引言
|
5 | - 数据来源于开源项目 <https://github.com/pwxcoo/chinese-xinhua>
|
6 | - 而该项目的数据是一个`JSON`文件,大小超出 `20M`,不利于页面加载使用,所以拆分了文件
|
7 | - 提取字、词、成语为数组,根据数组索引分页生成详情,具体请看 `build/parse.html` 的拆分脚本
|
8 |
|
9 | ### 使用
|
10 |
|
11 | ```html
|
12 | <script src="https://cdn.jsdelivr.net/npm/zidian@0.0.3/dist/zidian.js"></script>
|
13 | <!-- or -->
|
14 | <script src="https://cdn.jsdelivr.net/gh/netnr/zidian/dist/zidian.js"></script>
|
15 | ```
|
16 |
|
17 | 查看 <https://unpkg.com/zidian/>
|
18 | 拉取 `npm install zidian`
|
19 |
|
20 | 汉字查询
|
21 | ```js
|
22 | zidian.equalWord(key)
|
23 | zidian.equalWord("爱").then(console.log)
|
24 | ```
|
25 |
|
26 | 词语查询
|
27 | ```js
|
28 | zidian.equalCi(key)
|
29 | zidian.equalCi("美丽").then(console.log)
|
30 | ```
|
31 |
|
32 | 成语查询
|
33 | ```js
|
34 | zidian.equalIdiom(key)
|
35 | zidian.equalIdiom("叶公好龙").then(console.log)
|
36 | ```
|
37 |
|
38 | 词语模糊搜索
|
39 | ```js
|
40 | zidian.likeCi(key)
|
41 | zidian.likeCi("美").then(console.log)
|
42 | ```
|
43 |
|
44 | 成语模糊搜索
|
45 | ```js
|
46 | zidian.likeIdiom(key)
|
47 | zidian.likeIdiom("三百").then(console.log)
|
48 | ```
|
49 |
|
50 | ### 说明
|
51 | - 接口查询返回一个 `Promise` 对象
|
52 | - 查询的接口会缓存到 `zidian.cache` 对象
|
53 | - 查询无记录时,返回 `null`
|
54 | - `zidian.config.host` 可配置请求源 |
\ | No newline at end of file |