@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.
Files changed (60) hide show
  1. package/dist/parse.d.ts +62 -44
  2. package/dist/parse.d.ts.map +1 -1
  3. package/dist/parse.js +95 -59
  4. package/dist/parse.js.map +1 -1
  5. package/dist/range.d.ts +2 -10
  6. package/dist/range.d.ts.map +1 -1
  7. package/dist/range.js +0 -12
  8. package/dist/range.js.map +1 -1
  9. package/dist/stopwatch.d.ts +2 -2
  10. package/dist/stopwatch.d.ts.map +1 -1
  11. package/dist/stopwatch.js +9 -9
  12. package/dist/stopwatch.js.map +1 -1
  13. package/dist/string.d.ts +10 -0
  14. package/dist/string.d.ts.map +1 -1
  15. package/dist/string.js +20 -0
  16. package/dist/string.js.map +1 -1
  17. package/dist/timespan.d.ts +10 -15
  18. package/dist/timespan.d.ts.map +1 -1
  19. package/dist/timespan.js +10 -15
  20. package/dist/timespan.js.map +1 -1
  21. package/dist/triggers.d.ts +6 -15
  22. package/dist/triggers.d.ts.map +1 -1
  23. package/dist/triggers.js +8 -22
  24. package/dist/triggers.js.map +1 -1
  25. package/dist/uuid.d.ts +11 -11
  26. package/dist/uuid.d.ts.map +1 -1
  27. package/dist/uuid.js +18 -18
  28. package/dist/uuid.js.map +1 -1
  29. package/package.json +1 -1
  30. package/src/array.ts +0 -0
  31. package/src/async-pool-executor.ts +0 -0
  32. package/src/browser/form-utilities.ts +0 -0
  33. package/src/browser/geo-location.ts +0 -0
  34. package/src/browser/index.ts +0 -0
  35. package/src/browser/native-bridge.ts +0 -0
  36. package/src/cancellable-promise.ts +0 -0
  37. package/src/clean-url-search-params.ts +0 -0
  38. package/src/collections/cache-dictionary.ts +0 -0
  39. package/src/collections/default-map.ts +0 -0
  40. package/src/collections/default-weak-map.ts +0 -0
  41. package/src/collections/index.ts +0 -0
  42. package/src/draft.ts +0 -0
  43. package/src/event-bus.ts +0 -0
  44. package/src/functions.ts +0 -0
  45. package/src/key-value-pair.ts +0 -0
  46. package/src/lazy.ts +0 -0
  47. package/src/math.ts +0 -0
  48. package/src/order.ts +0 -0
  49. package/src/parse.ts +108 -66
  50. package/src/patch.ts +0 -0
  51. package/src/range.ts +2 -16
  52. package/src/stopwatch.ts +9 -9
  53. package/src/string.ts +24 -0
  54. package/src/timer.ts +0 -0
  55. package/src/timespan.ts +10 -15
  56. package/src/triggers.ts +10 -24
  57. package/src/type-code.ts +0 -0
  58. package/src/type.ts +0 -0
  59. package/src/types.ts +0 -0
  60. 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
- private interval: TimeSpan;
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 interval: number = 1;
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.setInterval(interval);
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.interval) {
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
- * Gets the configured check interval.
96
+ * Number of checks after which the callback runs.
109
97
  */
110
- public getInterval(): number {
111
- return this.interval;
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 setInterval(interval: number): void {
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.interval = interval;
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.parseOrThrow}.
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
- * @returns The UUID, or `null` when the value is not one.
76
+ * @throws {SyntaxError} If the value is not a UUID.
77
77
  */
78
- static parse(value: unknown): Nullable<Uuid> {
79
- if (typeof value !== 'string' || !Uuid.isValid(value)) {
80
- return null;
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 new Uuid(value.toLowerCase());
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
- * @throws {SyntaxError} If the value is not a UUID.
90
+ * @returns The UUID, or `undefined` when the value is not one.
90
91
  */
91
- static parseOrThrow(value: string): Uuid {
92
- const uuid = Uuid.parse(value);
93
- if (uuid === null) {
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 uuid;
97
+ return new Uuid(value.toLowerCase());
98
98
  }
99
99
 
100
100
  /**
101
- * Returns the RFC 9562 version, from 1 to 8, or 0 for the Nil UUID and 15 for the Max UUID.
101
+ * The RFC 9562 version, from 1 to 8, or 0 for the Nil UUID and 15 for the Max UUID.
102
102
  */
103
- getVersion(): number {
103
+ get version(): number {
104
104
  return Number.parseInt(this.value.charAt(14), 16);
105
105
  }
106
106
 
107
107
  /**
108
- * Returns the moment a version 7 UUID encodes, with millisecond precision.
108
+ * The moment a version 7 UUID encodes, with millisecond precision.
109
109
  *
110
- * @returns The moment, or `null` for other versions.
110
+ * It is `null` for other versions.
111
111
  */
112
- getDate(): Nullable<Date> {
113
- if (this.getVersion() !== 7) {
112
+ get date(): Nullable<Date> {
113
+ if (this.version !== 7) {
114
114
  return null;
115
115
  }
116
116