Skip to content

Commit 09b0129

Browse files
committed
规范结构 入口 和 代码风格
1 parent d175c7c commit 09b0129

File tree

8 files changed

+142
-116
lines changed

8 files changed

+142
-116
lines changed

CodeVar.alfredworkflow

783 KB
Binary file not shown.

Configuration/variableGlobale.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/**
2+
* 该文件名- variableGlobale
3+
* 编码作者- 许道龙
4+
* 创建日期- 2016/12/13 13:22
5+
* 作者邮箱- xudaolong@vip.qq.com
6+
* 作者博客- http://xudaolong.github.io/
7+
* 修改时间-
8+
* 修改备注-
9+
* 编码内容-
10+
*/
11+
12+
'use strict';
13+
14+
const alfy = require('alfy');
15+
16+
module.exports = {
17+
youDaoApi: 'http://fanyi.youdao.com/openapi.do',
18+
params : {
19+
query: {
20+
keyfrom: 'CoderVar',
21+
key: '802458398',
22+
type: 'data',
23+
doctype: 'json',
24+
version: '1.1',
25+
q: alfy.input
26+
}
27+
}
28+
};

Configuration/variableStyle.js

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/**
2+
* 该文件名- variableStyle
3+
* 编码作者- 许道龙
4+
* 创建日期- 2016/12/13 13:37
5+
* 作者邮箱- xudaolong@vip.qq.com
6+
* 作者博客- http://xudaolong.github.io/
7+
* 修改时间-
8+
* 修改备注-
9+
* 编码内容-
10+
*/
11+
12+
'use strict';
13+
14+
const without = require('lodash.without');
15+
16+
module.exports = {
17+
bigHump: function bigHump(s) {
18+
// 过滤冠词,有需要的自己添加咯
19+
let strArr = without(s.split(' '), 'the', 'The');
20+
// 首单词首小写
21+
strArr[0] = strArr[0].toLowerCase();
22+
strArr[0] = strArr[0].charAt(0).toUpperCase() + strArr[0].substring(1);
23+
// 单词首字母大写
24+
for (let i = 1; i < strArr.length; i++) {
25+
strArr[i] = strArr[i].charAt(0).toUpperCase() + strArr[i].substring(1);
26+
}
27+
return strArr.join('');
28+
},
29+
hump: function hump(str) {
30+
// 过滤冠词,有需要的自己添加咯
31+
let strArr = without(str.split(' '), 'the', 'The');
32+
// 首单词首小写
33+
strArr[0] = strArr[0].toLowerCase();
34+
// 单词首字母大写
35+
for (let i = 1; i < strArr.length; i++) {
36+
strArr[i] = strArr[i].charAt(0).toUpperCase() + strArr[i].substring(1);
37+
}
38+
return strArr.join('');
39+
},
40+
namedConst: function hump(str) {
41+
// 过滤冠词,有需要的自己添加咯
42+
let strArr = without(str.split(' '), 'the', 'The');
43+
for (let i = 0; i < strArr.length; i++) {
44+
strArr[i] = strArr[i].toUpperCase();
45+
}
46+
return strArr.join('_');
47+
},
48+
underline: function hump(str) {
49+
// 过滤冠词,有需要的自己添加咯
50+
let strArr = without(str.split(' '), 'the', 'The');
51+
52+
for (let i = 0; i < strArr.length; i++) {
53+
strArr[i] = strArr[i].toLowerCase();
54+
}
55+
return strArr.join('_');
56+
}
57+
};

NamedConstant.js

Lines changed: 13 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -13,28 +13,10 @@
1313

1414
const alfy = require('alfy');
1515
const without = require('lodash.without');
16+
const config = require('./Configuration/variableGlobale.js');
17+
const style = require('./Configuration/variableStyle.js');
1618

