@muspellheim/shared 0.6.1 → 0.8.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.
Files changed (46) hide show
  1. package/LICENSE.txt +1 -1
  2. package/README.md +11 -13
  3. package/dist/shared.d.ts +423 -0
  4. package/dist/shared.js +535 -0
  5. package/dist/shared.umd.cjs +1 -0
  6. package/package.json +27 -23
  7. package/.prettierignore +0 -3
  8. package/.prettierrc +0 -5
  9. package/deno.json +0 -15
  10. package/deno.mk +0 -68
  11. package/eslint.config.js +0 -23
  12. package/lib/assert.js +0 -15
  13. package/lib/browser/components.js +0 -165
  14. package/lib/browser/index.js +0 -3
  15. package/lib/color.js +0 -137
  16. package/lib/configurable-responses.js +0 -69
  17. package/lib/feature-toggle.js +0 -9
  18. package/lib/health.js +0 -510
  19. package/lib/index.js +0 -23
  20. package/lib/lang.js +0 -100
  21. package/lib/logging.js +0 -599
  22. package/lib/long-polling-client.js +0 -186
  23. package/lib/message-client.js +0 -68
  24. package/lib/messages.js +0 -68
  25. package/lib/metrics.js +0 -120
  26. package/lib/node/actuator-controller.js +0 -102
  27. package/lib/node/configuration-properties.js +0 -291
  28. package/lib/node/handler.js +0 -25
  29. package/lib/node/index.js +0 -9
  30. package/lib/node/logging.js +0 -60
  31. package/lib/node/long-polling.js +0 -83
  32. package/lib/node/sse-emitter.js +0 -104
  33. package/lib/node/static-files-controller.js +0 -15
  34. package/lib/output-tracker.js +0 -89
  35. package/lib/service-locator.js +0 -44
  36. package/lib/sse-client.js +0 -163
  37. package/lib/stop-watch.js +0 -54
  38. package/lib/store.js +0 -129
  39. package/lib/time.js +0 -445
  40. package/lib/util.js +0 -380
  41. package/lib/validation.js +0 -290
  42. package/lib/vector.js +0 -194
  43. package/lib/vitest/equality-testers.js +0 -19
  44. package/lib/vitest/index.js +0 -1
  45. package/lib/web-socket-client.js +0 -262
  46. package/tsconfig.json +0 -13
