@everyonesoftware/common 3.0.0 → 4.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/outputs/chunk-AY3YWKOM.js +7741 -0
- package/outputs/chunk-AY3YWKOM.js.map +1 -0
- package/outputs/sources.cjs +9007 -0
- package/outputs/sources.cjs.map +1 -0
- package/outputs/sources.d.cts +4082 -0
- package/outputs/sources.d.ts +4082 -0
- package/outputs/sources.js +1370 -0
- package/outputs/sources.js.map +1 -0
- package/outputs/tests.cjs +17208 -0
- package/outputs/tests.cjs.map +1 -0
- package/outputs/tests.d.cts +3 -0
- package/outputs/tests.d.ts +3 -0
- package/outputs/tests.js +9798 -0
- package/outputs/tests.js.map +1 -0
- package/package.json +6 -1
- package/.c8rc.json +0 -12
- package/.github/workflows/publish.yml +0 -54
- package/.mocharc.json +0 -9
- package/sources/assertMessageParameters.ts +0 -22
- package/sources/asyncIterator.ts +0 -437
- package/sources/asyncIteratorToJavascriptAsyncIteratorAdapter.ts +0 -48
- package/sources/asyncResult.ts +0 -95
- package/sources/basicDisposable.ts +0 -57
- package/sources/byteList.ts +0 -202
- package/sources/byteListStream.ts +0 -121
- package/sources/byteReadStream.ts +0 -24
- package/sources/byteWriteStream.ts +0 -16
- package/sources/bytes.ts +0 -25
- package/sources/characterList.ts +0 -195
- package/sources/characterListStream.ts +0 -151
- package/sources/characterReadStream.ts +0 -81
- package/sources/characterReadStreamIterator.ts +0 -128
- package/sources/characterWriteStream.ts +0 -45
- package/sources/commandLineParameter.ts +0 -45
- package/sources/commandLineParameters.ts +0 -21
- package/sources/comparable.ts +0 -144
- package/sources/comparer.ts +0 -133
- package/sources/comparison.ts +0 -20
- package/sources/concatenateIterable.ts +0 -119
- package/sources/concatenateIterator.ts +0 -165
- package/sources/condition.ts +0 -329
- package/sources/currentProcess.ts +0 -158
- package/sources/dateTime.ts +0 -130
- package/sources/depthFirstSearch.ts +0 -230
- package/sources/disposable.ts +0 -31
- package/sources/emptyError.ts +0 -10
- package/sources/english.ts +0 -45
- package/sources/equalFunctions.ts +0 -123
- package/sources/fetchHttpClient.ts +0 -89
- package/sources/fetchHttpResponse.ts +0 -106
- package/sources/flatMapIterable.ts +0 -104
- package/sources/flatMapIterator.ts +0 -152
- package/sources/generator.ts +0 -251
- package/sources/httpClient.ts +0 -36
- package/sources/httpHeader.ts +0 -37
- package/sources/httpHeaders.ts +0 -216
- package/sources/httpIncomingRequest.ts +0 -30
- package/sources/httpIncomingResponse.ts +0 -19
- package/sources/httpMethod.ts +0 -164
- package/sources/httpOutgoingRequest.ts +0 -119
- package/sources/httpOutgoingResponse.ts +0 -113
- package/sources/httpServer.ts +0 -34
- package/sources/inMemoryCharacterWriteStream.ts +0 -78
- package/sources/index.ts +0 -101
- package/sources/iterable.ts +0 -345
- package/sources/iterator.ts +0 -481
- package/sources/iteratorToJavascriptIteratorAdapter.ts +0 -48
- package/sources/javascript.ts +0 -59
- package/sources/javascriptArrayList.ts +0 -175
- package/sources/javascriptAsyncIteratorToAsyncIteratorAdapter.ts +0 -124
- package/sources/javascriptIteratorToIteratorAdapter.ts +0 -133
- package/sources/javascriptMapMap.ts +0 -143
- package/sources/javascriptSetSet.ts +0 -134
- package/sources/list.ts +0 -330
- package/sources/listQueue.ts +0 -62
- package/sources/listStack.ts +0 -62
- package/sources/luxonDateTime.ts +0 -109
- package/sources/map.ts +0 -302
- package/sources/mapAsyncIterator.ts +0 -141
- package/sources/mapIterable.ts +0 -105
- package/sources/mapIterator.ts +0 -145
- package/sources/mutableCondition.ts +0 -451
- package/sources/mutableHttpHeaders.ts +0 -204
- package/sources/mutableMap.ts +0 -292
- package/sources/network.ts +0 -18
- package/sources/node.ts +0 -37
- package/sources/nodeJSCharacterWriteStream.ts +0 -42
- package/sources/nodeJSHttpIncomingRequest.ts +0 -132
- package/sources/nodeJSHttpServer.ts +0 -134
- package/sources/notFoundError.ts +0 -12
- package/sources/postCondition.ts +0 -284
- package/sources/postConditionError.ts +0 -12
- package/sources/preCondition.ts +0 -284
- package/sources/preConditionError.ts +0 -12
- package/sources/promiseAsyncResult.ts +0 -174
- package/sources/property.ts +0 -63
- package/sources/queue.ts +0 -49
- package/sources/realNetwork.ts +0 -28
- package/sources/recreationDotGovClient.ts +0 -259
- package/sources/searchControl.ts +0 -42
- package/sources/set.ts +0 -244
- package/sources/skipAsyncIterator.ts +0 -145
- package/sources/skipIterator.ts +0 -155
- package/sources/stack.ts +0 -48
- package/sources/stringComparer.ts +0 -33
- package/sources/stringIterator.ts +0 -149
- package/sources/strings.ts +0 -322
- package/sources/syncResult.ts +0 -300
- package/sources/takeAsyncIterator.ts +0 -141
- package/sources/takeIterator.ts +0 -151
- package/sources/toStringFunctions.ts +0 -185
- package/sources/types.ts +0 -371
- package/sources/whereAsyncIterator.ts +0 -143
- package/sources/whereIterable.ts +0 -108
- package/sources/whereIterator.ts +0 -157
- package/sources/wonderlandTrailClient.ts +0 -1503
- package/tests/assertTest.ts +0 -113
- package/tests/assertTestTests.ts +0 -75
- package/tests/basicTestSkip.ts +0 -51
- package/tests/byteListStreamTests.ts +0 -390
- package/tests/byteListTests.ts +0 -27
- package/tests/bytesTests.ts +0 -43
- package/tests/characterListStreamTests.ts +0 -391
- package/tests/characterListTests.ts +0 -250
- package/tests/characterWriteStreamTests.ts +0 -12
- package/tests/comparerTests.ts +0 -92
- package/tests/conditionTests.ts +0 -877
- package/tests/consoleTestRunner.ts +0 -404
- package/tests/consoleTestRunnerTests.ts +0 -651
- package/tests/dateTimeTests.ts +0 -30
- package/tests/depthFirstSearchTests.ts +0 -106
- package/tests/disposableTests.ts +0 -121
- package/tests/englishTests.ts +0 -103
- package/tests/equalFunctionsTests.ts +0 -223
- package/tests/failedTest.ts +0 -43
- package/tests/fetchHttpClientTests.ts +0 -33
- package/tests/generatorTests.ts +0 -86
- package/tests/httpClientTests.ts +0 -18
- package/tests/inMemoryCharacterWriteStreamTests.ts +0 -117
- package/tests/iterableTests.ts +0 -141
- package/tests/iteratorTests.ts +0 -1086
- package/tests/javascriptMapMapTests.ts +0 -21
- package/tests/listTests.ts +0 -338
- package/tests/mapIteratorTests.ts +0 -55
- package/tests/mapTests.ts +0 -104
- package/tests/mutableConditionTests.ts +0 -273
- package/tests/mutableMapTests.ts +0 -154
- package/tests/nodeJSHttpServerTests.ts +0 -75
- package/tests/notFoundErrorTests.ts +0 -24
- package/tests/postConditionErrorTests.ts +0 -24
- package/tests/preConditionErrorTests.ts +0 -24
- package/tests/promiseAsyncResultTests.ts +0 -688
- package/tests/propertyTests.ts +0 -63
- package/tests/queueTests.ts +0 -29
- package/tests/recreationDotGovClientTests.ts +0 -191
- package/tests/setTests.ts +0 -140
- package/tests/skippedTest.ts +0 -39
- package/tests/stackTests.ts +0 -66
- package/tests/stringComparerTests.ts +0 -60
- package/tests/stringIteratorTests.ts +0 -156
- package/tests/stringsTests.ts +0 -516
- package/tests/syncResultTests.ts +0 -1251
- package/tests/test.ts +0 -228
- package/tests/testAction.ts +0 -75
- package/tests/testActionTests.ts +0 -93
- package/tests/testFailureTests.ts +0 -12
- package/tests/testRunner.ts +0 -267
- package/tests/testRunnerTests.ts +0 -895
- package/tests/testSkip.ts +0 -34
- package/tests/tests.ts +0 -103
- package/tests/toStringFunctionsTests.ts +0 -55
- package/tests/typesTests.ts +0 -257
- package/tests/whereIteratorTests.ts +0 -77
- package/tests/wonderlandTrailClientTests.ts +0 -452
- package/tsconfig.json +0 -20
- package/tsup.config.ts +0 -13
package/sources/characterList.ts
DELETED
|
@@ -1,195 +0,0 @@
|
|
|
1
|
-
import { EqualFunctions } from "./equalFunctions";
|
|
2
|
-
import { Iterable } from "./iterable";
|
|
3
|
-
import { Iterator } from "./iterator";
|
|
4
|
-
import { JavascriptIterable, JavascriptIterator } from "./javascript";
|
|
5
|
-
import { List } from "./list";
|
|
6
|
-
import { PreCondition } from "./preCondition";
|
|
7
|
-
import { StringIterator } from "./stringIterator";
|
|
8
|
-
import { join } from "./strings";
|
|
9
|
-
import { SyncResult } from "./syncResult";
|
|
10
|
-
import { ToStringFunctions } from "./toStringFunctions";
|
|
11
|
-
import { isString, Type } from "./types";
|
|
12
|
-
|
|
13
|
-
export class CharacterList implements List<string>
|
|
14
|
-
{
|
|
15
|
-
private characters: string;
|
|
16
|
-
|
|
17
|
-
private constructor(values?: JavascriptIterable<string> | string)
|
|
18
|
-
{
|
|
19
|
-
if (isString(values))
|
|
20
|
-
{
|
|
21
|
-
this.characters = values;
|
|
22
|
-
}
|
|
23
|
-
else if (values)
|
|
24
|
-
{
|
|
25
|
-
this.characters = join("", values);
|
|
26
|
-
}
|
|
27
|
-
else
|
|
28
|
-
{
|
|
29
|
-
this.characters = "";
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
public static create(values?: JavascriptIterable<string>): CharacterList
|
|
34
|
-
{
|
|
35
|
-
return new CharacterList(values);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
public getCount(): SyncResult<number>
|
|
39
|
-
{
|
|
40
|
-
return SyncResult.value(this.characters.length);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
public insert(index: number, value: string): this
|
|
44
|
-
{
|
|
45
|
-
PreCondition.assertInsertIndex(index, this.getCount().await(), "index");
|
|
46
|
-
PreCondition.assertCharacter(value, "value");
|
|
47
|
-
|
|
48
|
-
if (index === 0)
|
|
49
|
-
{
|
|
50
|
-
this.characters = value + this.characters;
|
|
51
|
-
}
|
|
52
|
-
else if (index === this.getCount().await())
|
|
53
|
-
{
|
|
54
|
-
this.characters += value;
|
|
55
|
-
}
|
|
56
|
-
else
|
|
57
|
-
{
|
|
58
|
-
this.characters = this.characters.slice(0, index) + value + this.characters.slice(index);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
return this;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
public removeAt(index: number): SyncResult<string>
|
|
65
|
-
{
|
|
66
|
-
PreCondition.assertAccessIndex(index, this.getCount().await(), "index");
|
|
67
|
-
|
|
68
|
-
const result: string = this.get(index).await();
|
|
69
|
-
this.characters =
|
|
70
|
-
(index === 0 ? "" : this.characters.slice(0, index)) +
|
|
71
|
-
(index === this.getCount().await() - 1 ? "" : this.characters.slice(index + 1));
|
|
72
|
-
|
|
73
|
-
return SyncResult.value(result);
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
public set(index: number, value: string): this
|
|
77
|
-
{
|
|
78
|
-
PreCondition.assertAccessIndex(index, this.getCount().await(), "index");
|
|
79
|
-
PreCondition.assertCharacter(value, "value");
|
|
80
|
-
|
|
81
|
-
this.characters =
|
|
82
|
-
(index === 0 ? "" : this.characters.slice(0, index)) +
|
|
83
|
-
value +
|
|
84
|
-
(index === this.getCount().await() - 1 ? "" : this.characters.slice(index + 1));
|
|
85
|
-
|
|
86
|
-
return this;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
public iterate(): Iterator<string>
|
|
90
|
-
{
|
|
91
|
-
return StringIterator.create(this.characters);
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
public get(index: number): SyncResult<string>
|
|
95
|
-
{
|
|
96
|
-
PreCondition.assertAccessIndex(index, this.getCount().await(), "index");
|
|
97
|
-
|
|
98
|
-
return SyncResult.value(this.characters.charAt(index));
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
public add(value: string): this
|
|
102
|
-
{
|
|
103
|
-
return List.add(this, value);
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
public addAll(values: JavascriptIterable<string>): this
|
|
107
|
-
{
|
|
108
|
-
return List.addAll(this, values);
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
public insertAll(index: number, values: JavascriptIterable<string>): this
|
|
112
|
-
{
|
|
113
|
-
return List.insertAll(this, index, values);
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
public remove(value: string, equalFunctions?: EqualFunctions): SyncResult<string>
|
|
117
|
-
{
|
|
118
|
-
return List.remove(this, value, equalFunctions);
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
public removeFirst(): SyncResult<string>
|
|
122
|
-
{
|
|
123
|
-
return List.removeFirst(this);
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
public removeLast(): SyncResult<string>
|
|
127
|
-
{
|
|
128
|
-
return List.removeLast(this);
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
public toArray(): SyncResult<string[]>
|
|
132
|
-
{
|
|
133
|
-
return List.toArray(this);
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
public any(): SyncResult<boolean>
|
|
137
|
-
{
|
|
138
|
-
return List.any(this);
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
public equals(right: JavascriptIterable<string>, equalFunctions?: EqualFunctions): SyncResult<boolean>
|
|
142
|
-
{
|
|
143
|
-
return List.equals(this, right, equalFunctions);
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
public toString(toStringFunctions?: ToStringFunctions): string
|
|
147
|
-
{
|
|
148
|
-
return List.toString(this, toStringFunctions);
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
public concatenate(...toConcatenate: JavascriptIterable<string>[]): Iterable<string>
|
|
152
|
-
{
|
|
153
|
-
return List.concatenate(this, ...toConcatenate);
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
public map<TOutput>(mapping: (value: string) => TOutput | SyncResult<TOutput>): Iterable<TOutput>
|
|
157
|
-
{
|
|
158
|
-
return List.map(this, mapping);
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
public flatMap<TOutput>(mapping: (value: string) => JavascriptIterable<TOutput>): Iterable<TOutput>
|
|
162
|
-
{
|
|
163
|
-
return List.flatMap(this, mapping);
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
public where(condition: (value: string) => (boolean | SyncResult<boolean>)): Iterable<string>
|
|
167
|
-
{
|
|
168
|
-
return List.where(this, condition);
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
public instanceOf<TOutput extends string>(typeOrTypeCheck: Type<TOutput> | ((value: string) => value is TOutput)): Iterable<TOutput>
|
|
172
|
-
{
|
|
173
|
-
return List.instanceOf(this, typeOrTypeCheck);
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
public first(condition?: (value: string) => (boolean | SyncResult<boolean>)): SyncResult<string>
|
|
177
|
-
{
|
|
178
|
-
return List.first(this, condition);
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
public last(condition?: (value: string) => (boolean | SyncResult<boolean>)): SyncResult<string>
|
|
182
|
-
{
|
|
183
|
-
return List.last(this, condition);
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
public contains(value: string, equalFunctions?: EqualFunctions): SyncResult<boolean>
|
|
187
|
-
{
|
|
188
|
-
return List.contains(this, value, equalFunctions);
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
public [Symbol.iterator](): JavascriptIterator<string>
|
|
192
|
-
{
|
|
193
|
-
return List[Symbol.iterator](this);
|
|
194
|
-
}
|
|
195
|
-
}
|
|
@@ -1,151 +0,0 @@
|
|
|
1
|
-
import { CharacterList } from "./characterList";
|
|
2
|
-
import { CharacterReadStream } from "./characterReadStream";
|
|
3
|
-
import { CharacterWriteStream } from "./characterWriteStream";
|
|
4
|
-
import { EmptyError } from "./emptyError";
|
|
5
|
-
import { JavascriptIterable } from "./javascript";
|
|
6
|
-
import { PreCondition } from "./preCondition";
|
|
7
|
-
import { AsyncResult } from "./asyncResult";
|
|
8
|
-
import { join } from "./strings";
|
|
9
|
-
import { SyncResult } from "./syncResult";
|
|
10
|
-
import { isNumber, isString, isUndefinedOrNull } from "./types";
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* A {@link CharacterReadStream} and {@link CharacterWriteStream} implementation that is implemented using a
|
|
14
|
-
* {@link CharacterList}.
|
|
15
|
-
*/
|
|
16
|
-
export class CharacterListStream implements CharacterReadStream, CharacterWriteStream
|
|
17
|
-
{
|
|
18
|
-
private readonly list: CharacterList;
|
|
19
|
-
|
|
20
|
-
private constructor()
|
|
21
|
-
{
|
|
22
|
-
this.list = CharacterList.create();
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
public static create(initialValues?: JavascriptIterable<string>): CharacterListStream
|
|
26
|
-
{
|
|
27
|
-
const result: CharacterListStream = new CharacterListStream();
|
|
28
|
-
if (initialValues)
|
|
29
|
-
{
|
|
30
|
-
result.writeCharacters(initialValues).await();
|
|
31
|
-
}
|
|
32
|
-
return result;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
public writeCharacters(characters: JavascriptIterable<string>, startIndex?: number, length?: number): SyncResult<number>
|
|
36
|
-
{
|
|
37
|
-
PreCondition.assertNotUndefinedAndNotNull(characters, "characters");
|
|
38
|
-
|
|
39
|
-
const characterString: string = isString(characters) ? characters : join("", characters);
|
|
40
|
-
if (isUndefinedOrNull(startIndex))
|
|
41
|
-
{
|
|
42
|
-
startIndex = 0;
|
|
43
|
-
}
|
|
44
|
-
if (isUndefinedOrNull(length))
|
|
45
|
-
{
|
|
46
|
-
length = characterString.length - startIndex;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
PreCondition.assertInsertIndex(startIndex, characterString.length, "startIndex");
|
|
50
|
-
PreCondition.assertBetween(0, length, characterString.length - startIndex, "length");
|
|
51
|
-
|
|
52
|
-
this.list.addAll(characterString.slice(startIndex, length + startIndex));
|
|
53
|
-
|
|
54
|
-
return SyncResult.value(length);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
public writeString(text: string): AsyncResult<number>
|
|
59
|
-
{
|
|
60
|
-
this.list.addAll(text);
|
|
61
|
-
|
|
62
|
-
return SyncResult.value(text.length);
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
public writeLine(text?: string): AsyncResult<number>
|
|
66
|
-
{
|
|
67
|
-
return CharacterWriteStream.writeLine(this, text);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* Get the number of characters that are available to be read.
|
|
72
|
-
*/
|
|
73
|
-
public getAvailableCharacterCount(): number
|
|
74
|
-
{
|
|
75
|
-
return this.list.getCount().await();
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
public readCharacter(): AsyncResult<string>
|
|
79
|
-
{
|
|
80
|
-
return !this.list.any().await()
|
|
81
|
-
? SyncResult.error(new EmptyError())
|
|
82
|
-
: SyncResult.value(this.list.removeFirst().await());
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
public readCharacters(count: number): SyncResult<string>;
|
|
86
|
-
public readCharacters(output: string[], startIndex?: number, count?: number): SyncResult<number>;
|
|
87
|
-
readCharacters(countOrOutput: number | string[], startIndex?: number, count?: number): SyncResult<number> | SyncResult<string>
|
|
88
|
-
{
|
|
89
|
-
let result: SyncResult<number> | SyncResult<string>;
|
|
90
|
-
if (isNumber(countOrOutput))
|
|
91
|
-
{
|
|
92
|
-
PreCondition.assertGreaterThanOrEqualTo(countOrOutput, 0, "count");
|
|
93
|
-
|
|
94
|
-
if (!this.list.any().await())
|
|
95
|
-
{
|
|
96
|
-
result = SyncResult.error<string>(new EmptyError());
|
|
97
|
-
}
|
|
98
|
-
else
|
|
99
|
-
{
|
|
100
|
-
const bytesReadCount: number = Math.min(countOrOutput, this.list.getCount().await());
|
|
101
|
-
let output: string = "";
|
|
102
|
-
for (let i = 0; i < bytesReadCount; i++)
|
|
103
|
-
{
|
|
104
|
-
output += this.list.removeFirst().await();
|
|
105
|
-
}
|
|
106
|
-
result = SyncResult.value(output);
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
else
|
|
110
|
-
{
|
|
111
|
-
PreCondition.assertNotUndefinedAndNotNull(countOrOutput, "output");
|
|
112
|
-
|
|
113
|
-
if (isUndefinedOrNull(startIndex))
|
|
114
|
-
{
|
|
115
|
-
startIndex = 0;
|
|
116
|
-
}
|
|
117
|
-
if (isUndefinedOrNull(count))
|
|
118
|
-
{
|
|
119
|
-
count = countOrOutput.length - startIndex;
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
PreCondition.assertInsertIndex(startIndex, countOrOutput.length, "startIndex");
|
|
123
|
-
PreCondition.assertBetween(0, count, countOrOutput.length - startIndex, "count");
|
|
124
|
-
|
|
125
|
-
if (!this.list.any().await())
|
|
126
|
-
{
|
|
127
|
-
result = SyncResult.error<number>(new EmptyError());
|
|
128
|
-
}
|
|
129
|
-
else
|
|
130
|
-
{
|
|
131
|
-
const bytesReadCount: number = Math.min(count, this.list.getCount().await());
|
|
132
|
-
for (let i = 0; i < bytesReadCount; i++)
|
|
133
|
-
{
|
|
134
|
-
countOrOutput[startIndex + i] = this.list.removeFirst().await();
|
|
135
|
-
}
|
|
136
|
-
result = SyncResult.value(bytesReadCount);
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
return result;
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
public readUntil(searchString: string): AsyncResult<string>
|
|
143
|
-
{
|
|
144
|
-
return CharacterReadStream.readUntil(this, searchString);
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
public readLine(): AsyncResult<string>
|
|
148
|
-
{
|
|
149
|
-
return CharacterReadStream.readLine(this);
|
|
150
|
-
}
|
|
151
|
-
}
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
import { PreCondition } from "./preCondition";
|
|
2
|
-
import { AsyncResult } from "./asyncResult";
|
|
3
|
-
import { SyncResult } from "./syncResult";
|
|
4
|
-
|
|
5
|
-
export abstract class CharacterReadStream
|
|
6
|
-
{
|
|
7
|
-
/**
|
|
8
|
-
* Read a single character from this stream.
|
|
9
|
-
*/
|
|
10
|
-
public abstract readCharacter(): AsyncResult<string>;
|
|
11
|
-
|
|
12
|
-
public readCharacters(count: number): AsyncResult<string>
|
|
13
|
-
{
|
|
14
|
-
return CharacterReadStream.readCharacters(this, count);
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
public static readCharacters(readStream: CharacterReadStream, count: number): AsyncResult<string>
|
|
18
|
-
{
|
|
19
|
-
let characters: string = "";
|
|
20
|
-
function readUntilCount(countRemaining: number): AsyncResult<string>
|
|
21
|
-
{
|
|
22
|
-
return readStream.readCharacter()
|
|
23
|
-
.then((character: string) =>
|
|
24
|
-
{
|
|
25
|
-
characters += character;
|
|
26
|
-
return countRemaining === 0
|
|
27
|
-
? SyncResult.value(characters)
|
|
28
|
-
: readUntilCount(countRemaining - 1);
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
return readUntilCount(count);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Read characters from this stream until the provided {@link searchString} is found or the end
|
|
36
|
-
* of the stream is reached. The {@link searchString} will be included in the returned string if
|
|
37
|
-
* it is found..
|
|
38
|
-
* @param searchString The string to search for.
|
|
39
|
-
*/
|
|
40
|
-
public readUntil(searchString: string): AsyncResult<string>
|
|
41
|
-
{
|
|
42
|
-
return CharacterReadStream.readUntil(this, searchString);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
public static readUntil(readStream: CharacterReadStream, searchString: string): AsyncResult<string>
|
|
46
|
-
{
|
|
47
|
-
PreCondition.assertNotUndefinedAndNotNull(readStream, "readStream");
|
|
48
|
-
PreCondition.assertNotEmpty(searchString, "searchString");
|
|
49
|
-
|
|
50
|
-
let characters: string = "";
|
|
51
|
-
function readUntilSearchString(): AsyncResult<string>
|
|
52
|
-
{
|
|
53
|
-
return readStream.readCharacter()
|
|
54
|
-
.then((character: string) =>
|
|
55
|
-
{
|
|
56
|
-
characters += character;
|
|
57
|
-
return characters.endsWith(searchString)
|
|
58
|
-
? SyncResult.value(characters)
|
|
59
|
-
: readUntilSearchString();
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
return readUntilSearchString();
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* Read a sequence of characters from this stream until either a newline character ('\\n') or
|
|
67
|
-
* the end of the stream is reached. Terminating newline characters will be included in the
|
|
68
|
-
* returned string.
|
|
69
|
-
*/
|
|
70
|
-
public readLine(): AsyncResult<string>
|
|
71
|
-
{
|
|
72
|
-
return CharacterReadStream.readLine(this);
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
public static readLine(readStream: CharacterReadStream): AsyncResult<string>
|
|
76
|
-
{
|
|
77
|
-
PreCondition.assertNotUndefinedAndNotNull(readStream, "readStream");
|
|
78
|
-
|
|
79
|
-
return readStream.readUntil("\n");
|
|
80
|
-
}
|
|
81
|
-
}
|
|
@@ -1,128 +0,0 @@
|
|
|
1
|
-
import { AsyncIterator } from "./asyncIterator";
|
|
2
|
-
import { PromiseAsyncResult } from "./promiseAsyncResult";
|
|
3
|
-
import { CharacterReadStream } from "./characterReadStream";
|
|
4
|
-
import { JavascriptAsyncIterator } from "./javascript";
|
|
5
|
-
import { NotFoundError } from "./notFoundError";
|
|
6
|
-
import { PreCondition } from "./preCondition";
|
|
7
|
-
import { Type } from "./types";
|
|
8
|
-
|
|
9
|
-
export class CharacterReadStreamAsyncIterator implements AsyncIterator<string>
|
|
10
|
-
{
|
|
11
|
-
private readonly readStream: CharacterReadStream;
|
|
12
|
-
private current: string;
|
|
13
|
-
private started: boolean;
|
|
14
|
-
|
|
15
|
-
private constructor(readStream: CharacterReadStream)
|
|
16
|
-
{
|
|
17
|
-
PreCondition.assertNotUndefinedAndNotNull(readStream, "readStream");
|
|
18
|
-
|
|
19
|
-
this.readStream = readStream;
|
|
20
|
-
this.current = "";
|
|
21
|
-
this.started = false;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
public static create(readStream: CharacterReadStream): CharacterReadStreamAsyncIterator
|
|
25
|
-
{
|
|
26
|
-
return new CharacterReadStreamAsyncIterator(readStream);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
public next(): PromiseAsyncResult<boolean>
|
|
30
|
-
{
|
|
31
|
-
return PromiseAsyncResult.create(async () =>
|
|
32
|
-
{
|
|
33
|
-
this.started = true;
|
|
34
|
-
|
|
35
|
-
this.current = await this.readStream.readCharacter()
|
|
36
|
-
.catch(NotFoundError, () => "");
|
|
37
|
-
|
|
38
|
-
return this.hasCurrent();
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
public hasStarted(): boolean
|
|
43
|
-
{
|
|
44
|
-
return this.started;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
public hasCurrent(): boolean
|
|
48
|
-
{
|
|
49
|
-
return this.current !== "";
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
public getCurrent(): string
|
|
53
|
-
{
|
|
54
|
-
PreCondition.assertTrue(this.hasCurrent(), "this.hasCurrent()");
|
|
55
|
-
|
|
56
|
-
return this.current;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
public start(): PromiseAsyncResult<this>
|
|
60
|
-
{
|
|
61
|
-
return AsyncIterator.start<string,this>(this);
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
public takeCurrent(): PromiseAsyncResult<string>
|
|
65
|
-
{
|
|
66
|
-
return AsyncIterator.takeCurrent(this);
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
public any(): PromiseAsyncResult<boolean>
|
|
70
|
-
{
|
|
71
|
-
return AsyncIterator.any(this);
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
public getCount(): PromiseAsyncResult<number>
|
|
75
|
-
{
|
|
76
|
-
return AsyncIterator.getCount(this);
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
public toArray(): PromiseAsyncResult<string[]>
|
|
80
|
-
{
|
|
81
|
-
return AsyncIterator.toArray(this);
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
public where(condition: (value: string) => boolean | PromiseLike<boolean>): AsyncIterator<string>
|
|
85
|
-
{
|
|
86
|
-
return AsyncIterator.where(this, condition);
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
public map<TOutput>(mapping: (value: string) => (TOutput | PromiseLike<TOutput>)): AsyncIterator<TOutput>
|
|
90
|
-
{
|
|
91
|
-
return AsyncIterator.map(this, mapping);
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
public whereInstanceOf<U extends string>(typeCheck: (value: string) => value is U): AsyncIterator<U>
|
|
95
|
-
{
|
|
96
|
-
return AsyncIterator.whereInstanceOf(this, typeCheck);
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
public whereInstanceOfType<U extends string>(type: Type<U>): AsyncIterator<U>
|
|
100
|
-
{
|
|
101
|
-
return AsyncIterator.whereInstanceOfType(this, type);
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
public first(condition?: (value: string) => (boolean | PromiseLike<boolean>)): PromiseAsyncResult<string>
|
|
105
|
-
{
|
|
106
|
-
return AsyncIterator.first(this, condition);
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
public last(condition?: (value: string) => (boolean | PromiseLike<boolean>)): PromiseAsyncResult<string>
|
|
110
|
-
{
|
|
111
|
-
return AsyncIterator.last(this, condition);
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
public take(maximumToTake: number): AsyncIterator<string>
|
|
115
|
-
{
|
|
116
|
-
return AsyncIterator.take(this, maximumToTake);
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
public skip(maximumToSkip: number): AsyncIterator<string>
|
|
120
|
-
{
|
|
121
|
-
return AsyncIterator.skip(this, maximumToSkip);
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
public [Symbol.asyncIterator](): JavascriptAsyncIterator<string>
|
|
125
|
-
{
|
|
126
|
-
return AsyncIterator[Symbol.asyncIterator](this);
|
|
127
|
-
}
|
|
128
|
-
}
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { PromiseAsyncResult } from "./promiseAsyncResult";
|
|
2
|
-
import { PostCondition } from "./postCondition";
|
|
3
|
-
import { PreCondition } from "./preCondition";
|
|
4
|
-
import { AsyncResult } from "./asyncResult";
|
|
5
|
-
|
|
6
|
-
export abstract class CharacterWriteStream
|
|
7
|
-
{
|
|
8
|
-
/**
|
|
9
|
-
* Write the provided text to this {@link CharacterWriteStream}.
|
|
10
|
-
* @param text The text to write.
|
|
11
|
-
* @returns The number of characters that were written.
|
|
12
|
-
*/
|
|
13
|
-
public abstract writeString(text: string): AsyncResult<number>
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Write the provided text (if provided) and then write a newline character sequence to this
|
|
17
|
-
* {@link CharacterWriteStream}.
|
|
18
|
-
* @param text The optional text to write before the newline character sequence.
|
|
19
|
-
* @returns The number of characters that were written.
|
|
20
|
-
*/
|
|
21
|
-
public writeLine(text?: string): AsyncResult<number>
|
|
22
|
-
{
|
|
23
|
-
return CharacterWriteStream.writeLine(this, text);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
public static writeLine(writeStream: CharacterWriteStream, text?: string): AsyncResult<number>
|
|
27
|
-
{
|
|
28
|
-
PreCondition.assertNotUndefinedAndNotNull(writeStream, "writeStream");
|
|
29
|
-
|
|
30
|
-
return PromiseAsyncResult.create(async () =>
|
|
31
|
-
{
|
|
32
|
-
let result: number = 0;
|
|
33
|
-
|
|
34
|
-
if (text)
|
|
35
|
-
{
|
|
36
|
-
result += await writeStream.writeString(text);
|
|
37
|
-
}
|
|
38
|
-
result += await writeStream.writeString("\n");
|
|
39
|
-
|
|
40
|
-
PostCondition.assertGreaterThan(result, 0, "result");
|
|
41
|
-
|
|
42
|
-
return result;
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
}
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* An individual parameter from a {@link CommandLineParameters} object.
|
|
3
|
-
*/
|
|
4
|
-
export class CommandLineParameter<T>
|
|
5
|
-
{
|
|
6
|
-
/**
|
|
7
|
-
* The full name of this {@link CommandLineParameter}.
|
|
8
|
-
*/
|
|
9
|
-
private readonly name: string;
|
|
10
|
-
/**
|
|
11
|
-
* The description for this {@link CommandLineParameter}.
|
|
12
|
-
*/
|
|
13
|
-
private readonly description: string;
|
|
14
|
-
/**
|
|
15
|
-
* The function that can be invoked to get this {@link CommandLineParameter}'s value.
|
|
16
|
-
*/
|
|
17
|
-
private readonly valueGetter: () => T;
|
|
18
|
-
|
|
19
|
-
private constructor(name: string, description: string, valueGetter: () => T)
|
|
20
|
-
{
|
|
21
|
-
this.name = name;
|
|
22
|
-
this.description = description;
|
|
23
|
-
this.valueGetter = valueGetter;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Create a new {@link CommandLineParameter}.
|
|
28
|
-
* @param name The full name of the {@link CommandLineParameter}.
|
|
29
|
-
* @param description The description for the {@link CommandLineParameter}.
|
|
30
|
-
* @param valueGetter The function that will be used to get the returned
|
|
31
|
-
* {@link CommandLineParameter}'s value.
|
|
32
|
-
*/
|
|
33
|
-
public static create<T>(name: string, description: string, valueGetter: () => T)
|
|
34
|
-
{
|
|
35
|
-
return new CommandLineParameter<T>(name, description, valueGetter);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* Get the value for this {@link CommandLineParameter}.
|
|
40
|
-
*/
|
|
41
|
-
public getValue(): T
|
|
42
|
-
{
|
|
43
|
-
return this.valueGetter();
|
|
44
|
-
}
|
|
45
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { JavascriptIterable } from "./javascript";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* A class that can be used to define and interact with an application's command line interface.
|
|
5
|
-
*/
|
|
6
|
-
export class CommandLineParameters
|
|
7
|
-
{
|
|
8
|
-
private readonly args: JavascriptIterable<string>;
|
|
9
|
-
|
|
10
|
-
private constructor(argv: JavascriptIterable<string>)
|
|
11
|
-
{
|
|
12
|
-
this.args = argv
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
public static create(args: JavascriptIterable<string>): CommandLineParameters
|
|
16
|
-
{
|
|
17
|
-
return new CommandLineParameters(args)
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
}
|