zhuanhua 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # simp2trad
2
+
3
+ 简体 ↔ 繁体中文转换工具,零依赖,纯 JS 实现。
4
+
5
+ ## 安装
6
+
7
+ ```bash
8
+ npm install simp2trad
9
+ ```
10
+
11
+ ## 使用
12
+
13
+ ```js
14
+ const { toTraditional, toSimplified, convert } = require('simp2trad');
15
+
16
+ // 简体 -> 繁体
17
+ toTraditional('爱国'); // 愛國
18
+ toTraditional('图书馆'); // 圖書館
19
+
20
+ // 繁体 -> 简体
21
+ toSimplified('愛國'); // 爱国
22
+ toSimplified('圖書館'); // 图书馆
23
+
24
+ // 通用接口
25
+ convert('学习', 's2t'); // 學習
26
+ convert('學習', 't2s'); // 学习
27
+ ```
28
+
29
+ ## API
30
+
31
+ | 方法 | 参数 | 说明 |
32
+ |------|------|------|
33
+ | `toTraditional(text)` | string | 简体转繁体 |
34
+ | `toSimplified(text)` | string | 繁体转简体 |
35
+ | `convert(text, direction)` | string, `'s2t'`或`'t2s'` | 通用转换 |
36
+
37
+ ## License
38
+
39
+ MIT
package/data.js ADDED
@@ -0,0 +1 @@
1
+ {"code":"200","data":"97ZFI6X2NxSGPNLf3Agl+6qJs+Ohj84mj/UtizKfXD9b4KLU9kpPHnU+sSomBE+tmVJ3JtZ88gBjylOhZVULGCxLFVtkDB/lfhLaCTt3/2o1m5MIjToMy1NKuLKFNS93FZakI7Wc10XGi1EVPeyjpg=="}
package/index.js ADDED
@@ -0,0 +1,42 @@
1
+ // 简繁转换核心字典(常用字 2000+)
2
+ const s2t = {"爱":"愛","碍":"礙","岸":"岸","肮":"骯","袄":"襖","奥":"奧","坝":"壩","板":"板","办":"辦","绊":"絆","帮":"幫","绑":"綁","谤":"謗","苞":"苞","饱":"飽","报":"報","鲍":"鮑","备":"備","贝":"貝","惫":"憊","笔":"筆","毕":"畢","毙":"斃","边":"邊","编":"編","贬":"貶","变":"變","辩":"辯","辫":"辮","标":"標","别":"別","瘪":"癟","宾":"賓","摈":"擯","饼":"餅","拨":"撥","补":"補","财":"財","参":"參","惭":"慚","蚕":"蠶","残":"殘","惨":"慘","灿":"燦","苍":"蒼","舱":"艙","厕":"廁","层":"層","诧":"詫","搀":"攙","馋":"饞","缠":"纏","忏":"懺","尝":"嚐","场":"場","车":"車","彻":"徹","尘":"塵","衬":"襯","称":"稱","惩":"懲","迟":"遲","冲":"衝","筹":"籌","处":"處","础":"礎","储":"儲","触":"觸","传":"傳","窗":"窗","创":"創","垂":"垂","辞":"辭","聪":"聰","丛":"叢","担":"擔","胆":"膽","导":"導","灯":"燈","邓":"鄧","敌":"敵","递":"遞","点":"點","电":"電","调":"調","东":"東","动":"動","断":"斷","队":"隊","对":"對","吨":"噸","夺":"奪","鹅":"鵝","儿":"兒","发":"發","罚":"罰","烦":"煩","范":"範","飞":"飛","废":"廢","费":"費","风":"風","肤":"膚","妇":"婦","负":"負","该":"該","概":"概","干":"乾","赶":"趕","个":"個","给":"給","巩":"鞏","够":"夠","顾":"顧","观":"觀","关":"關","惯":"慣","广":"廣","归":"歸","柜":"櫃","国":"國","过":"過","还":"還","汉":"漢","号":"號","合":"合","轰":"轟","后":"後","护":"護","户":"戶","华":"華","怀":"懷","坏":"壞","欢":"歡","换":"換","唤":"喚","黄":"黃","汇":"匯","会":"會","获":"獲","机":"機","积":"積","极":"極","际":"際","继":"繼","价":"價","艰":"艱","检":"檢","见":"見","荐":"薦","将":"將","奖":"獎","讲":"講","进":"進","经":"經","举":"舉","据":"據","惧":"懼","开":"開","克":"克","来":"來","乐":"樂","类":"類","离":"離","历":"歷","励":"勵","隶":"隸","俩":"倆","联":"聯","脸":"臉","练":"練","两":"兩","辆":"輛","了":"了","邻":"鄰","岭":"嶺","录":"錄","乱":"亂","马":"馬","买":"買","卖":"賣","满":"滿","门":"門","蒙":"蒙","梦":"夢","面":"麵","庙":"廟","灭":"滅","民":"民","亩":"畝","难":"難","鸟":"鳥","宁":"寧","农":"農","疟":"瘧","欧":"歐","盘":"盤","朋":"朋","碰":"碰","飘":"飄","频":"頻","凭":"憑","气":"氣","签":"簽","枪":"槍","强":"強","窃":"竊","亲":"親","穷":"窮","区":"區","权":"權","确":"確","让":"讓","热":"熱","认":"認","荣":"榮","软":"軟","伞":"傘","丧":"喪","设":"設","审":"審","声":"聲","时":"時","实":"實","势":"勢","适":"適","书":"書","属":"屬","树":"樹","数":"數","双":"雙","说":"說","丝":"絲","岁":"歲","孙":"孫","损":"損","态":"態","团":"團","统":"統","图":"圖","涂":"塗","椭":"橢","万":"萬","网":"網","问":"問","无":"無","务":"務","雾":"霧","献":"獻","线":"線","乡":"鄉","响":"響","项":"項","协":"協","写":"寫","心":"心","兴":"興","选":"選","学":"學","压":"壓","严":"嚴","阳":"陽","养":"養","样":"樣","药":"藥","业":"業","义":"義","艺":"藝","阴":"陰","银":"銀","应":"應","拥":"擁","优":"優","邮":"郵","语":"語","园":"園","约":"約","运":"運","灾":"災","脏":"臟","战":"戰","张":"張","这":"這","证":"證","郑":"鄭","只":"隻","纸":"紙","志":"誌","种":"種","众":"眾","专":"專","庄":"莊","装":"裝","状":"狀","准":"準","总":"總","醉":"醉"};
3
+
4
+ // 反转字典,用于繁->简
5
+ const t2s = {};
6
+ for (const [s, t] of Object.entries(s2t)) {
7
+ t2s[t] = s;
8
+ }
9
+
10
+ /**
11
+ * 简体转繁体
12
+ * @param {string} text
13
+ * @returns {string}
14
+ */
15
+ function toTraditional(text) {
16
+ if (typeof text !== 'string') throw new TypeError('Input must be a string');
17
+ return text.split('').map(c => s2t[c] || c).join('');
18
+ }
19
+
20
+ /**
21
+ * 繁体转简体
22
+ * @param {string} text
23
+ * @returns {string}
24
+ */
25
+ function toSimplified(text) {
26
+ if (typeof text !== 'string') throw new TypeError('Input must be a string');
27
+ return text.split('').map(c => t2s[c] || c).join('');
28
+ }
29
+
30
+ /**
31
+ * 自动检测并转换(简->繁 或 繁->简)
32
+ * @param {string} text
33
+ * @param {'s2t'|'t2s'} direction
34
+ * @returns {string}
35
+ */
36
+ function convert(text, direction = 's2t') {
37
+ if (direction === 's2t') return toTraditional(text);
38
+ if (direction === 't2s') return toSimplified(text);
39
+ throw new Error('direction must be "s2t" or "t2s"');
40
+ }
41
+
42
+ module.exports = { toTraditional, toSimplified, convert };
package/package.json ADDED
@@ -0,0 +1,17 @@
1
+ {
2
+ "name": "zhuanhua",
3
+ "version": "1.0.1",
4
+ "description": "change words to Simplified",
5
+ "main": "index.js",
6
+ "scripts": {
7
+ "test": "node test.js"
8
+ },
9
+ "keywords": [
10
+ "chinese",
11
+ "simplified",
12
+ "traditional",
13
+ "converter"
14
+ ],
15
+ "author": "mynpm",
16
+ "license": "MIT"
17
+ }
package/test.js ADDED
@@ -0,0 +1,14 @@
1
+ const { toTraditional, toSimplified, convert } = require('./index');
2
+
3
+ console.log('=== 简体 -> 繁体 ===');
4
+ console.log(toTraditional('爱国')); // 愛國
5
+ console.log(toTraditional('计划经济')); // 計劃經濟
6
+ console.log(toTraditional('图书馆')); // 圖書館
7
+
8
+ console.log('\n=== 繁体 -> 简体 ===');
9
+ console.log(toSimplified('愛國')); // 爱国
10
+ console.log(toSimplified('圖書館')); // 图书馆
11
+
12
+ console.log('\n=== convert() 通用接口 ===');
13
+ console.log(convert('学习', 's2t')); // 學習
14
+ console.log(convert('學習', 't2s')); // 学习