@vope/utils 1.0.1 → 1.1.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/README.md +5 -0
- package/cjs/clamp.js +14 -0
- package/cjs/classnames.js +22 -0
- package/cjs/compare/version.js +21 -0
- package/cjs/compare/{value.js → weak-equal.js} +6 -6
- package/cjs/convert/json.js +1 -1
- package/cjs/encoding.js +65 -0
- package/cjs/index.js +25 -5
- package/cjs/is/class.js +1 -2
- package/cjs/memory/basic.js +148 -0
- package/cjs/memory/list.js +20 -0
- package/cjs/memory/power.js +19 -0
- package/cjs/once.js +15 -0
- package/cjs/power/decon.js +31 -0
- package/cjs/union.js +25 -0
- package/cjs/url/join.js +1 -2
- package/lib/clamp.js +12 -0
- package/lib/classnames.js +20 -0
- package/lib/compare/version.js +19 -0
- package/lib/compare/{value.js → weak-equal.js} +6 -6
- package/lib/convert/json.js +1 -1
- package/lib/encoding.js +63 -0
- package/lib/index.js +13 -3
- package/lib/is/class.js +2 -1
- package/lib/memory/basic.js +142 -0
- package/lib/memory/list.js +14 -0
- package/lib/memory/power.js +13 -0
- package/lib/once.js +13 -0
- package/lib/power/decon.js +29 -0
- package/lib/union.js +22 -0
- package/lib/url/join.js +2 -1
- package/package.json +8 -6
- package/types/clamp.d.ts +5 -0
- package/types/classnames.d.ts +7 -0
- package/types/compare/version.d.ts +6 -0
- package/types/compare/weak-equal.d.ts +5 -0
- package/types/convert/json.d.ts +2 -2
- package/types/encoding.d.ts +16 -0
- package/types/index.d.ts +13 -3
- package/types/is/class.d.ts +2 -1
- package/types/memory/basic.d.ts +63 -0
- package/types/memory/list.d.ts +8 -0
- package/types/memory/power.d.ts +8 -0
- package/types/memory/type.d.ts +11 -0
- package/types/once.d.ts +7 -0
- package/types/power/decon.d.ts +9 -0
- package/types/union.d.ts +20 -0
- package/types/url/join.d.ts +2 -1
- package/types/compare/value.d.ts +0 -5
package/lib/encoding.js
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
const utf8_first_prefix = /^1{2,}/g;
|
|
2
|
+
const utf8_other_prefix = /^10/;
|
|
3
|
+
var Encodes;
|
|
4
|
+
(function (Encodes) {
|
|
5
|
+
Encodes["UTF_8"] = "utf-8";
|
|
6
|
+
Encodes["UTF_16LE"] = "utf-16le";
|
|
7
|
+
Encodes["UTF_16BE"] = "utf-16be";
|
|
8
|
+
Encodes["GBK"] = "gbk";
|
|
9
|
+
})(Encodes || (Encodes = {}));
|
|
10
|
+
const defaults = {
|
|
11
|
+
utf8: [0xef, 0xbb, 0xbf],
|
|
12
|
+
};
|
|
13
|
+
const equal = (uint, list) => {
|
|
14
|
+
if (uint.length !== list.length)
|
|
15
|
+
return false;
|
|
16
|
+
return !uint.some((value, index) => value !== list[index]);
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* 根据文件内容判断文件的编码
|
|
20
|
+
* @param uint 文件内容Uint8Array格式
|
|
21
|
+
* @param limit 用于约束GBK和utf_8的判定上限
|
|
22
|
+
*/
|
|
23
|
+
const getEncoding = (uint, limit = 1024) => {
|
|
24
|
+
let encoding;
|
|
25
|
+
let offset = 0;
|
|
26
|
+
if (equal(uint.slice(0, 3), defaults.utf8)) {
|
|
27
|
+
offset = defaults.utf8.length;
|
|
28
|
+
encoding = Encodes.UTF_8;
|
|
29
|
+
}
|
|
30
|
+
else if (equal(uint.slice(0, 2), [0xff, 0xfe])) {
|
|
31
|
+
encoding = Encodes.UTF_16LE;
|
|
32
|
+
}
|
|
33
|
+
else if (equal(uint.slice(0, 2), [0xfe, 0xff])) {
|
|
34
|
+
encoding = Encodes.UTF_16BE;
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
let isBreak = false;
|
|
38
|
+
top: for (let i = 0; i < Math.min(uint.length, limit); i++) {
|
|
39
|
+
const data = uint[i];
|
|
40
|
+
if (data < 128)
|
|
41
|
+
continue;
|
|
42
|
+
const match = data.toString(2).match(utf8_first_prefix);
|
|
43
|
+
if (match) {
|
|
44
|
+
for (let m = 0; m < match[0].length - 1; m++) {
|
|
45
|
+
const target = uint[++i];
|
|
46
|
+
if (target == void 0 || !utf8_other_prefix.test(target.toString(2))) {
|
|
47
|
+
encoding = Encodes.GBK;
|
|
48
|
+
isBreak = true;
|
|
49
|
+
break top;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
encoding = Encodes.GBK;
|
|
55
|
+
isBreak = true;
|
|
56
|
+
break;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
isBreak || (encoding = Encodes.UTF_8);
|
|
60
|
+
}
|
|
61
|
+
return { encoding, offset };
|
|
62
|
+
};
|
|
63
|
+
export default getEncoding;
|
package/lib/index.js
CHANGED
|
@@ -1,10 +1,20 @@
|
|
|
1
1
|
export { apiPost, apiGet } from './api';
|
|
2
|
-
export { default as
|
|
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';
|
|
3
6
|
export { default as hash8json } from './convert/json';
|
|
4
7
|
export { default as hash8object } from './convert/object';
|
|
5
8
|
export { default as hash8strings } from './convert/strings';
|
|
6
|
-
export {
|
|
9
|
+
export { default as getEncoding } from './encoding';
|
|
10
|
+
export { default as isClass } from './is/class';
|
|
7
11
|
export { default as isEmpty } from './is/empty';
|
|
8
12
|
export { default as isNull } from './is/null';
|
|
9
|
-
export {
|
|
13
|
+
export { default as MemoryBasic } from './memory/basic';
|
|
14
|
+
export { default as MemoryList } from './memory/list';
|
|
15
|
+
export { default as MemoryPower } from './memory/power';
|
|
16
|
+
export { default as once } from './once';
|
|
17
|
+
export { default as deconPowersSum } from './power/decon';
|
|
18
|
+
export { default as Union } from './union';
|
|
19
|
+
export { default as joinURLs } from './url/join';
|
|
10
20
|
export { default as connectURLParams } from './url/params';
|
package/lib/is/class.js
CHANGED
|
@@ -6,7 +6,7 @@ const re_default = /^function\sdefault_\d+\s*\(/;
|
|
|
6
6
|
/**
|
|
7
7
|
* 检测是否为class
|
|
8
8
|
*/
|
|
9
|
-
|
|
9
|
+
const isClass = (value, strict = true) => {
|
|
10
10
|
if (typeof value !== 'function')
|
|
11
11
|
return false;
|
|
12
12
|
const proto = value.prototype;
|
|
@@ -27,3 +27,4 @@ export const isClass = (value, strict = true) => {
|
|
|
27
27
|
}
|
|
28
28
|
return false;
|
|
29
29
|
};
|
|
30
|
+
export default isClass;
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import hash8strings from '../convert/strings';
|
|
2
|
+
/**
|
|
3
|
+
* 分类存储(通过继承,可用于拓展存储方式)
|
|
4
|
+
*/
|
|
5
|
+
export default class MemoryBasic {
|
|
6
|
+
key;
|
|
7
|
+
#mount;
|
|
8
|
+
#reflex;
|
|
9
|
+
list = [];
|
|
10
|
+
memorys = new Map();
|
|
11
|
+
/**
|
|
12
|
+
* 返回存储长度
|
|
13
|
+
*/
|
|
14
|
+
get size() {
|
|
15
|
+
return this.list.length;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* @param key 用于对数据进行分类的key
|
|
19
|
+
* @param config
|
|
20
|
+
*/
|
|
21
|
+
constructor(key, config) {
|
|
22
|
+
this.key = key;
|
|
23
|
+
this.#mount = config.mount;
|
|
24
|
+
this.#reflex = config.reflex;
|
|
25
|
+
}
|
|
26
|
+
getType(data) {
|
|
27
|
+
const { key } = this;
|
|
28
|
+
return typeof key === 'function' ? key(data) : data[key];
|
|
29
|
+
}
|
|
30
|
+
push(...list) {
|
|
31
|
+
const { memorys } = this;
|
|
32
|
+
list.forEach((data) => {
|
|
33
|
+
const type = this.getType(data);
|
|
34
|
+
const memory = memorys.get(type);
|
|
35
|
+
const index = this.list.push(data) - 1;
|
|
36
|
+
const result = this.#mount(index, memory);
|
|
37
|
+
memory === result || memorys.set(type, result);
|
|
38
|
+
});
|
|
39
|
+
return this;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* 遍历所有存储数据(按入栈顺序)
|
|
43
|
+
*/
|
|
44
|
+
forEach(callback) {
|
|
45
|
+
this.list.forEach(callback);
|
|
46
|
+
return this;
|
|
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 type in this.memorys;
|
|
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);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
return this;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* 删除指定类型存储数据
|
|
120
|
+
*/
|
|
121
|
+
deleteType(type) {
|
|
122
|
+
const { memorys, list } = this;
|
|
123
|
+
if (!memorys.has(type))
|
|
124
|
+
return this;
|
|
125
|
+
const local = hash8strings(this.#reflex(memorys.get(type)));
|
|
126
|
+
const Memory = this.constructor;
|
|
127
|
+
const imitator = new Memory(this.key);
|
|
128
|
+
list.forEach((data, index) => {
|
|
129
|
+
index in local || imitator.push(data);
|
|
130
|
+
});
|
|
131
|
+
this.list = imitator.list;
|
|
132
|
+
this.memorys = imitator.memorys;
|
|
133
|
+
return this;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* 清理存储
|
|
137
|
+
*/
|
|
138
|
+
clear() {
|
|
139
|
+
this.list = [];
|
|
140
|
+
this.memorys.clear();
|
|
141
|
+
}
|
|
142
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import MemoryBasic from './basic';
|
|
2
|
+
/**
|
|
3
|
+
* 分类存储(基于普通的键值存储)
|
|
4
|
+
*/
|
|
5
|
+
export default class MemoryList extends MemoryBasic {
|
|
6
|
+
constructor(key) {
|
|
7
|
+
super(key, {
|
|
8
|
+
mount: (index, reactor) => reactor
|
|
9
|
+
? (reactor.push(index), reactor)
|
|
10
|
+
: [index],
|
|
11
|
+
reflex: (reactor) => reactor,
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import deconPowersSum from '../power/decon';
|
|
2
|
+
import MemoryBasic from './basic';
|
|
3
|
+
/**
|
|
4
|
+
* 分类存储(基于2的n次幂之和构建唯一键进行存储)
|
|
5
|
+
*/
|
|
6
|
+
export default class MemoryPower extends MemoryBasic {
|
|
7
|
+
constructor(key) {
|
|
8
|
+
super(key, {
|
|
9
|
+
mount: (index, reactor) => (reactor || 0) + 2 ** index,
|
|
10
|
+
reflex: (reactor) => deconPowersSum(reactor, 'asc'),
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
}
|
package/lib/once.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 缓存函数返回值
|
|
3
|
+
* @param callback 运行返回值的函数
|
|
4
|
+
* @param thisArg 绑定到运行函数的this对象
|
|
5
|
+
*/
|
|
6
|
+
export default (func, thisArg) => {
|
|
7
|
+
let local;
|
|
8
|
+
let inited = false;
|
|
9
|
+
return (...list) => inited
|
|
10
|
+
? local
|
|
11
|
+
: (inited = true,
|
|
12
|
+
local = func.apply(thisArg, list));
|
|
13
|
+
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
const ERROR_MESSAGE = {
|
|
2
|
+
INT: '参数必须是整数',
|
|
3
|
+
MIN: '多个2的正整数幂(两两不相等)之和必定大于等于1',
|
|
4
|
+
};
|
|
5
|
+
/**
|
|
6
|
+
* 解构多个2的正整数幂(两两不相等)之和
|
|
7
|
+
* @param sum 幂和
|
|
8
|
+
* @param sort 排序方式(默认降序)
|
|
9
|
+
* @description sum > 2**53则会因为精度问题计算报错
|
|
10
|
+
*/
|
|
11
|
+
const deconPowersSum = (sum, sort) => {
|
|
12
|
+
if (sum < 1) {
|
|
13
|
+
throw new Error(ERROR_MESSAGE.MIN);
|
|
14
|
+
}
|
|
15
|
+
else if (sum !== Math.floor(sum)) {
|
|
16
|
+
throw new Error(ERROR_MESSAGE.INT);
|
|
17
|
+
}
|
|
18
|
+
const list = [];
|
|
19
|
+
let cache = sum;
|
|
20
|
+
while (cache) {
|
|
21
|
+
const power = Math.log2(cache) ^ 0;
|
|
22
|
+
list.push(power);
|
|
23
|
+
cache -= Math.pow(2, power);
|
|
24
|
+
}
|
|
25
|
+
return sort === 'asc'
|
|
26
|
+
? list.reverse()
|
|
27
|
+
: list;
|
|
28
|
+
};
|
|
29
|
+
export default deconPowersSum;
|
package/lib/union.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 数据联合(用于需要对加入的数据进行智能提示)
|
|
3
|
+
*/
|
|
4
|
+
export default class Union {
|
|
5
|
+
key;
|
|
6
|
+
formater;
|
|
7
|
+
#map = {};
|
|
8
|
+
get value() {
|
|
9
|
+
return this.#map;
|
|
10
|
+
}
|
|
11
|
+
constructor(key, formater) {
|
|
12
|
+
this.key = key;
|
|
13
|
+
this.formater = formater;
|
|
14
|
+
}
|
|
15
|
+
add(data) {
|
|
16
|
+
const { formater } = this;
|
|
17
|
+
this.#map[data[this.key]] = formater
|
|
18
|
+
? formater(data)
|
|
19
|
+
: data;
|
|
20
|
+
return this;
|
|
21
|
+
}
|
|
22
|
+
}
|
package/lib/url/join.js
CHANGED
|
@@ -2,7 +2,7 @@ const re = /(^|[^:/])\/{2,}/g;
|
|
|
2
2
|
/**
|
|
3
3
|
* 实现多个路径拼接
|
|
4
4
|
*/
|
|
5
|
-
|
|
5
|
+
const joinURLs = (...list) => {
|
|
6
6
|
const { length } = list;
|
|
7
7
|
if (length === 0)
|
|
8
8
|
return '';
|
|
@@ -10,3 +10,4 @@ export const joinURLs = (...list) => {
|
|
|
10
10
|
? list[0]
|
|
11
11
|
: list.join('/').replace(re, ($0, $1) => `${$1}/`);
|
|
12
12
|
};
|
|
13
|
+
export default joinURLs;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vope/utils",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"publishConfig": {
|
|
@@ -11,17 +11,18 @@
|
|
|
11
11
|
"module": "./lib/index.js",
|
|
12
12
|
"main": "./cjs/index.js",
|
|
13
13
|
"scripts": {
|
|
14
|
-
"build": "
|
|
14
|
+
"build": "npm run cjs | npm run esm | npm run types",
|
|
15
|
+
"init:build": "npm run devs & npm run trove & npm run test:build",
|
|
15
16
|
"cjs": "rimraf cjs & npx tsc -p ./tsconfig.cjs.json",
|
|
16
17
|
"esm": "rimraf lib & npx tsc -p ./tsconfig.esm.json",
|
|
18
|
+
"types": "rimraf types & npx tsc -p ./tsconfig.types.json & node ./__devs/type.cjs",
|
|
17
19
|
"trove": "node ./__devs/trove.cjs",
|
|
18
20
|
"trove:build": "npm run devs & npm run trove",
|
|
19
21
|
"devs": "rimraf __devs & npx tsc -p ./tsconfig.devs.json",
|
|
20
22
|
"test": "mocha __tests/**/*.js",
|
|
21
23
|
"test:dev": "npm run test:build & npm run test",
|
|
22
|
-
"test:build": "
|
|
24
|
+
"test:build": "node ./__devs/test.cjs",
|
|
23
25
|
"test:all": "npm run devs & npm run test:build & npm run test",
|
|
24
|
-
"init": "npm run devs & npm run trove & npm run test:build",
|
|
25
26
|
"prepublishOnly": "npm run devs & npm run trove & npm run build"
|
|
26
27
|
},
|
|
27
28
|
"exports": {
|
|
@@ -44,10 +45,11 @@
|
|
|
44
45
|
"@types/babel__traverse": "^7.20.1",
|
|
45
46
|
"@types/mocha": "^10.0.1",
|
|
46
47
|
"@types/node": "^20.4.5",
|
|
47
|
-
"@vope/types": "^1.0.
|
|
48
|
+
"@vope/types": "^1.0.2",
|
|
49
|
+
"iconv-lite": "^0.6.3",
|
|
48
50
|
"mocha": "^10.2.0",
|
|
49
51
|
"rimraf": "^5.0.1",
|
|
50
|
-
"rollup": "^3.
|
|
52
|
+
"rollup": "^3.28.1",
|
|
51
53
|
"tslib": "^2.6.1",
|
|
52
54
|
"typescript": "^5.1.6"
|
|
53
55
|
},
|
package/types/clamp.d.ts
ADDED
package/types/convert/json.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* 对象数组转hash(要求主键值为string类型)
|
|
2
|
+
* 对象数组转hash(要求主键值为string|number类型)
|
|
3
3
|
* @example
|
|
4
4
|
* hash8json(
|
|
5
5
|
* [
|
|
@@ -9,5 +9,5 @@
|
|
|
9
9
|
* 'key'
|
|
10
10
|
* ).a.value // 1
|
|
11
11
|
*/
|
|
12
|
-
declare const hash8json: <K extends string | symbol, T extends Record<K, string>>(list: T[], key: K) => Record<T[K], T>;
|
|
12
|
+
declare const hash8json: <K extends string | symbol, T extends Record<K, string | number>>(list: T[], key: K) => Record<T[K], T>;
|
|
13
13
|
export default hash8json;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
declare enum Encodes {
|
|
2
|
+
UTF_8 = "utf-8",
|
|
3
|
+
UTF_16LE = "utf-16le",
|
|
4
|
+
UTF_16BE = "utf-16be",
|
|
5
|
+
GBK = "gbk"
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* 根据文件内容判断文件的编码
|
|
9
|
+
* @param uint 文件内容Uint8Array格式
|
|
10
|
+
* @param limit 用于约束GBK和utf_8的判定上限
|
|
11
|
+
*/
|
|
12
|
+
declare const getEncoding: (uint: Uint8Array, limit?: number) => {
|
|
13
|
+
encoding: Encodes;
|
|
14
|
+
offset: number;
|
|
15
|
+
};
|
|
16
|
+
export default getEncoding;
|
package/types/index.d.ts
CHANGED
|
@@ -1,10 +1,20 @@
|
|
|
1
1
|
export { apiPost, apiGet } from './api';
|
|
2
|
-
export { default as
|
|
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';
|
|
3
6
|
export { default as hash8json } from './convert/json';
|
|
4
7
|
export { default as hash8object } from './convert/object';
|
|
5
8
|
export { default as hash8strings } from './convert/strings';
|
|
6
|
-
export {
|
|
9
|
+
export { default as getEncoding } from './encoding';
|
|
10
|
+
export { default as isClass } from './is/class';
|
|
7
11
|
export { default as isEmpty } from './is/empty';
|
|
8
12
|
export { default as isNull } from './is/null';
|
|
9
|
-
export {
|
|
13
|
+
export { default as MemoryBasic } from './memory/basic';
|
|
14
|
+
export { default as MemoryList } from './memory/list';
|
|
15
|
+
export { default as MemoryPower } from './memory/power';
|
|
16
|
+
export { default as once } from './once';
|
|
17
|
+
export { default as deconPowersSum } from './power/decon';
|
|
18
|
+
export { default as Union } from './union';
|
|
19
|
+
export { default as joinURLs } from './url/join';
|
|
10
20
|
export { default as connectURLParams } from './url/params';
|
package/types/is/class.d.ts
CHANGED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { Memory } from './type';
|
|
2
|
+
interface Config<Reactor> {
|
|
3
|
+
/**
|
|
4
|
+
* 定义数据如何挂载到存储中
|
|
5
|
+
* @param index 当前存入数据对应的角标
|
|
6
|
+
* @param reactor 当前存入数据对应存储单元
|
|
7
|
+
*/
|
|
8
|
+
mount(index: number, reactor?: Reactor): Reactor;
|
|
9
|
+
/**
|
|
10
|
+
* 定义存储单元和存储关系
|
|
11
|
+
* @param reactor 存储单元
|
|
12
|
+
*/
|
|
13
|
+
reflex(reactor: Reactor): number[];
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* 分类存储(通过继承,可用于拓展存储方式)
|
|
17
|
+
*/
|
|
18
|
+
export default class MemoryBasic<V, Reactor, Type extends Memory.Type> {
|
|
19
|
+
#private;
|
|
20
|
+
protected key: Memory.Pitch<V, Type>;
|
|
21
|
+
protected list: V[];
|
|
22
|
+
protected memorys: Map<Type, Reactor>;
|
|
23
|
+
/**
|
|
24
|
+
* 返回存储长度
|
|
25
|
+
*/
|
|
26
|
+
get size(): number;
|
|
27
|
+
/**
|
|
28
|
+
* @param key 用于对数据进行分类的key
|
|
29
|
+
* @param config
|
|
30
|
+
*/
|
|
31
|
+
constructor(key: Memory.Pitch<V, Type>, config: Config<Reactor>);
|
|
32
|
+
protected getType(data: V): Type;
|
|
33
|
+
push(...list: V[]): this;
|
|
34
|
+
/**
|
|
35
|
+
* 遍历所有存储数据(按入栈顺序)
|
|
36
|
+
*/
|
|
37
|
+
forEach(callback: (data: V, index: number) => void): this;
|
|
38
|
+
/**
|
|
39
|
+
* 遍历所有存储类型
|
|
40
|
+
*/
|
|
41
|
+
forType(callback: (data: V[], type: Type) => void): this;
|
|
42
|
+
/**
|
|
43
|
+
* 检测存储是否包含某种类型
|
|
44
|
+
*/
|
|
45
|
+
includes(type: Type): boolean;
|
|
46
|
+
/**
|
|
47
|
+
* 获取指定类型存储数据
|
|
48
|
+
*/
|
|
49
|
+
get(type: Type): V[] | null;
|
|
50
|
+
/**
|
|
51
|
+
* 删除指定存储数据
|
|
52
|
+
*/
|
|
53
|
+
delete(data: V): this;
|
|
54
|
+
/**
|
|
55
|
+
* 删除指定类型存储数据
|
|
56
|
+
*/
|
|
57
|
+
deleteType(type: Type): this;
|
|
58
|
+
/**
|
|
59
|
+
* 清理存储
|
|
60
|
+
*/
|
|
61
|
+
clear(): void;
|
|
62
|
+
}
|
|
63
|
+
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import MemoryBasic from './basic';
|
|
2
|
+
import { Memory } from './type';
|
|
3
|
+
/**
|
|
4
|
+
* 分类存储(基于2的n次幂之和构建唯一键进行存储)
|
|
5
|
+
*/
|
|
6
|
+
export default class MemoryPower<V, Type extends Memory.Type = Memory.Type> extends MemoryBasic<V, number, Type> {
|
|
7
|
+
constructor(key: Memory.Pitch<V, Type>);
|
|
8
|
+
}
|
package/types/once.d.ts
ADDED
package/types/union.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Revise } from '@vope/types';
|
|
2
|
+
type IMap<K extends string, VV extends string, T extends {
|
|
3
|
+
[key in K]: string;
|
|
4
|
+
}> = {
|
|
5
|
+
[key in VV]?: T;
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* 数据联合(用于需要对加入的数据进行智能提示)
|
|
9
|
+
*/
|
|
10
|
+
export default class Union<K extends string, VV extends string, T extends {
|
|
11
|
+
[key in K]: string;
|
|
12
|
+
}, L extends VV | never = never> {
|
|
13
|
+
#private;
|
|
14
|
+
private key;
|
|
15
|
+
private formater?;
|
|
16
|
+
get value(): Required<IMap<K, L, T>>;
|
|
17
|
+
constructor(key: K, formater?: ((data: T) => T) | undefined);
|
|
18
|
+
add<V extends Exclude<VV, L>>(data: Revise<T, K, V>): Union<K, VV, T, L | V>;
|
|
19
|
+
}
|
|
20
|
+
export {};
|
package/types/url/join.d.ts
CHANGED