@vope/utils 1.3.1 → 1.4.1
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/cjs/clamp.js +29 -12
- package/cjs/classnames.js +34 -20
- package/cjs/compare/version.js +35 -18
- package/cjs/compare/weak-equal.js +49 -36
- package/cjs/convert/json.js +25 -15
- package/cjs/convert/object.js +26 -16
- package/cjs/convert/strings.js +25 -9
- package/cjs/encoding.js +64 -51
- package/cjs/index.js +76 -53
- package/cjs/input-regex.js +24 -5
- package/cjs/is/class.js +40 -23
- package/cjs/is/empty.js +34 -10
- package/cjs/is/null.js +24 -7
- package/cjs/memory/basic.js +159 -139
- package/cjs/memory/list.js +39 -17
- package/cjs/memory/power.js +40 -16
- package/cjs/memory/type.d.js +16 -0
- package/cjs/once.js +26 -13
- package/cjs/power/decon.js +38 -26
- package/cjs/rotate/angle.js +34 -12
- package/cjs/rotate/rad.js +29 -14
- package/cjs/union.js +41 -26
- package/cjs/url/join.js +27 -11
- package/cjs/url/params.js +41 -33
- package/cjs/wait.js +23 -5
- package/lib/clamp.js +7 -10
- package/lib/classnames.js +12 -18
- package/lib/compare/version.js +13 -16
- package/lib/compare/weak-equal.js +27 -34
- package/lib/convert/json.js +3 -13
- package/lib/convert/object.js +4 -14
- package/lib/convert/strings.js +3 -7
- package/lib/encoding.js +42 -49
- package/lib/index.js +24 -24
- package/lib/input-regex.js +2 -3
- package/lib/is/class.js +18 -21
- package/lib/is/empty.js +3 -6
- package/lib/is/null.js +2 -5
- package/lib/memory/basic.js +129 -135
- package/lib/memory/list.js +8 -12
- package/lib/memory/power.js +9 -11
- package/lib/memory/type.d.js +1 -0
- package/lib/once.js +4 -11
- package/lib/power/decon.js +16 -24
- package/lib/rotate/angle.js +2 -7
- package/lib/rotate/rad.js +7 -12
- package/lib/union.js +20 -24
- package/lib/url/join.js +5 -9
- package/lib/url/params.js +19 -31
- package/lib/wait.js +1 -3
- package/package.json +6 -8
- package/types/index.d.ts +0 -1
- package/cjs/api.js +0 -56
- package/lib/api.js +0 -48
- package/types/api.d.ts +0 -19
package/cjs/index.js
CHANGED
|
@@ -1,55 +1,78 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
4
11
|
};
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
var
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
var
|
|
51
|
-
|
|
52
|
-
var
|
|
53
|
-
|
|
54
|
-
var
|
|
55
|
-
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var src_exports = {};
|
|
30
|
+
__export(src_exports, {
|
|
31
|
+
MemoryBasic: () => import_basic.default,
|
|
32
|
+
MemoryList: () => import_list.default,
|
|
33
|
+
MemoryPower: () => import_power.default,
|
|
34
|
+
Union: () => import_union.default,
|
|
35
|
+
clamp: () => import_clamp.default,
|
|
36
|
+
classnames: () => import_classnames.default,
|
|
37
|
+
compareVersion: () => import_version.default,
|
|
38
|
+
connectURLParams: () => import_params.default,
|
|
39
|
+
deconPowersSum: () => import_decon.default,
|
|
40
|
+
deepWeakEqual: () => import_weak_equal.default,
|
|
41
|
+
getEncoding: () => import_encoding.default,
|
|
42
|
+
hash8json: () => import_json.default,
|
|
43
|
+
hash8object: () => import_object.default,
|
|
44
|
+
hash8strings: () => import_strings.default,
|
|
45
|
+
inputRegex: () => import_input_regex.default,
|
|
46
|
+
isClass: () => import_class.default,
|
|
47
|
+
isEmpty: () => import_empty.default,
|
|
48
|
+
isNull: () => import_null.default,
|
|
49
|
+
joinPaths: () => import_join.default,
|
|
50
|
+
once: () => import_once.default,
|
|
51
|
+
rotateAngle: () => import_angle.default,
|
|
52
|
+
rotateRad: () => import_rad.default,
|
|
53
|
+
wait: () => import_wait.default
|
|
54
|
+
});
|
|
55
|
+
module.exports = __toCommonJS(src_exports);
|
|
56
|
+
var import_clamp = __toESM(require("./clamp"), 1);
|
|
57
|
+
var import_classnames = __toESM(require("./classnames"), 1);
|
|
58
|
+
var import_version = __toESM(require("./compare/version"), 1);
|
|
59
|
+
var import_weak_equal = __toESM(require("./compare/weak-equal"), 1);
|
|
60
|
+
var import_json = __toESM(require("./convert/json"), 1);
|
|
61
|
+
var import_object = __toESM(require("./convert/object"), 1);
|
|
62
|
+
var import_strings = __toESM(require("./convert/strings"), 1);
|
|
63
|
+
var import_encoding = __toESM(require("./encoding"), 1);
|
|
64
|
+
var import_input_regex = __toESM(require("./input-regex"), 1);
|
|
65
|
+
var import_class = __toESM(require("./is/class"), 1);
|
|
66
|
+
var import_empty = __toESM(require("./is/empty"), 1);
|
|
67
|
+
var import_null = __toESM(require("./is/null"), 1);
|
|
68
|
+
var import_basic = __toESM(require("./memory/basic"), 1);
|
|
69
|
+
var import_list = __toESM(require("./memory/list"), 1);
|
|
70
|
+
var import_power = __toESM(require("./memory/power"), 1);
|
|
71
|
+
var import_once = __toESM(require("./once"), 1);
|
|
72
|
+
var import_decon = __toESM(require("./power/decon"), 1);
|
|
73
|
+
var import_angle = __toESM(require("./rotate/angle"), 1);
|
|
74
|
+
var import_rad = __toESM(require("./rotate/rad"), 1);
|
|
75
|
+
var import_union = __toESM(require("./union"), 1);
|
|
76
|
+
var import_join = __toESM(require("./url/join"), 1);
|
|
77
|
+
var import_params = __toESM(require("./url/params"), 1);
|
|
78
|
+
var import_wait = __toESM(require("./wait"), 1);
|
package/cjs/input-regex.js
CHANGED
|
@@ -1,10 +1,29 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.defineProperty
|
|
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 input_regex_exports = {};
|
|
20
|
+
__export(input_regex_exports, {
|
|
21
|
+
default: () => input_regex_default
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(input_regex_exports);
|
|
3
24
|
const RE_REGEX = /[$()*+.[?\\^{|]/g;
|
|
4
25
|
const RE_STRING = /[$()*+.[?\\^{|-]/g;
|
|
5
26
|
function inputRegex(text, flags) {
|
|
6
|
-
|
|
7
|
-
? text.replace(RE_STRING, ($0) => '\\' + $0)
|
|
8
|
-
: new RegExp(text.replace(RE_REGEX, ($0) => '\\' + $0), flags);
|
|
27
|
+
return flags === false ? text.replace(RE_STRING, ($0) => "\\" + $0) : new RegExp(text.replace(RE_REGEX, ($0) => "\\" + $0), flags);
|
|
9
28
|
}
|
|
10
|
-
|
|
29
|
+
var input_regex_default = inputRegex;
|
package/cjs/is/class.js
CHANGED
|
@@ -1,32 +1,49 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.defineProperty
|
|
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 class_exports = {};
|
|
20
|
+
__export(class_exports, {
|
|
21
|
+
default: () => class_default
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(class_exports);
|
|
3
24
|
const re_anonymous = /^function\s+\(|^function\s+anonymous\(/;
|
|
4
25
|
const re_function = /^function\s+[A-Z]/;
|
|
5
26
|
const re_this = /\b\(this\b|\bthis[\.\[]\b/;
|
|
6
27
|
const re_check = /classCallCheck\(this/;
|
|
7
28
|
const re_default = /^function\sdefault_\d+\s*\(/;
|
|
8
|
-
/**
|
|
9
|
-
* 检测是否为class
|
|
10
|
-
*/
|
|
11
29
|
const isClass = (value, strict = true) => {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
if (re_anonymous.test(str))
|
|
22
|
-
return false;
|
|
23
|
-
if (strict && re_function.test(str))
|
|
24
|
-
return true;
|
|
25
|
-
if (re_this.test(str)) {
|
|
26
|
-
if (!strict || re_check.test(str))
|
|
27
|
-
return true;
|
|
28
|
-
return re_default.test(str);
|
|
29
|
-
}
|
|
30
|
+
if (typeof value !== "function")
|
|
31
|
+
return false;
|
|
32
|
+
const proto = value.prototype;
|
|
33
|
+
if (!proto || proto.constructor !== value)
|
|
34
|
+
return false;
|
|
35
|
+
const str = value.toString();
|
|
36
|
+
if (str.slice(0, 5) === "class" || Object.getOwnPropertyNames(proto).length >= 2)
|
|
37
|
+
return true;
|
|
38
|
+
if (re_anonymous.test(str))
|
|
30
39
|
return false;
|
|
40
|
+
if (strict && re_function.test(str))
|
|
41
|
+
return true;
|
|
42
|
+
if (re_this.test(str)) {
|
|
43
|
+
if (!strict || re_check.test(str))
|
|
44
|
+
return true;
|
|
45
|
+
return re_default.test(str);
|
|
46
|
+
}
|
|
47
|
+
return false;
|
|
31
48
|
};
|
|
32
|
-
|
|
49
|
+
var class_default = isClass;
|
package/cjs/is/empty.js
CHANGED
|
@@ -1,12 +1,36 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
4
11
|
};
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var empty_exports = {};
|
|
30
|
+
__export(empty_exports, {
|
|
31
|
+
default: () => empty_default
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(empty_exports);
|
|
34
|
+
var import_null = __toESM(require("./null"), 1);
|
|
35
|
+
const isEmpty = (value) => (0, import_null.default)(value) || value === "";
|
|
36
|
+
var empty_default = isEmpty;
|
package/cjs/is/null.js
CHANGED
|
@@ -1,8 +1,25 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.defineProperty
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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 null_exports = {};
|
|
20
|
+
__export(null_exports, {
|
|
21
|
+
default: () => null_default
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(null_exports);
|
|
24
|
+
const isNull = (value) => value === void 0 || value === null;
|
|
25
|
+
var null_default = isNull;
|
package/cjs/memory/basic.js
CHANGED
|
@@ -1,148 +1,168 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
4
11
|
};
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var basic_exports = {};
|
|
30
|
+
__export(basic_exports, {
|
|
31
|
+
default: () => MemoryBasic
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(basic_exports);
|
|
34
|
+
var import_strings = __toESM(require("../convert/strings"), 1);
|
|
10
35
|
class MemoryBasic {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
forEach(callback)
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
callback(caches, type);
|
|
61
|
-
}
|
|
62
|
-
return this;
|
|
63
|
-
}
|
|
64
|
-
/**
|
|
65
|
-
* 检测存储是否包含某种类型
|
|
66
|
-
*/
|
|
67
|
-
includes(type) {
|
|
68
|
-
return this.memorys.has(type);
|
|
36
|
+
/**
|
|
37
|
+
* @param key 用于对数据进行分类的key
|
|
38
|
+
* @param config
|
|
39
|
+
*/
|
|
40
|
+
constructor(key, config) {
|
|
41
|
+
this.key = key;
|
|
42
|
+
this.#mount = config.mount;
|
|
43
|
+
this.#reflex = config.reflex;
|
|
44
|
+
}
|
|
45
|
+
#mount;
|
|
46
|
+
#reflex;
|
|
47
|
+
list = [];
|
|
48
|
+
memorys = /* @__PURE__ */ new Map();
|
|
49
|
+
/**
|
|
50
|
+
* 返回存储长度
|
|
51
|
+
*/
|
|
52
|
+
get size() {
|
|
53
|
+
return this.list.length;
|
|
54
|
+
}
|
|
55
|
+
getType(data) {
|
|
56
|
+
const { key } = this;
|
|
57
|
+
return typeof key === "function" ? key(data) : data[key];
|
|
58
|
+
}
|
|
59
|
+
push(...list) {
|
|
60
|
+
const { memorys } = this;
|
|
61
|
+
list.forEach((data) => {
|
|
62
|
+
const type = this.getType(data);
|
|
63
|
+
const memory = memorys.get(type);
|
|
64
|
+
const index = this.list.push(data) - 1;
|
|
65
|
+
const result = this.#mount(index, memory);
|
|
66
|
+
memory === result || memorys.set(type, result);
|
|
67
|
+
});
|
|
68
|
+
return this;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* 遍历所有存储数据(按入栈顺序)
|
|
72
|
+
*/
|
|
73
|
+
forEach(callback) {
|
|
74
|
+
this.list.forEach(callback);
|
|
75
|
+
return this;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* 遍历所有存储类型
|
|
79
|
+
*/
|
|
80
|
+
forType(callback) {
|
|
81
|
+
const { memorys, list } = this;
|
|
82
|
+
for (const [type, memory] of memorys) {
|
|
83
|
+
const caches = this.#reflex(memory).map((index) => list[index]);
|
|
84
|
+
callback(caches, type);
|
|
69
85
|
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
}))
|
|
105
|
-
return this;
|
|
106
|
-
for (const [type, target] of memorys) {
|
|
107
|
-
const memory = this.#reflex(target);
|
|
108
|
-
memory.forEach((value, index) => {
|
|
109
|
-
if (value >= index) {
|
|
110
|
-
memory[index] = value - 1;
|
|
111
|
-
}
|
|
112
|
-
});
|
|
113
|
-
if (memory !== target) {
|
|
114
|
-
let reactor;
|
|
115
|
-
memory.forEach((count) => {
|
|
116
|
-
reactor = this.#mount(count, reactor);
|
|
117
|
-
});
|
|
118
|
-
memorys.set(type, reactor);
|
|
86
|
+
return this;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* 检测存储是否包含某种类型
|
|
90
|
+
*/
|
|
91
|
+
includes(type) {
|
|
92
|
+
return this.memorys.has(type);
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* 获取指定类型存储数据
|
|
96
|
+
*/
|
|
97
|
+
get(type) {
|
|
98
|
+
const memory = this.memorys.get(type);
|
|
99
|
+
return memory === void 0 ? null : this.#reflex(memory).map((count) => this.list[count]);
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* 删除指定存储数据
|
|
103
|
+
*/
|
|
104
|
+
delete(data) {
|
|
105
|
+
const { memorys, list } = this;
|
|
106
|
+
let index = -1;
|
|
107
|
+
if (!list.some((value, i) => {
|
|
108
|
+
if (data === value) {
|
|
109
|
+
index = i;
|
|
110
|
+
list.splice(index, 1);
|
|
111
|
+
const type = this.getType(value);
|
|
112
|
+
const memory = this.#reflex(memorys.get(type));
|
|
113
|
+
if (memory.length === 1) {
|
|
114
|
+
memorys.delete(type);
|
|
115
|
+
} else {
|
|
116
|
+
memory.some((count, j) => {
|
|
117
|
+
if (count === i) {
|
|
118
|
+
memory.splice(j, 1);
|
|
119
|
+
return true;
|
|
119
120
|
}
|
|
121
|
+
});
|
|
120
122
|
}
|
|
121
|
-
return
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
if (
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
123
|
+
return true;
|
|
124
|
+
}
|
|
125
|
+
}))
|
|
126
|
+
return this;
|
|
127
|
+
for (const [type, target] of memorys) {
|
|
128
|
+
const memory = this.#reflex(target);
|
|
129
|
+
memory.forEach((value, index2) => {
|
|
130
|
+
if (value >= index2) {
|
|
131
|
+
memory[index2] = value - 1;
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
if (memory !== target) {
|
|
135
|
+
let reactor;
|
|
136
|
+
memory.forEach((count) => {
|
|
137
|
+
reactor = this.#mount(count, reactor);
|
|
135
138
|
});
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
return this;
|
|
139
|
-
}
|
|
140
|
-
/**
|
|
141
|
-
* 清理存储
|
|
142
|
-
*/
|
|
143
|
-
clear() {
|
|
144
|
-
this.list = [];
|
|
145
|
-
this.memorys.clear();
|
|
139
|
+
memorys.set(type, reactor);
|
|
140
|
+
}
|
|
146
141
|
}
|
|
142
|
+
return this;
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* 删除指定类型存储数据
|
|
146
|
+
*/
|
|
147
|
+
deleteType(type) {
|
|
148
|
+
const { memorys, list } = this;
|
|
149
|
+
if (!memorys.has(type))
|
|
150
|
+
return this;
|
|
151
|
+
const local = (0, import_strings.default)(this.#reflex(memorys.get(type)));
|
|
152
|
+
const Memory2 = this.constructor;
|
|
153
|
+
const imitator = new Memory2(this.key);
|
|
154
|
+
list.forEach((data, index) => {
|
|
155
|
+
index in local || imitator.push(data);
|
|
156
|
+
});
|
|
157
|
+
this.list = imitator.list;
|
|
158
|
+
this.memorys = imitator.memorys;
|
|
159
|
+
return this;
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* 清理存储
|
|
163
|
+
*/
|
|
164
|
+
clear() {
|
|
165
|
+
this.list = [];
|
|
166
|
+
this.memorys.clear();
|
|
167
|
+
}
|
|
147
168
|
}
|
|
148
|
-
exports.default = MemoryBasic;
|