@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.
@@ -0,0 +1,4 @@
1
+ /**
2
+ * 随机颜色
3
+ */
4
+ export declare function getRandomColor(): string;
@@ -0,0 +1,6 @@
1
+ /**
2
+ * 随机颜色
3
+ */
4
+ export function getRandomColor() {
5
+ return "#".concat(Math.floor(Math.random() * 0xffffff).toString(16));
6
+ }
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 './stringifyQuery';
60
+ export * from './stringTrim';
61
+ export * from './stringifyQuery';
62
+ export * from './typeOf';
@@ -0,0 +1,6 @@
1
+ /**
2
+ * 判断是否是数组
3
+ * @param val 待判断值
4
+ * @returns 是否
5
+ */
6
+ export declare function isArray(val: unknown): val is any[];
package/es/isArray.js ADDED
@@ -0,0 +1,8 @@
1
+ /**
2
+ * 判断是否是数组
3
+ * @param val 待判断值
4
+ * @returns 是否
5
+ */
6
+ export function isArray(val) {
7
+ return Array.isArray(val);
8
+ }
@@ -0,0 +1,5 @@
1
+ /**
2
+ * 判断是否是布尔值
3
+ * @param val 需要判断的值
4
+ */
5
+ export declare function isBoolean(val: unknown): val is boolean;
@@ -0,0 +1,7 @@
1
+ /**
2
+ * 判断是否是布尔值
3
+ * @param val 需要判断的值
4
+ */
5
+ export function isBoolean(val) {
6
+ return typeof val === 'boolean';
7
+ }
@@ -0,0 +1,4 @@
1
+ /**
2
+ * 是否是微信环境
3
+ */
4
+ export declare function isWeixin(): boolean;
package/es/isWeixin.js ADDED
@@ -0,0 +1,6 @@
1
+ /**
2
+ * 是否是微信环境
3
+ */
4
+ export function isWeixin() {
5
+ return /MicroMessenger/gi.test(navigator.userAgent);
6
+ }
@@ -0,0 +1,7 @@
1
+ /**
2
+ * 加载外部js、css、写入style样式
3
+ * @param res 资源url或内容
4
+ * @param type 类型
5
+ * @param callback 回调函数
6
+ */
7
+ export declare function loadResource(res: string, type: 'js' | 'css' | 'style', callback?: any): void;
@@ -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
+ }
@@ -0,0 +1,4 @@
1
+ /**
2
+ *去除字符串空格
3
+ */
4
+ export declare function stringTrim(str: string, type?: 1 | 2 | 3 | 4): string;
@@ -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
@@ -0,0 +1,6 @@
1
+ /**
2
+ * 判断类型
3
+ * @param val 待判断数据
4
+ * @returns 'undefined'|'null'|'boolean'|'string'|'number'|'object'|'array'|'function'|'symbol'|'map'|'weakmap'|'bigint'|'regexp'|'date'
5
+ */
6
+ export declare function typeOf<T>(val: T): val is T;
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
+ }
@@ -0,0 +1,4 @@
1
+ /**
2
+ * 替换字符串里面的回车换行符
3
+ */
4
+ export declare function filterCRLF(v: string): string;
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.filterCRLF = filterCRLF;
7
+ /**
8
+ * 替换字符串里面的回车换行符
9
+ */
10
+ function filterCRLF(v) {
11
+ return v.replace(/\r|\n/gi, '<br/>');
12
+ }
@@ -23,5 +23,6 @@ function getBlobByUrl(url) {
23
23
  reject(new Error("".concat(statusText, "[").concat(status, "]")));
24
24
  }
25
25
  };
26
+ xhr.send();
26
27
  });
27
28
  }
@@ -0,0 +1,4 @@
1
+ /**
2
+ * 随机颜色
3
+ */
4
+ export declare function getRandomColor(): string;
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.getRandomColor = getRandomColor;
7
+ /**
8
+ * 随机颜色
9
+ */
10
+ function getRandomColor() {
11
+ return "#".concat(Math.floor(Math.random() * 0xffffff).toString(16));
12
+ }
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
  });
@@ -0,0 +1,6 @@
1
+ /**
2
+ * 判断是否是数组
3
+ * @param val 待判断值
4
+ * @returns 是否
5
+ */
6
+ export declare function isArray(val: unknown): val is any[];
package/lib/isArray.js ADDED
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.isArray = isArray;
7
+ /**
8
+ * 判断是否是数组
9
+ * @param val 待判断值
10
+ * @returns 是否
11
+ */
12
+ function isArray(val) {
13
+ return Array.isArray(val);
14
+ }
@@ -0,0 +1,5 @@
1
+ /**
2
+ * 判断是否是布尔值
3
+ * @param val 需要判断的值
4
+ */
5
+ export declare function isBoolean(val: unknown): val is boolean;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.isBoolean = isBoolean;
7
+ /**
8
+ * 判断是否是布尔值
9
+ * @param val 需要判断的值
10
+ */
11
+ function isBoolean(val) {
12
+ return typeof val === 'boolean';
13
+ }
@@ -0,0 +1,4 @@
1
+ /**
2
+ * 是否是微信环境
3
+ */
4
+ export declare function isWeixin(): boolean;
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.isWeixin = isWeixin;
7
+ /**
8
+ * 是否是微信环境
9
+ */
10
+ function isWeixin() {
11
+ return /MicroMessenger/gi.test(navigator.userAgent);
12
+ }
@@ -0,0 +1,7 @@
1
+ /**
2
+ * 加载外部js、css、写入style样式
3
+ * @param res 资源url或内容
4
+ * @param type 类型
5
+ * @param callback 回调函数
6
+ */
7
+ export declare function loadResource(res: string, type: 'js' | 'css' | 'style', callback?: any): void;
@@ -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,4 @@
1
+ /**
2
+ *去除字符串空格
3
+ */
4
+ export declare function stringTrim(str: string, type?: 1 | 2 | 3 | 4): string;
@@ -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
+ }
@@ -0,0 +1,6 @@
1
+ /**
2
+ * 判断类型
3
+ * @param val 待判断数据
4
+ * @returns 'undefined'|'null'|'boolean'|'string'|'number'|'object'|'array'|'function'|'symbol'|'map'|'weakmap'|'bigint'|'regexp'|'date'
5
+ */
6
+ export declare function typeOf<T>(val: T): val is T;
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
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@daysnap/utils",
3
- "version": "0.0.34",
3
+ "version": "0.0.36",
4
4
  "description": "通用的工具库",
5
5
  "main": "lib/index.js",
6
6
  "module": "es/index.js",