hsu-utils 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 LazyCat
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1 @@
1
+ # some front-end utils
@@ -0,0 +1,138 @@
1
+ /*!
2
+ *
3
+ * hsu-utils v0.0.0
4
+ *
5
+ * some front-end uilts
6
+ *
7
+ * MIT License
8
+ *
9
+ * Copyright (c) 2023 LazyCat
10
+ *
11
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
12
+ * of this software and associated documentation files (the "Software"), to deal
13
+ * in the Software without restriction, including without limitation the rights
14
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15
+ * copies of the Software, and to permit persons to whom the Software is
16
+ * furnished to do so, subject to the following conditions:
17
+ *
18
+ * The above copyright notice and this permission notice shall be included in all
19
+ * copies or substantial portions of the Software.
20
+ *
21
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27
+ * SOFTWARE.
28
+ *
29
+ */
30
+ /*
31
+ * ATTENTION: The "eval" devtool has been used (maybe by default in mode: "development").
32
+ * This devtool is neither made for production nor for readable output files.
33
+ * It uses "eval()" calls to create a separate source file in the browser devtools.
34
+ * If you are trying to read the output file, select a different devtool (https://webpack.js.org/configuration/devtool/)
35
+ * or disable the default devtool with "devtool: false".
36
+ * If you are looking for production-ready output files, see mode: "production" (https://webpack.js.org/configuration/mode/).
37
+ */
38
+ (function webpackUniversalModuleDefinition(root, factory) {
39
+ if(typeof exports === 'object' && typeof module === 'object')
40
+ module.exports = factory();
41
+ else if(typeof define === 'function' && define.amd)
42
+ define([], factory);
43
+ else if(typeof exports === 'object')
44
+ exports["hsu-utils"] = factory();
45
+ else
46
+ root["hsu-utils"] = factory();
47
+ })(this, () => {
48
+ return /******/ (() => { // webpackBootstrap
49
+ /******/ "use strict";
50
+ /******/ var __webpack_modules__ = ({
51
+
52
+ /***/ "./tools/ConsoleTable/index.ts":
53
+ /*!*************************************!*\
54
+ !*** ./tools/ConsoleTable/index.ts ***!
55
+ \*************************************/
56
+ /***/ ((__unused_webpack_module, exports) => {
57
+
58
+ eval("\nObject.defineProperty(exports, \"__esModule\", ({ value: true }));\nvar NODE = '+';\nvar EDGE = '-';\nvar HIGH = '|';\nvar SPACE = ' ';\nvar EMPTY = '';\nfunction get_string_width(str) {\n var width = 0;\n for (var _i = 0, str_1 = str; _i < str_1.length; _i++) {\n var char = str_1[_i];\n width += char.charCodeAt(0) < 128 && char.charCodeAt(0) >= 0 ? 1 : 2;\n }\n return width;\n}\nfunction get_egde(width) {\n var edge = '';\n for (var i = 0; i <= width; i++) {\n edge += EDGE;\n }\n return edge;\n}\nfunction get_edge(widths, no_line_break) {\n if (no_line_break === void 0) { no_line_break = false; }\n var col_num = widths.length;\n var border = '';\n widths.forEach(function (width, col) {\n border += NODE + get_egde(width + 1);\n if (col === col_num - 1) {\n border += NODE + (no_line_break ? EMPTY : '\\n');\n }\n else {\n border += EMPTY;\n }\n });\n return border;\n}\nfunction get_space(width) {\n var space = '';\n for (var i = 0; i <= width; i++) {\n space += SPACE;\n }\n return space;\n}\nfunction wirte_data(widths, data) {\n var col_num = widths.length;\n var content = '';\n widths.forEach(function (width, col) {\n var col_data = data[col];\n var _content = '';\n if (!isNaN(+col_data)) {\n _content += get_space(width - get_string_width(col_data.toString())) + col_data + SPACE;\n }\n else {\n _content += SPACE + (col_data !== null && col_data !== void 0 ? col_data : '') + get_space(width - get_string_width((col_data !== null && col_data !== void 0 ? col_data : '').toString()));\n }\n content += HIGH + _content;\n if (col === col_num - 1) {\n content += HIGH + '\\n';\n }\n else {\n content += EMPTY;\n }\n });\n return content;\n}\nfunction get_max_widths(data) {\n var max_widths = Object.keys(data[0]).map(function (v) { return +v; });\n for (var _i = 0, data_1 = data; _i < data_1.length; _i++) {\n var row_data = data_1[_i];\n row_data.forEach(function (col_data, idx) {\n var width = get_string_width(col_data.toString());\n max_widths[idx] = Math.max(width, max_widths[idx]);\n });\n }\n return max_widths;\n}\nfunction console_table(data, callBack) {\n var row_num = data.length;\n var max_widths = get_max_widths(data);\n var table = '';\n data.forEach(function (row_data, row) {\n if (row <= 1) {\n table += get_edge(max_widths);\n }\n table += wirte_data(max_widths, row_data);\n if (row === row_num - 1) {\n table += get_edge(max_widths, true);\n }\n });\n console.log(table);\n if (callBack) {\n callBack(table);\n }\n}\nexports[\"default\"] = console_table;\n\n\n//# sourceURL=webpack://hsu-utils/./tools/ConsoleTable/index.ts?");
59
+
60
+ /***/ }),
61
+
62
+ /***/ "./tools/DeepCopy/index.ts":
63
+ /*!*********************************!*\
64
+ !*** ./tools/DeepCopy/index.ts ***!
65
+ \*********************************/
66
+ /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
67
+
68
+ eval("\nObject.defineProperty(exports, \"__esModule\", ({ value: true }));\nvar __1 = __webpack_require__(/*! .. */ \"./tools/index.ts\");\nfunction deepCopy(data) {\n if ((0, __1.Typeof)(data) === 'date') {\n return new Date(data.toISOString());\n }\n else if ((0, __1.Typeof)(data) === 'formdata') {\n var _data = data;\n var _formData_1 = new FormData();\n _data.forEach(function (value, key) {\n _formData_1.append(key, value);\n });\n return _formData_1;\n }\n else if (Array.isArray(data)) {\n var newData = data.map(function (item) {\n if (typeof item === 'object') {\n return deepCopy(item);\n }\n else {\n return item;\n }\n });\n return newData;\n }\n else if (data && (0, __1.Typeof)(data) === 'object') {\n var _data_1 = data;\n var newData_1 = {};\n Object.keys(_data_1).forEach(function (key) {\n var _item = _data_1[key];\n if (typeof _item === 'object') {\n newData_1[key] = deepCopy(_item);\n }\n else {\n newData_1[key] = _item;\n }\n });\n return newData_1;\n }\n return data;\n}\nexports[\"default\"] = deepCopy;\n\n\n//# sourceURL=webpack://hsu-utils/./tools/DeepCopy/index.ts?");
69
+
70
+ /***/ }),
71
+
72
+ /***/ "./tools/Equal/index.ts":
73
+ /*!******************************!*\
74
+ !*** ./tools/Equal/index.ts ***!
75
+ \******************************/
76
+ /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
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 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 = { ObjEqual: ObjEqual, ValEqual: ValEqual, TypeEqual: TypeEqual };\nexports[\"default\"] = Equal;\n\n\n//# sourceURL=webpack://hsu-utils/./tools/Equal/index.ts?");
79
+
80
+ /***/ }),
81
+
82
+ /***/ "./tools/Typeof/index.ts":
83
+ /*!*******************************!*\
84
+ !*** ./tools/Typeof/index.ts ***!
85
+ \*******************************/
86
+ /***/ ((__unused_webpack_module, exports) => {
87
+
88
+ eval("\nObject.defineProperty(exports, \"__esModule\", ({ value: true }));\nfunction Typeof(value) {\n var object_type = Object.prototype.toString.call(value);\n var reg = new RegExp(' (.+?)]');\n var type = object_type.match(reg)[1];\n return type.toLowerCase();\n}\nexports[\"default\"] = Typeof;\n\n\n//# sourceURL=webpack://hsu-utils/./tools/Typeof/index.ts?");
89
+
90
+ /***/ }),
91
+
92
+ /***/ "./tools/index.ts":
93
+ /*!************************!*\
94
+ !*** ./tools/index.ts ***!
95
+ \************************/
96
+ /***/ (function(__unused_webpack_module, exports, __webpack_require__) {
97
+
98
+ eval("\nvar __importDefault = (this && this.__importDefault) || function (mod) {\n return (mod && mod.__esModule) ? mod : { \"default\": mod };\n};\nObject.defineProperty(exports, \"__esModule\", ({ value: true }));\nexports.Typeof = exports.Equal = exports.deepCopy = exports.console_table = void 0;\nvar ConsoleTable_1 = __importDefault(__webpack_require__(/*! ./ConsoleTable */ \"./tools/ConsoleTable/index.ts\"));\nexports.console_table = ConsoleTable_1.default;\nvar DeepCopy_1 = __importDefault(__webpack_require__(/*! ./DeepCopy */ \"./tools/DeepCopy/index.ts\"));\nexports.deepCopy = DeepCopy_1.default;\nvar Equal_1 = __importDefault(__webpack_require__(/*! ./Equal */ \"./tools/Equal/index.ts\"));\nexports.Equal = Equal_1.default;\nvar Typeof_1 = __importDefault(__webpack_require__(/*! ./Typeof */ \"./tools/Typeof/index.ts\"));\nexports.Typeof = Typeof_1.default;\n\n\n//# sourceURL=webpack://hsu-utils/./tools/index.ts?");
99
+
100
+ /***/ })
101
+
102
+ /******/ });
103
+ /************************************************************************/
104
+ /******/ // The module cache
105
+ /******/ var __webpack_module_cache__ = {};
106
+ /******/
107
+ /******/ // The require function
108
+ /******/ function __webpack_require__(moduleId) {
109
+ /******/ // Check if module is in cache
110
+ /******/ var cachedModule = __webpack_module_cache__[moduleId];
111
+ /******/ if (cachedModule !== undefined) {
112
+ /******/ return cachedModule.exports;
113
+ /******/ }
114
+ /******/ // Create a new module (and put it into the cache)
115
+ /******/ var module = __webpack_module_cache__[moduleId] = {
116
+ /******/ // no module.id needed
117
+ /******/ // no module.loaded needed
118
+ /******/ exports: {}
119
+ /******/ };
120
+ /******/
121
+ /******/ // Execute the module function
122
+ /******/ __webpack_modules__[moduleId].call(module.exports, module, module.exports, __webpack_require__);
123
+ /******/
124
+ /******/ // Return the exports of the module
125
+ /******/ return module.exports;
126
+ /******/ }
127
+ /******/
128
+ /************************************************************************/
129
+ /******/
130
+ /******/ // startup
131
+ /******/ // Load entry module and return exports
132
+ /******/ // This entry module is referenced by other modules so it can't be inlined
133
+ /******/ var __webpack_exports__ = __webpack_require__("./tools/index.ts");
134
+ /******/
135
+ /******/ return __webpack_exports__;
136
+ /******/ })()
137
+ ;
138
+ });
@@ -0,0 +1,2 @@
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!==e&&null!==t){if(Array.isArray(e)&&Array.isArray(t))if(e.sort(),t.sort(),e.length!==t.length)r=!1;else for(var o=0;o<e.length&&(r=u(e[o],t[o]));o++);else if("object"==typeof e&&"object"==typeof t)if(Object.keys(e).length!==Object.keys(t).length)r=!1;else for(var n in e)if(!(r=u(e[n],t[n])))break}else null===e&&null===t&&(r=!0);return r}t.TypeEqual=n,t.ValEqual=u,t.ObjEqual=a;var f={ObjEqual:a,ValEqual:u,TypeEqual:n};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})()));
@@ -0,0 +1,29 @@
1
+ /*!
2
+ *
3
+ * hsu-utils v0.0.0
4
+ *
5
+ * some front-end uilts
6
+ *
7
+ * MIT License
8
+ *
9
+ * Copyright (c) 2023 LazyCat
10
+ *
11
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
12
+ * of this software and associated documentation files (the "Software"), to deal
13
+ * in the Software without restriction, including without limitation the rights
14
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15
+ * copies of the Software, and to permit persons to whom the Software is
16
+ * furnished to do so, subject to the following conditions:
17
+ *
18
+ * The above copyright notice and this permission notice shall be included in all
19
+ * copies or substantial portions of the Software.
20
+ *
21
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27
+ * SOFTWARE.
28
+ *
29
+ */
@@ -0,0 +1,2 @@
1
+ export type ConsoleData = Array<Array<string | number>>;
2
+ export default function console_table(data: ConsoleData, callBack?: (str: string) => void): void;
@@ -0,0 +1,90 @@
1
+ const NODE = '+';
2
+ const EDGE = '-';
3
+ const HIGH = '|';
4
+ const SPACE = ' ';
5
+ const EMPTY = '';
6
+ function get_string_width(str) {
7
+ let width = 0;
8
+ for (const char of str) {
9
+ width += char.charCodeAt(0) < 128 && char.charCodeAt(0) >= 0 ? 1 : 2;
10
+ }
11
+ return width;
12
+ }
13
+ function get_egde(width) {
14
+ let edge = '';
15
+ for (let i = 0; i <= width; i++) {
16
+ edge += EDGE;
17
+ }
18
+ return edge;
19
+ }
20
+ function get_edge(widths, no_line_break = false) {
21
+ const col_num = widths.length;
22
+ let border = '';
23
+ widths.forEach((width, col) => {
24
+ border += NODE + get_egde(width + 1);
25
+ if (col === col_num - 1) {
26
+ border += NODE + (no_line_break ? EMPTY : '\n');
27
+ }
28
+ else {
29
+ border += EMPTY;
30
+ }
31
+ });
32
+ return border;
33
+ }
34
+ function get_space(width) {
35
+ let space = '';
36
+ for (let i = 0; i <= width; i++) {
37
+ space += SPACE;
38
+ }
39
+ return space;
40
+ }
41
+ function wirte_data(widths, data) {
42
+ const col_num = widths.length;
43
+ let content = '';
44
+ widths.forEach((width, col) => {
45
+ const col_data = data[col];
46
+ let _content = '';
47
+ if (!isNaN(+col_data)) {
48
+ _content += get_space(width - get_string_width(col_data.toString())) + col_data + SPACE;
49
+ }
50
+ else {
51
+ _content += SPACE + (col_data !== null && col_data !== void 0 ? col_data : '') + get_space(width - get_string_width((col_data !== null && col_data !== void 0 ? col_data : '').toString()));
52
+ }
53
+ content += HIGH + _content;
54
+ if (col === col_num - 1) {
55
+ content += HIGH + '\n';
56
+ }
57
+ else {
58
+ content += EMPTY;
59
+ }
60
+ });
61
+ return content;
62
+ }
63
+ function get_max_widths(data) {
64
+ let max_widths = Object.keys(data[0]).map((v) => +v);
65
+ for (const row_data of data) {
66
+ row_data.forEach((col_data, idx) => {
67
+ const width = get_string_width(col_data.toString());
68
+ max_widths[idx] = Math.max(width, max_widths[idx]);
69
+ });
70
+ }
71
+ return max_widths;
72
+ }
73
+ export default function console_table(data, callBack) {
74
+ const row_num = data.length;
75
+ const max_widths = get_max_widths(data);
76
+ let table = '';
77
+ data.forEach((row_data, row) => {
78
+ if (row <= 1) {
79
+ table += get_edge(max_widths);
80
+ }
81
+ table += wirte_data(max_widths, row_data);
82
+ if (row === row_num - 1) {
83
+ table += get_edge(max_widths, true);
84
+ }
85
+ });
86
+ console.log(table);
87
+ if (callBack) {
88
+ callBack(table);
89
+ }
90
+ }
@@ -0,0 +1 @@
1
+ export default function deepCopy<T = unknown>(data: T): T;
@@ -0,0 +1,40 @@
1
+ import { Typeof } from '..';
2
+ export default function deepCopy(data) {
3
+ if (Typeof(data) === 'date') {
4
+ return new Date(data.toISOString());
5
+ }
6
+ else if (Typeof(data) === 'formdata') {
7
+ const _data = data;
8
+ const _formData = new FormData();
9
+ _data.forEach((value, key) => {
10
+ _formData.append(key, value);
11
+ });
12
+ return _formData;
13
+ }
14
+ else if (Array.isArray(data)) {
15
+ const newData = data.map((item) => {
16
+ if (typeof item === 'object') {
17
+ return deepCopy(item);
18
+ }
19
+ else {
20
+ return item;
21
+ }
22
+ });
23
+ return newData;
24
+ }
25
+ else if (data && Typeof(data) === 'object') {
26
+ const _data = data;
27
+ const newData = {};
28
+ Object.keys(_data).forEach((key) => {
29
+ const _item = _data[key];
30
+ if (typeof _item === 'object') {
31
+ newData[key] = deepCopy(_item);
32
+ }
33
+ else {
34
+ newData[key] = _item;
35
+ }
36
+ });
37
+ return newData;
38
+ }
39
+ return data;
40
+ }
@@ -0,0 +1,9 @@
1
+ export declare function TypeEqual<T = unknown>(obj1: T, obj2: T): boolean;
2
+ export declare function ValEqual<T = unknown>(obj1: T, obj2: T): boolean;
3
+ export declare function ObjEqual<T = object>(obj1: T, obj2: T): boolean;
4
+ declare const Equal: {
5
+ ObjEqual: typeof ObjEqual;
6
+ ValEqual: typeof ValEqual;
7
+ TypeEqual: typeof TypeEqual;
8
+ };
9
+ export default Equal;
@@ -0,0 +1,66 @@
1
+ import { Typeof } from '..';
2
+ export function TypeEqual(obj1, obj2) {
3
+ let isEqual = false;
4
+ if (Typeof(obj1) !== Typeof(obj2)) {
5
+ isEqual = false;
6
+ }
7
+ else {
8
+ isEqual = true;
9
+ }
10
+ return isEqual;
11
+ }
12
+ export function ValEqual(obj1, obj2) {
13
+ let isEqual = false;
14
+ if ((obj1 === null && obj2 === undefined) || (obj1 === undefined && obj2 === null)) {
15
+ isEqual = true;
16
+ }
17
+ else {
18
+ if (typeof obj1 === 'object' && typeof obj2 === 'object') {
19
+ isEqual = ObjEqual(obj1, obj2);
20
+ }
21
+ else if (typeof obj1 === 'function' && typeof obj2 === 'function') {
22
+ isEqual = JSON.stringify(obj1) === JSON.stringify(obj2);
23
+ }
24
+ else {
25
+ isEqual = obj1 === obj2;
26
+ }
27
+ }
28
+ return isEqual;
29
+ }
30
+ export function ObjEqual(obj1, obj2) {
31
+ let isEqual = false;
32
+ if (obj1 !== null && obj2 !== null) {
33
+ if (Array.isArray(obj1) && Array.isArray(obj2)) {
34
+ obj1.sort();
35
+ obj2.sort();
36
+ if (obj1.length !== obj2.length) {
37
+ isEqual = false;
38
+ }
39
+ else {
40
+ for (let i = 0; i < obj1.length; i++) {
41
+ isEqual = ValEqual(obj1[i], obj2[i]);
42
+ if (!isEqual)
43
+ break;
44
+ }
45
+ }
46
+ }
47
+ else if (typeof obj1 === 'object' && typeof obj2 === 'object') {
48
+ if (Object.keys(obj1).length !== Object.keys(obj2).length) {
49
+ isEqual = false;
50
+ }
51
+ else {
52
+ for (const key in obj1) {
53
+ isEqual = ValEqual(obj1[key], obj2[key]);
54
+ if (!isEqual)
55
+ break;
56
+ }
57
+ }
58
+ }
59
+ }
60
+ else if (obj1 === null && obj2 === null) {
61
+ isEqual = true;
62
+ }
63
+ return isEqual;
64
+ }
65
+ const Equal = { ObjEqual, ValEqual, TypeEqual };
66
+ export default Equal;
@@ -0,0 +1,3 @@
1
+ type Type = 'number' | 'string' | 'boolean' | 'object' | 'array' | 'null' | 'undefined' | 'unknown' | 'function' | 'symbol' | 'date' | 'formdata' | string;
2
+ export default function Typeof(value: any): Type;
3
+ export {};
@@ -0,0 +1,6 @@
1
+ export default function Typeof(value) {
2
+ const object_type = Object.prototype.toString.call(value);
3
+ const reg = new RegExp(' (.+?)]');
4
+ const type = object_type.match(reg)[1];
5
+ return type.toLowerCase();
6
+ }
package/es/index.d.ts ADDED
@@ -0,0 +1,6 @@
1
+ import console_table, { ConsoleData } from './ConsoleTable';
2
+ import deepCopy from './DeepCopy';
3
+ import Equal from './Equal';
4
+ import Typeof from './Typeof';
5
+ export type { ConsoleData };
6
+ export { console_table, deepCopy, Equal, Typeof };
package/es/index.js ADDED
@@ -0,0 +1,5 @@
1
+ import console_table from './ConsoleTable';
2
+ import deepCopy from './DeepCopy';
3
+ import Equal from './Equal';
4
+ import Typeof from './Typeof';
5
+ export { console_table, deepCopy, Equal, Typeof };
@@ -0,0 +1,2 @@
1
+ export type ConsoleData = Array<Array<string | number>>;
2
+ export default function console_table(data: ConsoleData, callBack?: (str: string) => void): void;
@@ -0,0 +1,96 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ var NODE = '+';
4
+ var EDGE = '-';
5
+ var HIGH = '|';
6
+ var SPACE = ' ';
7
+ var EMPTY = '';
8
+ function get_string_width(str) {
9
+ var width = 0;
10
+ for (var _i = 0, str_1 = str; _i < str_1.length; _i++) {
11
+ var char = str_1[_i];
12
+ width += char.charCodeAt(0) < 128 && char.charCodeAt(0) >= 0 ? 1 : 2;
13
+ }
14
+ return width;
15
+ }
16
+ function get_egde(width) {
17
+ var edge = '';
18
+ for (var i = 0; i <= width; i++) {
19
+ edge += EDGE;
20
+ }
21
+ return edge;
22
+ }
23
+ function get_edge(widths, no_line_break) {
24
+ if (no_line_break === void 0) { no_line_break = false; }
25
+ var col_num = widths.length;
26
+ var border = '';
27
+ widths.forEach(function (width, col) {
28
+ border += NODE + get_egde(width + 1);
29
+ if (col === col_num - 1) {
30
+ border += NODE + (no_line_break ? EMPTY : '\n');
31
+ }
32
+ else {
33
+ border += EMPTY;
34
+ }
35
+ });
36
+ return border;
37
+ }
38
+ function get_space(width) {
39
+ var space = '';
40
+ for (var i = 0; i <= width; i++) {
41
+ space += SPACE;
42
+ }
43
+ return space;
44
+ }
45
+ function wirte_data(widths, data) {
46
+ var col_num = widths.length;
47
+ var content = '';
48
+ widths.forEach(function (width, col) {
49
+ var col_data = data[col];
50
+ var _content = '';
51
+ if (!isNaN(+col_data)) {
52
+ _content += get_space(width - get_string_width(col_data.toString())) + col_data + SPACE;
53
+ }
54
+ else {
55
+ _content += SPACE + (col_data !== null && col_data !== void 0 ? col_data : '') + get_space(width - get_string_width((col_data !== null && col_data !== void 0 ? col_data : '').toString()));
56
+ }
57
+ content += HIGH + _content;
58
+ if (col === col_num - 1) {
59
+ content += HIGH + '\n';
60
+ }
61
+ else {
62
+ content += EMPTY;
63
+ }
64
+ });
65
+ return content;
66
+ }
67
+ function get_max_widths(data) {
68
+ var max_widths = Object.keys(data[0]).map(function (v) { return +v; });
69
+ for (var _i = 0, data_1 = data; _i < data_1.length; _i++) {
70
+ var row_data = data_1[_i];
71
+ row_data.forEach(function (col_data, idx) {
72
+ var width = get_string_width(col_data.toString());
73
+ max_widths[idx] = Math.max(width, max_widths[idx]);
74
+ });
75
+ }
76
+ return max_widths;
77
+ }
78
+ function console_table(data, callBack) {
79
+ var row_num = data.length;
80
+ var max_widths = get_max_widths(data);
81
+ var table = '';
82
+ data.forEach(function (row_data, row) {
83
+ if (row <= 1) {
84
+ table += get_edge(max_widths);
85
+ }
86
+ table += wirte_data(max_widths, row_data);
87
+ if (row === row_num - 1) {
88
+ table += get_edge(max_widths, true);
89
+ }
90
+ });
91
+ console.log(table);
92
+ if (callBack) {
93
+ callBack(table);
94
+ }
95
+ }
96
+ exports.default = console_table;
@@ -0,0 +1 @@
1
+ export default function deepCopy<T = unknown>(data: T): T;
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ var __1 = require("..");
4
+ function deepCopy(data) {
5
+ if ((0, __1.Typeof)(data) === 'date') {
6
+ return new Date(data.toISOString());
7
+ }
8
+ else if ((0, __1.Typeof)(data) === 'formdata') {
9
+ var _data = data;
10
+ var _formData_1 = new FormData();
11
+ _data.forEach(function (value, key) {
12
+ _formData_1.append(key, value);
13
+ });
14
+ return _formData_1;
15
+ }
16
+ else if (Array.isArray(data)) {
17
+ var newData = data.map(function (item) {
18
+ if (typeof item === 'object') {
19
+ return deepCopy(item);
20
+ }
21
+ else {
22
+ return item;
23
+ }
24
+ });
25
+ return newData;
26
+ }
27
+ else if (data && (0, __1.Typeof)(data) === 'object') {
28
+ var _data_1 = data;
29
+ var newData_1 = {};
30
+ Object.keys(_data_1).forEach(function (key) {
31
+ var _item = _data_1[key];
32
+ if (typeof _item === 'object') {
33
+ newData_1[key] = deepCopy(_item);
34
+ }
35
+ else {
36
+ newData_1[key] = _item;
37
+ }
38
+ });
39
+ return newData_1;
40
+ }
41
+ return data;
42
+ }
43
+ exports.default = deepCopy;
@@ -0,0 +1,9 @@
1
+ export declare function TypeEqual<T = unknown>(obj1: T, obj2: T): boolean;
2
+ export declare function ValEqual<T = unknown>(obj1: T, obj2: T): boolean;
3
+ export declare function ObjEqual<T = object>(obj1: T, obj2: T): boolean;
4
+ declare const Equal: {
5
+ ObjEqual: typeof ObjEqual;
6
+ ValEqual: typeof ValEqual;
7
+ TypeEqual: typeof TypeEqual;
8
+ };
9
+ export default Equal;
@@ -0,0 +1,72 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ObjEqual = exports.ValEqual = exports.TypeEqual = void 0;
4
+ var __1 = require("..");
5
+ function TypeEqual(obj1, obj2) {
6
+ var isEqual = false;
7
+ if ((0, __1.Typeof)(obj1) !== (0, __1.Typeof)(obj2)) {
8
+ isEqual = false;
9
+ }
10
+ else {
11
+ isEqual = true;
12
+ }
13
+ return isEqual;
14
+ }
15
+ exports.TypeEqual = TypeEqual;
16
+ function ValEqual(obj1, obj2) {
17
+ var isEqual = false;
18
+ if ((obj1 === null && obj2 === undefined) || (obj1 === undefined && obj2 === null)) {
19
+ isEqual = true;
20
+ }
21
+ else {
22
+ if (typeof obj1 === 'object' && typeof obj2 === 'object') {
23
+ isEqual = ObjEqual(obj1, obj2);
24
+ }
25
+ else if (typeof obj1 === 'function' && typeof obj2 === 'function') {
26
+ isEqual = JSON.stringify(obj1) === JSON.stringify(obj2);
27
+ }
28
+ else {
29
+ isEqual = obj1 === obj2;
30
+ }
31
+ }
32
+ return isEqual;
33
+ }
34
+ exports.ValEqual = ValEqual;
35
+ function ObjEqual(obj1, obj2) {
36
+ var isEqual = false;
37
+ if (obj1 !== null && obj2 !== null) {
38
+ if (Array.isArray(obj1) && Array.isArray(obj2)) {
39
+ obj1.sort();
40
+ obj2.sort();
41
+ if (obj1.length !== obj2.length) {
42
+ isEqual = false;
43
+ }
44
+ else {
45
+ for (var i = 0; i < obj1.length; i++) {
46
+ isEqual = ValEqual(obj1[i], obj2[i]);
47
+ if (!isEqual)
48
+ break;
49
+ }
50
+ }
51
+ }
52
+ else if (typeof obj1 === 'object' && typeof obj2 === 'object') {
53
+ if (Object.keys(obj1).length !== Object.keys(obj2).length) {
54
+ isEqual = false;
55
+ }
56
+ else {
57
+ for (var key in obj1) {
58
+ isEqual = ValEqual(obj1[key], obj2[key]);
59
+ if (!isEqual)
60
+ break;
61
+ }
62
+ }
63
+ }
64
+ }
65
+ else if (obj1 === null && obj2 === null) {
66
+ isEqual = true;
67
+ }
68
+ return isEqual;
69
+ }
70
+ exports.ObjEqual = ObjEqual;
71
+ var Equal = { ObjEqual: ObjEqual, ValEqual: ValEqual, TypeEqual: TypeEqual };
72
+ exports.default = Equal;
@@ -0,0 +1,3 @@
1
+ type Type = 'number' | 'string' | 'boolean' | 'object' | 'array' | 'null' | 'undefined' | 'unknown' | 'function' | 'symbol' | 'date' | 'formdata' | string;
2
+ export default function Typeof(value: any): Type;
3
+ export {};
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ function Typeof(value) {
4
+ var object_type = Object.prototype.toString.call(value);
5
+ var reg = new RegExp(' (.+?)]');
6
+ var type = object_type.match(reg)[1];
7
+ return type.toLowerCase();
8
+ }
9
+ exports.default = Typeof;
package/lib/index.d.ts ADDED
@@ -0,0 +1,6 @@
1
+ import console_table, { ConsoleData } from './ConsoleTable';
2
+ import deepCopy from './DeepCopy';
3
+ import Equal from './Equal';
4
+ import Typeof from './Typeof';
5
+ export type { ConsoleData };
6
+ export { console_table, deepCopy, Equal, Typeof };
package/lib/index.js ADDED
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.Typeof = exports.Equal = exports.deepCopy = exports.console_table = void 0;
7
+ var ConsoleTable_1 = __importDefault(require("./ConsoleTable"));
8
+ exports.console_table = ConsoleTable_1.default;
9
+ var DeepCopy_1 = __importDefault(require("./DeepCopy"));
10
+ exports.deepCopy = DeepCopy_1.default;
11
+ var Equal_1 = __importDefault(require("./Equal"));
12
+ exports.Equal = Equal_1.default;
13
+ var Typeof_1 = __importDefault(require("./Typeof"));
14
+ exports.Typeof = Typeof_1.default;
package/package.json ADDED
@@ -0,0 +1,55 @@
1
+ {
2
+ "name": "hsu-utils",
3
+ "version": "0.0.1",
4
+ "description": "some front-end uilts",
5
+ "repository": "git@github.com:VitaTsui/hsu-utils.git",
6
+ "author": "VitaHsu <vitahsu7@gmail.com>",
7
+ "license": "MIT",
8
+ "main": "lib/index.js",
9
+ "module": "es/index.js",
10
+ "unpkg": "dist/hsu-utils.min.js",
11
+ "files": [
12
+ "es",
13
+ "lib",
14
+ "dist",
15
+ "package.json",
16
+ "README.md",
17
+ "LICENSE"
18
+ ],
19
+ "sideEffects": [
20
+ "es/*",
21
+ "lib/*",
22
+ "dist/*"
23
+ ],
24
+ "scripts": {
25
+ "build": "yarn build:es && yarn build:cjs && rimraf dist && yarn build:umd",
26
+ "build:es": "rimraf es && tsc -p build/tsconfig.es.json",
27
+ "build:cjs": "rimraf lib && tsc -p build/tsconfig.cjs.json",
28
+ "build:umd": "rimraf dist && yarn build:dev && yarn build:prod",
29
+ "build:dev": "cross-env NODE_ENV=development webpack --config build/webpack.config.js",
30
+ "build:prod": "cross-env NODE_ENV=production webpack --config build/webpack.config.js",
31
+ "clear": "rimraf lib && rimraf es && rimraf dist",
32
+ "test": "jest",
33
+ "publish:patch": "yarn build && yarn publish --new-version patch",
34
+ "publish:minor": "yarn build && yarn publish --new-version minor",
35
+ "publish:major": "yarn build && yarn publish --new-version major"
36
+ },
37
+ "devDependencies": {
38
+ "@jest/globals": "^29.5.0",
39
+ "@testing-library/react-hooks": "^8.0.1",
40
+ "@types/jest": "^29.5.2",
41
+ "cross-env": "^7.0.3",
42
+ "jest": "^29.5.0",
43
+ "jest-environment-jsdom": "^29.5.0",
44
+ "jsdom": "^22.1.0",
45
+ "rimraf": "^5.0.1",
46
+ "terser-webpack-plugin": "^5.3.0",
47
+ "ts-jest": "^29.1.0",
48
+ "ts-loader": "^9.2.6",
49
+ "ts-node": "^10.9.1",
50
+ "typescript": "^5.1.3",
51
+ "webpack": "^5.65.0",
52
+ "webpack-cli": "^4.9.1"
53
+ },
54
+ "dependencies": {}
55
+ }