@daysnap/utils 0.0.29 → 0.0.30

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/es/index.d.ts CHANGED
@@ -19,9 +19,13 @@ export * from './getVideoInfo';
19
19
  export * from './isAndroid';
20
20
  export * from './isEmail';
21
21
  export * from './isEmpty';
22
+ export * from './isEmptyObject';
23
+ export * from './isError';
22
24
  export * from './isFunction';
23
25
  export * from './isIOS';
24
26
  export * from './isIdCard';
27
+ export * from './isJSONString';
28
+ export * from './isLicenseCode';
25
29
  export * from './isMobile';
26
30
  export * from './isNull';
27
31
  export * from './isObject';
@@ -34,7 +38,10 @@ export * from './omit';
34
38
  export * from './parseDate';
35
39
  export * from './parseError';
36
40
  export * from './parsePath';
41
+ export * from './parseQuery';
37
42
  export * from './pick';
38
43
  export * from './replaceCrlf';
39
44
  export * from './reserve';
45
+ export * from './sleep';
40
46
  export * from './storage';
47
+ export * from './stringifyQuery';
package/es/index.js CHANGED
@@ -20,9 +20,13 @@ export * from './getVideoInfo';
20
20
  export * from './isAndroid';
21
21
  export * from './isEmail';
22
22
  export * from './isEmpty';
23
+ export * from './isEmptyObject';
24
+ export * from './isError';
23
25
  export * from './isFunction';
24
26
  export * from './isIOS';
25
27
  export * from './isIdCard';
28
+ export * from './isJSONString';
29
+ export * from './isLicenseCode';
26
30
  export * from './isMobile';
27
31
  export * from './isNull';
28
32
  export * from './isObject';
@@ -35,7 +39,10 @@ export * from './omit';
35
39
  export * from './parseDate';
36
40
  export * from './parseError';
37
41
  export * from './parsePath';
42
+ export * from './parseQuery';
38
43
  export * from './pick';
39
44
  export * from './replaceCrlf';
40
45
  export * from './reserve';
41
- export * from './storage';
46
+ export * from './sleep';
47
+ export * from './storage';
48
+ 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,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
+ }
package/lib/index.d.ts CHANGED
@@ -19,9 +19,13 @@ export * from './getVideoInfo';
19
19
  export * from './isAndroid';
20
20
  export * from './isEmail';
21
21
  export * from './isEmpty';
22
+ export * from './isEmptyObject';
23
+ export * from './isError';
22
24
  export * from './isFunction';
23
25
  export * from './isIOS';
24
26
  export * from './isIdCard';
27
+ export * from './isJSONString';
28
+ export * from './isLicenseCode';
25
29
  export * from './isMobile';
26
30
  export * from './isNull';
27
31
  export * from './isObject';
@@ -34,7 +38,10 @@ export * from './omit';
34
38
  export * from './parseDate';
35
39
  export * from './parseError';
36
40
  export * from './parsePath';
41
+ export * from './parseQuery';
37
42
  export * from './pick';
38
43
  export * from './replaceCrlf';
39
44
  export * from './reserve';
45
+ export * from './sleep';
40
46
  export * from './storage';
47
+ export * from './stringifyQuery';
package/lib/index.js CHANGED
@@ -234,6 +234,28 @@ Object.keys(_isEmpty).forEach(function (key) {
234
234
  }
235
235
  });
236
236
  });
237
+ var _isEmptyObject = require("./isEmptyObject");
238
+ Object.keys(_isEmptyObject).forEach(function (key) {
239
+ if (key === "default" || key === "__esModule") return;
240
+ if (key in exports && exports[key] === _isEmptyObject[key]) return;
241
+ Object.defineProperty(exports, key, {
242
+ enumerable: true,
243
+ get: function get() {
244
+ return _isEmptyObject[key];
245
+ }
246
+ });
247
+ });
248
+ var _isError = require("./isError");
249
+ Object.keys(_isError).forEach(function (key) {
250
+ if (key === "default" || key === "__esModule") return;
251
+ if (key in exports && exports[key] === _isError[key]) return;
252
+ Object.defineProperty(exports, key, {
253
+ enumerable: true,
254
+ get: function get() {
255
+ return _isError[key];
256
+ }
257
+ });
258
+ });
237
259
  var _isFunction = require("./isFunction");
