Skip to content

Commit e829bf7

Browse files
committed
过滤虚词..
1 parent 570b970 commit e829bf7

File tree

7 files changed

+52
-20
lines changed

7 files changed

+52
-20
lines changed

CodeVar.alfredworkflow

802 KB
Binary file not shown.

Configuration/variableFilter.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/**
2+
* 该文件名- variableFilter
3+
* 编码作者- 许道龙
4+
* 创建日期- 2016/12/13 16:23
5+
* 作者邮箱- xudaolong@vip.qq.com
6+
* 作者博客- http://xudaolong.github.io/
7+
* 修改时间-
8+
* 修改备注-
9+
* 编码内容-
10+
*/
11+
12+
'use strict';
13+
14+
const config = require('./variableGlobale.js');
15+
const diff = require('lodash.difference');
16+
const union = require('lodash.union');
17+
18+
module.exports = {
19+
run:function (s) {
20+
let strArr = s.toLowerCase();
21+
return diff(strArr.split(' '),union(config.filter.prep,config.filter.prefix,config.filter.suffix,config.filter.verb));
22+
}
23+
};

Configuration/variableGlobale.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,19 @@ module.exports = {
2424
version: '1.1',
2525
q: alfy.input
2626
}
27+
},
28+
filter:{
29+
prep:[
30+
'and','or','the','a','at','of'
31+
],
32+
prefix:[
33+
34+
],
35+
suffix:[
36+
'ing','ed','ly'
37+
],
38+
verb:[
39+
'was'
40+
]
2741
}
2842
};

Configuration/variableStyle.js

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
'use strict';
1313

1414
const alfy = require('alfy');
15-
const without = require('lodash.without');
15+
const filter = require('./variableFilter.js');
1616

1717
module.exports = {
1818
core: function (api, params, style) {
@@ -58,9 +58,8 @@ module.exports = {
5858
}
5959
});
6060
},
61-
bigHump: function bigHump(s) {
62-
// 过滤冠词,有需要的自己添加咯
63-
let strArr = without(s.split(' '), 'the', 'The');
61+
bigHump: function (s) {
62+
let strArr = filter.run(s);
6463
// 首单词首小写
6564
strArr[0] = strArr[0].toLowerCase();
6665
strArr[0] = strArr[0].charAt(0).toUpperCase() + strArr[0].substring(1);
@@ -70,9 +69,8 @@ module.exports = {
7069
}
7170
return strArr.join('');
7271
},
73-
hump: function hump(str) {
74-
// 过滤冠词,有需要的自己添加咯
75-
let strArr = without(str.split(' '), 'the', 'The');
72+
hump: function (s) {
73+
let strArr = filter.run(s);
7674
// 首单词首小写
7775
strArr[0] = strArr[0].toLowerCase();
7876
// 单词首字母大写
@@ -81,18 +79,15 @@ module.exports = {
8179
}
8280
return strArr.join('');
8381
},
84-
namedConst: function hump(str) {
85-
// 过滤冠词,有需要的自己添加咯
86-
let strArr = without(str.split(' '), 'the', 'The');
82+
namedConst: function (s) {
83+
let strArr = filter.run(s);
8784
for (let i = 0; i < strArr.length; i++) {
8885
strArr[i] = strArr[i].toUpperCase();
8986
}
9087
return strArr.join('_');
9188
},
92-
underline: function hump(str) {
93-
// 过滤冠词,有需要的自己添加咯
94-
let strArr = without(str.split(' '), 'the', 'The');
95-
89+
underline: function (s) {
90+
let strArr = filter.run(s);
9691
for (let i = 0; i < strArr.length; i++) {
9792
strArr[i] = strArr[i].toLowerCase();
9893
}

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@
77

88
# 开发趋向
99

10-
- 使用标准的缩写(如 rpt)。
11-
- 去掉虚词 and,or,the。
10+
- 使用标准的缩写(如 rpt)。✔️
11+
- 去掉虚词 and,or,the。✔️
1212
- 使用名字中的每一个重要单词,最多不超过3个。❎
1313
- 去掉无用的后缀(如 ing、ed 等)。❎
14-
- 确保不要改变变量的含义。
14+
- 确保不要改变变量的含义。✔️
1515
- 不要从每个单词中删除一个字符的方式来缩写。❎
16-
- 缩写要一致:如果将 function 缩写成 func。那么将整个项目里,最好都统一使用这种缩写。
16+
- 缩写要一致:如果将 function 缩写成 func。那么将整个项目里,最好都统一使用这种缩写。✔️
1717

1818
# 效果
1919
> 小驼峰命名法:xt

index.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111

1212
'use strict';
1313

14-
const alfy = require('alfy');
15-
const without = require('lodash.without');
1614
const config = require('./Configuration/variableGlobale.js');
1715
const style = require('./Configuration/variableStyle.js');
1816

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
"alfy": "^0.6.0"
1313
},
1414
"dependencies": {
15+
"lodash.difference": "^4.5.0",
16+
"lodash.union": "^4.6.0",
1517
"lodash.without": "^4.4.0"
1618
}
1719
}

0 commit comments

Comments
 (0)