@daysnap/utils 0.0.34 → 0.0.36
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/docs/modules.md +240 -55
- package/es/filterCRLF.d.ts +4 -0
- package/es/filterCRLF.js +6 -0
- package/es/getBlobByUrl.js +1 -0
- package/es/getRandomColor.d.ts +4 -0
- package/es/getRandomColor.js +6 -0
- package/es/index.d.ts +8 -0
- package/es/index.js +9 -1
- package/es/isArray.d.ts +6 -0
- package/es/isArray.js +8 -0
- package/es/isBoolean.d.ts +5 -0
- package/es/isBoolean.js +7 -0
- package/es/isWeixin.d.ts +4 -0
- package/es/isWeixin.js +6 -0
- package/es/loadResource.d.ts +7 -0
- package/es/loadResource.js +31 -0
- package/es/stringTrim.d.ts +4 -0
- package/es/stringTrim.js +21 -0
- package/es/typeOf.d.ts +6 -0
- package/es/typeOf.js +8 -0
- package/lib/filterCRLF.d.ts +4 -0
- package/lib/filterCRLF.js +12 -0
- package/lib/getBlobByUrl.js +1 -0
- package/lib/getRandomColor.d.ts +4 -0
- package/lib/getRandomColor.js +12 -0
- package/lib/index.d.ts +8 -0
- package/lib/index.js +88 -0
- package/lib/isArray.d.ts +6 -0
- package/lib/isArray.js +14 -0
- package/lib/isBoolean.d.ts +5 -0
- package/lib/isBoolean.js +13 -0
- package/lib/isWeixin.d.ts +4 -0
- package/lib/isWeixin.js +12 -0
- package/lib/loadResource.d.ts +7 -0
- package/lib/loadResource.js +37 -0
- package/lib/stringTrim.d.ts +4 -0
- package/lib/stringTrim.js +27 -0
- package/lib/typeOf.d.ts +6 -0
- package/lib/typeOf.js +14 -0
- package/package.json +1 -1
package/es/index.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ export * from './createHexColorByHash';
|
|
|
7
7
|
export * from './downloadFile';
|
|
8
8
|
export * from './each';
|
|
9
9
|
export * from './filterBankCardNo';
|
|
10
|
+
export * from './filterCRLF';
|
|
10
11
|
export * from './filterEmoji';
|
|
11
12
|
export * from './filterIdCard';
|
|
12
13
|
export * from './filterName';
|
|
@@ -16,9 +17,12 @@ export * from './formatDate';
|
|
|
16
17
|
export * from './getBlobByUrl';
|
|
17
18
|
export * from './getDayMillisecond';
|
|
18
19
|
export * from './getImageInfo';
|
|
20
|
+
export * from './getRandomColor';
|
|
19
21
|
export * from './getVideoInfo';
|
|
20
22
|
export * from './inBrowser';
|
|
21
23
|
export * from './isAndroid';
|
|
24
|
+
export * from './isArray';
|
|
25
|
+
export * from './isBoolean';
|
|
22
26
|
export * from './isEmail';
|
|
23
27
|
export * from './isEmpty';
|
|
24
28
|
export * from './isEmptyObject';
|
|
@@ -38,7 +42,9 @@ export * from './isPromise';
|
|
|
38
42
|
export * from './isRegExp';
|
|
39
43
|
export * from './isString';
|
|
40
44
|
export * from './isUndefined';
|
|
45
|
+
export * from './isWeixin';
|
|
41
46
|
export * from './isWindow';
|
|
47
|
+
export * from './loadResource';
|
|
42
48
|
export * from './omit';
|
|
43
49
|
export * from './parseDate';
|
|
44
50
|
export * from './parseError';
|
|
@@ -50,4 +56,6 @@ export * from './reserve';
|
|
|
50
56
|
export * from './round';
|
|
51
57
|
export * from './sleep';
|
|
52
58
|
export * from './storage';
|
|
59
|
+
export * from './stringTrim';
|
|
53
60
|
export * from './stringifyQuery';
|
|
61
|
+
export * from './typeOf';
|
package/es/index.js
CHANGED
|
@@ -8,6 +8,7 @@ export * from './createHexColorByHash';
|
|
|
8
8
|
export * from './downloadFile';
|
|
9
9
|
export * from './each';
|
|
10
10
|
export * from './filterBankCardNo';
|
|
11
|
+
export * from './filterCRLF';
|
|
11
12
|
export * from './filterEmoji';
|
|
12
13
|
export * from './filterIdCard';
|
|
13
14
|
export * from './filterName';
|
|
@@ -17,9 +18,12 @@ export * from './formatDate';
|
|
|
17
18
|
export * from './getBlobByUrl';
|
|
18
19
|
export * from './getDayMillisecond';
|
|
19
20
|
export * from './getImageInfo';
|
|
21
|
+
export * from './getRandomColor';
|
|
20
22
|
export * from './getVideoInfo';
|
|
21
23
|
export * from './inBrowser';
|
|
22
24
|
export * from './isAndroid';
|
|
25
|
+
export * from './isArray';
|
|
26
|
+
export * from './isBoolean';
|
|
23
27
|
export * from './isEmail';
|
|
24
28
|
export * from './isEmpty';
|
|
25
29
|
export * from './isEmptyObject';
|
|
@@ -39,7 +43,9 @@ export * from './isPromise';
|
|
|
39
43
|
export * from './isRegExp';
|
|
40
44
|
export * from './isString';
|
|
41
45
|
export * from './isUndefined';
|
|
46
|
+
export * from './isWeixin';
|
|
42
47
|
export * from './isWindow';
|
|
48
|
+
export * from './loadResource';
|
|
43
49
|
export * from './omit';
|
|
44
50
|
export * from './parseDate';
|
|
45
51
|
export * from './parseError';
|
|
@@ -51,4 +57,6 @@ export * from './reserve';
|
|
|
51
57
|
export * from './round';
|
|
52
58
|
export * from './sleep';
|
|
53
59
|
export * from './storage';
|
|
54
|
-
export * from './
|
|
60
|
+
export * from './stringTrim';
|
|
61
|
+
export * from './stringifyQuery';
|
|
62
|
+
export * from './typeOf';
|
package/es/isArray.d.ts
ADDED
package/es/isArray.js
ADDED
package/es/isBoolean.js
ADDED
package/es/isWeixin.d.ts
ADDED
package/es/isWeixin.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { isFunction } from './isFunction';
|
|
2
|
+
/**
|
|
3
|
+
* 加载外部js、css、写入style样式
|
|
4
|
+
* @param res 资源url或内容
|
|
5
|
+
* @param type 类型
|
|
6
|
+
* @param callback 回调函数
|
|
7
|
+
*/
|
|
8
|
+
export function loadResource(res, type, callback) {
|
|
9
|
+
var ref;
|
|
10
|
+
if (type === 'js') {
|
|
11
|
+
// 外部js
|
|
12
|
+
ref = document.createElement('js');
|
|
13
|
+
ref.setAttribute('type', 'text/javascript');
|
|
14
|
+
ref.setAttribute('src', res);
|
|
15
|
+
} else if (type === 'css') {
|
|
16
|
+
// 外部css
|
|
17
|
+
ref = document.createElement('link');
|
|
18
|
+
ref.setAttribute('rel', 'stylesheet');
|
|
19
|
+
ref.setAttribute('type', 'text/css');
|
|
20
|
+
ref.setAttribute('href', res);
|
|
21
|
+
} else if (type === 'style') {
|
|
22
|
+
ref = document.createElement('style');
|
|
23
|
+
ref.innerHTML = res;
|
|
24
|
+
}
|
|
25
|
+
if (ref) {
|
|
26
|
+
document.querySelector('head').appendChild(ref);
|
|
27
|
+
ref.onload = function () {
|
|
28
|
+
if (isFunction(callback)) callback();
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
}
|
package/es/stringTrim.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*去除字符串空格
|
|
3
|
+
*/
|
|
4
|
+
export function stringTrim(str, type) {
|
|
5
|
+
var _type;
|
|
6
|
+
// 1-所有空格,2-前后空格,3-前空格,4-后空格
|
|
7
|
+
// eslint-disable-next-line no-param-reassign
|
|
8
|
+
type = (_type = type) !== null && _type !== void 0 ? _type : 1;
|
|
9
|
+
switch (type) {
|
|
10
|
+
case 1:
|
|
11
|
+
return str.replace(/\s+/g, '');
|
|
12
|
+
case 2:
|
|
13
|
+
return str.replace(/(^\s*)|(\s*$)/g, '');
|
|
14
|
+
case 3:
|
|
15
|
+
return str.replace(/(^\s*)/g, '');
|
|
16
|
+
case 4:
|
|
17
|
+
return str.replace(/(\s*$)/g, '');
|
|
18
|
+
default:
|
|
19
|
+
return str;
|
|
20
|
+
}
|
|
21
|
+
}
|
package/es/typeOf.d.ts
ADDED
package/es/typeOf.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 判断类型
|
|
3
|
+
* @param val 待判断数据
|
|
4
|
+
* @returns 'undefined'|'null'|'boolean'|'string'|'number'|'object'|'array'|'function'|'symbol'|'map'|'weakmap'|'bigint'|'regexp'|'date'
|
|
5
|
+
*/
|
|
6
|
+
export function typeOf(val) {
|
|
7
|
+
return Object.prototype.toString.call(val).slice(8, -1).toLowerCase();
|
|
8
|
+
}
|
package/lib/getBlobByUrl.js
CHANGED
package/lib/index.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ export * from './createHexColorByHash';
|
|
|
7
7
|
export * from './downloadFile';
|
|
8
8
|
export * from './each';
|
|
9
9
|
export * from './filterBankCardNo';
|
|
10
|
+
export * from './filterCRLF';
|
|
10
11
|
export * from './filterEmoji';
|
|
11
12
|
export * from './filterIdCard';
|
|
12
13
|
export * from './filterName';
|
|
@@ -16,9 +17,12 @@ export * from './formatDate';
|
|
|
16
17
|
export * from './getBlobByUrl';
|
|
17
18
|
export * from './getDayMillisecond';
|
|
18
19
|
export * from './getImageInfo';
|
|
20
|
+
export * from './getRandomColor';
|
|
19
21
|
export * from './getVideoInfo';
|
|
20
22
|
export * from './inBrowser';
|
|
21
23
|
export * from './isAndroid';
|
|
24
|
+
export * from './isArray';
|
|
25
|
+
export * from './isBoolean';
|
|
22
26
|
export * from './isEmail';
|
|
23
27
|
export * from './isEmpty';
|
|
24
28
|
export * from './isEmptyObject';
|
|
@@ -38,7 +42,9 @@ export * from './isPromise';
|
|
|
38
42
|
export * from './isRegExp';
|
|
39
43
|
export * from './isString';
|
|
40
44
|
export * from './isUndefined';
|
|
45
|
+
export * from './isWeixin';
|
|
41
46
|
export * from './isWindow';
|
|
47
|
+
export * from './loadResource';
|
|
42
48
|
export * from './omit';
|
|
43
49
|
export * from './parseDate';
|
|
44
50
|
export * from './parseError';
|
|
@@ -50,4 +56,6 @@ export * from './reserve';
|
|
|
50
56
|
export * from './round';
|
|
51
57
|
export * from './sleep';
|
|
52
58
|
export * from './storage';
|
|
59
|
+
export * from './stringTrim';
|
|
53
60
|
export * from './stringifyQuery';
|
|
61
|
+
export * from './typeOf';
|
package/lib/index.js
CHANGED
|
@@ -102,6 +102,17 @@ Object.keys(_filterBankCardNo).forEach(function (key) {
|
|
|
102
102
|
}
|
|
103
103
|
});
|
|
104
104
|
});
|
|
105
|
+
var _filterCRLF = require("./filterCRLF");
|
|
106
|
+
Object.keys(_filterCRLF).forEach(function (key) {
|
|
107
|
+
if (key === "default" || key === "__esModule") return;
|
|
108
|
+
if (key in exports && exports[key] === _filterCRLF[key]) return;
|
|
109
|
+
Object.defineProperty(exports, key, {
|
|
110
|
+
enumerable: true,
|
|
111
|
+
get: function get() {
|
|
112
|
+
return _filterCRLF[key];
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
});
|
|
105
116
|
var _filterEmoji = require("./filterEmoji");
|
|
106
117
|
Object.keys(_filterEmoji).forEach(function (key) {
|
|
107
118
|
if (key === "default" || key === "__esModule") return;
|
|
@@ -201,6 +212,17 @@ Object.keys(_getImageInfo).forEach(function (key) {
|
|
|
201
212
|
}
|
|
202
213
|
});
|
|
203
214
|
});
|
|
215
|
+
var _getRandomColor = require("./getRandomColor");
|
|
216
|
+
Object.keys(_getRandomColor).forEach(function (key) {
|
|
217
|
+
if (key === "default" || key === "__esModule") return;
|
|
218
|
+
if (key in exports && exports[key] === _getRandomColor[key]) return;
|
|
219
|
+
Object.defineProperty(exports, key, {
|
|
220
|
+
enumerable: true,
|
|
221
|
+
get: function get() {
|
|
222
|
+
return _getRandomColor[key];
|
|
223
|
+
}
|
|
224
|
+
});
|
|
225
|
+
});
|
|
204
226
|
var _getVideoInfo = require("./getVideoInfo");
|
|
205
227
|
Object.keys(_getVideoInfo).forEach(function (key) {
|
|
206
228
|
if (key === "default" || key === "__esModule") return;
|
|
@@ -234,6 +256,28 @@ Object.keys(_isAndroid).forEach(function (key) {
|
|
|
234
256
|
}
|
|
235
257
|
});
|
|
236
258
|
});
|
|
259
|
+
var _isArray = require("./isArray");
|
|
260
|
+
Object.keys(_isArray).forEach(function (key) {
|
|
261
|
+
if (key === "default" || key === "__esModule") return;
|
|
262
|
+
if (key in exports && exports[key] === _isArray[key]) return;
|
|
263
|
+
Object.defineProperty(exports, key, {
|
|
264
|
+
enumerable: true,
|
|
265
|
+
get: function get() {
|
|
266
|
+
return _isArray[key];
|
|
267
|
+
}
|
|
268
|
+
});
|
|
269
|
+
});
|
|
270
|
+
var _isBoolean = require("./isBoolean");
|
|
271
|
+
Object.keys(_isBoolean).forEach(function (key) {
|
|
272
|
+
if (key === "default" || key === "__esModule") return;
|
|
273
|
+
if (key in exports && exports[key] === _isBoolean[key]) return;
|
|
274
|
+
Object.defineProperty(exports, key, {
|
|
275
|
+
enumerable: true,
|
|
276
|
+
get: function get() {
|
|
277
|
+
return _isBoolean[key];
|
|
278
|
+
}
|
|
279
|
+
});
|
|
280
|
+
});
|
|
237
281
|
var _isEmail = require("./isEmail");
|
|
238
282
|
Object.keys(_isEmail).forEach(function (key) {
|
|
239
283
|
if (key === "default" || key === "__esModule") return;
|
|
@@ -443,6 +487,17 @@ Object.keys(_isUndefined).forEach(function (key) {
|
|
|
443
487
|
}
|
|
444
488
|
});
|
|
445
489
|
});
|
|
490
|
+
var _isWeixin = require("./isWeixin");
|
|
491
|
+
Object.keys(_isWeixin).forEach(function (key) {
|
|
492
|
+
if (key === "default" || key === "__esModule") return;
|
|
493
|
+
if (key in exports && exports[key] === _isWeixin[key]) return;
|
|
494
|
+
Object.defineProperty(exports, key, {
|
|
495
|
+
enumerable: true,
|
|
496
|
+
get: function get() {
|
|
497
|
+
return _isWeixin[key];
|
|
498
|
+
}
|
|
499
|
+
});
|
|
500
|
+
});
|
|
446
501
|
var _isWindow = require("./isWindow");
|
|
447
502
|
Object.keys(_isWindow).forEach(function (key) {
|
|
448
503
|
if (key === "default" || key === "__esModule") return;
|
|
@@ -454,6 +509,17 @@ Object.keys(_isWindow).forEach(function (key) {
|
|
|
454
509
|
}
|
|
455
510
|
});
|
|
456
511
|
});
|
|
512
|
+
var _loadResource = require("./loadResource");
|
|
513
|
+
Object.keys(_loadResource).forEach(function (key) {
|
|
514
|
+
if (key === "default" || key === "__esModule") return;
|
|
515
|
+
if (key in exports && exports[key] === _loadResource[key]) return;
|
|
516
|
+
Object.defineProperty(exports, key, {
|
|
517
|
+
enumerable: true,
|
|
518
|
+
get: function get() {
|
|
519
|
+
return _loadResource[key];
|
|
520
|
+
}
|
|
521
|
+
});
|
|
522
|
+
});
|
|
457
523
|
var _omit = require("./omit");
|
|
458
524
|
Object.keys(_omit).forEach(function (key) {
|
|
459
525
|
if (key === "default" || key === "__esModule") return;
|
|
@@ -575,6 +641,17 @@ Object.keys(_storage).forEach(function (key) {
|
|
|
575
641
|
}
|
|
576
642
|
});
|
|
577
643
|
});
|
|
644
|
+
var _stringTrim = require("./stringTrim");
|
|
645
|
+
Object.keys(_stringTrim).forEach(function (key) {
|
|
646
|
+
if (key === "default" || key === "__esModule") return;
|
|
647
|
+
if (key in exports && exports[key] === _stringTrim[key]) return;
|
|
648
|
+
Object.defineProperty(exports, key, {
|
|
649
|
+
enumerable: true,
|
|
650
|
+
get: function get() {
|
|
651
|
+
return _stringTrim[key];
|
|
652
|
+
}
|
|
653
|
+
});
|
|
654
|
+
});
|
|
578
655
|
var _stringifyQuery = require("./stringifyQuery");
|
|
579
656
|
Object.keys(_stringifyQuery).forEach(function (key) {
|
|
580
657
|
if (key === "default" || key === "__esModule") return;
|
|
@@ -585,4 +662,15 @@ Object.keys(_stringifyQuery).forEach(function (key) {
|
|
|
585
662
|
return _stringifyQuery[key];
|
|
586
663
|
}
|
|
587
664
|
});
|
|
665
|
+
});
|
|
666
|
+
var _typeOf = require("./typeOf");
|
|
667
|
+
Object.keys(_typeOf).forEach(function (key) {
|
|
668
|
+
if (key === "default" || key === "__esModule") return;
|
|
669
|
+
if (key in exports && exports[key] === _typeOf[key]) return;
|
|
670
|
+
Object.defineProperty(exports, key, {
|
|
671
|
+
enumerable: true,
|
|
672
|
+
get: function get() {
|
|
673
|
+
return _typeOf[key];
|
|
674
|
+
}
|
|
675
|
+
});
|
|
588
676
|
});
|
package/lib/isArray.d.ts
ADDED
package/lib/isArray.js
ADDED
package/lib/isBoolean.js
ADDED
package/lib/isWeixin.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.loadResource = loadResource;
|
|
7
|
+
var _isFunction = require("./isFunction");
|
|
8
|
+
/**
|
|
9
|
+
* 加载外部js、css、写入style样式
|
|
10
|
+
* @param res 资源url或内容
|
|
11
|
+
* @param type 类型
|
|
12
|
+
* @param callback 回调函数
|
|
13
|
+
*/
|
|
14
|
+
function loadResource(res, type, callback) {
|
|
15
|
+
var ref;
|
|
16
|
+
if (type === 'js') {
|
|
17
|
+
// 外部js
|
|
18
|
+
ref = document.createElement('js');
|
|
19
|
+
ref.setAttribute('type', 'text/javascript');
|
|
20
|
+
ref.setAttribute('src', res);
|
|
21
|
+
} else if (type === 'css') {
|
|
22
|
+
// 外部css
|
|
23
|
+
ref = document.createElement('link');
|
|
24
|
+
ref.setAttribute('rel', 'stylesheet');
|
|
25
|
+
ref.setAttribute('type', 'text/css');
|
|
26
|
+
ref.setAttribute('href', res);
|
|
27
|
+
} else if (type === 'style') {
|
|
28
|
+
ref = document.createElement('style');
|
|
29
|
+
ref.innerHTML = res;
|
|
30
|
+
}
|
|
31
|
+
if (ref) {
|
|
32
|
+
document.querySelector('head').appendChild(ref);
|
|
33
|
+
ref.onload = function () {
|
|
34
|
+
if ((0, _isFunction.isFunction)(callback)) callback();
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.stringTrim = stringTrim;
|
|
7
|
+
/**
|
|
8
|
+
*去除字符串空格
|
|
9
|
+
*/
|
|
10
|
+
function stringTrim(str, type) {
|
|
11
|
+
var _type;
|
|
12
|
+
// 1-所有空格,2-前后空格,3-前空格,4-后空格
|
|
13
|
+
// eslint-disable-next-line no-param-reassign
|
|
14
|
+
type = (_type = type) !== null && _type !== void 0 ? _type : 1;
|
|
15
|
+
switch (type) {
|
|
16
|
+
case 1:
|
|
17
|
+
return str.replace(/\s+/g, '');
|
|
18
|
+
case 2:
|
|
19
|
+
return str.replace(/(^\s*)|(\s*$)/g, '');
|
|
20
|
+
case 3:
|
|
21
|
+
return str.replace(/(^\s*)/g, '');
|
|
22
|
+
case 4:
|
|
23
|
+
return str.replace(/(\s*$)/g, '');
|
|
24
|
+
default:
|
|
25
|
+
return str;
|
|
26
|
+
}
|
|
27
|
+
}
|
package/lib/typeOf.d.ts
ADDED
package/lib/typeOf.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.typeOf = typeOf;
|
|
7
|
+
/**
|
|
8
|
+
* 判断类型
|
|
9
|
+
* @param val 待判断数据
|
|
10
|
+
* @returns 'undefined'|'null'|'boolean'|'string'|'number'|'object'|'array'|'function'|'symbol'|'map'|'weakmap'|'bigint'|'regexp'|'date'
|
|
11
|
+
*/
|
|
12
|
+
function typeOf(val) {
|
|
13
|
+
return Object.prototype.toString.call(val).slice(8, -1).toLowerCase();
|
|
14
|
+
}
|