-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUtils.html
230 lines (227 loc) · 7.16 KB
/
Utils.html
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Pattaya.Global.Utils</title>
<link rel="stylesheet" href="css/base.css" />
<link href="css/demo.css" type="text/css" rel="stylesheet"/>
<script type="text/javascript" src="js/jquery-1.7.js"></script>
<script type="text/javascript" src="js/global.js"></script>
</head>
<body>
<article class="layout">
<hgroup class="header">
<h1>Pattaya.Global.Utils</h1>
<h4>定义一系列小工具、小方法。各方法介绍如下:</h4>
</hgroup>
<ol>
<li class="cbox">
<h3 class="title">fixedEncodeURI(string str)</h3>
<div class="container">
<h4 class="subtitle">方法原型:</h4>
<div class="subcon">
<pre>
function fixedEncodeURI(str) {
return encodeURI(str).replace(/%5B/g, '[').replace(/%5D/g, ']');
}
</pre>
</div>
</div>
</li>
<li class="cbox">
<h3 class="title">fixedEncodeURIComponent(string str)</h3>
<div class="container">
<h4 class="subtitle">方法原型:</h4>
<div class="subcon example">
<pre>
function fixedEncodeURIComponent(str) {
return encodeURIComponent(str).replace(/!/g, '%21').replace(/'/g, '%27').replace(/\(/g, '%28').replace(/\)/g, '%29').replace(/\*/g, '%2A');
}
</pre>
</div>
</div>
</li>
<li class="cbox">
<h3 class="title">format(string str, {object} | params)</h3>
<div class="container">
<h4 class="subtitle">概述:</h4>
<div class="subcon">
用于字符串替换。待替换的数据有2中传参形式:一种是使用json格式数据, 一种是多个参数以字符串形式传入。
</div>
<h4 class="subtitle">Example:</h4>
<div class="subcon example">
<pre>
Pattaya.Global.Utils.format("{0} is a {1}", "It", "dog"); // return "It is a dog"
Pattaya.Global.Utils.format("{name} is a {thing}", {"name": "It", "thing": "dog"}); // return "It is a dog"
</pre>
</div>
</div>
</li>
<li class="cbox">
<h3 class="title">contains(source, target, funcCompare)</h3>
<div class="container">
<h4 class="subtitle">概述:</h4>
<div class="subcon">
判断原参数值是否包含目标参数值。source和target参数必须的。
</div>
<h4 class="subtitle">参数:</h4>
<ul class="subcon">
<li>
<b>source:</b>
<span>原参数值</span>
</li>
<li>
<b>target:</b>
<span>待比较的参数值</span>
</li>
<li>
<b>funcCompare:</b>
<span>自定义包含规则</span>
</li>
</ul>
<h4 class="subtitle">Example:</h4>
<div class="subcon example">
<pre>
Pattaya.Global.Utils.contains("12", 1); // return true;
Pattaya.Global.Utils.contains([1,2], 1); // return true;
Pattaya.Global.Utils.contains([1,2], 0); //return false;
Pattaya.Global.Utils.contains([1,2], 0, function(s, t){return s > t}); //return true;
</pre>
</div>
</div>
</li>
<li class="cbox">
<h3 class="title">firstOrUndefined(source, funcCompare)</h3>
<div class="container">
<h4 class="subtitle" >概述:</h4>
<div class="subcon">
根据匹配规则, 获取数组中第一个匹配到的元素。匹配到,则返回该匹配到的元素;没有匹配到,则返回undefined。
目前,source只支持数组类型
</div>
<h4 class="subtitle">参数:</h4>
<ul class="subcon">
<li>
<b>source:</b>
<span>待匹配数组</span>
</li>
<li>
<b>[funcCompare]:</b>
<span>自定义匹配规则</span>
</li>
</ul>
<h4 class="subtitle">Example:</h4>
<div class="subcon example">
<pre>
Pattaya.Global.Utils.firstOrUndefined([1, 2], function(v){return v == 1;}); // return 1;
Pattaya.Global.Utils.firstOrUndefined([1, 2], function(v){return v == 3;}); // return undefined;
</pre>
</div>
</div>
</li>
<li class="cbox">
<h3 class="title">find(source, funcCompare)</h3>
<div class="container">
<h4 class="subtitle">概述:</h4>
<div class="subcon">
类似于firstOrUndefined()方法,不同的是find()返回所有匹配到的元素,返回类型为Array,没有匹配到,则返回一个空Array。
目前,该方法只支持数组类型的匹配。source, funcCompare都是必须的参数。
</div>
<h4 class="subtitle">参数:</h4>
<ul class="subcon">
<li>
<b>source:</b>
<span>待匹配数组</span>
</li>
<li>
<b>funcCompare:</b>
<span>自定义匹配规则</span>
</li>
</ul>
<h4 class="subtitle">Example:</h4>
<div class="example subcon">
<pre>
Pattaya.Global.Utils.find([1, 2], function(v){return v > 0;}); // return [1, 2];
Pattaya.Global.Utils.find([1, 2], function(v){return v > 3;}); // return [];
</pre>
</div>
</div>
</li>
<li class="cbox">
<h3 class="title">cutString(str, len, endWith)</h3>
<div class="container">
<h4 class="subtitle">概述:</h4>
<div class="subcon">
将字符串剪切为需要的长度,字符串大于要求的长度,则以所设置的后缀结尾,
</div>
<h4 class="subtitle">参数:</h4>
<ul class="subcon">
<li>
<b class="lbl">str:</b>
<span class="con">待剪切字符串</span>
</li>
<li>
<b class="lbl">lei:</b>
<span class="con">剪切长度</span>
</li>
<li>
<b class="lbl">[endWith]:</b>
<span class="con">结尾后缀</span>
</li>
</ul>
<h4 class="subtitle">Example:</h4>
<div class="example subcon">
<pre>
Pattaya.Global.Utils.cutString("abcdefghigklmn", 5, "..."); // return "ab...";
Pattaya.Global.Utils.cutString("abc", 5, "..."); // return "abc";
</pre>
</div>
</div>
</li>
<li class="cbox">
<h3 class="title">encodeHtml(str)</h3>
<div class="container">
<h4 class="subtitle">概述:</h4>
<div class="subcon">
对字符串进行html的特殊字符转义
</div>
<h4 class="subtitle">参数:</h4>
<ul class="subcon">
<li>
<b class="lbl">str:</b>
<span class="con">待转义字符串</span>
</li>
</ul>
<h4 class="subtitle">Example:</h4>
<div class="example subcon">
<pre>
Pattaya.Global.Utils.encodeHtml("\<a\>\<\/a\>"); // return "&lt;a&gt;&lt;&#x2F;a&gt;";
</pre>
</div>
</div>
</li>
<li class="cbox">
<h3 class="title">decodeHtml(str)</h3>
<div class="container">
<h4 class="subtitle">概述:</h4>
<div class="subcon">
对字符串进行html的特殊字符反转义
</div>
<h4 class="subtitle">参数:</h4>
<ul class="subcon">
<li>
<b class="lbl">str:</b>
<span class="con">待反转义字符串</span>
</li>
</ul>
<h4 class="subtitle">Example:</h4>
<div class="example subcon">
<pre>
Pattaya.Global.Utils.decodeHtml("&lt;a&gt;&lt;&#x2F;a&gt;"); // return "<a></a>";
</pre>
</div>
</div>
</li>
</ol>
</article>
</body>
</html>