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.
- package/LightCore.js +56 -0
- package/common/base/BaseSingleton.js +29 -0
- package/common/base/IClear.js +2 -0
- package/common/base/IDestroy.js +2 -0
- package/common/md5/{MD5.ts → MD5.js} +346 -376
- package/common/util/BeizerUtil.js +83 -0
- package/common/util/{BitUtil.ts → BitUtil.js} +43 -37
- package/common/util/BooleanUtil.js +23 -0
- package/common/util/CollisionDetectionUtil.js +310 -0
- package/common/util/Crc32Util.js +35 -0
- package/common/util/{DateUtil.ts → DateUtil.js} +116 -120
- package/common/util/FloatDigitUtil.js +63 -0
- package/common/util/NumberUtil.js +23 -0
- package/common/util/PromiseUtil.js +74 -0
- package/common/util/{RandomNumUtil.ts → RandomNumUtil.js} +92 -81
- package/common/util/SelfDecrypt.js +38 -0
- package/common/util/StringUtil.js +126 -0
- package/common/util/UniqueIDUtil.js +21 -0
- package/package.json +1 -1
- package/pool/PoolObj.js +79 -0
- package/type/index.d.ts +94 -0
- package/LightCore.ts +0 -49
- package/common/base/BaseSingleton.ts +0 -28
- package/common/base/IClear.ts +0 -5
- package/common/base/IDestroy.ts +0 -3
- package/common/util/BeizerUtil.ts +0 -87
- package/common/util/BooleanUtil.ts +0 -15
- package/common/util/Crc32Util.ts +0 -30
- package/common/util/FloatDigitUtil.ts +0 -55
- package/common/util/NumberUtil.ts +0 -15
- package/common/util/PromiseUtil.ts +0 -25
- package/common/util/SelfDecrypt.ts +0 -31
- package/common/util/StringUtil.ts +0 -83
- package/common/util/UniqueIDUtil.ts +0 -14
- package/pool/PoolObj.ts +0 -69
|
@@ -1,120 +1,116 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
*
|
|
27
|
-
* @param
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
result
|
|
43
|
-
result
|
|
44
|
-
result
|
|
45
|
-
result
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* 格式化时间(分,秒)
|
|
51
|
-
* @param s 秒
|
|
52
|
-
* @param separator 分隔符(default: ":")
|
|
53
|
-
* @param isSingle0 是否补0(default:true)
|
|
54
|
-
*/
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
result =
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
*
|
|
67
|
-
* @
|
|
68
|
-
*
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
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
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
second
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
}
|
|
118
|
-
return curSecond + durationSecond;
|
|
119
|
-
}
|
|
120
|
-
}
|
|
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
|
+
/**
|
|
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
|
+
};
|
|
114
|
+
return DateUtil;
|
|
115
|
+
}());
|
|
116
|
+
exports.DateUtil = DateUtil;
|
|
@@ -0,0 +1,63 @@
|
|
|
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
|
+
//#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
|
+
};
|
|
61
|
+
return FloatDigitUtil;
|
|
62
|
+
}());
|
|
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;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
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 = 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
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
/**
|
|
40
|
+
* 异步处理工具
|
|
41
|
+
* @author Aonaufly
|
|
42
|
+
*/
|
|
43
|
+
var PromiseUtil = /** @class */ (function () {
|
|
44
|
+
function PromiseUtil() {
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* 执行所有异步并返回数据
|
|
48
|
+
*/
|
|
49
|
+
PromiseUtil.all = function (promiseArr) {
|
|
50
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
51
|
+
return __generator(this, function (_a) {
|
|
52
|
+
return [2 /*return*/, new Promise(function (resolve, reject) {
|
|
53
|
+
var promises = Array.from(promiseArr);
|
|
54
|
+
var r = [];
|
|
55
|
+
var len = promises.length;
|
|
56
|
+
var count = 0;
|
|
57
|
+
var _loop_1 = function (i) {
|
|
58
|
+
Promise.resolve(promises[i]).then(function (o) {
|
|
59
|
+
r[i] = o;
|
|
60
|
+
if (++count === len) {
|
|
61
|
+
resolve(r);
|
|
62
|
+
}
|
|
63
|
+
}).catch(function (e) { return reject(e); });
|
|
64
|
+
};
|
|
65
|
+
for (var i = 0; i < len; i++) {
|
|
66
|
+
_loop_1(i);
|
|
67
|
+
}
|
|
68
|
+
})];
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
};
|
|
72
|
+
return PromiseUtil;
|
|
73
|
+
}());
|
|
74
|
+
exports.default = PromiseUtil;
|
|
@@ -1,81 +1,92 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
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
|
+
/**
|
|
39
|
+
* 打乱数组
|
|
40
|
+
*/
|
|
41
|
+
RandomNumUtil.shuffleSort = function (arr) {
|
|
42
|
+
var n = arr.length;
|
|
43
|
+
var index;
|
|
44
|
+
var temp;
|
|
45
|
+
while (n--) {
|
|
46
|
+
index = Math.floor(Math.random() * n);
|
|
47
|
+
temp = arr[index];
|
|
48
|
+
arr[index] = arr[n];
|
|
49
|
+
arr[n] = temp;
|
|
50
|
+
}
|
|
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
|
+
};
|
|
90
|
+
return RandomNumUtil;
|
|
91
|
+
}());
|
|
92
|
+
exports.RandomNumUtil = RandomNumUtil;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SelfDecrypt = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* 解码
|
|
6
|
+
* @author Aonaufly
|
|
7
|
+
*/
|
|
8
|
+
var SelfDecrypt = /** @class */ (function () {
|
|
9
|
+
function SelfDecrypt() {
|
|
10
|
+
}
|
|
11
|
+
SelfDecrypt.b64Decode = function (b64) {
|
|
12
|
+
// 浏览器安全解码,自动补 =
|
|
13
|
+
var s = b64.replace(/[^A-Za-z0-9+/]/g, '');
|
|
14
|
+
var bin = atob(s);
|
|
15
|
+
return new Uint8Array(bin.length).map(function (_, i) { return bin.charCodeAt(i); });
|
|
16
|
+
};
|
|
17
|
+
SelfDecrypt.b64Encode = function (bytes) {
|
|
18
|
+
var bin = '';
|
|
19
|
+
for (var i = 0; i < bytes.length; i++) {
|
|
20
|
+
bin += String.fromCharCode(bytes[i]);
|
|
21
|
+
}
|
|
22
|
+
return btoa(bin);
|
|
23
|
+
};
|
|
24
|
+
SelfDecrypt.xorBytes = function (bytes, key) {
|
|
25
|
+
var k = new TextEncoder().encode(key);
|
|
26
|
+
return bytes.map(function (b, i) { return b ^ k[i % k.length]; });
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* 解码
|
|
30
|
+
*/
|
|
31
|
+
SelfDecrypt.decryptBase64 = function (b64, key) {
|
|
32
|
+
var cipher = SelfDecrypt.b64Decode(b64);
|
|
33
|
+
var plain = SelfDecrypt.xorBytes(cipher, key);
|
|
34
|
+
return new TextDecoder().decode(plain);
|
|
35
|
+
};
|
|
36
|
+
return SelfDecrypt;
|
|
37
|
+
}());
|
|
38
|
+
exports.SelfDecrypt = SelfDecrypt;
|