@wzyjs/utils 0.0.30 → 0.1.0

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 (176) hide show
  1. package/dist/{browser/cjs/utils/src → cjs}/browser/element.d.ts +9 -9
  2. package/dist/cjs/browser/element.js +59 -0
  3. package/dist/{node/cjs/utils/src → cjs}/browser/index.d.ts +18 -18
  4. package/dist/cjs/browser/index.js +64 -0
  5. package/dist/{browser/cjs/utils/src → cjs}/browser/other.d.ts +1 -1
  6. package/dist/cjs/browser/other.js +35 -0
  7. package/dist/{browser/esm/utils/src → cjs}/browser/style.d.ts +10 -10
  8. package/dist/cjs/browser/style.js +81 -0
  9. package/dist/{browser/cjs/utils/src → cjs}/browser.d.ts +2 -2
  10. package/dist/cjs/browser.js +25 -0
  11. package/dist/{browser/esm/utils/src → cjs}/common/classs.d.ts +5 -5
  12. package/dist/cjs/common/classs.js +36 -0
  13. package/dist/{browser/cjs/utils/src → cjs}/common/dayjs.d.ts +4 -4
  14. package/dist/cjs/common/dayjs.js +57 -0
  15. package/dist/{node/cjs/utils/src → cjs}/common/index.d.ts +11 -11
  16. package/dist/cjs/common/index.js +99 -0
  17. package/dist/{browser/cjs/utils/src → cjs}/common/number.d.ts +3 -3
  18. package/dist/cjs/common/number.js +55 -0
  19. package/dist/{browser/esm/utils/src → cjs}/common/object.d.ts +10 -10
  20. package/dist/cjs/common/object.js +65 -0
  21. package/dist/{node/esm/utils/src → cjs}/common/other.d.ts +26 -26
  22. package/dist/cjs/common/other.js +129 -0
  23. package/dist/{browser/cjs/utils/src → cjs}/common/string.d.ts +16 -16
  24. package/dist/cjs/common/string.js +157 -0
  25. package/dist/{node/cjs/utils/src → cjs}/node/database/Collection.d.ts +22 -22
  26. package/dist/cjs/node/database/Collection.js +219 -0
  27. package/dist/{node/cjs/utils/src → cjs}/node/database/Database.d.ts +10 -10
  28. package/dist/cjs/node/database/Database.js +47 -0
  29. package/dist/{browser/esm/utils/src → cjs}/node/database/index.d.ts +2 -2
  30. package/dist/cjs/node/database/index.js +38 -0
  31. package/dist/{node/esm/utils/src → cjs}/node/database/types.d.ts +151 -151
  32. package/dist/cjs/node/database/types.js +51 -0
  33. package/dist/{browser/cjs/utils/src → cjs}/node/database/utils.d.ts +3 -3
  34. package/dist/cjs/node/database/utils.js +53 -0
  35. package/dist/{browser/cjs/utils/src → cjs}/node/index.d.ts +3 -3
  36. package/dist/cjs/node/index.js +27 -0
  37. package/dist/{node/cjs/utils/src → cjs}/node/jsonFile/index.d.ts +6 -6
  38. package/dist/cjs/node/jsonFile/index.js +51 -0
  39. package/dist/{browser/cjs/utils/src → cjs}/node/mail/index.d.ts +1 -1
  40. package/dist/cjs/node/mail/index.js +67 -0
  41. package/dist/{node/cjs/utils/src → cjs}/node.d.ts +2 -2
  42. package/dist/cjs/node.js +25 -0
  43. package/dist/{node/cjs/utils/src → esm}/browser/element.d.ts +9 -9
  44. package/dist/esm/browser/element.js +43 -0
  45. package/dist/{node/esm/utils/src → esm}/browser/index.d.ts +18 -18
  46. package/dist/esm/browser/index.js +15 -0
  47. package/dist/{node/cjs/utils/src → esm}/browser/other.d.ts +1 -1
  48. package/dist/esm/browser/other.js +28 -0
  49. package/dist/{browser/cjs/utils/src → esm}/browser/style.d.ts +10 -10
  50. package/dist/esm/browser/style.js +55 -0
  51. package/dist/{node/cjs/utils/src → esm}/browser.d.ts +2 -2
  52. package/dist/esm/browser.js +2 -0
  53. package/dist/{browser/cjs/utils/src → esm}/common/classs.d.ts +5 -5
  54. package/dist/esm/common/classs.js +33 -0
  55. package/dist/{browser/esm/utils/src → esm}/common/dayjs.d.ts +4 -4
  56. package/dist/{browser/esm → esm}/common/dayjs.js +10 -10
  57. package/dist/{node/esm/utils/src → esm}/common/index.d.ts +11 -11
  58. package/dist/{browser/cjs/utils/src/common/index.d.ts → esm/common/index.js} +12 -11
  59. package/dist/{browser/esm/utils/src → esm}/common/number.d.ts +3 -3
  60. package/dist/esm/common/number.js +31 -0
  61. package/dist/{node/cjs/utils/src → esm}/common/object.d.ts +10 -10
  62. package/dist/esm/common/object.js +84 -0
  63. package/dist/{browser/esm/utils/src → esm}/common/other.d.ts +26 -26
  64. package/dist/esm/common/other.js +173 -0
  65. package/dist/{browser/esm/utils/src → esm}/common/string.d.ts +16 -16
  66. package/dist/esm/common/string.js +140 -0
  67. package/dist/{browser/cjs/utils/src → esm}/node/database/Collection.d.ts +22 -22
  68. package/dist/esm/node/database/Collection.js +356 -0
  69. package/dist/{browser/cjs/utils/src → esm}/node/database/Database.d.ts +10 -10
  70. package/dist/esm/node/database/Database.js +36 -0
  71. package/dist/{node/cjs/utils/src → esm}/node/database/index.d.ts +2 -2
  72. package/dist/{browser/cjs/utils/src/node/database/index.d.ts → esm/node/database/index.js} +2 -2
  73. package/dist/{node/cjs/utils/src → esm}/node/database/types.d.ts +151 -151
  74. package/dist/esm/node/database/types.js +55 -0
  75. package/dist/{browser/esm/utils/src → esm}/node/database/utils.d.ts +3 -3
  76. package/dist/esm/node/database/utils.js +29 -0
  77. package/dist/{browser/esm/utils/src → esm}/node/index.d.ts +3 -3
  78. package/dist/esm/node/index.js +3 -0
  79. package/dist/{browser/cjs/utils/src → esm}/node/jsonFile/index.d.ts +6 -6
  80. package/dist/esm/node/jsonFile/index.js +43 -0
  81. package/dist/{browser/esm/utils/src → esm}/node/mail/index.d.ts +1 -1
  82. package/dist/esm/node/mail/index.js +48 -0
  83. package/dist/{browser/cjs/utils/src → esm}/node.d.ts +2 -2
  84. package/dist/esm/node.js +2 -0
  85. package/package.json +10 -23
  86. package/dist/browser/cjs/browser/element.js +0 -40
  87. package/dist/browser/cjs/browser/index.js +0 -20
  88. package/dist/browser/cjs/browser/other.js +0 -12
  89. package/dist/browser/cjs/browser/style.js +0 -49
  90. package/dist/browser/cjs/browser.js +0 -171
  91. package/dist/browser/cjs/common/classs.js +0 -14
  92. package/dist/browser/cjs/common/dayjs.js +0 -27
  93. package/dist/browser/cjs/common/number.js +0 -34
  94. package/dist/browser/cjs/common/object.js +0 -43
  95. package/dist/browser/cjs/common/other.js +0 -112
  96. package/dist/browser/cjs/common/string.js +0 -137
  97. package/dist/browser/cjs/types/index.d.ts +0 -27
  98. package/dist/browser/cjs/utils/src/browser/index.d.ts +0 -18
  99. package/dist/browser/cjs/utils/src/common/object.d.ts +0 -10
  100. package/dist/browser/cjs/utils/src/common/other.d.ts +0 -26
  101. package/dist/browser/cjs/utils/src/node/database/types.d.ts +0 -151
  102. package/dist/browser/esm/browser/element.js +0 -36
  103. package/dist/browser/esm/browser/index.js +0 -14
  104. package/dist/browser/esm/browser/other.js +0 -10
  105. package/dist/browser/esm/browser/style.js +0 -45
  106. package/dist/browser/esm/browser.js +0 -19
  107. package/dist/browser/esm/common/classs.js +0 -12
  108. package/dist/browser/esm/common/number.js +0 -30
  109. package/dist/browser/esm/common/object.js +0 -39
  110. package/dist/browser/esm/common/other.js +0 -106
  111. package/dist/browser/esm/common/string.js +0 -120
  112. package/dist/browser/esm/types/index.d.ts +0 -27
  113. package/dist/browser/esm/utils/src/browser/element.d.ts +0 -9
  114. package/dist/browser/esm/utils/src/browser/index.d.ts +0 -18
  115. package/dist/browser/esm/utils/src/browser/other.d.ts +0 -1
  116. package/dist/browser/esm/utils/src/browser.d.ts +0 -2
  117. package/dist/browser/esm/utils/src/common/index.d.ts +0 -11
  118. package/dist/browser/esm/utils/src/node/database/Collection.d.ts +0 -22
  119. package/dist/browser/esm/utils/src/node/database/Database.d.ts +0 -10
  120. package/dist/browser/esm/utils/src/node/database/types.d.ts +0 -151
  121. package/dist/browser/esm/utils/src/node/jsonFile/index.d.ts +0 -6
  122. package/dist/browser/esm/utils/src/node.d.ts +0 -2
  123. package/dist/node/cjs/common/classs.js +0 -14
  124. package/dist/node/cjs/common/dayjs.js +0 -27
  125. package/dist/node/cjs/common/number.js +0 -34
  126. package/dist/node/cjs/common/object.js +0 -43
  127. package/dist/node/cjs/common/other.js +0 -112
  128. package/dist/node/cjs/common/string.js +0 -137
  129. package/dist/node/cjs/node/database/Collection.js +0 -202
  130. package/dist/node/cjs/node/database/Database.js +0 -25
  131. package/dist/node/cjs/node/database/types.js +0 -25
  132. package/dist/node/cjs/node/database/utils.js +0 -30
  133. package/dist/node/cjs/node/jsonFile/index.js +0 -29
  134. package/dist/node/cjs/node/mail/index.js +0 -31
  135. package/dist/node/cjs/node.js +0 -157
  136. package/dist/node/cjs/types/index.d.ts +0 -27
  137. package/dist/node/cjs/utils/src/browser/style.d.ts +0 -10
  138. package/dist/node/cjs/utils/src/common/classs.d.ts +0 -5
  139. package/dist/node/cjs/utils/src/common/dayjs.d.ts +0 -4
  140. package/dist/node/cjs/utils/src/common/number.d.ts +0 -3
  141. package/dist/node/cjs/utils/src/common/other.d.ts +0 -26
  142. package/dist/node/cjs/utils/src/common/string.d.ts +0 -16
  143. package/dist/node/cjs/utils/src/node/database/utils.d.ts +0 -3
  144. package/dist/node/cjs/utils/src/node/index.d.ts +0 -3
  145. package/dist/node/cjs/utils/src/node/mail/index.d.ts +0 -1
  146. package/dist/node/esm/common/classs.js +0 -12
  147. package/dist/node/esm/common/dayjs.js +0 -18
  148. package/dist/node/esm/common/number.js +0 -30
  149. package/dist/node/esm/common/object.js +0 -39
  150. package/dist/node/esm/common/other.js +0 -106
  151. package/dist/node/esm/common/string.js +0 -120
  152. package/dist/node/esm/node/database/Collection.js +0 -200
  153. package/dist/node/esm/node/database/Database.js +0 -23
  154. package/dist/node/esm/node/database/types.js +0 -25
  155. package/dist/node/esm/node/database/utils.js +0 -27
  156. package/dist/node/esm/node/jsonFile/index.js +0 -27
  157. package/dist/node/esm/node/mail/index.js +0 -29
  158. package/dist/node/esm/node.js +0 -14
  159. package/dist/node/esm/types/index.d.ts +0 -27
  160. package/dist/node/esm/utils/src/browser/element.d.ts +0 -9
  161. package/dist/node/esm/utils/src/browser/other.d.ts +0 -1
  162. package/dist/node/esm/utils/src/browser/style.d.ts +0 -10
  163. package/dist/node/esm/utils/src/browser.d.ts +0 -2
  164. package/dist/node/esm/utils/src/common/classs.d.ts +0 -5
  165. package/dist/node/esm/utils/src/common/dayjs.d.ts +0 -4
  166. package/dist/node/esm/utils/src/common/number.d.ts +0 -3
  167. package/dist/node/esm/utils/src/common/object.d.ts +0 -10
  168. package/dist/node/esm/utils/src/common/string.d.ts +0 -16
  169. package/dist/node/esm/utils/src/node/database/Collection.d.ts +0 -22
  170. package/dist/node/esm/utils/src/node/database/Database.d.ts +0 -10
  171. package/dist/node/esm/utils/src/node/database/index.d.ts +0 -2
  172. package/dist/node/esm/utils/src/node/database/utils.d.ts +0 -3
  173. package/dist/node/esm/utils/src/node/index.d.ts +0 -3
  174. package/dist/node/esm/utils/src/node/jsonFile/index.d.ts +0 -6
  175. package/dist/node/esm/utils/src/node/mail/index.d.ts +0 -1
  176. package/dist/node/esm/utils/src/node.d.ts +0 -2
