light-h5-core-lib 2.8.0 → 2.8.1
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/LightCore.js +8 -2
- package/common/base/BaseSingleton.js +6 -0
- package/common/md5/MD5.js +7 -0
- package/common/util/BitUtil.js +1 -1
- package/common/util/BooleanUtil.js +23 -0
- package/common/util/DateUtil.js +27 -0
- package/common/util/FloatDigitUtil.js +41 -0
- package/common/util/NumberUtil.js +23 -0
- package/common/util/PromiseUtil.js +2 -2
- package/common/util/RandomNumUtil.js +38 -0
- package/common/util/StringUtil.js +7 -0
- package/package.json +1 -1
- package/pool/PoolObj.js +1 -1
- package/type/index.d.ts +69 -3
package/LightCore.js
CHANGED
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.Crc32Util = exports.PromiseUtil = exports.BeizerUtil = exports.UniqueIDUtil = exports.StringUtil = exports.RandomNumUtil = exports.FloatDigitUtil = exports.DateUtil = exports.BitUtil = exports.MD5 = exports.BaseSingleton = exports.PoolObj = void 0;
|
|
6
|
+
exports.NumberUtil = exports.BooleanUtil = exports.Crc32Util = exports.PromiseUtil = exports.BeizerUtil = exports.UniqueIDUtil = exports.StringUtil = exports.RandomNumUtil = exports.FloatDigitUtil = exports.DateUtil = exports.BitUtil = exports.MD5 = exports.BaseSingleton = exports.PoolObj = void 0;
|
|
7
7
|
var PoolObj_1 = require("./pool/PoolObj");
|
|
8
8
|
Object.defineProperty(exports, "PoolObj", { enumerable: true, get: function () { return PoolObj_1.PoolObj; } });
|
|
9
9
|
var BaseSingleton_1 = require("./common/base/BaseSingleton");
|
|
@@ -28,6 +28,10 @@ var PromiseUtil_1 = __importDefault(require("./common/util/PromiseUtil"));
|
|
|
28
28
|
exports.PromiseUtil = PromiseUtil_1.default;
|
|
29
29
|
var Crc32Util_1 = __importDefault(require("./common/util/Crc32Util"));
|
|
30
30
|
exports.Crc32Util = Crc32Util_1.default;
|
|
31
|
+
var BooleanUtil_1 = require("./common/util/BooleanUtil");
|
|
32
|
+
Object.defineProperty(exports, "BooleanUtil", { enumerable: true, get: function () { return BooleanUtil_1.BooleanUtil; } });
|
|
33
|
+
var NumberUtil_1 = require("./common/util/NumberUtil");
|
|
34
|
+
Object.defineProperty(exports, "NumberUtil", { enumerable: true, get: function () { return NumberUtil_1.NumberUtil; } });
|
|
31
35
|
module.exports = {
|
|
32
36
|
PoolObj: PoolObj_1.PoolObj,
|
|
33
37
|
BaseSingleton: BaseSingleton_1.BaseSingleton,
|
|
@@ -40,5 +44,7 @@ module.exports = {
|
|
|
40
44
|
UniqueIDUtil: UniqueIDUtil_1.UniqueIDUtil,
|
|
41
45
|
BeizerUtil: BeizerUtil_1.BeizerUtil,
|
|
42
46
|
PromiseUtil: PromiseUtil_1.default,
|
|
43
|
-
Crc32Util: Crc32Util_1.default
|
|
47
|
+
Crc32Util: Crc32Util_1.default,
|
|
48
|
+
BooleanUtil: BooleanUtil_1.BooleanUtil,
|
|
49
|
+
NumberUtil: NumberUtil_1.NumberUtil,
|
|
44
50
|
};
|
|
@@ -11,9 +11,15 @@ var BaseSingleton = /** @class */ (function () {
|
|
|
11
11
|
BaseSingleton.getInstance = function (c) {
|
|
12
12
|
if (this._instance == null) {
|
|
13
13
|
this._instance = new c();
|
|
14
|
+
this._instance.ctor();
|
|
14
15
|
}
|
|
15
16
|
return this._instance;
|
|
16
17
|
};
|
|
18
|
+
/**
|
|
19
|
+
* 相当于构造函数
|
|
20
|
+
*/
|
|
21
|
+
BaseSingleton.prototype.ctor = function () {
|
|
22
|
+
};
|
|
17
23
|
BaseSingleton.prototype.destroy = function () {
|
|
18
24
|
BaseSingleton._instance = null;
|
|
19
25
|
};
|
package/common/md5/MD5.js
CHANGED
|
@@ -341,6 +341,13 @@ var MD5 = /** @class */ (function (_super) {
|
|
|
341
341
|
MD5.prototype.bit_rol = function (num, cnt) {
|
|
342
342
|
return (num << cnt) | (num >>> (32 - cnt));
|
|
343
343
|
};
|
|
344
|
+
MD5.prototype.selfDecrypt = function (data, secretKey) {
|
|
345
|
+
var info = "";
|
|
346
|
+
for (var i = 0, j = data.length; i < j; i++) {
|
|
347
|
+
info += String.fromCharCode(data.charCodeAt(i) ^ (secretKey[i % secretKey.length]).charCodeAt(0));
|
|
348
|
+
}
|
|
349
|
+
return info;
|
|
350
|
+
};
|
|
344
351
|
return MD5;
|
|
345
352
|
}(BaseSingleton_1.BaseSingleton));
|
|
346
353
|
exports.MD5 = MD5;
|
package/common/util/BitUtil.js
CHANGED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BooleanUtil = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Bool类型处理
|
|
6
|
+
* @author Aonaufly
|
|
7
|
+
*/
|
|
8
|
+
var BooleanUtil = /** @class */ (function () {
|
|
9
|
+
function BooleanUtil() {
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* 获得Proto中的Bool值
|
|
13
|
+
*/
|
|
14
|
+
BooleanUtil.getProtoBool = function (data, key, defaultValue) {
|
|
15
|
+
if (defaultValue === void 0) { defaultValue = false; }
|
|
16
|
+
if (key in data) {
|
|
17
|
+
return data[key];
|
|
18
|
+
}
|
|
19
|
+
return defaultValue;
|
|
20
|
+
};
|
|
21
|
+
return BooleanUtil;
|
|
22
|
+
}());
|
|
23
|
+
exports.BooleanUtil = BooleanUtil;
|
package/common/util/DateUtil.js
CHANGED
|
@@ -84,6 +84,33 @@ var DateUtil = /** @class */ (function () {
|
|
|
84
84
|
if (millisecond === void 0) { millisecond = 0; }
|
|
85
85
|
return Math.ceil(new Date(new Date(nowSecond * 1000).setHours(hour, minute, second, millisecond)).getTime() / 1000);
|
|
86
86
|
};
|
|
87
|
+
/**
|
|
88
|
+
* 获得剩余的过期时间秒(S)用于倒计时
|
|
89
|
+
* @param targetExpireSecond 过期的时间戳(s)
|
|
90
|
+
* @param curSecond 当前时间戳(s)
|
|
91
|
+
* @param offsetSecond 误差值(s) (targetExpireSecond + offsetSecond)用于延长/缩短一些过期时间
|
|
92
|
+
*/
|
|
93
|
+
DateUtil.getRemainingSecond = function (targetExpireSecond, curSecond, offsetSecond) {
|
|
94
|
+
if (curSecond === void 0) { curSecond = null; }
|
|
95
|
+
if (offsetSecond === void 0) { offsetSecond = 1; }
|
|
96
|
+
if (curSecond == null) {
|
|
97
|
+
curSecond = Math.floor(Date.now() / 1000);
|
|
98
|
+
}
|
|
99
|
+
return targetExpireSecond + offsetSecond - curSecond;
|
|
100
|
+
};
|
|
101
|
+
/**
|
|
102
|
+
* 获得过期的时间戳(S)
|
|
103
|
+
* @param durationSecond 过期的时间倒计时(s)
|
|
104
|
+
* @param curSecond 当前的时间(s)
|
|
105
|
+
* @return 过期的时间戳(s)
|
|
106
|
+
*/
|
|
107
|
+
DateUtil.getExpireSecond = function (durationSecond, curSecond) {
|
|
108
|
+
if (curSecond === void 0) { curSecond = null; }
|
|
109
|
+
if (curSecond == null) {
|
|
110
|
+
curSecond = Math.floor(Date.now() / 1000);
|
|
111
|
+
}
|
|
112
|
+
return curSecond + durationSecond;
|
|
113
|
+
};
|
|
87
114
|
return DateUtil;
|
|
88
115
|
}());
|
|
89
116
|
exports.DateUtil = DateUtil;
|
|
@@ -17,6 +17,47 @@ var FloatDigitUtil = /** @class */ (function () {
|
|
|
17
17
|
var m = Math.pow(10, digit);
|
|
18
18
|
return parseInt((fNum * m).toString(), 10) / m;
|
|
19
19
|
};
|
|
20
|
+
//#region 小数格式化
|
|
21
|
+
/**
|
|
22
|
+
* 小数的格式化
|
|
23
|
+
*/
|
|
24
|
+
FloatDigitUtil.formatDecimalNumber = function (num, factor, isRound) {
|
|
25
|
+
if (isRound === void 0) { isRound = true; }
|
|
26
|
+
if (factor <= 0) {
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
var factorX = Math.pow(10, factor);
|
|
30
|
+
var value;
|
|
31
|
+
if (isRound) {
|
|
32
|
+
value = Math.round(num * factorX) / factorX;
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
value = Math.trunc(num * factorX) / factorX;
|
|
36
|
+
}
|
|
37
|
+
return value;
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* 小数的格式化
|
|
41
|
+
*/
|
|
42
|
+
FloatDigitUtil.formatDecimalString = function (num, factor, isRound, isSupplementZero) {
|
|
43
|
+
if (isRound === void 0) { isRound = true; }
|
|
44
|
+
if (isSupplementZero === void 0) { isSupplementZero = true; }
|
|
45
|
+
if (factor <= 0) {
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
var factorX = Math.pow(10, factor);
|
|
49
|
+
var value;
|
|
50
|
+
if (isRound) {
|
|
51
|
+
value = Math.round(num * factorX) / factorX;
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
value = Math.trunc(num * factorX) / factorX;
|
|
55
|
+
}
|
|
56
|
+
if (isSupplementZero) {
|
|
57
|
+
return value.toFixed(factor);
|
|
58
|
+
}
|
|
59
|
+
return "".concat(value);
|
|
60
|
+
};
|
|
20
61
|
return FloatDigitUtil;
|
|
21
62
|
}());
|
|
22
63
|
exports.FloatDigitUtil = FloatDigitUtil;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NumberUtil = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* 数值类型处理
|
|
6
|
+
* @author Aonaufly
|
|
7
|
+
*/
|
|
8
|
+
var NumberUtil = /** @class */ (function () {
|
|
9
|
+
function NumberUtil() {
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* 获得Proto中的数字
|
|
13
|
+
*/
|
|
14
|
+
NumberUtil.getProtoNum = function (data, key, defaultValue) {
|
|
15
|
+
if (defaultValue === void 0) { defaultValue = 0; }
|
|
16
|
+
if (key in data) {
|
|
17
|
+
return data[key];
|
|
18
|
+
}
|
|
19
|
+
return defaultValue;
|
|
20
|
+
};
|
|
21
|
+
return NumberUtil;
|
|
22
|
+
}());
|
|
23
|
+
exports.NumberUtil = NumberUtil;
|
|
@@ -9,8 +9,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
-
return g =
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
13
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
14
|
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
15
|
function step(op) {
|
|
16
16
|
if (f) throw new TypeError("Generator is already executing.");
|
|
@@ -49,6 +49,44 @@ var RandomNumUtil = /** @class */ (function () {
|
|
|
49
49
|
arr[n] = temp;
|
|
50
50
|
}
|
|
51
51
|
};
|
|
52
|
+
/**
|
|
53
|
+
* 获得偏振系数
|
|
54
|
+
* @param factor 偏振因子(>0)
|
|
55
|
+
* @param negativeIntRadio 负数的比率(> 0的整数)
|
|
56
|
+
* @param positiveIntRadio 正数的比率 (>0的整数)
|
|
57
|
+
* @return -factor 或者factor
|
|
58
|
+
*/
|
|
59
|
+
RandomNumUtil.getPolarizationFactor = function (factor, negativeIntRadio, positiveIntRadio) {
|
|
60
|
+
if (factor === void 0) { factor = 1; }
|
|
61
|
+
if (negativeIntRadio === void 0) { negativeIntRadio = 1; }
|
|
62
|
+
if (positiveIntRadio === void 0) { positiveIntRadio = 1; }
|
|
63
|
+
var r = RandomNumUtil.randomNumWithRadio(0, 1, [negativeIntRadio, positiveIntRadio]);
|
|
64
|
+
if (r == 0)
|
|
65
|
+
return -1 * factor;
|
|
66
|
+
return r * factor;
|
|
67
|
+
};
|
|
68
|
+
/**
|
|
69
|
+
* 按照比率获得随机数(对于整数)
|
|
70
|
+
* @param min 最小数
|
|
71
|
+
* @param max 最大数
|
|
72
|
+
* @param radioArr 比率
|
|
73
|
+
*/
|
|
74
|
+
RandomNumUtil.randomNumWithRadio = function (min, max, radioArr) {
|
|
75
|
+
var total = 0;
|
|
76
|
+
var i;
|
|
77
|
+
for (i = 0; i < radioArr.length; i++) {
|
|
78
|
+
total += radioArr[i];
|
|
79
|
+
}
|
|
80
|
+
var r = RandomNumUtil.randomNumBoth(1, total, true);
|
|
81
|
+
var target = 0;
|
|
82
|
+
for (i = 0; i < radioArr.length; i++) {
|
|
83
|
+
target += radioArr[i];
|
|
84
|
+
if (r <= target) {
|
|
85
|
+
return i + min;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
return max;
|
|
89
|
+
};
|
|
52
90
|
return RandomNumUtil;
|
|
53
91
|
}());
|
|
54
92
|
exports.RandomNumUtil = RandomNumUtil;
|
|
@@ -25,6 +25,13 @@ var StringUtil = /** @class */ (function () {
|
|
|
25
25
|
}
|
|
26
26
|
return str;
|
|
27
27
|
};
|
|
28
|
+
/**
|
|
29
|
+
* 将字符串中所有的\/替换成/
|
|
30
|
+
*/
|
|
31
|
+
StringUtil.replaceBackslash = function (input) {
|
|
32
|
+
// 使用正则表达式替换所有的 \\/ 为 /
|
|
33
|
+
return input.replace(/\\\//g, '/');
|
|
34
|
+
};
|
|
28
35
|
StringUtil.code2utf8 = function (uni) {
|
|
29
36
|
var uni2 = uni.toString(2);
|
|
30
37
|
if (uni < 128) {
|
package/package.json
CHANGED
package/pool/PoolObj.js
CHANGED
package/type/index.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ export interface IClear extends IDestroy {
|
|
|
8
8
|
}
|
|
9
9
|
/**
|
|
10
10
|
* 对象池(泛型)
|
|
11
|
-
* @author
|
|
11
|
+
* @author Aonaufly
|
|
12
12
|
*/
|
|
13
13
|
export declare class PoolObj<T> implements IClear {
|
|
14
14
|
private _pool;
|
|
@@ -42,11 +42,15 @@ export declare abstract class BaseSingleton<T> implements IDestroy {
|
|
|
42
42
|
static getInstance<T>(c: {
|
|
43
43
|
new (): T;
|
|
44
44
|
}): T;
|
|
45
|
+
/**
|
|
46
|
+
* 相当于构造函数
|
|
47
|
+
*/
|
|
48
|
+
protected ctor(): void;
|
|
45
49
|
destroy(): void;
|
|
46
50
|
}
|
|
47
51
|
/**
|
|
48
52
|
* 位操作工具(从右向左←)
|
|
49
|
-
* @author
|
|
53
|
+
* @author Aonaufly
|
|
50
54
|
*/
|
|
51
55
|
export declare class BitUtil {
|
|
52
56
|
/**
|
|
@@ -106,6 +110,20 @@ export declare class DateUtil {
|
|
|
106
110
|
* @param millisecond 指定的毫秒数 0~999
|
|
107
111
|
*/
|
|
108
112
|
static getTodayAppointTimeStamp(nowSecond: number, hour: number, minute?: number, second?: number, millisecond?: number): number;
|
|
113
|
+
/**
|
|
114
|
+
* 获得剩余的过期时间秒(S)用于倒计时
|
|
115
|
+
* @param targetExpireSecond 过期的时间戳(s)
|
|
116
|
+
* @param curSecond 当前时间戳(s)
|
|
117
|
+
* @param offsetSecond 误差值(s) (targetExpireSecond + offsetSecond)用于延长/缩短一些过期时间
|
|
118
|
+
*/
|
|
119
|
+
static getRemainingSecond(targetExpireSecond: number, curSecond?: number, offsetSecond?: number): number;
|
|
120
|
+
/**
|
|
121
|
+
* 获得过期的时间戳(S)
|
|
122
|
+
* @param durationSecond 过期的时间倒计时(s)
|
|
123
|
+
* @param curSecond 当前的时间(s)
|
|
124
|
+
* @return 过期的时间戳(s)
|
|
125
|
+
*/
|
|
126
|
+
static getExpireSecond(durationSecond: number, curSecond?: number): number;
|
|
109
127
|
}
|
|
110
128
|
/**
|
|
111
129
|
* Float精度
|
|
@@ -118,6 +136,14 @@ export declare class FloatDigitUtil {
|
|
|
118
136
|
* @param digit 精度
|
|
119
137
|
*/
|
|
120
138
|
static formatFloat(fNum: number, digit: number): number;
|
|
139
|
+
/**
|
|
140
|
+
* 小数的格式化
|
|
141
|
+
*/
|
|
142
|
+
static formatDecimalNumber(num: number, factor: number, isRound?: boolean): number;
|
|
143
|
+
/**
|
|
144
|
+
* 小数的格式化
|
|
145
|
+
*/
|
|
146
|
+
static formatDecimalString(num: number, factor: number, isRound?: boolean, isSupplementZero?: boolean): string;
|
|
121
147
|
}
|
|
122
148
|
/**
|
|
123
149
|
* 随机数生成工具
|
|
@@ -138,6 +164,21 @@ export declare class RandomNumUtil {
|
|
|
138
164
|
* 打乱数组
|
|
139
165
|
*/
|
|
140
166
|
static shuffleSort<T>(arr: T[]): void;
|
|
167
|
+
/**
|
|
168
|
+
* 获得偏振系数
|
|
169
|
+
* @param factor 偏振因子(>0)
|
|
170
|
+
* @param negativeIntRadio 负数的比率(> 0的整数)
|
|
171
|
+
* @param positiveIntRadio 正数的比率 (>0的整数)
|
|
172
|
+
* @return -factor 或者factor
|
|
173
|
+
*/
|
|
174
|
+
static getPolarizationFactor(factor?: number, negativeIntRadio?: number, positiveIntRadio?: number): number;
|
|
175
|
+
/**
|
|
176
|
+
* 按照比率获得随机数(对于整数)
|
|
177
|
+
* @param min 最小数
|
|
178
|
+
* @param max 最大数
|
|
179
|
+
* @param radioArr 比率
|
|
180
|
+
*/
|
|
181
|
+
static randomNumWithRadio(min: number, max: number, radioArr: number[]): number;
|
|
141
182
|
}
|
|
142
183
|
/**
|
|
143
184
|
* 字符串工具
|
|
@@ -149,7 +190,11 @@ export declare class StringUtil {
|
|
|
149
190
|
* @param str 源字符串
|
|
150
191
|
* @param args 填充参数
|
|
151
192
|
*/
|
|
152
|
-
static format(str: string, ...args:
|
|
193
|
+
static format(str: string, ...args: any): string;
|
|
194
|
+
/**
|
|
195
|
+
* 将字符串中所有的\/替换成/
|
|
196
|
+
*/
|
|
197
|
+
static replaceBackslash(input: string): string;
|
|
153
198
|
private static code2utf8;
|
|
154
199
|
/**
|
|
155
200
|
* 将字符串转化成UTF8的Buffer
|
|
@@ -227,6 +272,7 @@ export declare class MD5 extends BaseSingleton<MD5> {
|
|
|
227
272
|
md5_ii(a: any, b: any, c: any, d: any, x: any, s: any, t: any): number;
|
|
228
273
|
safe_add(x: any, y: any): number;
|
|
229
274
|
bit_rol(num: any, cnt: any): number;
|
|
275
|
+
selfDecrypt(data: string, secretKey: string): string;
|
|
230
276
|
}
|
|
231
277
|
/**
|
|
232
278
|
* 异步处理工具
|
|
@@ -253,5 +299,25 @@ export declare class Crc32Util {
|
|
|
253
299
|
*/
|
|
254
300
|
static getCrc32String(str: string, crc?: number): string;
|
|
255
301
|
}
|
|
302
|
+
/**
|
|
303
|
+
* Bool类型处理
|
|
304
|
+
* @author Aonaufly
|
|
305
|
+
*/
|
|
306
|
+
export declare class BooleanUtil {
|
|
307
|
+
/**
|
|
308
|
+
* 获得Proto中的Bool值
|
|
309
|
+
*/
|
|
310
|
+
static getProtoBool(data: any, key: string, defaultValue?: boolean): boolean;
|
|
311
|
+
}
|
|
312
|
+
/**
|
|
313
|
+
* 数值类型处理
|
|
314
|
+
* @author Aonaufly
|
|
315
|
+
*/
|
|
316
|
+
export declare class NumberUtil {
|
|
317
|
+
/**
|
|
318
|
+
* 获得Proto中的数字
|
|
319
|
+
*/
|
|
320
|
+
static getProtoNum(data: any, key: string, defaultValue?: number): number;
|
|
321
|
+
}
|
|
256
322
|
|
|
257
323
|
export {};
|