@daysnap/utils 0.0.29 → 0.0.31

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.
Files changed (49) hide show
  1. package/README.md +4 -0
  2. package/docs/.nojekyll +1 -0
  3. package/docs/README.md +18 -0
  4. package/docs/modules.md +1209 -0
  5. package/es/compareVersion.d.ts +6 -4
  6. package/es/compareVersion.js +14 -12
  7. package/es/inBrowser.d.ts +4 -0
  8. package/es/inBrowser.js +6 -0
  9. package/es/index.d.ts +9 -0
  10. package/es/index.js +10 -1
  11. package/es/isEmptyObject.d.ts +5 -0
  12. package/es/isEmptyObject.js +7 -0
  13. package/es/isError.d.ts +4 -0
  14. package/es/isError.js +6 -0
  15. package/es/isJSONString.d.ts +5 -0
  16. package/es/isJSONString.js +13 -0
  17. package/es/isLicenseCode.d.ts +5 -0
  18. package/es/isLicenseCode.js +7 -0
  19. package/es/isWindow.d.ts +5 -0
  20. package/es/isWindow.js +7 -0
  21. package/es/parseQuery.d.ts +6 -0
  22. package/es/parseQuery.js +33 -0
  23. package/es/sleep.d.ts +4 -0
  24. package/es/sleep.js +9 -0
  25. package/es/stringifyQuery.d.ts +4 -0
  26. package/es/stringifyQuery.js +13 -0
  27. package/lib/compareVersion.d.ts +6 -4
  28. package/lib/compareVersion.js +14 -12
  29. package/lib/inBrowser.d.ts +4 -0
  30. package/lib/inBrowser.js +12 -0
  31. package/lib/index.d.ts +9 -0
  32. package/lib/index.js +99 -0
  33. package/lib/isEmptyObject.d.ts +5 -0
  34. package/lib/isEmptyObject.js +13 -0
  35. package/lib/isError.d.ts +4 -0
  36. package/lib/isError.js +12 -0
  37. package/lib/isJSONString.d.ts +5 -0
  38. package/lib/isJSONString.js +19 -0
  39. package/lib/isLicenseCode.d.ts +5 -0
  40. package/lib/isLicenseCode.js +13 -0
  41. package/lib/isWindow.d.ts +5 -0
  42. package/lib/isWindow.js +13 -0
  43. package/lib/parseQuery.d.ts +6 -0
  44. package/lib/parseQuery.js +40 -0
  45. package/lib/sleep.d.ts +4 -0
  46. package/lib/sleep.js +15 -0
  47. package/lib/stringifyQuery.d.ts +4 -0
  48. package/lib/stringifyQuery.js +19 -0
  49. package/package.json +9 -4
@@ -1,7 +1,9 @@
1
1
  /**
2
2
  * 比对版本
3
- * -1 => V < v
4
- * 0 => V === v
5
- * 1 => V > v
3
+ * -1 => nv < v
4
+ * 0 => nv === v
5
+ * 1 => nv > v
6
+ * @param nv 新版本
7
+ * @param v 版本
6
8
  */
7
- export declare function compareVersion(V: string, v: string): number;
9
+ export declare function compareVersion(nv: string, v: string): -1 | 0 | 1;
@@ -1,21 +1,23 @@
1
1
  import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
2
2
  /**
3
3
  * 比对版本
4
- * -1 => V < v
5
- * 0 => V === v
6
- * 1 => V > v
4
+ * -1 => nv < v
5
+ * 0 => nv === v
6
+ * 1 => nv > v
7
+ * @param nv 新版本
8
+ * @param v 版本
7
9
  */
