hsu-utils 0.0.4 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +24 -1
- package/dist/hsu-utils.js +2 -2
- package/dist/hsu-utils.min.js +1 -1
- package/dist/hsu-utils.min.js.LICENSE.txt +1 -1
- package/es/Equal/index.js +15 -13
- package/lib/Equal/index.js +14 -12
- package/package.json +1 -1
package/README.md
CHANGED
@@ -1 +1,24 @@
|
|
1
|
-
#
|
1
|
+
# [Hsu Utils](https://github.com/VitaTsui/hsu-utils#hsu-utils)
|
2
|
+
|
3
|
+
## 前言
|
4
|
+
|
5
|
+
`hsu-utils` 一些前端的工具集
|
6
|
+
|
7
|
+
## 安装
|
8
|
+
|
9
|
+
```sh
|
10
|
+
npm install --save hsu-utils
|
11
|
+
# 或
|
12
|
+
yarn add hsu-utils
|
13
|
+
```
|
14
|
+
|
15
|
+
## 功能
|
16
|
+
|
17
|
+
- `console_table` 在控制台打印像 MySql 一样的表格
|
18
|
+
- `deepCopy` 深拷贝
|
19
|
+
- `Equal`
|
20
|
+
|
21
|
+
> `ValEqual` 判断值相等,`TypeEqual` 判断类型相同,`ObjEqual` 判断对象相等
|
22
|
+
|
23
|
+
- `Typeof` 获取类型
|
24
|
+
> `number`、`string`、`boolean`、`object`、`array`、`null`、`undefined`、`unknown`、`function`、`symbol`、`date`、`formdata`
|
package/dist/hsu-utils.js
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
/*!
|
2
2
|
*
|
3
|
-
* hsu-utils v0.0.
|
3
|
+
* hsu-utils v0.0.5
|
4
4
|
*
|
5
5
|
* some front-end utils
|
6
6
|
*
|
@@ -75,7 +75,7 @@ eval("\nObject.defineProperty(exports, \"__esModule\", ({ value: true }));\nvar
|
|
75
75
|
\******************************/
|
76
76
|
/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
|
77
77
|
|
78
|
-
eval("\nObject.defineProperty(exports, \"__esModule\", ({ value: true }));\nexports.ObjEqual = exports.ValEqual = exports.TypeEqual = void 0;\nvar __1 = __webpack_require__(/*! .. */ \"./tools/index.ts\");\nfunction TypeEqual(obj1, obj2) {\n var isEqual = false;\n if ((0, __1.Typeof)(obj1) !== (0, __1.Typeof)(obj2)) {\n isEqual = false;\n }\n else {\n isEqual = true;\n }\n return isEqual;\n}\nexports.TypeEqual = TypeEqual;\nfunction ValEqual(obj1, obj2) {\n var isEqual = false;\n if ((obj1 === null && obj2 === undefined) || (obj1 === undefined && obj2 === null)) {\n isEqual = true;\n }\n else {\n if (typeof obj1 === 'object' && typeof obj2 === 'object') {\n isEqual = ObjEqual(obj1, obj2);\n }\n else if (typeof obj1 === 'function' && typeof obj2 === 'function') {\n isEqual = JSON.stringify(obj1) === JSON.stringify(obj2);\n }\n else {\n isEqual = obj1 === obj2;\n }\n }\n return isEqual;\n}\nexports.ValEqual = ValEqual;\nfunction ObjEqual(obj1, obj2) {\n var isEqual = false;\n
|
78
|
+
eval("\nObject.defineProperty(exports, \"__esModule\", ({ value: true }));\nexports.ObjEqual = exports.ValEqual = exports.TypeEqual = void 0;\nvar __1 = __webpack_require__(/*! .. */ \"./tools/index.ts\");\nfunction TypeEqual(obj1, obj2) {\n var isEqual = false;\n if ((0, __1.Typeof)(obj1) !== (0, __1.Typeof)(obj2)) {\n isEqual = false;\n }\n else {\n isEqual = true;\n }\n return isEqual;\n}\nexports.TypeEqual = TypeEqual;\nfunction ValEqual(obj1, obj2) {\n var isEqual = false;\n if ((obj1 === null && obj2 === undefined) || (obj1 === undefined && obj2 === null)) {\n isEqual = true;\n }\n else {\n if (typeof obj1 === 'object' && typeof obj2 === 'object') {\n isEqual = ObjEqual(obj1, obj2);\n }\n else if (typeof obj1 === 'function' && typeof obj2 === 'function') {\n isEqual = JSON.stringify(obj1) === JSON.stringify(obj2);\n }\n else {\n isEqual = obj1 === obj2;\n }\n }\n return isEqual;\n}\nexports.ValEqual = ValEqual;\nfunction ObjEqual(obj1, obj2) {\n var isEqual = false;\n var _obj1 = (0, __1.deepCopy)(obj1);\n var _obj2 = (0, __1.deepCopy)(obj2);\n if (_obj1 !== null && _obj2 !== null) {\n if (Array.isArray(_obj1) && Array.isArray(_obj2)) {\n _obj1.sort();\n _obj2.sort();\n if (_obj1.length !== _obj2.length) {\n isEqual = false;\n }\n else {\n for (var i = 0; i < _obj1.length; i++) {\n isEqual = ValEqual(_obj1[i], _obj2[i]);\n if (!isEqual)\n break;\n }\n }\n }\n else if (typeof _obj1 === 'object' && typeof _obj2 === 'object') {\n if (Object.keys(_obj1).length !== Object.keys(_obj2).length) {\n isEqual = false;\n }\n else {\n for (var key in _obj1) {\n isEqual = ValEqual(_obj1[key], _obj2[key]);\n if (!isEqual)\n break;\n }\n }\n }\n }\n else if (_obj1 === null && _obj2 === null) {\n isEqual = true;\n }\n return isEqual;\n}\nexports.ObjEqual = ObjEqual;\nvar Equal = {\n ValEqual: ValEqual,\n TypeEqual: TypeEqual,\n ObjEqual: ObjEqual\n};\nexports[\"default\"] = Equal;\n\n\n//# sourceURL=webpack://hsu-utils/./tools/Equal/index.ts?");
|
79
79
|
|
80
80
|
/***/ }),
|
81
81
|
|
package/dist/hsu-utils.min.js
CHANGED
@@ -1,2 +1,2 @@
|
|
1
1
|
/*! For license information please see hsu-utils.min.js.LICENSE.txt */
|
2
|
-
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports["hsu-utils"]=t():e["hsu-utils"]=t()}(this,(()=>(()=>{"use strict";var e={442:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0});var r="+",o="-",n="|",u=" ",a="";function f(e){for(var t=0,r=0,o=e;r<o.length;r++){var n=o[r];t+=n.charCodeAt(0)<128&&n.charCodeAt(0)>=0?1:2}return t}function l(e,t){void 0===t&&(t=!1);var n=e.length,u="";return e.forEach((function(e,f){u+=r+function(e){for(var t="",r=0;r<=e;r++)t+=o;return t}(e+1),u+=f===n-1?r+(t?a:"\n"):a})),u}function i(e){for(var t="",r=0;r<=e;r++)t+=u;return t}t.default=function(e,t){var r=e.length,o=function(e){for(var t=Object.keys(e[0]).map((function(e){return+e})),r=0,o=e;r<o.length;r++)o[r].forEach((function(e,r){var o=f(e.toString());t[r]=Math.max(o,t[r])}));return t}(e),c="";e.forEach((function(e,t){t<=1&&(c+=l(o)),c+=function(e,t){var r=e.length,o="";return e.forEach((function(e,l){var c=t[l],p="";isNaN(+c)?p+=u+(null!=c?c:"")+i(e-f((null!=c?c:"").toString())):p+=i(e-f(c.toString()))+c+u,o+=n+p,o+=l===r-1?n+"\n":a})),o}(o,e),t===r-1&&(c+=l(o,!0))})),console.log(c),t&&t(c)}},819:(e,t,r)=>{Object.defineProperty(t,"__esModule",{value:!0});var o=r(243);t.default=function e(t){if("date"===(0,o.Typeof)(t))return new Date(t.toISOString());if("formdata"===(0,o.Typeof)(t)){var r=t,n=new FormData;return r.forEach((function(e,t){n.append(t,e)})),n}if(Array.isArray(t))return t.map((function(t){return"object"==typeof t?e(t):t}));if(t&&"object"===(0,o.Typeof)(t)){var u=t,a={};return Object.keys(u).forEach((function(t){var r=u[t];a[t]="object"==typeof r?e(r):r})),a}return t}},962:(e,t,r)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ObjEqual=t.ValEqual=t.TypeEqual=void 0;var o=r(243);function n(e,t){return(0,o.Typeof)(e)===(0,o.Typeof)(t)}function u(e,t){return null===e&&void 0===t||void 0===e&&null===t||("object"==typeof e&&"object"==typeof t?a(e,t):"function"==typeof e&&"function"==typeof t?JSON.stringify(e)===JSON.stringify(t):e===t)}function a(e,t){var r=!1;if(null!==
|
2
|
+
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports["hsu-utils"]=t():e["hsu-utils"]=t()}(this,(()=>(()=>{"use strict";var e={442:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0});var r="+",o="-",n="|",u=" ",a="";function f(e){for(var t=0,r=0,o=e;r<o.length;r++){var n=o[r];t+=n.charCodeAt(0)<128&&n.charCodeAt(0)>=0?1:2}return t}function l(e,t){void 0===t&&(t=!1);var n=e.length,u="";return e.forEach((function(e,f){u+=r+function(e){for(var t="",r=0;r<=e;r++)t+=o;return t}(e+1),u+=f===n-1?r+(t?a:"\n"):a})),u}function i(e){for(var t="",r=0;r<=e;r++)t+=u;return t}t.default=function(e,t){var r=e.length,o=function(e){for(var t=Object.keys(e[0]).map((function(e){return+e})),r=0,o=e;r<o.length;r++)o[r].forEach((function(e,r){var o=f(e.toString());t[r]=Math.max(o,t[r])}));return t}(e),c="";e.forEach((function(e,t){t<=1&&(c+=l(o)),c+=function(e,t){var r=e.length,o="";return e.forEach((function(e,l){var c=t[l],p="";isNaN(+c)?p+=u+(null!=c?c:"")+i(e-f((null!=c?c:"").toString())):p+=i(e-f(c.toString()))+c+u,o+=n+p,o+=l===r-1?n+"\n":a})),o}(o,e),t===r-1&&(c+=l(o,!0))})),console.log(c),t&&t(c)}},819:(e,t,r)=>{Object.defineProperty(t,"__esModule",{value:!0});var o=r(243);t.default=function e(t){if("date"===(0,o.Typeof)(t))return new Date(t.toISOString());if("formdata"===(0,o.Typeof)(t)){var r=t,n=new FormData;return r.forEach((function(e,t){n.append(t,e)})),n}if(Array.isArray(t))return t.map((function(t){return"object"==typeof t?e(t):t}));if(t&&"object"===(0,o.Typeof)(t)){var u=t,a={};return Object.keys(u).forEach((function(t){var r=u[t];a[t]="object"==typeof r?e(r):r})),a}return t}},962:(e,t,r)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ObjEqual=t.ValEqual=t.TypeEqual=void 0;var o=r(243);function n(e,t){return(0,o.Typeof)(e)===(0,o.Typeof)(t)}function u(e,t){return null===e&&void 0===t||void 0===e&&null===t||("object"==typeof e&&"object"==typeof t?a(e,t):"function"==typeof e&&"function"==typeof t?JSON.stringify(e)===JSON.stringify(t):e===t)}function a(e,t){var r=!1,n=(0,o.deepCopy)(e),a=(0,o.deepCopy)(t);if(null!==n&&null!==a){if(Array.isArray(n)&&Array.isArray(a))if(n.sort(),a.sort(),n.length!==a.length)r=!1;else for(var f=0;f<n.length&&(r=u(n[f],a[f]));f++);else if("object"==typeof n&&"object"==typeof a)if(Object.keys(n).length!==Object.keys(a).length)r=!1;else for(var l in n)if(!(r=u(n[l],a[l])))break}else null===n&&null===a&&(r=!0);return r}t.TypeEqual=n,t.ValEqual=u,t.ObjEqual=a;var f={ValEqual:u,TypeEqual:n,ObjEqual:a};t.default=f},332:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.default=function(e){var t=Object.prototype.toString.call(e),r=new RegExp(" (.+?)]");return t.match(r)[1].toLowerCase()}},243:function(e,t,r){var o=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.Typeof=t.Equal=t.deepCopy=t.console_table=void 0;var n=o(r(442));t.console_table=n.default;var u=o(r(819));t.deepCopy=u.default;var a=o(r(962));t.Equal=a.default;var f=o(r(332));t.Typeof=f.default}},t={};var r=function r(o){var n=t[o];if(void 0!==n)return n.exports;var u=t[o]={exports:{}};return e[o].call(u.exports,u,u.exports,r),u.exports}(243);return r})()));
|
package/es/Equal/index.js
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import { Typeof } from '..';
|
1
|
+
import { Typeof, deepCopy } from '..';
|
2
2
|
export function TypeEqual(obj1, obj2) {
|
3
3
|
let isEqual = false;
|
4
4
|
if (Typeof(obj1) !== Typeof(obj2)) {
|
@@ -29,35 +29,37 @@ export function ValEqual(obj1, obj2) {
|
|
29
29
|
}
|
30
30
|
export function ObjEqual(obj1, obj2) {
|
31
31
|
let isEqual = false;
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
32
|
+
let _obj1 = deepCopy(obj1);
|
33
|
+
let _obj2 = deepCopy(obj2);
|
34
|
+
if (_obj1 !== null && _obj2 !== null) {
|
35
|
+
if (Array.isArray(_obj1) && Array.isArray(_obj2)) {
|
36
|
+
_obj1.sort();
|
37
|
+
_obj2.sort();
|
38
|
+
if (_obj1.length !== _obj2.length) {
|
37
39
|
isEqual = false;
|
38
40
|
}
|
39
41
|
else {
|
40
|
-
for (let i = 0; i <
|
41
|
-
isEqual = ValEqual(
|
42
|
+
for (let i = 0; i < _obj1.length; i++) {
|
43
|
+
isEqual = ValEqual(_obj1[i], _obj2[i]);
|
42
44
|
if (!isEqual)
|
43
45
|
break;
|
44
46
|
}
|
45
47
|
}
|
46
48
|
}
|
47
|
-
else if (typeof
|
48
|
-
if (Object.keys(
|
49
|
+
else if (typeof _obj1 === 'object' && typeof _obj2 === 'object') {
|
50
|
+
if (Object.keys(_obj1).length !== Object.keys(_obj2).length) {
|
49
51
|
isEqual = false;
|
50
52
|
}
|
51
53
|
else {
|
52
|
-
for (const key in
|
53
|
-
isEqual = ValEqual(
|
54
|
+
for (const key in _obj1) {
|
55
|
+
isEqual = ValEqual(_obj1[key], _obj2[key]);
|
54
56
|
if (!isEqual)
|
55
57
|
break;
|
56
58
|
}
|
57
59
|
}
|
58
60
|
}
|
59
61
|
}
|
60
|
-
else if (
|
62
|
+
else if (_obj1 === null && _obj2 === null) {
|
61
63
|
isEqual = true;
|
62
64
|
}
|
63
65
|
return isEqual;
|
package/lib/Equal/index.js
CHANGED
@@ -34,35 +34,37 @@ function ValEqual(obj1, obj2) {
|
|
34
34
|
exports.ValEqual = ValEqual;
|
35
35
|
function ObjEqual(obj1, obj2) {
|
36
36
|
var isEqual = false;
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
37
|
+
var _obj1 = (0, __1.deepCopy)(obj1);
|
38
|
+
var _obj2 = (0, __1.deepCopy)(obj2);
|
39
|
+
if (_obj1 !== null && _obj2 !== null) {
|
40
|
+
if (Array.isArray(_obj1) && Array.isArray(_obj2)) {
|
41
|
+
_obj1.sort();
|
42
|
+
_obj2.sort();
|
43
|
+
if (_obj1.length !== _obj2.length) {
|
42
44
|
isEqual = false;
|
43
45
|
}
|
44
46
|
else {
|
45
|
-
for (var i = 0; i <
|
46
|
-
isEqual = ValEqual(
|
47
|
+
for (var i = 0; i < _obj1.length; i++) {
|
48
|
+
isEqual = ValEqual(_obj1[i], _obj2[i]);
|
47
49
|
if (!isEqual)
|
48
50
|
break;
|
49
51
|
}
|
50
52
|
}
|
51
53
|
}
|
52
|
-
else if (typeof
|
53
|
-
if (Object.keys(
|
54
|
+
else if (typeof _obj1 === 'object' && typeof _obj2 === 'object') {
|
55
|
+
if (Object.keys(_obj1).length !== Object.keys(_obj2).length) {
|
54
56
|
isEqual = false;
|
55
57
|
}
|
56
58
|
else {
|
57
|
-
for (var key in
|
58
|
-
isEqual = ValEqual(
|
59
|
+
for (var key in _obj1) {
|
60
|
+
isEqual = ValEqual(_obj1[key], _obj2[key]);
|
59
61
|
if (!isEqual)
|
60
62
|
break;
|
61
63
|
}
|
62
64
|
}
|
63
65
|
}
|
64
66
|
}
|
65
|
-
else if (
|
67
|
+
else if (_obj1 === null && _obj2 === null) {
|
66
68
|
isEqual = true;
|
67
69
|
}
|
68
70
|
return isEqual;
|