@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.
Files changed (176) hide show
  1. package/outputs/chunk-AY3YWKOM.js +7741 -0
  2. package/outputs/chunk-AY3YWKOM.js.map +1 -0
  3. package/outputs/sources.cjs +9007 -0
  4. package/outputs/sources.cjs.map +1 -0
  5. package/outputs/sources.d.cts +4082 -0
  6. package/outputs/sources.d.ts +4082 -0
  7. package/outputs/sources.js +1370 -0
  8. package/outputs/sources.js.map +1 -0
  9. package/outputs/tests.cjs +17208 -0
  10. package/outputs/tests.cjs.map +1 -0
  11. package/outputs/tests.d.cts +3 -0
  12. package/outputs/tests.d.ts +3 -0
  13. package/outputs/tests.js +9798 -0
  14. package/outputs/tests.js.map +1 -0
  15. package/package.json +6 -1
  16. package/.c8rc.json +0 -12
  17. package/.github/workflows/publish.yml +0 -54
  18. package/.mocharc.json +0 -9
  19. package/sources/assertMessageParameters.ts +0 -22
  20. package/sources/asyncIterator.ts +0 -437
  21. package/sources/asyncIteratorToJavascriptAsyncIteratorAdapter.ts +0 -48
  22. package/sources/asyncResult.ts +0 -95
  23. package/sources/basicDisposable.ts +0 -57
  24. package/sources/byteList.ts +0 -202
  25. package/sources/byteListStream.ts +0 -121
  26. package/sources/byteReadStream.ts +0 -24
  27. package/sources/byteWriteStream.ts +0 -16
  28. package/sources/bytes.ts +0 -25
  29. package/sources/characterList.ts +0 -195
  30. package/sources/characterListStream.ts +0 -151
  31. package/sources/characterReadStream.ts +0 -81
  32. package/sources/characterReadStreamIterator.ts +0 -128
  33. package/sources/characterWriteStream.ts +0 -45
  34. package/sources/commandLineParameter.ts +0 -45
  35. package/sources/commandLineParameters.ts +0 -21
  36. package/sources/comparable.ts +0 -144
  37. package/sources/comparer.ts +0 -133
  38. package/sources/comparison.ts +0 -20
  39. package/sources/concatenateIterable.ts +0 -119
  40. package/sources/concatenateIterator.ts +0 -165
  41. package/sources/condition.ts +0 -329
  42. package/sources/currentProcess.ts +0 -158
  43. package/sources/dateTime.ts +0 -130
  44. package/sources/depthFirstSearch.ts +0 -230
  45. package/sources/disposable.ts +0 -31
  46. package/sources/emptyError.ts +0 -10
  47. package/sources/english.ts +0 -45
  48. package/sources/equalFunctions.ts +0 -123
  49. package/sources/fetchHttpClient.ts +0 -89
  50. package/sources/fetchHttpResponse.ts +0 -106
  51. package/sources/flatMapIterable.ts +0 -104
  52. package/sources/flatMapIterator.ts +0 -152
  53. package/sources/generator.ts +0 -251
  54. package/sources/httpClient.ts +0 -36
  55. package/sources/httpHeader.ts +0 -37
  56. package/sources/httpHeaders.ts +0 -216
  57. package/sources/httpIncomingRequest.ts +0 -30
  58. package/sources/httpIncomingResponse.ts +0 -19
  59. package/sources/httpMethod.ts +0 -164
  60. package/sources/httpOutgoingRequest.ts +0 -119
  61. package/sources/httpOutgoingResponse.ts +0 -113
  62. package/sources/httpServer.ts +0 -34
  63. package/sources/inMemoryCharacterWriteStream.ts +0 -78
  64. package/sources/index.ts +0 -101
  65. package/sources/iterable.ts +0 -345
  66. package/sources/iterator.ts +0 -481
  67. package/sources/iteratorToJavascriptIteratorAdapter.ts +0 -48
  68. package/sources/javascript.ts +0 -59
  69. package/sources/javascriptArrayList.ts +0 -175
  70. package/sources/javascriptAsyncIteratorToAsyncIteratorAdapter.ts +0 -124
  71. package/sources/javascriptIteratorToIteratorAdapter.ts +0 -133
  72. package/sources/javascriptMapMap.ts +0 -143
  73. package/sources/javascriptSetSet.ts +0 -134
  74. package/sources/list.ts +0 -330
  75. package/sources/listQueue.ts +0 -62
  76. package/sources/listStack.ts +0 -62
  77. package/sources/luxonDateTime.ts +0 -109
  78. package/sources/map.ts +0 -302
  79. package/sources/mapAsyncIterator.ts +0 -141
  80. package/sources/mapIterable.ts +0 -105
  81. package/sources/mapIterator.ts +0 -145
  82. package/sources/mutableCondition.ts +0 -451
  83. package/sources/mutableHttpHeaders.ts +0 -204
  84. package/sources/mutableMap.ts +0 -292
  85. package/sources/network.ts +0 -18
  86. package/sources/node.ts +0 -37
  87. package/sources/nodeJSCharacterWriteStream.ts +0 -42
  88. package/sources/nodeJSHttpIncomingRequest.ts +0 -132
  89. package/sources/nodeJSHttpServer.ts +0 -134
  90. package/sources/notFoundError.ts +0 -12
  91. package/sources/postCondition.ts +0 -284
  92. package/sources/postConditionError.ts +0 -12
  93. package/sources/preCondition.ts +0 -284
  94. package/sources/preConditionError.ts +0 -12
  95. package/sources/promiseAsyncResult.ts +0 -174
  96. package/sources/property.ts +0 -63
  97. package/sources/queue.ts +0 -49
  98. package/sources/realNetwork.ts +0 -28
  99. package/sources/recreationDotGovClient.ts +0 -259
  100. package/sources/searchControl.ts +0 -42
  101. package/sources/set.ts +0 -244
  102. package/sources/skipAsyncIterator.ts +0 -145
  103. package/sources/skipIterator.ts +0 -155
  104. package/sources/stack.ts +0 -48
  105. package/sources/stringComparer.ts +0 -33
  106. package/sources/stringIterator.ts +0 -149
  107. package/sources/strings.ts +0 -322
  108. package/sources/syncResult.ts +0 -300
  109. package/sources/takeAsyncIterator.ts +0 -141
  110. package/sources/takeIterator.ts +0 -151
  111. package/sources/toStringFunctions.ts +0 -185
  112. package/sources/types.ts +0 -371
  113. package/sources/whereAsyncIterator.ts +0 -143
  114. package/sources/whereIterable.ts +0 -108
  115. package/sources/whereIterator.ts +0 -157
  116. package/sources/wonderlandTrailClient.ts +0 -1503
  117. package/tests/assertTest.ts +0 -113
  118. package/tests/assertTestTests.ts +0 -75
  119. package/tests/basicTestSkip.ts +0 -51
  120. package/tests/byteListStreamTests.ts +0 -390
  121. package/tests/byteListTests.ts +0 -27
  122. package/tests/bytesTests.ts +0 -43
  123. package/tests/characterListStreamTests.ts +0 -391
  124. package/tests/characterListTests.ts +0 -250
  125. package/tests/characterWriteStreamTests.ts +0 -12
  126. package/tests/comparerTests.ts +0 -92
  127. package/tests/conditionTests.ts +0 -877
  128. package/tests/consoleTestRunner.ts +0 -404
  129. package/tests/consoleTestRunnerTests.ts +0 -651
  130. package/tests/dateTimeTests.ts +0 -30
  131. package/tests/depthFirstSearchTests.ts +0 -106
  132. package/tests/disposableTests.ts +0 -121
  133. package/tests/englishTests.ts +0 -103
  134. package/tests/equalFunctionsTests.ts +0 -223
  135. package/tests/failedTest.ts +0 -43
  136. package/tests/fetchHttpClientTests.ts +0 -33
  137. package/tests/generatorTests.ts +0 -86
  138. package/tests/httpClientTests.ts +0 -18
  139. package/tests/inMemoryCharacterWriteStreamTests.ts +0 -117
  140. package/tests/iterableTests.ts +0 -141
  141. package/tests/iteratorTests.ts +0 -1086
  142. package/tests/javascriptMapMapTests.ts +0 -21
  143. package/tests/listTests.ts +0 -338
  144. package/tests/mapIteratorTests.ts +0 -55
  145. package/tests/mapTests.ts +0 -104
  146. package/tests/mutableConditionTests.ts +0 -273
  147. package/tests/mutableMapTests.ts +0 -154
  148. package/tests/nodeJSHttpServerTests.ts +0 -75
  149. package/tests/notFoundErrorTests.ts +0 -24
  150. package/tests/postConditionErrorTests.ts +0 -24
  151. package/tests/preConditionErrorTests.ts +0 -24
  152. package/tests/promiseAsyncResultTests.ts +0 -688
  153. package/tests/propertyTests.ts +0 -63
  154. package/tests/queueTests.ts +0 -29
  155. package/tests/recreationDotGovClientTests.ts +0 -191
  156. package/tests/setTests.ts +0 -140
  157. package/tests/skippedTest.ts +0 -39
  158. package/tests/stackTests.ts +0 -66
  159. package/tests/stringComparerTests.ts +0 -60
  160. package/tests/stringIteratorTests.ts +0 -156
  161. package/tests/stringsTests.ts +0 -516
  162. package/tests/syncResultTests.ts +0 -1251
  163. package/tests/test.ts +0 -228
  164. package/tests/testAction.ts +0 -75
  165. package/tests/testActionTests.ts +0 -93
  166. package/tests/testFailureTests.ts +0 -12
  167. package/tests/testRunner.ts +0 -267
  168. package/tests/testRunnerTests.ts +0 -895
  169. package/tests/testSkip.ts +0 -34
  170. package/tests/tests.ts +0 -103
  171. package/tests/toStringFunctionsTests.ts +0 -55
  172. package/tests/typesTests.ts +0 -257
  173. package/tests/whereIteratorTests.ts +0 -77
  174. package/tests/wonderlandTrailClientTests.ts +0 -452
  175. package/tsconfig.json +0 -20
  176. package/tsup.config.ts +0 -13
