@vope/utils 1.6.0-bate.7 → 1.6.0-bate.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/neo4j.js DELETED
@@ -1,181 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var neo4j_exports = {};
20
- __export(neo4j_exports, {
21
- default: () => Neo4j
22
- });
23
- module.exports = __toCommonJS(neo4j_exports);
24
- var import_strings = require("./convert/strings");
25
- var import_list = require("./memory/list");
26
- var import_simple = require("./memory/simple");
27
- class Neo4j {
28
- #nPrimaryKey;
29
- #ePrimaryKey;
30
- #sourceKey;
31
- #targetKey;
32
- #dirKey;
33
- #nodes;
34
- #edges;
35
- #sources;
36
- #targets;
37
- #dirs;
38
- get nodeField() {
39
- return this.#nPrimaryKey;
40
- }
41
- get edgeField() {
42
- return this.#ePrimaryKey;
43
- }
44
- get sourceField() {
45
- return this.#sourceKey;
46
- }
47
- get targetField() {
48
- return this.#targetKey;
49
- }
50
- get dirKey() {
51
- return this.#dirKey;
52
- }
53
- /**
54
- * 点视图
55
- */
56
- nodes;
57
- /**
58
- * 边视图
59
- */
60
- edges;
61
- /**
62
- * (边)出点视图
63
- */
64
- sources;
65
- /**
66
- * (边)入点视图
67
- */
68
- targets;
69
- /**
70
- * (边)方向视图
71
- */
72
- dirs;
73
- constructor(nodeList, edgeList, {
74
- nid,
75
- eid,
76
- sourceKey,
77
- targetKey,
78
- dir = (edge) => edge[sourceKey] + "|" + edge[targetKey]
79
- }) {
80
- shield(this, "nodes", this.#nodes = new import_simple.MemorySimple(this.#nPrimaryKey = nid));
81
- shield(this, "edges", this.#edges = new import_simple.MemorySimple(this.#ePrimaryKey = eid));
82
- shield(this, "sources", this.#sources = new import_list.MemoryList(this.#sourceKey = sourceKey));
83
- shield(this, "targets", this.#targets = new import_list.MemoryList(this.#targetKey = targetKey));
84
- shield(this, "dirs", this.#dirs = new import_list.MemoryList(this.#dirKey = dir));
85
- nodeList.forEach((node) => this.node("add", node));
86
- edgeList.forEach((edge) => this.edge("add", edge));
87
- }
88
- node(type, value) {
89
- const nodes = this.#nodes;
90
- if (type === "add") {
91
- nodes.push(value);
92
- } else if (type === "delete") {
93
- const node = nodes.get(value);
94
- if (!node) return [];
95
- nodes.delete(node);
96
- const id = node[this.#nPrimaryKey];
97
- const sourceKey = this.#sourceKey;
98
- const targetKey = this.#targetKey;
99
- const edges = this.#edges;
100
- const sources = this.#sources;
101
- const targets = this.#targets;
102
- const dirs = this.#dirs;
103
- const list = [];
104
- sources.get(id)?.reduce((_, edge) => {
105
- edges.delete(edge);
106
- targets.delete(edge);
107
- edge[sourceKey] === edge[targetKey] || dirs.delete(edge);
108
- list.push(edge);
109
- return true;
110
- }, false) && sources.deleteType(id);
111
- targets.get(id)?.reduce((_, edge) => {
112
- edges.delete(edge);
113
- sources.delete(edge);
114
- edge[sourceKey] === edge[targetKey] || dirs.delete(edge);
115
- list.push(edge);
116
- return true;
117
- }, false) && targets.deleteType(id);
118
- return list;
119
- }
120
- }
121
- edge(type, value) {
122
- const sourceKey = this.#sourceKey;
123
- const targetKey = this.#targetKey;
124
- const edges = this.#edges;
125
- const sources = this.#sources;
126
- const targets = this.#targets;
127
- const dirs = this.#dirs;
128
- if (type === "add") {
129
- const edge = value;
130
- edges.push(edge);
131
- sources.push(edge);
132
- targets.push(edge);
133
- edge[sourceKey] === edge[targetKey] || dirs.push(edge);
134
- } else if (type === "delete") {
135
- const edge = edges.get(value);
136
- if (!edge) return false;
137
- edges.delete(edge);
138
- sources.delete(edge);
139
- targets.delete(edge);
140
- edge[sourceKey] === edge[targetKey] || dirs.delete(edge);
141
- return true;
142
- }
143
- }
144
- /**
145
- * 清理图管理数据
146
- */
147
- clear() {
148
- this.#nodes.clear();
149
- this.#edges.clear();
150
- this.#sources.clear();
151
- this.#targets.clear();
152
- this.#dirs.clear();
153
- }
154
- }
155
- const shield_keys = (0, import_strings.hash8strings)([
156
- "push",
157
- "delete",
158
- "deleteType",
159
- "clear"
160
- ]);
161
- const shield = (obj, key, origin) => {
162
- const proxy = new Proxy({}, {
163
- get(target, p) {
164
- if (p in shield_keys) return;
165
- const value = origin[p];
166
- if (typeof value === "function") {
167
- return function(...args) {
168
- const result = origin[p](...args);
169
- return result === origin ? proxy : result;
170
- };
171
- } else {
172
- return value;
173
- }
174
- }
175
- });
176
- Object.defineProperty(obj, key, {
177
- get() {
178
- return proxy;
179
- }
180
- });
181
- };
package/dist/once.js DELETED
@@ -1,28 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var once_exports = {};
20
- __export(once_exports, {
21
- once: () => once
22
- });
23
- module.exports = __toCommonJS(once_exports);
24
- const once = (func, thisArg) => {
25
- let local;
26
- let inited = false;
27
- return (...list) => inited ? local : (inited = true, local = func.apply(thisArg, list));
28
- };
package/dist/parse/num.js DELETED
@@ -1,51 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var num_exports = {};
20
- __export(num_exports, {
21
- parseNum: () => parseNum
22
- });
23
- module.exports = __toCommonJS(num_exports);
24
- var import_lodash_es = require("lodash-es");
25
- const pow = Math.floor(Math.log10(Number.MAX_SAFE_INTEGER));
26
- const re_num = /^([-+]?)0*(\d+)(?:(n)|(?:\.(\d+))?(?:[Ee]([-+]?)(\d+))?)$/;
27
- const parseNum = (num) => {
28
- if ((0, import_lodash_es.isNumber)(num) || typeof num === "bigint") return num;
29
- const match = num.match(re_num);
30
- if (!match) return Number.NaN;
31
- const [, valueSymbol, integer, bigint, decimal, powSymbol, powValue] = match;
32
- if (bigint === "n") return BigInt(valueSymbol + integer);
33
- const powSize = integer.length - 1 + (powValue ? powSymbol === "-" ? -powValue : +powValue : 0);
34
- if (powSize < pow || powSize === pow && +integer.slice(0, -1) < Number.MAX_SAFE_INTEGER / 10) return +num;
35
- try {
36
- const bigValue = BigInt(integer.slice(0, powSize + 1).padEnd(powSize + 1, "0"));
37
- let smallValue;
38
- if (decimal && powValue && powSymbol !== "-") {
39
- const powNum = +powValue;
40
- const effectDecimal = decimal.slice(0, Math.min(pow, powNum));
41
- const tinyValue = decimal.length > pow && powNum > pow ? BigInt(+decimal.slice(pow, powNum)) * BigInt(10 ** Math.max(powNum - decimal.length, 0)) : BigInt(0);
42
- smallValue = BigInt(effectDecimal) * BigInt(10 ** (powNum - effectDecimal.length)) + tinyValue;
43
- } else {
44
- smallValue = BigInt(0);
45
- }
46
- const value = bigValue + smallValue;
47
- return valueSymbol === "-" ? value * BigInt(-1) : value;
48
- } catch {
49
- return Number.NaN;
50
- }
51
- };
@@ -1,42 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var decon_exports = {};
20
- __export(decon_exports, {
21
- deconPowersSum: () => deconPowersSum
22
- });
23
- module.exports = __toCommonJS(decon_exports);
24
- const ERROR_MESSAGE = {
25
- INT: "\u53C2\u6570\u5FC5\u987B\u662F\u6574\u6570",
26
- MIN: "\u591A\u4E2A2\u7684\u6B63\u6574\u6570\u5E42(\u4E24\u4E24\u4E0D\u76F8\u7B49)\u4E4B\u548C\u5FC5\u5B9A\u5927\u4E8E\u7B49\u4E8E1"
27
- };
28
- const deconPowersSum = (sum, sort) => {
29
- if (sum < 1) {
30
- throw new Error(ERROR_MESSAGE.MIN);
31
- } else if (sum !== Math.floor(sum)) {
32
- throw new Error(ERROR_MESSAGE.INT);
33
- }
34
- const list = [];
35
- let cache = sum;
36
- while (cache) {
37
- const power = Math.log2(cache) ^ 0;
38
- list.push(power);
39
- cache -= Math.pow(2, power);
40
- }
41
- return sort === "asc" ? list.reverse() : list;
42
- };
@@ -1,25 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var angle_exports = {};
20
- __export(angle_exports, {
21
- rotateAngle: () => rotateAngle
22
- });
23
- module.exports = __toCommonJS(angle_exports);
24
- var import_rad = require("./rad");
25
- const rotateAngle = (from, angle, visit) => (0, import_rad.rotateRad)(from, angle / 180 * Math.PI, visit);
@@ -1,31 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var rad_exports = {};
20
- __export(rad_exports, {
21
- rotateRad: () => rotateRad
22
- });
23
- module.exports = __toCommonJS(rad_exports);
24
- const rotateRad = (from, rad, visit = [0, 0]) => {
25
- const x = from[0] - visit[0];
26
- const y = from[1] - visit[1];
27
- return [
28
- x * Math.cos(rad) + y * Math.sin(rad) + visit[0],
29
- y * Math.cos(rad) - x * Math.sin(rad) + visit[1]
30
- ];
31
- };
@@ -1,73 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var url_params_exports = {};
20
- __export(url_params_exports, {
21
- cubeURLParams: () => cubeURLParams,
22
- flatURLParams: () => flatURLParams
23
- });
24
- module.exports = __toCommonJS(url_params_exports);
25
- var import_lodash_es = require("lodash-es");
26
- var import_key = require("../is/key");
27
- const cubes = {
28
- string: (text) => text,
29
- boolean: (text) => text === "true",
30
- number: (text) => Number(text),
31
- bigint: (text) => BigInt(text),
32
- date: (text) => new Date(text),
33
- regexp: (text) => new RegExp(text),
34
- null: () => null
35
- };
36
- const flats = {
37
- string: (data) => flatEncode(data),
38
- boolean: (data) => `${data}`,
39
- number: (data) => `${data}`,
40
- bigint: (data) => `${data}`,
41
- date: (data) => data.toJSON(),
42
- regexp: (data) => flatEncode(data.source),
43
- null: () => "null"
44
- };
45
- const cubeURLParams = (text, serializes) => {
46
- const params = new URLSearchParams(text);
47
- const result = {};
48
- for (const [key, value] of params) {
49
- const serialize = serializes[key];
50
- if (!serialize) continue;
51
- if ((0, import_lodash_es.isString)(serialize) && (0, import_key.isKey)(serialize, cubes)) {
52
- result[key] = cubes[serialize](value);
53
- } else {
54
- result[key] = serialize.cube(value);
55
- }
56
- }
57
- return result;
58
- };
59
- const re_flat = /\+/g;
60
- const flatEncode = (text) => text.replace(re_flat, () => "%2B");
61
- const flatURLParams = (data, serializes) => {
62
- const params = new URLSearchParams();
63
- for (const key in data) {
64
- const value = data[key];
65
- const serialize = serializes[key];
66
- if (!serialize) continue;
67
- params.append(
68
- key,
69
- (0, import_lodash_es.isString)(serialize) && (0, import_key.isKey)(serialize, flats) ? flats[serialize](value) : serialize.flat(value)
70
- );
71
- }
72
- return params.toString();
73
- };
package/dist/style/css.js DELETED
@@ -1,45 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var css_exports = {};
20
- __export(css_exports, {
21
- css: () => css
22
- });
23
- module.exports = __toCommonJS(css_exports);
24
- var import_lodash_es = require("lodash-es");
25
- var import_null = require("../is/null");
26
- const hump = /[A-Z]/g;
27
- const css = (...args) => {
28
- const list = [];
29
- for (let i = 0; i < args.length; i++) {
30
- const data = args[i];
31
- if (!data) continue;
32
- if ((0, import_lodash_es.isString)(data)) {
33
- list.push(data);
34
- } else if (Array.isArray(data)) {
35
- const result = css(...data);
36
- result && list.push(result);
37
- } else {
38
- for (const key in data) {
39
- const value = data[key];
40
- (0, import_null.isNull)(value) || list.push(`${key.replace(hump, ($0) => "-" + $0.toLocaleLowerCase())}: ${value}`);
41
- }
42
- }
43
- }
44
- return list.join(";");
45
- };
@@ -1,84 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var subscriber_exports = {};
20
- __export(subscriber_exports, {
21
- default: () => Subscriber
22
- });
23
- module.exports = __toCommonJS(subscriber_exports);
24
- var import_strings = require("./convert/strings");
25
- class Subscriber {
26
- #listeners = {};
27
- #once = {};
28
- $on(name, listener) {
29
- const listeners = this.#listeners;
30
- if (name in listeners) {
31
- listeners[name].push(listener);
32
- } else {
33
- listeners[name] = [listener];
34
- }
35
- return this;
36
- }
37
- $once(name, listener) {
38
- this.$on(name, listener);
39
- const index = this.#listeners[name].length - 1;
40
- const once = this.#once;
41
- if (name in once) {
42
- once[name].push(index);
43
- } else {
44
- once[name] = [index];
45
- }
46
- return this;
47
- }
48
- $emit(name, ...args) {
49
- const listeners = this.#listeners[name];
50
- if (!listeners) return this;
51
- const once = (0, import_strings.hash8strings)(this.#once[name] || []);
52
- this.#listeners[name] = listeners.reduce((list, listener, index) => {
53
- listener(...args);
54
- index in once || list.push(listener);
55
- return list;
56
- }, []);
57
- delete this.#once[name];
58
- return this;
59
- }
60
- $off(name, listener) {
61
- const listeners = this.#listeners;
62
- const once = this.#once;
63
- if (name in listeners === false) return this;
64
- if (listener) {
65
- let count;
66
- listeners[name].some((value, index) => {
67
- if (value === listener) {
68
- count = index;
69
- listeners[name].splice(index, 1);
70
- return true;
71
- }
72
- }) && once[name].some((value, index) => {
73
- if (value === count) {
74
- listeners[name].splice(index, 1);
75
- return true;
76
- }
77
- });
78
- } else {
79
- delete listeners[name];
80
- delete this.#once[name];
81
- }
82
- return this;
83
- }
84
- }
@@ -1,116 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var flex_exports = {};
20
- __export(flex_exports, {
21
- FlexTable: () => FlexTable
22
- });
23
- module.exports = __toCommonJS(flex_exports);
24
- class FlexTable {
25
- #data = [];
26
- /**
27
- * 行数
28
- */
29
- get rowspan() {
30
- return this.#data.length;
31
- }
32
- /**
33
- * 总数据长度
34
- */
35
- get length() {
36
- return this.#data.reduce((length, list) => length + list.length, 0);
37
- }
38
- constructor() {
39
- this.newline();
40
- }
41
- /**
42
- * 创建新行
43
- */
44
- newline() {
45
- this.#data.push([]);
46
- return this;
47
- }
48
- push(value) {
49
- const rowspan = this.#data.length;
50
- rowspan || this.newline();
51
- this.#data[rowspan - 1].push(value);
52
- return this;
53
- }
54
- /**
55
- * 替换指定位置的数据
56
- * @description 指定位置必需为有效位置
57
- */
58
- replace(rowspan, colspan, value) {
59
- const list = this.#data[rowspan];
60
- list && colspan in list && (list[colspan] = value);
61
- return this;
62
- }
63
- /**
64
- * 从指定位置开始移除或者替换/添加元素
65
- * @description 指定位置必需为有效位置
66
- */
67
- splice(rowspan, colspan, deleteCount, ...values) {
68
- const list = this.#data[rowspan];
69
- list && colspan in list && list.splice(colspan, deleteCount, ...values);
70
- return this;
71
- }
72
- pop() {
73
- const data = this.#data;
74
- const rowspan = data.length;
75
- if (!rowspan) return null;
76
- const list = data[rowspan - 1];
77
- if (list.length) {
78
- return list.pop();
79
- } else {
80
- data.pop();
81
- return this.pop();
82
- }
83
- }
84
- /**
85
- * 遍历数据
86
- */
87
- each(callback) {
88
- const data = this.#data;
89
- outloop: for (let i = 0; i < data.length; i++) {
90
- const list = data[i];
91
- for (let j = 0; j < list.length; j++) {
92
- if (callback(list[j], i, j) === false) break outloop;
93
- }
94
- }
95
- }
96
- /**
97
- * 反序遍历数据
98
- */
99
- reverseEach(callback) {
100
- const data = this.#data;
101
- outloop: for (let i = data.length; i; ) {
102
- const list = data[--i];
103
- for (let j = list.length; j; ) {
104
- if (callback(list[--j], i, j) === false) break outloop;
105
- }
106
- }
107
- }
108
- /**
109
- * 清空数据
110
- */
111
- clear() {
112
- if (this.#data.length) {
113
- this.#data = [];
114
- }
115
- }
116
- }