hsu-utils 0.0.16 → 0.0.18

Sign up to get free protection for your applications and to get access to all the features.
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2023 LazyCat
3
+ Copyright (c) 2023 VitaHsu
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -1,32 +1,32 @@
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
-
25
- > string、number、boolean、undefined、function、symbol、bigint、object、array、null、date、formdata、set、map、regexp、arraybuffer、blob
26
-
27
- - `get_string_width` 获取字符串长度
28
- > 根据字体属性进行计算,默认 size 为 12,family 为 微软雅黑
29
- - `loadImage` 异步加载图片
30
- > 确保相同的图片只加载一次
31
- - `renderPDF` 渲染 PDF
32
- - `downloadFile` 下载文件
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
+
25
+ > string、number、boolean、undefined、function、symbol、bigint、object、array、null、date、formdata、set、map、regexp、arraybuffer、blob
26
+
27
+ - `get_string_width` 获取字符串长度
28
+ > 根据字体属性进行计算,默认 size 为 12,family 为 微软雅黑
29
+ - `loadImage` 异步加载图片
30
+ > 确保相同的图片只加载一次
31
+ - `renderPDF` 渲染 PDF
32
+ - `downloadFile` 下载文件
package/dist/hsu-utils.js CHANGED
@@ -1,12 +1,12 @@
1
1
  /*!
2
2
  *
3
- * hsu-utils v0.0.15
3
+ * hsu-utils v0.0.17
4
4
  *
5
5
  * some front-end utils
6
6
  *
7
7
  * MIT License
8
8
  *
9
- * Copyright (c) 2023 LazyCat
9
+ * Copyright (c) 2023 VitaHsu
10
10
  *
11
11
  * Permission is hereby granted, free of charge, to any person obtaining a copy
12
12
  * of this software and associated documentation files (the "Software"), to deal
@@ -62,10 +62,10 @@ eval("/**\n * @licstart The following is the entire license notice for the\n * J
62
62
  /*!****************************************!*\
63
63
  !*** ./tools/ArrayIsIncludes/index.ts ***!
64
64
  \****************************************/
65
- /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
65
+ /***/ (function(__unused_webpack_module, exports, __webpack_require__) {
66
66
 
67
67
  "use strict";
68
- eval("\nObject.defineProperty(exports, \"__esModule\", ({ value: true }));\nvar __1 = __webpack_require__(/*! .. */ \"./tools/index.ts\");\nfunction array_is_includes(arr1, arr2) {\n var largeArr = arr1.length >= arr2.length ? arr1 : arr2;\n var smallArr = arr1.length < arr2.length ? arr1 : arr2;\n return smallArr.every(function (item) {\n return !!largeArr.find(function (i) { return __1.Equal.ValEqual(item, i); });\n });\n}\nexports[\"default\"] = array_is_includes;\n\n\n//# sourceURL=webpack://hsu-utils/./tools/ArrayIsIncludes/index.ts?");
68
+ eval("\nvar __read = (this && this.__read) || function (o, n) {\n var m = typeof Symbol === \"function\" && o[Symbol.iterator];\n if (!m) return o;\n var i = m.call(o), r, ar = [], e;\n try {\n while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);\n }\n catch (error) { e = { error: error }; }\n finally {\n try {\n if (r && !r.done && (m = i[\"return\"])) m.call(i);\n }\n finally { if (e) throw e.error; }\n }\n return ar;\n};\nvar __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {\n if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {\n if (ar || !(i in from)) {\n if (!ar) ar = Array.prototype.slice.call(from, 0, i);\n ar[i] = from[i];\n }\n }\n return to.concat(ar || Array.prototype.slice.call(from));\n};\nvar __values = (this && this.__values) || function(o) {\n var s = typeof Symbol === \"function\" && Symbol.iterator, m = s && o[s], i = 0;\n if (m) return m.call(o);\n if (o && typeof o.length === \"number\") return {\n next: function () {\n if (o && i >= o.length) o = void 0;\n return { value: o && o[i++], done: !o };\n }\n };\n throw new TypeError(s ? \"Object is not iterable.\" : \"Symbol.iterator is not defined.\");\n};\nObject.defineProperty(exports, \"__esModule\", ({ value: true }));\nvar __1 = __webpack_require__(/*! .. */ \"./tools/index.ts\");\nfunction countMap(arr) {\n var map = new Map();\n arr.forEach(function (item) {\n map.set(item, (map.get(item) || 0) + 1);\n });\n return map;\n}\nfunction array_is_includes(arr1, arr2) {\n var e_1, _a;\n var smallArr = arr1.length <= arr2.length ? arr1 : arr2;\n var largeArr = arr1.length > arr2.length ? arr1 : arr2;\n var smallArrMap = countMap(smallArr);\n var largeArrMap = countMap(largeArr);\n var _loop_1 = function (key, count) {\n var largekey = __spreadArray([], __read(largeArrMap.keys()), false).find(function (item) { return __1.Equal.ValEqual(item, key); });\n if (!largekey || (largekey && largeArrMap.get(largekey) !== count)) {\n return { value: false };\n }\n };\n try {\n for (var _b = __values(smallArrMap.entries()), _c = _b.next(); !_c.done; _c = _b.next()) {\n var _d = __read(_c.value, 2), key = _d[0], count = _d[1];\n var state_1 = _loop_1(key, count);\n if (typeof state_1 === \"object\")\n return state_1.value;\n }\n }\n catch (e_1_1) { e_1 = { error: e_1_1 }; }\n finally {\n try {\n if (_c && !_c.done && (_a = _b.return)) _a.call(_b);\n }\n finally { if (e_1) throw e_1.error; }\n }\n return true;\n}\nexports[\"default\"] = array_is_includes;\n\n\n//# sourceURL=webpack://hsu-utils/./tools/ArrayIsIncludes/index.ts?");
69
69
 
70
70
  /***/ }),
