@everyonesoftware/common 2.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 (59) hide show
  1. package/.github/workflows/publish.yml +54 -36
  2. package/package.json +6 -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/tsup.config.ts +12 -12
@@ -1,141 +1,141 @@
1
- import { AsyncIterator } from "./asyncIterator";
2
- import { PromiseAsyncResult } from "./promiseAsyncResult";
3
- import { JavascriptAsyncIterator } from "./javascript";
4
- import { PreCondition } from "./preCondition";
5
- import { Type } from "./types";
6
-
7
- /**
8
- * An {@link AsyncIterator} that iterates over a maximum number of values.
9
- */
10
- export class TakeAsyncIterator<T> implements AsyncIterator<T>
11
- {
12
- private readonly innerIterator: AsyncIterator<T>;
13
- private started: boolean;
14
- private readonly maximumToTake: number;
15
- private taken: number;
16
-
17
- private constructor(innerIterator: AsyncIterator<T>, maximumToTake: number)
18
- {
19
- PreCondition.assertGreaterThanOrEqualTo(maximumToTake, 0, "maximumToTake");
20
-
21
- this.innerIterator = innerIterator;
22
- this.started = false;
23
- this.maximumToTake = maximumToTake;
24
- this.taken = 0;
25
- }
26
-
27
- public static create<T>(innerIterator: AsyncIterator<T>, maximumToTake: number)
28
- {
29
- return new TakeAsyncIterator(innerIterator, maximumToTake);
30
- }
31
-
32
- public hasCurrent(): boolean
33
- {
34
- return this.hasStarted() && this.taken <= this.maximumToTake && this.innerIterator.hasCurrent();
35
- }
36
-
37
- public next(): PromiseAsyncResult<boolean>
38
- {
39
- return PromiseAsyncResult.create(async () =>
40
- {
41
- if (this.maximumToTake <= 0)
42
- {
43
- return false;
44
- }
45
- else if (!this.hasStarted())
46
- {
47
- this.started = true;
48
- await this.innerIterator.start();
49
- this.taken++;
50
- }
51
- else if (this.taken <= this.maximumToTake)
52
- {
53
- await this.innerIterator.next();
54
- this.taken++;
55
- }
56
- return this.hasCurrent();
57
- });
58
- }
59
-
60
- public hasStarted(): boolean
61
- {
62
- return this.started;
63
- }
64
-
65
- public getCurrent(): T
66
- {
67
- PreCondition.assertTrue(this.hasCurrent(), "this.hasCurrent()");
68
-
69
- return this.innerIterator.getCurrent();
70
- }
71
-
72
- public start(): PromiseAsyncResult<this>
73
- {
74
- return AsyncIterator.start<T, this>(this);
75
- }
76
-
77
- public takeCurrent(): PromiseAsyncResult<T>
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<T[]>
93
- {
94
- return AsyncIterator.toArray(this);
95
- }
96
-
97
- public where(condition: (value: T) => boolean): AsyncIterator<T>
98
- {
99
- return AsyncIterator.where(this, condition);
100
- }
101
-
102
- public whereInstanceOf<U extends T>(typeCheck: (value: T) => value is U): AsyncIterator<U>
103
- {
104
- return AsyncIterator.whereInstanceOf(this, typeCheck);
105
- }
106
-
107
- public whereInstanceOfType<U extends T>(type: Type<U>): AsyncIterator<U>
108
- {
109
- return AsyncIterator.whereInstanceOfType(this, type);
110
- }
111
-
112
- public map<TOutput>(mapping: (value: T) => (TOutput | PromiseLike<TOutput>)): AsyncIterator<TOutput>
113
- {
114
- return AsyncIterator.map(this, mapping);
115
- }
116
-
117
- public first(condition?: (value: T) => (boolean | PromiseLike<boolean>)): PromiseAsyncResult<T>
118
- {
119
- return AsyncIterator.first(this, condition);
120
- }
121
-
122
- public last(condition?: (value: T) => (boolean | PromiseLike<boolean>)): PromiseAsyncResult<T>
123
- {
124
- return AsyncIterator.last(this, condition);
125
- }
126
-
127
- public [Symbol.asyncIterator](): JavascriptAsyncIterator<T>
128
- {
129
- return AsyncIterator[Symbol.asyncIterator](this);
130
- }
131
-
132
- public take(maximumToTake: number): AsyncIterator<T>
133
- {
134
- return AsyncIterator.take(this, maximumToTake);
135
- }
136
-
137
- public skip(maximumToSkip: number): AsyncIterator<T>
138
- {
139
- return AsyncIterator.skip(this, maximumToSkip);
140
- }
1
+ import { AsyncIterator } from "./asyncIterator";
2
+ import { PromiseAsyncResult } from "./promiseAsyncResult";
3
+ import { JavascriptAsyncIterator } from "./javascript";
4
+ import { PreCondition } from "./preCondition";
5
+ import { Type } from "./types";
6
+
7
+ /**
8
+ * An {@link AsyncIterator} that iterates over a maximum number of values.
9
+ */
10
+ export class TakeAsyncIterator<T> implements AsyncIterator<T>
11
+ {
12
+ private readonly innerIterator: AsyncIterator<T>;
13
+ private started: boolean;
14
+ private readonly maximumToTake: number;
15
+ private taken: number;
16
+
17
+ private constructor(innerIterator: AsyncIterator<T>, maximumToTake: number)
18
+ {
19
+ PreCondition.assertGreaterThanOrEqualTo(maximumToTake, 0, "maximumToTake");
20
+
21
+ this.innerIterator = innerIterator;
22
+ this.started = false;
23
+ this.maximumToTake = maximumToTake;
24
+ this.taken = 0;
25
+ }
26
+
27
+ public static create<T>(innerIterator: AsyncIterator<T>, maximumToTake: number)
28
+ {
29
+ return new TakeAsyncIterator(innerIterator, maximumToTake);
30
+ }
31
+
32
+ public hasCurrent(): boolean
33
+ {
34
+ return this.hasStarted() && this.taken <= this.maximumToTake && this.innerIterator.hasCurrent();
35
+ }
36
+
37
+ public next(): PromiseAsyncResult<boolean>
38
+ {
39
+ return PromiseAsyncResult.create(async () =>
40
+ {
41
+ if (this.maximumToTake <= 0)
42
+ {
43
+ return false;
44
+ }
45
+ else if (!this.hasStarted())
46
+ {
47
+ this.started = true;
48
+ await this.innerIterator.start();
49
+ this.taken++;
50
+ }
51
+ else if (this.taken <= this.maximumToTake)
52
+ {
53
+ await this.innerIterator.next();
54
+ this.taken++;
55
+ }
56
+ return this.hasCurrent();
57
+ });
58
+ }
59
+
60
+ public hasStarted(): boolean
61
+ {
62
+ return this.started;
63
+ }
64
+
65
+ public getCurrent(): T
66
+ {
67
+ PreCondition.assertTrue(this.hasCurrent(), "this.hasCurrent()");
68
+
69
+ return this.innerIterator.getCurrent();
70
+ }
71
+
72
+ public start(): PromiseAsyncResult<this>
73
+ {
74
+ return AsyncIterator.start<T, this>(this);
75
+ }
76
+
77
+ public takeCurrent(): PromiseAsyncResult<T>
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<T[]>
93
+ {
94
+ return AsyncIterator.toArray(this);
95
+ }
96
+
97
+ public where(condition: (value: T) => boolean): AsyncIterator<T>
98
+ {
99
+ return AsyncIterator.where(this, condition);
100
+ }
101
+
102
+ public whereInstanceOf<U extends T>(typeCheck: (value: T) => value is U): AsyncIterator<U>
103
+ {
104
+ return AsyncIterator.whereInstanceOf(this, typeCheck);
105
+ }
106
+
107
+ public whereInstanceOfType<U extends T>(type: Type<U>): AsyncIterator<U>
108
+ {
109
+ return AsyncIterator.whereInstanceOfType(this, type);
110
+ }
111
+
112
+ public map<TOutput>(mapping: (value: T) => (TOutput | PromiseLike<TOutput>)): AsyncIterator<TOutput>
113
+ {
114
+ return AsyncIterator.map(this, mapping);
115
+ }
116
+
117
+ public first(condition?: (value: T) => (boolean | PromiseLike<boolean>)): PromiseAsyncResult<T>
118
+ {
119
+ return AsyncIterator.first(this, condition);
120
+ }
121
+
122
+ public last(condition?: (value: T) => (boolean | PromiseLike<boolean>)): PromiseAsyncResult<T>
123
+ {
124
+ return AsyncIterator.last(this, condition);
125
+ }
126
+
127
+ public [Symbol.asyncIterator](): JavascriptAsyncIterator<T>
128
+ {
129
+ return AsyncIterator[Symbol.asyncIterator](this);
130
+ }
131
+
132
+ public take(maximumToTake: number): AsyncIterator<T>
133
+ {
134
+ return AsyncIterator.take(this, maximumToTake);
135
+ }
136
+
137
+ public skip(maximumToSkip: number): AsyncIterator<T>
138
+ {
139
+ return AsyncIterator.skip(this, maximumToSkip);
140
+ }
141
141
  }
@@ -1,143 +1,143 @@
1
- import { AsyncIterator } from "./asyncIterator";
2
- import { PromiseAsyncResult } from "./promiseAsyncResult";
3
- import { JavascriptAsyncIterator } from "./javascript";
4
- import { PreCondition } from "./preCondition";
5
- import { Type } from "./types";
6
-
7
- /**
8
- * An {@link Iterator} that only returns values that match a condition.
9
- */
10
- export class WhereAsyncIterator<T> implements AsyncIterator<T>
11
- {
12
- private readonly innerIterator: AsyncIterator<T>;
13
- private started: boolean;
14
- private readonly condition: (value: T) => (boolean | PromiseLike<boolean>);
15
-
16
- private constructor(innerIterator: AsyncIterator<T>, condition: (value: T) => (boolean | PromiseLike<boolean>))
17
- {
18
- PreCondition.assertNotUndefinedAndNotNull(innerIterator, "innerIterator");
19
- PreCondition.assertNotUndefinedAndNotNull(condition, "condition");
20
-
21
- this.innerIterator = innerIterator;
22
- this.started = false;
23
- this.condition = condition;
24
- }
25
-
26
- public hasStarted(): boolean
27
- {
28
- return this.started;
29
- }
30
-
31
- public hasCurrent(): boolean
32
- {
33
- return this.hasStarted() && this.innerIterator.hasCurrent();
34
- }
35
-
36
- public getCurrent(): T
37
- {
38
- PreCondition.assertTrue(this.hasCurrent(), "this.hasCurrent()");
39
-
40
- return this.innerIterator.getCurrent();
41
- }
42
-
43
- public static create<T>(innerIterator: AsyncIterator<T>, condition: (value: T) => (boolean | PromiseLike<boolean>)): WhereAsyncIterator<T>
44
- {
45
- return new WhereAsyncIterator(innerIterator, condition);
46
- }
47
-
48
- public next(): PromiseAsyncResult<boolean>
49
- {
50
- return PromiseAsyncResult.create(async () =>
51
- {
52
- if (!this.hasStarted())
53
- {
54
- await this.innerIterator.start();
55
- this.started = true;
56
-
57
- while (this.hasCurrent() && !await this.condition(this.getCurrent()))
58
- {
59
- await this.innerIterator.next();
60
- }
61
- }
62
- else
63
- {
64
- do
65
- {
66
- await this.innerIterator.next();
67
- }
68
- while (this.hasCurrent() && !await this.condition(this.getCurrent()));
69
- }
70
- return this.hasCurrent();
71
- });
72
- }
73
-
74
- public start(): PromiseAsyncResult<this>
75
- {
76
- return AsyncIterator.start<T, this>(this);
77
- }
78
-
79
- public takeCurrent(): PromiseAsyncResult<T>
80
- {
81
- return AsyncIterator.takeCurrent(this);
82
- }
83
-
84
- public any(): PromiseAsyncResult<boolean>
85
- {
86
- return AsyncIterator.any(this);
87
- }
88
-
89
- public getCount(): PromiseAsyncResult<number>
90
- {
91
- return AsyncIterator.getCount(this);
92
- }
93
-
94
- public toArray(): PromiseAsyncResult<T[]>
95
- {
96
- return AsyncIterator.toArray(this);
97
- }
98
-
99
- public where(condition: (value: T) => (boolean | PromiseLike<boolean>)): AsyncIterator<T>
100
- {
101
- return AsyncIterator.where(this, condition);
102
- }
103
-
104
- public map<TOutput>(mapping: (value: T) => (TOutput | PromiseLike<TOutput>)): AsyncIterator<TOutput>
105
- {
106
- return AsyncIterator.map(this, mapping);
107
- }
108
-
109
- public whereInstanceOf<U extends T>(typeCheck: (value: T) => value is U): AsyncIterator<U>
110
- {
111
- return AsyncIterator.whereInstanceOf(this, typeCheck);
112
- }
113
-
114
- public whereInstanceOfType<U extends T>(type: Type<U>): AsyncIterator<U>
115
- {
116
- return AsyncIterator.whereInstanceOfType(this, type);
117
- }
118
-
119
- public first(condition?: (value: T) => (boolean | PromiseLike<boolean>)): PromiseAsyncResult<T>
120
- {
121
- return AsyncIterator.first(this, condition);
122
- }
123
-
124
- public last(condition?: (value: T) => (boolean | PromiseLike<boolean>)): PromiseAsyncResult<T>
125
- {
126
- return AsyncIterator.last(this, condition);
127
- }
128
-
129
- public take(maximumToTake: number): AsyncIterator<T>
130
- {
131
- return AsyncIterator.take(this, maximumToTake);
132
- }
133
-
134
- public skip(maximumToSkip: number): AsyncIterator<T>
135
- {
136
- return AsyncIterator.skip(this, maximumToSkip);
137
- }
138
-
139
- public [Symbol.asyncIterator](): JavascriptAsyncIterator<T>
140
- {
141
- return AsyncIterator[Symbol.asyncIterator](this);
142
- }
1
+ import { AsyncIterator } from "./asyncIterator";
2
+ import { PromiseAsyncResult } from "./promiseAsyncResult";
3
+ import { JavascriptAsyncIterator } from "./javascript";
4
+ import { PreCondition } from "./preCondition";
5
+ import { Type } from "./types";
6
+
7
+ /**
8
+ * An {@link Iterator} that only returns values that match a condition.
9
+ */
10
+ export class WhereAsyncIterator<T> implements AsyncIterator<T>
11
+ {
12
+ private readonly innerIterator: AsyncIterator<T>;
13
+ private started: boolean;
14
+ private readonly condition: (value: T) => (boolean | PromiseLike<boolean>);
15
+
16
+ private constructor(innerIterator: AsyncIterator<T>, condition: (value: T) => (boolean | PromiseLike<boolean>))
17
+ {
18
+ PreCondition.assertNotUndefinedAndNotNull(innerIterator, "innerIterator");
19
+ PreCondition.assertNotUndefinedAndNotNull(condition, "condition");
20
+
21
+ this.innerIterator = innerIterator;
22
+ this.started = false;
23
+ this.condition = condition;
24
+ }
25
+
26
+ public hasStarted(): boolean
27
+ {
28
+ return this.started;
29
+ }
30
+
31
+ public hasCurrent(): boolean
32
+ {
33
+ return this.hasStarted() && this.innerIterator.hasCurrent();
34
+ }
35
+
36
+ public getCurrent(): T
37
+ {
38
+ PreCondition.assertTrue(this.hasCurrent(), "this.hasCurrent()");
39
+
40
+ return this.innerIterator.getCurrent();
41
+ }
42
+
43
+ public static create<T>(innerIterator: AsyncIterator<T>, condition: (value: T) => (boolean | PromiseLike<boolean>)): WhereAsyncIterator<T>
44
+ {
45
+ return new WhereAsyncIterator(innerIterator, condition);
46
+ }
47
+
48
+ public next(): PromiseAsyncResult<boolean>
49
+ {
50
+ return PromiseAsyncResult.create(async () =>
51
+ {
52
+ if (!this.hasStarted())
53
+ {
54
+ await this.innerIterator.start();
55
+ this.started = true;
56
+
57
+ while (this.hasCurrent() && !await this.condition(this.getCurrent()))
58
+ {
59
+ await this.innerIterator.next();
60
+ }
61
+ }
62
+ else
63
+ {
64
+ do
65
+ {
66
+ await this.innerIterator.next();
67
+ }
68
+ while (this.hasCurrent() && !await this.condition(this.getCurrent()));
69
+ }
70
+ return this.hasCurrent();
71
+ });
72
+ }
73
+
74
+ public start(): PromiseAsyncResult<this>
75
+ {
76
+ return AsyncIterator.start<T, this>(this);
77
+ }
78
+
79
+ public takeCurrent(): PromiseAsyncResult<T>
80
+ {
81
+ return AsyncIterator.takeCurrent(this);
82
+ }
83
+
84
+ public any(): PromiseAsyncResult<boolean>
85
+ {
86
+ return AsyncIterator.any(this);
87
+ }
88
+
89
+ public getCount(): PromiseAsyncResult<number>
90
+ {
91
+ return AsyncIterator.getCount(this);
92
+ }
93
+
94
+ public toArray(): PromiseAsyncResult<T[]>
95
+ {
96
+ return AsyncIterator.toArray(this);
97
+ }
98
+
99
+ public where(condition: (value: T) => (boolean | PromiseLike<boolean>)): AsyncIterator<T>
100
+ {
101
+ return AsyncIterator.where(this, condition);
102
+ }
103
+
104
+ public map<TOutput>(mapping: (value: T) => (TOutput | PromiseLike<TOutput>)): AsyncIterator<TOutput>
105
+ {
106
+ return AsyncIterator.map(this, mapping);
107
+ }
108
+
109
+ public whereInstanceOf<U extends T>(typeCheck: (value: T) => value is U): AsyncIterator<U>
110
+ {
111
+ return AsyncIterator.whereInstanceOf(this, typeCheck);
112
+ }
113
+
114
+ public whereInstanceOfType<U extends T>(type: Type<U>): AsyncIterator<U>
115
+ {
116
+ return AsyncIterator.whereInstanceOfType(this, type);
117
+ }
118
+
119
+ public first(condition?: (value: T) => (boolean | PromiseLike<boolean>)): PromiseAsyncResult<T>
120
+ {
121
+ return AsyncIterator.first(this, condition);
122
+ }
123
+
124
+ public last(condition?: (value: T) => (boolean | PromiseLike<boolean>)): PromiseAsyncResult<T>
125
+ {
126
+ return AsyncIterator.last(this, condition);
127
+ }
128
+
129
+ public take(maximumToTake: number): AsyncIterator<T>
130
+ {
131
+ return AsyncIterator.take(this, maximumToTake);
132
+ }
133
+
134
+ public skip(maximumToSkip: number): AsyncIterator<T>
135
+ {
136
+ return AsyncIterator.skip(this, maximumToSkip);
137
+ }
138
+
139
+ public [Symbol.asyncIterator](): JavascriptAsyncIterator<T>
140
+ {
141
+ return AsyncIterator[Symbol.asyncIterator](this);
142
+ }
143
143
  }