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

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.
@@ -0,0 +1,84 @@
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
+ }
@@ -0,0 +1,116 @@
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
+ }
package/dist/union.js ADDED
@@ -0,0 +1,67 @@
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 union_exports = {};
20
+ __export(union_exports, {
21
+ Union: () => Union
22
+ });
23
+ module.exports = __toCommonJS(union_exports);
24
+ class Union {
25
+ constructor(key, formatter) {
26
+ this.key = key;
27
+ this.formatter = formatter;
28
+ }
29
+ #data = {};
30
+ #options = {};
31
+ #raws = {};
32
+ get data() {
33
+ return this.#data;
34
+ }
35
+ get options() {
36
+ return this.#options;
37
+ }
38
+ add(data) {
39
+ const key = data[this.key];
40
+ const result = this.formatter(data);
41
+ this.#raws[key] = data;
42
+ this.#data[key] = result.data;
43
+ this.#options[key] = result.option;
44
+ return this;
45
+ }
46
+ /**
47
+ * 获取原始数据
48
+ */
49
+ getRaw(key) {
50
+ return this.#raws[key];
51
+ }
52
+ /**
53
+ * 从已有的联合中拷贝数据
54
+ */
55
+ clone(target, key) {
56
+ const { data, options } = target;
57
+ const keys = Array.isArray(key) ? key : [key];
58
+ keys.forEach((key2) => {
59
+ if (key2 in data) {
60
+ this.#raws[key2] = target.getRaw(key2);
61
+ this.#data[key2] = data[key2];
62
+ this.#options[key2] = options[key2];
63
+ }
64
+ });
65
+ return this;
66
+ }
67
+ }
@@ -0,0 +1,29 @@
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 join_exports = {};
20
+ __export(join_exports, {
21
+ joinPaths: () => joinPaths
22
+ });
23
+ module.exports = __toCommonJS(join_exports);
24
+ const re = /([^:])\/{2,}/g;
25
+ const joinPaths = (...list) => {
26
+ const { length } = list;
27
+ if (length === 0) return "";
28
+ return length === 1 ? list[0] : list.join("/").replace(re, ($0, $1) => `${$1}/`);
29
+ };
@@ -0,0 +1,28 @@
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 params_exports = {};
20
+ __export(params_exports, {
21
+ connectURLParams: () => connectURLParams
22
+ });
23
+ module.exports = __toCommonJS(params_exports);
24
+ var import_url_params = require("../serialize/url-params");
25
+ const connectURLParams = (url, params, serializes) => {
26
+ const query = (0, import_url_params.flatURLParams)(params, serializes);
27
+ return query ? url.includes("?") ? url + "&" + query : url + "?" + query : url;
28
+ };
package/dist/wait.js ADDED
@@ -0,0 +1,24 @@
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 wait_exports = {};
20
+ __export(wait_exports, {
21
+ wait: () => wait
22
+ });
23
+ module.exports = __toCommonJS(wait_exports);
24
+ const wait = (delay = 0) => new Promise((resolve) => setTimeout(resolve, delay));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vope/utils",
3
- "version": "1.6.0-bate.5",
3
+ "version": "1.6.0-bate.7",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "publishConfig": {
@@ -26,8 +26,6 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
26
26
  mod
27
27
  ));
28
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
-
30
- // src/storage/offline.ts
31
29
  var offline_exports = {};
32
30
  __export(offline_exports, {
33
31
  OfflineStorage: () => OfflineStorage
@@ -36,17 +34,17 @@ module.exports = __toCommonJS(offline_exports);
36
34
  var import_localforage = __toESM(require("localforage"), 1);
37
35
  var import_lodash_es = require("lodash-es");
38
36
  var import_sm_crypto = require("sm-crypto");
39
- var NAME = "@vope/utils";
40
- var PREFIX = NAME + "_";
41
- var key = [25, 144, 1, 32, 25, 135, 6, 40, 32, 23, 18, 19, 32, 36, 9, 5];
42
- var iv = [182, 59, 9, 29, 86, 64, 118, 111, 112, 101, 47, 117, 116, 105, 108, 115];
43
- var config = {
37
+ const NAME = "@vope/utils";
38
+ const PREFIX = NAME + "_";
39
+ const key = [25, 144, 1, 32, 25, 135, 6, 40, 32, 23, 18, 19, 32, 36, 9, 5];
40
+ const iv = [182, 59, 9, 29, 86, 64, 118, 111, 112, 101, 47, 117, 116, 105, 108, 115];
41
+ const config = {
44
42
  output: "string",
45
43
  mode: "cbc",
46
44
  iv
47
45
  };
48
- var HEADER = "." + import_sm_crypto.sm4.encrypt(NAME, key, config);
49
- var encrypt = (data) => {
46
+ const HEADER = "." + import_sm_crypto.sm4.encrypt(NAME, key, config);
47
+ const encrypt = (data) => {
50
48
  let text = "";
51
49
  for (const key2 in data) {
52
50
  const value = data[key2];
@@ -56,7 +54,7 @@ var encrypt = (data) => {
56
54
  }
57
55
  return import_sm_crypto.sm4.encrypt(text, key, config);
58
56
  };
59
- var decrypt = (text) => {
57
+ const decrypt = (text) => {
60
58
  const data = {};
61
59
  let value;
62
60
  try {
@@ -74,21 +72,21 @@ var decrypt = (text) => {
74
72
  });
75
73
  return data;
76
74
  };
77
- var structKey = (index) => index.toString(16).padStart(8, "0");
78
- var reductKey = (key2) => parseInt(key2, 16);
79
- var MESSAGES = {
75
+ const structKey = (index) => index.toString(16).padStart(8, "0");
76
+ const reductKey = (key2) => parseInt(key2, 16);
77
+ const MESSAGES = {
80
78
  mount: "Please wait for the mounting to complete",
81
79
  auth: "Unauthorized operation",
82
80
  push: "Cannot add data to expired databases",
83
81
  update: "Cannot update data to expired databases",
84
82
  get: "Cannot get data from expired databases"
85
83
  };
86
- var createInstance = (name, version = 2) => import_localforage.default.createInstance({
84
+ const createInstance = (name, version = 2) => import_localforage.default.createInstance({
87
85
  driver: import_localforage.default.INDEXEDDB,
88
86
  name,
89
87
  version
90
88
  });
91
- var OfflineStorage = class _OfflineStorage {
89
+ class OfflineStorage {
92
90
  #forage;
93
91
  #expire;
94
92
  #auth = false;
@@ -216,7 +214,7 @@ var OfflineStorage = class _OfflineStorage {
216
214
  }
217
215
  static default(options) {
218
216
  (0, import_lodash_es.isString)(options) && (options = { name: options });
219
- return new _OfflineStorage({
217
+ return new OfflineStorage({
220
218
  ...options,
221
219
  crypto: {
222
220
  encrypt(plain) {
@@ -252,4 +250,4 @@ var OfflineStorage = class _OfflineStorage {
252
250
  }
253
251
  await Promise.all(tasks);
254
252
  }
255
- };
253
+ }