71
71
 
@@ -73,10 +73,10 @@ eval("\nObject.defineProperty(exports, \"__esModule\", ({ value: true }));\nvar
73
73
  /*!*************************************!*\
74
74
  !*** ./tools/ConsoleTable/index.ts ***!
75
75
  \*************************************/
76
- /***/ ((__unused_webpack_module, exports) => {
76
+ /***/ (function(__unused_webpack_module, exports) {
77
77
 
78
78
  "use strict";
79
- 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?");
79
+ eval("\nvar __values = (this && this.__values) || function(o) {\n var s = typeof Symbol === \"function\" && Symbol.iterator, m = s && o[s], i = 0;\n if (m) return m.call(o);\n if (o && typeof o.length === \"number\") return {\n next: function () {\n if (o && i >= o.length) o = void 0;\n return { value: o && o[i++], done: !o };\n }\n };\n throw new TypeError(s ? \"Object is not iterable.\" : \"Symbol.iterator is not defined.\");\n};\nObject.defineProperty(exports, \"__esModule\", ({ value: true }));\nvar NODE = '+';\nvar EDGE = '-';\nvar HIGH = '|';\nvar SPACE = ' ';\nvar EMPTY = '';\nfunction get_string_width(str) {\n var e_1, _a;\n var width = 0;\n try {\n for (var str_1 = __values(str), str_1_1 = str_1.next(); !str_1_1.done; str_1_1 = str_1.next()) {\n var char = str_1_1.value;\n width += char.charCodeAt(0) < 128 && char.charCodeAt(0) >= 0 ? 1 : 2;\n }\n }\n catch (e_1_1) { e_1 = { error: e_1_1 }; }\n finally {\n try {\n if (str_1_1 && !str_1_1.done && (_a = str_1.return)) _a.call(str_1);\n }\n finally { if (e_1) throw e_1.error; }\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 e_2, _a;\n var max_widths = Object.keys(data[0]).map(function (v) { return +v; });\n try {\n for (var data_1 = __values(data), data_1_1 = data_1.next(); !data_1_1.done; data_1_1 = data_1.next()) {\n var row_data = data_1_1.value;\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 }\n catch (e_2_1) { e_2 = { error: e_2_1 }; }\n finally {\n try {\n if (data_1_1 && !data_1_1.done && (_a = data_1.return)) _a.call(data_1);\n }\n finally { if (e_2) throw e_2.error; }\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?");
80
80
 
81
81
  /***/ }),
82
82