light-h5-core-lib 2.10.6 → 2.10.7

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.
@@ -5,122 +5,109 @@ exports.StringUtil = void 0;
5
5
  * 字符串工具
6
6
  * @author Aonaufly
7
7
  */
8
- var StringUtil = /** @class */ (function () {
9
- function StringUtil() {
10
- }
8
+ class StringUtil {
11
9
  /**
12
10
  * 字符串的格式化 , 使用 {index = 0}的模式
13
11
  * @param str 源字符串
14
12
  * @param args 填充参数
15
13
  */
16
- StringUtil.format = function (str) {
17
- var args = [];
18
- for (var _i = 1; _i < arguments.length; _i++) {
19
- args[_i - 1] = arguments[_i];
20
- }
14
+ static format(str, ...args) {
21
15
  if (!args || args.length == 0)
22
16
  return str;
23
- for (var i = 0, j = args.length; i < j; i++) {
24
- str = str.replace("{".concat(i, "}"), args[i]);
17
+ for (let i = 0, j = args.length; i < j; i++) {
18
+ str = str.replace(`{${i}}`, args[i]);
25
19
  }
26
20
  return str;
27
- };
21
+ }
28
22
  /**
29
23
  * 字符串的格式化 , 从1开始
30
24
  * @param str 源字符串
31
25
  * @param args 填充参数
32
26
  */
33
- StringUtil.formatWithStart1 = function (str) {
34
- var args = [];
35
- for (var _i = 1; _i < arguments.length; _i++) {
36
- args[_i - 1] = arguments[_i];
37
- }
27
+ static formatWithStart1(str, ...args) {
38
28
  if (!args || args.length == 0)
39
29
  return str;
40
- for (var i = 1, j = args.length; i <= j; i++) {
41
- str = str.replace("{".concat(i, "}"), args[i - 1]);
30
+ for (let i = 1, j = args.length; i <= j; i++) {
31
+ str = str.replace(`{${i}}`, args[i - 1]);
42
32
  }
43
33
  return str;
44
- };
34
+ }
45
35
  /**
46
36
  * 单个替换
47
37
  */
48
- StringUtil.replace = function (text, searchValue, replaceValue, ignoreCase) {
49
- if (ignoreCase === void 0) { ignoreCase = false; }
50
- var flags = ignoreCase ? 'gi' : 'g';
51
- var esc = searchValue.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
38
+ static replace(text, searchValue, replaceValue, ignoreCase = false) {
39
+ const flags = ignoreCase ? 'gi' : 'g';
40
+ const esc = searchValue.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
52
41
  return text.replace(new RegExp(esc, flags), replaceValue);
53
- };
42
+ }
54
43
  /**
55
44
  * 批量替换
56
45
  */
57
- StringUtil.replaceBatch = function (text, map, ignoreCase) {
58
- if (ignoreCase === void 0) { ignoreCase = false; }
46
+ static replaceBatch(text, map, ignoreCase = false) {
59
47
  if (!Object.keys(map).length)
60
48
  return text;
61
- var flags = ignoreCase ? 'gi' : 'g';
62
- var keys = Object.keys(map).sort(function (a, b) { return b.length - a.length; }); // 长优先
63
- var pattern = keys.map(function (k) { return k.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); }).join('|');
64
- return text.replace(new RegExp(pattern, flags), function (m) { var _a; return (_a = map[m]) !== null && _a !== void 0 ? _a : m; });
65
- };
49
+ const flags = ignoreCase ? 'gi' : 'g';
50
+ const keys = Object.keys(map).sort((a, b) => b.length - a.length); // 长优先
51
+ const pattern = keys.map(k => k.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')).join('|');
52
+ return text.replace(new RegExp(pattern, flags), m => map[m] ?? m);
53
+ }
66
54
  /**
67
55
  * 将字符串中所有的\/替换成/
68
56
  */
69
- StringUtil.replaceBackslash = function (input) {
57
+ static replaceBackslash(input) {
70
58
  // 使用正则表达式替换所有的 \\/ 为 /
71
59
  return input.replace(/\\\//g, '/');
72
- };
73
- StringUtil.code2utf8 = function (uni) {
74
- var uni2 = uni.toString(2);
60
+ }
61
+ static code2utf8(uni) {
62
+ let uni2 = uni.toString(2);
75
63
  if (uni < 128) {
76
64
  return uni.toString(16);
77
65
  }
78
66
  else if (uni < 2048) {
79
67
  uni2 = ("00000000000000000" + uni2).slice(-11);
80
- var s1 = parseInt("110" + uni2.substring(0, 5), 2);
81
- var s2 = parseInt("10" + uni2.substring(5), 2);
68
+ const s1 = parseInt("110" + uni2.substring(0, 5), 2);
69
+ const s2 = parseInt("10" + uni2.substring(5), 2);
82
70
  return s1.toString(16) + "," + s2.toString(16);
83
71
  }
84
72
  else {
85
73
  uni2 = ("00000000000000000" + uni2).slice(-16);
86
- var s1 = parseInt("1110" + uni2.substring(0, 4), 2);
87
- var s2 = parseInt("10" + uni2.substring(4, 10), 2);
88
- var s3 = parseInt("10" + uni2.substring(10), 2);
74
+ const s1 = parseInt("1110" + uni2.substring(0, 4), 2);
75
+ const s2 = parseInt("10" + uni2.substring(4, 10), 2);
76
+ const s3 = parseInt("10" + uni2.substring(10), 2);
89
77
  return s1.toString(16) + "," + s2.toString(16) + "," + s3.toString(16);
90
78
  }
91
- };
79
+ }
92
80
  /**
93
81
  * 将字符串转化成UTF8的Buffer
94
82
  * @param str 字符串
95
83
  */
96
- StringUtil.string2UTF8Buffer = function (str) {
97
- var val = "";
98
- for (var i = 0; i < str.length; i++) {
84
+ static string2UTF8Buffer(str) {
85
+ let val = "";
86
+ for (let i = 0; i < str.length; i++) {
99
87
  val += "," + StringUtil.code2utf8(str.charCodeAt(i));
100
88
  }
101
89
  val += ",00";
102
90
  // 将16进制转化为ArrayBuffer
103
- return new Uint8Array(val.match(/[\da-f]{2}/gi).map(function (h) {
91
+ return new Uint8Array(val.match(/[\da-f]{2}/gi).map((h) => {
104
92
  return parseInt(h, 16);
105
93
  })).buffer;
106
- };
107
- // /**
108
- // * 将buffer转化成UTF8
109
- // * @param buffer
110
- // */
111
- // public static buffer2UTF8String(buffer: ArrayBuffer): string {
112
- // const encodedString: string = String.fromCharCode.apply(null, new Uint8Array(buffer));
113
- // // const decodedString: string = decodeURIComponent(escape(atob(encodedString)));
114
- // return encodedString;
115
- // }
116
- /* 将buffer转化成UTF8
117
- * @param buffer
118
- */
119
- StringUtil.buffer2UTF8String = function (buffer) {
120
- var uint8Array = new Uint8Array(buffer);
121
- var data = uint8Array.reduce(function (acc, i) { return (acc += String.fromCharCode.apply(null, [i])); }, "");
122
- return data;
123
- };
124
- return StringUtil;
125
- }());
94
+ }
95
+ }
126
96
  exports.StringUtil = StringUtil;
97
+ // /**
98
+ // * 将buffer转化成UTF8
99
+ // * @param buffer
100
+ // */
101
+ // public static buffer2UTF8String(buffer: ArrayBuffer): string {
102
+ // const encodedString: string = String.fromCharCode.apply(null, new Uint8Array(buffer));
103
+ // // const decodedString: string = decodeURIComponent(escape(atob(encodedString)));
104
+ // return encodedString;
105
+ // }
106
+ /* 将buffer转化成UTF8
107
+ * @param buffer
108
+ */
109
+ StringUtil.buffer2UTF8String = (buffer) => {
110
+ const uint8Array = new Uint8Array(buffer);
111
+ const data = uint8Array.reduce((acc, i) => (acc += String.fromCharCode.apply(null, [i])), "");
112
+ return data;
113
+ };
@@ -5,17 +5,14 @@ exports.UniqueIDUtil = void 0;
5
5
  * 唯一ID生成器
6
6
  * @author Aonaufly
7
7
  */
8
- var UniqueIDUtil = /** @class */ (function () {
9
- function UniqueIDUtil() {
10
- }
8
+ class UniqueIDUtil {
11
9
  /**生成唯一ID值*/
12
- UniqueIDUtil.getUniqueId = function () {
10
+ static getUniqueId() {
13
11
  return new Date().getTime() + Math.random().toString(36).substring(2);
14
- };
12
+ }
15
13
  /**生成复合的Key值*/
16
- UniqueIDUtil.getCompositeKey = function (key, uniqueId) {
17
- return "".concat(key, "-id:").concat(uniqueId);
18
- };
19
- return UniqueIDUtil;
20
- }());
14
+ static getCompositeKey(key, uniqueId) {
15
+ return `${key}-id:${uniqueId}`;
16
+ }
17
+ }
21
18
  exports.UniqueIDUtil = UniqueIDUtil;
package/package.json CHANGED
@@ -1,18 +1,18 @@
1
- {
2
- "name": "light-h5-core-lib",
3
- "version": "2.10.6",
4
- "description": "light core lib",
5
- "main": "./LightCore.js",
6
- "types": "./type/index.d.ts",
7
- "scripts": {
8
- "test": "echo \"Error: no test specified\" && exit 1"
9
- },
10
- "keywords": [
11
- "core",
12
- "h5",
13
- "lib"
14
- ],
15
- "author": "Aonaufly",
16
- "license": "ISC",
17
- "dependencies": {}
18
- }
1
+ {
2
+ "name": "light-h5-core-lib",
3
+ "version": "2.10.7",
4
+ "description": "light core lib",
5
+ "main": "./LightCore.js",
6
+ "types": "./type/index.d.ts",
7
+ "scripts": {
8
+ "test": "echo \"Error: no test specified\" && exit 1"
9
+ },
10
+ "keywords": [
11
+ "core",
12
+ "h5",
13
+ "lib"
14
+ ],
15
+ "author": "Aonaufly",
16
+ "license": "ISC",
17
+ "dependencies": {}
18
+ }
package/pool/PoolObj.js CHANGED
@@ -5,7 +5,7 @@ exports.PoolObj = void 0;
5
5
  * 对象池(泛型)
6
6
  * @author Aonaufly
7
7
  */
8
- var PoolObj = /** @class */ (function () {
8
+ class PoolObj {
9
9
  /**
10
10
  * @param cap 容量(容积) <b style="color:red">小于等于0:无限容量,慎用</b>
11
11
  * @param initCreateNum 初始化创建数量 <b style="color:red">(createCallback != null 有效)</b>
@@ -13,12 +13,7 @@ var PoolObj = /** @class */ (function () {
13
13
  * @param clearCallback Item清理函数
14
14
  * @param destroyCallback Item销毁函数
15
15
  */
16
- function PoolObj(cap, initCreateNum, createCallback, clearCallback, destroyCallback) {
17
- if (cap === void 0) { cap = 5; }
18
- if (initCreateNum === void 0) { initCreateNum = 0; }
19
- if (createCallback === void 0) { createCallback = null; }
20
- if (clearCallback === void 0) { clearCallback = null; }
21
- if (destroyCallback === void 0) { destroyCallback = null; }
16
+ constructor(cap = 5, initCreateNum = 0, createCallback = null, clearCallback = null, destroyCallback = null) {
22
17
  this._cap = cap == null ? 5 : cap;
23
18
  this._createCallback = createCallback;
24
19
  this._clearCallback = clearCallback;
@@ -29,21 +24,21 @@ var PoolObj = /** @class */ (function () {
29
24
  /**
30
25
  * 初始化一些数量的item
31
26
  */
32
- PoolObj.prototype.initCreate = function (initCreateNum) {
27
+ initCreate(initCreateNum) {
33
28
  if (initCreateNum <= 0)
34
29
  return;
35
30
  if (!this._createCallback)
36
31
  return;
37
- var maxNum = this._cap > 0 ? Math.min(this._cap, initCreateNum) : initCreateNum;
38
- for (var i = 0; i < maxNum; i++) {
32
+ const maxNum = this._cap > 0 ? Math.min(this._cap, initCreateNum) : initCreateNum;
33
+ for (let i = 0; i < maxNum; i++) {
39
34
  this._pool.push(this._createCallback());
40
35
  }
41
- };
36
+ }
42
37
  /**
43
38
  * 放入到对象池
44
39
  * @return 放入到对象池是否成功
45
40
  */
46
- PoolObj.prototype.put = function (obj) {
41
+ put(obj) {
47
42
  if (!obj)
48
43
  return false;
49
44
  if (this._cap > 0 && this._pool.length >= this._cap) {
@@ -53,82 +48,63 @@ var PoolObj = /** @class */ (function () {
53
48
  this._clearCallback && this._clearCallback(obj);
54
49
  this._pool.push(obj);
55
50
  return true;
56
- };
51
+ }
57
52
  /**
58
53
  * 获得一个Item<br>
59
54
  * <div style="color: #FF0000;">⚠️友情提示:如果有createCallback需要判断是否是New的item则提前使用 this.size == 0保存句柄</div><br>
60
55
  * <b style="color:#FFFF00">⚠️如果size==0,则自动使用createCallback创建 ,如果size==0 && createCallback==null,则返回null</b>
56
+ * @return { item: T; isCreate: boolean } isCreate: 是否是new出来的
61
57
  */
62
- PoolObj.prototype.one = function () {
58
+ one() {
63
59
  if (this._pool.length == 0) {
64
60
  if (!this._createCallback)
65
61
  return null;
66
- return this._createCallback();
62
+ return { item: this._createCallback(), isCreate: true };
67
63
  }
68
- return this._pool.shift();
69
- };
70
- Object.defineProperty(PoolObj.prototype, "isExistCreateCallback", {
71
- /**
72
- * 是否存在Item创建方法
73
- */
74
- get: function () {
75
- return this._createCallback != null;
76
- },
77
- enumerable: false,
78
- configurable: true
79
- });
80
- Object.defineProperty(PoolObj.prototype, "isExistClearCallback", {
81
- /**
82
- * 是否存在Item的清理函数
83
- */
84
- get: function () {
85
- return this._clearCallback != null;
86
- },
87
- enumerable: false,
88
- configurable: true
89
- });
90
- Object.defineProperty(PoolObj.prototype, "isExistDestroyCallback", {
91
- /**
92
- * 是否存在Item的销毁函数
93
- */
94
- get: function () {
95
- return this._destroyCallback != null;
96
- },
97
- enumerable: false,
98
- configurable: true
99
- });
100
- Object.defineProperty(PoolObj.prototype, "cap", {
101
- /**
102
- * 获取容量(容积)
103
- */
104
- get: function () {
105
- return this._cap;
106
- },
107
- enumerable: false,
108
- configurable: true
109
- });
110
- Object.defineProperty(PoolObj.prototype, "size", {
111
- /**
112
- * 获取当前数量(已经保存的元素个数)
113
- */
114
- get: function () {
115
- if (!this._pool)
116
- return 0;
117
- return this._pool.length;
118
- },
119
- enumerable: false,
120
- configurable: true
121
- });
64
+ return { item: this._pool.shift(), isCreate: true };
65
+ }
66
+ /**
67
+ * 是否存在Item创建方法
68
+ */
69
+ get isExistCreateCallback() {
70
+ return this._createCallback != null;
71
+ }
72
+ /**
73
+ * 是否存在Item的清理函数
74
+ */
75
+ get isExistClearCallback() {
76
+ return this._clearCallback != null;
77
+ }
78
+ /**
79
+ * 是否存在Item的销毁函数
80
+ */
81
+ get isExistDestroyCallback() {
82
+ return this._destroyCallback != null;
83
+ }
84
+ /**
85
+ * 获取容量(容积)
86
+ */
87
+ get cap() {
88
+ return this._cap;
89
+ }
90
+ /**
91
+ * 获取当前数量(已经保存的元素个数)
92
+ */
93
+ get size() {
94
+ if (!this._pool)
95
+ return 0;
96
+ return this._pool.length;
97
+ }
122
98
  /**
123
99
  * 清理对象池
124
100
  */
125
- PoolObj.prototype.clear = function () {
101
+ clear() {
126
102
  if (!this._pool)
127
103
  return;
128
104
  if (this._pool.length == 0)
129
105
  return;
130
- var obj;
131
- for (var i = 0, j = this._pool.length; i < j; i++) {
106
+ let obj;
107
+ for (let i = 0, j = this._pool.length; i < j; i++) {
132
108
  obj = this._pool[i];
133
109
  if (obj) {
134
110
  this._destroyCallback && this._destroyCallback(obj);
@@ -136,8 +112,8 @@ var PoolObj = /** @class */ (function () {
136
112
  }
137
113
  }
138
114
  this._pool.length = 0;
139
- };
140
- PoolObj.prototype.destroy = function (isCleared) {
115
+ }
116
+ destroy(isCleared) {
141
117
  if (!isCleared) {
142
118
  this.clear();
143
119
  }
@@ -145,7 +121,6 @@ var PoolObj = /** @class */ (function () {
145
121
  this._clearCallback = null;
146
122
  this._destroyCallback = null;
147
123
  this._pool && (this._pool = null);
148
- };
149
- return PoolObj;
150
- }());
124
+ }
125
+ }
151
126
  exports.PoolObj = PoolObj;
package/type/index.d.ts CHANGED
@@ -37,8 +37,12 @@ export declare class PoolObj<T> implements IClear {
37
37
  * 获得一个Item<br>
38
38
  * <div style="color: #FF0000;">⚠️友情提示:如果有createCallback需要判断是否是New的item则提前使用 this.size == 0保存句柄</div><br>
39
39
  * <b style="color:#FFFF00">⚠️如果size==0,则自动使用createCallback创建 ,如果size==0 && createCallback==null,则返回null</b>
40
+ * @return { item: T; isCreate: boolean } isCreate: 是否是new出来的
40
41
  */
41
- one(): T;
42
+ one(): {
43
+ item: T;
44
+ isCreate: boolean;
45
+ };
42
46
  /**
43
47
  * 是否存在Item创建方法
44
48
  */
@@ -544,5 +548,17 @@ export declare class GetDecorateUtils {
544
548
  */
545
549
  static setFieldValue<T>(classObj: any, fieldName: string, value: T): boolean;
546
550
  }
551
+ /**
552
+ * Map工具
553
+ * @author Aonaufly
554
+ */
555
+ export declare class MapUtil {
556
+ /**
557
+ * 遍历Map中的所有元素<b style="color:red">每次执行everyCallback</b>
558
+ * @param targetMap 目标Map
559
+ * @param everyCallback 每次的回调
560
+ */
561
+ static all(targetMap: Map<any, any>, everyCallback: (key: any, item: any) => void): void;
562
+ }
547
563
 
548
564
  export {};