@develia/commons 0.5.0 → 0.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/parse.d.ts +62 -44
- package/dist/parse.d.ts.map +1 -1
- package/dist/parse.js +95 -59
- package/dist/parse.js.map +1 -1
- package/dist/range.d.ts +2 -10
- package/dist/range.d.ts.map +1 -1
- package/dist/range.js +0 -12
- package/dist/range.js.map +1 -1
- package/dist/stopwatch.d.ts +2 -2
- package/dist/stopwatch.d.ts.map +1 -1
- package/dist/stopwatch.js +9 -9
- package/dist/stopwatch.js.map +1 -1
- package/dist/string.d.ts +10 -0
- package/dist/string.d.ts.map +1 -1
- package/dist/string.js +20 -0
- package/dist/string.js.map +1 -1
- package/dist/timespan.d.ts +10 -15
- package/dist/timespan.d.ts.map +1 -1
- package/dist/timespan.js +10 -15
- package/dist/timespan.js.map +1 -1
- package/dist/triggers.d.ts +6 -15
- package/dist/triggers.d.ts.map +1 -1
- package/dist/triggers.js +8 -22
- package/dist/triggers.js.map +1 -1
- package/dist/uuid.d.ts +11 -11
- package/dist/uuid.d.ts.map +1 -1
- package/dist/uuid.js +18 -18
- package/dist/uuid.js.map +1 -1
- package/package.json +1 -1
- package/src/array.ts +0 -0
- package/src/async-pool-executor.ts +0 -0
- package/src/browser/form-utilities.ts +0 -0
- package/src/browser/geo-location.ts +0 -0
- package/src/browser/index.ts +0 -0
- package/src/browser/native-bridge.ts +0 -0
- package/src/cancellable-promise.ts +0 -0
- package/src/clean-url-search-params.ts +0 -0
- package/src/collections/cache-dictionary.ts +0 -0
- package/src/collections/default-map.ts +0 -0
- package/src/collections/default-weak-map.ts +0 -0
- package/src/collections/index.ts +0 -0
- package/src/draft.ts +0 -0
- package/src/event-bus.ts +0 -0
- package/src/functions.ts +0 -0
- package/src/key-value-pair.ts +0 -0
- package/src/lazy.ts +0 -0
- package/src/math.ts +0 -0
- package/src/order.ts +0 -0
- package/src/parse.ts +108 -66
- package/src/patch.ts +0 -0
- package/src/range.ts +2 -16
- package/src/stopwatch.ts +9 -9
- package/src/string.ts +24 -0
- package/src/timer.ts +0 -0
- package/src/timespan.ts +10 -15
- package/src/triggers.ts +10 -24
- package/src/type-code.ts +0 -0
- package/src/type.ts +0 -0
- package/src/types.ts +0 -0
- package/src/uuid.ts +19 -19
package/src/triggers.ts
CHANGED
|
@@ -7,7 +7,8 @@ import type {Nullable, Supplier} from './types.js';
|
|
|
7
7
|
*/
|
|
8
8
|
export class TimeTrigger<T> {
|
|
9
9
|
private callback: Supplier<T | Promise<T>>;
|
|
10
|
-
|
|
10
|
+
/** Time that must pass between two runs. */
|
|
11
|
+
public interval: TimeSpan;
|
|
11
12
|
private lastRunTime: Nullable<number>;
|
|
12
13
|
|
|
13
14
|
public constructor(callback: Supplier<T | Promise<T>>, interval: TimeSpan) {
|
|
@@ -46,19 +47,6 @@ export class TimeTrigger<T> {
|
|
|
46
47
|
this.callback = callback;
|
|
47
48
|
}
|
|
48
49
|
|
|
49
|
-
/**
|
|
50
|
-
* Gets the configured time interval.
|
|
51
|
-
*/
|
|
52
|
-
public getInterval(): TimeSpan {
|
|
53
|
-
return this.interval;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* Replaces the configured time interval.
|
|
58
|
-
*/
|
|
59
|
-
public setInterval(interval: TimeSpan): void {
|
|
60
|
-
this.interval = interval;
|
|
61
|
-
}
|
|
62
50
|
|
|
63
51
|
|
|
64
52
|
}
|
|
@@ -68,12 +56,12 @@ export class TimeTrigger<T> {
|
|
|
68
56
|
*/
|
|
69
57
|
export class CountTrigger<T> {
|
|
70
58
|
private callback: Supplier<T | Promise<T>>;
|
|
71
|
-
private
|
|
59
|
+
private _interval: number = 1;
|
|
72
60
|
private checkCount: number = 0;
|
|
73
61
|
|
|
74
62
|
public constructor(callback: Supplier<T | Promise<T>>, interval: number) {
|
|
75
63
|
this.callback = callback;
|
|
76
|
-
this.
|
|
64
|
+
this.interval = interval;
|
|
77
65
|
}
|
|
78
66
|
|
|
79
67
|
/**
|
|
@@ -82,7 +70,7 @@ export class CountTrigger<T> {
|
|
|
82
70
|
public async check(): Promise<Result<T>> {
|
|
83
71
|
this.checkCount++;
|
|
84
72
|
|
|
85
|
-
if (this.checkCount >= this.
|
|
73
|
+
if (this.checkCount >= this._interval) {
|
|
86
74
|
return {success: true, output: await this.trigger()};
|
|
87
75
|
}
|
|
88
76
|
|
|
@@ -105,22 +93,20 @@ export class CountTrigger<T> {
|
|
|
105
93
|
}
|
|
106
94
|
|
|
107
95
|
/**
|
|
108
|
-
*
|
|
96
|
+
* Number of checks after which the callback runs.
|
|
109
97
|
*/
|
|
110
|
-
public
|
|
111
|
-
return this.
|
|
98
|
+
public get interval(): number {
|
|
99
|
+
return this._interval;
|
|
112
100
|
}
|
|
113
101
|
|
|
114
102
|
/**
|
|
115
|
-
* Replaces the configured check interval.
|
|
116
|
-
*
|
|
117
103
|
* @throws {RangeError} When the interval is less than one.
|
|
118
104
|
*/
|
|
119
|
-
public
|
|
105
|
+
public set interval(interval: number) {
|
|
120
106
|
if (interval < 1) {
|
|
121
107
|
throw new RangeError('Interval must be greater than zero.');
|
|
122
108
|
}
|
|
123
109
|
|
|
124
|
-
this.
|
|
110
|
+
this._interval = interval;
|
|
125
111
|
}
|
|
126
112
|
}
|
package/src/type-code.ts
CHANGED
|
File without changes
|
package/src/type.ts
CHANGED
|
File without changes
|
package/src/types.ts
CHANGED
|
File without changes
|
package/src/uuid.ts
CHANGED
|
@@ -11,7 +11,7 @@ const MAX_V7_MILLISECONDS = 0xffffffffffff;
|
|
|
11
11
|
* such as `019a4f8b-4bae-7d2e-9f10-4a5b6c7d8e9f`.
|
|
12
12
|
*
|
|
13
13
|
* It serializes to its string with `JSON.stringify`, so DTOs carry it as text; read those
|
|
14
|
-
* strings back with {@link Uuid.parse} or {@link Uuid.
|
|
14
|
+
* strings back with {@link Uuid.parse} or {@link Uuid.tryParse}.
|
|
15
15
|
*/
|
|
16
16
|
export default class Uuid {
|
|
17
17
|
private readonly value: string;
|
|
@@ -73,44 +73,44 @@ export default class Uuid {
|
|
|
73
73
|
/**
|
|
74
74
|
* Reads a UUID in canonical form, in any letter case, as {@link Uuid.isValid} accepts it.
|
|
75
75
|
*
|
|
76
|
-
* @
|
|
76
|
+
* @throws {SyntaxError} If the value is not a UUID.
|
|
77
77
|
*/
|
|
78
|
-
static parse(value:
|
|
79
|
-
|
|
80
|
-
|
|
78
|
+
static parse(value: string): Uuid {
|
|
79
|
+
const uuid = Uuid.tryParse(value);
|
|
80
|
+
if (uuid === undefined) {
|
|
81
|
+
throw new SyntaxError(`Invalid UUID "${value}".`);
|
|
81
82
|
}
|
|
82
83
|
|
|
83
|
-
return
|
|
84
|
+
return uuid;
|
|
84
85
|
}
|
|
85
86
|
|
|
86
87
|
/**
|
|
87
|
-
* Reads a UUID in canonical form, in any letter case.
|
|
88
|
+
* Reads a UUID in canonical form, in any letter case, as {@link Uuid.isValid} accepts it.
|
|
88
89
|
*
|
|
89
|
-
* @
|
|
90
|
+
* @returns The UUID, or `undefined` when the value is not one.
|
|
90
91
|
*/
|
|
91
|
-
static
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
throw new SyntaxError(`Invalid UUID "${value}".`);
|
|
92
|
+
static tryParse(value: unknown): Uuid | undefined {
|
|
93
|
+
if (typeof value !== 'string' || !Uuid.isValid(value)) {
|
|
94
|
+
return undefined;
|
|
95
95
|
}
|
|
96
96
|
|
|
97
|
-
return
|
|
97
|
+
return new Uuid(value.toLowerCase());
|
|
98
98
|
}
|
|
99
99
|
|
|
100
100
|
/**
|
|
101
|
-
*
|
|
101
|
+
* The RFC 9562 version, from 1 to 8, or 0 for the Nil UUID and 15 for the Max UUID.
|
|
102
102
|
*/
|
|
103
|
-
|
|
103
|
+
get version(): number {
|
|
104
104
|
return Number.parseInt(this.value.charAt(14), 16);
|
|
105
105
|
}
|
|
106
106
|
|
|
107
107
|
/**
|
|
108
|
-
*
|
|
108
|
+
* The moment a version 7 UUID encodes, with millisecond precision.
|
|
109
109
|
*
|
|
110
|
-
*
|
|
110
|
+
* It is `null` for other versions.
|
|
111
111
|
*/
|
|
112
|
-
|
|
113
|
-
if (this.
|
|
112
|
+
get date(): Nullable<Date> {
|
|
113
|
+
if (this.version !== 7) {
|
|
114
114
|
return null;
|
|
115
115
|
}
|
|
116
116
|
|