238
260
  Object.keys(_isFunction).forEach(function (key) {
239
261
  if (key === "default" || key === "__esModule") return;
@@ -267,6 +289,28 @@ Object.keys(_isIdCard).forEach(function (key) {
267
289
  }
268
290
  });
269
291
  });
292
+ var _isJSONString = require("./isJSONString");
293
+ Object.keys(_isJSONString).forEach(function (key) {
294
+ if (key === "default" || key === "__esModule") return;
295
+ if (key in exports && exports[key] === _isJSONString[key]) return;
296
+ Object.defineProperty(exports, key, {
297
+ enumerable: true,
298
+ get: function get() {
299
+ return _isJSONString[key];
300
+ }
301
+ });
302
+ });
303
+ var _isLicenseCode = require("./isLicenseCode");
304
+ Object.keys(_isLicenseCode).forEach(function (key) {
305
+ if (key === "default" || key === "__esModule") return;
306
+ if (key in exports && exports[key] === _isLicenseCode[key]) return;
307
+ Object.defineProperty(exports, key, {
308
+ enumerable: true,
309
+ get: function get() {
310
+ return _isLicenseCode[key];
311
+ }
312
+ });
313
+ });
270
314
  var _isMobile = require("./isMobile");
271
315
  Object.keys(_isMobile).forEach(function (key) {
272
316
  if (key === "default" || key === "__esModule") return;
@@ -399,6 +443,17 @@ Object.keys(_parsePath).forEach(function (key) {
399
443
  }
400
444
  });
401
445
  });
446
+ var _parseQuery = require("./parseQuery");
447
+ Object.keys(_parseQuery).forEach(function (key) {
448
+ if (key === "default" || key === "__esModule") return;
449
+ if (key in exports && exports[key] === _parseQuery[key]) return;
450
+ Object.defineProperty(exports, key, {
451
+ enumerable: true,
452
+ get: function get() {
453
+ return _parseQuery[key];
454
+ }
455
+ });
456
+ });
402
457
  var _pick = require("./pick");
403
458
  Object.keys(_pick).forEach(function (key) {
404
459
  if (key === "default" || key === "__esModule") return;
@@ -432,6 +487,17 @@ Object.keys(_reserve).forEach(function (key) {
432
487
  }
433
488
  });
434
489
  });
490
+ var _sleep = require("./sleep");
491
+ Object.keys(_sleep).forEach(function (key) {
492
+ if (key === "default" || key === "__esModule") return;
493
+ if (key in exports && exports[key] === _sleep[key]) return;
494
+ Object.defineProperty(exports, key, {
495
+ enumerable: true,
496
+ get: function get() {
497
+ return _sleep[key];
498
+ }
499
+ });
500
+ });
435
501
  var _storage = require("./storage");
436
502
  Object.keys(_storage).forEach(function (key) {
437
503
  if (key === "default" || key === "__esModule") return;
@@ -442,4 +508,15 @@ Object.keys(_storage).forEach(function (key) {
442
508
  return _storage[key];
443
509
  }
444
510
  });
511
+ });
512
+ var _stringifyQuery = require("./stringifyQuery");
513
+ Object.keys(_stringifyQuery).forEach(function (key) {
514
+ if (key === "default" || key === "__esModule") return;
515
+ if (key in exports && exports[key] === _stringifyQuery[key]) return;
516
+ Object.defineProperty(exports, key, {
517
+ enumerable: true,
518
+ get: function get() {
519
+ return _stringifyQuery[key];
520
+ }
521
+ });
445
522
  });
