@everyonesoftware/common 1.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.
- package/.c8rc.json +12 -0
- package/.github/workflows/publish.yml +38 -0
- package/.mocharc.json +9 -0
- package/README.md +9 -0
- package/package.json +36 -0
- package/sources/assertMessageParameters.ts +22 -0
- package/sources/asyncIterator.ts +437 -0
- package/sources/asyncIteratorToJavascriptAsyncIteratorAdapter.ts +48 -0
- package/sources/asyncResult.ts +95 -0
- package/sources/basicDisposable.ts +57 -0
- package/sources/byteList.ts +202 -0
- package/sources/byteListStream.ts +121 -0
- package/sources/byteReadStream.ts +24 -0
- package/sources/byteWriteStream.ts +16 -0
- package/sources/bytes.ts +25 -0
- package/sources/characterList.ts +195 -0
- package/sources/characterListStream.ts +151 -0
- package/sources/characterReadStream.ts +81 -0
- package/sources/characterReadStreamIterator.ts +128 -0
- package/sources/characterWriteStream.ts +45 -0
- package/sources/commandLineParameter.ts +45 -0
- package/sources/commandLineParameters.ts +21 -0
- package/sources/comparable.ts +144 -0
- package/sources/comparer.ts +133 -0
- package/sources/comparison.ts +20 -0
- package/sources/concatenateIterable.ts +119 -0
- package/sources/concatenateIterator.ts +165 -0
- package/sources/condition.ts +329 -0
- package/sources/currentProcess.ts +158 -0
- package/sources/dateTime.ts +130 -0
- package/sources/depthFirstSearch.ts +230 -0
- package/sources/disposable.ts +31 -0
- package/sources/emptyError.ts +10 -0
- package/sources/english.ts +45 -0
- package/sources/equalFunctions.ts +123 -0
- package/sources/fetchHttpClient.ts +89 -0
- package/sources/fetchHttpResponse.ts +106 -0
- package/sources/flatMapIterable.ts +104 -0
- package/sources/flatMapIterator.ts +152 -0
- package/sources/generator.ts +251 -0
- package/sources/httpClient.ts +36 -0
- package/sources/httpHeader.ts +37 -0
- package/sources/httpHeaders.ts +216 -0
- package/sources/httpIncomingRequest.ts +30 -0
- package/sources/httpIncomingResponse.ts +19 -0
- package/sources/httpMethod.ts +164 -0
- package/sources/httpOutgoingRequest.ts +119 -0
- package/sources/httpOutgoingResponse.ts +113 -0
- package/sources/httpServer.ts +34 -0
- package/sources/inMemoryCharacterWriteStream.ts +78 -0
- package/sources/index.ts +101 -0
- package/sources/iterable.ts +345 -0
- package/sources/iterator.ts +481 -0
- package/sources/iteratorToJavascriptIteratorAdapter.ts +48 -0
- package/sources/javascript.ts +59 -0
- package/sources/javascriptArrayList.ts +175 -0
- package/sources/javascriptAsyncIteratorToAsyncIteratorAdapter.ts +124 -0
- package/sources/javascriptIteratorToIteratorAdapter.ts +133 -0
- package/sources/javascriptMapMap.ts +143 -0
- package/sources/javascriptSetSet.ts +134 -0
- package/sources/list.ts +330 -0
- package/sources/listQueue.ts +62 -0
- package/sources/listStack.ts +62 -0
- package/sources/luxonDateTime.ts +109 -0
- package/sources/map.ts +302 -0
- package/sources/mapAsyncIterator.ts +141 -0
- package/sources/mapIterable.ts +105 -0
- package/sources/mapIterator.ts +145 -0
- package/sources/mutableCondition.ts +451 -0
- package/sources/mutableHttpHeaders.ts +204 -0
- package/sources/mutableMap.ts +292 -0
- package/sources/network.ts +18 -0
- package/sources/node.ts +37 -0
- package/sources/nodeJSCharacterWriteStream.ts +42 -0
- package/sources/nodeJSHttpIncomingRequest.ts +132 -0
- package/sources/nodeJSHttpServer.ts +134 -0
- package/sources/notFoundError.ts +12 -0
- package/sources/postCondition.ts +284 -0
- package/sources/postConditionError.ts +12 -0
- package/sources/preCondition.ts +284 -0
- package/sources/preConditionError.ts +12 -0
- package/sources/promiseAsyncResult.ts +174 -0
- package/sources/property.ts +63 -0
- package/sources/queue.ts +49 -0
- package/sources/realNetwork.ts +28 -0
- package/sources/recreationDotGovClient.ts +259 -0
- package/sources/searchControl.ts +42 -0
- package/sources/set.ts +244 -0
- package/sources/skipAsyncIterator.ts +145 -0
- package/sources/skipIterator.ts +155 -0
- package/sources/stack.ts +48 -0
- package/sources/stringComparer.ts +33 -0
- package/sources/stringIterator.ts +149 -0
- package/sources/strings.ts +322 -0
- package/sources/syncResult.ts +300 -0
- package/sources/takeAsyncIterator.ts +141 -0
- package/sources/takeIterator.ts +151 -0
- package/sources/toStringFunctions.ts +185 -0
- package/sources/types.ts +371 -0
- package/sources/whereAsyncIterator.ts +143 -0
- package/sources/whereIterable.ts +108 -0
- package/sources/whereIterator.ts +157 -0
- package/sources/wonderlandTrailClient.ts +1503 -0
- package/tests/assertTest.ts +113 -0
- package/tests/assertTestTests.ts +75 -0
- package/tests/basicTestSkip.ts +51 -0
- package/tests/byteListStreamTests.ts +390 -0
- package/tests/byteListTests.ts +27 -0
- package/tests/bytesTests.ts +43 -0
- package/tests/characterListStreamTests.ts +391 -0
- package/tests/characterListTests.ts +250 -0
- package/tests/characterWriteStreamTests.ts +12 -0
- package/tests/comparerTests.ts +92 -0
- package/tests/conditionTests.ts +877 -0
- package/tests/consoleTestRunner.ts +404 -0
- package/tests/consoleTestRunnerTests.ts +651 -0
- package/tests/dateTimeTests.ts +30 -0
- package/tests/depthFirstSearchTests.ts +106 -0
- package/tests/disposableTests.ts +121 -0
- package/tests/englishTests.ts +103 -0
- package/tests/equalFunctionsTests.ts +223 -0
- package/tests/failedTest.ts +43 -0
- package/tests/fetchHttpClientTests.ts +33 -0
- package/tests/generatorTests.ts +86 -0
- package/tests/httpClientTests.ts +18 -0
- package/tests/inMemoryCharacterWriteStreamTests.ts +117 -0
- package/tests/iterableTests.ts +141 -0
- package/tests/iteratorTests.ts +1086 -0
- package/tests/javascriptMapMapTests.ts +21 -0
- package/tests/listTests.ts +338 -0
- package/tests/mapIteratorTests.ts +55 -0
- package/tests/mapTests.ts +104 -0
- package/tests/mutableConditionTests.ts +273 -0
- package/tests/mutableMapTests.ts +154 -0
- package/tests/nodeJSHttpServerTests.ts +75 -0
- package/tests/notFoundErrorTests.ts +24 -0
- package/tests/postConditionErrorTests.ts +24 -0
- package/tests/preConditionErrorTests.ts +24 -0
- package/tests/promiseAsyncResultTests.ts +688 -0
- package/tests/propertyTests.ts +63 -0
- package/tests/queueTests.ts +29 -0
- package/tests/recreationDotGovClientTests.ts +191 -0
- package/tests/setTests.ts +140 -0
- package/tests/skippedTest.ts +39 -0
- package/tests/stackTests.ts +66 -0
- package/tests/stringComparerTests.ts +60 -0
- package/tests/stringIteratorTests.ts +156 -0
- package/tests/stringsTests.ts +516 -0
- package/tests/syncResultTests.ts +1251 -0
- package/tests/test.ts +228 -0
- package/tests/testAction.ts +75 -0
- package/tests/testActionTests.ts +93 -0
- package/tests/testFailureTests.ts +12 -0
- package/tests/testRunner.ts +267 -0
- package/tests/testRunnerTests.ts +895 -0
- package/tests/testSkip.ts +34 -0
- package/tests/tests.ts +103 -0
- package/tests/toStringFunctionsTests.ts +55 -0
- package/tests/typesTests.ts +257 -0
- package/tests/whereIteratorTests.ts +77 -0
- package/tests/wonderlandTrailClientTests.ts +452 -0
- package/tsconfig.json +17 -0
- package/tsup.config.ts +13 -0
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { EqualFunctions } from "./equalFunctions";
|
|
2
|
+
import { Iterable } from "./iterable";
|
|
3
|
+
import { Iterator } from "./iterator";
|
|
4
|
+
import { JavascriptIterable, JavascriptIterator } from "./javascript";
|
|
5
|
+
import { PreCondition } from "./preCondition";
|
|
6
|
+
import { SyncResult } from "./syncResult";
|
|
7
|
+
import { ToStringFunctions } from "./toStringFunctions";
|
|
8
|
+
import { Type } from "./types";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* An {@link Iterable} that only returns values that match a condition.
|
|
12
|
+
*/
|
|
13
|
+
export class WhereIterable<T> implements Iterable<T>
|
|
14
|
+
{
|
|
15
|
+
// WhereIterable cannot extend Iterable because their create() functions are different.
|
|
16
|
+
|
|
17
|
+
private readonly innerIterable: Iterable<T>;
|
|
18
|
+
private readonly condition: (value: T) => (boolean | SyncResult<boolean>);
|
|
19
|
+
|
|
20
|
+
private constructor(innerIterable: Iterable<T>, condition: (value: T) => (boolean | SyncResult<boolean>))
|
|
21
|
+
{
|
|
22
|
+
PreCondition.assertNotUndefinedAndNotNull(innerIterable, "innerIterable");
|
|
23
|
+
PreCondition.assertNotUndefinedAndNotNull(condition, "condition");
|
|
24
|
+
|
|
25
|
+
this.innerIterable = innerIterable;
|
|
26
|
+
this.condition = condition;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
public static create<T>(innerIterable: Iterable<T>, condition: (value: T) => (boolean | SyncResult<boolean>)): WhereIterable<T>
|
|
30
|
+
{
|
|
31
|
+
return new WhereIterable(innerIterable, condition);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
public iterate(): Iterator<T>
|
|
35
|
+
{
|
|
36
|
+
return this.innerIterable.iterate().where(this.condition);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
public toArray(): SyncResult<T[]>
|
|
40
|
+
{
|
|
41
|
+
return Iterable.toArray(this);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
public any(): SyncResult<boolean>
|
|
45
|
+
{
|
|
46
|
+
return Iterable.any(this);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
public getCount(): SyncResult<number>
|
|
50
|
+
{
|
|
51
|
+
return Iterable.getCount(this);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
public equals(right: JavascriptIterable<T>, equalFunctions?: EqualFunctions): SyncResult<boolean>
|
|
55
|
+
{
|
|
56
|
+
return Iterable.equals(this, right, equalFunctions);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
public toString(toStringFunctions?: ToStringFunctions): string
|
|
60
|
+
{
|
|
61
|
+
return Iterable.toString(this, toStringFunctions);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
public concatenate(...toConcatenate: JavascriptIterable<T>[]): Iterable<T>
|
|
65
|
+
{
|
|
66
|
+
return Iterable.concatenate(this, ...toConcatenate);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
public map<TOutput>(mapping: (value: T) => (TOutput | SyncResult<TOutput>)): Iterable<TOutput>
|
|
70
|
+
{
|
|
71
|
+
return Iterable.map(this, mapping);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
public flatMap<TOutput>(mapping: (value: T) => JavascriptIterable<TOutput>): Iterable<TOutput>
|
|
75
|
+
{
|
|
76
|
+
return Iterable.flatMap(this, mapping);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
public where(condition: (value: T) => (boolean | SyncResult<boolean>)): Iterable<T>
|
|
80
|
+
{
|
|
81
|
+
return Iterable.where(this, condition);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
public instanceOf<TOutput extends T>(typeOrTypeCheck: Type<TOutput> | ((value: T) => value is TOutput)): Iterable<TOutput>
|
|
85
|
+
{
|
|
86
|
+
return Iterable.instanceOf(this, typeOrTypeCheck);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
public first(condition?: ((value: T) => (boolean | SyncResult<boolean>)) | undefined): SyncResult<T>
|
|
90
|
+
{
|
|
91
|
+
return Iterable.first(this, condition);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
public last(condition?: ((value: T) => (boolean | SyncResult<boolean>)) | undefined): SyncResult<T>
|
|
95
|
+
{
|
|
96
|
+
return Iterable.last(this, condition);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
public [Symbol.iterator](): JavascriptIterator<T>
|
|
100
|
+
{
|
|
101
|
+
return Iterable[Symbol.iterator](this);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
public contains(value: T, equalFunctions?: EqualFunctions): SyncResult<boolean>
|
|
105
|
+
{
|
|
106
|
+
return Iterable.contains(this, value, equalFunctions);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import { Iterator } from "./iterator";
|
|
2
|
+
import { JavascriptIterable, JavascriptIterator } from "./javascript";
|
|
3
|
+
import { PreCondition } from "./preCondition";
|
|
4
|
+
import { SyncResult } from "./syncResult";
|
|
5
|
+
import { isBoolean, Type } from "./types";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* An {@link Iterator} that only returns values that match a condition.
|
|
9
|
+
*/
|
|
10
|
+
export class WhereIterator<T> implements Iterator<T>
|
|
11
|
+
{
|
|
12
|
+
// WhereIterator cannot extend Iterator because their create() functions are different.
|
|
13
|
+
private readonly innerIterator: Iterator<T>;
|
|
14
|
+
private started: boolean;
|
|
15
|
+
private readonly condition: (value: T) => (boolean | SyncResult<boolean>);
|
|
16
|
+
|
|
17
|
+
private constructor(innerIterator: Iterator<T>, condition: (value: T) => (boolean | SyncResult<boolean>))
|
|
18
|
+
{
|
|
19
|
+
PreCondition.assertNotUndefinedAndNotNull(innerIterator, "innerIterator");
|
|
20
|
+
PreCondition.assertNotUndefinedAndNotNull(condition, "condition");
|
|
21
|
+
|
|
22
|
+
this.innerIterator = innerIterator;
|
|
23
|
+
this.started = false;
|
|
24
|
+
this.condition = condition;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
public static create<T>(innerIterator: Iterator<T>, condition: (value: T) => (boolean | SyncResult<boolean>)): WhereIterator<T>
|
|
28
|
+
{
|
|
29
|
+
return new WhereIterator(innerIterator, condition);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
public hasStarted(): boolean
|
|
33
|
+
{
|
|
34
|
+
return this.started;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
public hasCurrent(): boolean
|
|
38
|
+
{
|
|
39
|
+
return this.hasStarted() && this.innerIterator.hasCurrent();
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
public getCurrent(): T
|
|
43
|
+
{
|
|
44
|
+
PreCondition.assertTrue(this.hasCurrent(), "this.hasCurrent()");
|
|
45
|
+
|
|
46
|
+
return this.innerIterator.getCurrent();
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
public next(): SyncResult<boolean>
|
|
50
|
+
{
|
|
51
|
+
return SyncResult.create(() =>
|
|
52
|
+
{
|
|
53
|
+
if (!this.hasStarted())
|
|
54
|
+
{
|
|
55
|
+
this.innerIterator.start().await();
|
|
56
|
+
this.started = true;
|
|
57
|
+
}
|
|
58
|
+
else
|
|
59
|
+
{
|
|
60
|
+
this.innerIterator.next().await();
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
while (this.hasCurrent())
|
|
64
|
+
{
|
|
65
|
+
const conditionResult: boolean | SyncResult<boolean> = this.condition(this.getCurrent());
|
|
66
|
+
const conditionBoolean: boolean = isBoolean(conditionResult) ? conditionResult : conditionResult.await();
|
|
67
|
+
if (conditionBoolean)
|
|
68
|
+
{
|
|
69
|
+
break;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
this.innerIterator.next().await();
|
|
73
|
+
}
|
|
74
|
+
return this.hasCurrent();
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
public start(): SyncResult<this>
|
|
79
|
+
{
|
|
80
|
+
return Iterator.start<T, this>(this);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
public takeCurrent(): SyncResult<T>
|
|
84
|
+
{
|
|
85
|
+
return Iterator.takeCurrent(this);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
public any(): SyncResult<boolean>
|
|
89
|
+
{
|
|
90
|
+
return Iterator.any(this);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
public getCount(): SyncResult<number>
|
|
94
|
+
{
|
|
95
|
+
return Iterator.getCount(this);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
public toArray(): SyncResult<T[]>
|
|
99
|
+
{
|
|
100
|
+
return Iterator.toArray(this);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
public concatenate(...toConcatenate: JavascriptIterable<T>[]): Iterator<T>
|
|
104
|
+
{
|
|
105
|
+
return Iterator.concatenate(this, ...toConcatenate);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
public where(condition: (value: T) => boolean): Iterator<T>
|
|
109
|
+
{
|
|
110
|
+
return Iterator.where(this, condition);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
public map<TOutput>(mapping: (value: T) => (TOutput | SyncResult<TOutput>)): Iterator<TOutput>
|
|
114
|
+
{
|
|
115
|
+
return Iterator.map(this, mapping);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
public flatMap<TOutput>(mapping: (value: T) => JavascriptIterable<TOutput>): Iterator<TOutput>
|
|
119
|
+
{
|
|
120
|
+
return Iterator.flatMap(this, mapping);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
public whereInstanceOf<U extends T>(typeCheck: (value: T) => value is U): Iterator<U>
|
|
124
|
+
{
|
|
125
|
+
return Iterator.whereInstanceOf(this, typeCheck);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
public whereInstanceOfType<U extends T>(type: Type<U>): Iterator<U>
|
|
129
|
+
{
|
|
130
|
+
return Iterator.whereInstanceOfType(this, type);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
public first(condition?: (value: T) => boolean): SyncResult<T>
|
|
134
|
+
{
|
|
135
|
+
return Iterator.first(this, condition);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
public last(condition?: (value: T) => boolean): SyncResult<T>
|
|
139
|
+
{
|
|
140
|
+
return Iterator.last(this, condition);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
public take(maximumToTake: number): Iterator<T>
|
|
144
|
+
{
|
|
145
|
+
return Iterator.take(this, maximumToTake);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
public skip(maximumToSkip: number): Iterator<T>
|
|
149
|
+
{
|
|
150
|
+
return Iterator.skip(this, maximumToSkip);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
public [Symbol.iterator](): JavascriptIterator<T>
|
|
154
|
+
{
|
|
155
|
+
return Iterator[Symbol.iterator](this);
|
|
156
|
+
}
|
|
157
|
+
}
|