light-h5-core-lib 2.8.2 → 2.9.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.
@@ -1,31 +0,0 @@
1
- /**
2
- * 解码
3
- * @author Aonaufly
4
- */
5
- export class SelfDecrypt {
6
- private static b64Decode(b64: string): Uint8Array {
7
- // 浏览器安全解码,自动补 =
8
- const s: string = b64.replace(/[^A-Za-z0-9+/]/g, '');
9
- const bin: string = atob(s);
10
- return new Uint8Array(bin.length).map((_, i) => bin.charCodeAt(i));
11
- }
12
-
13
- private static b64Encode(bytes: Uint8Array): string {
14
- const bin: string = String.fromCharCode(...bytes);
15
- return btoa(bin);
16
- }
17
-
18
- private static xorBytes(bytes: Uint8Array, key: string): Uint8Array {
19
- const k: Uint8Array = new TextEncoder().encode(key);
20
- return bytes.map((b, i) => b ^ k[i % k.length]);
21
- }
22
-
23
- /**
24
- * 解码
25
- */
26
- public static decryptBase64(b64: string, key: string): string {
27
- const cipher: Uint8Array = SelfDecrypt.b64Decode(b64);
28
- const plain: Uint8Array = SelfDecrypt.xorBytes(cipher, key);
29
- return new TextDecoder().decode(plain);
30
- }
31
- }
@@ -1,83 +0,0 @@
1
- /**
2
- * 字符串工具
3
- * @author aonaufly
4
- */
5
- export class StringUtil {
6
- /**
7
- * 字符串的格式化 , 使用 {index = 0}的模式
8
- * @param str 源字符串
9
- * @param args 填充参数
10
- */
11
- public static format(str: string, ...args: any): string {
12
- if (!args || args.length == 0) return str;
13
- for (let i: number = 0, j: number = args.length; i < j; i++) {
14
- str = str.replace(`{${i}}`, args[i]);
15
- }
16
- return str;
17
- }
18
-
19
- /**
20
- * 将字符串中所有的\/替换成/
21
- */
22
- public static replaceBackslash(input: string): string {
23
- // 使用正则表达式替换所有的 \\/ 为 /
24
- return input.replace(/\\\//g, '/');
25
- }
26
-
27
- private static code2utf8(uni: number): string {
28
- let uni2: string = uni.toString(2);
29
- if (uni < 128) {
30
- return uni.toString(16);
31
- } else if (uni < 2048) {
32
- uni2 = ("00000000000000000" + uni2).slice(-11);
33
- const s1 = parseInt("110" + uni2.substring(0, 5), 2);
34
- const s2 = parseInt("10" + uni2.substring(5), 2);
35
- return s1.toString(16) + "," + s2.toString(16);
36
- } else {
37
- uni2 = ("00000000000000000" + uni2).slice(-16);
38
- const s1 = parseInt("1110" + uni2.substring(0, 4), 2);
39
- const s2 = parseInt("10" + uni2.substring(4, 10), 2);
40
- const s3 = parseInt("10" + uni2.substring(10), 2);
41
- return s1.toString(16) + "," + s2.toString(16) + "," + s3.toString(16);
42
- }
43
- }
44
-
45
- /**
46
- * 将字符串转化成UTF8的Buffer
47
- * @param str 字符串
48
- */
49
- public static string2UTF8Buffer(str: string): ArrayBuffer {
50
- let val: string = "";
51
- for (let i: number = 0; i < str.length; i++) {
52
- val += "," + StringUtil.code2utf8(str.charCodeAt(i));
53
- }
54
- val += ",00";
55
- // 将16进制转化为ArrayBuffer
56
- return new Uint8Array(
57
- val.match(/[\da-f]{2}/gi).map((h) => {
58
- return parseInt(h, 16);
59
- })
60
- ).buffer;
61
- }
62
-
63
- // /**
64
- // * 将buffer转化成UTF8
65
- // * @param buffer
66
- // */
67
- // public static buffer2UTF8String(buffer: ArrayBuffer): string {
68
- // const encodedString: string = String.fromCharCode.apply(null, new Uint8Array(buffer));
69
- // // const decodedString: string = decodeURIComponent(escape(atob(encodedString)));
70
- // return encodedString;
71
- // }
72
- /* 将buffer转化成UTF8
73
- * @param buffer
74
- */
75
- public static buffer2UTF8String = (buffer: ArrayBuffer) => {
76
- const uint8Array = new Uint8Array(buffer);
77
- const data = uint8Array.reduce(
78
- (acc, i) => (acc += String.fromCharCode.apply(null, [i])),
79
- ""
80
- );
81
- return data;
82
- };
83
- }
@@ -1,14 +0,0 @@
1
- /**
2
- * 唯一ID生成器
3
- * @author Aonaufly
4
- */
5
- export class UniqueIDUtil {
6
- /**生成唯一ID值*/
7
- public static getUniqueId(): string {
8
- return new Date().getTime() + Math.random().toString(36).substring(2);
9
- }
10
- /**生成复合的Key值*/
11
- public static getCompositeKey(key: string | number, uniqueId: string): string {
12
- return `${key}-id:${uniqueId}`;
13
- }
14
- }
package/pool/PoolObj.ts DELETED
@@ -1,69 +0,0 @@
1
- import { IClear } from "../common/base/IClear";
2
-
3
- /**
4
- * 对象池(泛型)
5
- * @author Aonaufly
6
- */
7
- export class PoolObj<T> implements IClear {
8
- private _pool: T[];
9
- private _cap: number;
10
- /**
11
- * @param cap 容量(容积)
12
- */
13
- public constructor(cap: number = 5) {
14
- this._cap = cap;
15
- this._pool = [];
16
- }
17
-
18
- public put(obj: T): boolean {
19
- if (!obj || this._pool.length >= this._cap) return false;
20
- this._pool.push(obj);
21
- return true;
22
- }
23
-
24
- public one(): T {
25
- if (this._pool.length == 0) return null;
26
- return this._pool.shift();
27
- }
28
-
29
- /**
30
- * 获取容量(容积)
31
- */
32
- public get cap(): number {
33
- return this._cap;
34
- }
35
-
36
- /**
37
- * 获取当前数量(已经保存的元素个数)
38
- */
39
- public get size(): number {
40
- if (!this._pool) return 0;
41
- return this._pool.length;
42
- }
43
-
44
- /**
45
- * 清理对象池
46
- */
47
- public clear(): void {
48
- if (!this._pool) return;
49
- if (this._pool.length == 0) return;
50
- let obj: any;
51
- for (let i: number = 0, j: number = this._pool.length; i < j; i++) {
52
- obj = this._pool[i];
53
- if (obj.destroy) {
54
- obj.destroy();
55
- } else if (obj.onDestroy) {
56
- obj.onDestroy();
57
- }
58
- obj = null;
59
- }
60
- this._pool.length = 0;
61
- }
62
-
63
- public destroy(isCleared?: boolean): void {
64
- if (!isCleared) {
65
- this.clear();
66
- }
67
- this._pool && (this._pool = null);
68
- }
69
- }