8
- export function compareVersion(V, v) {
9
- var _V$split$map = V.split('.').map(function (i) {
10
+ export function compareVersion(nv, v) {
11
+ var _nv$split$map = nv.split('.').map(function (i) {
10
12
  return +i;
11
13
  }),
12
- _V$split$map2 = _slicedToArray(_V$split$map, 3),
13
- _V$split$map2$ = _V$split$map2[0],
14
- H = _V$split$map2$ === void 0 ? 0 : _V$split$map2$,
15
- _V$split$map2$2 = _V$split$map2[1],
16
- T = _V$split$map2$2 === void 0 ? 0 : _V$split$map2$2,
17
- _V$split$map2$3 = _V$split$map2[2],
18
- S = _V$split$map2$3 === void 0 ? 0 : _V$split$map2$3; // 新
14
+ _nv$split$map2 = _slicedToArray(_nv$split$map, 3),
15
+ _nv$split$map2$ = _nv$split$map2[0],
16
+ H = _nv$split$map2$ === void 0 ? 0 : _nv$split$map2$,
17
+ _nv$split$map2$2 = _nv$split$map2[1],
18
+ T = _nv$split$map2$2 === void 0 ? 0 : _nv$split$map2$2,
19
+ _nv$split$map2$3 = _nv$split$map2[2],
20
+ S = _nv$split$map2$3 === void 0 ? 0 : _nv$split$map2$3; // 新
19
21
  var _v$split$map = v.split('.').map(function (i) {
20
22
  return +i;
21
23
  }),
@@ -0,0 +1,4 @@
1
+ /**
2
+ * 判断是否是浏览器环境
3
+ */
4
+ export declare function inBrowser(): boolean;
@@ -0,0 +1,6 @@
1
+ /**
2
+ * 判断是否是浏览器环境
3
+ */
4
+ export function inBrowser() {
5
+ return typeof window !== 'undefined';
6
+ }
package/es/index.d.ts CHANGED
@@ -16,12 +16,17 @@ export * from './getBlobByUrl';
16
16
  export * from './getDayMillisecond';
17
17
  export * from './getImageInfo';
18
18
  export * from './getVideoInfo';
19
+ export * from './inBrowser';
19
20
  export * from './isAndroid';
20
21
  export * from './isEmail';
21
22
  export * from './isEmpty';
23
+ export * from './isEmptyObject';
24
+ export * from './isError';
22
25
  export * from './isFunction';
23
26
  export * from './isIOS';
24
27
  export * from './isIdCard';
28
+ export * from './isJSONString';
29
+ export * from './isLicenseCode';
25
30
  export * from './isMobile';
26
31
  export * from './isNull';
27
32
  export * from './isObject';
@@ -30,11 +35,15 @@ export * from './isPromise';
30
35
  export * from './isRegExp';
31
36
  export * from './isString';
32
37
  export * from './isUndefined';
38
+ export * from './isWindow';
33
39
  export * from './omit';
34
40
  export * from './parseDate';
35
41
  export * from './parseError';
36
42
  export * from './parsePath';
43
+ export * from './parseQuery';
37
44
  export * from './pick';
38
45
  export * from './replaceCrlf';
39
46
  export * from './reserve';
47
+ export * from './sleep';
40
48
  export * from './storage';
49
+ export * from './stringifyQuery';
package/es/index.js CHANGED
@@ -17,12 +17,17 @@ export * from './getBlobByUrl';
17
17
  export * from './getDayMillisecond';
18
18
  export * from './getImageInfo';
19
19
  export * from './getVideoInfo';
20
+ export * from './inBrowser';
20
21
  export * from './isAndroid';
21
22
  export * from './isEmail';
22
23
  export * from './isEmpty';
24
+ export * from './isEmptyObject';
25
+ export * from './isError';
23
26
  export * from './isFunction';
24
27
  export * from './isIOS';
25
28
  export * from './isIdCard';
29
+ export * from './isJSONString';
30
+ export * from './isLicenseCode';
26
31
  export * from './isMobile';
27
32
  export * from './isNull';
28
33
  export * from './isObject';
@@ -31,11 +36,15 @@ export * from './isPromise';
31
36
  export * from './isRegExp';
32
37
  export * from './isString';
33
38
  export * from './isUndefined';
39
+ export * from './isWindow';
34
40
  export * from './omit';
35
41
  export * from './parseDate';
36
42
  export * from './parseError';
37
43
  export * from './parsePath';
44
+ export * from './parseQuery';
38
45
  export * from './pick';
39
46
  export * from './replaceCrlf';
40
47
  export * from './reserve';
41
- export * from './storage';
48
+ export * from './sleep';
49
+ export * from './storage';
50
+ export * from './stringifyQuery';
@@ -0,0 +1,5 @@
1
+ /**
2
+ * 判断是否是空对象
3
+ * @param v 对象
4
+ */
5
+ export declare function isEmptyObject(v: object): boolean;
@@ -0,0 +1,7 @@
1
+ /**
2
+ * 判断是否是空对象
3
+ * @param v 对象
4
+ */
5
+ export function isEmptyObject(v) {
6
+ return !Object.keys(v).length;
7
+ }
@@ -0,0 +1,4 @@
1
+ /**
2
+ * 校验是否是 error
3
+ */
4
+ export declare function isError(val: unknown): val is Error;
package/es/isError.js ADDED
@@ -0,0 +1,6 @@
1
+ /**
2
+ * 校验是否是 error
3
+ */
4
+ export function isError(val) {
5
+ return val instanceof Error;
6
+ }
@@ -0,0 +1,5 @@
1
+ /**
2
+ * 是否是JSON 字符串
3
+ * @param v
4
+ */
5
+ export declare function isJSONString(v: string): boolean;
@@ -0,0 +1,13 @@
1
+ import { isObject } from './isObject';
2
+ /**
3
+ * 是否是JSON 字符串
4
+ * @param v
5
+ */
6
+ export function isJSONString(v) {
7
+ try {
8
+ var obj = JSON.parse(v);
9
+ return isObject(obj);
10
+ } catch (_unused) {
11
+ return false;
12
+ }
13
+ }
@@ -0,0 +1,5 @@
1
+ /**
2
+ * 校验是否是车牌号
3
+ * @param v 车牌号
4
+ */
5
+ export declare function isLicenseCode(v: string): boolean;
@@ -0,0 +1,7 @@
1
+ /**
2
+ * 校验是否是车牌号
3
+ * @param v 车牌号
4
+ */
5
+ export function isLicenseCode(v) {
6
+ return /(^[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领A-Z]{1}[A-Z]{1}[A-Z0-9]{4,5}[A-Z0-9挂学警港澳]{1}$)/.test(v);
7
+ }
@@ -0,0 +1,5 @@
1
+ /**
2
+ * 判断是否是 window 对象
3
+ * @param val 需要判断的值
4
+ */
5
+ export declare function isWindow(val: unknown): val is Window;
package/es/isWindow.js ADDED
@@ -0,0 +1,7 @@
1
+ /**
2
+ * 判断是否是 window 对象
3
+ * @param val 需要判断的值
4
+ */
5
+ export function isWindow(val) {
6
+ return val === window;
7
+ }
@@ -0,0 +1,6 @@
1
+ /**
2
+ * 解析url参数
3
+ * @param v URl
4
+ * @param k 键名
5
+ */
6
+ export declare function parseQuery(v?: string, k?: string): {};
@@ -0,0 +1,33 @@
1
+ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
2
+ import _createForOfIteratorHelper from "@babel/runtime/helpers/esm/createForOfIteratorHelper";
3
+ import { isJSONString } from './isJSONString';
4
+ /**
5
+ * 解析url参数
6
+ * @param v URl
7
+ * @param k 键名
8
+ */
9
+ export function parseQuery(v, k) {
10
+ var url = new URL(v);
11
+ var searchStr = v ? url.search : window.location.search;
12
+ var query = new URLSearchParams(decodeURIComponent(searchStr));
13
+ // 单个直接返回
14
+ if (k) return query.get(k);
15
+ var res = {};
16
+ // eslint-disable-next-line no-restricted-syntax
17
+ var _iterator = _createForOfIteratorHelper(query.entries()),
18
+ _step;
19
+ try {
20
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
21
+ var _step$value = _slicedToArray(_step.value, 2),
22
+ key = _step$value[0],
23
+ value = _step$value[1];
24
+ console.log(key, value);
25
+ res[key] = isJSONString(value) ? JSON.parse(value) : value;
26
+ }
27
+ } catch (err) {
28
+ _iterator.e(err);
29
+ } finally {
30
+ _iterator.f();
31
+ }
32
+ return res;
33
+ }
package/es/sleep.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ /**
2
+ * 说明
3
+ */
4
+ export declare function sleep(timeout: number, isSuccess?: boolean): Promise<void>;
package/es/sleep.js ADDED
@@ -0,0 +1,9 @@
1
+ /**
2
+ * 说明
3
+ */
4
+ export function sleep(timeout) {
5
+ var isSuccess = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
6
+ return new Promise(function (resolve, reject) {
7
+ setTimeout(isSuccess ? resolve : reject, timeout);
8
+ });
9
+ }
@@ -0,0 +1,4 @@
1
+ /**
2
+ * 说明
3
+ */
4
+ export declare function stringifyQuery(v: object): string;
@@ -0,0 +1,13 @@
1
+ import { isEmptyObject } from './isEmptyObject';
2
+ /**
3
+ * 说明
4
+ */
5
+ export function stringifyQuery(v) {
6
+ if (isEmptyObject(v)) return '';
7
+ var query = new URLSearchParams();
8
+ Object.keys(v).forEach(function (key) {
9
+ var value = typeof v[key] === 'string' ? v[key] : JSON.stringify(v[key]);
10
+ query.append(key, value);
11
+ });
12
+ return query.toString();
13
+ }
@@ -1,7 +1,9 @@
1
1
  /**
2
2
  * 比对版本
3
- * -1 => V < v
4
- * 0 => V === v
5
- * 1 => V > v
3
+ * -1 => nv < v
4
+ * 0 => nv === v
5
+ * 1 => nv > v
6
+ * @param nv 新版本
7
+ * @param v 版本
6
8
  */
7
- export declare function compareVersion(V: string, v: string): number;
9
+ export declare function compareVersion(nv: string, v: string): -1 | 0 | 1;
@@ -8,21 +8,23 @@ exports.compareVersion = compareVersion;
8
8
  var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
9
9
  /**
10
10
  * 比对版本
11
- * -1 => V < v
12
- * 0 => V === v
13
- * 1 => V > v
11
+ * -1 => nv < v
12
+ * 0 => nv === v
13
+ * 1 => nv > v
14
+ * @param nv 新版本
15
+ * @param v 版本
14
16
  */
15
- function compareVersion(V, v) {
16
- var _V$split$map = V.split('.').map(function (i) {
17
+ function compareVersion(nv, v) {
18
+ var _nv$split$map = nv.split('.').map(function (i) {
17
19
  return +i;
18
20
  }),
19
- _V$split$map2 = (0, _slicedToArray2["default"])(_V$split$map, 3),
20
- _V$split$map2$ = _V$split$map2[0],
21
- H = _V$split$map2$ === void 0 ? 0 : _V$split$map2$,
22
- _V$split$map2$2 = _V$split$map2[1],
23
- T = _V$split$map2$2 === void 0 ? 0 : _V$split$map2$2,
24
- _V$split$map2$3 = _V$split$map2[2],
25
- S = _V$split$map2$3 === void 0 ? 0 : _V$split$map2$3; // 新
21
+ _nv$split$map2 = (0, _slicedToArray2["default"])(_nv$split$map, 3),
22
+ _nv$split$map2$ = _nv$split$map2[0],
23
+ H = _nv$split$map2$ === void 0 ? 0 : _nv$split$map2$,
24
+ _nv$split$map2$2 = _nv$split$map2[1],
25
+ T = _nv$split$map2$2 === void 0 ? 0 : _nv$split$map2$2,
26
+ _nv$split$map2$3 = _nv$split$map2[2],
27
+ S = _nv$split$map2$3 === void 0 ? 0 : _nv$split$map2$3; // 新
26
28
  var _v$split$map = v.split('.').map(function (i) {
27
29
  return +i;
28
30
  }),
@@ -0,0 +1,4 @@
1
+ /**
2
+ * 判断是否是浏览器环境
3
+ */
4
+ export declare function inBrowser(): boolean;
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.inBrowser = inBrowser;
7
+ /**
8
+ * 判断是否是浏览器环境
9
+ */
10
+ function inBrowser() {
11
+ return typeof window !== 'undefined';
12
+ }
package/lib/index.d.ts CHANGED
@@ -16,12 +16,17 @@ export * from './getBlobByUrl';
16
16
  export * from './getDayMillisecond';
17
17
  export * from './getImageInfo';
18
18
  export * from './getVideoInfo';
19
+ export * from './inBrowser';
19
20
  export * from './isAndroid';
20
21
  export * from './isEmail';
21
22
  export * from './isEmpty';
23
+ export * from './isEmptyObject';
24
+ export * from './isError';
22
25
  export * from './isFunction';
23
26
  export * from './isIOS';
24
27
  export * from './isIdCard';
28
+ export * from './isJSONString';
29
+ export * from './isLicenseCode';
25
30
  export * from './isMobile';
26
31
  export * from './isNull';
27
32
  export * from './isObject';
@@ -30,11 +35,15 @@ export * from './isPromise';
30
35
  export * from './isRegExp';
31
36
  export * from './isString';
32
37
  export * from './isUndefined';
38
+ export * from './isWindow';
33
39
  export * from './omit';
34
40
  export * from './parseDate';
35
41
  export * from './parseError';
36
42
  export * from './parsePath';
43
+ export * from './parseQuery';
37
44
  export * from './pick';
38
45
  export * from './replaceCrlf';
39
46
  export * from './reserve';
47
+ export * from './sleep';
40
48
  export * from './storage';
49
+ export * from './stringifyQuery';
package/lib/index.js CHANGED
@@ -201,6 +201,17 @@ Object.keys(_getVideoInfo).forEach(function (key) {
201
201
  }
202
202
  });
203
203
  });
204
+ var _inBrowser = require("./inBrowser");
205
+ Object.keys(_inBrowser).forEach(function (key) {
206
+ if (key === "default" || key === "__esModule") return;
207
+ if (key in exports && exports[key] === _inBrowser[key]) return;
208
+ Object.defineProperty(exports, key, {
209
+ enumerable: true,
210
+ get: function get() {
211
+ return _inBrowser[key];
212
+ }
213
+ });
214
+ });
204
215
  var _isAndroid = require("./isAndroid");
205
216
  Object.keys(_isAndroid).forEach(function (key) {
206
217
  if (key === "default" || key === "__esModule") return;
@@ -234,6 +245,28 @@ Object.keys(_isEmpty).forEach(function (key) {
234
245
  }
235
246
  });
236
247
  });
248
+ var _isEmptyObject = require("./isEmptyObject");
249
+ Object.keys(_isEmptyObject).forEach(function (key) {
250
+ if (key === "default" || key === "__esModule") return;
251
+ if (key in exports && exports[key] === _isEmptyObject[key]) return;
252
+ Object.defineProperty(exports, key, {
253
+ enumerable: true,
254
+ get: function get() {
255
+ return _isEmptyObject[key];
256
+ }
257
+ });
258
+ });
259
+ var _isError = require("./isError");
260
+ Object.keys(_isError).forEach(function (key) {
261
+ if (key === "default" || key === "__esModule") return;
262
+ if (key in exports && exports[key] === _isError[key]) return;
263
+ Object.defineProperty(exports, key, {
264
+ enumerable: true,
265
+ get: function get() {
266
+ return _isError[key];
267
+ }
268
+ });
269
+ });
237
270
  var _isFunction = require("./isFunction");
238
271
  Object.keys(_isFunction).forEach(function (key) {
239
272
  if (key === "default" || key === "__esModule") return;
@@ -267,6 +300,28 @@ Object.keys(_isIdCard).forEach(function (key) {
267
300
  }
268
301
  });
269
302
  });
303
+ var _isJSONString = require("./isJSONString");
304
+ Object.keys(_isJSONString).forEach(function (key) {
305
+ if (key === "default" || key === "__esModule") return;
306
+ if (key in exports && exports[key] === _isJSONString[key]) return;
307
+ Object.defineProperty(exports, key, {
308
+ enumerable: true,
309
+ get: function get() {
310
+ return _isJSONString[key];
311
+ }
312
+ });
313
+ });
314
+ var _isLicenseCode = require("./isLicenseCode");
315
+ Object.keys(_isLicenseCode).forEach(function (key) {
316
+ if (key === "default" || key === "__esModule") return;
317
+ if (key in exports && exports[key] === _isLicenseCode[key]) return;
318
+ Object.defineProperty(exports, key, {
319
+ enumerable: true,
320
+ get: function get() {
321
+ return _isLicenseCode[key];
322
+ }
323
+ });
324
+ });
270
325
  var _isMobile = require("./isMobile");
271
326
  Object.keys(_isMobile).forEach(function (key) {
272
327
  if (key === "default" || key === "__esModule") return;
@@ -355,6 +410,17 @@ Object.keys(_isUndefined).forEach(function (key) {
355
410
  }
356
411
  });
357
412
  });
413
+ var _isWindow = require("./isWindow");
414
+ Object.keys(_isWindow).forEach(function (key) {
415
+ if (key === "default" || key === "__esModule") return;
416
+ if (key in exports && exports[key] === _isWindow[key]) return;
417
+ Object.defineProperty(exports, key, {
418
+ enumerable: true,
419
+ get: function get() {
420
+ return _isWindow[key];
421
+ }
422
+ });
423
+ });
358
424
  var _omit = require("./omit");
359
425
  Object.keys(_omit).forEach(function (key) {
360
426
  if (key === "default" || key === "__esModule") return;
@@ -399,6 +465,17 @@ Object.keys(_parsePath).forEach(function (key) {
399
465
  }
400
466
  });
401
467
  });
