@vope/utils 1.6.0-bate.1 → 1.6.0-bate.2
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/package.json +13 -15
- package/cjs/index.js +0 -1361
- package/cjs/storage/offline.js +0 -5186
- package/lib/clamp.js +0 -11
- package/lib/classnames.js +0 -17
- package/lib/compare/version.js +0 -15
- package/lib/compare/weak-equal.js +0 -33
- package/lib/convert/json.js +0 -7
- package/lib/convert/object.js +0 -7
- package/lib/convert/strings.js +0 -7
- package/lib/desens.js +0 -51
- package/lib/encoding.js +0 -56
- package/lib/index.js +0 -73
- package/lib/input-regex.js +0 -8
- package/lib/is/class.js +0 -22
- package/lib/is/empty.js +0 -5
- package/lib/is/key.js +0 -4
- package/lib/is/null.js +0 -4
- package/lib/load/image.js +0 -11
- package/lib/memory/basic.js +0 -167
- package/lib/memory/list.js +0 -12
- package/lib/memory/power.js +0 -13
- package/lib/memory/simple.js +0 -94
- package/lib/memory/type.d.js +0 -0
- package/lib/neo4j-anchors.js +0 -169
- package/lib/neo4j.js +0 -161
- package/lib/once.js +0 -8
- package/lib/parse/num.js +0 -31
- package/lib/power/decon.js +0 -22
- package/lib/rotate/angle.js +0 -5
- package/lib/rotate/rad.js +0 -11
- package/lib/serialize/url-params.js +0 -53
- package/lib/storage/offline.js +0 -223
- package/lib/style/css.js +0 -25
- package/lib/subscriber.js +0 -64
- package/lib/table/flex.js +0 -96
- package/lib/union.js +0 -47
- package/lib/url/join.js +0 -9
- package/lib/url/params.js +0 -8
- package/lib/wait.js +0 -4
- package/types/clamp.d.ts +0 -4
- package/types/classnames.d.ts +0 -7
- package/types/compare/version.d.ts +0 -5
- package/types/compare/weak-equal.d.ts +0 -4
- package/types/convert/json.d.ts +0 -12
- package/types/convert/object.d.ts +0 -12
- package/types/convert/strings.d.ts +0 -6
- package/types/desens.d.ts +0 -40
- package/types/encoding.d.ts +0 -9
- package/types/index.d.ts +0 -34
- package/types/input-regex.d.ts +0 -12
- package/types/is/class.d.ts +0 -4
- package/types/is/empty.d.ts +0 -4
- package/types/is/key.d.ts +0 -4
- package/types/is/null.d.ts +0 -4
- package/types/load/image.d.ts +0 -5
- package/types/memory/basic.d.ts +0 -79
- package/types/memory/list.d.ts +0 -8
- package/types/memory/power.d.ts +0 -8
- package/types/memory/simple.d.ts +0 -60
- package/types/memory/type.d.ts +0 -11
- package/types/neo4j-anchors.d.ts +0 -50
- package/types/neo4j.d.ts +0 -82
- package/types/once.d.ts +0 -6
- package/types/parse/num.d.ts +0 -8
- package/types/power/decon.d.ts +0 -9
- package/types/rotate/angle.d.ts +0 -8
- package/types/rotate/rad.d.ts +0 -8
- package/types/serialize/url-params.d.ts +0 -43
- package/types/storage/offline.d.ts +0 -51
- package/types/style/css.d.ts +0 -9
- package/types/subscriber.d.ts +0 -11
- package/types/table/flex.d.ts +0 -43
- package/types/union.d.ts +0 -34
- package/types/url/join.d.ts +0 -4
- package/types/url/params.d.ts +0 -8
- package/types/wait.d.ts +0 -4
package/lib/clamp.js
DELETED
package/lib/classnames.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { isBoolean, isString } from "lodash-es";
|
|
2
|
-
const add = (a, b) => a ? a + " " + b : b;
|
|
3
|
-
const classnames = (...list) => list.reduce((caches, data) => {
|
|
4
|
-
if (isString(data)) {
|
|
5
|
-
data && (caches = add(caches, data));
|
|
6
|
-
} else if (Array.isArray(data)) {
|
|
7
|
-
data.forEach((value) => value && isString(value) && (caches = add(caches, value)));
|
|
8
|
-
} else if (!isBoolean(data)) {
|
|
9
|
-
for (const key in data) {
|
|
10
|
-
key && data[key] && (caches = add(caches, key));
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
return caches;
|
|
14
|
-
}, "");
|
|
15
|
-
export {
|
|
16
|
-
classnames
|
|
17
|
-
};
|
package/lib/compare/version.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
const CHAR = ".";
|
|
2
|
-
const compareVersion = (from, to) => {
|
|
3
|
-
const froms = from.split(CHAR);
|
|
4
|
-
const tos = to.split(CHAR);
|
|
5
|
-
for (let i = 0, max = Math.max(froms.length, tos.length); i < max; i++) {
|
|
6
|
-
const fromV = +froms[i] || 0;
|
|
7
|
-
const toV = +tos[i] || 0;
|
|
8
|
-
if (fromV > toV) return -1;
|
|
9
|
-
if (fromV < toV) return 1;
|
|
10
|
-
}
|
|
11
|
-
return 0;
|
|
12
|
-
};
|
|
13
|
-
export {
|
|
14
|
-
compareVersion
|
|
15
|
-
};
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { hash8strings } from "../convert/strings";
|
|
2
|
-
const deepWeakEqual = (from, to, exclude) => {
|
|
3
|
-
if (typeof from !== "object" || from === null || typeof to !== "object" || to === null) return from === to;
|
|
4
|
-
if (Array.isArray(from) && Array.isArray(to)) {
|
|
5
|
-
if (from.length !== to.length) return false;
|
|
6
|
-
return !from.some((t1, index) => {
|
|
7
|
-
if (!deepWeakEqual(t1, to[index])) {
|
|
8
|
-
return true;
|
|
9
|
-
}
|
|
10
|
-
});
|
|
11
|
-
} else {
|
|
12
|
-
const caches = {};
|
|
13
|
-
const excludeCaches = exclude && hash8strings(exclude);
|
|
14
|
-
for (const key in from) {
|
|
15
|
-
if (excludeCaches && key in excludeCaches) continue;
|
|
16
|
-
if (!deepWeakEqual(from[key], to[key])) {
|
|
17
|
-
return false;
|
|
18
|
-
} else {
|
|
19
|
-
caches[key] = key;
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
for (const key in to) {
|
|
23
|
-
if (excludeCaches && key in excludeCaches || key in caches) continue;
|
|
24
|
-
if (!deepWeakEqual(from[key], to[key])) {
|
|
25
|
-
return false;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
return true;
|
|
30
|
-
};
|
|
31
|
-
export {
|
|
32
|
-
deepWeakEqual
|
|
33
|
-
};
|
package/lib/convert/json.js
DELETED
package/lib/convert/object.js
DELETED
package/lib/convert/strings.js
DELETED
package/lib/desens.js
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import { isString } from "lodash-es";
|
|
2
|
-
const desensEncrypt = (plaintext, encrypt) => {
|
|
3
|
-
const rules = [];
|
|
4
|
-
let point = -1;
|
|
5
|
-
let ciphertext = encrypt(plaintext).reduce((cache, { range, ciphertext: ciphertext2 }) => {
|
|
6
|
-
cache += plaintext.slice(point + 1, range[0]) + ciphertext2;
|
|
7
|
-
point = range[1];
|
|
8
|
-
rules.push({
|
|
9
|
-
range,
|
|
10
|
-
modify: ciphertext2.length
|
|
11
|
-
});
|
|
12
|
-
return cache;
|
|
13
|
-
}, "");
|
|
14
|
-
if (point !== -1) {
|
|
15
|
-
ciphertext += plaintext.slice(point + 1);
|
|
16
|
-
}
|
|
17
|
-
return {
|
|
18
|
-
ciphertext,
|
|
19
|
-
rules
|
|
20
|
-
};
|
|
21
|
-
};
|
|
22
|
-
const desensDecrypt = (ciphertext, rules, decrypt) => {
|
|
23
|
-
Array.isArray(rules) || (rules = [rules]);
|
|
24
|
-
let offset = 0;
|
|
25
|
-
let from = 0;
|
|
26
|
-
return rules.reduce((cache, { range: [start, stop], modify }) => {
|
|
27
|
-
cache += ciphertext.slice(from, start + offset) + decrypt(ciphertext.slice(start + offset, start + offset + modify));
|
|
28
|
-
from = start + offset + modify;
|
|
29
|
-
offset += modify - (stop + 1 - start);
|
|
30
|
-
return cache;
|
|
31
|
-
}, "") + ciphertext.slice(from);
|
|
32
|
-
};
|
|
33
|
-
const desensReplace = (ciphertext, rules, replacer = "*") => {
|
|
34
|
-
Array.isArray(rules) || (rules = [rules]);
|
|
35
|
-
let offset = 0;
|
|
36
|
-
let from = 0;
|
|
37
|
-
return rules.reduce((cache, { range: [start, stop], modify }) => {
|
|
38
|
-
const part = ciphertext.slice(start + offset, start + offset + modify);
|
|
39
|
-
const size = stop + 1 - start;
|
|
40
|
-
const replaceValue = isString(replacer) ? replacer.repeat(size) : replacer[Symbol.replace](part, size);
|
|
41
|
-
cache += ciphertext.slice(from, start + offset) + replaceValue;
|
|
42
|
-
from = start + offset + modify;
|
|
43
|
-
offset += modify - size;
|
|
44
|
-
return cache;
|
|
45
|
-
}, "") + ciphertext.slice(from);
|
|
46
|
-
};
|
|
47
|
-
export {
|
|
48
|
-
desensDecrypt,
|
|
49
|
-
desensEncrypt,
|
|
50
|
-
desensReplace
|
|
51
|
-
};
|
package/lib/encoding.js
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
const utf8_first_prefix = /^1{2,}/g;
|
|
2
|
-
const utf8_other_prefix = /^10/;
|
|
3
|
-
const Encodes = {
|
|
4
|
-
UTF_8: "utf-8",
|
|
5
|
-
UTF_16LE: "utf-16le",
|
|
6
|
-
UTF_16BE: "utf-16be",
|
|
7
|
-
GBK: "gbk"
|
|
8
|
-
};
|
|
9
|
-
const BOM = {
|
|
10
|
-
UTF_8: [239, 187, 191],
|
|
11
|
-
UTF_16LE: [255, 254],
|
|
12
|
-
UTF_16BE: [254, 255]
|
|
13
|
-
};
|
|
14
|
-
const equal = (uint, list) => {
|
|
15
|
-
return uint.length === list.length ? !uint.some((value, index) => value !== list[index]) : false;
|
|
16
|
-
};
|
|
17
|
-
const getEncoding = (uint, limit = 1024) => {
|
|
18
|
-
let encoding;
|
|
19
|
-
let offset = 0;
|
|
20
|
-
for (const key in BOM) {
|
|
21
|
-
const head = BOM[key];
|
|
22
|
-
if (equal(uint.slice(0, head.length), head)) {
|
|
23
|
-
offset = head.length;
|
|
24
|
-
encoding = Encodes[key];
|
|
25
|
-
break;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
if (!encoding) {
|
|
29
|
-
let isBreak = false;
|
|
30
|
-
top:
|
|
31
|
-
for (let i = 0, max = Math.min(uint.length, limit); i < max; i++) {
|
|
32
|
-
const data = uint[i];
|
|
33
|
-
if (data < 128) continue;
|
|
34
|
-
const match = data.toString(2).match(utf8_first_prefix);
|
|
35
|
-
if (match) {
|
|
36
|
-
for (let m = 0; m < match[0].length - 1; m++) {
|
|
37
|
-
const target = uint[++i];
|
|
38
|
-
if (target == void 0 || !utf8_other_prefix.test(target.toString(2))) {
|
|
39
|
-
encoding = Encodes.GBK;
|
|
40
|
-
isBreak = true;
|
|
41
|
-
break top;
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
} else {
|
|
45
|
-
encoding = Encodes.GBK;
|
|
46
|
-
isBreak = true;
|
|
47
|
-
break;
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
isBreak || (encoding = Encodes.UTF_8);
|
|
51
|
-
}
|
|
52
|
-
return { encoding, offset };
|
|
53
|
-
};
|
|
54
|
-
export {
|
|
55
|
-
getEncoding
|
|
56
|
-
};
|
package/lib/index.js
DELETED
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
import { clamp } from "./clamp";
|
|
2
|
-
import { classnames } from "./classnames";
|
|
3
|
-
import { compareVersion } from "./compare/version";
|
|
4
|
-
import { deepWeakEqual } from "./compare/weak-equal";
|
|
5
|
-
import { hash8json } from "./convert/json";
|
|
6
|
-
import { hash8object } from "./convert/object";
|
|
7
|
-
import { hash8strings } from "./convert/strings";
|
|
8
|
-
import { desensEncrypt, desensDecrypt, desensReplace } from "./desens";
|
|
9
|
-
import { getEncoding } from "./encoding";
|
|
10
|
-
import { inputRegex } from "./input-regex";
|
|
11
|
-
import { isClass } from "./is/class";
|
|
12
|
-
import { isEmpty } from "./is/empty";
|
|
13
|
-
import { isKey } from "./is/key";
|
|
14
|
-
import { isNull } from "./is/null";
|
|
15
|
-
import { loadImage } from "./load/image";
|
|
16
|
-
import { MemoryBasic } from "./memory/basic";
|
|
17
|
-
import { MemoryList } from "./memory/list";
|
|
18
|
-
import { MemoryPower } from "./memory/power";
|
|
19
|
-
import { MemorySimple } from "./memory/simple";
|
|
20
|
-
import { default as default2 } from "./neo4j-anchors";
|
|
21
|
-
import { default as default3 } from "./neo4j";
|
|
22
|
-
import { once } from "./once";
|
|
23
|
-
import { parseNum } from "./parse/num";
|
|
24
|
-
import { deconPowersSum } from "./power/decon";
|
|
25
|
-
import { rotateAngle } from "./rotate/angle";
|
|
26
|
-
import { rotateRad } from "./rotate/rad";
|
|
27
|
-
import { cubeURLParams, flatURLParams } from "./serialize/url-params";
|
|
28
|
-
import { css } from "./style/css";
|
|
29
|
-
import { default as default4 } from "./subscriber";
|
|
30
|
-
import { FlexTable } from "./table/flex";
|
|
31
|
-
import { Union } from "./union";
|
|
32
|
-
import { joinPaths } from "./url/join";
|
|
33
|
-
import { connectURLParams } from "./url/params";
|
|
34
|
-
import { wait } from "./wait";
|
|
35
|
-
export {
|
|
36
|
-
FlexTable,
|
|
37
|
-
MemoryBasic,
|
|
38
|
-
MemoryList,
|
|
39
|
-
MemoryPower,
|
|
40
|
-
MemorySimple,
|
|
41
|
-
default3 as Neo4j,
|
|
42
|
-
default2 as Neo4jAhchors,
|
|
43
|
-
default4 as Subscriber,
|
|
44
|
-
Union,
|
|
45
|
-
clamp,
|
|
46
|
-
classnames,
|
|
47
|
-
compareVersion,
|
|
48
|
-
connectURLParams,
|
|
49
|
-
css,
|
|
50
|
-
cubeURLParams,
|
|
51
|
-
deconPowersSum,
|
|
52
|
-
deepWeakEqual,
|
|
53
|
-
desensDecrypt,
|
|
54
|
-
desensEncrypt,
|
|
55
|
-
desensReplace,
|
|
56
|
-
flatURLParams,
|
|
57
|
-
getEncoding,
|
|
58
|
-
hash8json,
|
|
59
|
-
hash8object,
|
|
60
|
-
hash8strings,
|
|
61
|
-
inputRegex,
|
|
62
|
-
isClass,
|
|
63
|
-
isEmpty,
|
|
64
|
-
isKey,
|
|
65
|
-
isNull,
|
|
66
|
-
joinPaths,
|
|
67
|
-
loadImage,
|
|
68
|
-
once,
|
|
69
|
-
parseNum,
|
|
70
|
-
rotateAngle,
|
|
71
|
-
rotateRad,
|
|
72
|
-
wait
|
|
73
|
-
};
|
package/lib/input-regex.js
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
const RE_REGEX = /[$()*+.[?\\^{|]/g;
|
|
2
|
-
const RE_STRING = /[$()*+.[?\\^{|-]/g;
|
|
3
|
-
function inputRegex(text, flags) {
|
|
4
|
-
return flags === false ? text.replace(RE_STRING, ($0) => "\\" + $0) : new RegExp(text.replace(RE_REGEX, ($0) => "\\" + $0), flags);
|
|
5
|
-
}
|
|
6
|
-
export {
|
|
7
|
-
inputRegex
|
|
8
|
-
};
|
package/lib/is/class.js
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
const re_anonymous = /^function\s+\(|^function\s+anonymous\(/;
|
|
2
|
-
const re_function = /^function\s+[A-Z]/;
|
|
3
|
-
const re_this = /\b\(this\b|\bthis[\.\[]\b/;
|
|
4
|
-
const re_check = /classCallCheck\(this/;
|
|
5
|
-
const re_default = /^function\sdefault_\d+\s*\(/;
|
|
6
|
-
const isClass = (value, strict = true) => {
|
|
7
|
-
if (typeof value !== "function") return false;
|
|
8
|
-
const proto = value.prototype;
|
|
9
|
-
if (!proto || proto.constructor !== value) return false;
|
|
10
|
-
const str = value.toString();
|
|
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;
|
|
14
|
-
if (re_this.test(str)) {
|
|
15
|
-
if (!strict || re_check.test(str)) return true;
|
|
16
|
-
return re_default.test(str);
|
|
17
|
-
}
|
|
18
|
-
return false;
|
|
19
|
-
};
|
|
20
|
-
export {
|
|
21
|
-
isClass
|
|
22
|
-
};
|
package/lib/is/empty.js
DELETED
package/lib/is/key.js
DELETED
package/lib/is/null.js
DELETED
package/lib/load/image.js
DELETED
package/lib/memory/basic.js
DELETED
|
@@ -1,167 +0,0 @@
|
|
|
1
|
-
import { hash8strings } from "../convert/strings";
|
|
2
|
-
class MemoryBasic {
|
|
3
|
-
/**
|
|
4
|
-
* @param key 用于对数据进行分类的key
|
|
5
|
-
* @param config
|
|
6
|
-
*/
|
|
7
|
-
constructor(key, config) {
|
|
8
|
-
this.key = key;
|
|
9
|
-
this.#mount = config.mount;
|
|
10
|
-
this.#reflex = config.reflex;
|
|
11
|
-
}
|
|
12
|
-
#mount;
|
|
13
|
-
#reflex;
|
|
14
|
-
list = [];
|
|
15
|
-
memorys = /* @__PURE__ */ new Map();
|
|
16
|
-
/**
|
|
17
|
-
* 返回存储长度
|
|
18
|
-
*/
|
|
19
|
-
get size() {
|
|
20
|
-
return this.list.length;
|
|
21
|
-
}
|
|
22
|
-
getType(data) {
|
|
23
|
-
const { key } = this;
|
|
24
|
-
return typeof key === "function" ? key(data) : data[key];
|
|
25
|
-
}
|
|
26
|
-
push(...list) {
|
|
27
|
-
const { memorys } = this;
|
|
28
|
-
list.forEach((data) => {
|
|
29
|
-
const type = this.getType(data);
|
|
30
|
-
const memory = memorys.get(type);
|
|
31
|
-
const index = this.list.push(data) - 1;
|
|
32
|
-
const result = this.#mount(index, memory);
|
|
33
|
-
memory === result || memorys.set(type, result);
|
|
34
|
-
});
|
|
35
|
-
return this;
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* 返回位于指定索引处的项
|
|
39
|
-
*/
|
|
40
|
-
at(index) {
|
|
41
|
-
const { list } = this;
|
|
42
|
-
if (index < 0) {
|
|
43
|
-
index += list.length;
|
|
44
|
-
}
|
|
45
|
-
return this.list.at(index);
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* 遍历所有存储数据(按入栈顺序)
|
|
49
|
-
*/
|
|
50
|
-
forEach(callback) {
|
|
51
|
-
this.list.forEach(callback);
|
|
52
|
-
return this;
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* 遍历所有存储类型
|
|
56
|
-
*/
|
|
57
|
-
forType(callback) {
|
|
58
|
-
const { memorys, list } = this;
|
|
59
|
-
for (const [type, memory] of memorys) {
|
|
60
|
-
const caches = this.#reflex(memory).map((index) => list[index]);
|
|
61
|
-
callback(caches, type);
|
|
62
|
-
}
|
|
63
|
-
return this;
|
|
64
|
-
}
|
|
65
|
-
/**
|
|
66
|
-
* some(按入栈顺序)
|
|
67
|
-
*/
|
|
68
|
-
some(callback) {
|
|
69
|
-
return this.list.some(callback);
|
|
70
|
-
}
|
|
71
|
-
/**
|
|
72
|
-
* map(按入栈顺序)
|
|
73
|
-
*/
|
|
74
|
-
map(callback) {
|
|
75
|
-
return this.list.map(callback);
|
|
76
|
-
}
|
|
77
|
-
/**
|
|
78
|
-
* reduce(按入栈顺序)
|
|
79
|
-
*/
|
|
80
|
-
reduce(callback, initialValue) {
|
|
81
|
-
return this.list.reduce(callback, initialValue);
|
|
82
|
-
}
|
|
83
|
-
/**
|
|
84
|
-
* 判断存储是否包含指定类型
|
|
85
|
-
*/
|
|
86
|
-
includes(type) {
|
|
87
|
-
return this.memorys.has(type);
|
|
88
|
-
}
|
|
89
|
-
/**
|
|
90
|
-
* 获取指定类型存储数据
|
|
91
|
-
*/
|
|
92
|
-
get(type) {
|
|
93
|
-
const memory = this.memorys.get(type);
|
|
94
|
-
return memory === void 0 ? null : this.#reflex(memory).map((count) => this.list[count]);
|
|
95
|
-
}
|
|
96
|
-
/**
|
|
97
|
-
* 删除指定存储数据
|
|
98
|
-
*/
|
|
99
|
-
delete(data) {
|
|
100
|
-
const { memorys, list } = this;
|
|
101
|
-
let index = -1;
|
|
102
|
-
if (!list.some((value, i) => {
|
|
103
|
-
if (data === value) {
|
|
104
|
-
index = i;
|
|
105
|
-
list.splice(index, 1);
|
|
106
|
-
const type = this.getType(value);
|
|
107
|
-
const memory = this.#reflex(memorys.get(type));
|
|
108
|
-
if (memory.length === 1) {
|
|
109
|
-
memorys.delete(type);
|
|
110
|
-
} else {
|
|
111
|
-
memory.some((count, j) => {
|
|
112
|
-
if (count === i) {
|
|
113
|
-
memory.splice(j, 1);
|
|
114
|
-
return true;
|
|
115
|
-
}
|
|
116
|
-
});
|
|
117
|
-
}
|
|
118
|
-
return true;
|
|
119
|
-
}
|
|
120
|
-
})) return this;
|
|
121
|
-
for (const [type, target] of memorys) {
|
|
122
|
-
const memory = this.#reflex(target);
|
|
123
|
-
memory.forEach((value, i) => {
|
|
124
|
-
if (value >= index) {
|
|
125
|
-
memory[i] = value - 1;
|
|
126
|
-
}
|
|
127
|
-
});
|
|
128
|
-
if (memory !== target) {
|
|
129
|
-
let reactor;
|
|
130
|
-
memory.forEach((count) => {
|
|
131
|
-
reactor = this.#mount(count, reactor);
|
|
132
|
-
});
|
|
133
|
-
memorys.set(type, reactor);
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
return this;
|
|
137
|
-
}
|
|
138
|
-
/**
|
|
139
|
-
* 删除指定类型存储数据
|
|
140
|
-
*/
|
|
141
|
-
deleteType(type) {
|
|
142
|
-
const { memorys, list } = this;
|
|
143
|
-
if (!memorys.has(type)) return this;
|
|
144
|
-
const local = hash8strings(this.#reflex(memorys.get(type)));
|
|
145
|
-
const Memory = this.constructor;
|
|
146
|
-
const imitator = new Memory(this.key, {
|
|
147
|
-
mount: this.#mount,
|
|
148
|
-
reflex: this.#reflex
|
|
149
|
-
});
|
|
150
|
-
list.forEach((data, index) => {
|
|
151
|
-
index in local || imitator.push(data);
|
|
152
|
-
});
|
|
153
|
-
this.list = imitator.list;
|
|
154
|
-
this.memorys = imitator.memorys;
|
|
155
|
-
return this;
|
|
156
|
-
}
|
|
157
|
-
/**
|
|
158
|
-
* 清理存储
|
|
159
|
-
*/
|
|
160
|
-
clear() {
|
|
161
|
-
this.list = [];
|
|
162
|
-
this.memorys.clear();
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
export {
|
|
166
|
-
MemoryBasic
|
|
167
|
-
};
|
package/lib/memory/list.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { MemoryBasic } from "./basic";
|
|
2
|
-
class MemoryList extends MemoryBasic {
|
|
3
|
-
constructor(key) {
|
|
4
|
-
super(key, {
|
|
5
|
-
mount: (index, reactor) => reactor ? (reactor.push(index), reactor) : [index],
|
|
6
|
-
reflex: (reactor) => reactor
|
|
7
|
-
});
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
export {
|
|
11
|
-
MemoryList
|
|
12
|
-
};
|
package/lib/memory/power.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { deconPowersSum } from "../power/decon";
|
|
2
|
-
import { MemoryBasic } from "./basic";
|
|
3
|
-
class MemoryPower extends MemoryBasic {
|
|
4
|
-
constructor(key) {
|
|
5
|
-
super(key, {
|
|
6
|
-
mount: (index, reactor) => (reactor || 0) + 2 ** index,
|
|
7
|
-
reflex: (reactor) => deconPowersSum(reactor, "asc")
|
|
8
|
-
});
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
export {
|
|
12
|
-
MemoryPower
|
|
13
|
-
};
|
package/lib/memory/simple.js
DELETED
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
import { MemoryBasic } from "./basic";
|
|
2
|
-
class MemorySimple {
|
|
3
|
-
#memory;
|
|
4
|
-
#key;
|
|
5
|
-
get size() {
|
|
6
|
-
return this.#memory.size;
|
|
7
|
-
}
|
|
8
|
-
constructor(key) {
|
|
9
|
-
this.#key = key;
|
|
10
|
-
this.#memory = new MemoryBasic(key, {
|
|
11
|
-
mount: (index) => index,
|
|
12
|
-
reflex: (reactor) => [reactor]
|
|
13
|
-
});
|
|
14
|
-
}
|
|
15
|
-
#getType(data) {
|
|
16
|
-
const key = this.#key;
|
|
17
|
-
return typeof key === "function" ? key(data) : data[key];
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* 返回位于指定索引处的项
|
|
21
|
-
*/
|
|
22
|
-
at(index) {
|
|
23
|
-
return this.#memory.at(index);
|
|
24
|
-
}
|
|
25
|
-
push(...list) {
|
|
26
|
-
const memory = this.#memory;
|
|
27
|
-
list.forEach((data) => {
|
|
28
|
-
memory.includes(this.#getType(data)) || memory.push(data);
|
|
29
|
-
});
|
|
30
|
-
return this;
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* 获取指定类型存储数据
|
|
34
|
-
*/
|
|
35
|
-
get(type) {
|
|
36
|
-
const value = this.#memory.get(type);
|
|
37
|
-
if (value === null) return value;
|
|
38
|
-
return value.length ? value[0] : null;
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* 遍历所有存储数据(按入栈顺序)
|
|
42
|
-
*/
|
|
43
|
-
forEach(callback) {
|
|
44
|
-
this.#memory.forEach(callback);
|
|
45
|
-
return this;
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* some(按入栈顺序)
|
|
49
|
-
*/
|
|
50
|
-
some(callback) {
|
|
51
|
-
return this.#memory.some(callback);
|
|
52
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
* map(按入栈顺序)
|
|
55
|
-
*/
|
|
56
|
-
map(callback) {
|
|
57
|
-
return this.#memory.map(callback);
|
|
58
|
-
}
|
|
59
|
-
/**
|
|
60
|
-
* reduce(按入栈顺序)
|
|
61
|
-
*/
|
|
62
|
-
reduce(callback, initialValue) {
|
|
63
|
-
return this.#memory.reduce(callback, initialValue);
|
|
64
|
-
}
|
|
65
|
-
/**
|
|
66
|
-
* 判断是否包含指定类型
|
|
67
|
-
*/
|
|
68
|
-
includes(type) {
|
|
69
|
-
return this.#memory.includes(type);
|
|
70
|
-
}
|
|
71
|
-
/**
|
|
72
|
-
* 删除指定存储数据
|
|
73
|
-
*/
|
|
74
|
-
delete(data) {
|
|
75
|
-
this.#memory.delete(data);
|
|
76
|
-
return this;
|
|
77
|
-
}
|
|
78
|
-
/**
|
|
79
|
-
* 删除指定类型存储数据
|
|
80
|
-
*/
|
|
81
|
-
deleteType(type) {
|
|
82
|
-
this.#memory.deleteType(type);
|
|
83
|
-
return this;
|
|
84
|
-
}
|
|
85
|
-
/**
|
|
86
|
-
* 清理存储
|
|
87
|
-
*/
|
|
88
|
-
clear() {
|
|
89
|
-
this.#memory.clear();
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
export {
|
|
93
|
-
MemorySimple
|
|
94
|
-
};
|
package/lib/memory/type.d.js
DELETED
|
File without changes
|