-
Notifications
You must be signed in to change notification settings - Fork 691
/
pinyin.js
50 lines (46 loc) · 1.14 KB
/
pinyin.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import pinyin from 'pinyin';
const tools = require('./store/tools').state();
function group(arr) {
let results = [];
let result = [];
function doExchange(arr, index) {
for (let i = 0; i < arr[index].length; i++) {
result[index] = arr[index][i];
if (index != arr.length - 1) {
doExchange(arr, index + 1);
} else {
results.push(result.join(''));
}
}
}
doExchange(arr, 0);
return results;
}
let toolName = [];
tools
.map(t => {
return t.list;
})
.forEach(t => {
t.forEach(n => {
toolName.push(n.name);
});
});
const toolPinyin = {};
toolName.forEach(name => {
toolPinyin[name] = {
first: group(
pinyin(name.replace(/\s/g, '').toLowerCase(), {
style: pinyin.STYLE_FIRST_LETTER,
heteronym: true
})
),
pinyin: group(
pinyin(name.replace(/\s/g, '').toLowerCase(), {
style: pinyin.STYLE_NORMAL,
heteronym: true
})
)
};
});
export default toolPinyin;