468
+ var _parseQuery = require("./parseQuery");
469
+ Object.keys(_parseQuery).forEach(function (key) {
470
+ if (key === "default" || key === "__esModule") return;
471
+ if (key in exports && exports[key] === _parseQuery[key]) return;
472
+ Object.defineProperty(exports, key, {
473
+ enumerable: true,
474
+ get: function get() {
475
+ return _parseQuery[key];
476
+ }
477
+ });
478
+ });
402
479
  var _pick = require("./pick");
403
480
  Object.keys(_pick).forEach(function (key) {
404
481
  if (key === "default" || key === "__esModule") return;
@@ -432,6 +509,17 @@ Object.keys(_reserve).forEach(function (key) {
432
509
  }
433
510
  });
434
511
  });
512
+ var _sleep = require("./sleep");
513
+ Object.keys(_sleep).forEach(function (key) {
514
+ if (key === "default" || key === "__esModule") return;
515
+ if (key in exports && exports[key] === _sleep[key]) return;
516
+ Object.defineProperty(exports, key, {
517
+ enumerable: true,
518
+ get: function get() {
519
+ return _sleep[key];
520
+ }
521
+ });
522
+ });
435
523
  var _storage = require("./storage");
436
524
  Object.keys(_storage).forEach(function (key) {
437
525
  if (key === "default" || key === "__esModule") return;
@@ -442,4 +530,15 @@ Object.keys(_storage).forEach(function (key) {
442
530
  return _storage[key];
443
531
  }
444
532
  });
533
+ });
534
+ var _stringifyQuery = require("./stringifyQuery");
535
+ Object.keys(_stringifyQuery).forEach(function (key) {
536
+ if (key === "default" || key === "__esModule") return;
537
+ if (key in exports && exports[key] === _stringifyQuery[key]) return;
538
+ Object.defineProperty(exports, key, {
539
+ enumerable: true,
540
+ get: function get() {
541
+ return _stringifyQuery[key];
542
+ }
543
+ });
445
544
  });