@@ -1,11 +1,11 @@
1
- import { cloneDeep, debounce, isBoolean, isEqual, isFunction, isNumber, isObject, isString, merge, omit, pick, uniq, uniqBy, uniqWith, isEmpty, isError, find, groupBy, noop } from 'lodash';
2
- export { cloneDeep, debounce, isBoolean, isEqual, isFunction, isNumber, isObject, isString, merge, omit, pick, uniq, uniqBy, uniqWith, isEmpty, isError, find, groupBy, noop, };
3
- export * as consola from 'consola';
4
- export { default as dayjs, Dayjs } from './dayjs';
5
- export * from 'zod';
6
- export * from './string';
7
- export * from './object';
8
- export * from './other';
9
- export * from './number';
10
- export * from './classs';
11
- export { default as _ } from 'lodash';
1
+ import { cloneDeep, debounce, isBoolean, isEqual, isFunction, isNumber, isObject, isString, merge, omit, pick, uniq, uniqBy, uniqWith, isEmpty, isError, find, groupBy, noop } from 'lodash';
2
+ export { cloneDeep, debounce, isBoolean, isEqual, isFunction, isNumber, isObject, isString, merge, omit, pick, uniq, uniqBy, uniqWith, isEmpty, isError, find, groupBy, noop, };
3
+ export * as consola from 'consola';
4
+ export { default as dayjs, Dayjs } from './dayjs';
5
+ export * from 'zod';
6
+ export * from './string';
7
+ export * from './object';
8
+ export * from './other';
9
+ export * from './number';
10
+ export * from './classs';
11
+ export { default as _ } from 'lodash';
@@ -1,11 +1,12 @@
1
- import { cloneDeep, debounce, isBoolean, isEqual, isFunction, isNumber, isObject, isString, merge, omit, pick, uniq, uniqBy, uniqWith, isEmpty, isError, find, groupBy, noop } from 'lodash';
2
- export { cloneDeep, debounce, isBoolean, isEqual, isFunction, isNumber, isObject, isString, merge, omit, pick, uniq, uniqBy, uniqWith, isEmpty, isError, find, groupBy, noop, };
3
- export * as consola from 'consola';
4
- export { default as dayjs, Dayjs } from './dayjs';
5
- export * from 'zod';
6
- export * from './string';
7
- export * from './object';
8
- export * from './other';
9
- export * from './number';
10
- export * from './classs';
11
- export { default as _ } from 'lodash';
1
+ import { cloneDeep, debounce, isBoolean, isEqual, isFunction, isNumber, isObject, isString, merge, omit, pick, uniq, uniqBy, uniqWith, isEmpty, isError, find, groupBy, noop } from 'lodash';
2
+ export { cloneDeep, debounce, isBoolean, isEqual, isFunction, isNumber, isObject, isString, merge, omit, pick, uniq, uniqBy, uniqWith, isEmpty, isError, find, groupBy, noop };
3
+ import * as _consola from 'consola';
4
+ export { _consola as consola };
5
+ export { default as dayjs, Dayjs } from "./dayjs";
6
+ export * from 'zod';
7
+ export * from "./string";
8
+ export * from "./object";
9
+ export * from "./other";
10
+ export * from "./number";
11
+ export * from "./classs";
12
+ export { default as _ } from 'lodash';
@@ -1,3 +1,3 @@
1
- export declare const getRandomNum: (min: number, max: number) => number;
2
- export declare const limitDecimals: (v: string, num: number | undefined, isForce: boolean) => string;
3
- export declare const getFileSize: (size: number) => string;
1
+ export declare const getRandomNum: (min: number, max: number) => number;
2
+ export declare const limitDecimals: (v: string, num: number | undefined, isForce: boolean) => string;
3
+ export declare const getFileSize: (size: number) => string;
@@ -0,0 +1,31 @@
1
+ // 取指定范围内的随机数
2
+ export var getRandomNum = function getRandomNum(min, max) {
3
+ return Math.floor(Math.random() * (max - min + 1) + min);
4
+ };
5
+
6
+ // 指定小数点的位数
7
+ export var limitDecimals = function limitDecimals(v) {
8
+ var num = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 2;
9
+ var isForce = arguments.length > 2 ? arguments[2] : undefined;
10
+ var value = parseFloat(v);
11
+ if (isNaN(value)) {
12
+ if (isForce) {
13
+ value = 0;
14
+ } else {
15
+ return '';
16
+ }
17
+ }
18
+ return value.toFixed(num).toString();
19
+ };
20
+
21
+ // 转换成更易读的尺寸单位
22
+ export var getFileSize = function getFileSize(size) {
23
+ var d = 'G';
24
+ var s = size / 1024 / 1024 / 1024;
25
+ if (s < 1) {
26
+ d = 'M';
27
+ s *= 1024;
28
+ }
29
+ // @ts-ignore
30
+ return "".concat((s.toFixed(1) / 1).toString()).concat(d);
31
+ };
@@ -1,10 +1,10 @@
1
- export declare const findItem: <I>(list: I[], attr: keyof I, value?: I[keyof I] | undefined) => I | undefined;
2
- export declare const filterParams: (params: {
3
- [key: string]: any;
4
- }) => {};
5
- export declare const watch: {
6
- observe(obj: {
7
- [key: string]: any;
8
- }, key: string, watchFun: (value: any, val: any) => undefined): void;
9
- setWatcher(data?: {}, watch?: {}): void;
10
- };
1
+ export declare const findItem: <I>(list: I[], attr: keyof I, value?: I[keyof I] | undefined) => I | undefined;
2
+ export declare const filterParams: (params: {
3
+ [key: string]: any;
4
+ }) => {};
5
+ export declare const watch: {
6
+ observe(obj: {
7
+ [key: string]: any;
8
+ }, key: string, watchFun: (value: any, val: any) => undefined): void;
9
+ setWatcher(data?: {}, watch?: {}): void;
10
+ };
@@ -0,0 +1,84 @@
1
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
2
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
3
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
4
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
5
+ function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i.return && (_r = _i.return(), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
6
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
7
+ import { getType, isJson } from "./string";
8
+
9
+ // 判断是否有包含指定属性的对象,第三个参数可以指定具体的值
10
+ export var findItem = function findItem(list, attr, value) {
11
+ return list.find(function (item) {
12
+ return value === undefined ? item[attr] : item[attr] === value;
13
+ });
14
+ };
15
+
16
+ // 在数据里深入找指定字段
17
+ var findAttr = function findAttr(variable, attr, curPath) {
18
+ if (isJson(variable)) {
19
+ variable = JSON.parse(variable);
20
+ curPath += '.toString()';
21
+ }
22
+ if (getType(variable) === 'Array') {
23
+ for (var index = 0; index < variable.length; index++) {
24
+ var res = findAttr(variable[index], attr, curPath + "[".concat(index, "]"));
25
+ if (res) {
26
+ return res;
27
+ }
28
+ }
29
+ }
30
+ if (getType(variable) === 'Object') {
31
+ if (variable[attr] !== undefined) {
32
+ return curPath + '.' + attr;
33
+ }
34
+ for (var _key in variable) {
35
+ var _res = findAttr(variable[_key], attr, curPath + ".".concat(_key));
36
+ if (_res) {
37
+ return _res;
38
+ }
39
+ }
40
+ }
41
+ };
42
+
43
+ // 过滤对象中为undefined的属性
44
+ export var filterParams = function filterParams(params) {
45
+ return Object.entries(params || {}).reduce(function (obj, _ref) {
46
+ var _ref2 = _slicedToArray(_ref, 2),
47
+ key = _ref2[0],
48
+ value = _ref2[1];
49
+ if (value !== undefined) {
50
+ obj[key] = value;
51
+ }
52
+ return obj;
53
+ }, {});
54
+ };
55
+
56
+ // 监听属性
57
+ export var watch = {
58
+ observe: function observe(obj, key, watchFun) {
59
+ // 给该属性设默认值
60
+ var val = obj[key];
61
+ Object.defineProperty(obj, key, {
62
+ configurable: true,
63
+ enumerable: true,
64
+ set: function set(value) {
65
+ obj[key] = value;
66
+ // 赋值(set)时,调用对应函数
67
+ watchFun(value, val);
68
+ },
69
+ get: function get() {
70
+ return val;
71
+ }
72
+ });
73
+ },
74
+ setWatcher: function setWatcher() {
75
+ var _this = this;
76
+ var data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
77
+ var watch = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
78
+ // 接收index.js传过来的data对象和watch对象
79
+ Object.keys(watch).forEach(function (v) {
80
+ // 将watch对象内的key遍历
81
+ _this.observe(data, v, watch[v]); // 监听data内的v属性,传入watch内对应函数以调用
82
+ });
83
+ }
84
+ };
@@ -1,26 +1,26 @@
1
- import { KeyValue, OrderParams, Pagination, SortParams } from '@wzyjs/types';
2
- export declare const handleParams: (params?: Pagination & KeyValue, sort?: SortParams) => {
3
- page: {
4
- size?: number | undefined;
5
- current?: number | undefined;
6
- };
7
- where: KeyValue<string, string | number | boolean | RegExp>;
8
- order?: OrderParams<string> | undefined;
9
- };
10
- export declare const handleRes2List: <D>(reqPromise: any) => Promise<{
11
- label: string;
12
- value: string;
13
- }[]>;
14
- export declare const executePromise: (promise: Promise<any>) => Promise<{
15
- result: any;
16
- time: number;
17
- }>;
18
- export declare const locationFn: {
19
- url2Params: (url?: string) => {};
20
- params2Url: (params: {
21
- [key: string]: any;
22
- }) => string;
23
- setUrlParams: (key: string, value: any, keepName: string) => void;
24
- urlGetPath: (url?: string) => string;
25
- };
26
- export declare const delay: (time?: number) => Promise<unknown>;
1
+ import { KeyValue, OrderParams, Pagination, SortParams } from '@wzyjs/types';
2
+ export declare const handleParams: (params?: Pagination & KeyValue, sort?: SortParams) => {
3
+ page: {
4
+ size?: number | undefined;
5
+ current?: number | undefined;
6
+ };
7
+ where: KeyValue<string, string | number | boolean | RegExp>;
8
+ order?: OrderParams<string> | undefined;
9
+ };
10
+ export declare const handleRes2List: <D>(reqPromise: any) => Promise<{
11
+ label: string;
12
+ value: string;
13
+ }[]>;
14
+ export declare const executePromise: (promise: Promise<any>) => Promise<{
15
+ result: any;
16
+ time: number;
17
+ }>;
18
+ export declare const locationFn: {
19
+ url2Params: (url?: string) => {};
20
+ params2Url: (params: {
21
+ [key: string]: any;
22
+ }) => string;
23
+ setUrlParams: (key: string, value: any, keepName: string) => void;
24
+ urlGetPath: (url?: string) => string;
25
+ };
26
+ export declare const delay: (time?: number) => Promise<unknown>;
@@ -0,0 +1,173 @@
1
+ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
2
+ var _excluded = ["current", "pageSize"];
3
+ function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return exports; }; var exports = {}, Op = Object.prototype, hasOwn = Op.hasOwnProperty, defineProperty = Object.defineProperty || function (obj, key, desc) { obj[key] = desc.value; }, $Symbol = "function" == typeof Symbol ? Symbol : {}, iteratorSymbol = $Symbol.iterator || "@@iterator", asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator", toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag"; function define(obj, key, value) { return Object.defineProperty(obj, key, { value: value, enumerable: !0, configurable: !0, writable: !0 }), obj[key]; } try { define({}, ""); } catch (err) { define = function define(obj, key, value) { return obj[key] = value; }; } function wrap(innerFn, outerFn, self, tryLocsList) { var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator, generator = Object.create(protoGenerator.prototype), context = new Context(tryLocsList || []); return defineProperty(generator, "_invoke", { value: makeInvokeMethod(innerFn, self, context) }), generator; } function tryCatch(fn, obj, arg) { try { return { type: "normal", arg: fn.call(obj, arg) }; } catch (err) { return { type: "throw", arg: err }; } } exports.wrap = wrap; var ContinueSentinel = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var IteratorPrototype = {}; define(IteratorPrototype, iteratorSymbol, function () { return this; }); var getProto = Object.getPrototypeOf, NativeIteratorPrototype = getProto && getProto(getProto(values([]))); NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype); var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype); function defineIteratorMethods(prototype) { ["next", "throw", "return"].forEach(function (method) { define(prototype, method, function (arg) { return this._invoke(method, arg); }); }); } function AsyncIterator(generator, PromiseImpl) { function invoke(method, arg, resolve, reject) { var record = tryCatch(generator[method], generator, arg); if ("throw" !== record.type) { var result = record.arg, value = result.value; return value && "object" == _typeof(value) && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) { invoke("next", value, resolve, reject); }, function (err) { invoke("throw", err, resolve, reject); }) : PromiseImpl.resolve(value).then(function (unwrapped) { result.value = unwrapped, resolve(result); }, function (error) { return invoke("throw", error, resolve, reject); }); } reject(record.arg); } var previousPromise; defineProperty(this, "_invoke", { value: function value(method, arg) { function callInvokeWithMethodAndArg() { return new PromiseImpl(function (resolve, reject) { invoke(method, arg, resolve, reject); }); } return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(innerFn, self, context) { var state = "suspendedStart"; return function (method, arg) { if ("executing" === state) throw new Error("Generator is already running"); if ("completed" === state) { if ("throw" === method) throw arg; return doneResult(); } for (context.method = method, context.arg = arg;;) { var delegate = context.delegate; if (delegate) { var delegateResult = maybeInvokeDelegate(delegate, context); if (delegateResult) { if (delegateResult === ContinueSentinel) continue; return delegateResult; } } if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) { if ("suspendedStart" === state) throw state = "completed", context.arg; context.dispatchException(context.arg); } else "return" === context.method && context.abrupt("return", context.arg); state = "executing"; var record = tryCatch(innerFn, self, context); if ("normal" === record.type) { if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue; return { value: record.arg, done: context.done }; } "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg); } }; } function maybeInvokeDelegate(delegate, context) { var methodName = context.method, method = delegate.iterator[methodName]; if (undefined === method) return context.delegate = null, "throw" === methodName && delegate.iterator.return && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method) || "return" !== methodName && (context.method = "throw", context.arg = new TypeError("The iterator does not provide a '" + methodName + "' method")), ContinueSentinel; var record = tryCatch(method, delegate.iterator, context.arg); if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel; var info = record.arg; return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel); } function pushTryEntry(locs) { var entry = { tryLoc: locs[0] }; 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry); } function resetTryEntry(entry) { var record = entry.completion || {}; record.type = "normal", delete record.arg, entry.completion = record; } function Context(tryLocsList) { this.tryEntries = [{ tryLoc: "root" }], tryLocsList.forEach(pushTryEntry, this), this.reset(!0); } function values(iterable) { if (iterable) { var iteratorMethod = iterable[iteratorSymbol]; if (iteratorMethod) return iteratorMethod.call(iterable); if ("function" == typeof iterable.next) return iterable; if (!isNaN(iterable.length)) { var i = -1, next = function next() { for (; ++i < iterable.length;) if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next; return next.value = undefined, next.done = !0, next; }; return next.next = next; } } return { next: doneResult }; } function doneResult() { return { value: undefined, done: !0 }; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, defineProperty(Gp, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), defineProperty(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) { var ctor = "function" == typeof genFun && genFun.constructor; return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name)); }, exports.mark = function (genFun) { return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun; }, exports.awrap = function (arg) { return { __await: arg }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () { return this; }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) { void 0 === PromiseImpl && (PromiseImpl = Promise); var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl); return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) { return result.done ? result.value : iter.next(); }); }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () { return this; }), define(Gp, "toString", function () { return "[object Generator]"; }), exports.keys = function (val) { var object = Object(val), keys = []; for (var key in object) keys.push(key); return keys.reverse(), function next() { for (; keys.length;) { var key = keys.pop(); if (key in object) return next.value = key, next.done = !1, next; } return next.done = !0, next; }; }, exports.values = values, Context.prototype = { constructor: Context, reset: function reset(skipTempReset) { if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined); }, stop: function stop() { this.done = !0; var rootRecord = this.tryEntries[0].completion; if ("throw" === rootRecord.type) throw rootRecord.arg; return this.rval; }, dispatchException: function dispatchException(exception) { if (this.done) throw exception; var context = this; function handle(loc, caught) { return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught; } for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i], record = entry.completion; if ("root" === entry.tryLoc) return handle("end"); if (entry.tryLoc <= this.prev) { var hasCatch = hasOwn.call(entry, "catchLoc"), hasFinally = hasOwn.call(entry, "finallyLoc"); if (hasCatch && hasFinally) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } else if (hasCatch) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); } else { if (!hasFinally) throw new Error("try statement without catch or finally"); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } } } }, abrupt: function abrupt(type, arg) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) { var finallyEntry = entry; break; } } finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null); var record = finallyEntry ? finallyEntry.completion : {}; return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record); }, complete: function complete(record, afterLoc) { if ("throw" === record.type) throw record.arg; return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel; }, finish: function finish(finallyLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel; } }, catch: function _catch(tryLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc === tryLoc) { var record = entry.completion; if ("throw" === record.type) { var thrown = record.arg; resetTryEntry(entry); } return thrown; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(iterable, resultName, nextLoc) { return this.delegate = { iterator: values(iterable), resultName: resultName, nextLoc: nextLoc }, "next" === this.method && (this.arg = undefined), ContinueSentinel; } }, exports; }
4
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
5
+ function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
6
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
7
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
8
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
9
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
10
+ function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i.return && (_r = _i.return(), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
11
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
12
+ function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
13
+ function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
14
+ import { pick } from 'lodash';
15
+ // 处理 ProComponents 中 ProTable 参数中的 page 和 where 和 sort
16
+ export var handleParams = function handleParams(params, sort) {
17
+ if (!params) {
18
+ return {
19
+ page: {},
20
+ where: {}
21
+ };
22
+ }
23
+ var current = params.current,
24
+ pageSize = params.pageSize,
25
+ other = _objectWithoutProperties(params, _excluded);
26
+ return {
27
+ page: {
28
+ current: current || 1,
29
+ size: pageSize || 10
30
+ },
31
+ where: Object.entries(other).reduce(function (acc, _ref) {
32
+ var _ref2 = _slicedToArray(_ref, 2),
33
+ key = _ref2[0],
34
+ value = _ref2[1];
35
+ if (key && value) {
36
+ acc[key] = typeof value === 'string' ? new RegExp(value) : value;
37
+ }
38
+ return acc;
39
+ }, {}),
40
+ order: sort && {
41
+ field: Object.keys(sort)[0],
42
+ type: Object.values(sort)[0] === 'ascend' ? 'asc' : 'desc'
43
+ }
44
+ };
45
+ };
46
+
47
+ // 将 list 的数据处理为 { label: string, value: string }[]
48
+ export var handleRes2List = /*#__PURE__*/function () {
49
+ var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(reqPromise) {
50
+ var _yield$reqPromise, data;
51
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
52
+ while (1) switch (_context.prev = _context.next) {
53
+ case 0:
54
+ _context.next = 2;
55
+ return reqPromise();
56
+ case 2:
57
+ _yield$reqPromise = _context.sent;
58
+ data = _yield$reqPromise.data;
59
+ return _context.abrupt("return", ((data === null || data === void 0 ? void 0 : data.list) || []).map(function (item) {
60
+ return {
61
+ label: item.name,
62
+ value: item._id || item.key
63
+ };
64
+ }));
65
+ case 5:
66
+ case "end":
67
+ return _context.stop();
68
+ }
69
+ }, _callee);
70
+ }));
71
+ return function handleRes2List(_x2) {
72
+ return _ref3.apply(this, arguments);
73
+ };
74
+ }();
75
+
76
+ // 计算执行 promise 花费的时间
77
+ export var executePromise = /*#__PURE__*/function () {
78
+ var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(promise) {
79
+ var start, result, time;
80
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
81
+ while (1) switch (_context2.prev = _context2.next) {
82
+ case 0:
83
+ start = Date.now();
84
+ _context2.next = 3;
85
+ return promise;
86
+ case 3:
87
+ result = _context2.sent;
88
+ time = Date.now() - start;
89
+ return _context2.abrupt("return", {
90
+ result: result,
91
+ time: time
92
+ });
93
+ case 6:
94
+ case "end":
95
+ return _context2.stop();
96
+ }
97
+ }, _callee2);
98
+ }));
99
+ return function executePromise(_x3) {
100
+ return _ref4.apply(this, arguments);
101
+ };
102
+ }();
103
+
104
+ // 地址栏方面的操作
105
+ export var locationFn = {
106
+ // url地址的query转为query对象
107
+ url2Params: function url2Params() {
108
+ var url = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : location.href;
109
+ url = decodeURIComponent(url);
110
+ var jsonList = {};
111
+ if (url.indexOf('?') > -1) {
112
+ var str = url.slice(url.indexOf('?') + 1);
113
+ var strs = str.split('&');
114
+ for (var i = 0; i < strs.length; i++) {
115
+ // @ts-ignore
116
+ jsonList[strs[i].split('=')[0]] = strs[i].split('=')[1]; // 如果出现乱码的话,可以用decodeURI()进行解码
117
+ }
118
+ }
119
+
120
+ return jsonList || {};
121
+ },
122
+ // 参数对象转换为url
123
+ params2Url: function params2Url(params) {
124
+ var url = '';
125
+ for (var k in params) {
126
+ if (k) {
127
+ url += "".concat(k, "=").concat(params[k], "&");
128
+ }
129
+ }
130
+ return url.substr(0, url.length - 1);
131
+ },
132
+ // 设置地址栏参数
133
+ setUrlParams: function setUrlParams(key, value, keepName) {
134
+ if (key === undefined || value === undefined) return;
135
+
136
+ // 给地址栏参数对象添加指定参数
137
+ var allParams = locationFn.url2Params();
138
+ if (keepName) {
139
+ allParams = pick(allParams, keepName) || {};
140
+ }
141
+ // @ts-ignore
142
+ allParams[key] = encodeURIComponent(value);
143
+
144
+ // 域名和路径
145
+ var url = location.href;
146
+ var sliceEnd = url.indexOf('?') === -1 ? url.length : url.indexOf('?');
147
+ var domainPath = url.slice(0, sliceEnd);
148
+
149
+ // 参数
150
+ var params = locationFn.params2Url(allParams);
151
+
152
+ // 修改地址栏url
153
+ location.replace("".concat(domainPath, "?").concat(params));
154
+ },
155
+ // 取地址栏的path部分
156
+ urlGetPath: function urlGetPath() {
157
+ var url = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : location.href;
158
+ // 计算要截取的最后一位
159
+ var lastIndex = url.indexOf('?');
160
+ if (lastIndex === -1) {
161
+ lastIndex = url.length;
162
+ }
163
+ return url.slice(0, lastIndex);
164
+ }
165
+ };
166
+
167
+ // 延迟指定毫秒数
168
+ export var delay = function delay() {
169
+ var time = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1000;
170
+ return new Promise(function (resolve) {
171
+ return setTimeout(resolve, time);
172
+ });
173
+ };
@@ -1,16 +1,16 @@
1
- export declare const getChineseByStr: (str: string) => string;
2
- export declare const getStrLength: (value: string) => number;
3
- export declare const replaceAll: (str: string, searchValue: string, replaceValue: string) => string;
4
- export declare const replaceByRules: (str: string, rules: [string, string][]) => string;
5
- export declare const getType: (value: any) => string;
6
- export declare const amount: (str: string) => string;
7
- export declare const jsonParse: (value: string | object) => object;
8
- export declare const isJson: (str: string) => boolean;
9
- export declare const toString: (value: any) => string;
10
- export declare const getRandomColor: () => string;
11
- export declare const getRandomString: (length?: number) => string;
12
- export declare const getChinese: (str: string) => string;
13
- export declare const getSliceStr: (str: string, before: string, after: string) => string;
14
- export declare const getProxyUrl: (url: string) => string;
15
- export declare const getLength: (value: string) => number;
16
- export declare const getCookie: (name: string) => string | null;
1
+ export declare const getChineseByStr: (str: string) => string;
2
+ export declare const getStrLength: (value: string) => number;
3
+ export declare const replaceAll: (str: string, searchValue: string, replaceValue: string) => string;
4
+ export declare const replaceByRules: (str: string, rules: [string, string][]) => string;
5
+ export declare const getType: (value: any) => string;
6
+ export declare const amount: (str: string) => string;
7
+ export declare const jsonParse: (value: string | object) => object;
8
+ export declare const isJson: (str: string) => boolean;
9
+ export declare const toString: (value: any) => string;
10
+ export declare const getRandomColor: () => string;
11
+ export declare const getRandomString: (length?: number) => string;
12
+ export declare const getChinese: (str: string) => string;
13
+ export declare const getSliceStr: (str: string, before: string, after: string) => string;
14
+ export declare const getProxyUrl: (url: string) => string;
15
+ export declare const getLength: (value: string) => number;
16
+ export declare const getCookie: (name: string) => string | null;
@@ -0,0 +1,140 @@
1
+ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
2
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
3
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
4
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
5
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
6
+ function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i.return && (_r = _i.return(), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
7
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
8
+ // 获取字符串中的中文字符串
9
+ export var getChineseByStr = function getChineseByStr(str) {
10
+ if (!str) {
11
+ return '';
12
+ }
13
+ var match = str.match(/[\u4e00-\u9fa5]/g);
14
+ if (!match) {
15
+ return '';
16
+ }
17
+ return match.join('');
18
+ };
19
+
20
+ // 获取字符串中的长度,中文算 2 个字符
21
+ export var getStrLength = function getStrLength(value) {
22
+ if (!value) {
23
+ return 0;
24
+ }
25
+ var chineseLength = getChineseByStr(value).length;
26
+ return value.length - chineseLength + chineseLength * 2;
27
+ };
28
+
29
+ // 替换全部指定字符串
30
+ export var replaceAll = function replaceAll(str, searchValue, replaceValue) {
31
+ if (!str || !searchValue || !replaceValue) {
32
+ return str || '';
33
+ }
34
+ str = str.replace(searchValue, replaceValue);
35
+ if (!str.includes(searchValue)) {
36
+ return str;
37
+ }
38
+ return replaceAll(str, searchValue, replaceValue);
39
+ };
40
+
41
+ // 根据规则替换字符串
42
+ export var replaceByRules = function replaceByRules(str, rules) {
43
+ rules.forEach(function (_ref) {
44
+ var _ref2 = _slicedToArray(_ref, 2),
45
+ searchValue = _ref2[0],
46
+ replaceValue = _ref2[1];
47
+ str = str.replaceAll(searchValue, replaceValue);
48
+ });
49
+ return str;
50
+ };
51
+
52
+ // 获取变量的类型
53
+ export var getType = function getType(value) {
54
+ return Object.prototype.toString.call(value).slice(8, -1);
55
+ };
56
+
57
+ // 金钱格式化,每三位加,
58
+ export var amount = function amount(str) {
59
+ var reg = /(?=(?!\b)(\d{3})+$)/g;
60
+ return str.replace(reg, ',');
61
+ };
62
+
63
+ // 更安全的 JSON.parse
64
+ export var jsonParse = function jsonParse(value) {
65
+ if (_typeof(value) === 'object') {
66
+ return value;
67
+ }
68
+ try {
69
+ return JSON.parse(value);
70
+ } catch (err) {
71
+ return {};
72
+ }
73
+ };
74
+
75
+ // 是否为json字符串
76
+ export var isJson = function isJson(str) {
77
+ try {
78
+ if (getType(JSON.parse(str)) === 'Object') {
79
+ return true;
80
+ }
81
+ } catch (e) {}
82
+ return false;
83
+ };
84
+
85
+ // 将变量转为字符串
86
+ export var toString = function toString(value) {
87
+ return Object.prototype.toString.call(value).slice(8, -1) === 'object' ? JSON.stringify(value) : String(value);
88
+ };
89
+
90
+ // 生成随机颜色
91
+ export var getRandomColor = function getRandomColor() {
92
+ var color = Math.floor(Math.random() * 16777215).toString(16);
93
+ if (color.length === 6) {
94
+ return color;
95
+ } else {
96
+ return getRandomColor();
97
+ }
98
+ };
99
+
100
+ // 生成随机字符串
101
+ export var getRandomString = function getRandomString() {
102
+ var length = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 4;
103
+ return Math.random().toString(36).substr(2, length);
104
+ };
105
+
106
+ // 获取字符串内的中文
107
+ export var getChinese = function getChinese(str) {
108
+ if (str == null || str === '') {
109
+ return '';
110
+ }
111
+ var res = str.match(/[\u4e00-\u9fa5]/g);
112
+ if (!res) {
113
+ return '';
114
+ }
115
+ return res.join('');
116
+ };
117
+
118
+ // 截取指定两个文本之间的字符串 (不好用)
119
+ export var getSliceStr = function getSliceStr(str, before, after) {
120
+ return str.slice(str.indexOf(before) + before.length, str.lastIndexOf(after));
121
+ };
122
+
123
+ // 获取代理后的url
124
+ export var getProxyUrl = function getProxyUrl(url) {
125
+ var beforeUrl = 'https://1141871752167714.cn-hangzhou.fc.aliyuncs.com/2016-08-15/proxy/a.LATEST/proxy/?url=';
126
+ return beforeUrl + url;
127
+ };
128
+
129
+ // 获取字符串的长度
130
+ export var getLength = function getLength(value) {
131
+ var chineseLength = getChinese(value).length;
132
+ return value.length - chineseLength + chineseLength * 2;
133
+ };
134
+
135
+ // 获取指定cookie
136
+ export var getCookie = function getCookie(name) {
137
+ var reg = new RegExp("(^| )".concat(name, "=([^;]*)(;|$)"));
138
+ var arr = document.cookie.match(reg);
139
+ return arr ? unescape(arr[2]) : null;
140
+ };