@@ -1,185 +0,0 @@
1
- import { Iterable } from "./iterable";
2
- import { Iterator } from "./iterator";
3
- import { isMap, Map, MapEntry } from "./map";
4
- import { isSet, Set } from "./set";
5
- import { escapeAndQuote, join } from "./strings";
6
- import { isArray, isIterable, isNumber, isObject, isString } from "./types";
7
-
8
- /**
9
- * A collection of {@link ToStringFunction}s.
10
- */
11
- export class ToStringFunctions
12
- {
13
- private readonly functions: ((value: unknown) => (string | undefined))[];
14
-
15
- private constructor()
16
- {
17
- this.functions = [];
18
- }
19
-
20
- public static create(): ToStringFunctions
21
- {
22
- return new ToStringFunctions();
23
- }
24
-
25
- private defaultToString(value: unknown): string
26
- {
27
- let result: string;
28
- if (isMap(value))
29
- {
30
- result = this.mapToString(value);
31
- }
32
- else if (isSet(value))
33
- {
34
- result = this.setToString(value);
35
- }
36
- else if (isIterable(value))
37
- {
38
- result = this.iterableToString(value);
39
- }
40
- else if (isNumber(value))
41
- {
42
- result = value.toString();
43
- }
44
- else if (value === undefined)
45
- {
46
- result = "undefined";
47
- }
48
- else if (value === null)
49
- {
50
- result = "null";
51
- }
52
- else if (isString(value))
53
- {
54
- result = escapeAndQuote(value);
55
- }
56
- else if (isArray(value))
57
- {
58
- result = `[${join(",", value.map(x => this.toString(x)))}]`;
59
- }
60
- else if (isObject(value))
61
- {
62
- result = `{${join(",", Object.entries(value).map(p => join(":", p.map(x => this.toString(x)))))}}`;
63
- }
64
- else
65
- {
66
- result = JSON.stringify(value);
67
- }
68
- return result;
69
- }
70
-
71
- /**
72
- * Get the {@link String} representation of the value with the registered
73
- * {@link ToStringFunction}s.
74
- * @param value The value to get the {@link String} representation of.
75
- */
76
- public toString(value: unknown): string
77
- {
78
- let result: string | undefined;
79
- for (const toStringFunction of this.functions)
80
- {
81
- result = toStringFunction(value);
82
- if (result !== undefined)
83
- {
84
- break;
85
- }
86
- }
87
-
88
- if (result === undefined)
89
- {
90
- result = this.defaultToString(value);
91
- }
92
-
93
- return result;
94
- }
95
-
96
- public add(toStringFunction: (value: unknown) => (string | undefined)): this;
97
- public add<T>(typeCheckFunction: (value: unknown) => value is T, typedToStringFunction: (value: T) => string): this;
98
- add<T>(typeCheckFunctionOrToStringFunction: ((value: unknown) => (string | undefined)) | ((value: unknown) => value is T), typedToStringFunction?: (value: T) => string): this
99
- {
100
- let toStringFunction: (value: unknown) => (string | undefined);
101
- if (typedToStringFunction)
102
- {
103
- const typeCheckFunction = typeCheckFunctionOrToStringFunction as (value: unknown) => value is T;
104
- toStringFunction = (value: unknown) =>
105
- {
106
- let result: string | undefined;
107
- if (typeCheckFunction(value))
108
- {
109
- result = typedToStringFunction!(value);
110
- }
111
- return result;
112
- };
113
- }
114
- else
115
- {
116
- toStringFunction = typeCheckFunctionOrToStringFunction as (value: unknown) => (string | undefined);
117
- }
118
-
119
- this.functions.unshift(toStringFunction);
120
-
121
- return this;
122
- }
123
-
124
- private iterableToString(values: Iterable<unknown>): string
125
- {
126
- let result: string = "";
127
- result += "[";
128
-
129
- const iterator: Iterator<unknown> = values.iterate().start().await();
130
- if (iterator.hasCurrent())
131
- {
132
- result += this.toString(iterator.takeCurrent().await());
133
- while (iterator.hasCurrent())
134
- {
135
- result += ",";
136
- result += this.toString(iterator.takeCurrent().await());
137
- }
138
- }
139
-
140
- result += "]";
141
- return result;
142
- }
143
-
144
- private mapToString(values: Map<unknown,unknown>): string
145
- {
146
- let result = "";
147
- result += "{";
148
-
149
- const iterator: Iterator<MapEntry<unknown,unknown>> = values.iterate();
150
- if (iterator.next().await())
151
- {
152
- let entry: MapEntry<unknown,unknown> = iterator.getCurrent();
153
- result += `${this.toString(entry.key)}:${this.toString(entry.value)}`;
154
- while (iterator.next().await())
155
- {
156
- result += ",";
157
-
158
- entry = iterator.getCurrent();
159
- result += `${this.toString(entry.key)}:${this.toString(entry.value)}`;
160
- }
161
- }
162
-
163
- result += "}";
164
- return result;
165
- }
166
-
167
- private setToString(values: Set<unknown>): string
168
- {
169
- let result = "";
170
- result += "{";
171
-
172
- const iterator: Iterator<unknown> = values.iterate();
173
- if (iterator.next().await())
174
- {
175
- result += this.toString(iterator.getCurrent());
176
- while (iterator.next().await())
177
- {
178
- result += `,${this.toString(iterator.getCurrent())}`;
179
- }
180
- }
181
-
182
- result += "}";
183
- return result;
184
- }
185
- }
package/sources/types.ts DELETED
@@ -1,371 +0,0 @@
1
- import { Iterable } from "./iterable";
2
- import { Iterator } from "./iterator";
3
- import { JavascriptAsyncIterable, JavascriptAsyncIterator, JavascriptIterable, JavascriptIterator } from "./javascript";
4
-
5
- /**
6
- * A {@link Type} that can be used to pass types as parameters.
7
- */
8
- export type Type<T> = Function & { prototype: T };
9
-
10
- /**
11
- * Get whether the provided value is an instance of {@link Type} {@link T}.
12
- * @param typeOrTypeCheck The {@link Type} to look for or type check {@link Function} to determine
13
- * if the provided value is a {@link T}.
14
- * @param value The value to check.
15
- */
16
- export function instanceOf<T>(value: unknown, typeCheck: (value: unknown) => value is T): value is T;
17
- /**
18
- * Get whether the provided value is an instance of {@link Type} {@link T}.
19
- * @param typeOrTypeCheck The {@link Type} to look for or type check {@link Function} to determine
20
- * if the provided value is a {@link T}.
21
- * @param value The value to check.
22
- */
23
- export function instanceOf<T>(value: unknown, type: Type<T>, typeCheck?: (value: unknown) => value is T): value is T;
24
- export function instanceOf<T>(value: unknown, typeOrTypeCheck: Type<T> | ((value: unknown) => value is T), typeCheck?: (value: unknown) => value is T): value is T
25
- {
26
- let result: boolean;
27
- if (!isUndefinedOrNull(typeCheck))
28
- {
29
- result = typeCheck(value);
30
- }
31
- else if (value instanceof typeOrTypeCheck)
32
- {
33
- result = true;
34
- }
35
- else if (isFunctionWithParameterCount(typeOrTypeCheck, 1))
36
- {
37
- typeCheck = typeOrTypeCheck as ((value: unknown) => value is T);
38
- result = typeCheck(value);
39
- }
40
- else
41
- {
42
- result = false;
43
- }
44
- return result;
45
- }
46
-
47
- /**
48
- * Get whether the provided value is an instance of the provided {@link Type}. This will return
49
- * false if value only implements the provided {@link Type} but doesn't extend it.
50
- * @param value The value to check.
51
- * @param type The {@link Type} to see if value is an instance of.
52
- */
53
- export function instanceOfType<T>(value: unknown, type: Type<T>): value is T
54
- {
55
- return value instanceof type;
56
- }
57
-
58
- /**
59
- * If the provided {@link value} is of type {@link T} (according to the provided {@link typeCheck}),
60
- * then return the {@link value}. Otherwise return undefined.
61
- * @param value The value to check.
62
- * @param typeOrTypeCheck The {@link Type} to look for or type check {@link Function} to determine
63
- * if the provided value is a {@link T}.
64
- */
65
- export function as<T>(value: unknown, typeOrTypeCheck: Type<T> | ((value: unknown) => value is T)): T | undefined
66
- {
67
- return instanceOf(value, typeOrTypeCheck) ? value as T : undefined;
68
- }
69
-
70
- /**
71
- * Get whether the provided value is undefined.
72
- * @param value The value to check.
73
- */
74
- export function isUndefined(value: unknown): value is undefined
75
- {
76
- return value === undefined;
77
- }
78
-
79
- /**
80
- * Get whether the provided value is null.
81
- * @param value The value to check.
82
- */
83
- export function isNull(value: unknown): value is null
84
- {
85
- return value === null;
86
- }
87
-
88
- /**
89
- * Return the provided value if it is null, otherwise return undefined.
90
- * @param value The value to check.
91
- */
92
- export function asNull(value: unknown): null | undefined
93
- {
94
- return as(value, isNull);
95
- }
96
-
97
- /**
98
- * Get whether the provided value is undefined or null.
99
- * @param value The value to check.
100
- */
101
- export function isUndefinedOrNull(value: unknown): value is undefined | null
102
- {
103
- return isUndefined(value) || isNull(value);
104
- }
105
-
106
- /**
107
- * Get whether the provided value is a {@link boolean}.
108
- * @param value The value to check.
109
- */
110
- export function isBoolean(value: unknown): value is boolean
111
- {
112
- return typeof value === "boolean";
113
- }
114
-
115
- /**
116
- * Return the provided value if it is a boolean, otherwise return undefined.
117
- * @param value The value to check.
118
- */
119
- export function asBoolean(value: unknown): boolean | undefined
120
- {
121
- return as(value, isBoolean);
122
- }
123
-
124
- /**
125
- * Get whether the provided value is a {@link number}.
126
- * @param value The value to check.
127
- */
128
- export function isNumber(value: unknown): value is number
129
- {
130
- return typeof value === "number";
131
- }
132
-
133
- /**
134
- * Return the provided value if it is a number, otherwise return undefined.
135
- * @param value The value to check.
136
- */
137
- export function asNumber(value: unknown): number | undefined
138
- {
139
- return as(value, isNumber);
140
- }
141
-
142
- /**
143
- * Get whether the provided value is a {@link string}.
144
- * @param value The value to check.
145
- */
146
- export function isString(value: unknown): value is string
147
- {
148
- return typeof value === "string";
149
- }
150
-
151
- /**
152
- * Return the provided value if it is a string, otherwise return undefined.
153
- * @param value The value to check.
154
- */
155
- export function asString(value: unknown): string | undefined
156
- {
157
- return as(value, isString);
158
- }
159
-
160
- /**
161
- * Get whether the provided value is a {@link function}.
162
- * @param value The value to check.
163
- */
164
- export function isFunction(value: unknown): value is Function
165
- {
166
- return typeof value === "function";
167
- }
168
-
169
- /**
170
- * Return the provided value if it is a function, otherwise return undefined.
171
- * @param value The value to check.
172
- */
173
- export function asFunction(value: unknown): Function | undefined
174
- {
175
- return as(value, isFunction);
176
- }
177
-
178
- /**
179
- * Get the number of parameters that the provided {@link Function} takes.
180
- * @param value The {@link Function} to get the parameter count for.
181
- */
182
- export function getParameterCount(value: Function): number
183
- {
184
- return value.length;
185
- }
186
-
187
- /**
188
- * Get whether the provided value is a function with the provided parameter count.
189
- * @param value The value to check.
190
- * @param parameterCount The number of parameters the function must have.
191
- */
192
- export function isFunctionWithParameterCount(value: unknown, parameterCount: number): value is Function
193
- {
194
- return isFunction(value) && getParameterCount(value) === parameterCount;
195
- }
196
-
197
- /**
198
- * Return the provided value if it is a function with the provided {@link parameterCount}, otherwise
199
- * return undefined.
200
- * @param value The value to check.
201
- */
202
- export function asFunctionWithParameterCount(value: unknown, parameterCount: number): Function | undefined
203
- {
204
- return as(value, (v: unknown) => isFunctionWithParameterCount(v, parameterCount));
205
- }
206
-
207
- /**
208
- * Get whether the provided value is an {@link Array}.
209
- * @param value The value to check.
210
- */
211
- export function isArray(value: unknown): value is unknown[]
212
- {
213
- return Array.isArray(value);
214
- }
215
-
216
- /**
217
- * Return the provided value if it is an array, otherwise return undefined.
218
- * @param value The value to check.
219
- */
220
- export function asArray(value: unknown): unknown[] | undefined
221
- {
222
- return as(value, isArray);
223
- }
224
-
225
- /**
226
- * Get whether the provided value is an {@link Object} or is null.
227
- * @param value The value to check.
228
- */
229
- export function isObjectOrArrayOrNull(value: unknown): value is {} | unknown[] | null
230
- {
231
- return typeof value === "object";
232
- }
233
-
234
- /**
235
- * Return the provided value if it is an array, otherwise return undefined.
236
- * @param value The value to check.
237
- */
238
- export function asObjectOrArrayOrNull(value: unknown): {} | unknown[] | null | undefined
239
- {
240
- return as(value, isObjectOrArrayOrNull);
241
- }
242
-
243
- /**
244
- * Get whether the provided value is an {@link Object}.
245
- * @param value The value to check.
246
- * @returns
247
- */
248
- export function isObject(value: unknown): value is {}
249
- {
250
- return isObjectOrArrayOrNull(value) && !!value && !isArray(value);
251
- }
252
-
253
- /**
254
- * Return the provided value if it is an {@link Object}, otherwise return undefined.
255
- * @param value The value to check.
256
- */
257
- export function asObject(value: unknown): {} | undefined
258
- {
259
- return as(value, isObject);
260
- }
261
-
262
- /**
263
- * Get an {@link Iterator} that can be used to iterate through the properties of the provided value.
264
- * @param value The value to iterate over.
265
- */
266
- export function getPropertyNames(value: {}): Iterable<string>
267
- {
268
- return Iterable.create(Object.keys(value));
269
- }
270
-
271
- /**
272
- * Get whether the provided value has a property with the provided key.
273
- * @param value The value to check.
274
- * @param propertyKey The key of the property to look for.
275
- */
276
- export function hasProperty<TValue, TPropertyKey extends PropertyKey>(value: TValue, propertyKey: TPropertyKey): value is TValue & Record<TPropertyKey, unknown>
277
- {
278
- return value !== undefined && value !== null && (value as any)[propertyKey] !== undefined;
279
- }
280
-
281
- /**
282
- * Get whether the value has a function with the provided name.
283
- * @param value The value to check.
284
- * @param functionName The name of the function to look for.
285
- */
286
- export function hasFunction<TValue, TPropertyKey extends PropertyKey>(value: TValue, functionName: TPropertyKey, parameterCount?: number): value is TValue & Record<TPropertyKey,Function>
287
- {
288
- let result: boolean = false;
289
- if (value !== undefined && value !== null)
290
- {
291
- const func: unknown = (value as any)[functionName];
292
- if (isUndefinedOrNull(parameterCount))
293
- {
294
- result = isFunction(func);
295
- }
296
- else
297
- {
298
- result = isFunctionWithParameterCount(func, parameterCount);
299
- }
300
- }
301
- return result;
302
- }
303
-
304
- /**
305
- * Get whether the provided value is a {@link JavascriptIterator}.
306
- * @param value The value to check.
307
- */
308
- export function isJavascriptIterator<T>(value: unknown): value is JavascriptIterator<T>
309
- {
310
- return hasFunction(value, "next");
311
- }
312
-
313
- /**
314
- * Get whether the provided value is a {@link JavascriptIterable}.
315
- * @param value The value to check.
316
- */
317
- export function isJavascriptIterable<T>(value: unknown): value is JavascriptIterable<T>
318
- {
319
- return hasFunction(value, Symbol.iterator);
320
- }
321
-
322
- export function isIterable<T>(value: unknown): value is Iterable<T>
323
- {
324
- return isJavascriptIterable(value) &&
325
- hasFunction(value, "iterate", 0);
326
- }
327
-
328
- /**
329
- * Get whether the provided value is a {@link JavascriptAsyncIterator}.
330
- * @param value The value to check.
331
- */
332
- export function isJavascriptAsyncIterator<T>(value: unknown): value is JavascriptAsyncIterator<T>
333
- {
334
- return hasFunction(value, "next");
335
- }
336
-
337
- /**
338
- * Get whether the provided value is a {@link JavascriptAsyncIterable}.
339
- * @param value The value to check.
340
- */
341
- export function isJavascriptAsyncIterable<T>(value: unknown): value is JavascriptAsyncIterable<T>
342
- {
343
- return hasFunction(value, Symbol.asyncIterator);
344
- }
345
-
346
- export function isAsyncIterable<T>(value: unknown): value is AsyncIterable<T>
347
- {
348
- return isJavascriptAsyncIterable(value) &&
349
- hasFunction(value, "iterate", 0);
350
- }
351
-
352
- /**
353
- * Get the name of the provided {@link Type}.
354
- * @param type The {@link Type} to get the name of.
355
- */
356
- export function getName(type: Type<unknown>): string
357
- {
358
- return type.name;
359
- }
360
-
361
- export function isPromiseLike<T>(value: unknown): value is PromiseLike<T>
362
- {
363
- return hasFunction(value, "then", 2);
364
- }
365
-
366
- export function isPromise<T>(value: unknown): value is Promise<T>
367
- {
368
- return isPromiseLike<T>(value) &&
369
- hasFunction(value, "catch", 1) &&
370
- hasFunction(value, "finally", 1);
371
- }
@@ -1,143 +0,0 @@
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
- }