tiny-pinyin
Advanced tools
Comparing version 1.0.0 to 1.1.0
@@ -1,1 +0,1 @@ | ||
!function(N,A){"object"==typeof exports&&"object"==typeof module?module.exports=A():"function"==typeof define&&define.amd?define([],A):"object"==typeof exports?exports.Pinyin=A():N.Pinyin=A()}(this,function(){return function(N){function A(U){if(I[U])return I[U].exports;var t=I[U]={i:U,l:!1,exports:{}};return N[U].call(t.exports,t,t.exports,A),t.l=!0,t.exports}var I={};return A.m=N,A.c=I,A.i=function(N){return N},A.d=function(N,I,U){A.o(N,I)||Object.defineProperty(N,I,{configurable:!1,enumerable:!0,get:U})},A.n=function(N){var I=N&&N.__esModule?function(){return N.default}:function(){return N};return A.d(I,"a",I),I},A.o=function(N,A){return Object.prototype.hasOwnProperty.call(N,A)},A.p="",A(A.s=1)}([function(N,A,I){"use strict";var U=["阿","哎","安","肮","凹","八","挀","扳","邦","勹","陂","奔","伻","屄","边","灬","憋","汃","冫","癶","峬","嚓","偲","参","仓","撡","冊","嵾","曽","曾","層","叉","芆","辿","伥","抄","车","抻","沈","沉","阷","吃","充","抽","出","欻","揣","巛","刅","吹","旾","逴","呲","匆","凑","粗","汆","崔","邨","搓","咑","呆","丹","当","刀","嘚","扥","灯","氐","甸","刁","爹","嗲","褺","丁","丟","东","吺","厾","碡","裻","耑","垖","吨","多","妸","诶","奀","鞥","儿","发","帆","匚","飞","分","丰","覅","仏","紑","夫","旮","侅","甘","冈","皋","戈","给","根","刯","工","勾","估","瓜","聒","颪","乖","关","光","归","炔","贵","丨","呙","哈","咍","佄","夯","茠","诃","蚵","龁","黒","拫","亨","噷","叿","齁","乎","花","怀","欢","巟","灰","昏","吙","砉","俰","丌","加","戋","江","艽","阶","巾","坕","冂","丩","凥","姢","噘","军","咔","开","刊","忼","尻","匼","肎","劥","空","抠","扝","夸","蒯","宽","匡","亏","坤","扩","垃","来","兰","啷","捞","肋","勒","崚","哩","俩","奁","良","撩","毟","拎","伶","溜","囖","龙","瞜","噜","驴","娈","掠","抡","罗","呣","妈","嬤","麻","埋","嫚","蹒","謾","牤","猫","么","呅","门","甿","咪","宀","喵","乜","民","名","谬","摸","哞","毪","嗯","拏","腉","囡","囔","孬","疒","娞","恁","能","妮","拈","娘","鸟","捏","囜","宁","妞","农","羺","奴","女","奻","疟","黁","郍","挪","喔","讴","妑","拍","眅","乓","抛","呸","喷","匉","丕","囨","剽","氕","姘","乒","钋","剖","仆","七","蹊","魌","掐","千","呛","丬","強","悄","癿","亲","靑","芎","卭","丘","区","峑","缺","夋","呥","穣","娆","惹","人","扔","日","茸","厹","邚","挼","堧","婑","瞤","捼","仨","毢","三","霰","饊","桒","掻","閪","森","僧","杀","筛","山","伤","弰","奢","谁","申","莘","敒","升","尸","豉","釈","収","书","刷","衰","闩","双","脽","吮","说","厶","忪","捜","苏","狻","夊","孙","唆","他","囼","坍","汤","饧","坣","夲","忑","熥","剔","天","旫","帖","厅","囲","偷","凸","湍","推","吞","乇","穵","歪","弯","尣","危","昷","翁","挝","乌","夕","虲","仙","乡","灱","些","心","星","凶","休","吁","吅","削","坃","丫","恹","央","幺","倻","一","囙","应","哟","佣","优","扜","囦","曰","晕","筠","筼","帀","災","兂","匨","傮","则","贼","怎","増","扎","捚","沾","张","长","長","佋","蜇","贞","争","帧","政","之","峙","庢","中","州","朱","抓","拽","专","妆","隹","宒","卓","乲","宗","邹","租","钻","厜","尊","昨","兙","鿃","鿄"],t=["A","AI","AN","ANG","AO","BA","BAI","BAN","BANG","BAO","BEI","BEN","BENG","BI","BIAN","BIAO","BIE","BIN","BING","BO","BU","CA","CAI","CAN","CANG","CAO","CE","CEN","CENG","ZENG","CENG","CHA","CHAI","CHAN","CHANG","CHAO","CHE","CHEN","SHEN","CHEN","CHENG","CHI","CHONG","CHOU","CHU","CHUA","CHUAI","CHUAN","CHUANG","CHUI","CHUN","CHUO","CI","CONG","COU","CU","CUAN","CUI","CUN","CUO","DA","DAI","DAN","DANG","DAO","DE","DEN","DENG","DI","DIAN","DIAO","DIE","DIA","DIE","DING","DIU","DONG","DOU","DU","ZHOU","DU","DUAN","DUI","DUN","DUO","E","EI","EN","ENG","ER","FA","FAN","FANG","FEI","FEN","FENG","FIAO","FO","FOU","FU","GA","GAI","GAN","GANG","GAO","GE","GEI","GEN","GENG","GONG","GOU","GU","GUA","GUO","GUA","GUAI","GUAN","GUANG","GUI","QUE","GUI","GUN","GUO","HA","HAI","HAN","HANG","HAO","HE","KE","HE","HEI","HEN","HENG","HM","HONG","HOU","HU","HUA","HUAI","HUAN","HUANG","HUI","HUN","HUO","HUA","HUO","JI","JIA","JIAN","JIANG","JIAO","JIE","JIN","JING","JIONG","JIU","JU","JUAN","JUE","JUN","KA","KAI","KAN","KANG","KAO","KE","KEN","KENG","KONG","KOU","KU","KUA","KUAI","KUAN","KUANG","KUI","KUN","KUO","LA","LAI","LAN","LANG","LAO","LE","LEI","LENG","LI","LIA","LIAN","LIANG","LIAO","LIE","LIN","LING","LIU","LO","LONG","LOU","LU","LV","LUAN","LVE","LUN","LUO","M","MA","MO","MA","MAI","MAN","PAN","MAN","MANG","MAO","ME","MEI","MEN","MENG","MI","MIAN","MIAO","MIE","MIN","MING","MIU","MO","MOU","MU","N","NA","NAI","NAN","NANG","NAO","NE","NEI","NEN","NENG","NI","NIAN","NIANG","NIAO","NIE","NIN","NING","NIU","NONG","NOU","NU","NV","NUAN","NVE","NUN","NA","NUO","O","OU","PA","PAI","PAN","PANG","PAO","PEI","PEN","PENG","PI","PIAN","PIAO","PIE","PIN","PING","PO","POU","PU","QI","XI","QI","QIA","QIAN","QIANG","PAN","QIANG","QIAO","QIE","QIN","QING","XIONG","QIONG","QIU","QU","QUAN","QUE","QUN","RAN","RANG","RAO","RE","REN","RENG","RI","RONG","ROU","RU","RUA","RUAN","RUI","RUN","RUO","SA","SAI","SAN","XIAN","SAN","SANG","SAO","SE","SEN","SENG","SHA","SHAI","SHAN","SHANG","SHAO","SHE","SHUI","SHEN","XIN","SHEN","SHENG","SHI","CHI","SHI","SHOU","SHU","SHUA","SHUAI","SHUAN","SHUANG","SHUI","SHUN","SHUO","SI","SONG","SOU","SU","SUAN","SUI","SUN","SUO","TA","TAI","TAN","TANG","XING","TANG","TAO","TE","TENG","TI","TIAN","TIAO","TIE","TING","TONG","TOU","TU","TUAN","TUI","TUN","TUO","WA","WAI","WAN","WANG","WEI","WEN","WENG","WO","WU","XI","XIA","XIAN","XIANG","XIAO","XIE","XIN","XING","XIONG","XIU","XU","XUAN","XUE","XUN","YA","YAN","YANG","YAO","YE","YI","YIN","YING","YO","YONG","YOU","YU","YUAN","YUE","YUN","JUN","YUN","ZA","ZAI","ZAN","ZANG","ZAO","ZE","ZEI","ZEN","ZENG","ZHA","ZHAI","ZHAN","ZHANG","CHANG","ZHANG","ZHAO","ZHE","ZHEN","ZHENG","ZHEN","ZHENG","ZHI","SHI","ZHI","ZHONG","ZHOU","ZHU","ZHUA","ZHUAI","ZHUAN","ZHUANG","ZHUI","ZHUN","ZHUO","ZI","ZONG","ZOU","ZU","ZUAN","ZUI","ZUN","ZUO","","SHAN",""];N.exports={PINYINS:t,UNIHANS:U}},function(N,A,I){"use strict";function U(N){return N||null===f?("object"===("undefined"==typeof Intl?"undefined":G(Intl))&&Intl.Collator?(S=new Intl.Collator(["zh-Hans-CN","zh-CN"]),f=1===Intl.Collator.supportedLocalesOf(["zh-CN"]).length):f=!1,f):f}function t(N){var A={source:N},I=-1,U=void 0;if(N.charCodeAt(0)<256)return A.type=H,A.target=N,A;if((U=S.compare(N,O))<0)return A.type=i,A.target=N,A;if(0===U)A.type=u,I=0;else{if((U=S.compare(N,E))>0)return A.type=i,A.target=N,A;0===U&&(A.type=u,I=n.length-1)}if(A.type=u,I<0)for(var t=0,e=n.length-1;t<=e;){I=~~((t+e)/2);var G=n[I];if(0===(U=S.compare(N,G)))break;U>0?t=I+1:e=I-1}return U<0&&I--,A.target=o[I],A.target||(A.type=i,A.target=A.source),A}function e(N){if("string"!=typeof N)throw new Error("argument should be string.");if(!U())throw new Error("not support Intl or zh-CN language.");return N.split("").map(function(N){return t(N)})}var G="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(N){return typeof N}:function(N){return N&&"function"==typeof Symbol&&N.constructor===Symbol&&N!==Symbol.prototype?"symbol":typeof N},r=I(0),n=r.UNIHANS,o=r.PINYINS,O="阿",E="鿿",H=1,u=2,i=3,f=null,S=void 0;N.exports={isSupported:U,parse:e,convertToPinyin:function(N,A,I){return e(N).map(function(N){return I&&N.type===u?N.target.toLowerCase():N.target}).join(A||"")}}}])}); | ||
!function(N,A){"object"==typeof exports&&"object"==typeof module?module.exports=A():"function"==typeof define&&define.amd?define([],A):"object"==typeof exports?exports.Pinyin=A():N.Pinyin=A()}(this,function(){return function(N){function A(I){if(t[I])return t[I].exports;var U=t[I]={i:I,l:!1,exports:{}};return N[I].call(U.exports,U,U.exports,A),U.l=!0,U.exports}var t={};return A.m=N,A.c=t,A.i=function(N){return N},A.d=function(N,t,I){A.o(N,t)||Object.defineProperty(N,t,{configurable:!1,enumerable:!0,get:I})},A.n=function(N){var t=N&&N.__esModule?function(){return N.default}:function(){return N};return A.d(t,"a",t),t},A.o=function(N,A){return Object.prototype.hasOwnProperty.call(N,A)},A.p="",A(A.s=2)}([function(N,A,t){"use strict";function I(N){N&&("function"==typeof N&&(N=[N]),N.forEach&&N.forEach(function(N){"function"==typeof N&&N(r)}))}function U(N){return N||null===u?("object"===("undefined"==typeof Intl?"undefined":o(Intl))&&Intl.Collator?(f=new Intl.Collator(["zh-Hans-CN","zh-CN"]),u=1===Intl.Collator.supportedLocalesOf(["zh-CN"]).length):u=!1,u):u}function e(N){var A=r.UNIHANS,t=r.PINYINS,I=r.EXCEPTIONS,U={source:N};if(N in I)return U.type=E,U.target=I[N],U;var e=-1,n=void 0;if(N.charCodeAt(0)<256)return U.type=O,U.target=N,U;if((n=f.compare(N,G))<0)return U.type=i,U.target=N,U;if(0===n)U.type=E,e=0;else{if((n=f.compare(N,H))>0)return U.type=i,U.target=N,U;0===n&&(U.type=E,e=A.length-1)}if(U.type=E,e<0)for(var o=0,u=A.length-1;o<=u;){e=~~((o+u)/2);var S=A[e];if(0===(n=f.compare(N,S)))break;n>0?o=e+1:u=e-1}return n<0&&e--,U.target=t[e],U.target||(U.type=i,U.target=U.source),U}function n(N){if("string"!=typeof N)throw new Error("argument should be string.");if(!U())throw new Error("not support Intl or zh-CN language.");return N.split("").map(function(N){return e(N)})}var o="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(N){return typeof N}:function(N){return N&&"function"==typeof Symbol&&N.constructor===Symbol&&N!==Symbol.prototype?"symbol":typeof N},r=t(3),G="阿",H="鿿",O=1,E=2,i=3,u=null,f=void 0;N.exports={isSupported:U,parse:n,patchDict:I,convertToPinyin:function(N,A,t){return n(N).map(function(N){return t&&N.type===E?N.target.toLowerCase():N.target}).join(A||"")}}},function(N,A,t){"use strict";N.exports=function(N){N.EXCEPTIONS={"嗲":"DIA","碡":"ZHOU","聒":"GUO","炔":"QUE","蚵":"KE","砉":"HUA","嬷":"MO","蹊":"XI","丬":"PAN","霰":"XIAN","豉":"CHI","饧":"XING","帧":"ZHEN","芎":"XIONG","谁":"SHUI","钶":"KE"},N.UNIHANS[91]="伕",N.UNIHANS[347]="仚",N.UNIHANS[393]="诌",N.UNIHANS[39]="婤",N.UNIHANS[50]="腠",N.UNIHANS[369]="攸",N.UNIHANS[123]="乯",N.UNIHANS[171]="刕",N.UNIHANS[102]="佝",N.UNIHANS[126]="犿",N.UNIHANS[176]="列",N.UNIHANS[178]="刢",N.UNIHANS[252]="娝",N.UNIHANS[330]="偸"}},function(N,A,t){"use strict";var I="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(N){return typeof N}:function(N){return N&&"function"==typeof Symbol&&N.constructor===Symbol&&N!==Symbol.prototype?"symbol":typeof N},U=t(0),e=t(1);"object"===("undefined"==typeof navigator?"undefined":I(navigator))&&/safari/i.test(navigator.userAgent)&&!/chrome|android/i.test(navigator.userAgent)&&U.patchDict(e),N.exports=U},function(N,A,t){"use strict";var I=["阿","哎","安","肮","凹","八","挀","扳","邦","勹","陂","奔","伻","屄","边","灬","憋","汃","冫","癶","峬","嚓","偲","参","仓","撡","冊","嵾","曽","叉","芆","辿","伥","抄","车","抻","阷","吃","充","抽","出","欻","揣","巛","刅","吹","旾","逴","呲","匆","凑","粗","汆","崔","邨","搓","咑","呆","丹","当","刀","嘚","扥","灯","氐","甸","刁","爹","丁","丟","东","吺","厾","耑","垖","吨","多","妸","诶","奀","鞥","儿","发","帆","匚","飞","分","丰","覅","仏","紑","夫","旮","侅","甘","冈","皋","戈","给","根","刯","工","勾","估","瓜","乖","关","光","归","丨","呙","哈","咍","佄","夯","茠","诃","黒","拫","亨","噷","叿","齁","乎","花","怀","欢","巟","灰","昏","吙","丌","加","戋","江","艽","阶","巾","坕","冂","丩","凥","姢","噘","军","咔","开","刊","忼","尻","匼","肎","劥","空","抠","扝","夸","蒯","宽","匡","亏","坤","扩","垃","来","兰","啷","捞","肋","勒","崚","哩","俩","奁","良","撩","毟","拎","伶","溜","囖","龙","瞜","噜","驴","娈","掠","抡","罗","呣","妈","埋","嫚","牤","猫","么","呅","门","甿","咪","宀","喵","乜","民","名","谬","摸","哞","毪","嗯","拏","腉","囡","囔","孬","疒","娞","恁","能","妮","拈","娘","鸟","捏","囜","宁","妞","农","羺","奴","女","奻","疟","黁","挪","喔","讴","妑","拍","眅","乓","抛","呸","喷","匉","丕","囨","剽","氕","姘","乒","钋","剖","仆","七","掐","千","呛","悄","癿","亲","靑","卭","丘","区","峑","缺","夋","呥","穣","娆","惹","人","扔","日","茸","厹","邚","挼","堧","婑","瞤","捼","仨","毢","三","桒","掻","閪","森","僧","杀","筛","山","伤","弰","奢","申","升","尸","収","书","刷","衰","闩","双","脽","吮","说","厶","忪","捜","苏","狻","夊","孙","唆","他","囼","坍","汤","夲","忑","熥","剔","天","旫","帖","厅","囲","偷","凸","湍","推","吞","乇","穵","歪","弯","尣","危","昷","翁","挝","乌","夕","虲","仙","乡","灱","些","心","星","凶","休","吁","吅","削","坃","丫","恹","央","幺","倻","一","囙","应","哟","佣","优","扜","囦","曰","晕","帀","災","兂","匨","傮","则","贼","怎","増","扎","捚","沾","张","佋","蜇","贞","争","之","中","州","朱","抓","拽","专","妆","隹","宒","卓","乲","宗","邹","租","钻","厜","尊","昨","兙"],U=["A","AI","AN","ANG","AO","BA","BAI","BAN","BANG","BAO","BEI","BEN","BENG","BI","BIAN","BIAO","BIE","BIN","BING","BO","BU","CA","CAI","CAN","CANG","CAO","CE","CEN","CENG","CHA","CHAI","CHAN","CHANG","CHAO","CHE","CHEN","CHENG","CHI","CHONG","CHOU","CHU","CHUA","CHUAI","CHUAN","CHUANG","CHUI","CHUN","CHUO","CI","CONG","COU","CU","CUAN","CUI","CUN","CUO","DA","DAI","DAN","DANG","DAO","DE","DEN","DENG","DI","DIAN","DIAO","DIE","DING","DIU","DONG","DOU","DU","DUAN","DUI","DUN","DUO","E","EI","EN","ENG","ER","FA","FAN","FANG","FEI","FEN","FENG","FIAO","FO","FOU","FU","GA","GAI","GAN","GANG","GAO","GE","GEI","GEN","GENG","GONG","GOU","GU","GUA","GUAI","GUAN","GUANG","GUI","GUN","GUO","HA","HAI","HAN","HANG","HAO","HE","HEI","HEN","HENG","HM","HONG","HOU","HU","HUA","HUAI","HUAN","HUANG","HUI","HUN","HUO","JI","JIA","JIAN","JIANG","JIAO","JIE","JIN","JING","JIONG","JIU","JU","JUAN","JUE","JUN","KA","KAI","KAN","KANG","KAO","KE","KEN","KENG","KONG","KOU","KU","KUA","KUAI","KUAN","KUANG","KUI","KUN","KUO","LA","LAI","LAN","LANG","LAO","LE","LEI","LENG","LI","LIA","LIAN","LIANG","LIAO","LIE","LIN","LING","LIU","LO","LONG","LOU","LU","LV","LUAN","LVE","LUN","LUO","M","MA","MAI","MAN","MANG","MAO","ME","MEI","MEN","MENG","MI","MIAN","MIAO","MIE","MIN","MING","MIU","MO","MOU","MU","N","NA","NAI","NAN","NANG","NAO","NE","NEI","NEN","NENG","NI","NIAN","NIANG","NIAO","NIE","NIN","NING","NIU","NONG","NOU","NU","NV","NUAN","NVE","NUN","NUO","O","OU","PA","PAI","PAN","PANG","PAO","PEI","PEN","PENG","PI","PIAN","PIAO","PIE","PIN","PING","PO","POU","PU","QI","QIA","QIAN","QIANG","QIAO","QIE","QIN","QING","QIONG","QIU","QU","QUAN","QUE","QUN","RAN","RANG","RAO","RE","REN","RENG","RI","RONG","ROU","RU","RUA","RUAN","RUI","RUN","RUO","SA","SAI","SAN","SANG","SAO","SE","SEN","SENG","SHA","SHAI","SHAN","SHANG","SHAO","SHE","SHEN","SHENG","SHI","SHOU","SHU","SHUA","SHUAI","SHUAN","SHUANG","SHUI","SHUN","SHUO","SI","SONG","SOU","SU","SUAN","SUI","SUN","SUO","TA","TAI","TAN","TANG","TAO","TE","TENG","TI","TIAN","TIAO","TIE","TING","TONG","TOU","TU","TUAN","TUI","TUN","TUO","WA","WAI","WAN","WANG","WEI","WEN","WENG","WO","WU","XI","XIA","XIAN","XIANG","XIAO","XIE","XIN","XING","XIONG","XIU","XU","XUAN","XUE","XUN","YA","YAN","YANG","YAO","YE","YI","YIN","YING","YO","YONG","YOU","YU","YUAN","YUE","YUN","ZA","ZAI","ZAN","ZANG","ZAO","ZE","ZEI","ZEN","ZENG","ZHA","ZHAI","ZHAN","ZHANG","ZHAO","ZHE","ZHEN","ZHENG","ZHI","ZHONG","ZHOU","ZHU","ZHUA","ZHUAI","ZHUAN","ZHUANG","ZHUI","ZHUN","ZHUO","ZI","ZONG","ZOU","ZU","ZUAN","ZUI","ZUN","ZUO",""],e={"曾":"ZENG","沈":"SHEN","嗲":"DIA","碡":"ZHOU","聒":"GUO","炔":"QUE","蚵":"KE","砉":"HUA","嬤":"MO","嬷":"MO","蹒":"PAN","蹊":"XI","丬":"PAN","霰":"XIAN","莘":"XIN","豉":"CHI","饧":"XING","筠":"JUN","长":"CHANG","帧":"ZHEN","峙":"SHI","郍":"NA","芎":"XIONG","谁":"SHUI"};N.exports={PINYINS:U,UNIHANS:I,EXCEPTIONS:e}}])}); |
{ | ||
"name": "tiny-pinyin", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "convert hanzi to pinyin", | ||
@@ -26,2 +26,9 @@ "main": "dist/index.js", | ||
"html-webpack-plugin": "^2.28.0", | ||
"karma": "^1.7.0", | ||
"karma-chrome-launcher": "^2.1.1", | ||
"karma-firefox-launcher": "^1.0.1", | ||
"karma-mocha": "^1.3.0", | ||
"karma-safari-launcher": "^1.0.0", | ||
"karma-sauce-launcher": "^1.1.0", | ||
"karma-webpack": "^2.0.3", | ||
"mocha": "^3.3.0", | ||
@@ -35,5 +42,7 @@ "postcss-loader": "^2.0.5", | ||
"pretest": "babel --presets=power-assert,es2015 test --out-dir test-compiled", | ||
"test": "npm run lint && npm run test-notsupport && npm run test-common", | ||
"test": "npm run lint && npm run test-notsupport && npm run test-common && npm run test:sauce", | ||
"test-common": "NODE_ICU_DATA='node_modules/full-icu' mocha test-compiled/index.spec.js", | ||
"test-notsupport": "mocha test-compiled/notSupport.spec.js", | ||
"test:browser": "karma start scripts/karma.conf.js --single-run", | ||
"test:sauce": "SAUCE='saucelabs' karma start scripts/karma.conf.js", | ||
"lint": "eslint src test scripts/{*.js,pre-commit}", | ||
@@ -40,0 +49,0 @@ "prepublish": "babel --presets=es2015 src --out-dir dist", |
@@ -5,2 +5,4 @@ # tiny-pinyin [![Build Status](https://travis-ci.org/creeperyang/pinyin.svg?branch=master)](https://travis-ci.org/creeperyang/pinyin) | ||
[![Build Status](https://saucelabs.com/browser-matrix/creeperyang.svg)](https://saucelabs.com/beta/builds/8f2adabb0c47479fbcf50d1bbcdf8ecb) | ||
轻量的 **汉字转拼音** JavaScript库。可以轻松获取汉字的拼音。有以下特性: | ||
@@ -12,9 +14,7 @@ | ||
[![Demo](https://cloud.githubusercontent.com/assets/8046480/25986097/a86896c2-3720-11e7-9bfe-17285f8005f0.png)](https://creeperyang.github.io/pinyin/) | ||
**注意:不支持多音字;`node 6/7`,最新 `safari/ios/chrome/firefox` 测试通过,`ie/edge` 测试不通过,`android` 需要更新字典。** | ||
可点击上面的图片体验[线上版本](https://creeperyang.github.io/pinyin/)。 | ||
## 安装和使用 | ||
安装:`$ npm i --save tiny-pinyin` | ||
[![NPM](https://nodei.co/npm/tiny-pinyin.png?compact=true)](https://nodei.co/npm/tiny-pinyin/) | ||
@@ -25,3 +25,3 @@ 使用: | ||
// test.js | ||
const pinyin = require('tiny-pinyin') | ||
const pinyin = require('tiny-pinyin') // Or require('tiny-pinyin/dist/browser') for browser | ||
@@ -43,2 +43,8 @@ if (pinyin.isSupported()) { | ||
## Demo | ||
[![Demo](https://cloud.githubusercontent.com/assets/8046480/25986097/a86896c2-3720-11e7-9bfe-17285f8005f0.png)](https://creeperyang.github.io/pinyin/) | ||
可点击上面的图片体验[线上版本](https://creeperyang.github.io/pinyin/)。 | ||
## API | ||
@@ -66,3 +72,3 @@ | ||
**请注意,当字符串为** | ||
**请注意,当字符串为:** | ||
@@ -85,2 +91,8 @@ 1. 拉丁字母,即ascii码`0-255`,不处理,原样输出,即`source/target`一致,`type`为`1`。 | ||
### 4. `pinyin.patchDict(fn)` | ||
- `fn`,`function`类型,接受参数为当前使用的字典对象`DICT`,可以修改`DICT.UNIHANS/DICT.PINYINS/DICT.EXCEPTIONS`来修改字典。另外,`fn`可以是数组,数组的每个元素为函数类型。 | ||
其中:`DICT.UNIHANS/DICT.PINYINS`两者相对应,记录边界汉字和其对应拼音。`DICT.EXCEPTIONS`是 **例外** 字典,为`汉字-拼音`的键值对,拥有更高优先级。 | ||
## 致谢 | ||
@@ -87,0 +99,0 @@ |
@@ -32,3 +32,3 @@ const path = require('path') | ||
{ | ||
entry: path.resolve(ROOT, 'src/index.js'), | ||
entry: path.resolve(ROOT, 'src/browser.js'), | ||
output: { | ||
@@ -35,0 +35,0 @@ filename: 'docs/browser.js', |
142
src/dict.js
@@ -12,5 +12,5 @@ /** | ||
'\u51ab', '\u7676', '\u5cec', '\u5693', '\u5072', '\u53c2', | ||
'\u4ed3', '\u64a1', '\u518a', '\u5d7e', '\u66fd', '\u66fe', | ||
'\u5c64', '\u53c9', '\u8286', '\u8fbf', '\u4f25', '\u6284', | ||
'\u8f66', '\u62bb', '\u6c88', '\u6c89', '\u9637', '\u5403', | ||
'\u4ed3', '\u64a1', '\u518a', '\u5d7e', '\u66fd', | ||
'\u53c9', '\u8286', '\u8fbf', '\u4f25', '\u6284', | ||
'\u8f66', '\u62bb', '\u9637', '\u5403', | ||
'\u5145', '\u62bd', '\u51fa', '\u6b3b', '\u63e3', '\u5ddb', | ||
@@ -20,14 +20,14 @@ '\u5205', '\u5439', '\u65fe', '\u9034', '\u5472', '\u5306', | ||
'\u5491', '\u5446', '\u4e39', '\u5f53', '\u5200', '\u561a', | ||
'\u6265', '\u706f', '\u6c10', /* '\u55f2', */'\u7538', '\u5201', | ||
'\u7239', '\u55f2', '\u893a', '\u4e01', '\u4e1f', '\u4e1c', '\u543a', '\u53be', '\u78a1', '\u88fb', // add 碡,裻 嗲,褺 | ||
'\u8011', '\u5796', '\u5428', '\u591a', '\u59b8', '\u8bf6', // dui: \u8968->\u5796 | ||
'\u6265', '\u706f', '\u6c10', '\u7538', '\u5201', | ||
'\u7239', '\u4e01', '\u4e1f', '\u4e1c', '\u543a', '\u53be', | ||
'\u8011', '\u5796', '\u5428', '\u591a', '\u59b8', '\u8bf6', | ||
'\u5940', '\u97a5', '\u513f', '\u53d1', '\u5e06', '\u531a', | ||
'\u98de', '\u5206', '\u4e30', '\u8985', '\u4ecf', '\u7d11', | ||
'\u592b', '\u65ee', '\u4f85', '\u7518', '\u5188', '\u768b', // 伕 --> 夫 | ||
'\u592b', '\u65ee', '\u4f85', '\u7518', '\u5188', '\u768b', | ||
'\u6208', '\u7ed9', '\u6839', '\u522f', '\u5de5', '\u52fe', | ||
'\u4f30', '\u74dc', '\u8052', '\u98aa', '\u4e56', '\u5173', '\u5149', '\u5f52', '\u7094', '\u8d35', // add 聒,颪,炔,贵 | ||
'\u4f30', '\u74dc', '\u4e56', '\u5173', '\u5149', '\u5f52', | ||
'\u4e28', '\u5459', '\u54c8', '\u548d', '\u4f44', '\u592f', | ||
'\u8320', '\u8bc3', '\u86b5', '\u9f81', '\u9ed2', '\u62eb', '\u4ea8', '\u5677', // add 蚵,龁 | ||
'\u53ff', '\u9f41', '\u4e4e', '\u82b1', '\u6000', '\u6b22', // 乯-->乎 犿-->欢 | ||
'\u5ddf', '\u7070', '\u660f', '\u5419', '\u7809', '\u4ff0', '\u4e0c', '\u52a0', // add 砉,俰 | ||
'\u8320', '\u8bc3', '\u9ed2', '\u62eb', '\u4ea8', '\u5677', | ||
'\u53ff', '\u9f41', '\u4e4e', '\u82b1', '\u6000', '\u6b22', | ||
'\u5ddf', '\u7070', '\u660f', '\u5419', '\u4e0c', '\u52a0', | ||
'\u620b', '\u6c5f', '\u827d', '\u9636', '\u5dfe', '\u5755', | ||
@@ -39,6 +39,6 @@ '\u5182', '\u4e29', '\u51e5', '\u59e2', '\u5658', '\u519b', | ||
'\u5783', '\u6765', '\u5170', '\u5577', '\u635e', '\u808b', | ||
'\u52d2', '\u5d1a', '\u54e9', '\u4fe9', '\u5941', '\u826f', // \u5215-->\u54e9 | ||
'\u64a9', '\u6bdf', '\u62ce', '\u4f36', '\u6e9c', '\u56d6', // 列->毟 刢-->伶 | ||
'\u9f99', '\u779c', '\u565c', '\u9a74', '\u5a08', '\u63a0', '\u62a1', // add 驴; 畧-->掠 | ||
'\u7f57', '\u5463', '\u5988', '\u5b24', '\u9ebb', '\u57cb', '\u5ada', '\u8e52', '\u8b3e', '\u7264', // add 嬤,麻,蹒,謾 | ||
'\u52d2', '\u5d1a', '\u54e9', '\u4fe9', '\u5941', '\u826f', | ||
'\u64a9', '\u6bdf', '\u62ce', '\u4f36', '\u6e9c', '\u56d6', | ||
'\u9f99', '\u779c', '\u565c', '\u9a74', '\u5a08', '\u63a0', '\u62a1', | ||
'\u7f57', '\u5463', '\u5988', '\u57cb', '\u5ada', '\u7264', | ||
'\u732b', '\u4e48', '\u5445', '\u95e8', '\u753f', '\u54aa', | ||
@@ -48,24 +48,24 @@ '\u5b80', '\u55b5', '\u4e5c', '\u6c11', '\u540d', '\u8c2c', | ||
'\u56e1', '\u56d4', '\u5b6c', '\u7592', '\u5a1e', '\u6041', | ||
'\u80fd', '\u59ae', '\u62c8', '\u5a18', '\u9e1f', '\u634f', // 嬢 --> 娘 | ||
'\u56dc', '\u5b81', '\u599e', '\u519c', '\u7fba', '\u5974', '\u5973', // add 女 | ||
'\u597b', '\u759f', '\u9ec1', '\u90cd', '\u632a', '\u5594', '\u8bb4', // add 挪 | ||
'\u80fd', '\u59ae', '\u62c8', '\u5a18', '\u9e1f', '\u634f', | ||
'\u56dc', '\u5b81', '\u599e', '\u519c', '\u7fba', '\u5974', '\u5973', | ||
'\u597b', '\u759f', '\u9ec1', '\u632a', '\u5594', '\u8bb4', | ||
'\u5991', '\u62cd', '\u7705', '\u4e53', '\u629b', '\u5478', | ||
'\u55b7', '\u5309', '\u4e15', '\u56e8', '\u527d', '\u6c15', | ||
'\u59d8', '\u4e52', '\u948b', '\u5256', '\u4ec6', '\u4e03', '\u8e4a', '\u9b4c', // add 蹊,魌 | ||
'\u6390', '\u5343', '\u545b', '\u4e2c', '\u5f37', '\u6084', '\u767f', '\u4eb2', // add 丬 | ||
'\u9751', '\u828e', '\u536d', '\u4e18', '\u533a', '\u5cd1', '\u7f3a', // 狅->靑 add 卭 | ||
'\u59d8', '\u4e52', '\u948b', '\u5256', '\u4ec6', '\u4e03', | ||
'\u6390', '\u5343', '\u545b', '\u6084', '\u767f', '\u4eb2', | ||
'\u9751', '\u536d', '\u4e18', '\u533a', '\u5cd1', '\u7f3a', | ||
'\u590b', '\u5465', '\u7a63', '\u5a06', '\u60f9', '\u4eba', | ||
'\u6254', '\u65e5', '\u8338', '\u53b9', '\u909a', '\u633c', | ||
'\u5827', '\u5a51', '\u77a4', '\u637c', '\u4ee8', '\u6be2', | ||
'\u4e09', '\u9730', '\u994a', '\u6852', '\u63bb', '\u95aa', '\u68ee', '\u50e7', // add 霰,饊 | ||
'\u6740', '\u7b5b', '\u5c71', '\u4f24', '\u5f30', '\u5962', '\u8c01', // add 谁 | ||
'\u7533', '\u8398', '\u6552', '\u5347', '\u5c38', '\u8c49', '\u91c8', '\u53ce', // add 豉,釈 | ||
'\u4e66', '\u5237', '\u8870', '\u95e9', '\u53cc', '\u813d', // 谁-->脽 | ||
'\u4e09', '\u6852', '\u63bb', '\u95aa', '\u68ee', '\u50e7', | ||
'\u6740', '\u7b5b', '\u5c71', '\u4f24', '\u5f30', '\u5962', | ||
'\u7533', '\u5347', '\u5c38', '\u53ce', | ||
'\u4e66', '\u5237', '\u8870', '\u95e9', '\u53cc', '\u813d', | ||
'\u542e', '\u8bf4', '\u53b6', '\u5fea', '\u635c', '\u82cf', | ||
'\u72fb', '\u590a', '\u5b59', '\u5506', '\u4ed6', '\u56fc', | ||
'\u574d', '\u6c64', '\u9967', '\u5763', '\u5932', '\u5fd1', '\u71a5', '\u5254', // add 饧,坣 | ||
'\u574d', '\u6c64', '\u5932', '\u5fd1', '\u71a5', '\u5254', | ||
'\u5929', '\u65eb', '\u5e16', '\u5385', '\u56f2', '\u5077', | ||
'\u51f8', '\u6e4d', '\u63a8', '\u541e', '\u4e47', '\u7a75', | ||
'\u6b6a', '\u5f2f', '\u5c23', '\u5371', '\u6637', '\u7fc1', | ||
'\u631d', '\u4e4c', '\u5915', '\u8672', '\u4ed9', '\u4e61', // \u4eda --> \u4ed9 | ||
'\u631d', '\u4e4c', '\u5915', '\u8672', '\u4ed9', '\u4e61', | ||
'\u7071', '\u4e9b', '\u5fc3', '\u661f', '\u51f6', '\u4f11', | ||
@@ -75,10 +75,9 @@ '\u5401', '\u5405', '\u524a', '\u5743', '\u4e2b', '\u6079', | ||
'\u54df', '\u4f63', '\u4f18', '\u625c', '\u56e6', '\u66f0', | ||
'\u6655', '\u7b60', '\u7b7c', '\u5e00', '\u707d', '\u5142', | ||
'\u6655', '\u5e00', '\u707d', '\u5142', | ||
'\u5328', '\u50ae', '\u5219', '\u8d3c', '\u600e', '\u5897', | ||
'\u624e', '\u635a', '\u6cbe', '\u5f20', '\u957f', '\u9577', | ||
'\u4f4b', '\u8707', '\u8d1e', '\u4e89', '\u5e27', '\u653f', '\u4e4b', '\u5cd9', // add 帧 | ||
'\u5ea2', '\u4e2d', '\u5dde', '\u6731', '\u6293', '\u62fd', | ||
'\u624e', '\u635a', '\u6cbe', '\u5f20', '\u4f4b', '\u8707', '\u8d1e', '\u4e89', '\u4e4b', | ||
'\u4e2d', '\u5dde', '\u6731', '\u6293', '\u62fd', | ||
'\u4e13', '\u5986', '\u96b9', '\u5b92', '\u5353', '\u4e72', | ||
'\u5b97', '\u90b9', '\u79df', '\u94bb', '\u539c', '\u5c0a', | ||
'\u6628', '\u5159', '\u9fc3', '\u9fc4' | ||
'\u6628', '\u5159' | ||
] | ||
@@ -92,5 +91,5 @@ | ||
'BING', 'BO', 'BU', 'CA', 'CAI', 'CAN', | ||
'CANG', 'CAO', 'CE', 'CEN', 'CENG', 'ZENG', | ||
'CENG', 'CHA', 'CHAI', 'CHAN', 'CHANG', 'CHAO', | ||
'CHE', 'CHEN', 'SHEN', 'CHEN', 'CHENG', 'CHI', | ||
'CANG', 'CAO', 'CE', 'CEN', 'CENG', | ||
'CHA', 'CHAI', 'CHAN', 'CHANG', 'CHAO', | ||
'CHE', 'CHEN', 'CHENG', 'CHI', | ||
'CHONG', 'CHOU', 'CHU', 'CHUA', 'CHUAI', 'CHUAN', | ||
@@ -100,4 +99,4 @@ 'CHUANG', 'CHUI', 'CHUN', 'CHUO', 'CI', 'CONG', | ||
'DA', 'DAI', 'DAN', 'DANG', 'DAO', 'DE', | ||
'DEN', 'DENG', 'DI', /* 'DIA', */'DIAN', 'DIAO', | ||
'DIE', 'DIA', 'DIE', 'DING', 'DIU', 'DONG', 'DOU', 'DU', 'ZHOU', 'DU', // add 碡,裻 嗲,褺 | ||
'DEN', 'DENG', 'DI', 'DIAN', 'DIAO', | ||
'DIE', 'DING', 'DIU', 'DONG', 'DOU', 'DU', | ||
'DUAN', 'DUI', 'DUN', 'DUO', 'E', 'EI', | ||
@@ -108,7 +107,7 @@ 'EN', 'ENG', 'ER', 'FA', 'FAN', 'FANG', | ||
'GE', 'GEI', 'GEN', 'GENG', 'GONG', 'GOU', | ||
'GU', 'GUA', 'GUO', 'GUA', 'GUAI', 'GUAN', 'GUANG', 'GUI', 'QUE', 'GUI', // add 聒,颪,炔,贵 | ||
'GU', 'GUA', 'GUAI', 'GUAN', 'GUANG', 'GUI', | ||
'GUN', 'GUO', 'HA', 'HAI', 'HAN', 'HANG', | ||
'HAO', 'HE', 'KE', 'HE', 'HEI', 'HEN', 'HENG', 'HM', // add 蚵,龁 | ||
'HAO', 'HE', 'HEI', 'HEN', 'HENG', 'HM', | ||
'HONG', 'HOU', 'HU', 'HUA', 'HUAI', 'HUAN', | ||
'HUANG', 'HUI', 'HUN', 'HUO', 'HUA', 'HUO', 'JI', 'JIA', // add 砉,俰 | ||
'HUANG', 'HUI', 'HUN', 'HUO', 'JI', 'JIA', | ||
'JIAN', 'JIANG', 'JIAO', 'JIE', 'JIN', 'JING', | ||
@@ -122,4 +121,4 @@ 'JIONG', 'JIU', 'JU', 'JUAN', 'JUE', 'JUN', | ||
'LIAO', 'LIE', 'LIN', 'LING', 'LIU', 'LO', | ||
'LONG', 'LOU', 'LU', 'LV', 'LUAN', 'LVE', 'LUN', // add LV | ||
'LUO', 'M', 'MA', 'MO', 'MA', 'MAI', 'MAN', 'PAN', 'MAN', 'MANG', // add PAN,MO | ||
'LONG', 'LOU', 'LU', 'LV', 'LUAN', 'LVE', 'LUN', | ||
'LUO', 'M', 'MA', 'MAI', 'MAN', 'MANG', | ||
'MAO', 'ME', 'MEI', 'MEN', 'MENG', 'MI', | ||
@@ -130,19 +129,19 @@ 'MIAN', 'MIAO', 'MIE', 'MIN', 'MING', 'MIU', | ||
'NENG', 'NI', 'NIAN', 'NIANG', 'NIAO', 'NIE', | ||
'NIN', 'NING', 'NIU', 'NONG', 'NOU', 'NU', 'NV', // add NV | ||
'NUAN', 'NVE', 'NUN', 'NA', 'NUO', 'O', 'OU', // add NA | ||
'NIN', 'NING', 'NIU', 'NONG', 'NOU', 'NU', 'NV', | ||
'NUAN', 'NVE', 'NUN', 'NUO', 'O', 'OU', | ||
'PA', 'PAI', 'PAN', 'PANG', 'PAO', 'PEI', | ||
'PEN', 'PENG', 'PI', 'PIAN', 'PIAO', 'PIE', | ||
'PIN', 'PING', 'PO', 'POU', 'PU', 'QI', 'XI', 'QI', // Correct 蹊 | ||
'QIA', 'QIAN', 'QIANG', 'PAN', 'QIANG', 'QIAO', 'QIE', 'QIN', // add 丬 | ||
'QING', 'XIONG', 'QIONG', 'QIU', 'QU', 'QUAN', 'QUE', // add XIONG | ||
'PIN', 'PING', 'PO', 'POU', 'PU', 'QI', | ||
'QIA', 'QIAN', 'QIANG', 'QIAO', 'QIE', 'QIN', | ||
'QING', 'QIONG', 'QIU', 'QU', 'QUAN', 'QUE', | ||
'QUN', 'RAN', 'RANG', 'RAO', 'RE', 'REN', | ||
'RENG', 'RI', 'RONG', 'ROU', 'RU', 'RUA', | ||
'RUAN', 'RUI', 'RUN', 'RUO', 'SA', 'SAI', | ||
'SAN', 'XIAN', 'SAN', 'SANG', 'SAO', 'SE', 'SEN', 'SENG', // add 霰,饊 | ||
'SHA', 'SHAI', 'SHAN', 'SHANG', 'SHAO', 'SHE', 'SHUI', // add 谁 | ||
'SHEN', 'XIN', 'SHEN', 'SHENG', 'SHI', 'CHI', 'SHI', 'SHOU', // add 豉,釈 | ||
'SAN', 'SANG', 'SAO', 'SE', 'SEN', 'SENG', | ||
'SHA', 'SHAI', 'SHAN', 'SHANG', 'SHAO', 'SHE', | ||
'SHEN', 'SHENG', 'SHI', 'SHOU', | ||
'SHU', 'SHUA', 'SHUAI', 'SHUAN', 'SHUANG', 'SHUI', | ||
'SHUN', 'SHUO', 'SI', 'SONG', 'SOU', 'SU', | ||
'SUAN', 'SUI', 'SUN', 'SUO', 'TA', 'TAI', | ||
'TAN', 'TANG', 'XING', 'TANG', 'TAO', 'TE', 'TENG', 'TI', // add 饧,坣 | ||
'TAN', 'TANG', 'TAO', 'TE', 'TENG', 'TI', | ||
'TIAN', 'TIAO', 'TIE', 'TING', 'TONG', 'TOU', | ||
@@ -156,15 +155,44 @@ 'TU', 'TUAN', 'TUI', 'TUN', 'TUO', 'WA', | ||
'YO', 'YONG', 'YOU', 'YU', 'YUAN', 'YUE', | ||
'YUN', 'JUN', 'YUN', 'ZA', 'ZAI', 'ZAN', | ||
'YUN', 'ZA', 'ZAI', 'ZAN', | ||
'ZANG', 'ZAO', 'ZE', 'ZEI', 'ZEN', 'ZENG', | ||
'ZHA', 'ZHAI', 'ZHAN', 'ZHANG', 'CHANG', 'ZHANG', | ||
'ZHAO', 'ZHE', 'ZHEN', 'ZHENG', 'ZHEN', 'ZHENG', 'ZHI', 'SHI', // add 帧 | ||
'ZHI', 'ZHONG', 'ZHOU', 'ZHU', 'ZHUA', 'ZHUAI', | ||
'ZHA', 'ZHAI', 'ZHAN', 'ZHANG', | ||
'ZHAO', 'ZHE', 'ZHEN', 'ZHENG', 'ZHI', 'ZHONG', 'ZHOU', 'ZHU', 'ZHUA', 'ZHUAI', | ||
'ZHUAN', 'ZHUANG', 'ZHUI', 'ZHUN', 'ZHUO', 'ZI', | ||
'ZONG', 'ZOU', 'ZU', 'ZUAN', 'ZUI', 'ZUN', | ||
'ZUO', '', 'SHAN', '' | ||
'ZUO', '' | ||
] | ||
// Separate from UNIHANS & PINYINS. | ||
// So PINYINS are completely of alphabetical order, and no duplicate pinyin. | ||
const EXCEPTIONS = { | ||
'\u66fe': 'ZENG', // CENG 曾 | ||
'\u6c88': 'SHEN', // CHEN 沈 | ||
'\u55f2': 'DIA', // DIE 嗲 | ||
'\u78a1': 'ZHOU', // DU 碡 | ||
'\u8052': 'GUO', // GUA 聒 | ||
'\u7094': 'QUE', // GUI 炔 | ||
'\u86b5': 'KE', // HE 蚵 | ||
'\u7809': 'HUA', // HUO 砉 | ||
'\u5b24': 'MO', // MA 嬤 | ||
'\u5b37': 'MO', // MA 嬷 | ||
'\u8e52': 'PAN', // MAN 蹒 | ||
'\u8e4a': 'XI', // QI 蹊 | ||
'\u4e2c': 'PAN', // QIANG 丬 | ||
'\u9730': 'XIAN', // SAN 霰 | ||
'\u8398': 'XIN', // SHEN 莘 | ||
'\u8c49': 'CHI', // SHI 豉 | ||
'\u9967': 'XING', // TANG 饧 | ||
'\u7b60': 'JUN', // YUN 筠 | ||
'\u957f': 'CHANG', // ZHANG 长 | ||
'\u5e27': 'ZHEN', // ZHENG 帧 | ||
'\u5cd9': 'SHI', // ZHI 峙 | ||
'\u90cd': 'NA', | ||
'\u828e': 'XIONG', | ||
'\u8c01': 'SHUI' | ||
} | ||
module.exports = { | ||
PINYINS, | ||
UNIHANS | ||
UNIHANS, | ||
EXCEPTIONS | ||
} |
'use strict' | ||
const DICT = require('./dict') | ||
const UNIHANS = DICT.UNIHANS | ||
const PINYINS = DICT.PINYINS | ||
@@ -17,2 +15,14 @@ const FIRST_PINYIN_UNIHAN = '\u963F' | ||
function patchDict (patchers) { | ||
if (!patchers) return | ||
if (typeof patchers === 'function') { | ||
patchers = [patchers] | ||
} | ||
if (patchers.forEach) { | ||
patchers.forEach(p => { | ||
typeof p === 'function' && p(DICT) | ||
}) | ||
} | ||
} | ||
function isSupported (force) { | ||
@@ -32,2 +42,6 @@ if (!force && supported !== null) { | ||
function genToken (ch) { | ||
// Access DICT here, give the chance to patch DICT. | ||
const UNIHANS = DICT.UNIHANS | ||
const PINYINS = DICT.PINYINS | ||
const EXCEPTIONS = DICT.EXCEPTIONS | ||
const token = { | ||
@@ -37,2 +51,9 @@ source: ch | ||
// First check EXCEPTIONS map, then search with UNIHANS table. | ||
if (ch in EXCEPTIONS) { | ||
token.type = PINYIN | ||
token.target = EXCEPTIONS[ch] | ||
return token | ||
} | ||
let offset = -1 | ||
@@ -115,2 +136,3 @@ let cmp | ||
parse, | ||
patchDict, | ||
convertToPinyin (str, separator, lowerCase) { | ||
@@ -117,0 +139,0 @@ return parse(str).map(v => { |
const assert = require('assert') | ||
const PinYin = require('../src') | ||
const { polyphone, common } = require('./hanziDict') | ||
let PinYin | ||
describe('PinYin', () => { | ||
before(done => { | ||
// Dynamically load lib | ||
if (typeof window === 'object' && window.window === window) { | ||
PinYin = require('../src/browser') | ||
} else { | ||
PinYin = require('../src/index') | ||
} | ||
done() | ||
}) | ||
describe('#isSupported()', () => { | ||
@@ -11,2 +21,23 @@ it('should return true when supported', () => { | ||
}) | ||
describe('#patchDict()', () => { | ||
it('should patch dict correctly', () => { | ||
let oriDict | ||
let oriPINYINS | ||
PinYin.patchDict(dict => { | ||
oriDict = dict | ||
oriPINYINS = dict.PINYINS | ||
}) | ||
assert.doesNotThrow(PinYin.patchDict) | ||
PinYin.patchDict([ | ||
dict => { | ||
assert(oriDict === dict) | ||
dict.PINYINS = ['hi'] | ||
}, | ||
dict => { | ||
assert.deepEqual(oriDict.PINYINS, ['hi']) | ||
dict.PINYINS = oriPINYINS | ||
} | ||
]) | ||
}) | ||
}) | ||
describe('#parse()', () => { | ||
@@ -13,0 +44,0 @@ it('should throw when argument is not string', () => { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 3 instances in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
116090
28
2068
97
27
3