@@ -0,0 +1,5 @@
1
+ /**
2
+ * 判断是否是空对象
3
+ * @param v 对象
4
+ */
5
+ export declare function isEmptyObject(v: object): boolean;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.isEmptyObject = isEmptyObject;
7
+ /**
8
+ * 判断是否是空对象
9
+ * @param v 对象
10
+ */
11
+ function isEmptyObject(v) {
12
+ return !Object.keys(v).length;
13
+ }
@@ -0,0 +1,4 @@
1
+ /**
2
+ * 校验是否是 error
3
+ */
4
+ export declare function isError(val: unknown): val is Error;
package/lib/isError.js ADDED
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.isError = isError;
7
+ /**
8
+ * 校验是否是 error
9
+ */
10
+ function isError(val) {
11
+ return val instanceof Error;
12
+ }
@@ -0,0 +1,5 @@
1
+ /**
2
+ * 是否是JSON 字符串
3
+ * @param v
4
+ */
5
+ export declare function isJSONString(v: string): boolean;
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.isJSONString = isJSONString;
7
+ var _isObject = require("./isObject");
8
+ /**
9
+ * 是否是JSON 字符串
10
+ * @param v
11
+ */
12
+ function isJSONString(v) {
13
+ try {
14
+ var obj = JSON.parse(v);
15
+ return (0, _isObject.isObject)(obj);
16
+ } catch (_unused) {
17
+ return false;
18
+ }
19
+ }
@@ -0,0 +1,5 @@
1
+ /**
2
+ * 校验是否是车牌号
3
+ * @param v 车牌号
4
+ */
5
+ export declare function isLicenseCode(v: string): boolean;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.isLicenseCode = isLicenseCode;
7
+ /**
8
+ * 校验是否是车牌号
9
+ * @param v 车牌号
10
+ */
11
+ function isLicenseCode(v) {
12
+ return /(^[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领A-Z]{1}[A-Z]{1}[A-Z0-9]{4,5}[A-Z0-9挂学警港澳]{1}$)/.test(v);
13
+ }
@@ -0,0 +1,5 @@
1
+ /**
2
+ * 判断是否是 window 对象
3
+ * @param val 需要判断的值
4
+ */
5
+ export declare function isWindow(val: unknown): val is Window;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.isWindow = isWindow;
7
+ /**
8
+ * 判断是否是 window 对象
9
+ * @param val 需要判断的值
10
+ */
11
+ function isWindow(val) {
12
+ return val === window;
13
+ }