mazey 1.4.35 → 1.4.39
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -21
- package/README.md +334 -282
- package/lib/index.cjs.js +125 -21
- package/lib/index.d.ts +26 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.esm.js +124 -22
- package/package.json +85 -85
- package/src/index.ts +1642 -1589
- package/src/js/data-structure/MSet.js +89 -89
- package/src/js/polyfill.js +63 -63
- package/src/js/service/common.js +4 -4
- package/src/scss/extend/index.scss +148 -148
- package/src/scss/index.scss +4 -4
- package/src/scss/mixin/index.scss +41 -41
- package/src/scss/variate/index.scss +27 -27
- package/src/test.html +33 -33
- package/src/test.ts +52 -197
- package/tsconfig.json +73 -73
- package/typing.d.ts +3 -3
package/LICENSE
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
The MIT License (MIT)
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2017 Mazey
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in
|
|
13
|
-
all copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
-
THE SOFTWARE.
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2017 Mazey
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,283 +1,335 @@
|
|
|
1
|
-
# Mazey
|
|
2
|
-
|
|
3
|
-
[![NPM version][npm-image]][npm-url]
|
|
4
|
-
[![l][l-image]][l-url]
|
|
5
|
-
|
|
6
|
-
[npm-image]: https://img.shields.io/npm/v/mazey
|
|
7
|
-
[npm-url]: https://npmjs.org/package/mazey
|
|
8
|
-
[l-image]: https://img.shields.io/npm/l/mazey
|
|
9
|
-
[l-url]: https://github.com/mazeyqian/mazey
|
|
10
|
-
|
|
11
|
-
Mazey's library for front end.
|
|
12
|
-
|
|
13
|
-
## Install
|
|
14
|
-
|
|
15
|
-
You can get Mazey via [npm](https://www.npmjs.com/package/mazey).
|
|
16
|
-
|
|
17
|
-
```
|
|
18
|
-
npm install mazey --save
|
|
19
|
-
```
|
|
20
|
-
|
|
21
|
-
## Usage
|
|
22
|
-
|
|
23
|
-
### 加载资源
|
|
24
|
-
|
|
25
|
-
加载 JavaScript
|
|
26
|
-
|
|
27
|
-
```
|
|
28
|
-
import { loadScript } from 'mazey';
|
|
29
|
-
|
|
30
|
-
loadScript({
|
|
31
|
-
url: 'http://www.mazey.net/js/plugin/jquery/jquery-2.1.1.min.js'
|
|
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
|
-
setLocalStorage
|
|
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
|
-
import {
|
|
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
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
1
|
+
# Mazey
|
|
2
|
+
|
|
3
|
+
[![NPM version][npm-image]][npm-url]
|
|
4
|
+
[![l][l-image]][l-url]
|
|
5
|
+
|
|
6
|
+
[npm-image]: https://img.shields.io/npm/v/mazey
|
|
7
|
+
[npm-url]: https://npmjs.org/package/mazey
|
|
8
|
+
[l-image]: https://img.shields.io/npm/l/mazey
|
|
9
|
+
[l-url]: https://github.com/mazeyqian/mazey
|
|
10
|
+
|
|
11
|
+
Mazey's library for front end.
|
|
12
|
+
|
|
13
|
+
## Install
|
|
14
|
+
|
|
15
|
+
You can get Mazey via [npm](https://www.npmjs.com/package/mazey).
|
|
16
|
+
|
|
17
|
+
```
|
|
18
|
+
npm install mazey --save
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Usage
|
|
22
|
+
|
|
23
|
+
### 加载资源
|
|
24
|
+
|
|
25
|
+
加载 JavaScript
|
|
26
|
+
|
|
27
|
+
```
|
|
28
|
+
import { loadScript } from 'mazey';
|
|
29
|
+
|
|
30
|
+
loadScript({
|
|
31
|
+
url: 'http://www.mazey.net/js/plugin/jquery/jquery-2.1.1.min.js',
|
|
32
|
+
id: 'iamid', // 可选,script 标签 ID,默认无 ID
|
|
33
|
+
timeout: 5000, // 可选,超时时间,默认 5000
|
|
34
|
+
isDefer: false, // 可选,defer,默认 false
|
|
35
|
+
})
|
|
36
|
+
.then(
|
|
37
|
+
res => {
|
|
38
|
+
console.log(`加载 JavaScript 成功: ${res}`);
|
|
39
|
+
}
|
|
40
|
+
)
|
|
41
|
+
.catch(
|
|
42
|
+
err => {
|
|
43
|
+
console.error(`加载 JavaScript 失败: ${err}`)
|
|
44
|
+
}
|
|
45
|
+
);
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
加载 CSS
|
|
49
|
+
|
|
50
|
+
```
|
|
51
|
+
import { loadCSS } from 'mazey';
|
|
52
|
+
|
|
53
|
+
loadCSS({
|
|
54
|
+
url: 'http://www.mazey.net/css/mazey-base.css',
|
|
55
|
+
id: 'iamid', // 可选,link 标签 ID,默认无 ID
|
|
56
|
+
})
|
|
57
|
+
.then(
|
|
58
|
+
res => {
|
|
59
|
+
console.log(`加载 CSS 成功: ${res}`);
|
|
60
|
+
}
|
|
61
|
+
)
|
|
62
|
+
.catch(
|
|
63
|
+
err => {
|
|
64
|
+
console.error(`加载 CSS 失败: ${err}`)
|
|
65
|
+
}
|
|
66
|
+
);
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
判断页面是否加载完成(兼容浏览器 `load` 事件已经触发过的情况)
|
|
70
|
+
|
|
71
|
+
```
|
|
72
|
+
import { loadCSS } from 'mazey';
|
|
73
|
+
|
|
74
|
+
windowLoaded({ timeout: 30 })
|
|
75
|
+
.then(res => {
|
|
76
|
+
console.log(`加载完成:${res}`); // 加载完成:load
|
|
77
|
+
})
|
|
78
|
+
.catch(err => {
|
|
79
|
+
console.log(`加载超时或失败:${err}`);
|
|
80
|
+
});
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
### 存储数据
|
|
84
|
+
|
|
85
|
+
Storage(兼容 JSON 格式,自行转换)
|
|
86
|
+
|
|
87
|
+
```
|
|
88
|
+
import { setSessionStorage, getSessionStorage, setLocalStorage, getLocalStorage } from 'mazey';
|
|
89
|
+
|
|
90
|
+
setSessionStorage('test', '123');
|
|
91
|
+
getSessionStorage('test'); // 123
|
|
92
|
+
setLocalStorage('test', '123');
|
|
93
|
+
getLocalStorage('test'); // 123
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
Cookie
|
|
97
|
+
|
|
98
|
+
```
|
|
99
|
+
import { setCookie, getCookie } from 'mazey';
|
|
100
|
+
|
|
101
|
+
setCookie('test', '123', 30, 'mazey.net'); // key value day domain
|
|
102
|
+
getCookie('test'); // 123
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
### 操作 DOM
|
|
106
|
+
|
|
107
|
+
修改 `class`
|
|
108
|
+
|
|
109
|
+
```
|
|
110
|
+
import { hasClass, addClass, removeClass } from 'mazey';
|
|
111
|
+
|
|
112
|
+
const dom = document.querySelector('#box');
|
|
113
|
+
|
|
114
|
+
// 判断 class
|
|
115
|
+
hasClass(dom, 'test');
|
|
116
|
+
// 增加 class
|
|
117
|
+
addClass(dom, 'test');
|
|
118
|
+
// 删除 class
|
|
119
|
+
removeClass(dom, 'test');
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
添加内联样式
|
|
123
|
+
|
|
124
|
+
```
|
|
125
|
+
import { addInlineStyle } from 'mazey';
|
|
126
|
+
|
|
127
|
+
// 添加有 id 的内联样式,重复添加会更新内联样式而不是新增
|
|
128
|
+
addInlineStyle({
|
|
129
|
+
inlineStyle: `
|
|
130
|
+
body {
|
|
131
|
+
background-color: #333;
|
|
132
|
+
}
|
|
133
|
+
`,
|
|
134
|
+
id: 'test',
|
|
135
|
+
});
|
|
136
|
+
// <style id="test">
|
|
137
|
+
// body {
|
|
138
|
+
// background-color: #333;
|
|
139
|
+
// }
|
|
140
|
+
// </style>
|
|
141
|
+
|
|
142
|
+
// 添加无 id 的内联样式,重复添加会新增内联样式
|
|
143
|
+
addInlineStyle({
|
|
144
|
+
inlineStyle: `
|
|
145
|
+
body {
|
|
146
|
+
background-color: #444;
|
|
147
|
+
}
|
|
148
|
+
`,
|
|
149
|
+
});
|
|
150
|
+
// <style>
|
|
151
|
+
// body {
|
|
152
|
+
// background-color: #444;
|
|
153
|
+
// }
|
|
154
|
+
// </style>
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
添加自定义滚动条(适用于用 `transform` 移动的元素)
|
|
158
|
+
|
|
159
|
+
```
|
|
160
|
+
import { customScrollBarForTransformEle } from 'mazey';
|
|
161
|
+
|
|
162
|
+
// 使用类名
|
|
163
|
+
customScrollBarForTransformEle({
|
|
164
|
+
containerClassName: 'i-am-container',
|
|
165
|
+
imgBoxClassName: 'i-am-img-father-i-can-transform',
|
|
166
|
+
imgClassName: 'i-am-img',
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
// 使用 Dom 对象
|
|
170
|
+
customScrollBarForTransformEle({
|
|
171
|
+
containerClassName: 'i-am-container',
|
|
172
|
+
imgBoxDom: document.querySelector('.i-am-img-father-i-can-transform'),
|
|
173
|
+
imgDom: document.querySelector('.i-am-img-father-i-can-transform'),
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
// 按需直接隐藏滚动条
|
|
177
|
+
customScrollBarForTransformEle({
|
|
178
|
+
containerClassName: 'i-am-container',
|
|
179
|
+
action: 'hide',
|
|
180
|
+
});
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
计算适配容器宽度的图片的尺寸、距离顶部的距离
|
|
184
|
+
|
|
185
|
+
```
|
|
186
|
+
import { calcContainImageSizeAndPosition } from 'mazey';
|
|
187
|
+
|
|
188
|
+
// 如果高度不足以占满容器,使其垂直居中;如果高度比容器长,由上向下铺开
|
|
189
|
+
calcContainImageSizeAndPosition({ oriImageWidth: 300, oriImageHeight: 300, viewportWidth: 375, viewportHeight: 812 });
|
|
190
|
+
// {"targetImageWidth":375,"targetImageHeight":375,"top":218.5,"wPer":1.25}
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
### 网站性能
|
|
194
|
+
|
|
195
|
+
获取加载时间
|
|
196
|
+
|
|
197
|
+
```
|
|
198
|
+
import { getPerformance } from 'mazey';
|
|
199
|
+
|
|
200
|
+
// camelCase:true(默认) 以驼峰形式返回数据 / false 以下划线形式返回数据
|
|
201
|
+
getPerformance({ camelCase: true })
|
|
202
|
+
.then(res => {
|
|
203
|
+
console.log(JSON.stringify(res));
|
|
204
|
+
// {"deviceType":"pc","network":"3g","unloadTime":0,"redirectTime":0,"dnsTime":0,"tcpTime":0,"responseTime":65,"downloadTime":1,"domreadyTime":369,"onloadTime":441,"whiteTime":94,"renderTime":441,"decodedBodySize":210,"encodedBodySize":210}
|
|
205
|
+
})
|
|
206
|
+
.catch(console.error);
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
| 指标 | 字段 | 计算⽅法 |
|
|
210
|
+
| --- | --- | --- |
|
|
211
|
+
| * DNS 查询时间 | dns_time | domainLookupEnd - domainLookupStart |
|
|
212
|
+
| * 服务器连接时间 | tcp_time | connectEnd - connectStart |
|
|
213
|
+
| * 服务器响应时间 | response_time | responseStart - requestStart |
|
|
214
|
+
| * ⽩屏时间 | white_time | responseStart - navigationStart |
|
|
215
|
+
| * DomReady 总时间 | domready_time | domContentLoadedEventStart - navigationStart |
|
|
216
|
+
| * 页面加载时间 | onload_time | loadEventStart - navigationStart |
|
|
217
|
+
| * EventEnd 总时间 | render_time | loadEventEnd -navigationStart |
|
|
218
|
+
| 上个⽂档卸载时间 | unload_time | unloadEventEnd - unloadEventStart |
|
|
219
|
+
| 重定向时间 | redirect_time | redirectEnd - redirectStart |
|
|
220
|
+
| 客户端⽩屏时间 | custom_white_time | renderTiming - navigationStart |
|
|
221
|
+
| SSL连接时间 | ssl_time | connectEnd - secureConnectionStart |
|
|
222
|
+
| ⽹⻚下载时间 | download_time | responseEnd - responseStart |
|
|
223
|
+
| FCP | first_contentful_paint_time | firstPaintTime |
|
|
224
|
+
|
|
225
|
+
### 公式计算
|
|
226
|
+
|
|
227
|
+
计算两个字符串的最长公共子串
|
|
228
|
+
|
|
229
|
+
```
|
|
230
|
+
import { calLongestCommonSubstring } from 'mazey';
|
|
231
|
+
|
|
232
|
+
calLongestCommonSubstring('fish', 'finish'); // 3
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
计算两个字符串的最长公共子序列
|
|
236
|
+
|
|
237
|
+
```
|
|
238
|
+
import { calLongestCommonSubsequence } from 'mazey';
|
|
239
|
+
|
|
240
|
+
calLongestCommonSubsequence('fish', 'finish'); // 4
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
命中概率(1% ~ 100%)
|
|
244
|
+
|
|
245
|
+
```
|
|
246
|
+
import { inRate } from 'mazey';
|
|
247
|
+
|
|
248
|
+
inRate(0.5); // 0.01 ~ 1 true / false
|
|
249
|
+
|
|
250
|
+
// 测试准确性
|
|
251
|
+
let trueCount = 0;
|
|
252
|
+
let falseCount = 0;
|
|
253
|
+
new Array(1000000).fill(0).forEach(() => {
|
|
254
|
+
if (inRate(0.5)) {
|
|
255
|
+
trueCount++;
|
|
256
|
+
} else {
|
|
257
|
+
falseCount++;
|
|
258
|
+
}
|
|
259
|
+
});
|
|
260
|
+
console.log(trueCount, falseCount); // 499994 500006
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
### 浏览器信息
|
|
264
|
+
|
|
265
|
+
```
|
|
266
|
+
import { getBrowserType } from 'mazey';
|
|
267
|
+
|
|
268
|
+
getBrowserType(); // {"engine":"webkit","engineVs":"537.36","platform":"desktop","supporter":"chrome","supporterVs":"85.0.4183.121","system":"windows","systemVs":"10"}
|
|
269
|
+
// 外壳和外壳版本 { shell: 'wechat', shellVs: '20' } shell: wechat qq uc 360 2345 sougou liebao maxthon
|
|
270
|
+
```
|
|
271
|
+
|
|
272
|
+
### 安全边际
|
|
273
|
+
|
|
274
|
+
判断是否是安全的 PWA 运行环境
|
|
275
|
+
|
|
276
|
+
```
|
|
277
|
+
import { isSafePWAEnv } from 'mazey';
|
|
278
|
+
|
|
279
|
+
isSafePWAEnv(); // true
|
|
280
|
+
```
|
|
281
|
+
|
|
282
|
+
### 函数
|
|
283
|
+
|
|
284
|
+
防抖
|
|
285
|
+
|
|
286
|
+
```
|
|
287
|
+
import { debounce } from 'mazey';
|
|
288
|
+
|
|
289
|
+
const foo = debounce(() => {
|
|
290
|
+
console.log('执行 1 秒内再次执行无反应');
|
|
291
|
+
}, 1000, { leading: true })
|
|
292
|
+
```
|
|
293
|
+
|
|
294
|
+
判断是否是有效数字
|
|
295
|
+
|
|
296
|
+
```
|
|
297
|
+
import { isNumber } from 'mazey';
|
|
298
|
+
|
|
299
|
+
isNumber(123); // true
|
|
300
|
+
isNumber('123'); // false
|
|
301
|
+
// 默认情况下 NaN、Infinity 不算有效数字
|
|
302
|
+
isNumber(Infinity); // false
|
|
303
|
+
isNumber(Infinity, { isUnFiniteAsNumber: true }); true
|
|
304
|
+
isNumber(NaN); // false
|
|
305
|
+
isNumber(NaN, { isNaNAsNumber: true, isUnFiniteAsNumber: true }); // true
|
|
306
|
+
```
|
|
307
|
+
|
|
308
|
+
### 调试
|
|
309
|
+
|
|
310
|
+
自定义控制台打印(`console`)
|
|
311
|
+
|
|
312
|
+
```
|
|
313
|
+
import { genCustomConsole } from 'mazey';
|
|
314
|
+
|
|
315
|
+
const myConsole = genCustomConsole({ prefix: 'MazeyLog:' });
|
|
316
|
+
myConsole.log('I am string.'); // MazeyLog: I am string.
|
|
317
|
+
myConsole.info('I am boolean.', true); // MazeyLog: I am boolean. true
|
|
318
|
+
myConsole.info('I am number.', 123, 456); // MazeyLog: I am number. 123 456
|
|
319
|
+
myConsole.info('I am object.', { a: 123, b: 456}); // MazeyLog: I am object. {a: 123, b: 456}
|
|
320
|
+
```
|
|
321
|
+
|
|
322
|
+
[更多接口>>](https://mazey.cn/docs/mazey/modules/_index_.html)
|
|
323
|
+
|
|
324
|
+
## Develop
|
|
325
|
+
|
|
326
|
+
```
|
|
327
|
+
# dev
|
|
328
|
+
npm run dev
|
|
329
|
+
|
|
330
|
+
# build
|
|
331
|
+
npm run build
|
|
332
|
+
|
|
333
|
+
# documentation
|
|
334
|
+
npm run docs
|
|
283
335
|
```
|