@everyonesoftware/common 1.0.0 → 3.0.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 (60) hide show
  1. package/.github/workflows/publish.yml +54 -38
  2. package/package.json +9 -2
  3. package/sources/asyncIterator.ts +436 -436
  4. package/sources/asyncIteratorToJavascriptAsyncIteratorAdapter.ts +47 -47
  5. package/sources/asyncResult.ts +95 -95
  6. package/sources/byteList.ts +201 -201
  7. package/sources/byteListStream.ts +120 -120
  8. package/sources/byteReadStream.ts +23 -23
  9. package/sources/byteWriteStream.ts +15 -15
  10. package/sources/characterList.ts +194 -194
  11. package/sources/characterListStream.ts +150 -150
  12. package/sources/characterReadStream.ts +80 -80
  13. package/sources/characterReadStreamIterator.ts +127 -127
  14. package/sources/concatenateIterable.ts +118 -118
  15. package/sources/concatenateIterator.ts +164 -164
  16. package/sources/currentProcess.ts +157 -157
  17. package/sources/dateTime.ts +129 -129
  18. package/sources/depthFirstSearch.ts +229 -229
  19. package/sources/flatMapIterable.ts +103 -103
  20. package/sources/flatMapIterator.ts +151 -151
  21. package/sources/generator.ts +250 -250
  22. package/sources/index.ts +1 -1
  23. package/sources/iterator.ts +480 -480
  24. package/sources/javascriptAsyncIteratorToAsyncIteratorAdapter.ts +123 -123
  25. package/sources/javascriptSetSet.ts +133 -133
  26. package/sources/listQueue.ts +61 -61
  27. package/sources/listStack.ts +61 -61
  28. package/sources/luxonDateTime.ts +108 -108
  29. package/sources/mapAsyncIterator.ts +140 -140
  30. package/sources/mutableMap.ts +291 -291
  31. package/sources/node.ts +36 -36
  32. package/sources/promiseAsyncResult.ts +173 -173
  33. package/sources/queue.ts +48 -48
  34. package/sources/recreationDotGovClient.ts +258 -258
  35. package/sources/searchControl.ts +41 -41
  36. package/sources/set.ts +243 -243
  37. package/sources/skipAsyncIterator.ts +144 -144
  38. package/sources/stack.ts +47 -47
  39. package/sources/syncResult.ts +299 -299
  40. package/sources/takeAsyncIterator.ts +140 -140
  41. package/sources/whereAsyncIterator.ts +142 -142
  42. package/sources/wonderlandTrailClient.ts +1502 -1502
  43. package/tests/assertTestTests.ts +74 -74
  44. package/tests/byteListStreamTests.ts +389 -389
  45. package/tests/byteListTests.ts +26 -26
  46. package/tests/characterListStreamTests.ts +390 -390
  47. package/tests/characterListTests.ts +249 -249
  48. package/tests/dateTimeTests.ts +29 -29
  49. package/tests/depthFirstSearchTests.ts +105 -105
  50. package/tests/generatorTests.ts +85 -85
  51. package/tests/mutableMapTests.ts +153 -153
  52. package/tests/promiseAsyncResultTests.ts +687 -687
  53. package/tests/queueTests.ts +28 -28
  54. package/tests/recreationDotGovClientTests.ts +190 -190
  55. package/tests/setTests.ts +139 -139
  56. package/tests/stackTests.ts +65 -65
  57. package/tests/syncResultTests.ts +1250 -1250
  58. package/tests/wonderlandTrailClientTests.ts +451 -451
  59. package/tsconfig.json +3 -0
  60. package/tsup.config.ts +12 -12
