mybase 1.1.19 → 1.1.21
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/package.json +4 -3
- package/ts/funcs/Geoip2Paths.js +1 -0
- package/ts/funcs/MaxRuntimeHours.d.ts +1 -0
- package/ts/funcs/MaxRuntimeHours.js +11 -0
- package/ts/funcs/MaxRuntimeHours.ts +7 -0
- package/ts/funcs/asJSON.js +1 -0
- package/ts/funcs/fileCacheIsValid.js +1 -0
- package/ts/funcs/getMysql1.js +26 -36
- package/ts/funcs/getMysql2.d.ts +2 -1
- package/ts/funcs/getMysql2.js +26 -36
- package/ts/funcs/getMysql2.ts +2 -2
- package/ts/funcs/hash_sha512.js +1 -0
- package/ts/funcs/initMysql2Pool.js +1 -0
- package/ts/funcs/int2ip.js +1 -0
- package/ts/funcs/ip2int.js +1 -0
- package/ts/funcs/isLANIp.js +1 -0
- package/ts/funcs/isLocal.js +1 -0
- package/ts/funcs/isLoopbackIP.js +1 -0
- package/ts/funcs/promiseTimeout.js +1 -0
- package/ts/funcs/randomIP.js +1 -0
- package/ts/funcs/randomIP6.js +1 -0
- package/ts/funcs/randomString.js +1 -0
- package/ts/funcs/randomTCPPort.js +46 -58
- package/ts/funcs/randomTCPPort.ts +0 -1
- package/ts/funcs/randomUTFString.js +1 -0
- package/ts/funcs/utcnow.js +1 -0
- package/ts/funcs/validEmail.js +1 -0
- package/ts/funcs/validIp.js +1 -0
- package/ts/funcs/vaultFill.js +23 -33
- package/ts/funcs/vaultRead.js +1 -0
- package/ts/funcs/wait.js +1 -0
- package/ts/global.js +1 -0
- package/ts/index.d.ts +1 -0
- package/ts/index.js +5 -0
- package/ts/index.ts +8 -1
- package/ts/models/Timespan.js +52 -0
- package/ts/models/Timespan.ts +66 -0
- package/ts/models/Unixtime.js +120 -0
- package/ts/models/Unixtime.test.ts +98 -0
- package/ts/models/Unixtime.ts +144 -0
- package/ts/types.js +1 -0
- package/tsconfig.json +30 -109
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Timespan = void 0;
|
|
4
|
+
class Timespan {
|
|
5
|
+
constructor(ms) {
|
|
6
|
+
this.ms = ms;
|
|
7
|
+
}
|
|
8
|
+
get miliseconds() {
|
|
9
|
+
return this.ms;
|
|
10
|
+
}
|
|
11
|
+
get seconds() {
|
|
12
|
+
return this.ms / 1000;
|
|
13
|
+
}
|
|
14
|
+
get minutes() {
|
|
15
|
+
return this.ms / 1000 / 60;
|
|
16
|
+
}
|
|
17
|
+
get hours() {
|
|
18
|
+
return this.ms / 1000 / 60 / 60;
|
|
19
|
+
}
|
|
20
|
+
get days() {
|
|
21
|
+
return this.ms / 1000 / 60 / 60 / 24;
|
|
22
|
+
}
|
|
23
|
+
get weeks() {
|
|
24
|
+
return this.ms / 1000 / 60 / 60 / 24 / 7;
|
|
25
|
+
}
|
|
26
|
+
get months() {
|
|
27
|
+
return this.ms / 1000 / 60 / 60 / 24 / 30;
|
|
28
|
+
}
|
|
29
|
+
static miliseconds(amount) {
|
|
30
|
+
return new Timespan(amount);
|
|
31
|
+
}
|
|
32
|
+
static seconds(amount) {
|
|
33
|
+
return new Timespan(amount * 1000);
|
|
34
|
+
}
|
|
35
|
+
static minutes(mins) {
|
|
36
|
+
return new Timespan(mins * 60 * 1000);
|
|
37
|
+
}
|
|
38
|
+
static hours(hours) {
|
|
39
|
+
return new Timespan(hours * 60 * 60 * 1000);
|
|
40
|
+
}
|
|
41
|
+
static days(days) {
|
|
42
|
+
return new Timespan(days * 24 * 60 * 60 * 1000);
|
|
43
|
+
}
|
|
44
|
+
static weeks(weeks) {
|
|
45
|
+
return new Timespan(weeks * 7 * 24 * 60 * 60 * 1000);
|
|
46
|
+
}
|
|
47
|
+
static months(months) {
|
|
48
|
+
return new Timespan(months * 30 * 24 * 60 * 60 * 1000);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
exports.Timespan = Timespan;
|
|
52
|
+
//# sourceMappingURL=Timespan.js.map
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
export class Timespan {
|
|
5
|
+
constructor(private readonly ms: number){
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
get miliseconds() : number {
|
|
9
|
+
return this.ms
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
get seconds() : number {
|
|
13
|
+
return this.ms / 1000
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
get minutes() : number {
|
|
17
|
+
return this.ms / 1000 / 60
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
get hours() : number {
|
|
21
|
+
return this.ms / 1000 / 60 / 60
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
get days() : number {
|
|
25
|
+
return this.ms / 1000 / 60 / 60 / 24
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
get weeks() : number {
|
|
29
|
+
return this.ms / 1000 / 60 / 60 / 24 / 7
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
get months() : number {
|
|
33
|
+
return this.ms / 1000 / 60 / 60 / 24 / 30
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
static miliseconds(amount: number): Timespan {
|
|
37
|
+
return new Timespan(amount)
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
static seconds(amount: number): Timespan {
|
|
41
|
+
return new Timespan(amount * 1000)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
static minutes(mins: number): Timespan {
|
|
45
|
+
return new Timespan(mins * 60 * 1000)
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
static hours(hours: number): Timespan {
|
|
49
|
+
return new Timespan(hours * 60 * 60 * 1000)
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
static days(days: number): Timespan {
|
|
53
|
+
return new Timespan(days * 24 * 60 * 60 * 1000)
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
static weeks(weeks: number): Timespan {
|
|
57
|
+
return new Timespan(weeks * 7 * 24 * 60 * 60 * 1000)
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
static months(months: number): Timespan {
|
|
61
|
+
return new Timespan(months * 30 * 24 * 60 * 60 * 1000)
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Unixtime = void 0;
|
|
4
|
+
const Timespan_1 = require("./Timespan");
|
|
5
|
+
// this will be a class to work with short and long version of unixtime format
|
|
6
|
+
class Unixtime {
|
|
7
|
+
static NOW() {
|
|
8
|
+
return new Unixtime(Date.now());
|
|
9
|
+
}
|
|
10
|
+
static now() {
|
|
11
|
+
return new Unixtime(Date.now());
|
|
12
|
+
}
|
|
13
|
+
greaterThan(other) {
|
|
14
|
+
return this.toLongUnixtime() > other.toLongUnixtime();
|
|
15
|
+
}
|
|
16
|
+
isEmpty() {
|
|
17
|
+
return this.toLongUnixtime() == 0;
|
|
18
|
+
}
|
|
19
|
+
lessThan(other) {
|
|
20
|
+
return this.toLongUnixtime() < other.toLongUnixtime();
|
|
21
|
+
}
|
|
22
|
+
get elapsed() {
|
|
23
|
+
return new Timespan_1.Timespan(Date.now() - this.toLongUnixtime());
|
|
24
|
+
}
|
|
25
|
+
constructor(value) {
|
|
26
|
+
if (typeof value === 'string') {
|
|
27
|
+
this.value = new Date(value);
|
|
28
|
+
}
|
|
29
|
+
else if (typeof value === 'number') {
|
|
30
|
+
// the number might be short or long form(from nodejs Date.now()
|
|
31
|
+
if (value < 10000000000)
|
|
32
|
+
value *= 1000;
|
|
33
|
+
else
|
|
34
|
+
value = Math.round(value);
|
|
35
|
+
// set the value
|
|
36
|
+
this.value = new Date(value);
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
this.value = value;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
addTimespan(timespan) {
|
|
43
|
+
this.value = new Date(this.value.getTime() + timespan.miliseconds);
|
|
44
|
+
return this;
|
|
45
|
+
}
|
|
46
|
+
subtractTimespan(timespan) {
|
|
47
|
+
this.value = new Date(this.value.getTime() - timespan.miliseconds);
|
|
48
|
+
return this;
|
|
49
|
+
}
|
|
50
|
+
addMiliseconds(miliseconds = 1) {
|
|
51
|
+
this.value = new Date(this.value.getTime() + miliseconds);
|
|
52
|
+
return this;
|
|
53
|
+
}
|
|
54
|
+
addSeconds(seconds = 1) {
|
|
55
|
+
this.value = new Date(this.value.getTime() + seconds * 1000);
|
|
56
|
+
return this;
|
|
57
|
+
}
|
|
58
|
+
addMinutes(minutes = 1) {
|
|
59
|
+
this.value = new Date(this.value.getTime() + minutes * 60000);
|
|
60
|
+
return this;
|
|
61
|
+
}
|
|
62
|
+
addHours(hours = 1) {
|
|
63
|
+
this.value = new Date(this.value.getTime() + hours * 3600000);
|
|
64
|
+
return this;
|
|
65
|
+
}
|
|
66
|
+
addDays(days = 1) {
|
|
67
|
+
this.value = new Date(this.value.getTime() + days * 86400000);
|
|
68
|
+
return this;
|
|
69
|
+
}
|
|
70
|
+
addMonths(months = 1) {
|
|
71
|
+
this.value.setMonth(this.value.getMonth() + months);
|
|
72
|
+
return this;
|
|
73
|
+
}
|
|
74
|
+
addYears(years = 1) {
|
|
75
|
+
this.value.setFullYear(this.value.getFullYear() + years);
|
|
76
|
+
return this;
|
|
77
|
+
}
|
|
78
|
+
yyyymmdd() {
|
|
79
|
+
let mm = this.value.getMonth() + 1;
|
|
80
|
+
let dd = this.value.getDate();
|
|
81
|
+
return [this.value.getFullYear(),
|
|
82
|
+
(mm > 9 ? '' : '0') + mm,
|
|
83
|
+
(dd > 9 ? '' : '0') + dd
|
|
84
|
+
].join('');
|
|
85
|
+
}
|
|
86
|
+
yyymmddhh() {
|
|
87
|
+
let mm = this.value.getMonth() + 1;
|
|
88
|
+
let dd = this.value.getDate();
|
|
89
|
+
let hh = this.value.getHours();
|
|
90
|
+
return [this.value.getFullYear(),
|
|
91
|
+
(mm > 9 ? '' : '0') + mm,
|
|
92
|
+
(dd > 9 ? '' : '0') + dd,
|
|
93
|
+
(hh > 9 ? '' : '0') + hh
|
|
94
|
+
].join('');
|
|
95
|
+
}
|
|
96
|
+
static from(value) {
|
|
97
|
+
return new Unixtime(value);
|
|
98
|
+
}
|
|
99
|
+
toShortUnixtime() {
|
|
100
|
+
return Math.round(this.toLongUnixtime() / 1000);
|
|
101
|
+
}
|
|
102
|
+
toLongUnixtime() {
|
|
103
|
+
return this.value.getTime();
|
|
104
|
+
}
|
|
105
|
+
toDate() {
|
|
106
|
+
return this.value;
|
|
107
|
+
}
|
|
108
|
+
toISOString() {
|
|
109
|
+
return this.value.toISOString();
|
|
110
|
+
}
|
|
111
|
+
elapsedSeconds() {
|
|
112
|
+
return Math.round((Date.now() - this.toLongUnixtime()) / 1000);
|
|
113
|
+
}
|
|
114
|
+
elapsedMinutes() {
|
|
115
|
+
return Math.round(this.elapsedSeconds() / 60);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
exports.Unixtime = Unixtime;
|
|
119
|
+
Unixtime.EMPTY = new Unixtime(new Date(0));
|
|
120
|
+
//# sourceMappingURL=Unixtime.js.map
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { Unixtime } from './Unixtime';
|
|
2
|
+
|
|
3
|
+
describe('Unixtime', () => {
|
|
4
|
+
it('should create Unixtime object from Date', () => {
|
|
5
|
+
const date = new Date();
|
|
6
|
+
const unixtime = new Unixtime(date);
|
|
7
|
+
expect(unixtime.toDate()).toEqual(date);
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
it('should create Unixtime object from string', () => {
|
|
11
|
+
const dateString = '2022-01-01T00:00:00Z';
|
|
12
|
+
const date = new Date(dateString);
|
|
13
|
+
const unixtime = new Unixtime(dateString);
|
|
14
|
+
expect(unixtime.toDate()).toEqual(date);
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
it('should create Unixtime object from number (short form)', () => {
|
|
18
|
+
const timestamp = 1640995200; // January 1, 2022 00:00:00 UTC
|
|
19
|
+
const date = new Date(timestamp * 1000);
|
|
20
|
+
const unixtime = new Unixtime(timestamp);
|
|
21
|
+
expect(unixtime.toDate()).toEqual(date);
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it('should create Unixtime object from number (long form)', () => {
|
|
25
|
+
const timestamp = 1640995200000; // January 1, 2022 00:00:00 UTC
|
|
26
|
+
const date = new Date(timestamp);
|
|
27
|
+
const unixtime = new Unixtime(timestamp);
|
|
28
|
+
expect(unixtime.toDate()).toEqual(date);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it('should convert Unixtime to short Unixtime', () => {
|
|
32
|
+
const date = new Date();
|
|
33
|
+
const unixtime = new Unixtime(date);
|
|
34
|
+
const shortUnixtime = Math.round(date.getTime() / 1000);
|
|
35
|
+
expect(unixtime.toShortUnixtime()).toEqual(shortUnixtime);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it('should convert Unixtime to long Unixtime', () => {
|
|
39
|
+
const date = new Date();
|
|
40
|
+
const unixtime = new Unixtime(date);
|
|
41
|
+
expect(unixtime.toLongUnixtime()).toEqual(date.getTime());
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it('should convert Unixtime to ISO string', () => {
|
|
45
|
+
const date = new Date();
|
|
46
|
+
const unixtime = new Unixtime(date);
|
|
47
|
+
expect(unixtime.toISOString()).toEqual(date.toISOString());
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it('should add miliseconds to Unixtime', () => {
|
|
51
|
+
const date = new Date();
|
|
52
|
+
const unixtime = new Unixtime(date);
|
|
53
|
+
const addedUnixtime = unixtime.addMiliseconds(1000);
|
|
54
|
+
expect(addedUnixtime.toDate()).toEqual(new Date(date.getTime() + 1000));
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it('should add seconds to Unixtime', () => {
|
|
58
|
+
const date = new Date();
|
|
59
|
+
const unixtime = new Unixtime(date);
|
|
60
|
+
const addedUnixtime = unixtime.addSeconds(1);
|
|
61
|
+
expect(addedUnixtime.toDate()).toEqual(new Date(date.getTime() + 1000));
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it('should add minutes to Unixtime', () => {
|
|
65
|
+
const date = new Date();
|
|
66
|
+
const unixtime = new Unixtime(date);
|
|
67
|
+
const addedUnixtime = unixtime.addMinutes(1);
|
|
68
|
+
expect(addedUnixtime.toDate()).toEqual(new Date(date.getTime() + 60000));
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it('should add hours to Unixtime', () => {
|
|
72
|
+
const date = new Date();
|
|
73
|
+
const unixtime = new Unixtime(date);
|
|
74
|
+
const addedUnixtime = unixtime.addHours(1);
|
|
75
|
+
expect(addedUnixtime.toDate()).toEqual(new Date(date.getTime() + 3600000));
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
it('should add days to Unixtime', () => {
|
|
79
|
+
const date = new Date();
|
|
80
|
+
const unixtime = new Unixtime(date);
|
|
81
|
+
const addedUnixtime = unixtime.addDays(1);
|
|
82
|
+
expect(addedUnixtime.toDate()).toEqual(new Date(date.getTime() + 86400000));
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
it('should add months to Unixtime', () => {
|
|
86
|
+
const date = new Date();
|
|
87
|
+
const unixtime = new Unixtime(date);
|
|
88
|
+
const addedUnixtime = unixtime.addMonths(1);
|
|
89
|
+
expect(addedUnixtime.toDate()).toEqual(new Date(date.setMonth(date.getMonth() + 1)));
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
it('should add years to Unixtime', () => {
|
|
93
|
+
const date = new Date();
|
|
94
|
+
const unixtime = new Unixtime(date);
|
|
95
|
+
const addedUnixtime = unixtime.addYears(1);
|
|
96
|
+
expect(addedUnixtime.toDate()).toEqual(new Date(date.setFullYear(date.getFullYear() + 1)));
|
|
97
|
+
});
|
|
98
|
+
});
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { Timespan } from "./Timespan"
|
|
2
|
+
|
|
3
|
+
// this will be a class to work with short and long version of unixtime format
|
|
4
|
+
export class Unixtime {
|
|
5
|
+
private value: Date
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
static EMPTY = new Unixtime(new Date(0))
|
|
9
|
+
|
|
10
|
+
static NOW() {
|
|
11
|
+
return new Unixtime(Date.now())
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
static now() {
|
|
15
|
+
return new Unixtime(Date.now())
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
greaterThan(other: Unixtime) {
|
|
19
|
+
return this.toLongUnixtime() > other.toLongUnixtime()
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
isEmpty() {
|
|
23
|
+
return this.toLongUnixtime() == 0
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
lessThan(other: Unixtime) {
|
|
27
|
+
return this.toLongUnixtime() < other.toLongUnixtime()
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
get elapsed():Timespan {
|
|
31
|
+
return new Timespan(Date.now() - this.toLongUnixtime())
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
constructor(value: Date | string | number) {
|
|
36
|
+
if (typeof value === 'string') {
|
|
37
|
+
this.value = new Date(value)
|
|
38
|
+
} else if (typeof value === 'number') {
|
|
39
|
+
// the number might be short or long form(from nodejs Date.now()
|
|
40
|
+
if (value < 10000000000) value *= 1000
|
|
41
|
+
else
|
|
42
|
+
value = Math.round(value)
|
|
43
|
+
// set the value
|
|
44
|
+
this.value = new Date(value)
|
|
45
|
+
} else {
|
|
46
|
+
this.value = value
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
public addTimespan(timespan: Timespan): Unixtime {
|
|
51
|
+
this.value = new Date(this.value.getTime() + timespan.miliseconds)
|
|
52
|
+
return this
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
public subtractTimespan(timespan: Timespan): Unixtime {
|
|
56
|
+
this.value = new Date(this.value.getTime() - timespan.miliseconds)
|
|
57
|
+
return this
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
public addMiliseconds(miliseconds: number = 1): Unixtime {
|
|
61
|
+
this.value = new Date(this.value.getTime() + miliseconds)
|
|
62
|
+
return this
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
public addSeconds(seconds: number = 1): Unixtime {
|
|
66
|
+
this.value = new Date(this.value.getTime() + seconds * 1000)
|
|
67
|
+
return this
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
public addMinutes(minutes: number = 1): Unixtime {
|
|
71
|
+
this.value = new Date(this.value.getTime() + minutes * 60000)
|
|
72
|
+
return this
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
public addHours(hours: number = 1): Unixtime {
|
|
76
|
+
this.value = new Date(this.value.getTime() + hours * 3600000)
|
|
77
|
+
return this
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
public addDays(days: number = 1): Unixtime {
|
|
81
|
+
this.value = new Date(this.value.getTime() + days * 86400000)
|
|
82
|
+
return this
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
public addMonths(months: number = 1): Unixtime {
|
|
86
|
+
this.value.setMonth(this.value.getMonth() + months)
|
|
87
|
+
return this
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
public addYears(years: number = 1): Unixtime {
|
|
91
|
+
this.value.setFullYear(this.value.getFullYear() + years)
|
|
92
|
+
return this
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
public yyyymmdd(): string {
|
|
96
|
+
let mm = this.value.getMonth() + 1
|
|
97
|
+
let dd = this.value.getDate()
|
|
98
|
+
return [this.value.getFullYear(),
|
|
99
|
+
(mm > 9 ? '' : '0') + mm,
|
|
100
|
+
(dd > 9 ? '' : '0') + dd
|
|
101
|
+
].join('')
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
public yyymmddhh(): string {
|
|
105
|
+
let mm = this.value.getMonth() + 1
|
|
106
|
+
let dd = this.value.getDate()
|
|
107
|
+
let hh = this.value.getHours()
|
|
108
|
+
return [this.value.getFullYear(),
|
|
109
|
+
(mm > 9 ? '' : '0') + mm,
|
|
110
|
+
(dd > 9 ? '' : '0') + dd,
|
|
111
|
+
(hh > 9 ? '' : '0') + hh
|
|
112
|
+
].join('')
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
static from(value: Date | string | number) {
|
|
117
|
+
return new Unixtime(value)
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
public toShortUnixtime(): number {
|
|
121
|
+
return Math.round(this.toLongUnixtime() / 1000)
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
public toLongUnixtime(): number {
|
|
125
|
+
return this.value.getTime()
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
public toDate(): Date {
|
|
129
|
+
return this.value
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
public toISOString(): string {
|
|
133
|
+
return this.value.toISOString()
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
public elapsedSeconds(): number {
|
|
137
|
+
return Math.round((Date.now() - this.toLongUnixtime()) / 1000)
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
public elapsedMinutes(): number {
|
|
141
|
+
return Math.round(this.elapsedSeconds() / 60)
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
}
|
package/ts/types.js
CHANGED
package/tsconfig.json
CHANGED
|
@@ -1,113 +1,34 @@
|
|
|
1
1
|
{
|
|
2
|
-
"compilerOptions": {
|
|
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
|
-
// "moduleResolution": "node10", /* Specify how TypeScript looks up a file from a given module specifier. */
|
|
31
|
-
// "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
|
|
32
|
-
// "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */
|
|
33
|
-
// "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */
|
|
34
|
-
// "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */
|
|
35
|
-
// "types": [], /* Specify type package names to be included without being referenced in a source file. */
|
|
36
|
-
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
|
|
37
|
-
// "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */
|
|
38
|
-
// "allowImportingTsExtensions": true, /* Allow imports to include TypeScript file extensions. Requires '--moduleResolution bundler' and either '--noEmit' or '--emitDeclarationOnly' to be set. */
|
|
39
|
-
// "resolvePackageJsonExports": true, /* Use the package.json 'exports' field when resolving package imports. */
|
|
40
|
-
// "resolvePackageJsonImports": true, /* Use the package.json 'imports' field when resolving imports. */
|
|
41
|
-
// "customConditions": [], /* Conditions to set in addition to the resolver-specific defaults when resolving imports. */
|
|
42
|
-
// "resolveJsonModule": true, /* Enable importing .json files. */
|
|
43
|
-
// "allowArbitraryExtensions": true, /* Enable importing files with any extension, provided a declaration file is present. */
|
|
44
|
-
// "noResolve": true, /* Disallow 'import's, 'require's or '<reference>'s from expanding the number of files TypeScript should add to a project. */
|
|
45
|
-
|
|
46
|
-
/* JavaScript Support */
|
|
47
|
-
// "allowJs": true, /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */
|
|
48
|
-
// "checkJs": true, /* Enable error reporting in type-checked JavaScript files. */
|
|
49
|
-
// "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from 'node_modules'. Only applicable with 'allowJs'. */
|
|
50
|
-
|
|
51
|
-
/* Emit */
|
|
52
|
-
"declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */
|
|
53
|
-
// "declarationMap": true, /* Create sourcemaps for d.ts files. */
|
|
54
|
-
// "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */
|
|
55
|
-
// "sourceMap": true, /* Create source map files for emitted JavaScript files. */
|
|
56
|
-
// "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */
|
|
57
|
-
// "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */
|
|
58
|
-
// "outDir": "./", /* Specify an output folder for all emitted files. */
|
|
59
|
-
// "removeComments": true, /* Disable emitting comments. */
|
|
60
|
-
// "noEmit": true, /* Disable emitting files from a compilation. */
|
|
61
|
-
// "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */
|
|
62
|
-
// "importsNotUsedAsValues": "remove", /* Specify emit/checking behavior for imports that are only used for types. */
|
|
63
|
-
// "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */
|
|
64
|
-
// "sourceRoot": "", /* Specify the root path for debuggers to find the reference source code. */
|
|
65
|
-
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
|
|
66
|
-
// "inlineSources": true, /* Include source code in the sourcemaps inside the emitted JavaScript. */
|
|
67
|
-
// "emitBOM": true, /* Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. */
|
|
68
|
-
// "newLine": "crlf", /* Set the newline character for emitting files. */
|
|
69
|
-
// "stripInternal": true, /* Disable emitting declarations that have '@internal' in their JSDoc comments. */
|
|
70
|
-
// "noEmitHelpers": true, /* Disable generating custom helper functions like '__extends' in compiled output. */
|
|
71
|
-
// "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */
|
|
72
|
-
// "preserveConstEnums": true, /* Disable erasing 'const enum' declarations in generated code. */
|
|
73
|
-
// "declarationDir": "./", /* Specify the output directory for generated declaration files. */
|
|
74
|
-
// "preserveValueImports": true, /* Preserve unused imported values in the JavaScript output that would otherwise be removed. */
|
|
75
|
-
|
|
76
|
-
/* Interop Constraints */
|
|
77
|
-
// "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */
|
|
78
|
-
// "verbatimModuleSyntax": true, /* Do not transform or elide any imports or exports not marked as type-only, ensuring they are written in the output file's format based on the 'module' setting. */
|
|
79
|
-
// "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */
|
|
80
|
-
"esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */
|
|
81
|
-
// "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */
|
|
82
|
-
"forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */
|
|
83
|
-
|
|
84
|
-
/* Type Checking */
|
|
85
|
-
"strict": true, /* Enable all strict type-checking options. */
|
|
86
|
-
// "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied 'any' type. */
|
|
87
|
-
// "strictNullChecks": true, /* When type checking, take into account 'null' and 'undefined'. */
|
|
88
|
-
// "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */
|
|
89
|
-
// "strictBindCallApply": true, /* Check that the arguments for 'bind', 'call', and 'apply' methods match the original function. */
|
|
90
|
-
// "strictPropertyInitialization": true, /* Check for class properties that are declared but not set in the constructor. */
|
|
91
|
-
// "noImplicitThis": true, /* Enable error reporting when 'this' is given the type 'any'. */
|
|
92
|
-
// "useUnknownInCatchVariables": true, /* Default catch clause variables as 'unknown' instead of 'any'. */
|
|
93
|
-
// "alwaysStrict": true, /* Ensure 'use strict' is always emitted. */
|
|
94
|
-
// "noUnusedLocals": true, /* Enable error reporting when local variables aren't read. */
|
|
95
|
-
// "noUnusedParameters": true, /* Raise an error when a function parameter isn't read. */
|
|
96
|
-
// "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */
|
|
97
|
-
// "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */
|
|
98
|
-
// "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */
|
|
99
|
-
// "noUncheckedIndexedAccess": true, /* Add 'undefined' to a type when accessed using an index. */
|
|
100
|
-
// "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an override modifier. */
|
|
101
|
-
// "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type. */
|
|
102
|
-
// "allowUnusedLabels": true, /* Disable error reporting for unused labels. */
|
|
103
|
-
// "allowUnreachableCode": true, /* Disable error reporting for unreachable code. */
|
|
104
|
-
|
|
105
|
-
/* Completeness */
|
|
106
|
-
// "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
|
|
107
|
-
"skipLibCheck": true /* Skip type checking all .d.ts files. */
|
|
108
|
-
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "es2017",
|
|
4
|
+
"experimentalDecorators": true,
|
|
5
|
+
"emitDecoratorMetadata": true,
|
|
6
|
+
"module": "commonjs",
|
|
7
|
+
"moduleResolution" : "Node",
|
|
8
|
+
"esModuleInterop": true,
|
|
9
|
+
"forceConsistentCasingInFileNames": true,
|
|
10
|
+
"strict": true,
|
|
11
|
+
"noImplicitReturns": true, // Report error when not all code paths in function return a value
|
|
12
|
+
"noUnusedLocals": true, // Report errors on unused locals
|
|
13
|
+
// "noUnusedParameters": true, // Report errors on unused parameters
|
|
14
|
+
"noFallthroughCasesInSwitch": true, // Report errors for fallthrough cases in switch statement
|
|
15
|
+
// "noUncheckedIndexedAccess": true, // Include 'undefined' in index signature results
|
|
16
|
+
"noImplicitAny": true, // Raise error on expressions and declarations with an implied 'any' type
|
|
17
|
+
"strictNullChecks": true, // Enable strict null checking
|
|
18
|
+
"strictFunctionTypes": true, // Ensure function parameter types match
|
|
19
|
+
"strictBindCallApply": true, // Ensure 'bind', 'call', and 'apply' methods match function types
|
|
20
|
+
"strictPropertyInitialization": true, // Ensure non-undefined class properties are initialized in the constructor
|
|
21
|
+
"alwaysStrict": true, // Parse in strict mode and emit "use strict" for each source file
|
|
22
|
+
"sourceMap": true,
|
|
23
|
+
"skipLibCheck": true,
|
|
24
|
+
"baseUrl": ".",
|
|
25
|
+
"paths": {
|
|
26
|
+
"@root/*": ["./*"],
|
|
27
|
+
"@models/*": ["./models/*"],
|
|
28
|
+
"@inc/*": ["./inc/ts/*"]
|
|
29
|
+
}
|
|
109
30
|
},
|
|
110
31
|
"exclude": [
|
|
111
|
-
"**/*.test.ts"
|
|
32
|
+
"**/*.test.ts"
|
|
112
33
|
]
|
|
113
|
-
}
|
|
34
|
+
}
|