light-h5-core-lib 1.0.3 → 2.0.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,16 +1,16 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.BaseSingleton = void 0;
4
- var BaseSingleton = /** @class */ (function () {
5
- function BaseSingleton() {
6
- }
7
- BaseSingleton.getInstance = function (c) {
8
- if (this._instance == null) {
9
- this._instance = new c();
10
- }
11
- return this._instance;
12
- };
13
- BaseSingleton._instance = null;
14
- return BaseSingleton;
15
- }());
16
- exports.BaseSingleton = BaseSingleton;
1
+ 'use strict';
2
+
3
+ var BaseSingleton = /** @class */ (function () {
4
+ function BaseSingleton() {
5
+ }
6
+ BaseSingleton.getInstance = function (c) {
7
+ if (this._instance == null) {
8
+ this._instance = new c();
9
+ }
10
+ return this._instance;
11
+ };
12
+ BaseSingleton._instance = null;
13
+ return BaseSingleton;
14
+ }());
15
+
16
+ exports.BaseSingleton = BaseSingleton;
@@ -1,43 +1,43 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.BitUtil = void 0;
4
- /**
5
- * 位操作工具(从右向左←)
6
- * @author aonaufly
7
- */
8
- var BitUtil = /** @class */ (function () {
9
- function BitUtil() {
10
- }
11
- /**
12
- * 读取uint类型某位的值, bit从1开始
13
- */
14
- BitUtil.getBit = function (value, bit) {
15
- return (value & (1 << (bit - 1))) >> (bit - 1);
16
- };
17
- /**
18
- * 设置value 第bit(从1开始)位的值为v(0|1)
19
- * 谨记bit<32
20
- */
21
- BitUtil.setBit = function (value, bit, v) {
22
- if (bit > 32) {
23
- return undefined;
24
- }
25
- if (v == 1) {
26
- return value | (v << (bit - 1));
27
- }
28
- else {
29
- return (value &= ~0 ^ (1 << (bit - 1)));
30
- }
31
- };
32
- /**获取1的个数 */
33
- BitUtil.get1num = function (value) {
34
- var count = 0;
35
- while (value) {
36
- value = value & (value - 1);
37
- count++;
38
- }
39
- return count;
40
- };
41
- return BitUtil;
42
- }());
43
- exports.BitUtil = BitUtil;
1
+ 'use strict';
2
+
3
+ /**
4
+ * 位操作工具(从右向左←)
5
+ * @author aonaufly
6
+ */
7
+ var BitUtil = /** @class */ (function () {
8
+ function BitUtil() {
9
+ }
10
+ /**
11
+ * 读取uint类型某位的值, bit从1开始
12
+ */
13
+ BitUtil.getBit = function (value, bit) {
14
+ return (value & (1 << (bit - 1))) >> (bit - 1);
15
+ };
16
+ /**
17
+ * 设置value 第bit(从1开始)位的值为v(0|1)
18
+ * 谨记bit<32
19
+ */
20
+ BitUtil.setBit = function (value, bit, v) {
21
+ if (bit > 32) {
22
+ return undefined;
23
+ }
24
+ if (v == 1) {
25
+ return value | (v << (bit - 1));
26
+ }
27
+ else {
28
+ return (value &= ~0 ^ (1 << (bit - 1)));
29
+ }
30
+ };
31
+ /**获取1的个数 */
32
+ BitUtil.get1num = function (value) {
33
+ var count = 0;
34
+ while (value) {
35
+ value = value & (value - 1);
36
+ count++;
37
+ }
38
+ return count;
39
+ };
40
+ return BitUtil;
41
+ }());
42
+
43
+ exports.BitUtil = BitUtil;
@@ -1,89 +1,89 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DateUtil = void 0;
4
- /**
5
- * 日期(时间)工具
6
- * @author aonaufly
7
- */
8
- var DateUtil = /** @class */ (function () {
9
- function DateUtil() {
10
- }
11
- /**
12
- * 获取指定时间的时间戳 (单位:ms)
13
- * @param date 如: "2020-3-14 11:30:30"
14
- */
15
- DateUtil.getTargetTimeStamp = function (date) {
16
- return new Date(date).getTime();
17
- };
18
- /**
19
- * 获取指定时间的时间秒 (单位:s)
20
- * @param date 如: "2020-3-14 11:30:30"
21
- */
22
- DateUtil.getTargetSeconds = function (date) {
23
- return Math.floor(DateUtil.getTargetTimeStamp(date) / 1000);
24
- };
25
- /**
26
- * 格式化时间(时,分,秒)
27
- * @param s
28
- * @param separator 分隔符(default: ":")
29
- * @param isSingle0 是否补0(default:true)
30
- * @param isDiscardH 小时数为0时,是否舍弃显示变成分,秒(default:false)
31
- */
32
- DateUtil.format_HMS = function (s, separator, isSingle0, isDiscardH) {
33
- if (separator === void 0) { separator = ":"; }
34
- if (isSingle0 === void 0) { isSingle0 = true; }
35
- if (isDiscardH === void 0) { isDiscardH = false; }
36
- var h = Math.floor(s / 3600);
37
- if (isDiscardH && h == 0) {
38
- return DateUtil.format_MS(s, separator, isSingle0);
39
- }
40
- var m = Math.floor((s - h * 3600) / 60);
41
- s = s - h * 3600 - m * 60;
42
- var result = isSingle0 ? (h < 10 ? "0".concat(h) : h.toString()) : h.toString();
43
- result += separator;
44
- result = result + (isSingle0 ? (m < 10 ? "0".concat(m) : m.toString()) : m.toString());
45
- result += separator;
46
- result = result + (isSingle0 ? (s < 10 ? "0".concat(s) : s.toString()) : s.toString());
47
- return result;
48
- };
49
- /**
50
- * 格式化时间(分,秒)
51
- * @param s
52
- * @param separator 分隔符(default: ":")
53
- * @param isSingle0 是否补0(default:true)
54
- */
55
- DateUtil.format_MS = function (s, separator, isSingle0) {
56
- if (separator === void 0) { separator = ":"; }
57
- if (isSingle0 === void 0) { isSingle0 = true; }
58
- var m = Math.floor(s / 60);
59
- s = s - m * 60;
60
- var result = isSingle0 ? (m < 10 ? "0".concat(m) : m.toString()) : m.toString();
61
- result += separator;
62
- result = result + (isSingle0 ? (s < 10 ? "0".concat(s) : s.toString()) : s.toString());
63
- return result;
64
- };
65
- /**
66
- * 获取下一天的时间(凌晨)秒 存在1ms误差可以忽略不计
67
- * @param nowSecond 现在的时间秒 ( 服务器的时间(一般))
68
- * @return 下一天的时间Second
69
- * */
70
- DateUtil.getNextDayTimeStamp = function (nowSecond) {
71
- return DateUtil.getTodayAppointTimeStamp(nowSecond, 23, 59, 59, 999);
72
- };
73
- /**
74
- * 获取今日指定的时间秒, 例如今日20:00
75
- * @param nowSecond 现在的时间秒 ( 服务器的时间(一般))
76
- * @param hour 指定的小时数 0~23
77
- * @param minute 指定的分钟数 0~59
78
- * @param second 指定的秒数 0~59
79
- * @param millisecond 指定的毫秒数 0~999
80
- */
81
- DateUtil.getTodayAppointTimeStamp = function (nowSecond, hour, minute, second, millisecond) {
82
- if (minute === void 0) { minute = 0; }
83
- if (second === void 0) { second = 0; }
84
- if (millisecond === void 0) { millisecond = 0; }
85
- return Math.ceil(new Date(new Date(nowSecond * 1000).setHours(hour, minute, second, millisecond)).getTime() / 1000);
86
- };
87
- return DateUtil;
88
- }());
89
- exports.DateUtil = DateUtil;
1
+ 'use strict';
2
+
3
+ /**
4
+ * 日期(时间)工具
5
+ * @author aonaufly
6
+ */
7
+ var DateUtil = /** @class */ (function () {
8
+ function DateUtil() {
9
+ }
10
+ /**
11
+ * 获取指定时间的时间戳 (单位:ms)
12
+ * @param date 如: "2020-3-14 11:30:30"
13
+ */
14
+ DateUtil.getTargetTimeStamp = function (date) {
15
+ return new Date(date).getTime();
16
+ };
17
+ /**
18
+ * 获取指定时间的时间秒 (单位:s)
19
+ * @param date 如: "2020-3-14 11:30:30"
20
+ */
21
+ DateUtil.getTargetSeconds = function (date) {
22
+ return Math.floor(DateUtil.getTargetTimeStamp(date) / 1000);
23
+ };
24
+ /**
25
+ * 格式化时间(时,分,秒)
26
+ * @param s 秒
27
+ * @param separator 分隔符(default: ":")
28
+ * @param isSingle0 是否补0(default:true)
29
+ * @param isDiscardH 小时数为0时,是否舍弃显示变成分,秒(default:false)
30
+ */
31
+ DateUtil.format_HMS = function (s, separator, isSingle0, isDiscardH) {
32
+ if (separator === void 0) { separator = ":"; }
33
+ if (isSingle0 === void 0) { isSingle0 = true; }
34
+ if (isDiscardH === void 0) { isDiscardH = false; }
35
+ var h = Math.floor(s / 3600);
36
+ if (isDiscardH && h == 0) {
37
+ return DateUtil.format_MS(s, separator, isSingle0);
38
+ }
39
+ var m = Math.floor((s - h * 3600) / 60);
40
+ s = s - h * 3600 - m * 60;
41
+ var result = isSingle0 ? (h < 10 ? "0".concat(h) : h.toString()) : h.toString();
42
+ result += separator;
43
+ result = result + (isSingle0 ? (m < 10 ? "0".concat(m) : m.toString()) : m.toString());
44
+ result += separator;
45
+ result = result + (isSingle0 ? (s < 10 ? "0".concat(s) : s.toString()) : s.toString());
46
+ return result;
47
+ };
48
+ /**
49
+ * 格式化时间(分,秒)
50
+ * @param s 秒
51
+ * @param separator 分隔符(default: ":")
52
+ * @param isSingle0 是否补0(default:true)
53
+ */
54
+ DateUtil.format_MS = function (s, separator, isSingle0) {
55
+ if (separator === void 0) { separator = ":"; }
56
+ if (isSingle0 === void 0) { isSingle0 = true; }
57
+ var m = Math.floor(s / 60);
58
+ s = s - m * 60;
59
+ var result = isSingle0 ? (m < 10 ? "0".concat(m) : m.toString()) : m.toString();
60
+ result += separator;
61
+ result = result + (isSingle0 ? (s < 10 ? "0".concat(s) : s.toString()) : s.toString());
62
+ return result;
63
+ };
64
+ /**
65
+ * 获取下一天的时间(凌晨)秒 存在1ms误差可以忽略不计
66
+ * @param nowSecond 现在的时间秒 ( 服务器的时间(一般))
67
+ * @return 下一天的时间Second
68
+ * */
69
+ DateUtil.getNextDayTimeStamp = function (nowSecond) {
70
+ return DateUtil.getTodayAppointTimeStamp(nowSecond, 23, 59, 59, 999);
71
+ };
72
+ /**
73
+ * 获取今日指定的时间秒, 例如今日20:00
74
+ * @param nowSecond 现在的时间秒 ( 服务器的时间(一般))
75
+ * @param hour 指定的小时数 0~23
76
+ * @param minute 指定的分钟数 0~59
77
+ * @param second 指定的秒数 0~59
78
+ * @param millisecond 指定的毫秒数 0~999
79
+ */
80
+ DateUtil.getTodayAppointTimeStamp = function (nowSecond, hour, minute, second, millisecond) {
81
+ if (minute === void 0) { minute = 0; }
82
+ if (second === void 0) { second = 0; }
83
+ if (millisecond === void 0) { millisecond = 0; }
84
+ return Math.ceil(new Date(new Date(nowSecond * 1000).setHours(hour, minute, second, millisecond)).getTime() / 1000);
85
+ };
86
+ return DateUtil;
87
+ }());
88
+
89
+ exports.DateUtil = DateUtil;
@@ -1,22 +1,22 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.FloatDigitUtil = void 0;
4
- /**
5
- * Float精度
6
- * @author aonaufly
7
- */
8
- var FloatDigitUtil = /** @class */ (function () {
9
- function FloatDigitUtil() {
10
- }
11
- /**
12
- * 确定小数的精度<b style="color:red">2个小数相加会有精度错误</b>
13
- * @param fNum 小数
14
- * @param digit 精度
15
- */
16
- FloatDigitUtil.formatFloat = function (fNum, digit) {
17
- var m = Math.pow(10, digit);
18
- return parseInt((fNum * m).toString(), 10) / m;
19
- };
20
- return FloatDigitUtil;
21
- }());
22
- exports.FloatDigitUtil = FloatDigitUtil;
1
+ 'use strict';
2
+
3
+ /**
4
+ * Float精度
5
+ * @author aonaufly
6
+ */
7
+ var FloatDigitUtil = /** @class */ (function () {
8
+ function FloatDigitUtil() {
9
+ }
10
+ /**
11
+ * 确定小数的精度<b style="color:red">2个小数相加会有精度错误</b>
12
+ * @param fNum 小数
13
+ * @param digit 精度
14
+ */
15
+ FloatDigitUtil.formatFloat = function (fNum, digit) {
16
+ var m = Math.pow(10, digit);
17
+ return parseInt((fNum * m).toString(), 10) / m;
18
+ };
19
+ return FloatDigitUtil;
20
+ }());
21
+
22
+ exports.FloatDigitUtil = FloatDigitUtil;
@@ -1,79 +1,79 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PoolObj = void 0;
4
- /**
5
- * 对象池(泛型)
6
- * @author aonaufly
7
- */
8
- var PoolObj = /** @class */ (function () {
9
- /**
10
- * @param cup 容量
11
- */
12
- function PoolObj(cup) {
13
- if (cup === void 0) { cup = 5; }
14
- this._cup = cup;
15
- this._pool = [];
16
- }
17
- PoolObj.prototype.put = function (obj) {
18
- if (!obj || this._pool.length >= this._cup)
19
- return false;
20
- this._pool.push(obj);
21
- return true;
22
- };
23
- PoolObj.prototype.one = function () {
24
- if (this._pool.length == 0)
25
- return null;
26
- return this._pool.shift();
27
- };
28
- Object.defineProperty(PoolObj.prototype, "cup", {
29
- /**
30
- * 获取容量(容积)
31
- */
32
- get: function () {
33
- return this._cup;
34
- },
35
- enumerable: false,
36
- configurable: true
37
- });
38
- Object.defineProperty(PoolObj.prototype, "size", {
39
- /**
40
- * 获取当前数量(已经保存的元素个数)
41
- */
42
- get: function () {
43
- if (!this._pool)
44
- return 0;
45
- return this._pool.length;
46
- },
47
- enumerable: false,
48
- configurable: true
49
- });
50
- /**
51
- * 清理对象池
52
- */
53
- PoolObj.prototype.clear = function () {
54
- if (!this._pool)
55
- return;
56
- if (this._pool.length == 0)
57
- return;
58
- var obj;
59
- for (var i = 0, j = this._pool.length; i < j; i++) {
60
- obj = this._pool[i];
61
- if (obj.destroy) {
62
- obj.destroy();
63
- }
64
- else if (obj.onDestroy) {
65
- obj.onDestroy();
66
- }
67
- obj = null;
68
- }
69
- this._pool.length = 0;
70
- };
71
- PoolObj.prototype.destroy = function (isCleared) {
72
- if (!isCleared) {
73
- this.clear();
74
- }
75
- this._pool && (this._pool = null);
76
- };
77
- return PoolObj;
78
- }());
79
- exports.PoolObj = PoolObj;
1
+ 'use strict';
2
+
3
+ /**
4
+ * 对象池(泛型)
5
+ * @author aonaufly
6
+ */
7
+ var PoolObj = /** @class */ (function () {
8
+ /**
9
+ * @param cup 容量
10
+ */
11
+ function PoolObj(cup) {
12
+ if (cup === void 0) { cup = 5; }
13
+ this._cup = cup;
14
+ this._pool = [];
15
+ }
16
+ PoolObj.prototype.put = function (obj) {
17
+ if (!obj || this._pool.length >= this._cup)
18
+ return false;
19
+ this._pool.push(obj);
20
+ return true;
21
+ };
22
+ PoolObj.prototype.one = function () {
23
+ if (this._pool.length == 0)
24
+ return null;
25
+ return this._pool.shift();
26
+ };
27
+ Object.defineProperty(PoolObj.prototype, "cup", {
28
+ /**
29
+ * 获取容量(容积)
30
+ */
31
+ get: function () {
32
+ return this._cup;
33
+ },
34
+ enumerable: false,
35
+ configurable: true
36
+ });
37
+ Object.defineProperty(PoolObj.prototype, "size", {
38
+ /**
39
+ * 获取当前数量(已经保存的元素个数)
40
+ */
41
+ get: function () {
42
+ if (!this._pool)
43
+ return 0;
44
+ return this._pool.length;
45
+ },
46
+ enumerable: false,
47
+ configurable: true
48
+ });
49
+ /**
50
+ * 清理对象池
51
+ */
52
+ PoolObj.prototype.clear = function () {
53
+ if (!this._pool)
54
+ return;
55
+ if (this._pool.length == 0)
56
+ return;
57
+ var obj;
58
+ for (var i = 0, j = this._pool.length; i < j; i++) {
59
+ obj = this._pool[i];
60
+ if (obj.destroy) {
61
+ obj.destroy();
62
+ }
63
+ else if (obj.onDestroy) {
64
+ obj.onDestroy();
65
+ }
66
+ obj = null;
67
+ }
68
+ this._pool.length = 0;
69
+ };
70
+ PoolObj.prototype.destroy = function (isCleared) {
71
+ if (!isCleared) {
72
+ this.clear();
73
+ }
74
+ this._pool && (this._pool = null);
75
+ };
76
+ return PoolObj;
77
+ }());
78
+
79
+ exports.PoolObj = PoolObj;
@@ -1,40 +1,40 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.RandomNumUtil = void 0;
4
- /**
5
- * 随机数生成工具
6
- * @author aonaufly
7
- */
8
- var RandomNumUtil = /** @class */ (function () {
9
- function RandomNumUtil() {
10
- }
11
- /**
12
- * 获取一定方位的随机整数
13
- *
14
- * <b>( min ≤ r ≤ max )</b>
15
- *
16
- * @param min 最小数
17
- * @param max 最大数
18
- * @param isInt 是否返回整数
19
- */
20
- RandomNumUtil.randomNumBoth = function (min, max, isInt) {
21
- if (isInt === void 0) { isInt = true; }
22
- var Range = max - min;
23
- if (Range > 0.0) {
24
- var Rand = Math.random();
25
- var num = void 0;
26
- if (isInt) {
27
- num = min + Math.round(Rand * Range); //四舍五入
28
- }
29
- else {
30
- num = min + Rand * Range;
31
- }
32
- return num;
33
- }
34
- else {
35
- return isInt ? min : Math.round(min);
36
- }
37
- };
38
- return RandomNumUtil;
39
- }());
40
- exports.RandomNumUtil = RandomNumUtil;
1
+ 'use strict';
2
+
3
+ /**
4
+ * 随机数生成工具
5
+ * @author aonaufly
6
+ */
7
+ var RandomNumUtil = /** @class */ (function () {
8
+ function RandomNumUtil() {
9
+ }
10
+ /**
11
+ * 获取一定方位的随机整数
12
+ *
13
+ * <b>( min ≤ r ≤ max )</b>
14
+ *
15
+ * @param min 最小数
16
+ * @param max 最大数
17
+ * @param isInt 是否返回整数
18
+ */
19
+ RandomNumUtil.randomNumBoth = function (min, max, isInt) {
20
+ if (isInt === void 0) { isInt = true; }
21
+ var Range = max - min;
22
+ if (Range > 0.0) {
23
+ var Rand = Math.random();
24
+ var num = void 0;
25
+ if (isInt) {
26
+ num = min + Math.round(Rand * Range); //四舍五入
27
+ }
28
+ else {
29
+ num = min + Rand * Range;
30
+ }
31
+ return num;
32
+ }
33
+ else {
34
+ return isInt ? min : Math.round(min);
35
+ }
36
+ };
37
+ return RandomNumUtil;
38
+ }());
39
+
40
+ exports.RandomNumUtil = RandomNumUtil;
@@ -1,81 +1,81 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.StringUtil = void 0;
4
- /**
5
- * 字符串工具
6
- * @author aonaufly
7
- */
8
- var StringUtil = /** @class */ (function () {
9
- function StringUtil() {
10
- }
11
- /**
12
- * 字符串的格式化 , 使用 {index = 0}的模式
13
- * @param str 源字符串
14
- * @param args 填充参数
15
- */
16
- StringUtil.format = function (str) {
17
- var args = [];
18
- for (var _i = 1; _i < arguments.length; _i++) {
19
- args[_i - 1] = arguments[_i];
20
- }
21
- if (!args || args.length == 0)
22
- return str;
23
- for (var i = 0, j = args.length; i < j; i++) {
24
- str = str.replace("{".concat(i, "}"), args[i]);
25
- }
26
- return str;
27
- };
28
- StringUtil.code2utf8 = function (uni) {
29
- var uni2 = uni.toString(2);
30
- if (uni < 128) {
31
- return uni.toString(16);
32
- }
33
- else if (uni < 2048) {
34
- uni2 = ("00000000000000000" + uni2).slice(-11);
35
- var s1 = parseInt("110" + uni2.substring(0, 5), 2);
36
- var s2 = parseInt("10" + uni2.substring(5), 2);
37
- return s1.toString(16) + "," + s2.toString(16);
38
- }
39
- else {
40
- uni2 = ("00000000000000000" + uni2).slice(-16);
41
- var s1 = parseInt("1110" + uni2.substring(0, 4), 2);
42
- var s2 = parseInt("10" + uni2.substring(4, 10), 2);
43
- var s3 = parseInt("10" + uni2.substring(10), 2);
44
- return s1.toString(16) + "," + s2.toString(16) + "," + s3.toString(16);
45
- }
46
- };
47
- /**
48
- * 将字符串转化成UTF8的Buffer
49
- * @param str 字符串
50
- */
51
- StringUtil.string2UTF8Buffer = function (str) {
52
- var val = "";
53
- for (var i = 0; i < str.length; i++) {
54
- val += "," + StringUtil.code2utf8(str.charCodeAt(i));
55
- }
56
- val += ",00";
57
- // 将16进制转化为ArrayBuffer
58
- return new Uint8Array(val.match(/[\da-f]{2}/gi).map(function (h) {
59
- return parseInt(h, 16);
60
- })).buffer;
61
- };
62
- // /**
63
- // * buffer转化成UTF8
64
- // * @param buffer
65
- // */
66
- // public static buffer2UTF8String(buffer: ArrayBuffer): string {
67
- // const encodedString: string = String.fromCharCode.apply(null, new Uint8Array(buffer));
68
- // // const decodedString: string = decodeURIComponent(escape(atob(encodedString)));
69
- // return encodedString;
70
- // }
71
- /* buffer转化成UTF8
72
- * @param buffer
73
- */
74
- StringUtil.buffer2UTF8String = function (buffer) {
75
- var uint8Array = new Uint8Array(buffer);
76
- var data = uint8Array.reduce(function (acc, i) { return (acc += String.fromCharCode.apply(null, [i])); }, "");
77
- return data;
78
- };
79
- return StringUtil;
80
- }());
81
- exports.StringUtil = StringUtil;
1
+ 'use strict';
2
+
3
+ /**
4
+ * 字符串工具
5
+ * @author aonaufly
6
+ */
7
+ var StringUtil = /** @class */ (function () {
8
+ function StringUtil() {
9
+ }
10
+ /**
11
+ * 字符串的格式化 , 使用 {index = 0}的模式
12
+ * @param str 源字符串
13
+ * @param args 填充参数
14
+ */
15
+ StringUtil.format = function (str) {
16
+ var args = [];
17
+ for (var _i = 1; _i < arguments.length; _i++) {
18
+ args[_i - 1] = arguments[_i];
19
+ }
20
+ if (!args || args.length == 0)
21
+ return str;
22
+ for (var i = 0, j = args.length; i < j; i++) {
23
+ str = str.replace("{".concat(i, "}"), args[i]);
24
+ }
25
+ return str;
26
+ };
27
+ StringUtil.code2utf8 = function (uni) {
28
+ var uni2 = uni.toString(2);
29
+ if (uni < 128) {
30
+ return uni.toString(16);
31
+ }
32
+ else if (uni < 2048) {
33
+ uni2 = ("00000000000000000" + uni2).slice(-11);
34
+ var s1 = parseInt("110" + uni2.substring(0, 5), 2);
35
+ var s2 = parseInt("10" + uni2.substring(5), 2);
36
+ return s1.toString(16) + "," + s2.toString(16);
37
+ }
38
+ else {
39
+ uni2 = ("00000000000000000" + uni2).slice(-16);
40
+ var s1 = parseInt("1110" + uni2.substring(0, 4), 2);
41
+ var s2 = parseInt("10" + uni2.substring(4, 10), 2);
42
+ var s3 = parseInt("10" + uni2.substring(10), 2);
43
+ return s1.toString(16) + "," + s2.toString(16) + "," + s3.toString(16);
44
+ }
45
+ };
46
+ /**
47
+ * 将字符串转化成UTF8的Buffer
48
+ * @param str 字符串
49
+ */
50
+ StringUtil.string2UTF8Buffer = function (str) {
51
+ var val = "";
52
+ for (var i = 0; i < str.length; i++) {
53
+ val += "," + StringUtil.code2utf8(str.charCodeAt(i));
54
+ }
55
+ val += ",00";
56
+ // 将16进制转化为ArrayBuffer
57
+ return new Uint8Array(val.match(/[\da-f]{2}/gi).map(function (h) {
58
+ return parseInt(h, 16);
59
+ })).buffer;
60
+ };
61
+ // /**
62
+ // * 将buffer转化成UTF8
63
+ // * @param buffer
64
+ // */
65
+ // public static buffer2UTF8String(buffer: ArrayBuffer): string {
66
+ // const encodedString: string = String.fromCharCode.apply(null, new Uint8Array(buffer));
67
+ // // const decodedString: string = decodeURIComponent(escape(atob(encodedString)));
68
+ // return encodedString;
69
+ // }
70
+ /* 将buffer转化成UTF8
71
+ * @param buffer
72
+ */
73
+ StringUtil.buffer2UTF8String = function (buffer) {
74
+ var uint8Array = new Uint8Array(buffer);
75
+ var data = uint8Array.reduce(function (acc, i) { return (acc += String.fromCharCode.apply(null, [i])); }, "");
76
+ return data;
77
+ };
78
+ return StringUtil;
79
+ }());
80
+
81
+ exports.StringUtil = StringUtil;
package/package.json CHANGED
@@ -1,10 +1,16 @@
1
1
  {
2
2
  "name": "light-h5-core-lib",
3
- "version": "1.0.3",
4
- "description": "",
5
- "main": "./lib/Main.js",
6
- "directories": {
7
- "lib": "lib"
3
+ "version": "2.0.0",
4
+ "types": "./type/index.d.ts",
5
+ "description": "light core lib",
6
+ "exports": {
7
+ "./PoolObj": "./PoolObj.js",
8
+ "./BaseSingleton": "./BaseSingleton.js",
9
+ "./BitUtil": "./BitUtil.js",
10
+ "./DateUtil": "./DateUtil.js",
11
+ "./FloatDigitUtil": "./FloatDigitUtil.js",
12
+ "./RandomNumUtil": "./RandomNumUtil.js",
13
+ "./StringUtil": "./StringUtil.js"
8
14
  },
9
15
  "scripts": {
10
16
  "test": "echo \"Error: no test specified\" && exit 1"
@@ -0,0 +1,158 @@
1
+ export interface IDestroy {
2
+ destroy(): void;
3
+ }
4
+ export interface IClear extends IDestroy {
5
+ clear(): void;
6
+ }
7
+ export declare class BaseSingleton<T> {
8
+ private static _instance;
9
+ static getInstance<T>(c: { new (): T }): T;
10
+ }
11
+ /**
12
+ * 对象池(泛型)
13
+ * @author aonaufly
14
+ */
15
+ export declare class PoolObj<T> implements IClear {
16
+ private _pool;
17
+ private _cup;
18
+ /**
19
+ * @param cup 容量
20
+ */
21
+ constructor(cup?: number);
22
+ put(obj: T): boolean;
23
+ one(): T;
24
+ /**
25
+ * 获取容量(容积)
26
+ */
27
+ get cup(): number;
28
+ /**
29
+ * 获取当前数量(已经保存的元素个数)
30
+ */
31
+ get size(): number;
32
+ /**
33
+ * 清理对象池
34
+ */
35
+ clear(): void;
36
+ destroy(isCleared?: boolean): void;
37
+ }
38
+ /**
39
+ * 位操作工具(从右向左←)
40
+ * @author aonaufly
41
+ */
42
+ export declare class BitUtil {
43
+ /**
44
+ * 读取uint类型某位的值, bit从1开始
45
+ */
46
+ static getBit(value: number, bit: number): number;
47
+ /**
48
+ * 设置value 第bit(从1开始)位的值为v(0|1)
49
+ * 谨记bit<32
50
+ */
51
+ static setBit(value: number, bit: number, v: 0 | 1): number;
52
+ /**获取1的个数 */
53
+ static get1num(value: number): number;
54
+ }
55
+ /**
56
+ * 日期(时间)工具
57
+ * @author aonaufly
58
+ */
59
+ export declare class DateUtil {
60
+ /**
61
+ * 获取指定时间的时间戳 (单位:ms)
62
+ * @param date 如: "2020-3-14 11:30:30"
63
+ */
64
+ static getTargetTimeStamp(date: string): number;
65
+ /**
66
+ * 获取指定时间的时间秒 (单位:s)
67
+ * @param date 如: "2020-3-14 11:30:30"
68
+ */
69
+ static getTargetSeconds(date: string): number;
70
+ /**
71
+ * 格式化时间(时,分,秒)
72
+ * @param s 秒
73
+ * @param separator 分隔符(default: ":")
74
+ * @param isSingle0 是否补0(default:true)
75
+ * @param isDiscardH 小时数为0时,是否舍弃显示变成分,秒(default:false)
76
+ */
77
+ static format_HMS(
78
+ s: number,
79
+ separator?: string,
80
+ isSingle0?: boolean,
81
+ isDiscardH?: boolean
82
+ ): string;
83
+ /**
84
+ * 格式化时间(分,秒)
85
+ * @param s 秒
86
+ * @param separator 分隔符(default: ":")
87
+ * @param isSingle0 是否补0(default:true)
88
+ */
89
+ static format_MS(s: number, separator?: string, isSingle0?: boolean): string;
90
+ /**
91
+ * 获取下一天的时间(凌晨)秒 存在1ms误差可以忽略不计
92
+ * @param nowSecond 现在的时间秒 ( 服务器的时间(一般))
93
+ * @return 下一天的时间Second
94
+ * */
95
+ static getNextDayTimeStamp(nowSecond: number): number;
96
+ /**
97
+ * 获取今日指定的时间秒, 例如今日20:00
98
+ * @param nowSecond 现在的时间秒 ( 服务器的时间(一般))
99
+ * @param hour 指定的小时数 0~23
100
+ * @param minute 指定的分钟数 0~59
101
+ * @param second 指定的秒数 0~59
102
+ * @param millisecond 指定的毫秒数 0~999
103
+ */
104
+ static getTodayAppointTimeStamp(
105
+ nowSecond: number,
106
+ hour: number,
107
+ minute?: number,
108
+ second?: number,
109
+ millisecond?: number
110
+ ): number;
111
+ }
112
+ /**
113
+ * Float精度
114
+ * @author aonaufly
115
+ */
116
+ export declare class FloatDigitUtil {
117
+ /**
118
+ * 确定小数的精度<b style="color:red">2个小数相加会有精度错误</b>
119
+ * @param fNum 小数
120
+ * @param digit 精度
121
+ */
122
+ static formatFloat(fNum: number, digit: number): number;
123
+ }
124
+ /**
125
+ * 随机数生成工具
126
+ * @author aonaufly
127
+ */
128
+ export declare class RandomNumUtil {
129
+ /**
130
+ * 获取一定方位的随机整数
131
+ *
132
+ * <b>( min ≤ r ≤ max )</b>
133
+ *
134
+ * @param min 最小数
135
+ * @param max 最大数
136
+ * @param isInt 是否返回整数
137
+ */
138
+ static randomNumBoth(min: number, max: number, isInt?: boolean): number;
139
+ }
140
+ /**
141
+ * 字符串工具
142
+ * @author aonaufly
143
+ */
144
+ export declare class StringUtil {
145
+ /**
146
+ * 字符串的格式化 , 使用 {index = 0}的模式
147
+ * @param str 源字符串
148
+ * @param args 填充参数
149
+ */
150
+ static format(str: string, ...args: Array<any>): string;
151
+ private static code2utf8;
152
+ /**
153
+ * 将字符串转化成UTF8的Buffer
154
+ * @param str 字符串
155
+ */
156
+ static string2UTF8Buffer(str: string): ArrayBuffer;
157
+ static buffer2UTF8String: (buffer: ArrayBuffer) => string;
158
+ }
package/lib/Main.d.ts DELETED
@@ -1,18 +0,0 @@
1
- import { BaseSingleton } from "./common/base/BaseSingleton";
2
- import { BitUtil } from "./common/util/BitUtil";
3
- import { DateUtil } from "./common/util/DateUtil";
4
- import { FloatDigitUtil } from "./common/util/FloatDigitUtil";
5
- import { RandomNumUtil } from "./common/util/RandomNumUtil";
6
- import { StringUtil } from "./common/util/StringUtil";
7
- import { PoolObj } from "./pool/PoolObj";
8
- export declare class Main {
9
- core: {
10
- BaseSingleton: typeof BaseSingleton;
11
- PoolObj: typeof PoolObj;
12
- StringUtil: typeof StringUtil;
13
- BitUtil: typeof BitUtil;
14
- DateUtil: typeof DateUtil;
15
- FloatDigitUtil: typeof FloatDigitUtil;
16
- RandomNumUtil: typeof RandomNumUtil;
17
- };
18
- }
package/lib/Main.js DELETED
@@ -1,25 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Main = void 0;
4
- var BaseSingleton_1 = require("./common/base/BaseSingleton");
5
- var BitUtil_1 = require("./common/util/BitUtil");
6
- var DateUtil_1 = require("./common/util/DateUtil");
7
- var FloatDigitUtil_1 = require("./common/util/FloatDigitUtil");
8
- var RandomNumUtil_1 = require("./common/util/RandomNumUtil");
9
- var StringUtil_1 = require("./common/util/StringUtil");
10
- var PoolObj_1 = require("./pool/PoolObj");
11
- var Main = /** @class */ (function () {
12
- function Main() {
13
- this.core = {
14
- BaseSingleton: BaseSingleton_1.BaseSingleton,
15
- PoolObj: PoolObj_1.PoolObj,
16
- StringUtil: StringUtil_1.StringUtil,
17
- BitUtil: BitUtil_1.BitUtil,
18
- DateUtil: DateUtil_1.DateUtil,
19
- FloatDigitUtil: FloatDigitUtil_1.FloatDigitUtil,
20
- RandomNumUtil: RandomNumUtil_1.RandomNumUtil,
21
- };
22
- }
23
- return Main;
24
- }());
25
- exports.Main = Main;
@@ -1,6 +0,0 @@
1
- export declare class BaseSingleton<T> {
2
- private static _instance;
3
- static getInstance<T>(c: {
4
- new (): T;
5
- }): T;
6
- }
@@ -1,4 +0,0 @@
1
- import { IDestroy } from "./IDestroy";
2
- export interface IClear extends IDestroy {
3
- clear(): void;
4
- }
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,3 +0,0 @@
1
- export interface IDestroy {
2
- destroy(): void;
3
- }
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,17 +0,0 @@
1
- /**
2
- * 位操作工具(从右向左←)
3
- * @author aonaufly
4
- */
5
- export declare class BitUtil {
6
- /**
7
- * 读取uint类型某位的值, bit从1开始
8
- */
9
- static getBit(value: number, bit: number): number;
10
- /**
11
- * 设置value 第bit(从1开始)位的值为v(0|1)
12
- * 谨记bit<32
13
- */
14
- static setBit(value: number, bit: number, v: 0 | 1): number;
15
- /**获取1的个数 */
16
- static get1num(value: number): number;
17
- }
@@ -1,46 +0,0 @@
1
- /**
2
- * 日期(时间)工具
3
- * @author aonaufly
4
- */
5
- export declare class DateUtil {
6
- /**
7
- * 获取指定时间的时间戳 (单位:ms)
8
- * @param date 如: "2020-3-14 11:30:30"
9
- */
10
- static getTargetTimeStamp(date: string): number;
11
- /**
12
- * 获取指定时间的时间秒 (单位:s)
13
- * @param date 如: "2020-3-14 11:30:30"
14
- */
15
- static getTargetSeconds(date: string): number;
16
- /**
17
- * 格式化时间(时,分,秒)
18
- * @param s 秒
19
- * @param separator 分隔符(default: ":")
20
- * @param isSingle0 是否补0(default:true)
21
- * @param isDiscardH 小时数为0时,是否舍弃显示变成分,秒(default:false)
22
- */
23
- static format_HMS(s: number, separator?: string, isSingle0?: boolean, isDiscardH?: boolean): string;
24
- /**
25
- * 格式化时间(分,秒)
26
- * @param s 秒
27
- * @param separator 分隔符(default: ":")
28
- * @param isSingle0 是否补0(default:true)
29
- */
30
- static format_MS(s: number, separator?: string, isSingle0?: boolean): string;
31
- /**
32
- * 获取下一天的时间(凌晨)秒 存在1ms误差可以忽略不计
33
- * @param nowSecond 现在的时间秒 ( 服务器的时间(一般))
34
- * @return 下一天的时间Second
35
- * */
36
- static getNextDayTimeStamp(nowSecond: number): number;
37
- /**
38
- * 获取今日指定的时间秒, 例如今日20:00
39
- * @param nowSecond 现在的时间秒 ( 服务器的时间(一般))
40
- * @param hour 指定的小时数 0~23
41
- * @param minute 指定的分钟数 0~59
42
- * @param second 指定的秒数 0~59
43
- * @param millisecond 指定的毫秒数 0~999
44
- */
45
- static getTodayAppointTimeStamp(nowSecond: number, hour: number, minute?: number, second?: number, millisecond?: number): number;
46
- }
@@ -1,12 +0,0 @@
1
- /**
2
- * Float精度
3
- * @author aonaufly
4
- */
5
- export declare class FloatDigitUtil {
6
- /**
7
- * 确定小数的精度<b style="color:red">2个小数相加会有精度错误</b>
8
- * @param fNum 小数
9
- * @param digit 精度
10
- */
11
- static formatFloat(fNum: number, digit: number): number;
12
- }
@@ -1,16 +0,0 @@
1
- /**
2
- * 随机数生成工具
3
- * @author aonaufly
4
- */
5
- export declare class RandomNumUtil {
6
- /**
7
- * 获取一定方位的随机整数
8
- *
9
- * <b>( min ≤ r ≤ max )</b>
10
- *
11
- * @param min 最小数
12
- * @param max 最大数
13
- * @param isInt 是否返回整数
14
- */
15
- static randomNumBoth(min: number, max: number, isInt?: boolean): number;
16
- }
@@ -1,19 +0,0 @@
1
- /**
2
- * 字符串工具
3
- * @author aonaufly
4
- */
5
- export declare class StringUtil {
6
- /**
7
- * 字符串的格式化 , 使用 {index = 0}的模式
8
- * @param str 源字符串
9
- * @param args 填充参数
10
- */
11
- static format(str: string, ...args: Array<any>): string;
12
- private static code2utf8;
13
- /**
14
- * 将字符串转化成UTF8的Buffer
15
- * @param str 字符串
16
- */
17
- static string2UTF8Buffer(str: string): ArrayBuffer;
18
- static buffer2UTF8String: (buffer: ArrayBuffer) => string;
19
- }
@@ -1,28 +0,0 @@
1
- import { IClear } from "../common/base/IClear";
2
- /**
3
- * 对象池(泛型)
4
- * @author aonaufly
5
- */
6
- export declare class PoolObj<T> implements IClear {
7
- private _pool;
8
- private _cup;
9
- /**
10
- * @param cup 容量
11
- */
12
- constructor(cup?: number);
13
- put(obj: T): boolean;
14
- one(): T;
15
- /**
16
- * 获取容量(容积)
17
- */
18
- get cup(): number;
19
- /**
20
- * 获取当前数量(已经保存的元素个数)
21
- */
22
- get size(): number;
23
- /**
24
- * 清理对象池
25
- */
26
- clear(): void;
27
- destroy(isCleared?: boolean): void;
28
- }