@vope/utils 1.4.32 → 1.5.0

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.
@@ -5,10 +5,8 @@ const compareVersion = (from, to) => {
5
5
  for (let i = 0, max = Math.max(froms.length, tos.length); i < max; i++) {
6
6
  const fromV = +froms[i] || 0;
7
7
  const toV = +tos[i] || 0;
8
- if (fromV > toV)
9
- return -1;
10
- if (fromV < toV)
11
- return 1;
8
+ if (fromV > toV) return -1;
9
+ if (fromV < toV) return 1;
12
10
  }
13
11
  return 0;
14
12
  };
@@ -1,10 +1,8 @@
1
1
  import { hash8strings } from "../convert/strings";
2
2
  const deepWeakEqual = (from, to, exclude) => {
3
- if (typeof from !== "object" || from === null || typeof to !== "object" || to === null)
4
- return from === to;
3
+ if (typeof from !== "object" || from === null || typeof to !== "object" || to === null) return from === to;
5
4
  if (Array.isArray(from) && Array.isArray(to)) {
6
- if (from.length !== to.length)
7
- return false;
5
+ if (from.length !== to.length) return false;
8
6
  return !from.some((t1, index) => {
9
7
  if (!deepWeakEqual(t1, to[index])) {
10
8
  return true;
@@ -14,8 +12,7 @@ const deepWeakEqual = (from, to, exclude) => {
14
12
  const caches = {};
15
13
  const excludeCaches = exclude && hash8strings(exclude);
16
14
  for (const key in from) {
17
- if (excludeCaches && key in excludeCaches)
18
- continue;
15
+ if (excludeCaches && key in excludeCaches) continue;
19
16
  if (!deepWeakEqual(from[key], to[key])) {
20
17
  return false;
21
18
  } else {
@@ -23,8 +20,7 @@ const deepWeakEqual = (from, to, exclude) => {
23
20
  }
24
21
  }
25
22
  for (const key in to) {
26
- if (excludeCaches && key in excludeCaches || key in caches)
27
- continue;
23
+ if (excludeCaches && key in excludeCaches || key in caches) continue;
28
24
  if (!deepWeakEqual(from[key], to[key])) {
29
25
  return false;
30
26
  }
package/lib/encoding.js CHANGED
@@ -30,8 +30,7 @@ const getEncoding = (uint, limit = 1024) => {
30
30
  top:
31
31
  for (let i = 0, max = Math.min(uint.length, limit); i < max; i++) {
32
32
  const data = uint[i];
33
- if (data < 128)
34
- continue;
33
+ if (data < 128) continue;
35
34
  const match = data.toString(2).match(utf8_first_prefix);
36
35
  if (match) {
37
36
  for (let m = 0; m < match[0].length - 1; m++) {
package/lib/is/class.js CHANGED
@@ -4,21 +4,15 @@ const re_this = /\b\(this\b|\bthis[\.\[]\b/;
4
4
  const re_check = /classCallCheck\(this/;
5
5
  const re_default = /^function\sdefault_\d+\s*\(/;
6
6
  const isClass = (value, strict = true) => {
7
- if (typeof value !== "function")
8
- return false;
7
+ if (typeof value !== "function") return false;
9
8
  const proto = value.prototype;
10
- if (!proto || proto.constructor !== value)
11
- return false;
9
+ if (!proto || proto.constructor !== value) return false;
12
10
  const str = value.toString();
13
- if (str.slice(0, 5) === "class" || Object.getOwnPropertyNames(proto).length >= 2)
14
- return true;
15
- if (re_anonymous.test(str))
16
- return false;
17
- if (strict && re_function.test(str))
18
- return true;
11
+ if (str.slice(0, 5) === "class" || Object.getOwnPropertyNames(proto).length >= 2) return true;
12
+ if (re_anonymous.test(str)) return false;
13
+ if (strict && re_function.test(str)) return true;
19
14
  if (re_this.test(str)) {
20
- if (!strict || re_check.test(str))
21
- return true;
15
+ if (!strict || re_check.test(str)) return true;
22
16
  return re_default.test(str);
23
17
  }
24
18
  return false;
@@ -117,8 +117,7 @@ class MemoryBasic {
117
117
  }
118
118
  return true;
119
119
  }
120
- }))
121
- return this;
120
+ })) return this;
122
121
  for (const [type, target] of memorys) {
123
122
  const memory = this.#reflex(target);
124
123
  memory.forEach((value, i) => {
@@ -141,8 +140,7 @@ class MemoryBasic {
141
140
  */
142
141
  deleteType(type) {
143
142
  const { memorys, list } = this;
144
- if (!memorys.has(type))
145
- return this;
143
+ if (!memorys.has(type)) return this;
146
144
  const local = hash8strings(this.#reflex(memorys.get(type)));
147
145
  const Memory = this.constructor;
148
146
  const imitator = new Memory(this.key, {
@@ -34,8 +34,7 @@ class MemorySimple {
34
34
  */
35
35
  get(type) {
36
36
  const value = this.#memory.get(type);
37
- if (value === null)
38
- return value;
37
+ if (value === null) return value;
39
38
  return value.length ? value[0] : null;
40
39
  }
41
40
  /**
@@ -33,8 +33,7 @@ class Neo4jAhchors {
33
33
  neo4j.sources.get(nodeId),
34
34
  neo4j.targets.get(nodeId)
35
35
  ].forEach((list, i) => {
36
- if (!list)
37
- return;
36
+ if (!list) return;
38
37
  let diffCount = 0;
39
38
  let sameCount = 0;
40
39
  list.forEach((edge) => {
@@ -83,8 +82,7 @@ class Neo4jAhchors {
83
82
  const target = edge[targetField];
84
83
  const direct = this.getDir(source, target);
85
84
  const invert = this.getDir(target, source);
86
- if (direct in caches)
87
- return;
85
+ if (direct in caches) return;
88
86
  const directs = dirs.get(direct) || [];
89
87
  const inverts = dirs.get(invert) || [];
90
88
  const directsLength = directs.length;
@@ -100,8 +98,7 @@ class Neo4jAhchors {
100
98
  const target = edge[targetField];
101
99
  const direct = this.getDir(source, target);
102
100
  const invert = this.getDir(target, source);
103
- if (direct in caches)
104
- return;
101
+ if (direct in caches) return;
105
102
  const directs = neo4j.dirs.get(direct) || [];
106
103
  const inverts = neo4j.dirs.get(invert) || [];
107
104
  const directsLength = directs.length;
@@ -119,8 +116,7 @@ class Neo4jAhchors {
119
116
  */
120
117
  findAnchor(id) {
121
118
  const anchor = this.#anchors[id];
122
- if (!anchor)
123
- return null;
119
+ if (!anchor) return null;
124
120
  return {
125
121
  source: anchor.source || 0,
126
122
  target: anchor.target || 0
@@ -133,8 +129,7 @@ class Neo4jAhchors {
133
129
  getOffset(id) {
134
130
  const { neo4j } = this;
135
131
  const edge = neo4j.edges.get(id);
136
- if (!edge)
137
- return -1;
132
+ if (!edge) return -1;
138
133
  const { dirs, edgeField, sourceField, targetField } = neo4j;
139
134
  const source = edge[sourceField];
140
135
  const target = edge[targetField];
@@ -155,8 +150,7 @@ class Neo4jAhchors {
155
150
  const directsSize = directs.length;
156
151
  const invertsSize = inverts.length;
157
152
  const total = directsSize + invertsSize;
158
- if (total === 1)
159
- return -1;
153
+ if (total === 1) return -1;
160
154
  if (directsSize === 0 || invertsSize === 0) {
161
155
  return total / 2 - index - 0.5;
162
156
  } else {
package/lib/neo4j.js CHANGED
@@ -68,8 +68,7 @@ class Neo4j {
68
68
  nodes.push(value);
69
69
  } else if (type === "delete") {
70
70
  const node = nodes.get(value);
71
- if (!node)
72
- return [];
71
+ if (!node) return [];
73
72
  nodes.delete(node);
74
73
  const id = node[this.#nPrimaryKey];
75
74
  const sourceKey = this.#sourceKey;
@@ -111,8 +110,7 @@ class Neo4j {
111
110
  edge[sourceKey] === edge[targetKey] || dirs.push(edge);
112
111
  } else if (type === "delete") {
113
112
  const edge = edges.get(value);
114
- if (!edge)
115
- return false;
113
+ if (!edge) return false;
116
114
  edges.delete(edge);
117
115
  sources.delete(edge);
118
116
  targets.delete(edge);
@@ -140,8 +138,7 @@ const shield_keys = hash8strings([
140
138
  const shield = (obj, key, origin) => {
141
139
  const proxy = new Proxy({}, {
142
140
  get(target, p) {
143
- if (p in shield_keys)
144
- return;
141
+ if (p in shield_keys) return;
145
142
  const value = origin[p];
146
143
  if (typeof value === "function") {
147
144
  return function(...args) {
package/lib/parse/num.js CHANGED
@@ -2,17 +2,13 @@ import { isNumber } from "lodash-es";
2
2
  const pow = Math.floor(Math.log10(Number.MAX_SAFE_INTEGER));
3
3
  const re_num = /^([-+]?)0*(\d+)(?:(n)|(?:\.(\d+))?(?:[Ee]([-+]?)(\d+))?)$/;
4
4
  const parseNum = (num) => {
5
- if (isNumber(num) || typeof num === "bigint")
6
- return num;
5
+ if (isNumber(num) || typeof num === "bigint") return num;
7
6
  const match = num.match(re_num);
8
- if (!match)
9
- return Number.NaN;
7
+ if (!match) return Number.NaN;
10
8
  const [, valueSymbol, integer, bigint, decimal, powSymbol, powValue] = match;
11
- if (bigint === "n")
12
- return BigInt(valueSymbol + integer);
9
+ if (bigint === "n") return BigInt(valueSymbol + integer);
13
10
  const powSize = integer.length - 1 + (powValue ? powSymbol === "-" ? -powValue : +powValue : 0);
14
- if (powSize < pow || powSize === pow && +integer.slice(0, -1) < Number.MAX_SAFE_INTEGER / 10)
15
- return +num;
11
+ if (powSize < pow || powSize === pow && +integer.slice(0, -1) < Number.MAX_SAFE_INTEGER / 10) return +num;
16
12
  try {
17
13
  const bigValue = BigInt(integer.slice(0, powSize + 1).padEnd(powSize + 1, "0"));
18
14
  let smallValue;
@@ -23,8 +23,7 @@ const cubeURLParams = (text, serializes) => {
23
23
  const result = {};
24
24
  for (const [key, value] of params) {
25
25
  const serialize = serializes[key];
26
- if (!serialize)
27
- continue;
26
+ if (!serialize) continue;
28
27
  if (isString(serialize) && isKey(serialize, cubes)) {
29
28
  result[key] = cubes[serialize](value);
30
29
  } else {
@@ -40,8 +39,7 @@ const flatURLParams = (data, serializes) => {
40
39
  for (const key in data) {
41
40
  const value = data[key];
42
41
  const serialize = serializes[key];
43
- if (!serialize)
44
- continue;
42
+ if (!serialize) continue;
45
43
  params.append(
46
44
  key,
47
45
  isString(serialize) && isKey(serialize, flats) ? flats[serialize](value) : serialize.flat(value)
@@ -15,8 +15,7 @@ const encrypt = (data) => {
15
15
  let text = "";
16
16
  for (const key2 in data) {
17
17
  const value = data[key2];
18
- if (value === void 0)
19
- continue;
18
+ if (value === void 0) continue;
20
19
  text && (text += "&");
21
20
  text += key2 + ":" + value;
22
21
  }
@@ -136,8 +135,7 @@ class OfflineStorage {
136
135
  */
137
136
  async push(data) {
138
137
  this.validate((e) => {
139
- if (e)
140
- throw e;
138
+ if (e) throw e;
141
139
  }, MESSAGES.push);
142
140
  const size = this.#size;
143
141
  const key2 = structKey(size);
@@ -149,14 +147,12 @@ class OfflineStorage {
149
147
  */
150
148
  async update(index, data) {
151
149
  this.validate((e) => {
152
- if (e)
153
- throw e;
150
+ if (e) throw e;
154
151
  }, MESSAGES.update);
155
152
  const forage = this.#forage;
156
153
  const key2 = structKey(index);
157
154
  const value = await forage.getItem(key2);
158
- if (value === null)
159
- return false;
155
+ if (value === null) return false;
160
156
  await forage.setItem(key2, await this.#crypto.encrypt(data));
161
157
  return true;
162
158
  }
@@ -165,8 +161,7 @@ class OfflineStorage {
165
161
  */
166
162
  async get(index) {
167
163
  this.validate((e) => {
168
- if (e)
169
- throw e;
164
+ if (e) throw e;
170
165
  }, MESSAGES.get);
171
166
  const key2 = structKey(index);
172
167
  const value = await this.#forage.getItem(key2);
@@ -177,8 +172,7 @@ class OfflineStorage {
177
172
  */
178
173
  async clear() {
179
174
  this.validate((e) => {
180
- if (e)
181
- throw e;
175
+ if (e) throw e;
182
176
  });
183
177
  this.#size = 0;
184
178
  await localforage.dropInstance({
@@ -204,20 +198,17 @@ class OfflineStorage {
204
198
  const databases = await indexedDB.databases();
205
199
  const tasks = [];
206
200
  for (const { name, version } of databases) {
207
- if (name === void 0)
208
- continue;
201
+ if (name === void 0) continue;
209
202
  let text;
210
203
  try {
211
204
  text = sm4.decrypt(name, key, config);
212
205
  } catch {
213
206
  continue;
214
207
  }
215
- if (text.slice(0, size) !== PREFIX)
216
- continue;
208
+ if (text.slice(0, size) !== PREFIX) continue;
217
209
  const forage = createInstance(name, version);
218
210
  const value = await forage.getItem(HEADER);
219
- if (value === null || decrypt(value).token !== token || callback && callback(text.slice(size)))
220
- continue;
211
+ if (value === null || decrypt(value).token !== token || callback && callback(text.slice(size))) continue;
221
212
  const idb = indexedDB.deleteDatabase(text);
222
213
  tasks.push(new Promise((resolve) => {
223
214
  idb.onerror = () => resolve();
package/lib/style/css.js CHANGED
@@ -5,8 +5,7 @@ const css = (...args) => {
5
5
  const list = [];
6
6
  for (let i = 0; i < args.length; i++) {
7
7
  const data = args[i];
8
- if (!data)
9
- continue;
8
+ if (!data) continue;
10
9
  if (isString(data)) {
11
10
  list.push(data);
12
11
  } else if (Array.isArray(data)) {
package/lib/subscriber.js CHANGED
@@ -24,8 +24,7 @@ class Subscriber {
24
24
  }
25
25
  $emit(name, ...args) {
26
26
  const listeners = this.#listeners[name];
27
- if (!listeners)
28
- return this;
27
+ if (!listeners) return this;
29
28
  const once = hash8strings(this.#once[name] || []);
30
29
  this.#listeners[name] = listeners.reduce((list, listener, index) => {
31
30
  listener(...args);
@@ -38,8 +37,7 @@ class Subscriber {
38
37
  $off(name, listener) {
39
38
  const listeners = this.#listeners;
40
39
  const once = this.#once;
41
- if (name in listeners === false)
42
- return this;
40
+ if (name in listeners === false) return this;
43
41
  if (listener) {
44
42
  let count;
45
43
  listeners[name].some((value, index) => {
package/lib/table/flex.js CHANGED
@@ -49,8 +49,7 @@ class FlexTable {
49
49
  pop() {
50
50
  const data = this.#data;
51
51
  const rowspan = data.length;
52
- if (!rowspan)
53
- return null;
52
+ if (!rowspan) return null;
54
53
  const list = data[rowspan - 1];
55
54
  if (list.length) {
56
55
  return list.pop();
@@ -64,28 +63,24 @@ class FlexTable {
64
63
  */
65
64
  each(callback) {
66
65
  const data = this.#data;
67
- outloop:
68
- for (let i = 0; i < data.length; i++) {
69
- const list = data[i];
70
- for (let j = 0; j < list.length; j++) {
71
- if (callback(list[j], i, j) === false)
72
- break outloop;
73
- }
66
+ outloop: for (let i = 0; i < data.length; i++) {
67
+ const list = data[i];
68
+ for (let j = 0; j < list.length; j++) {
69
+ if (callback(list[j], i, j) === false) break outloop;
74
70
  }
71
+ }
75
72
  }
76
73
  /**
77
74
  * 反序遍历数据
78
75
  */
79
76
  reverseEach(callback) {
80
77
  const data = this.#data;
81
- outloop:
82
- for (let i = data.length; i; ) {
83
- const list = data[--i];
84
- for (let j = list.length; j; ) {
85
- if (callback(list[--j], i, j) === false)
86
- break outloop;
87
- }
78
+ outloop: for (let i = data.length; i; ) {
79
+ const list = data[--i];
80
+ for (let j = list.length; j; ) {
81
+ if (callback(list[--j], i, j) === false) break outloop;
88
82
  }
83
+ }
89
84
  }
90
85
  /**
91
86
  * 清空数据
package/lib/url/join.js CHANGED
@@ -1,8 +1,7 @@
1
1
  const re = /([^:])\/{2,}/g;
2
2
  const joinPaths = (...list) => {
3
3
  const { length } = list;
4
- if (length === 0)
5
- return "";
4
+ if (length === 0) return "";
6
5
  return length === 1 ? list[0] : list.join("/").replace(re, ($0, $1) => `${$1}/`);
7
6
  };
8
7
  export {
package/package.json CHANGED
@@ -1,74 +1,79 @@
1
- {
2
- "name": "@vope/utils",
3
- "version": "1.4.32",
4
- "description": "",
5
- "type": "module",
6
- "publishConfig": {
7
- "access": "public",
8
- "registry": "https://registry.npmjs.org/"
9
- },
10
- "types": "./types/index.d.ts",
11
- "typings": "./types/index.d.ts",
12
- "module": "./lib/index.js",
13
- "main": "./cjs/index.js",
14
- "scripts": {
15
- "start": "esbuild ./start.ts --outfile=start.cjs --format=cjs & node ./start.cjs",
16
- "poststart": "esbuild ./pre.ts --outfile=pre.cjs --format=cjs & node ./pre.cjs",
17
- "build": "npm run start & node ./build.cjs",
18
- "premocha": "node ./build.cjs --type=test",
19
- "mocha": "mocha __tests/**/*.js",
20
- "test": "npm run mocha",
21
- "prepublishOnly": "npm run build & npm run test",
22
- "debug": "npm run start & npm run premocha"
23
- },
24
- "exports": {
25
- ".": {
26
- "import": "./lib/index.js",
27
- "require": "./cjs/index.js"
28
- },
29
- "./package.json": "./package.json"
30
- },
31
- "author": "vope",
32
- "license": "ISC",
33
- "sideEffects": [
34
- "lib/storage/offline.js",
35
- "src/storage/offline.ts"
36
- ],
37
- "files": [
38
- "cjs",
39
- "lib",
40
- "types"
41
- ],
42
- "devDependencies": {
43
- "@babel/parser": "^7.26.5",
44
- "@babel/traverse": "^7.26.5",
45
- "@babel/types": "^7.26.5",
46
- "@rollup/plugin-alias": "^5.1.1",
47
- "@rollup/plugin-commonjs": "^28.0.0",
48
- "@rollup/plugin-json": "^6.1.0",
49
- "@rollup/plugin-node-resolve": "^15.3.0",
50
- "@rollup/plugin-typescript": "^12.1.0",
51
- "@types/babel__traverse": "^7.20.6",
52
- "@types/mocha": "^10.0.6",
53
- "@types/node": "^20.4.5",
54
- "@types/sm-crypto": "^0.3.4",
55
- "esbuild": "^0.19.4",
56
- "glob": "^10.3.10",
57
- "iconv-lite": "^0.6.3",
58
- "mocha": "^10.2.0",
59
- "puppeteer": "^23.4.1",
60
- "rimraf": "^5.0.5",
61
- "rollup": "^4.34.6",
62
- "tslib": "^2.6.1",
63
- "typescript": "^5.3.3"
64
- },
65
- "dependencies": {
66
- "@type-challenges/utils": "^0.1.1",
67
- "@types/lodash-es": "^4.17.9",
68
- "@vope/types": "^1.0.13",
69
- "csstype": "^3.1.3",
70
- "localforage": "^1.10.0",
71
- "lodash-es": "^4.17.21",
72
- "sm-crypto": "^0.3.13"
73
- }
74
- }
1
+ {
2
+ "name": "@vope/utils",
3
+ "version": "1.5.0",
4
+ "description": "",
5
+ "type": "module",
6
+ "publishConfig": {
7
+ "access": "public",
8
+ "registry": "https://registry.npmjs.org/"
9
+ },
10
+ "types": "./types/index.d.ts",
11
+ "typings": "./types/index.d.ts",
12
+ "module": "./lib/index.js",
13
+ "main": "./cjs/index.js",
14
+ "scripts": {
15
+ "start": "esbuild ./start.ts --outfile=start.cjs --format=cjs & node ./start.cjs",
16
+ "poststart": "esbuild ./pre.ts --outfile=pre.cjs --format=cjs & node ./pre.cjs",
17
+ "build": "npm run start & node ./build.cjs",
18
+ "premocha": "node ./build.cjs --type=test",
19
+ "mocha": "mocha __tests/**/*.js",
20
+ "test": "npm run mocha",
21
+ "prepublishOnly": "npm run build & npm run test",
22
+ "debug": "npm run start & npm run premocha"
23
+ },
24
+ "exports": {
25
+ ".": {
26
+ "import": "./lib/index.js",
27
+ "require": "./cjs/index.js"
28
+ }
29
+ },
30
+ "author": "vope",
31
+ "license": "ISC",
32
+ "sideEffects": [
33
+ "lib/storage/offline.js",
34
+ "src/storage/offline.ts"
35
+ ],
36
+ "files": [
37
+ "cjs",
38
+ "lib",
39
+ "types"
40
+ ],
41
+ "devDependencies": {
42
+ "@babel/parser": "^7.26.9",
43
+ "@babel/traverse": "^7.26.9",
44
+ "@babel/types": "^7.26.9",
45
+ "@rollup/plugin-alias": "^5.1.1",
46
+ "@rollup/plugin-commonjs": "^28.0.2",
47
+ "@rollup/plugin-json": "^6.1.0",
48
+ "@rollup/plugin-node-resolve": "^16.0.0",
49
+ "@rollup/plugin-typescript": "^12.1.2",
50
+ "@types/babel__traverse": "^7.20.6",
51
+ "@types/mocha": "^10.0.6",
52
+ "@types/node": "^22.13.5",
53
+ "@types/sm-crypto": "^0.3.4",
54
+ "esbuild": "^0.25.0",
55
+ "glob": "^11.0.1",
56
+ "iconv-lite": "^0.6.3",
57
+ "mocha": "^10.2.0",
58
+ "puppeteer": "^24.3.0",
59
+ "rimraf": "^5.0.5",
60
+ "rollup": "^4.34.8",
61
+ "tslib": "^2.8.1",
62
+ "typescript": "^5.7.3"
63
+ },
64
+ "dependencies": {
65
+ "@type-challenges/utils": "^0.1.1",
66
+ "@types/lodash-es": "^4.17.12",
67
+ "@vope/types": "^1.1.1",
68
+ "csstype": "^3.1.3",
69
+ "localforage": "^1.10.0",
70
+ "lodash-es": "^4.17.21",
71
+ "sm-crypto": "^0.3.13"
72
+ },
73
+ "pnpm": {
74
+ "onlyBuiltDependencies": [
75
+ "esbuild",
76
+ "puppeteer"
77
+ ]
78
+ }
79
+ }
@@ -1,4 +1,4 @@
1
1
  /**
2
2
  * 深度相等性比较(弱比较)
3
3
  */
4
- export declare const deepWeakEqual: <A, B>(from: A, to: B, exclude?: (Extract<keyof A, string | number> | Extract<keyof B, string | number>)[] | undefined) => boolean;
4
+ export declare const deepWeakEqual: <A, B>(from: A, to: B, exclude?: Extract<keyof A | keyof B, string | number>[]) => boolean;
@@ -1,4 +1,4 @@
1
1
  /**
2
2
  * 检测是否为空(undefined/null/'')
3
3
  */
4
- export declare const isEmpty: (value: any) => value is "" | null | undefined;
4
+ export declare const isEmpty: (value: any) => value is undefined | null | "";
@@ -1,4 +1,4 @@
1
1
  /**
2
2
  * 检测是否无值(undefined/null)
3
3
  */
4
- export declare const isNull: (value: any) => value is null | undefined;
4
+ export declare const isNull: (value: any) => value is undefined | null;