mazey 3.3.2 → 3.3.5
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 +1 -1
- package/README.md +100 -68
- package/README_CN.md +1 -1
- package/images/mazey-v1.4.39.svg +1 -0
- package/lib/index.cjs.js +6 -1
- package/lib/index.d.ts +3 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.esm.js +6 -1
- package/lib/mazey.min.js +6 -1
- package/package.json +30 -30
- package/scripts/build-helper.js +17 -0
- package/scripts/dev.js +19 -0
- package/scripts/github-helper.js +57 -0
- package/scripts/release.js +2 -23
- package/{webpack.config.dev.js → scripts/webpack.config.dev.js} +8 -8
- package/{index.js → src/index.js} +0 -0
- package/src/index.ts +10 -6
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -84,15 +84,95 @@ mazey.loadScript(
|
|
|
84
84
|
|
|
85
85
|
## API Examples
|
|
86
86
|
|
|
87
|
-
There ara some
|
|
87
|
+
There ara some examples maintained by hand below. For more information, please check the [full documentation](https://i.mazey.net/mazey/docs/modules/_index_.html).
|
|
88
|
+
|
|
89
|
+
**Table of Contents**
|
|
90
|
+
|
|
91
|
+
<ul>
|
|
92
|
+
<li><a href="#load-resource">Load Resource</a>
|
|
93
|
+
<ul>
|
|
94
|
+
<li><a href="#load-script">Load Script</a></li>
|
|
95
|
+
<li><a href="#load-css">Load CSS</a></li>
|
|
96
|
+
<li><a href="#check-load">Check Load</a></li>
|
|
97
|
+
</ul>
|
|
98
|
+
</li>
|
|
99
|
+
<li><a href="#function">Function</a>
|
|
100
|
+
<ul>
|
|
101
|
+
<li><a href="#debounce">Debounce</a></li>
|
|
102
|
+
<li><a href="#throttle">Throttle</a></li>
|
|
103
|
+
<li><a href="#check-number">Check Number</a></li>
|
|
104
|
+
<li><a href="#camel-case">Camel Case</a></li>
|
|
105
|
+
<li><a href="#trim">Trim</a></li>
|
|
106
|
+
<li><a href="#deep-clone">Deep Clone</a></li>
|
|
107
|
+
<li><a href="#json">JSON</a></li>
|
|
108
|
+
<li><a href="#random">Random</a></li>
|
|
109
|
+
</ul>
|
|
110
|
+
</li>
|
|
111
|
+
<li><a href="#dom">DOM</a>
|
|
112
|
+
<ul>
|
|
113
|
+
<li><a href="#class">Class</a></li>
|
|
114
|
+
<li><a href="#style">Style</a></li>
|
|
115
|
+
<li><a href="#newline">Newline</a></li>
|
|
116
|
+
</ul>
|
|
117
|
+
</li>
|
|
118
|
+
<li><a href="#url">URL</a>
|
|
119
|
+
<ul>
|
|
120
|
+
<li><a href="#query-param">Query Param</a></li>
|
|
121
|
+
<li><a href="#update-param">Update Param</a></li>
|
|
122
|
+
<li><a href="#hash-param">Hash Param</a></li>
|
|
123
|
+
<li><a href="#domain">Domain</a></li>
|
|
124
|
+
</ul>
|
|
125
|
+
</li>
|
|
126
|
+
<li><a href="#cache-data">Cache Data</a>
|
|
127
|
+
<ul>
|
|
128
|
+
<li><a href="#storage">Storage</a></li>
|
|
129
|
+
<li><a href="#cookie">Cookie</a></li>
|
|
130
|
+
</ul>
|
|
131
|
+
</li>
|
|
132
|
+
<li><a href="#calculate-formula">Calculate&Formula</a>
|
|
133
|
+
<ul>
|
|
134
|
+
<li><a href="#rate">Rate</a></li>
|
|
135
|
+
<li><a href="#algorithm">Algorithm</a></li>
|
|
136
|
+
</ul>
|
|
137
|
+
</li>
|
|
138
|
+
<li><a href="#browser-information">Browser Information</a></li>
|
|
139
|
+
<li><a href="#web-performance">Web Performance</a></li>
|
|
140
|
+
<li><a href="#margin-of-safety">Margin of Safety</a></li>
|
|
141
|
+
<li><a href="#debug">Debug</a>
|
|
142
|
+
<ul>
|
|
143
|
+
<li><a href="#print">Print</a></li>
|
|
144
|
+
</ul>
|
|
145
|
+
</li>
|
|
146
|
+
</ul>
|
|
88
147
|
|
|
89
148
|
### Load Resource
|
|
90
149
|
|
|
91
|
-
#### Load
|
|
150
|
+
#### Load Script
|
|
92
151
|
|
|
93
152
|
```
|
|
94
|
-
|
|
153
|
+
loadScript(
|
|
154
|
+
'http://example.com/static/js/plugin-2.1.1.min.js',
|
|
155
|
+
{
|
|
156
|
+
id: 'iamid', // (Optional) script ID, default none
|
|
157
|
+
timeout: 5000, // (Optional) timeout, default `5000`
|
|
158
|
+
isDefer: false, // (Optional) defer, default `false`
|
|
159
|
+
}
|
|
160
|
+
)
|
|
161
|
+
.then(
|
|
162
|
+
res => {
|
|
163
|
+
console.log(`Load JavaScript script: ${res}`);
|
|
164
|
+
}
|
|
165
|
+
)
|
|
166
|
+
.catch(
|
|
167
|
+
err => {
|
|
168
|
+
console.error(`Load JavaScript script: ${err.message}`)
|
|
169
|
+
}
|
|
170
|
+
);
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
#### Load CSS
|
|
95
174
|
|
|
175
|
+
```
|
|
96
176
|
loadCSS(
|
|
97
177
|
'http://example.com/css/mazey-base.css',
|
|
98
178
|
{
|
|
@@ -116,8 +196,6 @@ loadCSS(
|
|
|
116
196
|
Check whether the page is loaded successfully (Keepe the compatibility in case that browser's `load` event has been triggered).
|
|
117
197
|
|
|
118
198
|
```
|
|
119
|
-
import { windowLoaded } from 'mazey';
|
|
120
|
-
|
|
121
199
|
windowLoaded(30) // second
|
|
122
200
|
.then(res => {
|
|
123
201
|
console.log(`Load Success: ${res}`); // Load Success: load
|
|
@@ -126,13 +204,12 @@ windowLoaded(30) // second
|
|
|
126
204
|
console.log(`Load Timeout or Fail: ${err.message}`);
|
|
127
205
|
});
|
|
128
206
|
```
|
|
207
|
+
|
|
129
208
|
### Function
|
|
130
209
|
|
|
131
210
|
#### Debounce
|
|
132
211
|
|
|
133
212
|
```
|
|
134
|
-
import { debounce } from 'mazey';
|
|
135
|
-
|
|
136
213
|
const foo = debounce(() => {
|
|
137
214
|
console.log('The debounced function will only be invoked in 1000 milliseconds, the other invoking will disappear during the wait time.');
|
|
138
215
|
}, 1000, true);
|
|
@@ -141,8 +218,6 @@ const foo = debounce(() => {
|
|
|
141
218
|
#### Throttle
|
|
142
219
|
|
|
143
220
|
```
|
|
144
|
-
import { throttle } from 'mazey';
|
|
145
|
-
|
|
146
221
|
const foo = throttle(() => {
|
|
147
222
|
console.log('The function will be invoked at most once per every wait 1000 milliseconds.');
|
|
148
223
|
}, 1000, { leading: true });
|
|
@@ -153,8 +228,6 @@ const foo = throttle(() => {
|
|
|
153
228
|
Check whether it is a right number.
|
|
154
229
|
|
|
155
230
|
```
|
|
156
|
-
import { isNumber } from 'mazey';
|
|
157
|
-
|
|
158
231
|
isNumber(123); // true
|
|
159
232
|
isNumber('123'); // false
|
|
160
233
|
// Default: NaN, Infinity is not Number
|
|
@@ -169,8 +242,6 @@ isNumber(NaN, { isNaNAsNumber: true, isUnFiniteAsNumber: true }); // true
|
|
|
169
242
|
Transfer CamelCase to KebabCase.
|
|
170
243
|
|
|
171
244
|
```
|
|
172
|
-
import { camelCaseToKebabCase } from 'mazey';
|
|
173
|
-
|
|
174
245
|
camelCaseToKebabCase('ABC'); // a-b-c
|
|
175
246
|
camelCaseToKebabCase('aBC'); // a-b-c
|
|
176
247
|
```
|
|
@@ -178,8 +249,6 @@ camelCaseToKebabCase('aBC'); // a-b-c
|
|
|
178
249
|
Transfer CamelCase to Underscore.
|
|
179
250
|
|
|
180
251
|
```
|
|
181
|
-
import { camelCase2Underscore } from 'mazey';
|
|
182
|
-
|
|
183
252
|
camelCase2Underscore('ABC'); // a_b_c
|
|
184
253
|
camelCase2Underscore('aBC'); // a_b_c
|
|
185
254
|
```
|
|
@@ -189,8 +258,6 @@ camelCase2Underscore('aBC'); // a_b_c
|
|
|
189
258
|
Remove leading and trailing whitespace or specified characters from string.
|
|
190
259
|
|
|
191
260
|
```
|
|
192
|
-
import { mTrim } from 'mazey';
|
|
193
|
-
|
|
194
261
|
mTrim(' 1 2 3 '); // '1 2 3'
|
|
195
262
|
mTrim('abc '); // 'abc'
|
|
196
263
|
```
|
|
@@ -200,8 +267,6 @@ mTrim('abc '); // 'abc'
|
|
|
200
267
|
Clone Object deeply.
|
|
201
268
|
|
|
202
269
|
```
|
|
203
|
-
import { deepCopyObject } from 'mazey';
|
|
204
|
-
|
|
205
270
|
deepCopyObject(['a', 'b', 'c']); // ['a', 'b', 'c']
|
|
206
271
|
deepCopyObject('abc'); // 'abc'
|
|
207
272
|
```
|
|
@@ -211,8 +276,6 @@ deepCopyObject('abc'); // 'abc'
|
|
|
211
276
|
Check whether it is a valid JSON string.
|
|
212
277
|
|
|
213
278
|
```
|
|
214
|
-
import { isJsonString } from 'mazey';
|
|
215
|
-
|
|
216
279
|
isJsonString(`['a', 'b', 'c']`); // false
|
|
217
280
|
isJsonString(`["a", "b", "c"]`); // true
|
|
218
281
|
```
|
|
@@ -222,8 +285,6 @@ isJsonString(`["a", "b", "c"]`); // true
|
|
|
222
285
|
Produce a random string of number, `generateRndNum(7)` => '7658495'.
|
|
223
286
|
|
|
224
287
|
```
|
|
225
|
-
import { generateRndNum } from 'mazey';
|
|
226
|
-
|
|
227
288
|
generateRndNum(4); // '9730'
|
|
228
289
|
generateRndNum(7); // '2262490'
|
|
229
290
|
```
|
|
@@ -235,8 +296,6 @@ generateRndNum(7); // '2262490'
|
|
|
235
296
|
Modify `class`.
|
|
236
297
|
|
|
237
298
|
```
|
|
238
|
-
import { hasClass, addClass, removeClass } from 'mazey';
|
|
239
|
-
|
|
240
299
|
const dom = document.querySelector('#box');
|
|
241
300
|
|
|
242
301
|
// Determine `class`
|
|
@@ -254,8 +313,6 @@ Add `<style>` in `<head>`.
|
|
|
254
313
|
Case 1: Add the `<style>` with `id`, and repeated invoking will update the content instead of adding a new one.
|
|
255
314
|
|
|
256
315
|
```
|
|
257
|
-
import { addStyle } from 'mazey';
|
|
258
|
-
|
|
259
316
|
addStyle(
|
|
260
317
|
`
|
|
261
318
|
body {
|
|
@@ -276,8 +333,6 @@ addStyle(
|
|
|
276
333
|
Case 2: Add the `<style>` without `id`, and repeated invoking will adding a new one.
|
|
277
334
|
|
|
278
335
|
```
|
|
279
|
-
import { addStyle } from 'mazey';
|
|
280
|
-
|
|
281
336
|
addStyle(
|
|
282
337
|
`
|
|
283
338
|
body {
|
|
@@ -297,8 +352,6 @@ addStyle(
|
|
|
297
352
|
Make a newline of HTML.
|
|
298
353
|
|
|
299
354
|
```
|
|
300
|
-
import { newLine } from 'mazey';
|
|
301
|
-
|
|
302
355
|
newLine('a\nb\nc'); // 'a<br />b<br />c'
|
|
303
356
|
newLine('a\n\nbc'); // 'a<br /><br />bc'
|
|
304
357
|
```
|
|
@@ -310,8 +363,6 @@ newLine('a\n\nbc'); // 'a<br /><br />bc'
|
|
|
310
363
|
Get the query param's value of the current Web URL(`location.search`).
|
|
311
364
|
|
|
312
365
|
```
|
|
313
|
-
import { getQueryParam } from 'mazey';
|
|
314
|
-
|
|
315
366
|
// http://example.com/?t1=1&t2=2&t3=3&t4=4#2333
|
|
316
367
|
// ?t1=1&t2=2&t3=3&t4=4
|
|
317
368
|
getQueryParam('t3'); // 3
|
|
@@ -321,8 +372,6 @@ getQueryParam('t4'); // 4
|
|
|
321
372
|
Get the query param's value of the input URL.
|
|
322
373
|
|
|
323
374
|
```
|
|
324
|
-
import { getUrlParam } from 'mazey';
|
|
325
|
-
|
|
326
375
|
getUrlParam('http://example.com/?t1=1&t2=2&t3=3&t4=4', 't3'); // 3
|
|
327
376
|
getUrlParam('http://example.com/?t1=1&t2=2&t3=3&t4=4', 't4'); // 4
|
|
328
377
|
```
|
|
@@ -332,8 +381,6 @@ getUrlParam('http://example.com/?t1=1&t2=2&t3=3&t4=4', 't4'); // 4
|
|
|
332
381
|
Update the query param's value of the input URL.
|
|
333
382
|
|
|
334
383
|
```
|
|
335
|
-
import { updateQueryParam } from 'mazey';
|
|
336
|
-
|
|
337
384
|
updateQueryParam('http://example.com/?t1=1&t2=2&t3=3&t4=4', 't3', 'three'); // http://example.com/?t1=1&t2=2&t3=three&t4=4
|
|
338
385
|
updateQueryParam('http://example.com/?t1=1&t2=2&t3=3&t4=4', 't4', 'four'); // http://example.com/?t1=1&t2=2&t3=3&t4=four
|
|
339
386
|
```
|
|
@@ -343,8 +390,6 @@ updateQueryParam('http://example.com/?t1=1&t2=2&t3=3&t4=4', 't4', 'four'); // ht
|
|
|
343
390
|
Get the hash query param's value of the current Web URL(`location.hash`).
|
|
344
391
|
|
|
345
392
|
```
|
|
346
|
-
import { getHashQueryParam } from 'mazey';
|
|
347
|
-
|
|
348
393
|
// http://example.com/?#2333?t1=1&t2=2&t3=3&t4=4
|
|
349
394
|
// #2333?t1=1&t2=2&t3=3&t4=4
|
|
350
395
|
getHashQueryParam('t3'); // 3
|
|
@@ -356,8 +401,6 @@ getHashQueryParam('t4'); // 4
|
|
|
356
401
|
Get the domain of URL, and other params.
|
|
357
402
|
|
|
358
403
|
```
|
|
359
|
-
import { getDomain } from 'mazey';
|
|
360
|
-
|
|
361
404
|
getDomain('http://example.com/?t1=1&t2=2&t3=3&t4=4'); // example.com
|
|
362
405
|
getDomain('http://example.com/test/thanks?t1=1&t2=2&t3=3&t4=4', ['hostname', 'pathname']); // example.com/test/thanks
|
|
363
406
|
```
|
|
@@ -369,8 +412,6 @@ getDomain('http://example.com/test/thanks?t1=1&t2=2&t3=3&t4=4', ['hostname', 'pa
|
|
|
369
412
|
Handle Storage (Keep fit for JSON, it can tansfer format automatically).
|
|
370
413
|
|
|
371
414
|
```
|
|
372
|
-
import { setSessionStorage, getSessionStorage, setLocalStorage, getLocalStorage } from 'mazey';
|
|
373
|
-
|
|
374
415
|
setSessionStorage('test', '123');
|
|
375
416
|
getSessionStorage('test'); // 123
|
|
376
417
|
setLocalStorage('test', '123');
|
|
@@ -392,8 +433,6 @@ function mGetLocalStorage (key) {
|
|
|
392
433
|
Handle Cookie.
|
|
393
434
|
|
|
394
435
|
```
|
|
395
|
-
import { setCookie, getCookie } from 'mazey';
|
|
396
|
-
|
|
397
436
|
setCookie('test', '123', 30, 'example.com'); // key value day domain
|
|
398
437
|
getCookie('test'); // 123
|
|
399
438
|
```
|
|
@@ -405,8 +444,6 @@ getCookie('test'); // 123
|
|
|
405
444
|
Hit probability (1% ~ 100%).
|
|
406
445
|
|
|
407
446
|
```
|
|
408
|
-
import { inRate } from 'mazey';
|
|
409
|
-
|
|
410
447
|
inRate(0.5); // 0.01 ~ 1 true / false
|
|
411
448
|
|
|
412
449
|
// Test
|
|
@@ -427,24 +464,18 @@ console.log(trueCount, falseCount); // 499994 500006
|
|
|
427
464
|
Computes the longest common substring of two strings.
|
|
428
465
|
|
|
429
466
|
```
|
|
430
|
-
import { calLongestCommonSubstring } from 'mazey';
|
|
431
|
-
|
|
432
467
|
calLongestCommonSubstring('fish', 'finish'); // 3
|
|
433
468
|
```
|
|
434
469
|
|
|
435
470
|
Computes the longest common subsequence of two strings.
|
|
436
471
|
|
|
437
472
|
```
|
|
438
|
-
import { calLongestCommonSubsequence } from 'mazey';
|
|
439
|
-
|
|
440
473
|
calLongestCommonSubsequence('fish', 'finish'); // 4
|
|
441
474
|
```
|
|
442
475
|
|
|
443
476
|
### Browser Information
|
|
444
477
|
|
|
445
478
|
```
|
|
446
|
-
import { getBrowserInfo } from 'mazey';
|
|
447
|
-
|
|
448
479
|
getBrowserInfo(); // {"engine":"webkit","engineVs":"537.36","platform":"desktop","supporter":"chrome","supporterVs":"85.0.4183.121","system":"windows","systemVs":"10"}
|
|
449
480
|
// Shell and shell version { shell: 'wechat', shellVs: '20' } shell: wechat qq uc 360 2345 sougou liebao maxthon
|
|
450
481
|
```
|
|
@@ -467,8 +498,6 @@ getBrowserInfo(); // {"engine":"webkit","engineVs":"537.36","platform":"desktop"
|
|
|
467
498
|
Get page load time(PerformanceTiming).
|
|
468
499
|
|
|
469
500
|
```
|
|
470
|
-
import { getPerformance } from 'mazey';
|
|
471
|
-
|
|
472
501
|
// `camelCase:true`(Default) Return hump data.
|
|
473
502
|
// `camelCase:false` Return underline data.
|
|
474
503
|
getPerformance(true)
|
|
@@ -498,8 +527,6 @@ getPerformance(true)
|
|
|
498
527
|
Determine if it is a secure PWA environment that it can run.
|
|
499
528
|
|
|
500
529
|
```
|
|
501
|
-
import { isSafePWAEnv } from 'mazey';
|
|
502
|
-
|
|
503
530
|
isSafePWAEnv(); // true
|
|
504
531
|
```
|
|
505
532
|
|
|
@@ -510,8 +537,6 @@ isSafePWAEnv(); // true
|
|
|
510
537
|
Custom console printing (`console`).
|
|
511
538
|
|
|
512
539
|
```
|
|
513
|
-
import { genCustomConsole } from 'mazey';
|
|
514
|
-
|
|
515
540
|
const myConsole = genCustomConsole('MazeyLog:');
|
|
516
541
|
myConsole.log('I am string.'); // MazeyLog: I am string.
|
|
517
542
|
myConsole.info('I am boolean.', true); // MazeyLog: I am boolean. true
|
|
@@ -519,18 +544,25 @@ myConsole.info('I am number.', 123, 456); // MazeyLog: I am number. 123 456
|
|
|
519
544
|
myConsole.info('I am object.', { a: 123, b: 456}); // MazeyLog: I am object. {a: 123, b: 456}
|
|
520
545
|
```
|
|
521
546
|
|
|
522
|
-
##
|
|
547
|
+
## Contributing
|
|
523
548
|
|
|
524
549
|
```
|
|
525
|
-
#
|
|
526
|
-
npm
|
|
550
|
+
# Install
|
|
551
|
+
npm i --registry=https://registry.npmjs.org
|
|
527
552
|
|
|
528
|
-
#
|
|
529
|
-
npm run
|
|
553
|
+
# Serve
|
|
554
|
+
npm run dev
|
|
530
555
|
|
|
531
|
-
#
|
|
532
|
-
npm run
|
|
556
|
+
# Build
|
|
557
|
+
npm run build
|
|
533
558
|
|
|
534
|
-
#
|
|
535
|
-
npm run
|
|
559
|
+
# Document
|
|
560
|
+
npm run docs
|
|
561
|
+
|
|
562
|
+
# Test
|
|
563
|
+
npm run test
|
|
536
564
|
```
|
|
565
|
+
|
|
566
|
+
## License
|
|
567
|
+
|
|
568
|
+
This software is released under the terms of the [MIT license](https://github.com/mazeyqian/mazey/blob/master/LICENSE).
|
package/README_CN.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
[![NPM version][npm-image]][npm-url]
|
|
4
4
|
[![l][l-image]][l-url]
|
|
5
5
|
|
|
6
|
-
[npm-image]:
|
|
6
|
+
[npm-image]: ./images/mazey-v1.4.39.svg
|
|
7
7
|
[npm-url]: https://www.npmjs.com/package/mazey/v/1.4.39
|
|
8
8
|
[l-image]: https://img.shields.io/npm/l/mazey
|
|
9
9
|
[l-url]: https://github.com/mazeyqian/mazey
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="88" height="20" role="img" aria-label="npm: v1.4.39"><title>npm: v1.4.39</title><linearGradient id="s" x2="0" y2="100%"><stop offset="0" stop-color="#bbb" stop-opacity=".1"/><stop offset="1" stop-opacity=".1"/></linearGradient><clipPath id="r"><rect width="88" height="20" rx="3" fill="#fff"/></clipPath><g clip-path="url(#r)"><rect width="35" height="20" fill="#555"/><rect x="35" width="53" height="20" fill="#007ec6"/><rect width="88" height="20" fill="url(#s)"/></g><g fill="#fff" text-anchor="middle" font-family="Verdana,Geneva,DejaVu Sans,sans-serif" text-rendering="geometricPrecision" font-size="110"><text aria-hidden="true" x="185" y="150" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="250">npm</text><text x="185" y="140" transform="scale(.1)" fill="#fff" textLength="250">npm</text><text aria-hidden="true" x="605" y="150" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="430">v1.4.39</text><text x="605" y="140" transform="scale(.1)" fill="#fff" textLength="430">v1.4.39</text></g></svg>
|