mazey 3.3.4 → 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 CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2022 Mazey Chu
3
+ Copyright (c) 2018-2022 Mazey Chu
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -84,15 +84,95 @@ mazey.loadScript(
84
84
 
85
85
  ## API Examples
86
86
 
87
- There ara some usage cases maintained by hand below. For more latest information, please check the [documentation](https://i.mazey.net/mazey/docs/modules/_index_.html).
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&amp;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 CSS
150
+ #### Load Script
92
151
 
93
152
  ```
94
- import { loadCSS } from 'mazey';
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
+ ```
95
172
 
173
+ #### Load CSS
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
@@ -132,8 +210,6 @@ windowLoaded(30) // second
132
210
  #### Debounce
133
211
 
134
212
  ```
135
- import { debounce } from 'mazey';
136
-
137
213
  const foo = debounce(() => {
138
214
  console.log('The debounced function will only be invoked in 1000 milliseconds, the other invoking will disappear during the wait time.');
139
215
  }, 1000, true);
@@ -142,8 +218,6 @@ const foo = debounce(() => {
142
218
  #### Throttle
143
219
 
144
220
  ```
145
- import { throttle } from 'mazey';
146
-
147
221
  const foo = throttle(() => {
148
222
  console.log('The function will be invoked at most once per every wait 1000 milliseconds.');
149
223
  }, 1000, { leading: true });
@@ -154,8 +228,6 @@ const foo = throttle(() => {
154
228
  Check whether it is a right number.
155
229
 
156
230
  ```
157
- import { isNumber } from 'mazey';
158
-
159
231
  isNumber(123); // true
160
232
  isNumber('123'); // false
161
233
  // Default: NaN, Infinity is not Number
@@ -170,8 +242,6 @@ isNumber(NaN, { isNaNAsNumber: true, isUnFiniteAsNumber: true }); // true
170
242
  Transfer CamelCase to KebabCase.
171
243
 
172
244
  ```
173
- import { camelCaseToKebabCase } from 'mazey';
174
-
175
245
  camelCaseToKebabCase('ABC'); // a-b-c
176
246
  camelCaseToKebabCase('aBC'); // a-b-c
177
247
  ```
@@ -179,8 +249,6 @@ camelCaseToKebabCase('aBC'); // a-b-c
179
249
  Transfer CamelCase to Underscore.
180
250
 
181
251
  ```
182
- import { camelCase2Underscore } from 'mazey';
183
-
184
252
  camelCase2Underscore('ABC'); // a_b_c
185
253
  camelCase2Underscore('aBC'); // a_b_c
186
254
  ```
@@ -190,8 +258,6 @@ camelCase2Underscore('aBC'); // a_b_c
190
258
  Remove leading and trailing whitespace or specified characters from string.
191
259
 
192
260
  ```
193
- import { mTrim } from 'mazey';
194
-
195
261
  mTrim(' 1 2 3 '); // '1 2 3'
196
262
  mTrim('abc '); // 'abc'
197
263
  ```
@@ -201,8 +267,6 @@ mTrim('abc '); // 'abc'
201
267
  Clone Object deeply.
202
268
 
203
269
  ```
204
- import { deepCopyObject } from 'mazey';
205
-
206
270
  deepCopyObject(['a', 'b', 'c']); // ['a', 'b', 'c']
207
271
  deepCopyObject('abc'); // 'abc'
208
272
  ```
@@ -212,8 +276,6 @@ deepCopyObject('abc'); // 'abc'
212
276
  Check whether it is a valid JSON string.
213
277
 
214
278
  ```
215
- import { isJsonString } from 'mazey';
216
-
217
279
  isJsonString(`['a', 'b', 'c']`); // false
218
280
  isJsonString(`["a", "b", "c"]`); // true
219
281
  ```
@@ -223,8 +285,6 @@ isJsonString(`["a", "b", "c"]`); // true
223
285
  Produce a random string of number, `generateRndNum(7)` => '7658495'.
224
286
 
225
287
  ```
226
- import { generateRndNum } from 'mazey';
227
-
228
288
  generateRndNum(4); // '9730'
229
289
  generateRndNum(7); // '2262490'
230
290
  ```
@@ -236,8 +296,6 @@ generateRndNum(7); // '2262490'
236
296
  Modify `class`.
237
297
 
238
298
  ```
239
- import { hasClass, addClass, removeClass } from 'mazey';
240
-
241
299
  const dom = document.querySelector('#box');
242
300
 
243
301
  // Determine `class`
@@ -255,8 +313,6 @@ Add `<style>` in `<head>`.
255
313
  Case 1: Add the `<style>` with `id`, and repeated invoking will update the content instead of adding a new one.
256
314
 
257
315
  ```
258
- import { addStyle } from 'mazey';
259
-
260
316
  addStyle(
261
317
  `
262
318
  body {
@@ -277,8 +333,6 @@ addStyle(
277
333
  Case 2: Add the `<style>` without `id`, and repeated invoking will adding a new one.
278
334
 
279
335
  ```
280
- import { addStyle } from 'mazey';
281
-
282
336
  addStyle(
283
337
  `
284
338
  body {
@@ -298,8 +352,6 @@ addStyle(
298
352
  Make a newline of HTML.
299
353
 
300
354
  ```
301
- import { newLine } from 'mazey';
302
-
303
355
  newLine('a\nb\nc'); // 'a<br />b<br />c'
304
356
  newLine('a\n\nbc'); // 'a<br /><br />bc'
305
357
  ```
@@ -311,8 +363,6 @@ newLine('a\n\nbc'); // 'a<br /><br />bc'
311
363
  Get the query param's value of the current Web URL(`location.search`).
312
364
 
313
365
  ```
314
- import { getQueryParam } from 'mazey';
315
-
316
366
  // http://example.com/?t1=1&t2=2&t3=3&t4=4#2333
317
367
  // ?t1=1&t2=2&t3=3&t4=4
318
368
  getQueryParam('t3'); // 3
@@ -322,8 +372,6 @@ getQueryParam('t4'); // 4
322
372
  Get the query param's value of the input URL.
323
373
 
324
374
  ```
325
- import { getUrlParam } from 'mazey';
326
-
327
375
  getUrlParam('http://example.com/?t1=1&t2=2&t3=3&t4=4', 't3'); // 3
328
376
  getUrlParam('http://example.com/?t1=1&t2=2&t3=3&t4=4', 't4'); // 4
329
377
  ```
@@ -333,8 +381,6 @@ getUrlParam('http://example.com/?t1=1&t2=2&t3=3&t4=4', 't4'); // 4
333
381
  Update the query param's value of the input URL.
334
382
 
335
383
  ```
336
- import { updateQueryParam } from 'mazey';
337
-
338
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
339
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
340
386
  ```
@@ -344,8 +390,6 @@ updateQueryParam('http://example.com/?t1=1&t2=2&t3=3&t4=4', 't4', 'four'); // ht
344
390
  Get the hash query param's value of the current Web URL(`location.hash`).
345
391
 
346
392
  ```
347
- import { getHashQueryParam } from 'mazey';
348
-
349
393
  // http://example.com/?#2333?t1=1&t2=2&t3=3&t4=4
350
394
  // #2333?t1=1&t2=2&t3=3&t4=4
351
395
  getHashQueryParam('t3'); // 3
@@ -357,8 +401,6 @@ getHashQueryParam('t4'); // 4
357
401
  Get the domain of URL, and other params.
358
402
 
359
403
  ```
360
- import { getDomain } from 'mazey';
361
-
362
404
  getDomain('http://example.com/?t1=1&t2=2&t3=3&t4=4'); // example.com
363
405
  getDomain('http://example.com/test/thanks?t1=1&t2=2&t3=3&t4=4', ['hostname', 'pathname']); // example.com/test/thanks
364
406
  ```
@@ -370,8 +412,6 @@ getDomain('http://example.com/test/thanks?t1=1&t2=2&t3=3&t4=4', ['hostname', 'pa
370
412
  Handle Storage (Keep fit for JSON, it can tansfer format automatically).
371
413
 
372
414
  ```
373
- import { setSessionStorage, getSessionStorage, setLocalStorage, getLocalStorage } from 'mazey';
374
-
375
415
  setSessionStorage('test', '123');
376
416
  getSessionStorage('test'); // 123
377
417
  setLocalStorage('test', '123');
@@ -393,8 +433,6 @@ function mGetLocalStorage (key) {
393
433
  Handle Cookie.
394
434
 
395
435
  ```
396
- import { setCookie, getCookie } from 'mazey';
397
-
398
436
  setCookie('test', '123', 30, 'example.com'); // key value day domain
399
437
  getCookie('test'); // 123
400
438
  ```
@@ -406,8 +444,6 @@ getCookie('test'); // 123
406
444
  Hit probability (1% ~ 100%).
407
445
 
408
446
  ```
409
- import { inRate } from 'mazey';
410
-
411
447
  inRate(0.5); // 0.01 ~ 1 true / false
412
448
 
413
449
  // Test
@@ -428,24 +464,18 @@ console.log(trueCount, falseCount); // 499994 500006
428
464
  Computes the longest common substring of two strings.
429
465
 
430
466
  ```
431
- import { calLongestCommonSubstring } from 'mazey';
432
-
433
467
  calLongestCommonSubstring('fish', 'finish'); // 3
434
468
  ```
435
469
 
436
470
  Computes the longest common subsequence of two strings.
437
471
 
438
472
  ```
439
- import { calLongestCommonSubsequence } from 'mazey';
440
-
441
473
  calLongestCommonSubsequence('fish', 'finish'); // 4
442
474
  ```
443
475
 
444
476
  ### Browser Information
445
477
 
446
478
  ```
447
- import { getBrowserInfo } from 'mazey';
448
-
449
479
  getBrowserInfo(); // {"engine":"webkit","engineVs":"537.36","platform":"desktop","supporter":"chrome","supporterVs":"85.0.4183.121","system":"windows","systemVs":"10"}
450
480
  // Shell and shell version { shell: 'wechat', shellVs: '20' } shell: wechat qq uc 360 2345 sougou liebao maxthon
451
481
  ```
@@ -468,8 +498,6 @@ getBrowserInfo(); // {"engine":"webkit","engineVs":"537.36","platform":"desktop"
468
498
  Get page load time(PerformanceTiming).
469
499
 
470
500
  ```
471
- import { getPerformance } from 'mazey';
472
-
473
501
  // `camelCase:true`(Default) Return hump data.
474
502
  // `camelCase:false` Return underline data.
475
503
  getPerformance(true)
@@ -499,8 +527,6 @@ getPerformance(true)
499
527
  Determine if it is a secure PWA environment that it can run.
500
528
 
501
529
  ```
502
- import { isSafePWAEnv } from 'mazey';
503
-
504
530
  isSafePWAEnv(); // true
505
531
  ```
506
532
 
@@ -511,8 +537,6 @@ isSafePWAEnv(); // true
511
537
  Custom console printing (`console`).
512
538
 
513
539
  ```
514
- import { genCustomConsole } from 'mazey';
515
-
516
540
  const myConsole = genCustomConsole('MazeyLog:');
517
541
  myConsole.log('I am string.'); // MazeyLog: I am string.
518
542
  myConsole.info('I am boolean.', true); // MazeyLog: I am boolean. true
@@ -520,18 +544,25 @@ myConsole.info('I am number.', 123, 456); // MazeyLog: I am number. 123 456
520
544
  myConsole.info('I am object.', { a: 123, b: 456}); // MazeyLog: I am object. {a: 123, b: 456}
521
545
  ```
522
546
 
523
- ## Develop
547
+ ## Contributing
524
548
 
525
549
  ```
526
- # dev
527
- npm run dev;
550
+ # Install
551
+ npm i --registry=https://registry.npmjs.org
528
552
 
529
- # build
530
- npm run build;
553
+ # Serve
554
+ npm run dev
531
555
 
532
- # documentation
533
- npm run docs;
556
+ # Build
557
+ npm run build
534
558
 
535
- # test
536
- npm run test;
559
+ # Document
560
+ npm run docs
561
+
562
+ # Test
563
+ npm run test
537
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).