hsu-utils 0.0.17 → 0.0.18
Sign up to get free protection for your applications and to get access to all the features.
@@ -1,8 +1,21 @@
|
|
1
1
|
import { Equal } from '..';
|
2
|
+
function countMap(arr) {
|
3
|
+
const map = new Map();
|
4
|
+
arr.forEach((item) => {
|
5
|
+
map.set(item, (map.get(item) || 0) + 1);
|
6
|
+
});
|
7
|
+
return map;
|
8
|
+
}
|
2
9
|
export default function array_is_includes(arr1, arr2) {
|
3
10
|
const smallArr = arr1.length <= arr2.length ? arr1 : arr2;
|
4
11
|
const largeArr = arr1.length > arr2.length ? arr1 : arr2;
|
5
|
-
|
6
|
-
|
7
|
-
|
12
|
+
const smallArrMap = countMap(smallArr);
|
13
|
+
const largeArrMap = countMap(largeArr);
|
14
|
+
for (const [key, count] of smallArrMap.entries()) {
|
15
|
+
const largekey = [...largeArrMap.keys()].find((item) => Equal.ValEqual(item, key));
|
16
|
+
if (!largekey || (largekey && largeArrMap.get(largekey) !== count)) {
|
17
|
+
return false;
|
18
|
+
}
|
19
|
+
}
|
20
|
+
return true;
|
8
21
|
}
|
@@ -1,11 +1,76 @@
|
|
1
1
|
"use strict";
|
2
|
+
var __read = (this && this.__read) || function (o, n) {
|
3
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
4
|
+
if (!m) return o;
|
5
|
+
var i = m.call(o), r, ar = [], e;
|
6
|
+
try {
|
7
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
8
|
+
}
|
9
|
+
catch (error) { e = { error: error }; }
|
10
|
+
finally {
|
11
|
+
try {
|
12
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
13
|
+
}
|
14
|
+
finally { if (e) throw e.error; }
|
15
|
+
}
|
16
|
+
return ar;
|
17
|
+
};
|
18
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
19
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
20
|
+
if (ar || !(i in from)) {
|
21
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
22
|
+
ar[i] = from[i];
|
23
|
+
}
|
24
|
+
}
|
25
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
26
|
+
};
|
27
|
+
var __values = (this && this.__values) || function(o) {
|
28
|
+
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
29
|
+
if (m) return m.call(o);
|
30
|
+
if (o && typeof o.length === "number") return {
|
31
|
+
next: function () {
|
32
|
+
if (o && i >= o.length) o = void 0;
|
33
|
+
return { value: o && o[i++], done: !o };
|
34
|
+
}
|
35
|
+
};
|
36
|
+
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
37
|
+
};
|
2
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
39
|
var __1 = require("..");
|
40
|
+
function countMap(arr) {
|
41
|
+
var map = new Map();
|
42
|
+
arr.forEach(function (item) {
|
43
|
+
map.set(item, (map.get(item) || 0) + 1);
|
44
|
+
});
|
45
|
+
return map;
|
46
|
+
}
|
4
47
|
function array_is_includes(arr1, arr2) {
|
48
|
+
var e_1, _a;
|
5
49
|
var smallArr = arr1.length <= arr2.length ? arr1 : arr2;
|
6
50
|
var largeArr = arr1.length > arr2.length ? arr1 : arr2;
|
7
|
-
|
8
|
-
|
9
|
-
|
51
|
+
var smallArrMap = countMap(smallArr);
|
52
|
+
var largeArrMap = countMap(largeArr);
|
53
|
+
var _loop_1 = function (key, count) {
|
54
|
+
var largekey = __spreadArray([], __read(largeArrMap.keys()), false).find(function (item) { return __1.Equal.ValEqual(item, key); });
|
55
|
+
if (!largekey || (largekey && largeArrMap.get(largekey) !== count)) {
|
56
|
+
return { value: false };
|
57
|
+
}
|
58
|
+
};
|
59
|
+
try {
|
60
|
+
for (var _b = __values(smallArrMap.entries()), _c = _b.next(); !_c.done; _c = _b.next()) {
|
61
|
+
var _d = __read(_c.value, 2), key = _d[0], count = _d[1];
|
62
|
+
var state_1 = _loop_1(key, count);
|
63
|
+
if (typeof state_1 === "object")
|
64
|
+
return state_1.value;
|
65
|
+
}
|
66
|
+
}
|
67
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
68
|
+
finally {
|
69
|
+
try {
|
70
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
71
|
+
}
|
72
|
+
finally { if (e_1) throw e_1.error; }
|
73
|
+
}
|
74
|
+
return true;
|
10
75
|
}
|
11
76
|
exports.default = array_is_includes;
|
@@ -1,4 +1,15 @@
|
|
1
1
|
"use strict";
|
2
|
+
var __values = (this && this.__values) || function(o) {
|
3
|
+
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
4
|
+
if (m) return m.call(o);
|
5
|
+
if (o && typeof o.length === "number") return {
|
6
|
+
next: function () {
|
7
|
+
if (o && i >= o.length) o = void 0;
|
8
|
+
return { value: o && o[i++], done: !o };
|
9
|
+
}
|
10
|
+
};
|
11
|
+
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
12
|
+
};
|
2
13
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
14
|
var NODE = '+';
|
4
15
|
var EDGE = '-';
|
@@ -6,10 +17,20 @@ var HIGH = '|';
|
|
6
17
|
var SPACE = ' ';
|
7
18
|
var EMPTY = '';
|
8
19
|
function get_string_width(str) {
|
20
|
+
var e_1, _a;
|
9
21
|
var width = 0;
|
10
|
-
|
11
|
-
var
|
12
|
-
|
22
|
+
try {
|
23
|
+
for (var str_1 = __values(str), str_1_1 = str_1.next(); !str_1_1.done; str_1_1 = str_1.next()) {
|
24
|
+
var char = str_1_1.value;
|
25
|
+
width += char.charCodeAt(0) < 128 && char.charCodeAt(0) >= 0 ? 1 : 2;
|
26
|
+
}
|
27
|
+
}
|
28
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
29
|
+
finally {
|
30
|
+
try {
|
31
|
+
if (str_1_1 && !str_1_1.done && (_a = str_1.return)) _a.call(str_1);
|
32
|
+
}
|
33
|
+
finally { if (e_1) throw e_1.error; }
|
13
34
|
}
|
14
35
|
return width;
|
15
36
|
}
|
@@ -65,13 +86,23 @@ function wirte_data(widths, data) {
|
|
65
86
|
return content;
|
66
87
|
}
|
67
88
|
function get_max_widths(data) {
|
89
|
+
var e_2, _a;
|
68
90
|
var max_widths = Object.keys(data[0]).map(function (v) { return +v; });
|
69
|
-
|
70
|
-
var
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
91
|
+
try {
|
92
|
+
for (var data_1 = __values(data), data_1_1 = data_1.next(); !data_1_1.done; data_1_1 = data_1.next()) {
|
93
|
+
var row_data = data_1_1.value;
|
94
|
+
row_data.forEach(function (col_data, idx) {
|
95
|
+
var width = get_string_width(col_data.toString());
|
96
|
+
max_widths[idx] = Math.max(width, max_widths[idx]);
|
97
|
+
});
|
98
|
+
}
|
99
|
+
}
|
100
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
101
|
+
finally {
|
102
|
+
try {
|
103
|
+
if (data_1_1 && !data_1_1.done && (_a = data_1.return)) _a.call(data_1);
|
104
|
+
}
|
105
|
+
finally { if (e_2) throw e_2.error; }
|
75
106
|
}
|
76
107
|
return max_widths;
|
77
108
|
}
|