17-
function hump(str){
18-
// 过滤冠词,有需要的自己添加咯
19-
let strArr=without(str.split(' '),'the','The');
20-
for(let i=0;i<strArr.length;i++){
21-
strArr[i]=strArr[i].toUpperCase();
22-
}
23-
return strArr.join('_');
24-
}
25-
26-
alfy.fetch('http://fanyi.youdao.com/openapi.do', {
27-
query: {
28-
// 暂时借用别人的
29-
keyfrom: 'whyliam',
30-
key: '1331254833',
31-
type: 'data',
32-
doctype: 'json',
33-
version: '1.1',
34-
q: alfy.input
35-
}
36-
}).then(result => {
37-
19+
alfy.fetch(config.youDaoApi, config.params).then(result => {
3820
if (result.errorCode == 0) {
3921
//结果
4022
let result_value = [];
@@ -45,9 +27,9 @@ alfy.fetch('http://fanyi.youdao.com/openapi.do', {
4527
for (let i = 0, len = result_translation.length; i < len; i++) {
4628
if (reg.test(result_translation[i])) {
4729
result_value.push({
48-
title: hump(result_translation[i]),
30+
title: style.namedConst(result_translation[i]),
4931
subtitle: `标准翻译 => ${result_translation[i]}`,
50-
arg: hump(result_translation[i]),
32+
arg: style.namedConst(result_translation[i]),
5133
});
5234
}
5335
}
@@ -59,16 +41,22 @@ alfy.fetch('http://fanyi.youdao.com/openapi.do', {
5941
for (let j = 0, ilen = result_web[i].value.length; j < ilen; j++) {
6042
if (reg.test(result_web[i].value[j])) {
6143
result_value.push({
62-
title: hump(result_web[i].value[j]),
44+
title: style.namedConst(result_web[i].value[j]),
6345
subtitle: `网络翻译 => ${result_web[i].value[j]}`,
64-
arg: hump(result_web[i].value[j]),
46+
arg: style.namedConst(result_web[i].value[j]),
6547
});
6648
}
6749
}
6850
}
6951
}
7052

7153
alfy.output(result_value);
54+
} else {
55+
alfy.output([{
56+
title: '抱歉',
57+
subtitle: `无相关记录`,
58+
arg: 'error',
59+
}]);
7260
}
7361
})
7462
;

bigHump.js

Lines changed: 16 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -13,66 +13,50 @@
1313

1414
const alfy = require('alfy');
1515
const without = require('lodash.without');
16+
const config = require('./Configuration/variableGlobale.js');
17+
const style = require('./Configuration/variableStyle.js');
1618

17-
function hump(str){
18-
// 过滤冠词,有需要的自己添加咯
19-
let strArr=without(str.split(' '),'the','The');
20-
// 首单词首小写
21-
strArr[0] = strArr[0].toLowerCase();
22-
strArr[0] = strArr[0].charAt(0).toUpperCase()+strArr[0].substring(1);
23-
// 单词首字母大写
24-
for(let i=1;i<strArr.length;i++){
25-
strArr[i]=strArr[i].charAt(0).toUpperCase()+strArr[i].substring(1);
26-
}
27-
return strArr.join('');
28-
}
29-
30-
alfy.fetch('http://fanyi.youdao.com/openapi.do', {
31-
query: {
32-
// 暂时借用别人的
33-
keyfrom: 'whyliam',
34-
key: '1331254833',
35-
type: 'data',
36-
doctype: 'json',
37-
version: '1.1',
38-
q: alfy.input
39-
}
40-
}).then(result => {
19+
alfy.fetch(config.youDaoApi, config.params).then(result => {
4120

4221
if (result.errorCode == 0) {
22+
4323
//结果
4424
let result_value = [];
4525
// 过滤中文
4626
let reg = /^[a-zA-Z ]/;
27+
4728
// 标准翻译结果 : translation
4829
let result_translation = result.translation;
4930
for (let i = 0, len = result_translation.length; i < len; i++) {
5031
if (reg.test(result_translation[i])) {
5132
result_value.push({
52-
title: hump(result_translation[i]),
33+
title: style.bigHump(result_translation[i]),
5334
subtitle: `标准翻译 => ${result_translation[i]}`,
54-
arg: hump(result_translation[i]),
35+
arg: style.bigHump(result_translation[i]),
5536
});
5637
}
5738
}
58-
5939
// 网络翻译 : web
6040
if (result.web) {
6141
let result_web = result.web;
6242
for (let i = 0, len = result_web.length; i < len; i++) {
6343
for (let j = 0, ilen = result_web[i].value.length; j < ilen; j++) {
6444
if (reg.test(result_web[i].value[j])) {
6545
result_value.push({
66-
title: hump(result_web[i].value[j]),
46+
title: style.bigHump(result_web[i].value[j]),
6747
subtitle: `网络翻译 => ${result_web[i].value[j]}`,
68-
arg: hump(result_web[i].value[j]),
48+
arg: style.bigHump(result_web[i].value[j]),
6949
});
7050
}
7151
}
7252
}
7353
}
74-
7554
alfy.output(result_value);
55+
} else {
56+
alfy.output([{
57+
title: '抱歉',
58+
subtitle: `无相关记录`,
59+
arg: 'error',
60+
}]);
7661
}
77-
})
78-
;
62+
});

index.js

Lines changed: 13 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -13,31 +13,10 @@
1313

1414
const alfy = require('alfy');
1515
const without = require('lodash.without');
16+
const config = require('./Configuration/variableGlobale.js');
17+
const style = require('./Configuration/variableStyle.js');
1618

17-
function hump(str){
18-
// 过滤冠词,有需要的自己添加咯
19-
let strArr=without(str.split(' '),'the','The');
20-
// 首单词首小写
21-
strArr[0] = strArr[0].toLowerCase();
22-
// 单词首字母大写
23-
for(let i=1;i<strArr.length;i++){
24-
strArr[i]=strArr[i].charAt(0).toUpperCase()+strArr[i].substring(1);
25-
}
26-
return strArr.join('');
27-
}
28-
29-
alfy.fetch('http://fanyi.youdao.com/openapi.do', {
30-
query: {
31-
// 暂时借用别人的
32-
keyfrom: 'whyliam',
33-
key: '1331254833',
34-
type: 'data',
35-
doctype: 'json',
36-
version: '1.1',
37-
q: alfy.input
38-
}
39-
}).then(result => {
40-
19+
alfy.fetch(config.youDaoApi, config.params).then(result => {
4120
if (result.errorCode == 0) {
4221
//结果
4322
let result_value = [];
@@ -48,30 +27,34 @@ alfy.fetch('http://fanyi.youdao.com/openapi.do', {
4827
for (let i = 0, len = result_translation.length; i < len; i++) {
4928
if (reg.test(result_translation[i])) {
5029
result_value.push({
51-
title: hump(result_translation[i]),
30+
title: style.hump(result_translation[i]),
5231
subtitle: `标准翻译 => ${result_translation[i]}`,
53-
arg: hump(result_translation[i]),
32+
arg: style.hump(result_translation[i]),
5433
});
5534
}
5635
}
57-
5836
// 网络翻译 : web
5937
if (result.web) {
6038
let result_web = result.web;
6139
for (let i = 0, len = result_web.length; i < len; i++) {
6240
for (let j = 0, ilen = result_web[i].value.length; j < ilen; j++) {
6341
if (reg.test(result_web[i].value[j])) {
6442
result_value.push({
65-
title: hump(result_web[i].value[j]),
43+
title: style.hump(result_web[i].value[j]),
6644
subtitle: `网络翻译 => ${result_web[i].value[j]}`,
67-
arg: hump(result_web[i].value[j]),
45+
arg: style.hump(result_web[i].value[j]),
6846
});
6947
}
7048
}
7149
}
7250
}
73-
7451
alfy.output(result_value);
52+
} else {
53+
alfy.output([{
54+
title: '抱歉',
55+
subtitle: `无相关记录`,
56+
arg: 'error',
57+
}]);
7558
}
7659
})
7760
;

info.plist

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@
277277
<key>xpos</key>
278278
<integer>130</integer>
279279
<key>ypos</key>
280-
<integer>10</integer>
280+
<integer>20</integer>
281281
</dict>
282282
<key>8039E6FB-F0FA-419B-B00E-048A1DBA460A</key>
283283
<dict>
@@ -298,7 +298,7 @@
298298
<key>xpos</key>
299299
<integer>130</integer>
300300
<key>ypos</key>
301-
<integer>360</integer>
301+
<integer>350</integer>
302302
</dict>
303303
</dict>
304304
<key>webaddress</key>

0 commit comments

Comments
 (0)