@naturalcycles/js-lib 14.155.0 → 14.156.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/dist/datetime/dateInterval.d.ts +3 -3
- package/dist/datetime/localDate.d.ts +18 -18
- package/dist/datetime/localTime.d.ts +21 -21
- package/dist/datetime/timeInterval.d.ts +3 -3
- package/dist/env/buildInfo.d.ts +0 -5
- package/dist/env/buildInfo.js +0 -2
- package/dist/lazy.js +3 -1
- package/dist-esm/env/buildInfo.js +0 -2
- package/dist-esm/lazy.js +3 -1
- package/package.json +2 -2
- package/src/array/array.util.ts +10 -7
- package/src/datetime/dateInterval.ts +7 -4
- package/src/datetime/localDate.ts +24 -20
- package/src/datetime/localTime.ts +21 -21
- package/src/datetime/timeInterval.ts +7 -4
- package/src/decorators/debounce.ts +11 -11
- package/src/env/buildInfo.ts +0 -9
- package/src/http/fetcher.ts +1 -1
- package/src/json-schema/jsonSchemaBuilder.ts +25 -25
- package/src/lazy.ts +2 -1
- package/src/math/sma.ts +4 -1
- package/src/object/deepEquals.ts +3 -3
- package/src/object/object.util.ts +17 -11
- package/src/promise/pMap.ts +1 -1
- package/src/seq/seq.ts +8 -2
- package/src/string/readingTime.ts +1 -1
- package/src/zod/zod.util.ts +5 -1
- package/src/__exclude/lazyLocalDate.ts +0 -73
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Inclusiveness,
|
|
1
|
+
import type { Inclusiveness, LocalDateInput, LocalDateUnit } from './localDate';
|
|
2
2
|
import { LocalDate } from './localDate';
|
|
3
3
|
export type DateIntervalConfig = DateInterval | DateIntervalString;
|
|
4
4
|
export type DateIntervalString = string;
|
|
@@ -11,7 +11,7 @@ export declare class DateInterval {
|
|
|
11
11
|
start: LocalDate;
|
|
12
12
|
end: LocalDate;
|
|
13
13
|
private constructor();
|
|
14
|
-
static of(start:
|
|
14
|
+
static of(start: LocalDateInput, end: LocalDateInput): DateInterval;
|
|
15
15
|
/**
|
|
16
16
|
* Parses string like `2022-02-24/2023-03-30` into a DateInterval.
|
|
17
17
|
*/
|
|
@@ -24,7 +24,7 @@ export declare class DateInterval {
|
|
|
24
24
|
/**
|
|
25
25
|
* Ranges of DateInterval (start, end) are INCLUSIVE.
|
|
26
26
|
*/
|
|
27
|
-
includes(d:
|
|
27
|
+
includes(d: LocalDateInput, incl?: Inclusiveness): boolean;
|
|
28
28
|
intersects(int: DateIntervalConfig, inclusive?: boolean): boolean;
|
|
29
29
|
/**
|
|
30
30
|
* DateIntervals compare by start date.
|
|
@@ -3,7 +3,7 @@ import { LocalTime } from './localTime';
|
|
|
3
3
|
export type LocalDateUnit = LocalDateUnitStrict | 'week';
|
|
4
4
|
export type LocalDateUnitStrict = 'year' | 'month' | 'day';
|
|
5
5
|
export type Inclusiveness = '()' | '[]' | '[)' | '(]';
|
|
6
|
-
export type
|
|
6
|
+
export type LocalDateInput = LocalDate | Date | IsoDateString;
|
|
7
7
|
export type LocalDateFormatter = (ld: LocalDate) => string;
|
|
8
8
|
/**
|
|
9
9
|
* @experimental
|
|
@@ -18,23 +18,23 @@ export declare class LocalDate {
|
|
|
18
18
|
* Parses input String into LocalDate.
|
|
19
19
|
* Input can already be a LocalDate - it is returned as-is in that case.
|
|
20
20
|
*/
|
|
21
|
-
static of(d:
|
|
21
|
+
static of(d: LocalDateInput): LocalDate;
|
|
22
22
|
static parseCompact(d: string): LocalDate;
|
|
23
23
|
static fromDate(d: Date): LocalDate;
|
|
24
24
|
static fromDateUTC(d: Date): LocalDate;
|
|
25
25
|
/**
|
|
26
26
|
* Returns null if invalid.
|
|
27
27
|
*/
|
|
28
|
-
static parseOrNull(d:
|
|
28
|
+
static parseOrNull(d: LocalDateInput | undefined | null): LocalDate | null;
|
|
29
29
|
static isValid(iso: string | undefined | null): boolean;
|
|
30
30
|
static today(): LocalDate;
|
|
31
31
|
static todayUTC(): LocalDate;
|
|
32
32
|
static sort(items: LocalDate[], mutate?: boolean, descending?: boolean): LocalDate[];
|
|
33
|
-
static earliestOrUndefined(items:
|
|
34
|
-
static earliest(items:
|
|
35
|
-
static latestOrUndefined(items:
|
|
36
|
-
static latest(items:
|
|
37
|
-
static range(min:
|
|
33
|
+
static earliestOrUndefined(items: LocalDateInput[]): LocalDate | undefined;
|
|
34
|
+
static earliest(items: LocalDateInput[]): LocalDate;
|
|
35
|
+
static latestOrUndefined(items: LocalDateInput[]): LocalDate | undefined;
|
|
36
|
+
static latest(items: LocalDateInput[]): LocalDate;
|
|
37
|
+
static range(min: LocalDateInput, max: LocalDateInput, incl?: Inclusiveness, step?: number, stepUnit?: LocalDateUnit): LocalDate[];
|
|
38
38
|
get(unit: LocalDateUnitStrict): number;
|
|
39
39
|
set(unit: LocalDateUnitStrict, v: number, mutate?: boolean): LocalDate;
|
|
40
40
|
year(): number;
|
|
@@ -43,28 +43,28 @@ export declare class LocalDate {
|
|
|
43
43
|
month(v: number): LocalDate;
|
|
44
44
|
day(): number;
|
|
45
45
|
day(v: number): LocalDate;
|
|
46
|
-
isSame(d:
|
|
47
|
-
isBefore(d:
|
|
48
|
-
isSameOrBefore(d:
|
|
49
|
-
isAfter(d:
|
|
50
|
-
isSameOrAfter(d:
|
|
51
|
-
isBetween(min:
|
|
46
|
+
isSame(d: LocalDateInput): boolean;
|
|
47
|
+
isBefore(d: LocalDateInput, inclusive?: boolean): boolean;
|
|
48
|
+
isSameOrBefore(d: LocalDateInput): boolean;
|
|
49
|
+
isAfter(d: LocalDateInput, inclusive?: boolean): boolean;
|
|
50
|
+
isSameOrAfter(d: LocalDateInput): boolean;
|
|
51
|
+
isBetween(min: LocalDateInput, max: LocalDateInput, incl?: Inclusiveness): boolean;
|
|
52
52
|
/**
|
|
53
53
|
* Returns 1 if this > d
|
|
54
54
|
* returns 0 if they are equal
|
|
55
55
|
* returns -1 if this < d
|
|
56
56
|
*/
|
|
57
|
-
cmp(d:
|
|
57
|
+
cmp(d: LocalDateInput): -1 | 0 | 1;
|
|
58
58
|
/**
|
|
59
59
|
* Same as Math.abs( diff )
|
|
60
60
|
*/
|
|
61
|
-
absDiff(d:
|
|
61
|
+
absDiff(d: LocalDateInput, unit: LocalDateUnit): number;
|
|
62
62
|
/**
|
|
63
63
|
* Returns the number of **full** units difference (aka `Math.floor`).
|
|
64
64
|
*
|
|
65
65
|
* a.diff(b) means "a minus b"
|
|
66
66
|
*/
|
|
67
|
-
diff(d:
|
|
67
|
+
diff(d: LocalDateInput, unit: LocalDateUnit): number;
|
|
68
68
|
add(num: number, unit: LocalDateUnit, mutate?: boolean): LocalDate;
|
|
69
69
|
subtract(num: number, unit: LocalDateUnit, mutate?: boolean): LocalDate;
|
|
70
70
|
startOf(unit: LocalDateUnitStrict): LocalDate;
|
|
@@ -96,4 +96,4 @@ export declare class LocalDate {
|
|
|
96
96
|
/**
|
|
97
97
|
* Shortcut wrapper around `LocalDate.parse` / `LocalDate.today`
|
|
98
98
|
*/
|
|
99
|
-
export declare function localDate(d?:
|
|
99
|
+
export declare function localDate(d?: LocalDateInput): LocalDate;
|
|
@@ -11,7 +11,7 @@ export declare enum ISODayOfWeek {
|
|
|
11
11
|
SATURDAY = 6,
|
|
12
12
|
SUNDAY = 7
|
|
13
13
|
}
|
|
14
|
-
export type
|
|
14
|
+
export type LocalTimeInput = LocalTime | Date | IsoDateTimeString | UnixTimestampNumber;
|
|
15
15
|
export type LocalTimeFormatter = (ld: LocalTime) => string;
|
|
16
16
|
export interface LocalTimeComponents {
|
|
17
17
|
year: number;
|
|
@@ -31,7 +31,7 @@ export declare class LocalTime {
|
|
|
31
31
|
* Parses input String into LocalDate.
|
|
32
32
|
* Input can already be a LocalDate - it is returned as-is in that case.
|
|
33
33
|
*/
|
|
34
|
-
static of(d:
|
|
34
|
+
static of(d: LocalTimeInput): LocalTime;
|
|
35
35
|
/**
|
|
36
36
|
* Create LocalTime from unixTimestamp in milliseconds (not in seconds).
|
|
37
37
|
*/
|
|
@@ -39,10 +39,10 @@ export declare class LocalTime {
|
|
|
39
39
|
/**
|
|
40
40
|
* Returns null if invalid
|
|
41
41
|
*/
|
|
42
|
-
static parseOrNull(d:
|
|
43
|
-
static parseToDate(d:
|
|
44
|
-
static parseToUnixTimestamp(d:
|
|
45
|
-
static isValid(d:
|
|
42
|
+
static parseOrNull(d: LocalTimeInput | undefined | null): LocalTime | null;
|
|
43
|
+
static parseToDate(d: LocalTimeInput): Date;
|
|
44
|
+
static parseToUnixTimestamp(d: LocalTimeInput): UnixTimestampNumber;
|
|
45
|
+
static isValid(d: LocalTimeInput | undefined | null): boolean;
|
|
46
46
|
static now(): LocalTime;
|
|
47
47
|
static fromComponents(c: {
|
|
48
48
|
year: number;
|
|
@@ -72,29 +72,29 @@ export declare class LocalTime {
|
|
|
72
72
|
setComponents(c: Partial<LocalTimeComponents>, mutate?: boolean): LocalTime;
|
|
73
73
|
add(num: number, unit: LocalTimeUnit, mutate?: boolean): LocalTime;
|
|
74
74
|
subtract(num: number, unit: LocalTimeUnit, mutate?: boolean): LocalTime;
|
|
75
|
-
absDiff(other:
|
|
76
|
-
diff(other:
|
|
75
|
+
absDiff(other: LocalTimeInput, unit: LocalTimeUnit): number;
|
|
76
|
+
diff(other: LocalTimeInput, unit: LocalTimeUnit): number;
|
|
77
77
|
startOf(unit: LocalTimeUnit, mutate?: boolean): LocalTime;
|
|
78
78
|
endOf(unit: LocalTimeUnit, mutate?: boolean): LocalTime;
|
|
79
79
|
static sort(items: LocalTime[], mutate?: boolean, descending?: boolean): LocalTime[];
|
|
80
|
-
static earliestOrUndefined(items:
|
|
81
|
-
static earliest(items:
|
|
82
|
-
static latestOrUndefined(items:
|
|
83
|
-
static latest(items:
|
|
84
|
-
isSame(d:
|
|
85
|
-
isBefore(d:
|
|
86
|
-
isSameOrBefore(d:
|
|
87
|
-
isAfter(d:
|
|
88
|
-
isSameOrAfter(d:
|
|
89
|
-
isBetween(min:
|
|
80
|
+
static earliestOrUndefined(items: LocalTimeInput[]): LocalTime | undefined;
|
|
81
|
+
static earliest(items: LocalTimeInput[]): LocalTime;
|
|
82
|
+
static latestOrUndefined(items: LocalTimeInput[]): LocalTime | undefined;
|
|
83
|
+
static latest(items: LocalTimeInput[]): LocalTime;
|
|
84
|
+
isSame(d: LocalTimeInput): boolean;
|
|
85
|
+
isBefore(d: LocalTimeInput, inclusive?: boolean): boolean;
|
|
86
|
+
isSameOrBefore(d: LocalTimeInput): boolean;
|
|
87
|
+
isAfter(d: LocalTimeInput, inclusive?: boolean): boolean;
|
|
88
|
+
isSameOrAfter(d: LocalTimeInput): boolean;
|
|
89
|
+
isBetween(min: LocalTimeInput, max: LocalTimeInput, incl?: Inclusiveness): boolean;
|
|
90
90
|
/**
|
|
91
91
|
* Returns 1 if this > d
|
|
92
92
|
* returns 0 if they are equal
|
|
93
93
|
* returns -1 if this < d
|
|
94
94
|
*/
|
|
95
|
-
cmp(d:
|
|
95
|
+
cmp(d: LocalTimeInput): -1 | 0 | 1;
|
|
96
96
|
components(): LocalTimeComponents;
|
|
97
|
-
fromNow(now?:
|
|
97
|
+
fromNow(now?: LocalTimeInput): string;
|
|
98
98
|
getDate(): Date;
|
|
99
99
|
clone(): LocalTime;
|
|
100
100
|
unix(): UnixTimestampNumber;
|
|
@@ -125,4 +125,4 @@ export declare class LocalTime {
|
|
|
125
125
|
/**
|
|
126
126
|
* Shortcut wrapper around `LocalDate.parse` / `LocalDate.today`
|
|
127
127
|
*/
|
|
128
|
-
export declare function localTime(d?:
|
|
128
|
+
export declare function localTime(d?: LocalTimeInput): LocalTime;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { UnixTimestampNumber } from '../types';
|
|
2
2
|
import type { Inclusiveness } from './localDate';
|
|
3
|
-
import type {
|
|
3
|
+
import type { LocalTimeInput } from './localTime';
|
|
4
4
|
import { LocalTime } from './localTime';
|
|
5
5
|
export type TimeIntervalConfig = TimeInterval | TimeIntervalString;
|
|
6
6
|
export type TimeIntervalString = string;
|
|
@@ -14,7 +14,7 @@ export declare class TimeInterval {
|
|
|
14
14
|
private $start;
|
|
15
15
|
private $end;
|
|
16
16
|
private constructor();
|
|
17
|
-
static of(start:
|
|
17
|
+
static of(start: LocalTimeInput, end: LocalTimeInput): TimeInterval;
|
|
18
18
|
get start(): UnixTimestampNumber;
|
|
19
19
|
get end(): UnixTimestampNumber;
|
|
20
20
|
get startTime(): LocalTime;
|
|
@@ -28,7 +28,7 @@ export declare class TimeInterval {
|
|
|
28
28
|
isSameOrBefore(d: TimeIntervalConfig): boolean;
|
|
29
29
|
isAfter(d: TimeIntervalConfig, inclusive?: boolean): boolean;
|
|
30
30
|
isSameOrAfter(d: TimeIntervalConfig): boolean;
|
|
31
|
-
includes(d:
|
|
31
|
+
includes(d: LocalTimeInput, incl?: Inclusiveness): boolean;
|
|
32
32
|
/**
|
|
33
33
|
* TimeIntervals compare by start date.
|
|
34
34
|
* If it's the same - then by end date.
|
package/dist/env/buildInfo.d.ts
CHANGED
|
@@ -8,11 +8,6 @@ export interface BuildInfo {
|
|
|
8
8
|
* Unix timestamp of commit ("committer date", not "author date")
|
|
9
9
|
*/
|
|
10
10
|
tsCommit: UnixTimestampNumber;
|
|
11
|
-
/**
|
|
12
|
-
* Human-readable time of the build. E.g:
|
|
13
|
-
* 2019-06-21 18:35:19
|
|
14
|
-
*/
|
|
15
|
-
tsStr: string;
|
|
16
11
|
repoName: string;
|
|
17
12
|
branchName: string;
|
|
18
13
|
/**
|
package/dist/env/buildInfo.js
CHANGED
|
@@ -5,7 +5,6 @@ const localTime_1 = require("../datetime/localTime");
|
|
|
5
5
|
function generateBuildInfoDev() {
|
|
6
6
|
const now = (0, localTime_1.localTime)();
|
|
7
7
|
const ts = now.unix();
|
|
8
|
-
const tsStr = now.toPretty();
|
|
9
8
|
const rev = 'devRev';
|
|
10
9
|
const branchName = 'devBranch';
|
|
11
10
|
const repoName = 'devRepo';
|
|
@@ -14,7 +13,6 @@ function generateBuildInfoDev() {
|
|
|
14
13
|
return {
|
|
15
14
|
ts,
|
|
16
15
|
tsCommit,
|
|
17
|
-
tsStr,
|
|
18
16
|
repoName,
|
|
19
17
|
branchName,
|
|
20
18
|
rev,
|
package/dist/lazy.js
CHANGED
|
@@ -37,7 +37,9 @@ exports._lazyValue = _lazyValue;
|
|
|
37
37
|
* Based on: https://github.com/sindresorhus/define-lazy-prop
|
|
38
38
|
*/
|
|
39
39
|
function _defineLazyProperty(obj, propertyName, fn) {
|
|
40
|
-
const define = (value) =>
|
|
40
|
+
const define = (value) => {
|
|
41
|
+
Object.defineProperty(obj, propertyName, { value, enumerable: true, writable: true });
|
|
42
|
+
};
|
|
41
43
|
Object.defineProperty(obj, propertyName, {
|
|
42
44
|
configurable: true,
|
|
43
45
|
enumerable: true,
|
|
@@ -2,7 +2,6 @@ import { localTime } from '../datetime/localTime';
|
|
|
2
2
|
export function generateBuildInfoDev() {
|
|
3
3
|
const now = localTime();
|
|
4
4
|
const ts = now.unix();
|
|
5
|
-
const tsStr = now.toPretty();
|
|
6
5
|
const rev = 'devRev';
|
|
7
6
|
const branchName = 'devBranch';
|
|
8
7
|
const repoName = 'devRepo';
|
|
@@ -11,7 +10,6 @@ export function generateBuildInfoDev() {
|
|
|
11
10
|
return {
|
|
12
11
|
ts,
|
|
13
12
|
tsCommit,
|
|
14
|
-
tsStr,
|
|
15
13
|
repoName,
|
|
16
14
|
branchName,
|
|
17
15
|
rev,
|
package/dist-esm/lazy.js
CHANGED
|
@@ -33,7 +33,9 @@ export function _lazyValue(fn) {
|
|
|
33
33
|
* Based on: https://github.com/sindresorhus/define-lazy-prop
|
|
34
34
|
*/
|
|
35
35
|
export function _defineLazyProperty(obj, propertyName, fn) {
|
|
36
|
-
const define = (value) =>
|
|
36
|
+
const define = (value) => {
|
|
37
|
+
Object.defineProperty(obj, propertyName, { value, enumerable: true, writable: true });
|
|
38
|
+
};
|
|
37
39
|
Object.defineProperty(obj, propertyName, {
|
|
38
40
|
configurable: true,
|
|
39
41
|
enumerable: true,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@naturalcycles/js-lib",
|
|
3
|
-
"version": "14.
|
|
3
|
+
"version": "14.156.0",
|
|
4
4
|
"scripts": {
|
|
5
5
|
"prepare": "husky install",
|
|
6
6
|
"build-prod": "build-prod-esm-cjs",
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"@types/node": "^20.1.0",
|
|
21
21
|
"crypto-js": "^4.1.1",
|
|
22
22
|
"jest": "^29.0.0",
|
|
23
|
-
"prettier": "^
|
|
23
|
+
"prettier": "^3.0.0",
|
|
24
24
|
"rxjs": "^7.0.1",
|
|
25
25
|
"vuepress": "^1.7.1",
|
|
26
26
|
"vuepress-plugin-typescript": "^0.3.1"
|
package/src/array/array.util.ts
CHANGED
|
@@ -97,13 +97,16 @@ export function _by<T>(items: readonly T[], mapper: Mapper<T, any>): StringMap<T
|
|
|
97
97
|
* Returning `undefined` from the Mapper will EXCLUDE the item.
|
|
98
98
|
*/
|
|
99
99
|
export function _groupBy<T>(items: readonly T[], mapper: Mapper<T, any>): StringMap<T[]> {
|
|
100
|
-
return items.reduce(
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
100
|
+
return items.reduce(
|
|
101
|
+
(map, item, index) => {
|
|
102
|
+
const res = mapper(item, index)
|
|
103
|
+
if (res !== undefined) {
|
|
104
|
+
map[res] = [...(map[res] || []), item]
|
|
105
|
+
}
|
|
106
|
+
return map
|
|
107
|
+
},
|
|
108
|
+
{} as StringMap<T[]>,
|
|
109
|
+
)
|
|
107
110
|
}
|
|
108
111
|
|
|
109
112
|
/**
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Inclusiveness,
|
|
1
|
+
import type { Inclusiveness, LocalDateInput, LocalDateUnit } from './localDate'
|
|
2
2
|
import { LocalDate } from './localDate'
|
|
3
3
|
|
|
4
4
|
export type DateIntervalConfig = DateInterval | DateIntervalString
|
|
@@ -10,9 +10,12 @@ export type DateIntervalString = string
|
|
|
10
10
|
* @experimental
|
|
11
11
|
*/
|
|
12
12
|
export class DateInterval {
|
|
13
|
-
private constructor(
|
|
13
|
+
private constructor(
|
|
14
|
+
public start: LocalDate,
|
|
15
|
+
public end: LocalDate,
|
|
16
|
+
) {}
|
|
14
17
|
|
|
15
|
-
static of(start:
|
|
18
|
+
static of(start: LocalDateInput, end: LocalDateInput): DateInterval {
|
|
16
19
|
return new DateInterval(LocalDate.of(start), LocalDate.of(end))
|
|
17
20
|
}
|
|
18
21
|
|
|
@@ -56,7 +59,7 @@ export class DateInterval {
|
|
|
56
59
|
/**
|
|
57
60
|
* Ranges of DateInterval (start, end) are INCLUSIVE.
|
|
58
61
|
*/
|
|
59
|
-
includes(d:
|
|
62
|
+
includes(d: LocalDateInput, incl: Inclusiveness = '[]'): boolean {
|
|
60
63
|
d = LocalDate.of(d)
|
|
61
64
|
// eslint-disable-next-line @typescript-eslint/prefer-string-starts-ends-with
|
|
62
65
|
return d.isAfter(this.start, incl[0] === '[') && d.isBefore(this.end, incl[1] === ']')
|
|
@@ -14,14 +14,18 @@ export type Inclusiveness = '()' | '[]' | '[)' | '(]'
|
|
|
14
14
|
const MDAYS = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
|
|
15
15
|
const DATE_REGEX = /^(\d\d\d\d)-(\d\d)-(\d\d)$/
|
|
16
16
|
|
|
17
|
-
export type
|
|
17
|
+
export type LocalDateInput = LocalDate | Date | IsoDateString
|
|
18
18
|
export type LocalDateFormatter = (ld: LocalDate) => string
|
|
19
19
|
|
|
20
20
|
/**
|
|
21
21
|
* @experimental
|
|
22
22
|
*/
|
|
23
23
|
export class LocalDate {
|
|
24
|
-
private constructor(
|
|
24
|
+
private constructor(
|
|
25
|
+
private $year: number,
|
|
26
|
+
private $month: number,
|
|
27
|
+
private $day: number,
|
|
28
|
+
) {}
|
|
25
29
|
|
|
26
30
|
static create(year: number, month: number, day: number): LocalDate {
|
|
27
31
|
return new LocalDate(year, month, day)
|
|
@@ -31,7 +35,7 @@ export class LocalDate {
|
|
|
31
35
|
* Parses input String into LocalDate.
|
|
32
36
|
* Input can already be a LocalDate - it is returned as-is in that case.
|
|
33
37
|
*/
|
|
34
|
-
static of(d:
|
|
38
|
+
static of(d: LocalDateInput): LocalDate {
|
|
35
39
|
const t = this.parseOrNull(d)
|
|
36
40
|
|
|
37
41
|
if (t === null) {
|
|
@@ -62,7 +66,7 @@ export class LocalDate {
|
|
|
62
66
|
/**
|
|
63
67
|
* Returns null if invalid.
|
|
64
68
|
*/
|
|
65
|
-
static parseOrNull(d:
|
|
69
|
+
static parseOrNull(d: LocalDateInput | undefined | null): LocalDate | null {
|
|
66
70
|
if (!d) return null
|
|
67
71
|
if (d instanceof LocalDate) return d
|
|
68
72
|
if (d instanceof Date) {
|
|
@@ -114,11 +118,11 @@ export class LocalDate {
|
|
|
114
118
|
return (mutate ? items : [...items]).sort((a, b) => a.cmp(b) * mod)
|
|
115
119
|
}
|
|
116
120
|
|
|
117
|
-
static earliestOrUndefined(items:
|
|
121
|
+
static earliestOrUndefined(items: LocalDateInput[]): LocalDate | undefined {
|
|
118
122
|
return items.length ? LocalDate.earliest(items) : undefined
|
|
119
123
|
}
|
|
120
124
|
|
|
121
|
-
static earliest(items:
|
|
125
|
+
static earliest(items: LocalDateInput[]): LocalDate {
|
|
122
126
|
_assert(items.length, 'LocalDate.earliest called on empty array')
|
|
123
127
|
|
|
124
128
|
return items
|
|
@@ -126,11 +130,11 @@ export class LocalDate {
|
|
|
126
130
|
.reduce((min, item) => (min.isSameOrBefore(item) ? min : item))
|
|
127
131
|
}
|
|
128
132
|
|
|
129
|
-
static latestOrUndefined(items:
|
|
133
|
+
static latestOrUndefined(items: LocalDateInput[]): LocalDate | undefined {
|
|
130
134
|
return items.length ? LocalDate.latest(items) : undefined
|
|
131
135
|
}
|
|
132
136
|
|
|
133
|
-
static latest(items:
|
|
137
|
+
static latest(items: LocalDateInput[]): LocalDate {
|
|
134
138
|
_assert(items.length, 'LocalDate.latest called on empty array')
|
|
135
139
|
|
|
136
140
|
return items
|
|
@@ -139,8 +143,8 @@ export class LocalDate {
|
|
|
139
143
|
}
|
|
140
144
|
|
|
141
145
|
static range(
|
|
142
|
-
min:
|
|
143
|
-
max:
|
|
146
|
+
min: LocalDateInput,
|
|
147
|
+
max: LocalDateInput,
|
|
144
148
|
incl: Inclusiveness = '[)',
|
|
145
149
|
step = 1,
|
|
146
150
|
stepUnit: LocalDateUnit = 'day',
|
|
@@ -205,30 +209,30 @@ export class LocalDate {
|
|
|
205
209
|
return v === undefined ? this.$day : this.set('day', v)
|
|
206
210
|
}
|
|
207
211
|
|
|
208
|
-
isSame(d:
|
|
212
|
+
isSame(d: LocalDateInput): boolean {
|
|
209
213
|
d = LocalDate.of(d)
|
|
210
214
|
return this.$day === d.$day && this.$month === d.$month && this.$year === d.$year
|
|
211
215
|
}
|
|
212
216
|
|
|
213
|
-
isBefore(d:
|
|
217
|
+
isBefore(d: LocalDateInput, inclusive = false): boolean {
|
|
214
218
|
const r = this.cmp(d)
|
|
215
219
|
return r === -1 || (r === 0 && inclusive)
|
|
216
220
|
}
|
|
217
221
|
|
|
218
|
-
isSameOrBefore(d:
|
|
222
|
+
isSameOrBefore(d: LocalDateInput): boolean {
|
|
219
223
|
return this.cmp(d) <= 0
|
|
220
224
|
}
|
|
221
225
|
|
|
222
|
-
isAfter(d:
|
|
226
|
+
isAfter(d: LocalDateInput, inclusive = false): boolean {
|
|
223
227
|
const r = this.cmp(d)
|
|
224
228
|
return r === 1 || (r === 0 && inclusive)
|
|
225
229
|
}
|
|
226
230
|
|
|
227
|
-
isSameOrAfter(d:
|
|
231
|
+
isSameOrAfter(d: LocalDateInput): boolean {
|
|
228
232
|
return this.cmp(d) >= 0
|
|
229
233
|
}
|
|
230
234
|
|
|
231
|
-
isBetween(min:
|
|
235
|
+
isBetween(min: LocalDateInput, max: LocalDateInput, incl: Inclusiveness = '[)'): boolean {
|
|
232
236
|
let r = this.cmp(min)
|
|
233
237
|
// eslint-disable-next-line @typescript-eslint/prefer-string-starts-ends-with
|
|
234
238
|
if (r < 0 || (r === 0 && incl[0] === '(')) return false
|
|
@@ -242,7 +246,7 @@ export class LocalDate {
|
|
|
242
246
|
* returns 0 if they are equal
|
|
243
247
|
* returns -1 if this < d
|
|
244
248
|
*/
|
|
245
|
-
cmp(d:
|
|
249
|
+
cmp(d: LocalDateInput): -1 | 0 | 1 {
|
|
246
250
|
d = LocalDate.of(d)
|
|
247
251
|
if (this.$year < d.$year) return -1
|
|
248
252
|
if (this.$year > d.$year) return 1
|
|
@@ -256,7 +260,7 @@ export class LocalDate {
|
|
|
256
260
|
/**
|
|
257
261
|
* Same as Math.abs( diff )
|
|
258
262
|
*/
|
|
259
|
-
absDiff(d:
|
|
263
|
+
absDiff(d: LocalDateInput, unit: LocalDateUnit): number {
|
|
260
264
|
return Math.abs(this.diff(d, unit))
|
|
261
265
|
}
|
|
262
266
|
|
|
@@ -265,7 +269,7 @@ export class LocalDate {
|
|
|
265
269
|
*
|
|
266
270
|
* a.diff(b) means "a minus b"
|
|
267
271
|
*/
|
|
268
|
-
diff(d:
|
|
272
|
+
diff(d: LocalDateInput, unit: LocalDateUnit): number {
|
|
269
273
|
d = LocalDate.of(d)
|
|
270
274
|
|
|
271
275
|
const sign = this.cmp(d)
|
|
@@ -505,6 +509,6 @@ export class LocalDate {
|
|
|
505
509
|
/**
|
|
506
510
|
* Shortcut wrapper around `LocalDate.parse` / `LocalDate.today`
|
|
507
511
|
*/
|
|
508
|
-
export function localDate(d?:
|
|
512
|
+
export function localDate(d?: LocalDateInput): LocalDate {
|
|
509
513
|
return d ? LocalDate.of(d) : LocalDate.today()
|
|
510
514
|
}
|
|
@@ -21,7 +21,7 @@ export enum ISODayOfWeek {
|
|
|
21
21
|
SUNDAY = 7,
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
export type
|
|
24
|
+
export type LocalTimeInput = LocalTime | Date | IsoDateTimeString | UnixTimestampNumber
|
|
25
25
|
export type LocalTimeFormatter = (ld: LocalTime) => string
|
|
26
26
|
|
|
27
27
|
export interface LocalTimeComponents {
|
|
@@ -50,7 +50,7 @@ export class LocalTime {
|
|
|
50
50
|
* Parses input String into LocalDate.
|
|
51
51
|
* Input can already be a LocalDate - it is returned as-is in that case.
|
|
52
52
|
*/
|
|
53
|
-
static of(d:
|
|
53
|
+
static of(d: LocalTimeInput): LocalTime {
|
|
54
54
|
const t = this.parseOrNull(d)
|
|
55
55
|
|
|
56
56
|
if (t === null) {
|
|
@@ -70,7 +70,7 @@ export class LocalTime {
|
|
|
70
70
|
/**
|
|
71
71
|
* Returns null if invalid
|
|
72
72
|
*/
|
|
73
|
-
static parseOrNull(d:
|
|
73
|
+
static parseOrNull(d: LocalTimeInput | undefined | null): LocalTime | null {
|
|
74
74
|
if (!d) return null
|
|
75
75
|
if (d instanceof LocalTime) return d
|
|
76
76
|
|
|
@@ -100,7 +100,7 @@ export class LocalTime {
|
|
|
100
100
|
return new LocalTime(date)
|
|
101
101
|
}
|
|
102
102
|
|
|
103
|
-
static parseToDate(d:
|
|
103
|
+
static parseToDate(d: LocalTimeInput): Date {
|
|
104
104
|
if (d instanceof LocalTime) return d.$date
|
|
105
105
|
if (d instanceof Date) return d
|
|
106
106
|
|
|
@@ -113,7 +113,7 @@ export class LocalTime {
|
|
|
113
113
|
return date
|
|
114
114
|
}
|
|
115
115
|
|
|
116
|
-
static parseToUnixTimestamp(d:
|
|
116
|
+
static parseToUnixTimestamp(d: LocalTimeInput): UnixTimestampNumber {
|
|
117
117
|
if (typeof d === 'number') return d
|
|
118
118
|
if (d instanceof LocalTime) return d.unix()
|
|
119
119
|
|
|
@@ -126,7 +126,7 @@ export class LocalTime {
|
|
|
126
126
|
return date.valueOf() / 1000
|
|
127
127
|
}
|
|
128
128
|
|
|
129
|
-
static isValid(d:
|
|
129
|
+
static isValid(d: LocalTimeInput | undefined | null): boolean {
|
|
130
130
|
return this.parseOrNull(d) !== null
|
|
131
131
|
}
|
|
132
132
|
|
|
@@ -283,11 +283,11 @@ export class LocalTime {
|
|
|
283
283
|
return this.add(num * -1, unit, mutate)
|
|
284
284
|
}
|
|
285
285
|
|
|
286
|
-
absDiff(other:
|
|
286
|
+
absDiff(other: LocalTimeInput, unit: LocalTimeUnit): number {
|
|
287
287
|
return Math.abs(this.diff(other, unit))
|
|
288
288
|
}
|
|
289
289
|
|
|
290
|
-
diff(other:
|
|
290
|
+
diff(other: LocalTimeInput, unit: LocalTimeUnit): number {
|
|
291
291
|
const date2 = LocalTime.parseToDate(other)
|
|
292
292
|
|
|
293
293
|
const secDiff = (this.$date.valueOf() - date2.valueOf()) / 1000
|
|
@@ -384,11 +384,11 @@ export class LocalTime {
|
|
|
384
384
|
})
|
|
385
385
|
}
|
|
386
386
|
|
|
387
|
-
static earliestOrUndefined(items:
|
|
387
|
+
static earliestOrUndefined(items: LocalTimeInput[]): LocalTime | undefined {
|
|
388
388
|
return items.length ? LocalTime.earliest(items) : undefined
|
|
389
389
|
}
|
|
390
390
|
|
|
391
|
-
static earliest(items:
|
|
391
|
+
static earliest(items: LocalTimeInput[]): LocalTime {
|
|
392
392
|
_assert(items.length, 'LocalTime.earliest called on empty array')
|
|
393
393
|
|
|
394
394
|
return items
|
|
@@ -396,11 +396,11 @@ export class LocalTime {
|
|
|
396
396
|
.reduce((min, item) => (min.isSameOrBefore(item) ? min : item))
|
|
397
397
|
}
|
|
398
398
|
|
|
399
|
-
static latestOrUndefined(items:
|
|
399
|
+
static latestOrUndefined(items: LocalTimeInput[]): LocalTime | undefined {
|
|
400
400
|
return items.length ? LocalTime.latest(items) : undefined
|
|
401
401
|
}
|
|
402
402
|
|
|
403
|
-
static latest(items:
|
|
403
|
+
static latest(items: LocalTimeInput[]): LocalTime {
|
|
404
404
|
_assert(items.length, 'LocalTime.latest called on empty array')
|
|
405
405
|
|
|
406
406
|
return items
|
|
@@ -408,29 +408,29 @@ export class LocalTime {
|
|
|
408
408
|
.reduce((max, item) => (max.isSameOrAfter(item) ? max : item))
|
|
409
409
|
}
|
|
410
410
|
|
|
411
|
-
isSame(d:
|
|
411
|
+
isSame(d: LocalTimeInput): boolean {
|
|
412
412
|
return this.cmp(d) === 0
|
|
413
413
|
}
|
|
414
414
|
|
|
415
|
-
isBefore(d:
|
|
415
|
+
isBefore(d: LocalTimeInput, inclusive = false): boolean {
|
|
416
416
|
const r = this.cmp(d)
|
|
417
417
|
return r === -1 || (r === 0 && inclusive)
|
|
418
418
|
}
|
|
419
419
|
|
|
420
|
-
isSameOrBefore(d:
|
|
420
|
+
isSameOrBefore(d: LocalTimeInput): boolean {
|
|
421
421
|
return this.cmp(d) <= 0
|
|
422
422
|
}
|
|
423
423
|
|
|
424
|
-
isAfter(d:
|
|
424
|
+
isAfter(d: LocalTimeInput, inclusive = false): boolean {
|
|
425
425
|
const r = this.cmp(d)
|
|
426
426
|
return r === 1 || (r === 0 && inclusive)
|
|
427
427
|
}
|
|
428
428
|
|
|
429
|
-
isSameOrAfter(d:
|
|
429
|
+
isSameOrAfter(d: LocalTimeInput): boolean {
|
|
430
430
|
return this.cmp(d) >= 0
|
|
431
431
|
}
|
|
432
432
|
|
|
433
|
-
isBetween(min:
|
|
433
|
+
isBetween(min: LocalTimeInput, max: LocalTimeInput, incl: Inclusiveness = '[)'): boolean {
|
|
434
434
|
let r = this.cmp(min)
|
|
435
435
|
// eslint-disable-next-line @typescript-eslint/prefer-string-starts-ends-with
|
|
436
436
|
if (r < 0 || (r === 0 && incl[0] === '(')) return false
|
|
@@ -444,7 +444,7 @@ export class LocalTime {
|
|
|
444
444
|
* returns 0 if they are equal
|
|
445
445
|
* returns -1 if this < d
|
|
446
446
|
*/
|
|
447
|
-
cmp(d:
|
|
447
|
+
cmp(d: LocalTimeInput): -1 | 0 | 1 {
|
|
448
448
|
const t1 = this.$date.valueOf()
|
|
449
449
|
const t2 = LocalTime.parseToDate(d).valueOf()
|
|
450
450
|
if (t1 === t2) return 0
|
|
@@ -462,7 +462,7 @@ export class LocalTime {
|
|
|
462
462
|
}
|
|
463
463
|
}
|
|
464
464
|
|
|
465
|
-
fromNow(now:
|
|
465
|
+
fromNow(now: LocalTimeInput = new Date()): string {
|
|
466
466
|
const msDiff = LocalTime.parseToDate(now).valueOf() - this.$date.valueOf()
|
|
467
467
|
|
|
468
468
|
if (msDiff === 0) return 'now'
|
|
@@ -599,7 +599,7 @@ export class LocalTime {
|
|
|
599
599
|
/**
|
|
600
600
|
* Shortcut wrapper around `LocalDate.parse` / `LocalDate.today`
|
|
601
601
|
*/
|
|
602
|
-
export function localTime(d?:
|
|
602
|
+
export function localTime(d?: LocalTimeInput): LocalTime {
|
|
603
603
|
return d ? LocalTime.of(d) : LocalTime.now()
|
|
604
604
|
}
|
|
605
605
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { UnixTimestampNumber } from '../types'
|
|
2
2
|
import type { Inclusiveness } from './localDate'
|
|
3
|
-
import type {
|
|
3
|
+
import type { LocalTimeInput } from './localTime'
|
|
4
4
|
import { LocalTime } from './localTime'
|
|
5
5
|
|
|
6
6
|
export type TimeIntervalConfig = TimeInterval | TimeIntervalString
|
|
@@ -13,9 +13,12 @@ export type TimeIntervalString = string
|
|
|
13
13
|
* @experimental
|
|
14
14
|
*/
|
|
15
15
|
export class TimeInterval {
|
|
16
|
-
private constructor(
|
|
16
|
+
private constructor(
|
|
17
|
+
private $start: UnixTimestampNumber,
|
|
18
|
+
private $end: UnixTimestampNumber,
|
|
19
|
+
) {}
|
|
17
20
|
|
|
18
|
-
static of(start:
|
|
21
|
+
static of(start: LocalTimeInput, end: LocalTimeInput): TimeInterval {
|
|
19
22
|
return new TimeInterval(
|
|
20
23
|
LocalTime.parseToUnixTimestamp(start),
|
|
21
24
|
LocalTime.parseToUnixTimestamp(end),
|
|
@@ -75,7 +78,7 @@ export class TimeInterval {
|
|
|
75
78
|
return this.cmp(d) >= 0
|
|
76
79
|
}
|
|
77
80
|
|
|
78
|
-
includes(d:
|
|
81
|
+
includes(d: LocalTimeInput, incl: Inclusiveness = '[)'): boolean {
|
|
79
82
|
d = LocalTime.parseToUnixTimestamp(d)
|
|
80
83
|
// eslint-disable-next-line @typescript-eslint/prefer-string-starts-ends-with
|
|
81
84
|
if (d < this.$start || (d === this.$start && incl[0] === '(')) return false
|
|
@@ -51,7 +51,7 @@ export function _debounce<T extends AnyFunction>(
|
|
|
51
51
|
const { leading = false, trailing = true } = opt
|
|
52
52
|
const maxWait = maxing ? Math.max(Number(opt.maxWait) || 0, wait) : opt.maxWait
|
|
53
53
|
|
|
54
|
-
function invokeFunc(time: number) {
|
|
54
|
+
function invokeFunc(time: number): any {
|
|
55
55
|
const args = lastArgs
|
|
56
56
|
const thisArg = lastThis
|
|
57
57
|
|
|
@@ -65,11 +65,11 @@ export function _debounce<T extends AnyFunction>(
|
|
|
65
65
|
return setTimeout(pendingFunc, wait) as any
|
|
66
66
|
}
|
|
67
67
|
|
|
68
|
-
function cancelTimer(id: number) {
|
|
68
|
+
function cancelTimer(id: number): void {
|
|
69
69
|
clearTimeout(id)
|
|
70
70
|
}
|
|
71
71
|
|
|
72
|
-
function leadingEdge(time: number) {
|
|
72
|
+
function leadingEdge(time: number): any {
|
|
73
73
|
// Reset any `maxWait` timer.
|
|
74
74
|
lastInvokeTime = time
|
|
75
75
|
// Start the timer for the trailing edge.
|
|
@@ -78,7 +78,7 @@ export function _debounce<T extends AnyFunction>(
|
|
|
78
78
|
return leading ? invokeFunc(time) : result
|
|
79
79
|
}
|
|
80
80
|
|
|
81
|
-
function remainingWait(time: number) {
|
|
81
|
+
function remainingWait(time: number): number {
|
|
82
82
|
const timeSinceLastCall = time - lastCallTime!
|
|
83
83
|
const timeSinceLastInvoke = time - lastInvokeTime
|
|
84
84
|
const timeWaiting = wait - timeSinceLastCall
|
|
@@ -86,7 +86,7 @@ export function _debounce<T extends AnyFunction>(
|
|
|
86
86
|
return maxing ? Math.min(timeWaiting, maxWait! - timeSinceLastInvoke) : timeWaiting
|
|
87
87
|
}
|
|
88
88
|
|
|
89
|
-
function shouldInvoke(time: number) {
|
|
89
|
+
function shouldInvoke(time: number): boolean {
|
|
90
90
|
const timeSinceLastCall = time - lastCallTime!
|
|
91
91
|
const timeSinceLastInvoke = time - lastInvokeTime
|
|
92
92
|
|
|
@@ -101,7 +101,7 @@ export function _debounce<T extends AnyFunction>(
|
|
|
101
101
|
)
|
|
102
102
|
}
|
|
103
103
|
|
|
104
|
-
function timerExpired() {
|
|
104
|
+
function timerExpired(): any {
|
|
105
105
|
const time = Date.now()
|
|
106
106
|
if (shouldInvoke(time)) {
|
|
107
107
|
return trailingEdge(time)
|
|
@@ -110,7 +110,7 @@ export function _debounce<T extends AnyFunction>(
|
|
|
110
110
|
timerId = startTimer(timerExpired, remainingWait(time))
|
|
111
111
|
}
|
|
112
112
|
|
|
113
|
-
function trailingEdge(time: number) {
|
|
113
|
+
function trailingEdge(time: number): any {
|
|
114
114
|
timerId = undefined
|
|
115
115
|
|
|
116
116
|
// Only invoke if we have `lastArgs` which means `func` has been
|
|
@@ -122,7 +122,7 @@ export function _debounce<T extends AnyFunction>(
|
|
|
122
122
|
return result
|
|
123
123
|
}
|
|
124
124
|
|
|
125
|
-
function cancel() {
|
|
125
|
+
function cancel(): void {
|
|
126
126
|
if (timerId !== undefined) {
|
|
127
127
|
cancelTimer(timerId)
|
|
128
128
|
}
|
|
@@ -130,15 +130,15 @@ export function _debounce<T extends AnyFunction>(
|
|
|
130
130
|
lastArgs = lastCallTime = lastThis = timerId = undefined
|
|
131
131
|
}
|
|
132
132
|
|
|
133
|
-
function flush() {
|
|
133
|
+
function flush(): any {
|
|
134
134
|
return timerId === undefined ? result : trailingEdge(Date.now())
|
|
135
135
|
}
|
|
136
136
|
|
|
137
|
-
function pending() {
|
|
137
|
+
function pending(): boolean {
|
|
138
138
|
return timerId !== undefined
|
|
139
139
|
}
|
|
140
140
|
|
|
141
|
-
function debounced(this: any, ...args: any[]) {
|
|
141
|
+
function debounced(this: any, ...args: any[]): any {
|
|
142
142
|
const time = Date.now()
|
|
143
143
|
const isInvoking = shouldInvoke(time)
|
|
144
144
|
|
package/src/env/buildInfo.ts
CHANGED
|
@@ -12,12 +12,6 @@ export interface BuildInfo {
|
|
|
12
12
|
*/
|
|
13
13
|
tsCommit: UnixTimestampNumber
|
|
14
14
|
|
|
15
|
-
/**
|
|
16
|
-
* Human-readable time of the build. E.g:
|
|
17
|
-
* 2019-06-21 18:35:19
|
|
18
|
-
*/
|
|
19
|
-
tsStr: string
|
|
20
|
-
|
|
21
15
|
repoName: string
|
|
22
16
|
branchName: string
|
|
23
17
|
|
|
@@ -51,8 +45,6 @@ export interface BuildInfo {
|
|
|
51
45
|
export function generateBuildInfoDev(): BuildInfo {
|
|
52
46
|
const now = localTime()
|
|
53
47
|
const ts = now.unix()
|
|
54
|
-
const tsStr = now.toPretty()
|
|
55
|
-
|
|
56
48
|
const rev = 'devRev'
|
|
57
49
|
const branchName = 'devBranch'
|
|
58
50
|
const repoName = 'devRepo'
|
|
@@ -63,7 +55,6 @@ export function generateBuildInfoDev(): BuildInfo {
|
|
|
63
55
|
return {
|
|
64
56
|
ts,
|
|
65
57
|
tsCommit,
|
|
66
|
-
tsStr,
|
|
67
58
|
repoName,
|
|
68
59
|
branchName,
|
|
69
60
|
rev,
|
package/src/http/fetcher.ts
CHANGED
|
@@ -242,16 +242,16 @@ export class JsonSchemaNumberBuilder extends JsonSchemaAnyBuilder<number, JsonSc
|
|
|
242
242
|
return this
|
|
243
243
|
}
|
|
244
244
|
|
|
245
|
-
int32 = () => this.format('int32')
|
|
246
|
-
int64 = () => this.format('int64')
|
|
247
|
-
float = () => this.format('float')
|
|
248
|
-
double = () => this.format('double')
|
|
249
|
-
unixTimestamp = () => this.format('unixTimestamp')
|
|
250
|
-
unixTimestamp2000 = () => this.format('unixTimestamp2000')
|
|
251
|
-
unixTimestampMillis = () => this.format('unixTimestampMillis')
|
|
252
|
-
unixTimestampMillis2000 = () => this.format('unixTimestampMillis2000')
|
|
253
|
-
utcOffset = () => this.format('utcOffset')
|
|
254
|
-
utcOffsetHours = () => this.format('utcOffsetHours')
|
|
245
|
+
int32 = (): this => this.format('int32')
|
|
246
|
+
int64 = (): this => this.format('int64')
|
|
247
|
+
float = (): this => this.format('float')
|
|
248
|
+
double = (): this => this.format('double')
|
|
249
|
+
unixTimestamp = (): this => this.format('unixTimestamp')
|
|
250
|
+
unixTimestamp2000 = (): this => this.format('unixTimestamp2000')
|
|
251
|
+
unixTimestampMillis = (): this => this.format('unixTimestampMillis')
|
|
252
|
+
unixTimestampMillis2000 = (): this => this.format('unixTimestampMillis2000')
|
|
253
|
+
utcOffset = (): this => this.format('utcOffset')
|
|
254
|
+
utcOffsetHours = (): this => this.format('utcOffsetHours')
|
|
255
255
|
}
|
|
256
256
|
|
|
257
257
|
export class JsonSchemaStringBuilder extends JsonSchemaAnyBuilder<string, JsonSchemaString> {
|
|
@@ -283,22 +283,22 @@ export class JsonSchemaStringBuilder extends JsonSchemaAnyBuilder<string, JsonSc
|
|
|
283
283
|
return this
|
|
284
284
|
}
|
|
285
285
|
|
|
286
|
-
email = () => this.format('email')
|
|
287
|
-
date = () => this.format('date')
|
|
288
|
-
url = () => this.format('url')
|
|
289
|
-
ipv4 = () => this.format('ipv4')
|
|
290
|
-
ipv6 = () => this.format('ipv6')
|
|
291
|
-
password = () => this.format('password')
|
|
292
|
-
id = () => this.format('id')
|
|
293
|
-
slug = () => this.format('slug')
|
|
294
|
-
semVer = () => this.format('semVer')
|
|
295
|
-
languageTag = () => this.format('languageTag')
|
|
296
|
-
countryCode = () => this.format('countryCode')
|
|
297
|
-
currency = () => this.format('currency')
|
|
286
|
+
email = (): this => this.format('email')
|
|
287
|
+
date = (): this => this.format('date')
|
|
288
|
+
url = (): this => this.format('url')
|
|
289
|
+
ipv4 = (): this => this.format('ipv4')
|
|
290
|
+
ipv6 = (): this => this.format('ipv6')
|
|
291
|
+
password = (): this => this.format('password')
|
|
292
|
+
id = (): this => this.format('id')
|
|
293
|
+
slug = (): this => this.format('slug')
|
|
294
|
+
semVer = (): this => this.format('semVer')
|
|
295
|
+
languageTag = (): this => this.format('languageTag')
|
|
296
|
+
countryCode = (): this => this.format('countryCode')
|
|
297
|
+
currency = (): this => this.format('currency')
|
|
298
298
|
|
|
299
|
-
trim = (trim = true) => this.transformModify('trim', trim)
|
|
300
|
-
toLowerCase = (toLowerCase = true) => this.transformModify('toLowerCase', toLowerCase)
|
|
301
|
-
toUpperCase = (toUpperCase = true) => this.transformModify('toUpperCase', toUpperCase)
|
|
299
|
+
trim = (trim = true): this => this.transformModify('trim', trim)
|
|
300
|
+
toLowerCase = (toLowerCase = true): this => this.transformModify('toLowerCase', toLowerCase)
|
|
301
|
+
toUpperCase = (toUpperCase = true): this => this.transformModify('toUpperCase', toUpperCase)
|
|
302
302
|
|
|
303
303
|
private transformModify(t: 'trim' | 'toLowerCase' | 'toUpperCase', add: boolean): this {
|
|
304
304
|
if (add) {
|
package/src/lazy.ts
CHANGED
|
@@ -42,8 +42,9 @@ export function _defineLazyProperty<OBJ extends AnyObject>(
|
|
|
42
42
|
propertyName: keyof OBJ,
|
|
43
43
|
fn: AnyFunction,
|
|
44
44
|
): OBJ {
|
|
45
|
-
const define = (value: any) =>
|
|
45
|
+
const define = (value: any): void => {
|
|
46
46
|
Object.defineProperty(obj, propertyName, { value, enumerable: true, writable: true })
|
|
47
|
+
}
|
|
47
48
|
|
|
48
49
|
Object.defineProperty(obj, propertyName, {
|
|
49
50
|
configurable: true,
|
package/src/math/sma.ts
CHANGED
|
@@ -2,7 +2,10 @@
|
|
|
2
2
|
* Implements a Simple Moving Average algorithm.
|
|
3
3
|
*/
|
|
4
4
|
export class SimpleMovingAverage {
|
|
5
|
-
constructor(
|
|
5
|
+
constructor(
|
|
6
|
+
public readonly size: number,
|
|
7
|
+
public readonly data: number[] = [],
|
|
8
|
+
) {}
|
|
6
9
|
|
|
7
10
|
/**
|
|
8
11
|
* Next index of array to push to
|
package/src/object/deepEquals.ts
CHANGED
|
@@ -15,7 +15,7 @@ export function _deepEquals(a: any, b: any): boolean {
|
|
|
15
15
|
const arrB = isArray(b)
|
|
16
16
|
let i
|
|
17
17
|
let length
|
|
18
|
-
let key
|
|
18
|
+
let key: string
|
|
19
19
|
|
|
20
20
|
if (arrA && arrB) {
|
|
21
21
|
length = a.length
|
|
@@ -44,8 +44,8 @@ export function _deepEquals(a: any, b: any): boolean {
|
|
|
44
44
|
for (i = length; i-- !== 0; ) if (!hasProp.call(b, keys[i]!)) return false
|
|
45
45
|
|
|
46
46
|
for (i = length; i-- !== 0; ) {
|
|
47
|
-
key = keys[i]
|
|
48
|
-
if (!_deepEquals(a[key
|
|
47
|
+
key = keys[i]!
|
|
48
|
+
if (!_deepEquals(a[key], b[key])) return false
|
|
49
49
|
}
|
|
50
50
|
|
|
51
51
|
return true
|
|
@@ -123,10 +123,13 @@ export function _mapValues<T extends AnyObject, OUT = T>(
|
|
|
123
123
|
mapper: ObjectMapper<T, any>,
|
|
124
124
|
mutate = false,
|
|
125
125
|
): OUT {
|
|
126
|
-
return Object.entries(obj).reduce(
|
|
127
|
-
map[k
|
|
128
|
-
|
|
129
|
-
|
|
126
|
+
return Object.entries(obj).reduce(
|
|
127
|
+
(map, [k, v]) => {
|
|
128
|
+
map[k as keyof OUT] = mapper(k, v, obj)
|
|
129
|
+
return map
|
|
130
|
+
},
|
|
131
|
+
(mutate ? obj : {}) as OUT,
|
|
132
|
+
)
|
|
130
133
|
}
|
|
131
134
|
|
|
132
135
|
/**
|
|
@@ -165,13 +168,16 @@ export function _mapObject<IN extends AnyObject, OUT>(
|
|
|
165
168
|
obj: IN,
|
|
166
169
|
mapper: ObjectMapper<IN, [key: string, value: any]>,
|
|
167
170
|
): { [P in keyof IN]: OUT } {
|
|
168
|
-
return Object.entries(obj).reduce(
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
171
|
+
return Object.entries(obj).reduce(
|
|
172
|
+
(map, [k, v]) => {
|
|
173
|
+
const r = mapper(k, v, obj) || []
|
|
174
|
+
if (r[0]) {
|
|
175
|
+
;(map[r[0]] as any) = r[1]
|
|
176
|
+
}
|
|
177
|
+
return map
|
|
178
|
+
},
|
|
179
|
+
{} as { [P in keyof IN]: OUT },
|
|
180
|
+
)
|
|
175
181
|
}
|
|
176
182
|
|
|
177
183
|
export function _findKeyByValue<T extends AnyObject>(obj: T, v: ValueOf<T>): keyof T | undefined {
|
package/src/promise/pMap.ts
CHANGED
package/src/seq/seq.ts
CHANGED
|
@@ -15,7 +15,10 @@ import { END, SKIP } from '../types'
|
|
|
15
15
|
* @experimental
|
|
16
16
|
*/
|
|
17
17
|
export class Sequence<T> implements Iterable<T> {
|
|
18
|
-
private constructor(
|
|
18
|
+
private constructor(
|
|
19
|
+
initialValue: T | typeof END,
|
|
20
|
+
private nextFn: AbortableMapper<T, T>,
|
|
21
|
+
) {
|
|
19
22
|
this.currentValue = initialValue
|
|
20
23
|
}
|
|
21
24
|
|
|
@@ -165,7 +168,10 @@ export function _seq<T>(initialValue: T | typeof END, nextFn: AbortableMapper<T,
|
|
|
165
168
|
* @experimental
|
|
166
169
|
*/
|
|
167
170
|
export class AsyncSequence<T> implements AsyncIterable<T> {
|
|
168
|
-
private constructor(
|
|
171
|
+
private constructor(
|
|
172
|
+
initialValue: T | typeof END,
|
|
173
|
+
private nextFn: AbortableAsyncMapper<T, T>,
|
|
174
|
+
) {
|
|
169
175
|
this.currentValue = initialValue
|
|
170
176
|
}
|
|
171
177
|
|
|
@@ -41,7 +41,7 @@ export interface ReadingTimeResult extends ReadingTimeStats {
|
|
|
41
41
|
|
|
42
42
|
type WordBoundFunction = (char: string) => boolean
|
|
43
43
|
|
|
44
|
-
function codeIsInRanges(num: number, arrayOfRanges: number[][]) {
|
|
44
|
+
function codeIsInRanges(num: number, arrayOfRanges: number[][]): boolean {
|
|
45
45
|
return arrayOfRanges.some(([lowerBound, upperBound]) => lowerBound! <= num && num <= upperBound!)
|
|
46
46
|
}
|
|
47
47
|
|
package/src/zod/zod.util.ts
CHANGED
|
@@ -44,7 +44,11 @@ export function zSafeValidate<T>(
|
|
|
44
44
|
}
|
|
45
45
|
|
|
46
46
|
export class ZodValidationError<T> extends ZodError<T> {
|
|
47
|
-
constructor(
|
|
47
|
+
constructor(
|
|
48
|
+
issues: ZodIssue[],
|
|
49
|
+
public value: T,
|
|
50
|
+
public schema: ZodSchema<T>,
|
|
51
|
+
) {
|
|
48
52
|
super(issues)
|
|
49
53
|
}
|
|
50
54
|
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
import { LocalDateUnit, LocalDate, LocalDateConfig } from '../datetime/localDate'
|
|
2
|
-
|
|
3
|
-
export class LazyLocalDate {
|
|
4
|
-
constructor(private str: string) {}
|
|
5
|
-
|
|
6
|
-
private ld?: LocalDate
|
|
7
|
-
|
|
8
|
-
eq(d: LocalDateConfig): boolean {
|
|
9
|
-
if (typeof d === 'string') return d === this.str
|
|
10
|
-
this.ld ||= LocalDate.of(this.str)
|
|
11
|
-
return this.ld.isSame(d)
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
lt(d: LocalDateConfig): boolean {
|
|
15
|
-
return this.cmp(d) === -1
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
lte(d: LocalDateConfig): boolean {
|
|
19
|
-
return this.cmp(d) <= 0
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
gt(d: LocalDateConfig): boolean {
|
|
23
|
-
return this.cmp(d) === 1
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
gte(d: LocalDateConfig): boolean {
|
|
27
|
-
return this.cmp(d) >= 0
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
cmp(d: LocalDateConfig): -1 | 0 | 1 {
|
|
31
|
-
if (typeof d === 'string') {
|
|
32
|
-
return this.str < d ? -1 : this.str > d ? 1 : 0
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
this.ld ||= LocalDate.of(this.str)
|
|
36
|
-
return this.ld.cmp(d)
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
absDiff(d: LocalDateConfig, unit: LocalDateUnit): number {
|
|
40
|
-
return Math.abs(this.diff(d, unit))
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
diff(d: LocalDateConfig, unit: LocalDateUnit): number {
|
|
44
|
-
this.ld ||= LocalDate.of(this.str)
|
|
45
|
-
return this.ld.diff(d, unit)
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
add(num: number, unit: LocalDateUnit): LocalDate {
|
|
49
|
-
this.ld ||= LocalDate.of(this.str)
|
|
50
|
-
return this.ld.add(num, unit)
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
subtract(num: number, unit: LocalDateUnit): LocalDate {
|
|
54
|
-
return this.add(-num, unit)
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
clone(): LazyLocalDate {
|
|
58
|
-
return new LazyLocalDate(this.str)
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
toDate(): Date {
|
|
62
|
-
this.ld ||= LocalDate.of(this.str)
|
|
63
|
-
return this.ld.toDate()
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
toString(): string {
|
|
67
|
-
return this.str
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
toJSON(): string {
|
|
71
|
-
return this.str
|
|
72
|
-
}
|
|
73
|
-
}
|