-
Notifications
You must be signed in to change notification settings - Fork 424
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
318 additions
and
87 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
https://github.com/liu11hao11/pinyin_js | ||
|
||
# pinyin_js | ||
中文转拼音 | ||
##安装 | ||
``` | ||
npm install | ||
``` | ||
|
||
|
||
##汉字转化成带音节的拼音 | ||
```javascript | ||
var pinyin=require("pinyin_js"); | ||
console.log(pinyin.pinyin("你好"," ")); | ||
//输出结果是nǐ hǎo | ||
``` | ||
|
||
##汉字转化成不带音节的拼音 | ||
```javascript | ||
var pinyin=require("pinyin_js"); | ||
console.log(pinyin.pinyinWithOutYin("你好"," ")); | ||
//输出结果是ni hao | ||
``` | ||
|
||
##判断是否是汉字 | ||
```javascript | ||
var pinyin=require("pinyin_js"); | ||
console.log(pinyin.isChineseWord("你好"));//true | ||
console.log(pinyin.isChineseWord("!你好",false));//true | ||
console.log(pinyin.isChineseWord("!你好",true));//第二个参数:true是严格模式,默认为严格模式 | ||
//false | ||
``` | ||
|
||
##首字母排序 | ||
|
||
```javascript | ||
var pinyin=require("pinyin_js"); | ||
var users = [ | ||
{ 'user': '张三丰', 'age': 40 }, | ||
{ 'user': '123', 'age': 48 }, | ||
{ 'user': '张三', 'age': 48 }, | ||
{ 'user': '李四', 'age': 36 }, | ||
{ 'user': '张三炮', 'age': 34 } | ||
]; | ||
var sortResult = pinyin.sort(users, "user"); | ||
console.log(sortResult) | ||
/*[ { user: '123', age: 48 }, | ||
{ user: '李四', age: 36 }, | ||
{ user: '张三', age: 48 }, | ||
{ user: '张三丰', age: 40 }, | ||
{ user: '张三炮', age: 34 } ]*/ | ||
|
||
``` |
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/** | ||
* Created by Alex on 2016/3/7. | ||
*/ | ||
var hzpy = require("./hanziPinyin").hzpy; | ||
var hzpyWithOutYin = require("./hanziPinyinWithoutYin").hzpy; | ||
var _ = require("lodash"); | ||
|
||
function pinyin(word,splitStr) { | ||
splitStr = splitStr === undefined ? ' ' : splitStr; | ||
var str = ''; | ||
var s; | ||
for (var i = 0; i < word.length; i++) { | ||
if (hzpy.indexOf(word.charAt(i)) != -1 && word.charCodeAt(i) > 200) { | ||
s = 1; | ||
while (hzpy.charAt(hzpy.indexOf(word.charAt(i)) + s) != ",") { | ||
str += hzpy.charAt(hzpy.indexOf(word.charAt(i)) + s); | ||
s++; | ||
} | ||
str += splitStr; | ||
} | ||
else { | ||
str += word.charAt(i); | ||
} | ||
} | ||
return str; | ||
} | ||
|
||
//无声调的拼音 | ||
function pinyinWithOutYin(word,splitStr) { | ||
splitStr = splitStr === undefined ? ' ' : splitStr; | ||
var str = ''; | ||
var s; | ||
for (var i = 0; i < word.length; i++) { | ||
if (hzpyWithOutYin.indexOf(word.charAt(i)) != -1 && word.charCodeAt(i) > 200) { | ||
s = 1; | ||
while (hzpyWithOutYin.charAt(hzpyWithOutYin.indexOf(word.charAt(i)) + s) != ",") { | ||
str += hzpyWithOutYin.charAt(hzpyWithOutYin.indexOf(word.charAt(i)) + s); | ||
s++; | ||
} | ||
str +=splitStr; | ||
} | ||
else { | ||
str += word.charAt(i); | ||
} | ||
} | ||
|
||
return str; | ||
} | ||
|
||
function isChineseWord(word, modle) { | ||
if (!modle) { | ||
//modle为false是非严格中文!默认是严格中文 | ||
modle = true; | ||
} | ||
var str = ''; | ||
var isChinese = false; | ||
for (var i = 0; i < word.length; i++) { | ||
if (hzpy.indexOf(word.charAt(i)) != -1 && word.charCodeAt(i) > 200) { | ||
isChinese = true; | ||
} | ||
else { | ||
if (modle) { | ||
return false; | ||
} | ||
} | ||
} | ||
return isChinese; | ||
} | ||
|
||
function sort(array, key) { | ||
return _.sortBy(array, [function (o) { | ||
return pinyinWithOutYin(o[key],""); | ||
}]); | ||
} | ||
|
||
module.exports = { | ||
pinyin: pinyin, | ||
pinyinWithOutYin: pinyinWithOutYin, | ||
isChineseWord: isChineseWord, | ||
sort: sort | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,85 +1,86 @@ | ||
@font-face { | ||
font-family: "ch-icon"; | ||
src: url('./fonts/ch-icon.eot'); | ||
src: url('./fonts/ch-icon.eot?#iefix') format('eot'), | ||
url('./fonts/ch-icon.woff2') format('woff2'), | ||
url('./fonts/ch-icon.woff') format('woff'), | ||
url('./fonts/ch-icon.ttf') format('truetype'), | ||
url('./fonts/ch-icon.svg#ch-icon') format('svg'); | ||
font-weight: normal; | ||
font-style: normal; | ||
} | ||
|
||
.ch-icon:before { | ||
display: inline-block; | ||
font-family: "ch-icon"; | ||
font-style: normal; | ||
font-weight: normal; | ||
//line-height: 1; | ||
-webkit-font-smoothing: antialiased; | ||
-moz-osx-font-smoothing: grayscale; | ||
} | ||
|
||
.ch-icon-list:before { content: "\EA03" } | ||
.ch-icon-check:before { content: "\EA04" } | ||
.ch-icon-square:before { content: "\EA09" } | ||
.ch-icon-bold:before { content: "\EA0A" } | ||
.ch-icon-code:before { content: "\EA0B" } | ||
.ch-icon-color:before { content: "\EA0C" } | ||
.ch-icon-header:before { content: "\EA0D" } | ||
.ch-icon-image:before { content: "\EA0E" } | ||
.ch-icon-italic:before { content: "\EA0F" } | ||
.ch-icon-link:before { content: "\EA10" } | ||
.ch-icon-ol:before { content: "\EA11" } | ||
.ch-icon-size:before { content: "\EA12" } | ||
.ch-icon-strike:before { content: "\EA13" } | ||
.ch-icon-table:before { content: "\EA14" } | ||
.ch-icon-ul:before { content: "\EA15" } | ||
.ch-icon-underline:before { content: "\EA16" } | ||
.ch-icon-word:before { content: "\EA17" } | ||
.ch-icon-blockquote:before { content: "\EA18" } | ||
.ch-icon-font:before { content: "\EA19" } | ||
.ch-icon-insertClass:before { content: "\EA1F" } | ||
.ch-icon-insertFlow:before { content: "\EA20" } | ||
.ch-icon-insertFormula:before { content: "\EA21" } | ||
.ch-icon-insertGantt:before { content: "\EA22" } | ||
.ch-icon-insertGraph:before { content: "\EA23" } | ||
.ch-icon-insertPie:before { content: "\EA24" } | ||
.ch-icon-insertSeq:before { content: "\EA25" } | ||
.ch-icon-insertState:before { content: "\EA26" } | ||
.ch-icon-line:before { content: "\EA27" } | ||
.ch-icon-preview:before { content: "\EA28" } | ||
.ch-icon-previewClose:before { content: "\EA29" } | ||
.ch-icon-toc:before { content: "\EA2A" } | ||
.ch-icon-sub:before { content: "\EA2D" } | ||
.ch-icon-sup:before { content: "\EA2E" } | ||
.ch-icon-h1:before { content: "\EA2F" } | ||
.ch-icon-h2:before { content: "\EA30" } | ||
.ch-icon-h3:before { content: "\EA31" } | ||
.ch-icon-h4:before { content: "\EA32" } | ||
.ch-icon-h5:before { content: "\EA33" } | ||
.ch-icon-h6:before { content: "\EA34" } | ||
.ch-icon-video:before { content: "\EA35" } | ||
.ch-icon-insert:before { content: "\EA36" } | ||
.ch-icon-little_table:before { content: "\EA37" } | ||
.ch-icon-pdf:before { content: "\EA38" } | ||
.ch-icon-checklist:before { content: "\EA39" } | ||
.ch-icon-close:before { content: "\EA40" } | ||
.ch-icon-fullscreen:before { content: "\EA41" } | ||
.ch-icon-minscreen:before { content: "\EA42" } | ||
.ch-icon-insertChart:before { content: "\EA43" } | ||
.ch-icon-question:before { content: "\EA44" } | ||
.ch-icon-settings:before { content: "\EA45" } | ||
.ch-icon-ok:before { content: "\EA46" } | ||
.ch-icon-br:before { content: "\EA47" } | ||
.ch-icon-normal:before { content: "\EA48" } | ||
.ch-icon-undo:before { content: "\EA49" } | ||
.ch-icon-redo:before { content: "\EA50" } | ||
.ch-icon-copy:before { content: "\EA51" } | ||
.ch-icon-phone:before { content: "\EA52" } | ||
.ch-icon-cherry-table-delete:before { content: "\EA53" } | ||
.ch-icon-cherry-table-insert-bottom:before { content: "\EA54" } | ||
.ch-icon-cherry-table-insert-left:before { content: "\EA55" } | ||
.ch-icon-cherry-table-insert-right:before { content: "\EA56" } | ||
.ch-icon-cherry-table-insert-top:before { content: "\EA57" } | ||
.ch-icon-sort-s:before { content: "\EA58" } | ||
@font-face { | ||
font-family: "ch-icon"; | ||
src: url('./fonts/ch-icon.eot'); | ||
src: url('./fonts/ch-icon.eot?#iefix') format('eot'), | ||
url('./fonts/ch-icon.woff2') format('woff2'), | ||
url('./fonts/ch-icon.woff') format('woff'), | ||
url('./fonts/ch-icon.ttf') format('truetype'), | ||
url('./fonts/ch-icon.svg#ch-icon') format('svg'); | ||
font-weight: normal; | ||
font-style: normal; | ||
} | ||
|
||
.ch-icon:before { | ||
display: inline-block; | ||
font-family: "ch-icon"; | ||
font-style: normal; | ||
font-weight: normal; | ||
//line-height: 1; | ||
-webkit-font-smoothing: antialiased; | ||
-moz-osx-font-smoothing: grayscale; | ||
} | ||
|
||
.ch-icon-pinyin:before { content: "\EA59" } | ||
.ch-icon-list:before { content: "\EA03" } | ||
.ch-icon-check:before { content: "\EA04" } | ||
.ch-icon-square:before { content: "\EA09" } | ||
.ch-icon-bold:before { content: "\EA0A" } | ||
.ch-icon-code:before { content: "\EA0B" } | ||
.ch-icon-color:before { content: "\EA0C" } | ||
.ch-icon-header:before { content: "\EA0D" } | ||
.ch-icon-image:before { content: "\EA0E" } | ||
.ch-icon-italic:before { content: "\EA0F" } | ||
.ch-icon-link:before { content: "\EA10" } | ||
.ch-icon-ol:before { content: "\EA11" } | ||
.ch-icon-size:before { content: "\EA12" } | ||
.ch-icon-strike:before { content: "\EA13" } | ||
.ch-icon-table:before { content: "\EA14" } | ||
.ch-icon-ul:before { content: "\EA15" } | ||
.ch-icon-underline:before { content: "\EA16" } | ||
.ch-icon-word:before { content: "\EA17" } | ||
.ch-icon-blockquote:before { content: "\EA18" } | ||
.ch-icon-font:before { content: "\EA19" } | ||
.ch-icon-insertClass:before { content: "\EA1F" } | ||
.ch-icon-insertFlow:before { content: "\EA20" } | ||
.ch-icon-insertFormula:before { content: "\EA21" } | ||
.ch-icon-insertGantt:before { content: "\EA22" } | ||
.ch-icon-insertGraph:before { content: "\EA23" } | ||
.ch-icon-insertPie:before { content: "\EA24" } | ||
.ch-icon-insertSeq:before { content: "\EA25" } | ||
.ch-icon-insertState:before { content: "\EA26" } | ||
.ch-icon-line:before { content: "\EA27" } | ||
.ch-icon-preview:before { content: "\EA28" } | ||
.ch-icon-previewClose:before { content: "\EA29" } | ||
.ch-icon-toc:before { content: "\EA2A" } | ||
.ch-icon-sub:before { content: "\EA2D" } | ||
.ch-icon-sup:before { content: "\EA2E" } | ||
.ch-icon-h1:before { content: "\EA2F" } | ||
.ch-icon-h2:before { content: "\EA30" } | ||
.ch-icon-h3:before { content: "\EA31" } | ||
.ch-icon-h4:before { content: "\EA32" } | ||
.ch-icon-h5:before { content: "\EA33" } | ||
.ch-icon-h6:before { content: "\EA34" } | ||
.ch-icon-video:before { content: "\EA35" } | ||
.ch-icon-insert:before { content: "\EA36" } | ||
.ch-icon-little_table:before { content: "\EA37" } | ||
.ch-icon-pdf:before { content: "\EA38" } | ||
.ch-icon-checklist:before { content: "\EA39" } | ||
.ch-icon-close:before { content: "\EA40" } | ||
.ch-icon-fullscreen:before { content: "\EA41" } | ||
.ch-icon-minscreen:before { content: "\EA42" } | ||
.ch-icon-insertChart:before { content: "\EA43" } | ||
.ch-icon-question:before { content: "\EA44" } | ||
.ch-icon-settings:before { content: "\EA45" } | ||
.ch-icon-ok:before { content: "\EA46" } | ||
.ch-icon-br:before { content: "\EA47" } | ||
.ch-icon-normal:before { content: "\EA48" } | ||
.ch-icon-undo:before { content: "\EA49" } | ||
.ch-icon-redo:before { content: "\EA50" } | ||
.ch-icon-copy:before { content: "\EA51" } | ||
.ch-icon-phone:before { content: "\EA52" } | ||
.ch-icon-cherry-table-delete:before { content: "\EA53" } | ||
.ch-icon-cherry-table-insert-bottom:before { content: "\EA54" } | ||
.ch-icon-cherry-table-insert-left:before { content: "\EA55" } | ||
.ch-icon-cherry-table-insert-right:before { content: "\EA56" } | ||
.ch-icon-cherry-table-insert-top:before { content: "\EA57" } | ||
.ch-icon-sort-s:before { content: "\EA58" } |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.