package/lib/time.js DELETED
@@ -1,445 +0,0 @@
1
- // Copyright (c) 2023-2024 Falko Schumann. All rights reserved. MIT license.
2
-
3
- /**
4
- * An API for time and durations.
5
- *
6
- * Portated from
7
- * [Java Time](https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/time/package-summary.html).
8
- *
9
- * @module
10
- */
11
-
12
- /**
13
- * A clock provides access to the current timestamp.
14
- */
15
- export class Clock {
16
- /**
17
- * Creates a clock using system clock.
18
- *
19
- * @return {Clock} A clock that uses system clock.
20
- */
21
- static system() {
22
- return new Clock();
23
- }
24
-
25
- /**
26
- * Creates a clock using a fixed date.
27
- *
28
- * @param {Date} [date='2024-02-21T19:16:00Z'] The fixed date of the clock.
29
- * @return {Clock} A clock that returns alaways a fixed date.
30
- * @see Clock#add
31
- */
32
- static fixed(date = new Date('2024-02-21T19:16:00Z')) {
33
- return new Clock(date);
34
- }
35
-
36
- #date;
37
-
38
- /** @hideconstructor */
39
- constructor(/** @type {Date} */ date) {
40
- this.#date = date;
41
- }
42
-
43
- /**
44
- * Returns the current timestamp of the clock.
45
- *
46
- * @return {Date} The current timestamp.
47
- */
48
- date() {
49
- return this.#date ? new Date(this.#date) : new Date();
50
- }
51
-
52
- /**
53
- * Returns the current timestamp of the clock in milliseconds.
54
- *
55
- * @return {number} The current timestamp in milliseconds.
56
- */
57
- millis() {
58
- return this.date().getTime();
59
- }
60
-
61
- /**
62
- * Adds a duration to the current timestamp of the clock.
63
- *
64
- * @param {Duration|string|number} offsetDuration The duration or number of
65
- * millis to add.
66
- */
67
- add(offsetDuration) {
68
- const current = this.date();
69
- this.#date = new Date(
70
- current.getTime() + new Duration(offsetDuration).millis,
71
- );
72
- }
73
- }
74
-
75
- /**
76
- * A duration is a time-based amount of time, such as '34.5 seconds'.
77
- */
78
- export class Duration {
79
- /**
80
- * Creates a duration with zero value.
81
- *
82
- * @return {Duration} A zero duration.
83
- */
84
- static zero() {
85
- return new Duration();
86
- }
87
-
88
- /**
89
- * Creates a duration from a ISO 8601 string like `[-]P[dD]T[hH][mM][s[.f]S]`.
90
- *
91
- * @param {string} isoString The ISO 8601 string to parse.
92
- * @return {Duration} The parsed duration.
93
- */
94
- static parse(isoString) {
95
- const match = isoString.match(
96
- /^(-)?P(?:(\d+)D)?T(?:(\d+)H)?(?:(\d+)M)?(?:(\d+\.?\d*)S)?$/,
97
- );
98
- if (match == null) {
99
- return new Duration(NaN);
100
- }
101
-
102
- const sign = match[1] === '-' ? -1 : 1;
103
- const days = Number(match[2] || 0);
104
- const hours = Number(match[3] || 0);
105
- const minutes = Number(match[4] || 0);
106
- const seconds = Number(match[5] || 0);
107
- const millis = Number(match[6] || 0);
108
- return new Duration(
109
- sign *
110
- (days * 86400000 +
111
- hours * 3600000 +
112
- minutes * 60000 +
113
- seconds * 1000 +
114
- millis),
115
- );
116
- }
117
-
118
- /**
119
- * Obtains a Duration representing the duration between two temporal objects.
120
- *
121
- * @param {Date|number} startInclusive The start date or millis, inclusive.
122
- * @param {Date|number} endExclusive The end date or millis, exclusive.
123
- * @return {Duration} The duration between the two dates.
124
- */
125
- static between(startInclusive, endExclusive) {
126
- return new Duration(endExclusive - startInclusive);
127
- }
128
-
129
- /**
130
- * The total length of the duration in milliseconds.
131
- *
132
- * @type {number}
133
- */
134
- millis;
135
-
136
- /**
137
- * Creates a duration.
138
- *
139
- * The duration is zero if no value is provided.
140
- *
141
- * @param {number|string|Duration} [value] The duration in millis, an ISO 8601
142
- * string or another duration.
143
- */
144
- constructor(value) {
145
- if (value === null || arguments.length === 0) {
146
- this.millis = 0;
147
- } else if (typeof value === 'string') {
148
- this.millis = Duration.parse(value).millis;
149
- } else if (typeof value === 'number') {
150
- if (Number.isFinite(value)) {
151
- this.millis = Math.trunc(value);
152
- } else {
153
- this.millis = NaN;
154
- }
155
- } else if (value instanceof Duration) {
156
- this.millis = value.millis;
157
- } else {
158
- this.millis = NaN;
159
- }
160
- }
161
-
162
- /**
163
- * Gets the number of days in the duration.
164
- *
165
- * @type {number}
166
- * @readonly
167
- */
168
- get days() {
169
- return Math.trunc(this.millis / 86400000);
170
- }
171
-
172
- /**
173
- * Extracts the number of days in the duration.
174
- *
175
- * @type {number}
176
- * @readonly
177
- */
178
- get daysPart() {
179
- const value = this.millis / 86400000;
180
- return this.isNegative() ? Math.ceil(value) : Math.floor(value);
181
- }
182
-
183
- /**
184
- * Gets the number of hours in the duration.
185
- *
186
- * @type {number}
187
- * @readonly
188
- */
189
- get hours() {
190
- return Math.trunc(this.millis / 3600000);
191
- }
192
-
193
- /**
194
- * Extracts the number of hours in the duration.
195
- *
196
- * @type {number}
197
- * @readonly
198
- */
199
- get hoursPart() {
200
- const value = (this.millis - this.daysPart * 86400000) / 3600000;
201
- return this.isNegative() ? Math.ceil(value) : Math.floor(value);
202
- }
203
-
204
- /**
205
- * Gets the number of minutes in the duration.
206
- *
207
- * @type {number}
208
- * @readonly
209
- */
210
- get minutes() {
211
- return Math.trunc(this.millis / 60000);
212
- }
213
-
214
- /**
215
- * Extracts the number of minutes in the duration.
216
- *
217
- * @type {number}
218
- * @readonly
219
- */
220
- get minutesPart() {
221
- const value =
222
- (this.millis - this.daysPart * 86400000 - this.hoursPart * 3600000) /
223
- 60000;
224
- return this.isNegative() ? Math.ceil(value) : Math.floor(value);
225
- }
226
-
227
- /**
228
- * Gets the number of seconds in the duration.
229
- *
230
- * @type {number}
231
- * @readonly
232
- */
233
- get seconds() {
234
- return Math.trunc(this.millis / 1000);
235
- }
236
-
237
- /**
238
- * Extracts the number of seconds in the duration.
239
- *
240
- * @type {number}
241
- * @readonly
242
- */
243
- get secondsPart() {
244
- const value =
245
- (this.millis -
246
- this.daysPart * 86400000 -
247
- this.hoursPart * 3600000 -
248
- this.minutesPart * 60000) /
249
- 1000;
250
- return this.isNegative() ? Math.ceil(value) : Math.floor(value);
251
- }
252
-
253
- /**
254
- * Gets the number of milliseconds in the duration.
255
- *
256
- * @type {number}
257
- * @readonly
258
- */
259
- get millisPart() {
260
- const value =
261
- this.millis -
262
- this.daysPart * 86400000 -
263
- this.hoursPart * 3600000 -
264
- this.minutesPart * 60000 -
265
- this.secondsPart * 1000;
266
- return this.isNegative() ? Math.ceil(value) : Math.floor(value);
267
- }
268
-
269
- /**
270
- * Checks if the duration is zero.
271
- *
272
- * @return {boolean}
273
- */
274
- isZero() {
275
- return this.millis === 0;
276
- }
277
-
278
- /**
279
- * Checks if the duration is negative.
280
- *
281
- * @return {boolean}
282
- */
283
- isNegative() {
284
- return this.millis < 0;
285
- }
286
-
287
- /**
288
- * Checks if the duration is positive.
289
- *
290
- * @return {boolean}
291
- */
292
- isPositive() {
293
- return this.millis > 0;
294
- }
295
-
296
- /**
297
- * Returns a copy of this duration with a positive length.
298
- *
299
- * @return {Duration} The absolute value of the duration.
300
- */
301
- absolutized() {
302
- return new Duration(Math.abs(this.millis));
303
- }
304
-
305
- /**
306
- * Returns a copy of this duration with length negated.
307
- *
308
- * @return {Duration} The negated value of the duration.
309
- */
310
- negated() {
311
- return new Duration(-this.millis);
312
- }
313
-
314
- /**
315
- * Returns a copy of this duration with the specified duration added.
316
- *
317
- * @param {Duration|string|number} duration The duration to add or number of
318
- * millis.
319
- * @return {Duration} The new duration.
320
- */
321
- plus(duration) {
322
- return new Duration(this.millis + new Duration(duration).millis);
323
- }
324
-
325
- /**
326
- * Returns a copy of this duration with the specified duration subtracted.
327
- *
328
- * @param {Duration|string|number} duration The duration to subtract or number
329
- * of millis.
330
- * @return {Duration} The new duration.
331
- */
332
- minus(duration) {
333
- return new Duration(this.millis - new Duration(duration));
334
- }
335
-
336
- /**
337
- * Returns a copy of this duration multiplied by the scalar.
338
- *
339
- * @param {number} multiplicand The value to multiply the duration by.
340
- * @return {Duration} The new duration.
341
- */
342
- multipliedBy(multiplicand) {
343
- return new Duration(this.millis * multiplicand);
344
- }
345
-
346
- /**
347
- * Returns a copy of this duration divided by the specified value.
348
- *
349
- * @param {number} divisor The value to divide the duration by.
350
- * @return {Duration} The new duration.
351
- */
352
- dividedBy(divisor) {
353
- return new Duration(this.millis / divisor);
354
- }
355
-
356
- /**
357
- * Returns a string representation of this duration using ISO 8601, such as
358
- * `PT8H6M12.345S`.
359
- *
360
- * @return {string} The ISO 8601 string representation of the duration.
361
- */
362
- toISOString() {
363
- if (this.isZero()) {
364
- return 'PT0S';
365
- }
366
-
367
- const value = this.absolutized();
368
-
369
- let period = 'PT';
370
- const days = value.daysPart;
371
- const hours = value.hoursPart;
372
- if (days > 0 || hours > 0) {
373
- period += `${days * 24 + hours}H`;
374
- }
375
- const minutes = value.minutesPart;
376
- if (minutes > 0) {
377
- period += `${minutes}M`;
378
- }
379
- const seconds = value.secondsPart;
380
- const millis = value.millisPart;
381
- if (seconds > 0 || millis > 0) {
382
- period += `${seconds + millis / 1000}S`;
383
- }
384
- if (this.isNegative()) {
385
- period = `-${period}`;
386
- }
387
- return period;
388
- }
389
-
390
- /**
391
- * Returns a parsable string representation of this duration.
392
- *
393
- * @return {string} The string representation of this duration.
394
- */
395
- toJSON() {
396
- return this.toISOString();
397
- }
398
-
399
- /**
400
- * Returns a string representation of this duration, such as `08:06:12`.
401
- *
402
- * @param {object} options The options to create the string.
403
- * @param {string} [options.style='medium'] The style of the string (`short`,
404
- * `medium`, `long`).
405
- * @return {string} The string representation of the duration.
406
- */
407
- toString({ style = 'medium' } = {}) {
408
- if (Number.isNaN(this.valueOf())) {
409
- return 'Invalid Duration';
410
- }
411
-
412
- const value = this.absolutized();
413
- const hours = String(Math.floor(value.hours)).padStart(2, '0');
414
- const minutes = String(value.minutesPart).padStart(2, '0');
415
- const seconds = String(value.secondsPart).padStart(2, '0');
416
- let result = `${hours}:${minutes}`;
417
- if (style === 'medium' || style === 'long') {
418
- result += `:${seconds}`;
419
- }
420
- if (style === 'long') {
421
- result += `.${String(value.millisPart).padStart(3, '0')}`;
422
- }
423
- if (this.isNegative()) {
424
- result = `-${result}`;
425
- }
426
- return result;
427
- }
428
-
429
- /**
430
- * Returns the value of the duration in milliseconds.
431
- *
432
- * @return {number} The value of the duration in milliseconds.
433
- */
434
- valueOf() {
435
- return this.millis;
436
- }
437
-
438
- [Symbol.toPrimitive](hint) {
439
- if (hint === 'number') {
440
- return this.valueOf();
441
- } else {
442
- return this.toString();
443
- }
444
- }
445
- }