@vope/utils 1.0.2 → 1.2.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 +0 -5
- 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/encoding.js +65 -0
- package/cjs/index.js +33 -5
- package/cjs/input-regex.js +10 -0
- 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/rotate/angle.js +14 -0
- package/cjs/rotate/rad.js +17 -0
- package/cjs/union.js +25 -0
- package/cjs/url/join.js +3 -4
- package/cjs/wait.js +6 -0
- 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/encoding.js +63 -0
- package/lib/index.js +17 -3
- package/lib/input-regex.js +8 -0
- 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/rotate/angle.js +9 -0
- package/lib/rotate/rad.js +15 -0
- package/lib/union.js +22 -0
- package/lib/url/join.js +3 -2
- package/lib/wait.js +4 -0
- package/package.json +9 -10
- 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/encoding.d.ts +16 -0
- package/types/index.d.ts +17 -3
- package/types/input-regex.d.ts +13 -0
- 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/rotate/angle.d.ts +9 -0
- package/types/rotate/rad.d.ts +9 -0
- package/types/union.d.ts +20 -0
- package/types/url/join.d.ts +2 -1
- package/types/wait.d.ts +5 -0
- package/types/compare/value.d.ts +0 -5
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* 深度相等性比较(弱比较)
|
|
3
3
|
*/
|
|
4
|
-
const
|
|
4
|
+
const deepWeakEqual = (from, to) => {
|
|
5
5
|
if (typeof from !== 'object'
|
|
6
6
|
|| from === null
|
|
7
7
|
|| typeof to !== 'object'
|
|
@@ -11,7 +11,7 @@ const compareValue = (from, to) => {
|
|
|
11
11
|
if (from.length !== to.length)
|
|
12
12
|
return false;
|
|
13
13
|
return !from.some((t1, index) => {
|
|
14
|
-
if (!
|
|
14
|
+
if (!deepWeakEqual(t1, to[index])) {
|
|
15
15
|
return true;
|
|
16
16
|
}
|
|
17
17
|
});
|
|
@@ -19,7 +19,7 @@ const compareValue = (from, to) => {
|
|
|
19
19
|
else {
|
|
20
20
|
const caches = {};
|
|
21
21
|
for (const key in from) {
|
|
22
|
-
if (!
|
|
22
|
+
if (!deepWeakEqual(from[key], to[key])) {
|
|
23
23
|
return false;
|
|
24
24
|
}
|
|
25
25
|
else {
|
|
@@ -29,11 +29,11 @@ const compareValue = (from, to) => {
|
|
|
29
29
|
for (const key in to) {
|
|
30
30
|
if (key in caches)
|
|
31
31
|
continue;
|
|
32
|
-
if (!
|
|
32
|
+
if (!deepWeakEqual(from[key], to[key])) {
|
|
33
33
|
return false;
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
37
|
return true;
|
|
38
38
|
};
|
|
39
|
-
export default
|
|
39
|
+
export default deepWeakEqual;
|
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,24 @@
|
|
|
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 inputRegex } from './input-regex';
|
|
11
|
+
export { default as isClass } from './is/class';
|
|
7
12
|
export { default as isEmpty } from './is/empty';
|
|
8
13
|
export { default as isNull } from './is/null';
|
|
9
|
-
export {
|
|
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';
|
|
10
23
|
export { default as connectURLParams } from './url/params';
|
|
24
|
+
export { default as wait } from './wait';
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
const RE_REGEX = /[$()*+.[?\\^{|]/g;
|
|
2
|
+
const RE_STRING = /[$()*+.[?\\^{|-]/g;
|
|
3
|
+
function inputRegex(text, flags) {
|
|
4
|
+
return flags === false
|
|
5
|
+
? text.replace(RE_STRING, ($0) => '\\' + $0)
|
|
6
|
+
: new RegExp(text.replace(RE_REGEX, ($0) => '\\' + $0), flags);
|
|
7
|
+
}
|
|
8
|
+
export default inputRegex;
|
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;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 返回点被旋转指定弧度后新的位置
|
|
3
|
+
* @param from 旋转点
|
|
4
|
+
* @param rad 旋转弧度
|
|
5
|
+
* @param visit 旋转原点
|
|
6
|
+
*/
|
|
7
|
+
const rotateRad = (from, rad, visit = [0, 0]) => {
|
|
8
|
+
const x = from[0] - visit[0];
|
|
9
|
+
const y = from[1] - visit[1];
|
|
10
|
+
return [
|
|
11
|
+
x * Math.cos(rad) + y * Math.sin(rad) + visit[0],
|
|
12
|
+
y * Math.cos(rad) - x * Math.sin(rad) + visit[1],
|
|
13
|
+
];
|
|
14
|
+
};
|
|
15
|
+
export default rotateRad;
|
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
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
const re = /(
|
|
1
|
+
const re = /([^:])\/{2,}/g;
|
|
2
2
|
/**
|
|
3
3
|
* 实现多个路径拼接
|
|
4
4
|
*/
|
|
5
|
-
|
|
5
|
+
const joinPaths = (...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 joinPaths;
|
package/lib/wait.js
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vope/utils",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"publishConfig": {
|
|
@@ -11,18 +11,16 @@
|
|
|
11
11
|
"module": "./lib/index.js",
|
|
12
12
|
"main": "./cjs/index.js",
|
|
13
13
|
"scripts": {
|
|
14
|
-
"build": "
|
|
15
|
-
"init:build": "npm run devs & npm run trove & npm run test:build",
|
|
14
|
+
"build": "npm run cjs | npm run esm | npm run types",
|
|
16
15
|
"cjs": "rimraf cjs & npx tsc -p ./tsconfig.cjs.json",
|
|
17
16
|
"esm": "rimraf lib & npx tsc -p ./tsconfig.esm.json",
|
|
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",
|
|
20
20
|
"devs": "rimraf __devs & npx tsc -p ./tsconfig.devs.json",
|
|
21
|
-
"test": "mocha __tests/**/*.js",
|
|
22
|
-
"test:
|
|
23
|
-
"
|
|
24
|
-
"test:all": "npm run devs & npm run test:build & npm run test",
|
|
25
|
-
"prepublishOnly": "npm run devs & npm run trove & npm run build"
|
|
21
|
+
"test": "node ./__devs/test.cjs & mocha __tests/**/*.js",
|
|
22
|
+
"test:build": "npm run devs & npm run trove & npm run test",
|
|
23
|
+
"prepublishOnly": "npm run devs & npm run trove & npm run test & npm run build"
|
|
26
24
|
},
|
|
27
25
|
"exports": {
|
|
28
26
|
".": {
|
|
@@ -44,10 +42,11 @@
|
|
|
44
42
|
"@types/babel__traverse": "^7.20.1",
|
|
45
43
|
"@types/mocha": "^10.0.1",
|
|
46
44
|
"@types/node": "^20.4.5",
|
|
47
|
-
"@vope/types": "^1.0.
|
|
45
|
+
"@vope/types": "^1.0.2",
|
|
46
|
+
"iconv-lite": "^0.6.3",
|
|
48
47
|
"mocha": "^10.2.0",
|
|
49
48
|
"rimraf": "^5.0.1",
|
|
50
|
-
"rollup": "^3.
|
|
49
|
+
"rollup": "^3.28.1",
|
|
51
50
|
"tslib": "^2.6.1",
|
|
52
51
|
"typescript": "^5.1.6"
|
|
53
52
|
},
|
package/types/clamp.d.ts
ADDED
|
@@ -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,24 @@
|
|
|
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 inputRegex } from './input-regex';
|
|
11
|
+
export { default as isClass } from './is/class';
|
|
7
12
|
export { default as isEmpty } from './is/empty';
|
|
8
13
|
export { default as isNull } from './is/null';
|
|
9
|
-
export {
|
|
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';
|
|
10
23
|
export { default as connectURLParams } from './url/params';
|
|
24
|
+
export { default as wait } from './wait';
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 处理输入文本中的特殊字符,用于转换正则表达式
|
|
3
|
+
* @param text
|
|
4
|
+
* @param flags 表示输出正则表达式
|
|
5
|
+
*/
|
|
6
|
+
declare function inputRegex(text: string, flags?: string): RegExp;
|
|
7
|
+
/**
|
|
8
|
+
* 处理输入文本中的特殊字符,用于转换正则表达式
|
|
9
|
+
* @param text
|
|
10
|
+
* @param flags 表示输出字符串,该字符串将作为正则表达式的一部分
|
|
11
|
+
*/
|
|
12
|
+
declare function inputRegex(text: string, flags: false): string;
|
|
13
|
+
export default inputRegex;
|
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 {};
|