@@ -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,6 @@
1
+ /**
2
+ * 解析url参数
3
+ * @param v URl
4
+ * @param k 键名
5
+ */
6
+ export declare function parseQuery(v?: string, k?: string): {};
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.parseQuery = parseQuery;
8
+ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
9
+ var _createForOfIteratorHelper2 = _interopRequireDefault(require("@babel/runtime/helpers/createForOfIteratorHelper"));
10
+ var _isJSONString = require("./isJSONString");
11
+ /**
12
+ * 解析url参数
13
+ * @param v URl
14
+ * @param k 键名
15
+ */
16
+ function parseQuery(v, k) {
17
+ var url = new URL(v);
18
+ var searchStr = v ? url.search : window.location.search;
19
+ var query = new URLSearchParams(decodeURIComponent(searchStr));
20
+ // 单个直接返回
21
+ if (k) return query.get(k);
22
+ var res = {};
23
+ // eslint-disable-next-line no-restricted-syntax
24
+ var _iterator = (0, _createForOfIteratorHelper2["default"])(query.entries()),
25
+ _step;
26
+ try {
27
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
28
+ var _step$value = (0, _slicedToArray2["default"])(_step.value, 2),
29
+ key = _step$value[0],
30
+ value = _step$value[1];
31
+ console.log(key, value);
32
+ res[key] = (0, _isJSONString.isJSONString)(value) ? JSON.parse(value) : value;
33
+ }
34
+ } catch (err) {
35
+ _iterator.e(err);
36
+ } finally {
37
+ _iterator.f();
38
+ }
39
+ return res;
40
+ }
package/lib/sleep.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ /**
2
+ * 说明
3
+ */
4
+ export declare function sleep(timeout: number, isSuccess?: boolean): Promise<void>;
package/lib/sleep.js ADDED
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.sleep = sleep;
7
+ /**
8
+ * 说明
9
+ */
10
+ function sleep(timeout) {
11
+ var isSuccess = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
12
+ return new Promise(function (resolve, reject) {
13
+ setTimeout(isSuccess ? resolve : reject, timeout);
14
+ });
15
+ }
@@ -0,0 +1,4 @@
1
+ /**
2
+ * 说明
3
+ */
4
+ export declare function stringifyQuery(v: object): string;
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.stringifyQuery = stringifyQuery;
7
+ var _isEmptyObject = require("./isEmptyObject");
8
+ /**
9
+ * 说明
10
+ */
11
+ function stringifyQuery(v) {
12
+ if ((0, _isEmptyObject.isEmptyObject)(v)) return '';
13
+ var query = new URLSearchParams();
14
+ Object.keys(v).forEach(function (key) {
15
+ var value = typeof v[key] === 'string' ? v[key] : JSON.stringify(v[key]);
16
+ query.append(key, value);
17
+ });
18
+ return query.toString();
19
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@daysnap/utils",
3
- "version": "0.0.29",
3
+ "version": "0.0.30",
4
4
  "description": "通用的工具库",
5
5
  "main": "lib/index.js",
6
6
  "module": "es/index.js",
@@ -12,8 +12,8 @@
12
12
  "build": "dsc build",
13
13
  "test": "jest",
14
14
  "coverage": "jest --coverage",
15
- "predeploy": "npm run entry && npm run test",
16
- "deploy": "npm run build && dsc publish",
15
+ "prerelease": "npm run entry && npm run test",
16
+ "release": "npm run build && dsc publish -t",
17
17
  "husky": "husky install && echo 'export PATH=\"/usr/local/bin/:$PATH\"' >> ~/.huskyrc",
18
18
  "lint": "eslint 'src/**/*.{js,ts}' --fix",
19
19
  "prepare": "husky install && echo 'export PATH=\"/usr/local/bin/:$PATH\"' >> ~/.huskyrc"