@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,151 +1,151 @@
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
- }
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
151
  }
@@ -1,81 +1,81 @@
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
- }
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
81
  }