forked from Tencent/APIJSON
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStringUtil.js
More file actions
92 lines (82 loc) · 1.69 KB
/
StringUtil.js
File metadata and controls
92 lines (82 loc) · 1.69 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/**获取string,为null则返回''
* @param s
* @return
*/
function getString(s) {
return s == null ? '' : s;
}
/**获取去掉前后空格后的string,为null则返回''
* @param s
* @return
*/
function getTrimmedString(s) {
return this.getString(s).trim();
}
/**获取去掉所有空格后的string,为null则返回''
* @param s
* @return
*/
function getNoBlankString(s) {
return this.getString(s).replace('\\s', '');
}
/**判断字符是否为空
* @param s
* @param trim
* @return
*/
function isEmpty(s, trim) {
if (s == null) {
return true;
}
if (trim) {
s = s.trim();
}
if (s == '') {
return true;
}
return false;
}
/**添加后缀
* @param key
* @param suffix
* @return key + suffix,第一个字母小写
*/
function addSuffix(key, suffix) {
key = this.getNoBlankString(key);
if (key == '') {
return this.firstCase(suffix);
}
return this.firstCase(key) + this.firstCase(suffix, true);
}
/**首字母大写或小写
* @param key
* @param upper
* @return
*/
function firstCase(key, upper) {
key = this.getString(key);
if (key == '') {
return '';
}
const first = key.substring(0, 1);
key = (upper ? first.toUpperCase() : first.toLowerCase()) + key.substring(1, key.length);
return key;
}
/**全部大写
* @param s
* @param trim
* @return
*/
function toUpperCase(s, trim) {
s = trim ? this.getTrimmedString(s) : this.getString(s);
return s.toUpperCase();
}
/**全部小写
* @param s
* @return
*/
function toLowerCase(s, trim) {
s = trim ? this.getTrimmedString(s) : this.getString(s);
return s.toLowerCase();
}
//校正(自动补全等)字符串>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>