badmfck-api-server 1.7.4 → 1.7.5
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/apiServer/helper/UID.d.ts +14 -0
- package/dist/apiServer/helper/UID.js +73 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.js +3 -1
- package/package.json +1 -1
@@ -0,0 +1,14 @@
|
|
1
|
+
export declare class UID {
|
2
|
+
private static readonly epoch;
|
3
|
+
private static nextUniqueID;
|
4
|
+
private static nextUniqueTRXID;
|
5
|
+
static generate(): string;
|
6
|
+
static generateRandomNumberBase(count: number): string;
|
7
|
+
static generateNumberic(year?: string): number;
|
8
|
+
static getNextDescendingIndex(): number;
|
9
|
+
static getNext(): string;
|
10
|
+
static getNextTRX(): string;
|
11
|
+
static generateTrxUID(date?: Date): number;
|
12
|
+
static sha256(str: string): string;
|
13
|
+
static leadZero(i: number): string;
|
14
|
+
}
|
@@ -0,0 +1,73 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
+
};
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
+
exports.UID = void 0;
|
7
|
+
const crypto_1 = __importDefault(require("crypto"));
|
8
|
+
class UID {
|
9
|
+
static epoch = 1697037922668;
|
10
|
+
static nextUniqueID = 1;
|
11
|
+
static nextUniqueTRXID = 1;
|
12
|
+
static generate() {
|
13
|
+
let uid = Buffer.from(parseInt(((+new Date()) - this.epoch)
|
14
|
+
+ ""
|
15
|
+
+ Math.round(Math.random() * 1000)).toString(16), 'hex').toString('base64');
|
16
|
+
uid = uid.replaceAll("=", "");
|
17
|
+
uid = uid.replaceAll("+", ".");
|
18
|
+
uid = uid.replaceAll("/", "-");
|
19
|
+
return uid;
|
20
|
+
}
|
21
|
+
static generateRandomNumberBase(count) {
|
22
|
+
let base = "";
|
23
|
+
for (let i = 0; i < count; i++)
|
24
|
+
base += Math.round(Math.random() * 9);
|
25
|
+
return base;
|
26
|
+
}
|
27
|
+
static generateNumberic(year) {
|
28
|
+
if (!year)
|
29
|
+
year = new Date().getFullYear() + "";
|
30
|
+
const nextID = UID.nextUniqueID++;
|
31
|
+
if (UID.nextUniqueID > 99)
|
32
|
+
UID.nextUniqueID = 1;
|
33
|
+
return parseInt(year.substring(2) + "" + (+new Date() - this.epoch) + "" + (nextID + "").padStart(2, "0"));
|
34
|
+
}
|
35
|
+
static getNextDescendingIndex() {
|
36
|
+
return Number.MAX_SAFE_INTEGER - (+new Date());
|
37
|
+
}
|
38
|
+
static getNext() {
|
39
|
+
const nextID = UID.nextUniqueID++;
|
40
|
+
if (UID.nextUniqueID > 99)
|
41
|
+
UID.nextUniqueID = 1;
|
42
|
+
return this.leadZero(nextID);
|
43
|
+
}
|
44
|
+
static getNextTRX() {
|
45
|
+
const nextID = UID.nextUniqueTRXID++;
|
46
|
+
if (UID.nextUniqueTRXID > 99)
|
47
|
+
UID.nextUniqueTRXID = 1;
|
48
|
+
return this.leadZero(nextID);
|
49
|
+
}
|
50
|
+
static generateTrxUID(date) {
|
51
|
+
if (!date)
|
52
|
+
date = new Date();
|
53
|
+
const year = (new Date().getFullYear() + "").substring(2);
|
54
|
+
const seconds = (date.getHours() * 3600 + date.getMinutes() * 60 + date.getSeconds()) + "";
|
55
|
+
const str = year
|
56
|
+
+ this.leadZero(date.getMonth() + 1)
|
57
|
+
+ this.leadZero(date.getDate())
|
58
|
+
+ seconds.padStart(5, "0")
|
59
|
+
+ this.getNextTRX();
|
60
|
+
return parseInt(str);
|
61
|
+
}
|
62
|
+
static sha256(str) {
|
63
|
+
let uid = crypto_1.default.createHash("sha256").update(str).digest("base64");
|
64
|
+
uid = uid.replaceAll("=", "");
|
65
|
+
uid = uid.replaceAll("+", ".");
|
66
|
+
uid = uid.replaceAll("/", "-");
|
67
|
+
return uid;
|
68
|
+
}
|
69
|
+
static leadZero(i) {
|
70
|
+
return (i + "").padStart(2, "0");
|
71
|
+
}
|
72
|
+
}
|
73
|
+
exports.UID = UID;
|
package/dist/index.d.ts
CHANGED
@@ -6,4 +6,5 @@ import { LogService } from "./apiServer/LogService";
|
|
6
6
|
import { ErrorUtils } from "./apiServer/structures/DefaultErrors";
|
7
7
|
import { S_MONITOR_REGISTRATE_ACTION } from "./apiServer/monitor/Monitor";
|
8
8
|
import { DataProvider } from "./apiServer/helper/DataProvider";
|
9
|
-
|
9
|
+
import { UID } from "./apiServer/helper/UID";
|
10
|
+
export { UID, APIService, Initializer, LocalRequest, MysqlService, Validator, LogService, DataProvider, ErrorUtils, S_MONITOR_REGISTRATE_ACTION };
|
package/dist/index.js
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.S_MONITOR_REGISTRATE_ACTION = exports.ErrorUtils = exports.DataProvider = exports.LogService = exports.Validator = exports.MysqlService = exports.LocalRequest = exports.Initializer = exports.APIService = void 0;
|
3
|
+
exports.S_MONITOR_REGISTRATE_ACTION = exports.ErrorUtils = exports.DataProvider = exports.LogService = exports.Validator = exports.MysqlService = exports.LocalRequest = exports.Initializer = exports.APIService = exports.UID = void 0;
|
4
4
|
const APIService_1 = require("./apiServer/APIService");
|
5
5
|
Object.defineProperty(exports, "APIService", { enumerable: true, get: function () { return APIService_1.APIService; } });
|
6
6
|
Object.defineProperty(exports, "Initializer", { enumerable: true, get: function () { return APIService_1.Initializer; } });
|
@@ -18,3 +18,5 @@ const Monitor_1 = require("./apiServer/monitor/Monitor");
|
|
18
18
|
Object.defineProperty(exports, "S_MONITOR_REGISTRATE_ACTION", { enumerable: true, get: function () { return Monitor_1.S_MONITOR_REGISTRATE_ACTION; } });
|
19
19
|
const DataProvider_1 = require("./apiServer/helper/DataProvider");
|
20
20
|
Object.defineProperty(exports, "DataProvider", { enumerable: true, get: function () { return DataProvider_1.DataProvider; } });
|
21
|
+
const UID_1 = require("./apiServer/helper/UID");
|
22
|
+
Object.defineProperty(exports, "UID", { enumerable: true, get: function () { return UID_1.UID; } });
|