@vope/utils 1.3.1 → 1.4.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.
- package/cjs/index.js +1 -4
- 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 +3 -5
- 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
|
@@ -3,10 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.wait = exports.connectURLParams = exports.joinPaths = exports.Union = exports.rotateRad = exports.rotateAngle = exports.deconPowersSum = exports.once = exports.MemoryPower = exports.MemoryList = exports.MemoryBasic = exports.isNull = exports.isEmpty = exports.isClass = exports.inputRegex = exports.getEncoding = exports.hash8strings = exports.hash8object = exports.hash8json = exports.deepWeakEqual = exports.compareVersion = exports.classnames = exports.clamp =
|
|
7
|
-
var api_1 = require("./api");
|
|
8
|
-
Object.defineProperty(exports, "apiPost", { enumerable: true, get: function () { return api_1.apiPost; } });
|
|
9
|
-
Object.defineProperty(exports, "apiGet", { enumerable: true, get: function () { return api_1.apiGet; } });
|
|
6
|
+
exports.wait = exports.connectURLParams = exports.joinPaths = exports.Union = exports.rotateRad = exports.rotateAngle = exports.deconPowersSum = exports.once = exports.MemoryPower = exports.MemoryList = exports.MemoryBasic = exports.isNull = exports.isEmpty = exports.isClass = exports.inputRegex = exports.getEncoding = exports.hash8strings = exports.hash8object = exports.hash8json = exports.deepWeakEqual = exports.compareVersion = exports.classnames = exports.clamp = void 0;
|
|
10
7
|
var clamp_1 = require("./clamp");
|
|
11
8
|
Object.defineProperty(exports, "clamp", { enumerable: true, get: function () { return __importDefault(clamp_1).default; } });
|
|
12
9
|
var classnames_1 = require("./classnames");
|
package/lib/clamp.js
CHANGED
|
@@ -1,12 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
* 获取中间数
|
|
3
|
-
*/
|
|
1
|
+
"use strict";
|
|
4
2
|
export default (value, min, max) => {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
return Math.min(max, Math.max(min, value));
|
|
3
|
+
if (min > max) {
|
|
4
|
+
const swap = max;
|
|
5
|
+
max = min;
|
|
6
|
+
min = swap;
|
|
7
|
+
}
|
|
8
|
+
return Math.min(max, Math.max(min, value));
|
|
12
9
|
};
|
package/lib/classnames.js
CHANGED
|
@@ -1,20 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
: b;
|
|
4
|
-
/**
|
|
5
|
-
* 拼接多个class
|
|
6
|
-
*/
|
|
1
|
+
"use strict";
|
|
2
|
+
const add = (a, b) => a ? a + " " + b : b;
|
|
7
3
|
export default (...list) => list.reduce((caches, data) => {
|
|
8
|
-
|
|
9
|
-
|
|
4
|
+
if (typeof data === "string") {
|
|
5
|
+
data && (caches = add(caches, data));
|
|
6
|
+
} else if (Array.isArray(data)) {
|
|
7
|
+
data.forEach((value) => value && (caches = add(caches, value)));
|
|
8
|
+
} else if (data) {
|
|
9
|
+
for (const key in data) {
|
|
10
|
+
key && data[key] && (caches = add(caches, key));
|
|
10
11
|
}
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
else if (data) {
|
|
15
|
-
for (const key in data) {
|
|
16
|
-
key && data[key] && (caches = add(caches, key));
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
return caches;
|
|
20
|
-
}, '');
|
|
12
|
+
}
|
|
13
|
+
return caches;
|
|
14
|
+
}, "");
|
package/lib/compare/version.js
CHANGED
|
@@ -1,19 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
* 版本号大小比较
|
|
4
|
-
* @description from < to = 1,from === to = 0,from > to = -1
|
|
5
|
-
*/
|
|
1
|
+
"use strict";
|
|
2
|
+
const CHAR = ".";
|
|
6
3
|
const compareVersion = (from, to) => {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
4
|
+
const froms = from.split(CHAR);
|
|
5
|
+
const tos = to.split(CHAR);
|
|
6
|
+
for (let i = 0, max = Math.max(froms.length, tos.length); i < max; i++) {
|
|
7
|
+
const fromV = +froms[i] || 0;
|
|
8
|
+
const toV = +tos[i] || 0;
|
|
9
|
+
if (fromV > toV)
|
|
10
|
+
return -1;
|
|
11
|
+
if (fromV < toV)
|
|
12
|
+
return 1;
|
|
13
|
+
}
|
|
14
|
+
return 0;
|
|
18
15
|
};
|
|
19
16
|
export default compareVersion;
|
|
@@ -1,39 +1,32 @@
|
|
|
1
|
-
|
|
2
|
-
* 深度相等性比较(弱比较)
|
|
3
|
-
*/
|
|
1
|
+
"use strict";
|
|
4
2
|
const deepWeakEqual = (from, to) => {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
3
|
+
if (typeof from !== "object" || from === null || typeof to !== "object" || to === null)
|
|
4
|
+
return from === to;
|
|
5
|
+
if (Array.isArray(from) && Array.isArray(to)) {
|
|
6
|
+
if (from.length !== to.length)
|
|
7
|
+
return false;
|
|
8
|
+
return !from.some((t1, index) => {
|
|
9
|
+
if (!deepWeakEqual(t1, to[index])) {
|
|
10
|
+
return true;
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
} else {
|
|
14
|
+
const caches = {};
|
|
15
|
+
for (const key in from) {
|
|
16
|
+
if (!deepWeakEqual(from[key], to[key])) {
|
|
17
|
+
return false;
|
|
18
|
+
} else {
|
|
19
|
+
caches[key] = key;
|
|
20
|
+
}
|
|
18
21
|
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
else {
|
|
26
|
-
caches[key] = key;
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
for (const key in to) {
|
|
30
|
-
if (key in caches)
|
|
31
|
-
continue;
|
|
32
|
-
if (!deepWeakEqual(from[key], to[key])) {
|
|
33
|
-
return false;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
22
|
+
for (const key in to) {
|
|
23
|
+
if (key in caches)
|
|
24
|
+
continue;
|
|
25
|
+
if (!deepWeakEqual(from[key], to[key])) {
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
36
28
|
}
|
|
37
|
-
|
|
29
|
+
}
|
|
30
|
+
return true;
|
|
38
31
|
};
|
|
39
32
|
export default deepWeakEqual;
|
package/lib/convert/json.js
CHANGED
|
@@ -1,16 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
* 对象数组转hash(要求主键值为string|number类型)
|
|
3
|
-
* @example
|
|
4
|
-
* hash8json(
|
|
5
|
-
* [
|
|
6
|
-
* { key: 'a', value: 1 },
|
|
7
|
-
* { key: 'b', value: 2 }
|
|
8
|
-
* ],
|
|
9
|
-
* 'key'
|
|
10
|
-
* ).a.value // 1
|
|
11
|
-
*/
|
|
1
|
+
"use strict";
|
|
12
2
|
const hash8json = (list, key) => list.reduce((caches, data) => {
|
|
13
|
-
|
|
14
|
-
|
|
3
|
+
caches[data[key]] = data;
|
|
4
|
+
return caches;
|
|
15
5
|
}, {});
|
|
16
6
|
export default hash8json;
|
package/lib/convert/object.js
CHANGED
|
@@ -1,16 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
* 对象数组转hash
|
|
3
|
-
* @example
|
|
4
|
-
* hash8object(
|
|
5
|
-
* [
|
|
6
|
-
* { key: String, value: 1 },
|
|
7
|
-
* { key: Object, value: 2 }
|
|
8
|
-
* ],
|
|
9
|
-
* 'key'
|
|
10
|
-
* ).get(Object).value // 2
|
|
11
|
-
*/
|
|
1
|
+
"use strict";
|
|
12
2
|
const hash8object = (list, key) => list.reduce((caches, data) => {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}, new Map());
|
|
3
|
+
caches.set(data[key], data);
|
|
4
|
+
return caches;
|
|
5
|
+
}, /* @__PURE__ */ new Map());
|
|
16
6
|
export default hash8object;
|
package/lib/convert/strings.js
CHANGED
|
@@ -1,10 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
* 字符数组转hash
|
|
3
|
-
* @example
|
|
4
|
-
* hash8strings(['a', 'b']).a // 0
|
|
5
|
-
*/
|
|
1
|
+
"use strict";
|
|
6
2
|
const hash8strings = (list) => list.reduce((caches, data, index) => {
|
|
7
|
-
|
|
8
|
-
|
|
3
|
+
caches[data] = index;
|
|
4
|
+
return caches;
|
|
9
5
|
}, {});
|
|
10
6
|
export default hash8strings;
|
package/lib/encoding.js
CHANGED
|
@@ -1,62 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
const utf8_first_prefix = /^1{2,}/g;
|
|
2
3
|
const utf8_other_prefix = /^10/;
|
|
3
4
|
const Encodes = {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
UTF_8: "utf-8",
|
|
6
|
+
UTF_16LE: "utf-16le",
|
|
7
|
+
UTF_16BE: "utf-16be",
|
|
8
|
+
GBK: "gbk"
|
|
8
9
|
};
|
|
9
10
|
const defaults = {
|
|
10
|
-
|
|
11
|
+
utf8: [239, 187, 191]
|
|
11
12
|
};
|
|
12
13
|
const equal = (uint, list) => {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
if (uint.length !== list.length)
|
|
15
|
+
return false;
|
|
16
|
+
return !uint.some((value, index) => value !== list[index]);
|
|
16
17
|
};
|
|
17
|
-
/**
|
|
18
|
-
* 根据文件内容判断文件的编码
|
|
19
|
-
* @param uint 文件内容Uint8Array格式
|
|
20
|
-
* @param limit 用于约束GBK和utf_8的判定上限
|
|
21
|
-
*/
|
|
22
18
|
const getEncoding = (uint, limit = 1024) => {
|
|
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
|
-
isBreak = true;
|
|
48
|
-
break top;
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
else {
|
|
53
|
-
encoding = Encodes.GBK;
|
|
54
|
-
isBreak = true;
|
|
55
|
-
break;
|
|
19
|
+
let encoding;
|
|
20
|
+
let offset = 0;
|
|
21
|
+
if (equal(uint.slice(0, 3), defaults.utf8)) {
|
|
22
|
+
offset = defaults.utf8.length;
|
|
23
|
+
encoding = Encodes.UTF_8;
|
|
24
|
+
} else if (equal(uint.slice(0, 2), [255, 254])) {
|
|
25
|
+
encoding = Encodes.UTF_16LE;
|
|
26
|
+
} else if (equal(uint.slice(0, 2), [254, 255])) {
|
|
27
|
+
encoding = Encodes.UTF_16BE;
|
|
28
|
+
} else {
|
|
29
|
+
let isBreak = false;
|
|
30
|
+
top:
|
|
31
|
+
for (let i = 0; i < Math.min(uint.length, limit); i++) {
|
|
32
|
+
const data = uint[i];
|
|
33
|
+
if (data < 128)
|
|
34
|
+
continue;
|
|
35
|
+
const match = data.toString(2).match(utf8_first_prefix);
|
|
36
|
+
if (match) {
|
|
37
|
+
for (let m = 0; m < match[0].length - 1; m++) {
|
|
38
|
+
const target = uint[++i];
|
|
39
|
+
if (target == void 0 || !utf8_other_prefix.test(target.toString(2))) {
|
|
40
|
+
encoding = Encodes.GBK;
|
|
41
|
+
isBreak = true;
|
|
42
|
+
break top;
|
|
56
43
|
}
|
|
44
|
+
}
|
|
45
|
+
} else {
|
|
46
|
+
encoding = Encodes.GBK;
|
|
47
|
+
isBreak = true;
|
|
48
|
+
break;
|
|
57
49
|
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
50
|
+
}
|
|
51
|
+
isBreak || (encoding = Encodes.UTF_8);
|
|
52
|
+
}
|
|
53
|
+
return { encoding, offset };
|
|
61
54
|
};
|
|
62
55
|
export default getEncoding;
|
package/lib/index.js
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
|
|
2
|
-
export { default as clamp } from
|
|
3
|
-
export { default as classnames } from
|
|
4
|
-
export { default as compareVersion } from
|
|
5
|
-
export { default as deepWeakEqual } from
|
|
6
|
-
export { default as hash8json } from
|
|
7
|
-
export { default as hash8object } from
|
|
8
|
-
export { default as hash8strings } from
|
|
9
|
-
export { default as getEncoding } from
|
|
10
|
-
export { default as inputRegex } from
|
|
11
|
-
export { default as isClass } from
|
|
12
|
-
export { default as isEmpty } from
|
|
13
|
-
export { default as isNull } from
|
|
14
|
-
export { default as MemoryBasic } from
|
|
15
|
-
export { default as MemoryList } from
|
|
16
|
-
export { default as MemoryPower } from
|
|
17
|
-
export { default as once } from
|
|
18
|
-
export { default as deconPowersSum } from
|
|
19
|
-
export { default as rotateAngle } from
|
|
20
|
-
export { default as rotateRad } from
|
|
21
|
-
export { default as Union } from
|
|
22
|
-
export { default as joinPaths } from
|
|
23
|
-
export { default as connectURLParams } from
|
|
24
|
-
export { default as wait } from
|
|
1
|
+
"use strict";
|
|
2
|
+
export { default as clamp } from "./clamp";
|
|
3
|
+
export { default as classnames } from "./classnames";
|
|
4
|
+
export { default as compareVersion } from "./compare/version";
|
|
5
|
+
export { default as deepWeakEqual } from "./compare/weak-equal";
|
|
6
|
+
export { default as hash8json } from "./convert/json";
|
|
7
|
+
export { default as hash8object } from "./convert/object";
|
|
8
|
+
export { default as hash8strings } from "./convert/strings";
|
|
9
|
+
export { default as getEncoding } from "./encoding";
|
|
10
|
+
export { default as inputRegex } from "./input-regex";
|
|
11
|
+
export { default as isClass } from "./is/class";
|
|
12
|
+
export { default as isEmpty } from "./is/empty";
|
|
13
|
+
export { default as isNull } from "./is/null";
|
|
14
|
+
export { default as MemoryBasic } from "./memory/basic";
|
|
15
|
+
export { default as MemoryList } from "./memory/list";
|
|
16
|
+
export { default as MemoryPower } from "./memory/power";
|
|
17
|
+
export { default as once } from "./once";
|
|
18
|
+
export { default as deconPowersSum } from "./power/decon";
|
|
19
|
+
export { default as rotateAngle } from "./rotate/angle";
|
|
20
|
+
export { default as rotateRad } from "./rotate/rad";
|
|
21
|
+
export { default as Union } from "./union";
|
|
22
|
+
export { default as joinPaths } from "./url/join";
|
|
23
|
+
export { default as connectURLParams } from "./url/params";
|
|
24
|
+
export { default as wait } from "./wait";
|
package/lib/input-regex.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
const RE_REGEX = /[$()*+.[?\\^{|]/g;
|
|
2
3
|
const RE_STRING = /[$()*+.[?\\^{|-]/g;
|
|
3
4
|
function inputRegex(text, flags) {
|
|
4
|
-
|
|
5
|
-
? text.replace(RE_STRING, ($0) => '\\' + $0)
|
|
6
|
-
: new RegExp(text.replace(RE_REGEX, ($0) => '\\' + $0), flags);
|
|
5
|
+
return flags === false ? text.replace(RE_STRING, ($0) => "\\" + $0) : new RegExp(text.replace(RE_REGEX, ($0) => "\\" + $0), flags);
|
|
7
6
|
}
|
|
8
7
|
export default inputRegex;
|
package/lib/is/class.js
CHANGED
|
@@ -1,30 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
const re_anonymous = /^function\s+\(|^function\s+anonymous\(/;
|
|
2
3
|
const re_function = /^function\s+[A-Z]/;
|
|
3
4
|
const re_this = /\b\(this\b|\bthis[\.\[]\b/;
|
|
4
5
|
const re_check = /classCallCheck\(this/;
|
|
5
6
|
const re_default = /^function\sdefault_\d+\s*\(/;
|
|
6
|
-
/**
|
|
7
|
-
* 检测是否为class
|
|
8
|
-
*/
|
|
9
7
|
const isClass = (value, strict = true) => {
|
|
10
|
-
|
|
11
|
-
return false;
|
|
12
|
-
const proto = value.prototype;
|
|
13
|
-
if (!proto || proto.constructor !== value)
|
|
14
|
-
return false;
|
|
15
|
-
const str = value.toString();
|
|
16
|
-
if (str.slice(0, 5) === 'class'
|
|
17
|
-
|| Object.getOwnPropertyNames(proto).length >= 2)
|
|
18
|
-
return true;
|
|
19
|
-
if (re_anonymous.test(str))
|
|
20
|
-
return false;
|
|
21
|
-
if (strict && re_function.test(str))
|
|
22
|
-
return true;
|
|
23
|
-
if (re_this.test(str)) {
|
|
24
|
-
if (!strict || re_check.test(str))
|
|
25
|
-
return true;
|
|
26
|
-
return re_default.test(str);
|
|
27
|
-
}
|
|
8
|
+
if (typeof value !== "function")
|
|
28
9
|
return false;
|
|
10
|
+
const proto = value.prototype;
|
|
11
|
+
if (!proto || proto.constructor !== value)
|
|
12
|
+
return false;
|
|
13
|
+
const str = value.toString();
|
|
14
|
+
if (str.slice(0, 5) === "class" || Object.getOwnPropertyNames(proto).length >= 2)
|
|
15
|
+
return true;
|
|
16
|
+
if (re_anonymous.test(str))
|
|
17
|
+
return false;
|
|
18
|
+
if (strict && re_function.test(str))
|
|
19
|
+
return true;
|
|
20
|
+
if (re_this.test(str)) {
|
|
21
|
+
if (!strict || re_check.test(str))
|
|
22
|
+
return true;
|
|
23
|
+
return re_default.test(str);
|
|
24
|
+
}
|
|
25
|
+
return false;
|
|
29
26
|
};
|
|
30
27
|
export default isClass;
|
package/lib/is/empty.js
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
*/
|
|
5
|
-
const isEmpty = (value) => isNull(value)
|
|
6
|
-
|| value === '';
|
|
1
|
+
"use strict";
|
|
2
|
+
import isNull from "./null";
|
|
3
|
+
const isEmpty = (value) => isNull(value) || value === "";
|
|
7
4
|
export default isEmpty;
|
package/lib/is/null.js
CHANGED
package/lib/memory/basic.js
CHANGED
|
@@ -1,142 +1,136 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
* 分类存储(通过继承,可用于拓展存储方式)
|
|
4
|
-
*/
|
|
1
|
+
"use strict";
|
|
2
|
+
import hash8strings from "../convert/strings";
|
|
5
3
|
export default class MemoryBasic {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
4
|
+
/**
|
|
5
|
+
* @param key 用于对数据进行分类的key
|
|
6
|
+
* @param config
|
|
7
|
+
*/
|
|
8
|
+
constructor(key, config) {
|
|
9
|
+
this.key = key;
|
|
10
|
+
this.#mount = config.mount;
|
|
11
|
+
this.#reflex = config.reflex;
|
|
12
|
+
}
|
|
13
|
+
#mount;
|
|
14
|
+
#reflex;
|
|
15
|
+
list = [];
|
|
16
|
+
memorys = /* @__PURE__ */ new Map();
|
|
17
|
+
/**
|
|
18
|
+
* 返回存储长度
|
|
19
|
+
*/
|
|
20
|
+
get size() {
|
|
21
|
+
return this.list.length;
|
|
22
|
+
}
|
|
23
|
+
getType(data) {
|
|
24
|
+
const { key } = this;
|
|
25
|
+
return typeof key === "function" ? key(data) : data[key];
|
|
26
|
+
}
|
|
27
|
+
push(...list) {
|
|
28
|
+
const { memorys } = this;
|
|
29
|
+
list.forEach((data) => {
|
|
30
|
+
const type = this.getType(data);
|
|
31
|
+
const memory = memorys.get(type);
|
|
32
|
+
const index = this.list.push(data) - 1;
|
|
33
|
+
const result = this.#mount(index, memory);
|
|
34
|
+
memory === result || memorys.set(type, result);
|
|
35
|
+
});
|
|
36
|
+
return this;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* 遍历所有存储数据(按入栈顺序)
|
|
40
|
+
*/
|
|
41
|
+
forEach(callback) {
|
|
42
|
+
this.list.forEach(callback);
|
|
43
|
+
return this;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* 遍历所有存储类型
|
|
47
|
+
*/
|
|
48
|
+
forType(callback) {
|
|
49
|
+
const { memorys, list } = this;
|
|
50
|
+
for (const [type, memory] of memorys) {
|
|
51
|
+
const caches = this.#reflex(memory).map((index) => list[index]);
|
|
52
|
+
callback(caches, type);
|
|
16
53
|
}
|
|
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
|
-
|
|
50
|
-
|
|
51
|
-
forType(callback) {
|
|
52
|
-
const { memorys, list } = this;
|
|
53
|
-
for (const [type, memory] of memorys) {
|
|
54
|
-
const caches = this.#reflex(memory).map((index) => list[index]);
|
|
55
|
-
callback(caches, type);
|
|
56
|
-
}
|
|
57
|
-
return this;
|
|
58
|
-
}
|
|
59
|
-
/**
|
|
60
|
-
* 检测存储是否包含某种类型
|
|
61
|
-
*/
|
|
62
|
-
includes(type) {
|
|
63
|
-
return this.memorys.has(type);
|
|
64
|
-
}
|
|
65
|
-
/**
|
|
66
|
-
* 获取指定类型存储数据
|
|
67
|
-
*/
|
|
68
|
-
get(type) {
|
|
69
|
-
const memory = this.memorys.get(type);
|
|
70
|
-
return memory === void 0
|
|
71
|
-
? null
|
|
72
|
-
: this.#reflex(memory).map((count) => this.list[count]);
|
|
73
|
-
}
|
|
74
|
-
/**
|
|
75
|
-
* 删除指定存储数据
|
|
76
|
-
*/
|
|
77
|
-
delete(data) {
|
|
78
|
-
const { memorys, list } = this;
|
|
79
|
-
let index = -1;
|
|
80
|
-
if (!list.some((value, i) => {
|
|
81
|
-
if (data === value) {
|
|
82
|
-
index = i;
|
|
83
|
-
list.splice(index, 1);
|
|
84
|
-
const type = this.getType(value);
|
|
85
|
-
const memory = this.#reflex(memorys.get(type));
|
|
86
|
-
if (memory.length === 1) {
|
|
87
|
-
memorys.delete(type);
|
|
88
|
-
}
|
|
89
|
-
else {
|
|
90
|
-
memory.some((count, j) => {
|
|
91
|
-
if (count === i) {
|
|
92
|
-
memory.splice(j, 1);
|
|
93
|
-
return true;
|
|
94
|
-
}
|
|
95
|
-
});
|
|
96
|
-
}
|
|
97
|
-
return true;
|
|
98
|
-
}
|
|
99
|
-
}))
|
|
100
|
-
return this;
|
|
101
|
-
for (const [type, target] of memorys) {
|
|
102
|
-
const memory = this.#reflex(target);
|
|
103
|
-
memory.forEach((value, index) => {
|
|
104
|
-
if (value >= index) {
|
|
105
|
-
memory[index] = value - 1;
|
|
106
|
-
}
|
|
107
|
-
});
|
|
108
|
-
if (memory !== target) {
|
|
109
|
-
let reactor;
|
|
110
|
-
memory.forEach((count) => {
|
|
111
|
-
reactor = this.#mount(count, reactor);
|
|
112
|
-
});
|
|
113
|
-
memorys.set(type, reactor);
|
|
54
|
+
return this;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* 检测存储是否包含某种类型
|
|
58
|
+
*/
|
|
59
|
+
includes(type) {
|
|
60
|
+
return this.memorys.has(type);
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* 获取指定类型存储数据
|
|
64
|
+
*/
|
|
65
|
+
get(type) {
|
|
66
|
+
const memory = this.memorys.get(type);
|
|
67
|
+
return memory === void 0 ? null : this.#reflex(memory).map((count) => this.list[count]);
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* 删除指定存储数据
|
|
71
|
+
*/
|
|
72
|
+
delete(data) {
|
|
73
|
+
const { memorys, list } = this;
|
|
74
|
+
let index = -1;
|
|
75
|
+
if (!list.some((value, i) => {
|
|
76
|
+
if (data === value) {
|
|
77
|
+
index = i;
|
|
78
|
+
list.splice(index, 1);
|
|
79
|
+
const type = this.getType(value);
|
|
80
|
+
const memory = this.#reflex(memorys.get(type));
|
|
81
|
+
if (memory.length === 1) {
|
|
82
|
+
memorys.delete(type);
|
|
83
|
+
} else {
|
|
84
|
+
memory.some((count, j) => {
|
|
85
|
+
if (count === i) {
|
|
86
|
+
memory.splice(j, 1);
|
|
87
|
+
return true;
|
|
114
88
|
}
|
|
89
|
+
});
|
|
115
90
|
}
|
|
116
|
-
return
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
if (
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
91
|
+
return true;
|
|
92
|
+
}
|
|
93
|
+
}))
|
|
94
|
+
return this;
|
|
95
|
+
for (const [type, target] of memorys) {
|
|
96
|
+
const memory = this.#reflex(target);
|
|
97
|
+
memory.forEach((value, index2) => {
|
|
98
|
+
if (value >= index2) {
|
|
99
|
+
memory[index2] = value - 1;
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
if (memory !== target) {
|
|
103
|
+
let reactor;
|
|
104
|
+
memory.forEach((count) => {
|
|
105
|
+
reactor = this.#mount(count, reactor);
|
|
130
106
|
});
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
return this;
|
|
134
|
-
}
|
|
135
|
-
/**
|
|
136
|
-
* 清理存储
|
|
137
|
-
*/
|
|
138
|
-
clear() {
|
|
139
|
-
this.list = [];
|
|
140
|
-
this.memorys.clear();
|
|
107
|
+
memorys.set(type, reactor);
|
|
108
|
+
}
|
|
141
109
|
}
|
|
110
|
+
return this;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* 删除指定类型存储数据
|
|
114
|
+
*/
|
|
115
|
+
deleteType(type) {
|
|
116
|
+
const { memorys, list } = this;
|
|
117
|
+
if (!memorys.has(type))
|
|
118
|
+
return this;
|
|
119
|
+
const local = hash8strings(this.#reflex(memorys.get(type)));
|
|
120
|
+
const Memory2 = this.constructor;
|
|
121
|
+
const imitator = new Memory2(this.key);
|
|
122
|
+
list.forEach((data, index) => {
|
|
123
|
+
index in local || imitator.push(data);
|
|
124
|
+
});
|
|
125
|
+
this.list = imitator.list;
|
|
126
|
+
this.memorys = imitator.memorys;
|
|
127
|
+
return this;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* 清理存储
|
|
131
|
+
*/
|
|
132
|
+
clear() {
|
|
133
|
+
this.list = [];
|
|
134
|
+
this.memorys.clear();
|
|
135
|
+
}
|
|
142
136
|
}
|
package/lib/memory/list.js
CHANGED
|
@@ -1,14 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
* 分类存储(基于普通的键值存储)
|
|
4
|
-
*/
|
|
1
|
+
"use strict";
|
|
2
|
+
import MemoryBasic from "./basic";
|
|
5
3
|
export default class MemoryList extends MemoryBasic {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
});
|
|
13
|
-
}
|
|
4
|
+
constructor(key) {
|
|
5
|
+
super(key, {
|
|
6
|
+
mount: (index, reactor) => reactor ? (reactor.push(index), reactor) : [index],
|
|
7
|
+
reflex: (reactor) => reactor
|
|
8
|
+
});
|
|
9
|
+
}
|
|
14
10
|
}
|
package/lib/memory/power.js
CHANGED
|
@@ -1,13 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
* 分类存储(基于2的n次幂之和构建唯一键进行存储)
|
|
5
|
-
*/
|
|
1
|
+
"use strict";
|
|
2
|
+
import deconPowersSum from "../power/decon";
|
|
3
|
+
import MemoryBasic from "./basic";
|
|
6
4
|
export default class MemoryPower extends MemoryBasic {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
5
|
+
constructor(key) {
|
|
6
|
+
super(key, {
|
|
7
|
+
mount: (index, reactor) => (reactor || 0) + 2 ** index,
|
|
8
|
+
reflex: (reactor) => deconPowersSum(reactor, "asc")
|
|
9
|
+
});
|
|
10
|
+
}
|
|
13
11
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|
package/lib/once.js
CHANGED
|
@@ -1,13 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
* 缓存函数返回值
|
|
3
|
-
* @param callback 运行返回值的函数
|
|
4
|
-
* @param thisArg 绑定到运行函数的this对象
|
|
5
|
-
*/
|
|
1
|
+
"use strict";
|
|
6
2
|
export default (func, thisArg) => {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
? local
|
|
11
|
-
: (inited = true,
|
|
12
|
-
local = func.apply(thisArg, list));
|
|
3
|
+
let local;
|
|
4
|
+
let inited = false;
|
|
5
|
+
return (...list) => inited ? local : (inited = true, local = func.apply(thisArg, list));
|
|
13
6
|
};
|
package/lib/power/decon.js
CHANGED
|
@@ -1,29 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
const ERROR_MESSAGE = {
|
|
2
|
-
|
|
3
|
-
|
|
3
|
+
INT: "\u53C2\u6570\u5FC5\u987B\u662F\u6574\u6570",
|
|
4
|
+
MIN: "\u591A\u4E2A2\u7684\u6B63\u6574\u6570\u5E42(\u4E24\u4E24\u4E0D\u76F8\u7B49)\u4E4B\u548C\u5FC5\u5B9A\u5927\u4E8E\u7B49\u4E8E1"
|
|
4
5
|
};
|
|
5
|
-
/**
|
|
6
|
-
* 解构多个2的正整数幂(两两不相等)之和
|
|
7
|
-
* @param sum 幂和
|
|
8
|
-
* @param sort 排序方式(默认降序)
|
|
9
|
-
* @description sum > 2**53则会因为精度问题计算报错
|
|
10
|
-
*/
|
|
11
6
|
const deconPowersSum = (sum, sort) => {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
return sort === 'asc'
|
|
26
|
-
? list.reverse()
|
|
27
|
-
: list;
|
|
7
|
+
if (sum < 1) {
|
|
8
|
+
throw new Error(ERROR_MESSAGE.MIN);
|
|
9
|
+
} else if (sum !== Math.floor(sum)) {
|
|
10
|
+
throw new Error(ERROR_MESSAGE.INT);
|
|
11
|
+
}
|
|
12
|
+
const list = [];
|
|
13
|
+
let cache = sum;
|
|
14
|
+
while (cache) {
|
|
15
|
+
const power = Math.log2(cache) ^ 0;
|
|
16
|
+
list.push(power);
|
|
17
|
+
cache -= Math.pow(2, power);
|
|
18
|
+
}
|
|
19
|
+
return sort === "asc" ? list.reverse() : list;
|
|
28
20
|
};
|
|
29
21
|
export default deconPowersSum;
|
package/lib/rotate/angle.js
CHANGED
|
@@ -1,9 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
* 返回点被旋转指定角度后新的位置
|
|
4
|
-
* @param from 旋转点
|
|
5
|
-
* @param angle 旋转角度
|
|
6
|
-
* @param visit 旋转原点
|
|
7
|
-
*/
|
|
1
|
+
"use strict";
|
|
2
|
+
import rotateRad from "./rad";
|
|
8
3
|
const rotateAngle = (from, angle, visit) => rotateRad(from, angle / 180 * Math.PI, visit);
|
|
9
4
|
export default rotateAngle;
|
package/lib/rotate/rad.js
CHANGED
|
@@ -1,15 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
* 返回点被旋转指定弧度后新的位置
|
|
3
|
-
* @param from 旋转点
|
|
4
|
-
* @param rad 旋转弧度
|
|
5
|
-
* @param visit 旋转原点
|
|
6
|
-
*/
|
|
1
|
+
"use strict";
|
|
7
2
|
const rotateRad = (from, rad, visit = [0, 0]) => {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
3
|
+
const x = from[0] - visit[0];
|
|
4
|
+
const y = from[1] - visit[1];
|
|
5
|
+
return [
|
|
6
|
+
x * Math.cos(rad) + y * Math.sin(rad) + visit[0],
|
|
7
|
+
y * Math.cos(rad) - x * Math.sin(rad) + visit[1]
|
|
8
|
+
];
|
|
14
9
|
};
|
|
15
10
|
export default rotateRad;
|
package/lib/union.js
CHANGED
|
@@ -1,26 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
* 数据联合(用于需要对加入的数据进行智能提示)
|
|
3
|
-
*/
|
|
1
|
+
"use strict";
|
|
4
2
|
export default class Union {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
return this;
|
|
25
|
-
}
|
|
3
|
+
constructor(key, formatter) {
|
|
4
|
+
this.key = key;
|
|
5
|
+
this.formatter = formatter;
|
|
6
|
+
}
|
|
7
|
+
#data = {};
|
|
8
|
+
#options = {};
|
|
9
|
+
get data() {
|
|
10
|
+
return this.#data;
|
|
11
|
+
}
|
|
12
|
+
get options() {
|
|
13
|
+
return this.#options;
|
|
14
|
+
}
|
|
15
|
+
add(data) {
|
|
16
|
+
const key = data[this.key];
|
|
17
|
+
const result = this.formatter(data);
|
|
18
|
+
this.#data[key] = result.data;
|
|
19
|
+
this.#options[key] = result.option;
|
|
20
|
+
return this;
|
|
21
|
+
}
|
|
26
22
|
}
|
package/lib/url/join.js
CHANGED
|
@@ -1,13 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
const re = /([^:])\/{2,}/g;
|
|
2
|
-
/**
|
|
3
|
-
* 实现多个路径拼接
|
|
4
|
-
*/
|
|
5
3
|
const joinPaths = (...list) => {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
? list[0]
|
|
11
|
-
: list.join('/').replace(re, ($0, $1) => `${$1}/`);
|
|
4
|
+
const { length } = list;
|
|
5
|
+
if (length === 0)
|
|
6
|
+
return "";
|
|
7
|
+
return length === 1 ? list[0] : list.join("/").replace(re, ($0, $1) => `${$1}/`);
|
|
12
8
|
};
|
|
13
9
|
export default joinPaths;
|
package/lib/url/params.js
CHANGED
|
@@ -1,35 +1,23 @@
|
|
|
1
|
-
|
|
2
|
-
* url拼接参数
|
|
3
|
-
* @param url
|
|
4
|
-
* @param params 需要让url携带的参数
|
|
5
|
-
* @param isOpenType 是否开启类型处理
|
|
6
|
-
* @description 开始类型处理的情况下,undefined会被转成null
|
|
7
|
-
*/
|
|
1
|
+
"use strict";
|
|
8
2
|
const connectURLParams = (url, params, isOpenType) => {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
: value.join(',')));
|
|
23
|
-
}
|
|
24
|
-
else {
|
|
25
|
-
list.push(key + '=' + (isOpenType ? JSON.stringify(value) : value.toString()));
|
|
26
|
-
}
|
|
3
|
+
if (!params)
|
|
4
|
+
return url;
|
|
5
|
+
const list = [];
|
|
6
|
+
for (const key in params) {
|
|
7
|
+
const value = params[key];
|
|
8
|
+
if (value === void 0) {
|
|
9
|
+
list.push(key);
|
|
10
|
+
} else if (Array.isArray(value)) {
|
|
11
|
+
list.push(
|
|
12
|
+
key + "=" + (isOpenType ? JSON.stringify(value).slice(1, -1) : value.join(","))
|
|
13
|
+
);
|
|
14
|
+
} else {
|
|
15
|
+
list.push(key + "=" + (isOpenType ? JSON.stringify(value) : value.toString()));
|
|
27
16
|
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
: url + '?' + caches;
|
|
17
|
+
}
|
|
18
|
+
if (!list.length)
|
|
19
|
+
return url;
|
|
20
|
+
const caches = list.join("&");
|
|
21
|
+
return url.includes("?") ? url + "&" + caches : url + "?" + caches;
|
|
34
22
|
};
|
|
35
23
|
export default connectURLParams;
|
package/lib/wait.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vope/utils",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"publishConfig": {
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"scripts": {
|
|
14
14
|
"build": "npm run cjs | npm run esm | npm run types",
|
|
15
15
|
"cjs": "rimraf cjs & npx tsc -p ./tsconfig.cjs.json",
|
|
16
|
-
"esm": "rimraf lib & npx
|
|
16
|
+
"esm": "rimraf lib & npx esbuild ./src/**/*.ts --outdir=lib",
|
|
17
17
|
"types": "rimraf types & npx tsc -p ./tsconfig.types.json & node ./__devs/type.cjs",
|
|
18
18
|
"trove": "node ./__devs/trove.cjs",
|
|
19
19
|
"trove:build": "npm run devs & npm run trove",
|
|
@@ -43,6 +43,7 @@
|
|
|
43
43
|
"@types/mocha": "^10.0.1",
|
|
44
44
|
"@types/node": "^20.4.5",
|
|
45
45
|
"@vope/types": "^1.0.2",
|
|
46
|
+
"esbuild": "^0.19.4",
|
|
46
47
|
"iconv-lite": "^0.6.3",
|
|
47
48
|
"mocha": "^10.2.0",
|
|
48
49
|
"rimraf": "^5.0.1",
|
|
@@ -50,9 +51,6 @@
|
|
|
50
51
|
"tslib": "^2.6.1",
|
|
51
52
|
"typescript": "^5.1.6"
|
|
52
53
|
},
|
|
53
|
-
"dependencies": {
|
|
54
|
-
"axios": "^1.4.0"
|
|
55
|
-
},
|
|
56
54
|
"files": [
|
|
57
55
|
"cjs",
|
|
58
56
|
"lib",
|
package/types/index.d.ts
CHANGED
package/cjs/api.js
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.apiGet = exports.apiPost = void 0;
|
|
7
|
-
const params_1 = __importDefault(require("./url/params"));
|
|
8
|
-
const cut = (config, key) => {
|
|
9
|
-
if (key in config) {
|
|
10
|
-
const value = config[key];
|
|
11
|
-
delete config[key];
|
|
12
|
-
return value;
|
|
13
|
-
}
|
|
14
|
-
};
|
|
15
|
-
const apiPost = (axios, handle) => {
|
|
16
|
-
function post(url, options, config) {
|
|
17
|
-
let twist;
|
|
18
|
-
let rejectValue = false;
|
|
19
|
-
if (config) {
|
|
20
|
-
twist = cut(config, 'twist');
|
|
21
|
-
const rejectValue0 = cut(config, 'rejectValue');
|
|
22
|
-
rejectValue0 !== void 0 && (rejectValue = rejectValue0);
|
|
23
|
-
}
|
|
24
|
-
return new Promise((resolve) => {
|
|
25
|
-
axios.post(url, options, config).then(
|
|
26
|
-
// @ts-ignore
|
|
27
|
-
resolve, (e) => {
|
|
28
|
-
twist ? twist(e) : handle(e);
|
|
29
|
-
resolve(rejectValue);
|
|
30
|
-
});
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
return post;
|
|
34
|
-
};
|
|
35
|
-
exports.apiPost = apiPost;
|
|
36
|
-
const apiGet = (axios, handle) => {
|
|
37
|
-
function get(url, options, config) {
|
|
38
|
-
let twist;
|
|
39
|
-
let rejectValue = false;
|
|
40
|
-
if (config) {
|
|
41
|
-
twist = cut(config, 'twist');
|
|
42
|
-
const rejectValue0 = cut(config, 'rejectValue');
|
|
43
|
-
rejectValue0 !== void 0 && (rejectValue = rejectValue0);
|
|
44
|
-
}
|
|
45
|
-
return new Promise((resolve) => {
|
|
46
|
-
axios.get((0, params_1.default)(url, options), config).then(
|
|
47
|
-
// @ts-ignore
|
|
48
|
-
resolve, (e) => {
|
|
49
|
-
twist ? twist(e) : handle(e);
|
|
50
|
-
resolve(rejectValue);
|
|
51
|
-
});
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
return get;
|
|
55
|
-
};
|
|
56
|
-
exports.apiGet = apiGet;
|
package/lib/api.js
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import connectURLParams from './url/params';
|
|
2
|
-
const cut = (config, key) => {
|
|
3
|
-
if (key in config) {
|
|
4
|
-
const value = config[key];
|
|
5
|
-
delete config[key];
|
|
6
|
-
return value;
|
|
7
|
-
}
|
|
8
|
-
};
|
|
9
|
-
export const apiPost = (axios, handle) => {
|
|
10
|
-
function post(url, options, config) {
|
|
11
|
-
let twist;
|
|
12
|
-
let rejectValue = false;
|
|
13
|
-
if (config) {
|
|
14
|
-
twist = cut(config, 'twist');
|
|
15
|
-
const rejectValue0 = cut(config, 'rejectValue');
|
|
16
|
-
rejectValue0 !== void 0 && (rejectValue = rejectValue0);
|
|
17
|
-
}
|
|
18
|
-
return new Promise((resolve) => {
|
|
19
|
-
axios.post(url, options, config).then(
|
|
20
|
-
// @ts-ignore
|
|
21
|
-
resolve, (e) => {
|
|
22
|
-
twist ? twist(e) : handle(e);
|
|
23
|
-
resolve(rejectValue);
|
|
24
|
-
});
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
return post;
|
|
28
|
-
};
|
|
29
|
-
export const apiGet = (axios, handle) => {
|
|
30
|
-
function get(url, options, config) {
|
|
31
|
-
let twist;
|
|
32
|
-
let rejectValue = false;
|
|
33
|
-
if (config) {
|
|
34
|
-
twist = cut(config, 'twist');
|
|
35
|
-
const rejectValue0 = cut(config, 'rejectValue');
|
|
36
|
-
rejectValue0 !== void 0 && (rejectValue = rejectValue0);
|
|
37
|
-
}
|
|
38
|
-
return new Promise((resolve) => {
|
|
39
|
-
axios.get(connectURLParams(url, options), config).then(
|
|
40
|
-
// @ts-ignore
|
|
41
|
-
resolve, (e) => {
|
|
42
|
-
twist ? twist(e) : handle(e);
|
|
43
|
-
resolve(rejectValue);
|
|
44
|
-
});
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
return get;
|
|
48
|
-
};
|
package/types/api.d.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { ReviseRequired } from '@vope/types';
|
|
2
|
-
import { AxiosInstance, AxiosRequestConfig } from 'axios';
|
|
3
|
-
import connectURLParams from './url/params';
|
|
4
|
-
interface Config<V> extends AxiosRequestConfig {
|
|
5
|
-
/** 变更默认错误返回值 */
|
|
6
|
-
rejectValue?: V;
|
|
7
|
-
/** 错误拦截 */
|
|
8
|
-
twist?: (e: Error) => void;
|
|
9
|
-
}
|
|
10
|
-
type Options = NonNullable<Parameters<typeof connectURLParams>[1]>;
|
|
11
|
-
export declare const apiPost: (axios: AxiosInstance, handle: (e: Error) => void) => {
|
|
12
|
-
<T, V extends false = false>(url: string, options?: Options, config?: Config<V> | undefined): Promise<T | V>;
|
|
13
|
-
<T_1, V_1 extends string | symbol>(url: string, options: Options | undefined, config: ReviseRequired<Config<V_1>, "rejectValue">): Promise<T_1 | V_1>;
|
|
14
|
-
};
|
|
15
|
-
export declare const apiGet: (axios: AxiosInstance, handle: (e: Error) => void) => {
|
|
16
|
-
<T, V extends false = false>(url: string, options?: Options, config?: Config<V> | undefined): Promise<T | V>;
|
|
17
|
-
<T_1, V_1 extends string | symbol>(url: string, options: Options | undefined, config: ReviseRequired<Config<V_1>, "rejectValue">): Promise<T_1 | V_1>;
|
|
18
|
-
};
|
|
19
|
-
export {};
|