@@ -1,62 +1,62 @@
1
- import { EmptyError } from "./emptyError";
2
- import { EqualFunctions } from "./equalFunctions";
3
- import { JavascriptIterable } from "./javascript";
4
- import { List } from "./list";
5
- import { PreCondition } from "./preCondition";
6
- import { Stack } from "./stack";
7
- import { SyncResult } from "./syncResult";
8
-
9
- export class ListStack<T> implements Stack<T>
10
- {
11
- private readonly list: List<T>;
12
-
13
- private constructor(list?: List<T>)
14
- {
15
- this.list = list ?? List.create();
16
- }
17
-
18
- public static create<T>(list?: List<T>): ListStack<T>
19
- {
20
- return new ListStack<T>(list);
21
- }
22
-
23
- public any(): SyncResult<boolean>
24
- {
25
- return this.list.any();
26
- }
27
-
28
- public add(value: T): SyncResult<void>
29
- {
30
- return SyncResult.create(() =>
31
- {
32
- this.list.add(value);
33
- });
34
- }
35
-
36
- public addAll(values: JavascriptIterable<T>): SyncResult<void>
37
- {
38
- PreCondition.assertNotUndefinedAndNotNull(values, "values");
39
-
40
- return SyncResult.create(() =>
41
- {
42
- this.list.addAll(values);
43
- });
44
- }
45
-
46
- public remove(): SyncResult<T>
47
- {
48
- return SyncResult.create(() =>
49
- {
50
- if (!this.any().await())
51
- {
52
- throw new EmptyError();
53
- }
54
- return this.list.removeLast().await();
55
- });
56
- }
57
-
58
- public contains(value: T, equalFunctions?: EqualFunctions): SyncResult<boolean>
59
- {
60
- return this.list.contains(value, equalFunctions);
61
- }
1
+ import { EmptyError } from "./emptyError";
2
+ import { EqualFunctions } from "./equalFunctions";
3
+ import { JavascriptIterable } from "./javascript";
4
+ import { List } from "./list";
5
+ import { PreCondition } from "./preCondition";
6
+ import { Stack } from "./stack";
7
+ import { SyncResult } from "./syncResult";
8
+
9
+ export class ListStack<T> implements Stack<T>
10
+ {
11
+ private readonly list: List<T>;
12
+
13
+ private constructor(list?: List<T>)
14
+ {
15
+ this.list = list ?? List.create();
16
+ }
17
+
18
+ public static create<T>(list?: List<T>): ListStack<T>
19
+ {
20
+ return new ListStack<T>(list);
21
+ }
22
+
23
+ public any(): SyncResult<boolean>
24
+ {
25
+ return this.list.any();
26
+ }
27
+
28
+ public add(value: T): SyncResult<void>
29
+ {
30
+ return SyncResult.create(() =>
31
+ {
32
+ this.list.add(value);
33
+ });
34
+ }
35
+
36
+ public addAll(values: JavascriptIterable<T>): SyncResult<void>
37
+ {
38
+ PreCondition.assertNotUndefinedAndNotNull(values, "values");
39
+
40
+ return SyncResult.create(() =>
41
+ {
42
+ this.list.addAll(values);
43
+ });
44
+ }
45
+
46
+ public remove(): SyncResult<T>
47
+ {
48
+ return SyncResult.create(() =>
49
+ {
50
+ if (!this.any().await())
51
+ {
52
+ throw new EmptyError();
53
+ }
54
+ return this.list.removeLast().await();
55
+ });
56
+ }
57
+
58
+ public contains(value: T, equalFunctions?: EqualFunctions): SyncResult<boolean>
59
+ {
60
+ return this.list.contains(value, equalFunctions);
61
+ }
62
62
  }
@@ -1,109 +1,109 @@
1
- import * as luxon from "luxon";
2
- import { DateTime } from "./dateTime";
3
-
4
- const pctTimeZone: string = "America/Los_Angeles";
5
-
6
- export class LuxonDateTime implements DateTime
7
- {
8
- private readonly dateTime: luxon.DateTime;
9
-
10
- private constructor(dateTime: luxon.DateTime)
11
- {
12
- this.dateTime = dateTime;
13
- }
14
-
15
- private static create(dateTime: luxon.DateTime): LuxonDateTime
16
- {
17
- return new LuxonDateTime(dateTime);
18
- }
19
-
20
- public static parse(text: string): LuxonDateTime
21
- {
22
- return LuxonDateTime.create(luxon.DateTime.fromISO(text, { zone: pctTimeZone }));
23
- }
24
-
25
- public static now(): LuxonDateTime
26
- {
27
- return LuxonDateTime.create(luxon.DateTime.now().setZone(pctTimeZone));
28
- }
29
-
30
- public getYear(): number
31
- {
32
- return this.dateTime.year;
33
- }
34
-
35
- public getMonth(): number
36
- {
37
- return this.dateTime.month;
38
- }
39
-
40
- public getDay(): number
41
- {
42
- return this.dateTime.day;
43
- }
44
-
45
- public getHour(): number
46
- {
47
- return this.dateTime.hour;
48
- }
49
-
50
- public getMinute(): number
51
- {
52
- return this.dateTime.minute;
53
- }
54
-
55
- public getSecond(): number
56
- {
57
- return this.dateTime.second;
58
- }
59
-
60
- public addDays(days: number): LuxonDateTime
61
- {
62
- return LuxonDateTime.create(this.dateTime.plus({ days: days }));
63
- }
64
-
65
- public toString(): string
66
- {
67
- return this.dateTime.toISO()!;
68
- }
69
-
70
- public toDateString(): string
71
- {
72
- return this.dateTime.toISODate()!;
73
- }
74
-
75
- public compareTo(dateTime: DateTime, compareTimes: boolean): number
76
- {
77
- return DateTime.compareTo(this, dateTime, compareTimes);
78
- }
79
-
80
- public lessThan(dateTime: DateTime, compareTimes: boolean): boolean
81
- {
82
- return DateTime.lessThan(this, dateTime, compareTimes);
83
- }
84
-
85
- public lessThanOrEqualTo(dateTime: DateTime, compareTimes: boolean): boolean
86
- {
87
- return DateTime.lessThanOrEqualTo(this, dateTime, compareTimes);
88
- }
89
-
90
- public equals(dateTime: DateTime, compareTimes: boolean): boolean
91
- {
92
- return DateTime.equals(this, dateTime, compareTimes);
93
- }
94
-
95
- public greaterThanOrEqualTo(dateTime: DateTime, compareTimes: boolean): boolean
96
- {
97
- return DateTime.greaterThanOrEqualTo(this, dateTime, compareTimes);
98
- }
99
-
100
- public greaterThan(dateTime: DateTime, compareTimes: boolean): boolean
101
- {
102
- return DateTime.greaterThan(this, dateTime, compareTimes);
103
- }
104
-
105
- public get debug(): string
106
- {
107
- return DateTime.debug(this);
108
- }
1
+ import * as luxon from "luxon";
2
+ import { DateTime } from "./dateTime";
3
+
4
+ const pctTimeZone: string = "America/Los_Angeles";
5
+
6
+ export class LuxonDateTime implements DateTime
7
+ {
8
+ private readonly dateTime: luxon.DateTime;
9
+
10
+ private constructor(dateTime: luxon.DateTime)
11
+ {
12
+ this.dateTime = dateTime;
13
+ }
14
+
15
+ private static create(dateTime: luxon.DateTime): LuxonDateTime
16
+ {
17
+ return new LuxonDateTime(dateTime);
18
+ }
19
+
20
+ public static parse(text: string): LuxonDateTime
21
+ {
22
+ return LuxonDateTime.create(luxon.DateTime.fromISO(text, { zone: pctTimeZone }));
23
+ }
24
+
25
+ public static now(): LuxonDateTime
26
+ {
27
+ return LuxonDateTime.create(luxon.DateTime.now().setZone(pctTimeZone));
28
+ }
29
+
30
+ public getYear(): number
31
+ {
32
+ return this.dateTime.year;
33
+ }
34
+
35
+ public getMonth(): number
36
+ {
37
+ return this.dateTime.month;
38
+ }
39
+
40
+ public getDay(): number
41
+ {
42
+ return this.dateTime.day;
43
+ }
44
+
45
+ public getHour(): number
46
+ {
47
+ return this.dateTime.hour;
48
+ }
49
+
50
+ public getMinute(): number
51
+ {
52
+ return this.dateTime.minute;
53
+ }
54
+
55
+ public getSecond(): number
56
+ {
57
+ return this.dateTime.second;
58
+ }
59
+
60
+ public addDays(days: number): LuxonDateTime
61
+ {
62
+ return LuxonDateTime.create(this.dateTime.plus({ days: days }));
63
+ }
64
+
65
+ public toString(): string
66
+ {
67
+ return this.dateTime.toISO()!;
68
+ }
69
+
70
+ public toDateString(): string
71
+ {
72
+ return this.dateTime.toISODate()!;
73
+ }
74
+
75
+ public compareTo(dateTime: DateTime, compareTimes: boolean): number
76
+ {
77
+ return DateTime.compareTo(this, dateTime, compareTimes);
78
+ }
79
+
80
+ public lessThan(dateTime: DateTime, compareTimes: boolean): boolean
81
+ {
82
+ return DateTime.lessThan(this, dateTime, compareTimes);
83
+ }
84
+
85
+ public lessThanOrEqualTo(dateTime: DateTime, compareTimes: boolean): boolean
86
+ {
87
+ return DateTime.lessThanOrEqualTo(this, dateTime, compareTimes);
88
+ }
89
+
90
+ public equals(dateTime: DateTime, compareTimes: boolean): boolean
91
+ {
92
+ return DateTime.equals(this, dateTime, compareTimes);
93
+ }
94
+
95
+ public greaterThanOrEqualTo(dateTime: DateTime, compareTimes: boolean): boolean
96
+ {
97
+ return DateTime.greaterThanOrEqualTo(this, dateTime, compareTimes);
98
+ }
99
+
100
+ public greaterThan(dateTime: DateTime, compareTimes: boolean): boolean
101
+ {
102
+ return DateTime.greaterThan(this, dateTime, compareTimes);
103
+ }
104
+
105
+ public get debug(): string
106
+ {
107
+ return DateTime.debug(this);
108
+ }
109
109
  }
@@ -1,141 +1,141 @@
1
- import { PreCondition } from "./preCondition";
2
- import { Type } from "./types";
3
- import { AsyncIterator } from "./asyncIterator";
4
- import { PromiseAsyncResult } from "./promiseAsyncResult";
5
- import { JavascriptAsyncIterator } from "./javascript";
6
-
7
- /**
8
- * An {@link AsyncIterator} that maps {@link TInput} values to {@link TOutput} values.
9
- */
10
- export class MapAsyncIterator<TInput, TOutput> implements AsyncIterator<TOutput>
11
- {
12
- private readonly inputIterator: AsyncIterator<TInput>;
13
- private readonly mapping: (value: TInput) => (TOutput | PromiseLike<TOutput>);
14
- private current: TOutput | undefined;
15
- private started: boolean;
16
-
17
- protected constructor(inputIterator: AsyncIterator<TInput>, mapping: (value: TInput) => (TOutput | PromiseLike<TOutput>))
18
- {
19
- PreCondition.assertNotUndefinedAndNotNull(inputIterator, "inputIterator");
20
- PreCondition.assertNotUndefinedAndNotNull(mapping, "mapping");
21
-
22
- this.inputIterator = inputIterator;
23
- this.mapping = mapping;
24
- this.started = false;
25
- }
26
-
27
- public static create<TInput, TOutput>(inputIterator: AsyncIterator<TInput>, mapping: (value: TInput) => (TOutput | PromiseLike<TOutput>)): MapAsyncIterator<TInput, TOutput>
28
- {
29
- return new MapAsyncIterator(inputIterator, mapping);
30
- }
31
-
32
- public next(): PromiseAsyncResult<boolean>
33
- {
34
- return PromiseAsyncResult.create(async () =>
35
- {
36
- if (!this.hasStarted())
37
- {
38
- this.started = true;
39
- await this.inputIterator.start();
40
- }
41
- else
42
- {
43
- await this.inputIterator.next();
44
- }
45
-
46
- const result: boolean = this.inputIterator.hasCurrent();
47
- this.current = result
48
- ? await this.mapping(this.inputIterator.getCurrent())
49
- : undefined;
50
-
51
- return result;
52
- });
53
- }
54
-
55
- public hasStarted(): boolean
56
- {
57
- return this.started;
58
- }
59
-
60
- public hasCurrent(): boolean
61
- {
62
- return this.hasStarted() && this.inputIterator.hasCurrent();
63
- }
64
-
65
- public getCurrent(): TOutput
66
- {
67
- PreCondition.assertTrue(this.hasCurrent(), "this.hasCurrent()");
68
-
69
- return this.current!;
70
- }
71
-
72
- public start(): PromiseAsyncResult<this>
73
- {
74
- return AsyncIterator.start<TOutput, this>(this);
75
- }
76
-
77
- public takeCurrent(): PromiseAsyncResult<TOutput>
78
- {
79
- return AsyncIterator.takeCurrent(this);
80
- }
81
-
82
- public any(): PromiseAsyncResult<boolean>
83
- {
84
- return AsyncIterator.any(this);
85
- }
86
-
87
- public getCount(): PromiseAsyncResult<number>
88
- {
89
- return AsyncIterator.getCount(this);
90
- }
91
-
92
- public toArray(): PromiseAsyncResult<TOutput[]>
93
- {
94
- return AsyncIterator.toArray(this);
95
- }
96
-
97
- public map<TOutput2>(mapping: (value: TOutput) => (TOutput2 | PromiseLike<TOutput2>)): AsyncIterator<TOutput2>
98
- {
99
- return AsyncIterator.map(this, mapping);
100
- }
101
-
102
- public [Symbol.asyncIterator](): JavascriptAsyncIterator<TOutput>
103
- {
104
- return AsyncIterator[Symbol.asyncIterator](this);
105
- }
106
-
107
- public first(condition?: (value: TOutput) => boolean): PromiseAsyncResult<TOutput>
108
- {
109
- return AsyncIterator.first(this, condition);
110
- }
111
-
112
- public last(): PromiseAsyncResult<TOutput>
113
- {
114
- return AsyncIterator.last(this);
115
- }
116
-
117
- public where(condition: (value: TOutput) => (boolean | PromiseLike<boolean>)): AsyncIterator<TOutput>
118
- {
119
- return AsyncIterator.where(this, condition);
120
- }
121
-
122
- public whereInstanceOf<U extends TOutput>(typeCheck: (value: TOutput) => value is U): AsyncIterator<U>
123
- {
124
- return AsyncIterator.whereInstanceOf(this, typeCheck);
125
- }
126
-
127
- public whereInstanceOfType<U extends TOutput>(type: Type<U>): AsyncIterator<U>
128
- {
129
- return AsyncIterator.whereInstanceOfType(this, type);
130
- }
131
-
132
- public take(maximumToTake: number): AsyncIterator<TOutput>
133
- {
134
- return AsyncIterator.take(this, maximumToTake);
135
- }
136
-
137
- public skip(maximumToSkip: number): AsyncIterator<TOutput>
138
- {
139
- return AsyncIterator.skip(this, maximumToSkip);
140
- }
1
+ import { PreCondition } from "./preCondition";
2
+ import { Type } from "./types";
3
+ import { AsyncIterator } from "./asyncIterator";
4
+ import { PromiseAsyncResult } from "./promiseAsyncResult";
5
+ import { JavascriptAsyncIterator } from "./javascript";
6
+
7
+ /**
8
+ * An {@link AsyncIterator} that maps {@link TInput} values to {@link TOutput} values.
9
+ */
10
+ export class MapAsyncIterator<TInput, TOutput> implements AsyncIterator<TOutput>
11
+ {
12
+ private readonly inputIterator: AsyncIterator<TInput>;
13
+ private readonly mapping: (value: TInput) => (TOutput | PromiseLike<TOutput>);
14
+ private current: TOutput | undefined;
15
+ private started: boolean;
16
+
17
+ protected constructor(inputIterator: AsyncIterator<TInput>, mapping: (value: TInput) => (TOutput | PromiseLike<TOutput>))
18
+ {
19
+ PreCondition.assertNotUndefinedAndNotNull(inputIterator, "inputIterator");
20
+ PreCondition.assertNotUndefinedAndNotNull(mapping, "mapping");
21
+
22
+ this.inputIterator = inputIterator;
23
+ this.mapping = mapping;
24
+ this.started = false;
25
+ }
26
+
27
+ public static create<TInput, TOutput>(inputIterator: AsyncIterator<TInput>, mapping: (value: TInput) => (TOutput | PromiseLike<TOutput>)): MapAsyncIterator<TInput, TOutput>
28
+ {
29
+ return new MapAsyncIterator(inputIterator, mapping);
30
+ }
31
+
32
+ public next(): PromiseAsyncResult<boolean>
33
+ {
34
+ return PromiseAsyncResult.create(async () =>
35
+ {
36
+ if (!this.hasStarted())
37
+ {
38
+ this.started = true;
39
+ await this.inputIterator.start();
40
+ }
41
+ else
42
+ {
43
+ await this.inputIterator.next();
44
+ }
45
+
46
+ const result: boolean = this.inputIterator.hasCurrent();
47
+ this.current = result
48
+ ? await this.mapping(this.inputIterator.getCurrent())
49
+ : undefined;
50
+
51
+ return result;
52
+ });
53
+ }
54
+
55
+ public hasStarted(): boolean
56
+ {
57
+ return this.started;
58
+ }
59
+
60
+ public hasCurrent(): boolean
61
+ {
62
+ return this.hasStarted() && this.inputIterator.hasCurrent();
63
+ }
64
+
65
+ public getCurrent(): TOutput
66
+ {
67
+ PreCondition.assertTrue(this.hasCurrent(), "this.hasCurrent()");
68
+
69
+ return this.current!;
70
+ }
71
+
72
+ public start(): PromiseAsyncResult<this>
73
+ {
74
+ return AsyncIterator.start<TOutput, this>(this);
75
+ }
76
+
77
+ public takeCurrent(): PromiseAsyncResult<TOutput>
78
+ {
79
+ return AsyncIterator.takeCurrent(this);
80
+ }
81
+
82
+ public any(): PromiseAsyncResult<boolean>
83
+ {
84
+ return AsyncIterator.any(this);
85
+ }
86
+
87
+ public getCount(): PromiseAsyncResult<number>
88
+ {
89
+ return AsyncIterator.getCount(this);
90
+ }
91
+
92
+ public toArray(): PromiseAsyncResult<TOutput[]>
93
+ {
94
+ return AsyncIterator.toArray(this);
95
+ }
96
+
97
+ public map<TOutput2>(mapping: (value: TOutput) => (TOutput2 | PromiseLike<TOutput2>)): AsyncIterator<TOutput2>
98
+ {
99
+ return AsyncIterator.map(this, mapping);
100
+ }
101
+
102
+ public [Symbol.asyncIterator](): JavascriptAsyncIterator<TOutput>
103
+ {
104
+ return AsyncIterator[Symbol.asyncIterator](this);
105
+ }
106
+
107
+ public first(condition?: (value: TOutput) => boolean): PromiseAsyncResult<TOutput>
108
+ {
109
+ return AsyncIterator.first(this, condition);
110
+ }
111
+
112
+ public last(): PromiseAsyncResult<TOutput>
113
+ {
114
+ return AsyncIterator.last(this);
115
+ }
116
+
117
+ public where(condition: (value: TOutput) => (boolean | PromiseLike<boolean>)): AsyncIterator<TOutput>
118
+ {
119
+ return AsyncIterator.where(this, condition);
120
+ }
121
+
122
+ public whereInstanceOf<U extends TOutput>(typeCheck: (value: TOutput) => value is U): AsyncIterator<U>
123
+ {
124
+ return AsyncIterator.whereInstanceOf(this, typeCheck);
125
+ }
126
+
127
+ public whereInstanceOfType<U extends TOutput>(type: Type<U>): AsyncIterator<U>
128
+ {
129
+ return AsyncIterator.whereInstanceOfType(this, type);
130
+ }
131
+
132
+ public take(maximumToTake: number): AsyncIterator<TOutput>
133
+ {
134
+ return AsyncIterator.take(this, maximumToTake);
135
+ }
136
+
137
+ public skip(maximumToSkip: number): AsyncIterator<TOutput>
138
+ {
139
+ return AsyncIterator.skip(this, maximumToSkip);
140
+ }
141
141
  }