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.
@@ -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
@@ -1,8 +1,21 @@
1
1
  import { Equal } from '..';
2
- export default function array_is_includes(arr1, arr2) {
3
- const largeArr = arr1.length >= arr2.length ? arr1 : arr2;
4
- const smallArr = arr1.length < arr2.length ? arr1 : arr2;
5
- return smallArr.every((item) => {
6
- return !!largeArr.find((i) => Equal.ValEqual(item, i));
2
+ function countMap(arr) {
3
+ const map = new Map();
4
+ arr.forEach((item) => {
5
+ map.set(item, (map.get(item) || 0) + 1);
7
6
  });
7
+ return map;
8
+ }
9
+ export default function array_is_includes(arr1, arr2) {
10
+ const smallArr = arr1.length <= arr2.length ? arr1 : arr2;
11
+ const largeArr = arr1.length > arr2.length ? arr1 : arr2;
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("..");
4
- function array_is_includes(arr1, arr2) {
5
- var largeArr = arr1.length >= arr2.length ? arr1 : arr2;
6
- var smallArr = arr1.length < arr2.length ? arr1 : arr2;
7
- return smallArr.every(function (item) {
8
- return !!largeArr.find(function (i) { return __1.Equal.ValEqual(item, i); });
40
+ function countMap(arr) {
41
+ var map = new Map();
42
+ arr.forEach(function (item) {
43
+ map.set(item, (map.get(item) || 0) + 1);
9
44
  });
45
+ return map;
46
+ }
47
+ function array_is_includes(arr1, arr2) {
48
+ var e_1, _a;
49
+ var smallArr = arr1.length <= arr2.length ? arr1 : arr2;
50
+ var largeArr = arr1.length > arr2.length ? arr1 : arr2;
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
- 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;
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
- 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
- });
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
  }
package/package.json CHANGED
@@ -1,59 +1,59 @@
1
- {
2
- "name": "hsu-utils",
3
- "version": "0.0.16",
4
- "description": "some front-end utils",
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
- "publish:alpha": "yarn build && yarn publish --tag alpha"
37
- },
38
- "devDependencies": {
39
- "@jest/globals": "^29.5.0",
40
- "@testing-library/react-hooks": "^8.0.1",
41
- "@types/jest": "^29.5.2",
42
- "cross-env": "^7.0.3",
43
- "jest": "^29.5.0",
44
- "jest-canvas-mock": "^2.5.2",
45
- "jest-environment-jsdom": "^29.5.0",
46
- "jsdom": "^22.1.0",
47
- "rimraf": "^5.0.1",
48
- "terser-webpack-plugin": "^5.3.0",
49
- "ts-jest": "^29.1.0",
50
- "ts-loader": "^9.2.6",
51
- "ts-node": "^10.9.1",
52
- "typescript": "^5.1.3",
53
- "webpack": "^5.65.0",
54
- "webpack-cli": "^4.9.1"
55
- },
56
- "dependencies": {
57
- "pdfjs-dist": "2.13.216"
58
- }
59
- }
1
+ {
2
+ "name": "hsu-utils",
3
+ "version": "0.0.18",
4
+ "description": "some front-end utils",
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
+ "publish:alpha": "yarn build && yarn publish --tag alpha"
37
+ },
38
+ "devDependencies": {
39
+ "@jest/globals": "^29.5.0",
40
+ "@testing-library/react-hooks": "^8.0.1",
41
+ "@types/jest": "^29.5.2",
42
+ "cross-env": "^7.0.3",
43
+ "jest": "^29.5.0",
44
+ "jest-canvas-mock": "^2.5.2",
45
+ "jest-environment-jsdom": "^29.5.0",
46
+ "jsdom": "^22.1.0",
47
+ "rimraf": "^5.0.1",
48
+ "terser-webpack-plugin": "^5.3.0",
49
+ "ts-jest": "^29.1.0",
50
+ "ts-loader": "^9.2.6",
51
+ "ts-node": "^10.9.1",
52
+ "typescript": "^5.1.3",
53
+ "webpack": "^5.65.0",
54
+ "webpack-cli": "^4.9.1"
55
+ },
56
+ "dependencies": {
57
+ "pdfjs-dist": "2.13.216"
58
+ }
59
+ }