metano-runtime 3.0.1 → 3.1.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/dist/system/char-members.d.ts +51 -0
- package/dist/system/char-members.js +108 -0
- package/dist/system/collections/array-helpers.d.ts +28 -0
- package/dist/system/collections/array-helpers.js +105 -0
- package/dist/system/collections/hash-core.d.ts +5 -0
- package/dist/system/collections/hash-core.js +24 -0
- package/dist/system/collections/helpers.d.ts +16 -3
- package/dist/system/collections/helpers.js +28 -2
- package/dist/system/collections/immutable-list-builder-core.d.ts +7 -2
- package/dist/system/collections/immutable-list-builder-core.js +11 -0
- package/dist/system/collections/immutable-list-core.d.ts +8 -0
- package/dist/system/collections/immutable-list-core.js +19 -1
- package/dist/system/collections/immutable-storage.d.ts +2 -0
- package/dist/system/collections/immutable-storage.js +6 -1
- package/dist/system/collections/index.d.ts +2 -0
- package/dist/system/collections/index.js +2 -0
- package/dist/system/collections/interfaces.d.ts +13 -0
- package/dist/system/collections/list.d.ts +3 -0
- package/dist/system/collections/list.js +8 -11
- package/dist/system/collections/read-only-list.d.ts +11 -0
- package/dist/system/collections/read-only-list.js +26 -1
- package/dist/system/collections/sorted-list.d.ts +5 -0
- package/dist/system/collections/sorted-list.js +12 -1
- package/dist/system/collections/string-comparer.d.ts +14 -0
- package/dist/system/collections/string-comparer.js +45 -0
- package/dist/system/decimal-parsing.d.ts +12 -0
- package/dist/system/decimal-parsing.js +86 -0
- package/dist/system/exceptions/index.d.ts +1 -0
- package/dist/system/exceptions/index.js +1 -0
- package/dist/system/exceptions/throw-error.d.ts +7 -0
- package/dist/system/exceptions/throw-error.js +9 -0
- package/dist/system/index.d.ts +5 -0
- package/dist/system/index.js +5 -0
- package/dist/system/int64.d.ts +6 -0
- package/dist/system/int64.js +18 -9
- package/dist/system/integer-division.d.ts +12 -4
- package/dist/system/integer-division.js +19 -2
- package/dist/system/json/contract-name.d.ts +2 -1
- package/dist/system/json/contract-name.js +3 -2
- package/dist/system/json/converters.d.ts +15 -52
- package/dist/system/json/converters.js +33 -317
- package/dist/system/json/dictionary-keys.js +1 -3
- package/dist/system/json/index.d.ts +1 -1
- package/dist/system/json/index.js +1 -1
- package/dist/system/json/json-serializer.d.ts +12 -1
- package/dist/system/json/json-serializer.js +29 -1
- package/dist/system/json/json-text-writer.d.ts +17 -0
- package/dist/system/json/json-text-writer.js +175 -0
- package/dist/system/json/null-reads.d.ts +2 -1
- package/dist/system/json/null-reads.js +3 -1
- package/dist/system/json/number-from-string.d.ts +2 -0
- package/dist/system/json/number-from-string.js +24 -6
- package/dist/system/json/numeric-converters.d.ts +4 -4
- package/dist/system/json/numeric-converters.js +46 -8
- package/dist/system/json/numeric-enum-members.d.ts +3 -3
- package/dist/system/json/numeric-enum-members.js +2 -4
- package/dist/system/json/spec-plans.d.ts +102 -0
- package/dist/system/json/spec-plans.js +312 -0
- package/dist/system/json/types.d.ts +15 -9
- package/dist/system/lazy.d.ts +15 -0
- package/dist/system/lazy.js +43 -0
- package/dist/system/linq/grouping.d.ts +12 -0
- package/dist/system/linq/grouping.js +42 -0
- package/dist/system/linq/index.d.ts +4 -3
- package/dist/system/linq/index.js +3 -2
- package/dist/system/linq/linq.js +20 -1
- package/dist/system/linq/lookup.d.ts +17 -0
- package/dist/system/linq/lookup.js +20 -0
- package/dist/system/linq/operators.d.ts +35 -5
- package/dist/system/linq/operators.js +82 -31
- package/dist/system/linq/terminals.d.ts +41 -2
- package/dist/system/linq/terminals.js +122 -2
- package/dist/system/linq/types.d.ts +48 -4
- package/dist/system/math.d.ts +7 -0
- package/dist/system/math.js +14 -0
- package/dist/system/number-members.d.ts +10 -0
- package/dist/system/number-members.js +25 -0
- package/dist/system/number-parsing.d.ts +16 -4
- package/dist/system/number-parsing.js +21 -4
- package/dist/system/string-builder.d.ts +30 -0
- package/dist/system/string-builder.js +86 -0
- package/dist/system/task-completion-source.d.ts +37 -0
- package/dist/system/task-completion-source.js +81 -0
- package/dist-unchecked/system/char-members.d.ts +51 -0
- package/dist-unchecked/system/char-members.js +108 -0
- package/dist-unchecked/system/collections/array-helpers.d.ts +28 -0
- package/dist-unchecked/system/collections/array-helpers.js +105 -0
- package/dist-unchecked/system/collections/hash-core.d.ts +5 -0
- package/dist-unchecked/system/collections/hash-core.js +24 -0
- package/dist-unchecked/system/collections/helpers.d.ts +16 -3
- package/dist-unchecked/system/collections/helpers.js +28 -2
- package/dist-unchecked/system/collections/immutable-list-builder-core.d.ts +7 -2
- package/dist-unchecked/system/collections/immutable-list-builder-core.js +11 -0
- package/dist-unchecked/system/collections/immutable-list-core.d.ts +8 -0
- package/dist-unchecked/system/collections/immutable-list-core.js +19 -1
- package/dist-unchecked/system/collections/immutable-storage.d.ts +2 -0
- package/dist-unchecked/system/collections/immutable-storage.js +6 -1
- package/dist-unchecked/system/collections/index.d.ts +2 -0
- package/dist-unchecked/system/collections/index.js +2 -0
- package/dist-unchecked/system/collections/interfaces.d.ts +13 -0
- package/dist-unchecked/system/collections/list.d.ts +3 -0
- package/dist-unchecked/system/collections/list.js +8 -11
- package/dist-unchecked/system/collections/read-only-list.d.ts +11 -0
- package/dist-unchecked/system/collections/read-only-list.js +26 -1
- package/dist-unchecked/system/collections/sorted-list.d.ts +5 -0
- package/dist-unchecked/system/collections/sorted-list.js +12 -1
- package/dist-unchecked/system/collections/string-comparer.d.ts +14 -0
- package/dist-unchecked/system/collections/string-comparer.js +45 -0
- package/dist-unchecked/system/decimal-parsing.d.ts +12 -0
- package/dist-unchecked/system/decimal-parsing.js +86 -0
- package/dist-unchecked/system/exceptions/index.d.ts +1 -0
- package/dist-unchecked/system/exceptions/index.js +1 -0
- package/dist-unchecked/system/exceptions/throw-error.d.ts +7 -0
- package/dist-unchecked/system/exceptions/throw-error.js +9 -0
- package/dist-unchecked/system/index.d.ts +5 -0
- package/dist-unchecked/system/index.js +5 -0
- package/dist-unchecked/system/int64.d.ts +6 -0
- package/dist-unchecked/system/int64.js +18 -9
- package/dist-unchecked/system/integer-division.d.ts +12 -4
- package/dist-unchecked/system/integer-division.js +19 -2
- package/dist-unchecked/system/json/contract-name.d.ts +2 -1
- package/dist-unchecked/system/json/contract-name.js +3 -2
- package/dist-unchecked/system/json/converters.d.ts +15 -52
- package/dist-unchecked/system/json/converters.js +33 -317
- package/dist-unchecked/system/json/dictionary-keys.js +1 -3
- package/dist-unchecked/system/json/index.d.ts +1 -1
- package/dist-unchecked/system/json/index.js +1 -1
- package/dist-unchecked/system/json/json-serializer.d.ts +12 -1
- package/dist-unchecked/system/json/json-serializer.js +29 -1
- package/dist-unchecked/system/json/json-text-writer.d.ts +17 -0
- package/dist-unchecked/system/json/json-text-writer.js +175 -0
- package/dist-unchecked/system/json/null-reads.d.ts +2 -1
- package/dist-unchecked/system/json/null-reads.js +3 -1
- package/dist-unchecked/system/json/number-from-string.d.ts +2 -0
- package/dist-unchecked/system/json/number-from-string.js +24 -6
- package/dist-unchecked/system/json/numeric-converters.d.ts +4 -4
- package/dist-unchecked/system/json/numeric-converters.js +46 -8
- package/dist-unchecked/system/json/numeric-enum-members.d.ts +3 -3
- package/dist-unchecked/system/json/numeric-enum-members.js +2 -4
- package/dist-unchecked/system/json/spec-plans.d.ts +102 -0
- package/dist-unchecked/system/json/spec-plans.js +312 -0
- package/dist-unchecked/system/json/types.d.ts +15 -9
- package/dist-unchecked/system/lazy.d.ts +15 -0
- package/dist-unchecked/system/lazy.js +43 -0
- package/dist-unchecked/system/linq/grouping.d.ts +12 -0
- package/dist-unchecked/system/linq/grouping.js +42 -0
- package/dist-unchecked/system/linq/index.d.ts +4 -3
- package/dist-unchecked/system/linq/index.js +3 -2
- package/dist-unchecked/system/linq/linq.js +20 -1
- package/dist-unchecked/system/linq/lookup.d.ts +17 -0
- package/dist-unchecked/system/linq/lookup.js +20 -0
- package/dist-unchecked/system/linq/operators.d.ts +35 -5
- package/dist-unchecked/system/linq/operators.js +82 -31
- package/dist-unchecked/system/linq/terminals.d.ts +41 -2
- package/dist-unchecked/system/linq/terminals.js +122 -2
- package/dist-unchecked/system/linq/types.d.ts +48 -4
- package/dist-unchecked/system/math.d.ts +7 -0
- package/dist-unchecked/system/math.js +14 -0
- package/dist-unchecked/system/number-members.d.ts +10 -0
- package/dist-unchecked/system/number-members.js +25 -0
- package/dist-unchecked/system/number-parsing.d.ts +16 -4
- package/dist-unchecked/system/number-parsing.js +21 -4
- package/dist-unchecked/system/string-builder.d.ts +30 -0
- package/dist-unchecked/system/string-builder.js +86 -0
- package/dist-unchecked/system/task-completion-source.d.ts +37 -0
- package/dist-unchecked/system/task-completion-source.js +81 -0
- package/package.json +1 -1
- package/src/system/char-members.ts +131 -0
- package/src/system/collections/array-helpers.ts +139 -0
- package/src/system/collections/hash-core.ts +31 -0
- package/src/system/collections/helpers.ts +39 -4
- package/src/system/collections/immutable-list-builder-core.ts +16 -2
- package/src/system/collections/immutable-list-core.ts +23 -1
- package/src/system/collections/immutable-storage.ts +8 -1
- package/src/system/collections/index.ts +2 -0
- package/src/system/collections/interfaces.ts +16 -0
- package/src/system/collections/list.ts +10 -15
- package/src/system/collections/read-only-list.ts +35 -1
- package/src/system/collections/sorted-list.ts +15 -1
- package/src/system/collections/string-comparer.ts +57 -0
- package/src/system/decimal-parsing.ts +109 -0
- package/src/system/exceptions/index.ts +1 -0
- package/src/system/exceptions/throw-error.ts +9 -0
- package/src/system/index.ts +5 -0
- package/src/system/int64.ts +27 -10
- package/src/system/integer-division.ts +43 -6
- package/src/system/json/contract-name.ts +3 -2
- package/src/system/json/converters.ts +38 -526
- package/src/system/json/dictionary-keys.ts +6 -4
- package/src/system/json/index.ts +1 -1
- package/src/system/json/json-serializer.ts +42 -1
- package/src/system/json/json-text-writer.ts +224 -0
- package/src/system/json/null-reads.ts +3 -1
- package/src/system/json/number-from-string.ts +31 -6
- package/src/system/json/numeric-converters.ts +60 -8
- package/src/system/json/numeric-enum-members.ts +4 -6
- package/src/system/json/spec-plans.ts +524 -0
- package/src/system/json/types.ts +15 -9
- package/src/system/lazy.ts +62 -0
- package/src/system/linq/grouping.ts +77 -0
- package/src/system/linq/index.ts +14 -0
- package/src/system/linq/linq.ts +23 -1
- package/src/system/linq/lookup.ts +34 -0
- package/src/system/linq/operators.ts +109 -17
- package/src/system/linq/terminals.ts +161 -2
- package/src/system/linq/types.ts +66 -3
- package/src/system/math.ts +19 -0
- package/src/system/number-members.ts +29 -0
- package/src/system/number-parsing.ts +24 -4
- package/src/system/string-builder.ts +117 -0
- package/src/system/task-completion-source.ts +106 -0
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `System.Text.StringBuilder`: a mutable text. Every mutator returns the builder, so calls
|
|
3
|
+
* chain as they do in C#. `AppendLine` adds `\n` (`Environment.NewLine` on Unix); an index
|
|
4
|
+
* or count outside the text throws `ArgumentOutOfRangeException`.
|
|
5
|
+
*/
|
|
6
|
+
export declare class StringBuilder {
|
|
7
|
+
private text;
|
|
8
|
+
constructor(initial?: string | null);
|
|
9
|
+
/** The number of characters; assigning truncates, or pads with NUL characters. */
|
|
10
|
+
get length(): number;
|
|
11
|
+
set length(value: number);
|
|
12
|
+
/** `Append(value)`: `null` appends nothing. */
|
|
13
|
+
append(value: string | null | undefined): this;
|
|
14
|
+
/** `Append(char, repeatCount)`. */
|
|
15
|
+
appendRepeated(value: string, repeatCount: number): this;
|
|
16
|
+
/** `AppendLine(value)`. */
|
|
17
|
+
appendLine(value?: string | null): this;
|
|
18
|
+
/** `Clear()`. */
|
|
19
|
+
clear(): this;
|
|
20
|
+
/** `Insert(index, value)`. */
|
|
21
|
+
insert(index: number, value: string | null | undefined): this;
|
|
22
|
+
/** `Remove(startIndex, length)`. */
|
|
23
|
+
remove(startIndex: number, length: number): this;
|
|
24
|
+
/** `Replace(oldValue, newValue)`: every occurrence, literally. */
|
|
25
|
+
replace(oldValue: string, newValue: string | null | undefined): this;
|
|
26
|
+
/** `ToString()`. */
|
|
27
|
+
toString(): string;
|
|
28
|
+
/** `ToString(startIndex, length)`. */
|
|
29
|
+
toSubstring(startIndex: number, length: number): string;
|
|
30
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { ArgumentOutOfRangeException } from "./exceptions/index.js";
|
|
2
|
+
/**
|
|
3
|
+
* `System.Text.StringBuilder`: a mutable text. Every mutator returns the builder, so calls
|
|
4
|
+
* chain as they do in C#. `AppendLine` adds `\n` (`Environment.NewLine` on Unix); an index
|
|
5
|
+
* or count outside the text throws `ArgumentOutOfRangeException`.
|
|
6
|
+
*/
|
|
7
|
+
export class StringBuilder {
|
|
8
|
+
text;
|
|
9
|
+
constructor(initial) {
|
|
10
|
+
this.text = initial ?? "";
|
|
11
|
+
}
|
|
12
|
+
/** The number of characters; assigning truncates, or pads with NUL characters. */
|
|
13
|
+
get length() {
|
|
14
|
+
return this.text.length;
|
|
15
|
+
}
|
|
16
|
+
set length(value) {
|
|
17
|
+
if (value < 0) {
|
|
18
|
+
throw new ArgumentOutOfRangeException("value", value, "Length cannot be less than zero.");
|
|
19
|
+
}
|
|
20
|
+
this.text =
|
|
21
|
+
value <= this.text.length
|
|
22
|
+
? this.text.slice(0, value)
|
|
23
|
+
: this.text + "\0".repeat(value - this.text.length);
|
|
24
|
+
}
|
|
25
|
+
/** `Append(value)`: `null` appends nothing. */
|
|
26
|
+
append(value) {
|
|
27
|
+
this.text += value ?? "";
|
|
28
|
+
return this;
|
|
29
|
+
}
|
|
30
|
+
/** `Append(char, repeatCount)`. */
|
|
31
|
+
appendRepeated(value, repeatCount) {
|
|
32
|
+
if (repeatCount < 0) {
|
|
33
|
+
throw new ArgumentOutOfRangeException("repeatCount", repeatCount, `repeatCount ('${repeatCount}') must be a non-negative value.`);
|
|
34
|
+
}
|
|
35
|
+
this.text += value.repeat(repeatCount);
|
|
36
|
+
return this;
|
|
37
|
+
}
|
|
38
|
+
/** `AppendLine(value)`. */
|
|
39
|
+
appendLine(value) {
|
|
40
|
+
this.text += `${value ?? ""}\n`;
|
|
41
|
+
return this;
|
|
42
|
+
}
|
|
43
|
+
/** `Clear()`. */
|
|
44
|
+
clear() {
|
|
45
|
+
this.text = "";
|
|
46
|
+
return this;
|
|
47
|
+
}
|
|
48
|
+
/** `Insert(index, value)`. */
|
|
49
|
+
insert(index, value) {
|
|
50
|
+
requireInRange(index, 0, this.text.length, "index");
|
|
51
|
+
this.text = this.text.slice(0, index) + (value ?? "") + this.text.slice(index);
|
|
52
|
+
return this;
|
|
53
|
+
}
|
|
54
|
+
/** `Remove(startIndex, length)`. */
|
|
55
|
+
remove(startIndex, length) {
|
|
56
|
+
requireInRange(length, 0, this.text.length, "length");
|
|
57
|
+
requireInRange(startIndex, 0, this.text.length - length, "startIndex");
|
|
58
|
+
this.text = this.text.slice(0, startIndex) + this.text.slice(startIndex + length);
|
|
59
|
+
return this;
|
|
60
|
+
}
|
|
61
|
+
/** `Replace(oldValue, newValue)`: every occurrence, literally. */
|
|
62
|
+
replace(oldValue, newValue) {
|
|
63
|
+
if (oldValue === "") {
|
|
64
|
+
throw new ArgumentOutOfRangeException("oldValue", oldValue, "The value cannot be empty.");
|
|
65
|
+
}
|
|
66
|
+
this.text = this.text.split(oldValue).join(newValue ?? "");
|
|
67
|
+
return this;
|
|
68
|
+
}
|
|
69
|
+
/** `ToString()`. */
|
|
70
|
+
toString() {
|
|
71
|
+
return this.text;
|
|
72
|
+
}
|
|
73
|
+
/** `ToString(startIndex, length)`. */
|
|
74
|
+
toSubstring(startIndex, length) {
|
|
75
|
+
requireInRange(length, 0, this.text.length, "length");
|
|
76
|
+
requireInRange(startIndex, 0, this.text.length - length, "startIndex");
|
|
77
|
+
return this.text.slice(startIndex, startIndex + length);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
const INDEX_AT_MOST_COUNT_MESSAGE = "Index was out of range. Must be non-negative and less than or equal to the size of the collection.";
|
|
81
|
+
/** An index or length outside the text. */
|
|
82
|
+
function requireInRange(value, min, max, parameter) {
|
|
83
|
+
if (value < min || value > max) {
|
|
84
|
+
throw new ArgumentOutOfRangeException(parameter, undefined, INDEX_AT_MOST_COUNT_MESSAGE);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `System.Threading.Tasks.TaskCompletionSource<T>`: a promise (`task`) settled from outside.
|
|
3
|
+
* The first `set*` / `trySet*` call wins; `set*` after that throws `InvalidOperationException`
|
|
4
|
+
* and `trySet*` returns `false`. A faulted or canceled task whose rejection nobody observes
|
|
5
|
+
* does not become an unhandled rejection, as an unobserved .NET task does not crash.
|
|
6
|
+
*/
|
|
7
|
+
export declare class TaskCompletionSource<T> {
|
|
8
|
+
readonly task: Promise<T>;
|
|
9
|
+
private resolveTask;
|
|
10
|
+
private rejectTask;
|
|
11
|
+
private completed;
|
|
12
|
+
constructor();
|
|
13
|
+
/** `TrySetResult(value)`. */
|
|
14
|
+
trySetResult(value: T): boolean;
|
|
15
|
+
/** `TrySetException(exception)`. */
|
|
16
|
+
trySetException(exception: Error): boolean;
|
|
17
|
+
/**
|
|
18
|
+
* `TrySetException(IEnumerable<Exception>)`: the task faults with the first exception, which
|
|
19
|
+
* is what awaiting it throws.
|
|
20
|
+
*
|
|
21
|
+
* @throws ArgumentNullException for `null`.
|
|
22
|
+
* @throws ArgumentException for an empty sequence.
|
|
23
|
+
*/
|
|
24
|
+
trySetExceptions(exceptions: Iterable<Error> | null): boolean;
|
|
25
|
+
/** `SetException(IEnumerable<Exception>)`. */
|
|
26
|
+
setExceptions(exceptions: Iterable<Error> | null): void;
|
|
27
|
+
/** `TrySetCanceled()`. */
|
|
28
|
+
trySetCanceled(): boolean;
|
|
29
|
+
/** `SetResult(value)`. */
|
|
30
|
+
setResult(value: T): void;
|
|
31
|
+
/** `SetException(exception)`. */
|
|
32
|
+
setException(exception: Error): void;
|
|
33
|
+
/** `SetCanceled()`. */
|
|
34
|
+
setCanceled(): void;
|
|
35
|
+
private complete;
|
|
36
|
+
private require;
|
|
37
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { ArgumentException, ArgumentNullException, InvalidOperationException, TaskCanceledException, } from "./exceptions/index.js";
|
|
2
|
+
const ALREADY_COMPLETED_MESSAGE = "An attempt was made to transition a task to a final state when it had already completed.";
|
|
3
|
+
/**
|
|
4
|
+
* `System.Threading.Tasks.TaskCompletionSource<T>`: a promise (`task`) settled from outside.
|
|
5
|
+
* The first `set*` / `trySet*` call wins; `set*` after that throws `InvalidOperationException`
|
|
6
|
+
* and `trySet*` returns `false`. A faulted or canceled task whose rejection nobody observes
|
|
7
|
+
* does not become an unhandled rejection, as an unobserved .NET task does not crash.
|
|
8
|
+
*/
|
|
9
|
+
export class TaskCompletionSource {
|
|
10
|
+
task;
|
|
11
|
+
resolveTask;
|
|
12
|
+
rejectTask;
|
|
13
|
+
completed = false;
|
|
14
|
+
constructor() {
|
|
15
|
+
this.task = new Promise((resolve, reject) => {
|
|
16
|
+
this.resolveTask = resolve;
|
|
17
|
+
this.rejectTask = reject;
|
|
18
|
+
});
|
|
19
|
+
this.task.catch(() => undefined);
|
|
20
|
+
}
|
|
21
|
+
/** `TrySetResult(value)`. */
|
|
22
|
+
trySetResult(value) {
|
|
23
|
+
return this.complete(() => this.resolveTask(value));
|
|
24
|
+
}
|
|
25
|
+
/** `TrySetException(exception)`. */
|
|
26
|
+
trySetException(exception) {
|
|
27
|
+
return this.complete(() => this.rejectTask(exception));
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* `TrySetException(IEnumerable<Exception>)`: the task faults with the first exception, which
|
|
31
|
+
* is what awaiting it throws.
|
|
32
|
+
*
|
|
33
|
+
* @throws ArgumentNullException for `null`.
|
|
34
|
+
* @throws ArgumentException for an empty sequence.
|
|
35
|
+
*/
|
|
36
|
+
trySetExceptions(exceptions) {
|
|
37
|
+
return this.trySetException(firstException(exceptions));
|
|
38
|
+
}
|
|
39
|
+
/** `SetException(IEnumerable<Exception>)`. */
|
|
40
|
+
setExceptions(exceptions) {
|
|
41
|
+
this.setException(firstException(exceptions));
|
|
42
|
+
}
|
|
43
|
+
/** `TrySetCanceled()`. */
|
|
44
|
+
trySetCanceled() {
|
|
45
|
+
return this.complete(() => this.rejectTask(new TaskCanceledException()));
|
|
46
|
+
}
|
|
47
|
+
/** `SetResult(value)`. */
|
|
48
|
+
setResult(value) {
|
|
49
|
+
this.require(this.trySetResult(value));
|
|
50
|
+
}
|
|
51
|
+
/** `SetException(exception)`. */
|
|
52
|
+
setException(exception) {
|
|
53
|
+
this.require(this.trySetException(exception));
|
|
54
|
+
}
|
|
55
|
+
/** `SetCanceled()`. */
|
|
56
|
+
setCanceled() {
|
|
57
|
+
this.require(this.trySetCanceled());
|
|
58
|
+
}
|
|
59
|
+
complete(settle) {
|
|
60
|
+
if (this.completed) {
|
|
61
|
+
return false;
|
|
62
|
+
}
|
|
63
|
+
this.completed = true;
|
|
64
|
+
settle();
|
|
65
|
+
return true;
|
|
66
|
+
}
|
|
67
|
+
require(succeeded) {
|
|
68
|
+
if (!succeeded) {
|
|
69
|
+
throw new InvalidOperationException(ALREADY_COMPLETED_MESSAGE);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
function firstException(exceptions) {
|
|
74
|
+
if (exceptions === null) {
|
|
75
|
+
throw new ArgumentNullException("exceptions");
|
|
76
|
+
}
|
|
77
|
+
for (const exception of exceptions) {
|
|
78
|
+
return exception;
|
|
79
|
+
}
|
|
80
|
+
throw new ArgumentException("The exceptions collection was empty.", "exceptions");
|
|
81
|
+
}
|
package/package.json
CHANGED
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `System.Char` category tests (`char.IsLetter`, ...) over a one-code-unit string, which is
|
|
3
|
+
* how a `char` is represented. The tests read Unicode general categories, as .NET does, so a
|
|
4
|
+
* lone surrogate is in no category. The Unicode version is the JavaScript engine's, which can
|
|
5
|
+
* differ from .NET's for recently assigned code points.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
const LETTER = /^\p{L}$/u;
|
|
9
|
+
const DIGIT = /^\p{Nd}$/u;
|
|
10
|
+
const LETTER_OR_DIGIT = /^[\p{L}\p{Nd}]$/u;
|
|
11
|
+
const NUMBER = /^\p{N}$/u;
|
|
12
|
+
const UPPER = /^\p{Lu}$/u;
|
|
13
|
+
const LOWER = /^\p{Ll}$/u;
|
|
14
|
+
const PUNCTUATION = /^\p{P}$/u;
|
|
15
|
+
const SYMBOL = /^\p{S}$/u;
|
|
16
|
+
const SEPARATOR = /^\p{Z}$/u;
|
|
17
|
+
const CONTROL = /^\p{Cc}$/u;
|
|
18
|
+
/** U+0009-U+000D and U+0085 are white space in .NET beyond the Unicode separators (`\s` also admits U+FEFF). */
|
|
19
|
+
const WHITE_SPACE = /^[\p{Z}\t-\r\u0085]$/u;
|
|
20
|
+
|
|
21
|
+
/** `char.IsLetter(c)`. */
|
|
22
|
+
export function charIsLetter(c: string): boolean {
|
|
23
|
+
return LETTER.test(c);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** `char.IsDigit(c)`: a decimal digit of any script. */
|
|
27
|
+
export function charIsDigit(c: string): boolean {
|
|
28
|
+
return DIGIT.test(c);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** `char.IsLetterOrDigit(c)`. */
|
|
32
|
+
export function charIsLetterOrDigit(c: string): boolean {
|
|
33
|
+
return LETTER_OR_DIGIT.test(c);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** `char.IsNumber(c)`: a decimal digit, a letter number or another number. */
|
|
37
|
+
export function charIsNumber(c: string): boolean {
|
|
38
|
+
return NUMBER.test(c);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** `char.IsUpper(c)`. */
|
|
42
|
+
export function charIsUpper(c: string): boolean {
|
|
43
|
+
return UPPER.test(c);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** `char.IsLower(c)`. */
|
|
47
|
+
export function charIsLower(c: string): boolean {
|
|
48
|
+
return LOWER.test(c);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** `char.IsPunctuation(c)`. */
|
|
52
|
+
export function charIsPunctuation(c: string): boolean {
|
|
53
|
+
return PUNCTUATION.test(c);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** `char.IsSymbol(c)`. */
|
|
57
|
+
export function charIsSymbol(c: string): boolean {
|
|
58
|
+
return SYMBOL.test(c);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** `char.IsSeparator(c)`. */
|
|
62
|
+
export function charIsSeparator(c: string): boolean {
|
|
63
|
+
return SEPARATOR.test(c);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** `char.IsControl(c)`. */
|
|
67
|
+
export function charIsControl(c: string): boolean {
|
|
68
|
+
return CONTROL.test(c);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** `char.IsWhiteSpace(c)`. */
|
|
72
|
+
export function charIsWhiteSpace(c: string): boolean {
|
|
73
|
+
return WHITE_SPACE.test(c);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** `char.IsAscii(c)`: a code unit below U+0080. */
|
|
77
|
+
export function charIsAscii(c: string): boolean {
|
|
78
|
+
return c.charCodeAt(0) < 0x80;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/** `char.IsAsciiDigit(c)`: `0`-`9`. */
|
|
82
|
+
export function charIsAsciiDigit(c: string): boolean {
|
|
83
|
+
return c >= "0" && c <= "9";
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/** `char.IsAsciiLetterLower(c)`: `a`-`z`. */
|
|
87
|
+
export function charIsAsciiLetterLower(c: string): boolean {
|
|
88
|
+
return c >= "a" && c <= "z";
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/** `char.IsAsciiLetterUpper(c)`: `A`-`Z`. */
|
|
92
|
+
export function charIsAsciiLetterUpper(c: string): boolean {
|
|
93
|
+
return c >= "A" && c <= "Z";
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/** `char.IsAsciiLetter(c)`: `a`-`z` or `A`-`Z`. */
|
|
97
|
+
export function charIsAsciiLetter(c: string): boolean {
|
|
98
|
+
return charIsAsciiLetterLower(c) || charIsAsciiLetterUpper(c);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/** `char.IsAsciiLetterOrDigit(c)`. */
|
|
102
|
+
export function charIsAsciiLetterOrDigit(c: string): boolean {
|
|
103
|
+
return charIsAsciiLetter(c) || charIsAsciiDigit(c);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/** `char.IsAsciiHexDigitLower(c)`: `0`-`9` or `a`-`f`. */
|
|
107
|
+
export function charIsAsciiHexDigitLower(c: string): boolean {
|
|
108
|
+
return charIsAsciiDigit(c) || (c >= "a" && c <= "f");
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/** `char.IsAsciiHexDigitUpper(c)`: `0`-`9` or `A`-`F`. */
|
|
112
|
+
export function charIsAsciiHexDigitUpper(c: string): boolean {
|
|
113
|
+
return charIsAsciiDigit(c) || (c >= "A" && c <= "F");
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/** `char.IsAsciiHexDigit(c)`: `0`-`9`, `a`-`f` or `A`-`F`. */
|
|
117
|
+
export function charIsAsciiHexDigit(c: string): boolean {
|
|
118
|
+
return charIsAsciiHexDigitLower(c) || charIsAsciiHexDigitUpper(c);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* `char.IsBetween(c, min, max)`: .NET computes `(uint)(c - min) <= (uint)(max - min)`
|
|
123
|
+
* by code unit, so the range wraps around when `min > max`.
|
|
124
|
+
*/
|
|
125
|
+
export function charIsBetween(c: string, min: string, max: string): boolean {
|
|
126
|
+
const start = min.charCodeAt(0);
|
|
127
|
+
const offset = (c.charCodeAt(0) - start) >>> 0;
|
|
128
|
+
const width = (max.charCodeAt(0) - start) >>> 0;
|
|
129
|
+
|
|
130
|
+
return offset <= width;
|
|
131
|
+
}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The free helpers an array or a span lowers to (#663, #664): the default order of
|
|
3
|
+
* `Array.Sort` / `MemoryExtensions.Sort`, and the value-equality searches of
|
|
4
|
+
* `Array.IndexOf` / `MemoryExtensions.Contains`. JavaScript's own `sort()` orders by text
|
|
5
|
+
* and `indexOf` compares by identity, so neither is what C# computes.
|
|
6
|
+
*/
|
|
7
|
+
import { type ComparisonArgument, comparisonOf, elementEquals } from "./default-comparer.ts";
|
|
8
|
+
import {
|
|
9
|
+
throwArgumentNull,
|
|
10
|
+
throwArrayTooSmall,
|
|
11
|
+
throwCompareFailed,
|
|
12
|
+
throwIndexAtMostCount,
|
|
13
|
+
} from "./throw-helpers.ts";
|
|
14
|
+
|
|
15
|
+
/** Primitives other than `NaN` compare by `===`, which `Array#indexOf` uses. */
|
|
16
|
+
export function isIdentityComparable(value: unknown): boolean {
|
|
17
|
+
return typeof value !== "object" && !Number.isNaN(value);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Sorts `items` in place (stable) with `comparison` or `Comparer<T>.Default`; a comparison
|
|
22
|
+
* that throws surfaces as `InvalidOperationException`, as `Array.Sort` reports it.
|
|
23
|
+
*/
|
|
24
|
+
export function sortInPlace<T>(items: T[], comparison?: ComparisonArgument<T>): void {
|
|
25
|
+
const compare = comparisonOf(comparison);
|
|
26
|
+
|
|
27
|
+
try {
|
|
28
|
+
items.sort(compare);
|
|
29
|
+
} catch (error) {
|
|
30
|
+
throwCompareFailed(error);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** `Array.Sort(array)`, `Array.Sort(array, comparison | comparer)`, `span.Sort(...)`. */
|
|
35
|
+
export function sortArray<T>(
|
|
36
|
+
array: T[] | null | undefined,
|
|
37
|
+
comparison?: ComparisonArgument<T>,
|
|
38
|
+
): void {
|
|
39
|
+
if (array === null || array === undefined) {
|
|
40
|
+
throwArgumentNull("array");
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
if (array.length > 1) {
|
|
44
|
+
sortInPlace(array, comparison);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** `Array.Sort(keys, items, comparer?)`: both arrays are permuted by the order of the keys. */
|
|
49
|
+
export function sortArrayByKeys<K, V>(
|
|
50
|
+
keys: K[] | null | undefined,
|
|
51
|
+
items: V[] | null | undefined,
|
|
52
|
+
comparison?: ComparisonArgument<K>,
|
|
53
|
+
): void {
|
|
54
|
+
if (keys === null || keys === undefined) {
|
|
55
|
+
throwArgumentNull("keys");
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
if (items === null || items === undefined) {
|
|
59
|
+
sortArray(keys, comparison);
|
|
60
|
+
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
if (items.length < keys.length) {
|
|
65
|
+
throwArrayTooSmall();
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const compare = comparisonOf(comparison);
|
|
69
|
+
const order = keys.map((_, index) => index);
|
|
70
|
+
|
|
71
|
+
try {
|
|
72
|
+
order.sort((a, b) => compare(keys[a] as K, keys[b] as K));
|
|
73
|
+
} catch (error) {
|
|
74
|
+
throwCompareFailed(error);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const sortedKeys = order.map((index) => keys[index] as K);
|
|
78
|
+
const sortedItems = order.map((index) => items[index] as V);
|
|
79
|
+
|
|
80
|
+
sortedKeys.forEach((key, index) => {
|
|
81
|
+
keys[index] = key;
|
|
82
|
+
items[index] = sortedItems[index] as V;
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* `Array.IndexOf(array, value, start?)` and the span search: `EqualityComparer<T>.Default`
|
|
88
|
+
* semantics (a record, a decimal or a date compares by value, `NaN` finds `NaN`). A string
|
|
89
|
+
* receiver, which a `ReadOnlySpan<char>` over text is, searches its characters.
|
|
90
|
+
*/
|
|
91
|
+
export function arrayIndexOf<T>(array: readonly T[] | string, value: T, start?: number): number {
|
|
92
|
+
const from = start ?? 0;
|
|
93
|
+
|
|
94
|
+
if (typeof array === "string") {
|
|
95
|
+
return array.indexOf(value as string, from);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
if (from >>> 0 > array.length) {
|
|
99
|
+
throwIndexAtMostCount();
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
if (isIdentityComparable(value)) {
|
|
103
|
+
return array.indexOf(value, from);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
for (let position = from; position < array.length; position++) {
|
|
107
|
+
if (elementEquals(array[position], value)) {
|
|
108
|
+
return position;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
return -1;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/** `Array.LastIndexOf(array, value)` and the span search; see {@link arrayIndexOf}. */
|
|
116
|
+
export function arrayLastIndexOf<T>(array: readonly T[] | string, value: T): number {
|
|
117
|
+
if (typeof array === "string") {
|
|
118
|
+
return array.lastIndexOf(value as string);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
if (isIdentityComparable(value)) {
|
|
122
|
+
return array.lastIndexOf(value);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
for (let position = array.length - 1; position >= 0; position--) {
|
|
126
|
+
if (elementEquals(array[position], value)) {
|
|
127
|
+
return position;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
return -1;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/** `span.Contains(value)` and `array.Contains(value)`; see {@link arrayIndexOf}. */
|
|
135
|
+
export function arrayContains<T>(array: readonly T[] | string, value: T): boolean {
|
|
136
|
+
return typeof array === "string"
|
|
137
|
+
? array.includes(value as string)
|
|
138
|
+
: arrayIndexOf(array, value) >= 0;
|
|
139
|
+
}
|
|
@@ -111,6 +111,37 @@ export class HashCore<K, V> {
|
|
|
111
111
|
return true;
|
|
112
112
|
}
|
|
113
113
|
|
|
114
|
+
/**
|
|
115
|
+
* Appends `element` to the array stored under `key`, storing a new array when there is none:
|
|
116
|
+
* a `get` and a `set` in one lookup, for the groupings of `groupBy`, `toLookup` and `join`.
|
|
117
|
+
*/
|
|
118
|
+
append<E>(this: HashCore<K, E[]>, key: K, element: E): void {
|
|
119
|
+
const entries = this._entries;
|
|
120
|
+
|
|
121
|
+
if (this._direct(key)) {
|
|
122
|
+
const bucket = entries.get(key);
|
|
123
|
+
|
|
124
|
+
if (bucket === undefined) {
|
|
125
|
+
entries.set(key, [element]);
|
|
126
|
+
} else {
|
|
127
|
+
bucket.push(element);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
const stored = this._find(key);
|
|
134
|
+
|
|
135
|
+
if (!isMissing(stored)) {
|
|
136
|
+
entries.get(stored)!.push(element);
|
|
137
|
+
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
entries.set(key, [element]);
|
|
142
|
+
this._bucketOf(this._hash(key)).push(key);
|
|
143
|
+
}
|
|
144
|
+
|
|
114
145
|
delete(key: K): boolean {
|
|
115
146
|
if (this._direct(key)) {
|
|
116
147
|
return this._entries.delete(key);
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import { IndexOutOfRangeException } from "../exceptions/index-out-of-range-exception.ts";
|
|
7
7
|
import { invalidCast } from "../reflection/invalid-cast.ts";
|
|
8
|
-
import type { IList, Span } from "./interfaces.ts";
|
|
8
|
+
import type { IList, IReadOnlyList, Span } from "./interfaces.ts";
|
|
9
9
|
import { List } from "./list.ts";
|
|
10
10
|
import { throwArgumentNull } from "./throw-helpers.ts";
|
|
11
11
|
|
|
@@ -44,7 +44,11 @@ export function asArray(value: unknown): unknown[] | null {
|
|
|
44
44
|
return value instanceof List && value.isFixedSize ? value._items : null;
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
-
/**
|
|
47
|
+
/**
|
|
48
|
+
* `list.AsJsArray()`: the backing array itself; `ArgumentNullException` for `null`.
|
|
49
|
+
* Contract (mirroring `CollectionsMarshal.AsSpan`): do not add or remove elements
|
|
50
|
+
* through the writable view while the `List` is being enumerated (it bypasses `_version`).
|
|
51
|
+
*/
|
|
48
52
|
export function asJsArray<T>(list: List<T> | null | undefined): T[] {
|
|
49
53
|
if (list === null || list === undefined) {
|
|
50
54
|
throwArgumentNull("list");
|
|
@@ -53,6 +57,32 @@ export function asJsArray<T>(list: List<T> | null | undefined): T[] {
|
|
|
53
57
|
return list._items;
|
|
54
58
|
}
|
|
55
59
|
|
|
60
|
+
/**
|
|
61
|
+
* `list.AsReadOnlyJsArray()`: a read-only view `readonly T[]` over the list's
|
|
62
|
+
* backing array; `ArgumentNullException` for `null`. Zero-copy and live for
|
|
63
|
+
* runtime array-backed list kinds (and native arrays); a shallow snapshot copy
|
|
64
|
+
* (`Array.from(list)`) when `ReadOnlyList` wraps a custom `IList`, when the
|
|
65
|
+
* receiver lacks `asReadOnlyJsArray()` (such as a user `IReadOnlyList` class),
|
|
66
|
+
* and for older immutable versions sharing a grown store.
|
|
67
|
+
*/
|
|
68
|
+
export function asReadOnlyJsArray<T>(
|
|
69
|
+
list: IReadOnlyList<T> | readonly T[] | null | undefined,
|
|
70
|
+
): readonly T[] {
|
|
71
|
+
if (list === null || list === undefined) {
|
|
72
|
+
throwArgumentNull("list");
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if (Array.isArray(list)) {
|
|
76
|
+
return list;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
if (typeof (list as IReadOnlyList<T>).asReadOnlyJsArray === "function") {
|
|
80
|
+
return (list as IReadOnlyList<T>).asReadOnlyJsArray();
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
return Array.from(list);
|
|
84
|
+
}
|
|
85
|
+
|
|
56
86
|
/** `list.AsSpan()` / `CollectionsMarshal.AsSpan(list)`: the backing array; empty for `null`. */
|
|
57
87
|
export function asSpan<T>(list: List<T> | null | undefined): Span<T> {
|
|
58
88
|
return list === null || list === undefined ? [] : list._items;
|
|
@@ -73,7 +103,10 @@ export function asReadOnlySpan<T>(list: List<T> | null | undefined): ReadonlyArr
|
|
|
73
103
|
* collection descriptor), so an object that is not a list fails at its first use instead
|
|
74
104
|
* of at the cast.
|
|
75
105
|
*/
|
|
76
|
-
export function asList<T>(
|
|
106
|
+
export function asList<T>(
|
|
107
|
+
value: unknown,
|
|
108
|
+
targetType: string,
|
|
109
|
+
): (IList<T> & IReadOnlyList<T>) | null {
|
|
77
110
|
if (value === null || value === undefined) {
|
|
78
111
|
return null;
|
|
79
112
|
}
|
|
@@ -82,7 +115,9 @@ export function asList<T>(value: unknown, targetType: string): IList<T> | null {
|
|
|
82
115
|
throw invalidCast(value, targetType);
|
|
83
116
|
}
|
|
84
117
|
|
|
85
|
-
return Array.isArray(value)
|
|
118
|
+
return Array.isArray(value)
|
|
119
|
+
? List.adopt(value as T[], { fixedSize: true })
|
|
120
|
+
: (value as IList<T> & IReadOnlyList<T>);
|
|
86
121
|
}
|
|
87
122
|
|
|
88
123
|
function isPrimitive(value: unknown): value is string | number | boolean | bigint {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type ComparisonArgument, elementEquals } from "./default-comparer.ts";
|
|
2
|
-
import type { IList } from "./interfaces.ts";
|
|
2
|
+
import type { IList, IReadOnlyList } from "./interfaces.ts";
|
|
3
3
|
import { List } from "./list.ts";
|
|
4
4
|
import { throwArgumentOutOfRange } from "./throw-helpers.ts";
|
|
5
5
|
|
|
@@ -14,7 +14,7 @@ import { throwArgumentOutOfRange } from "./throw-helpers.ts";
|
|
|
14
14
|
* check with .NET's default `ArgumentOutOfRangeException` text, not `List`'s.
|
|
15
15
|
* Internal.
|
|
16
16
|
*/
|
|
17
|
-
export abstract class ImmutableListBuilderCore<T> implements IList<T> {
|
|
17
|
+
export abstract class ImmutableListBuilderCore<T> implements IList<T>, IReadOnlyList<T> {
|
|
18
18
|
declare readonly _list: List<T>;
|
|
19
19
|
|
|
20
20
|
/** Defines `_list`, a copy of `source`; each subclass then defines its own fields. */
|
|
@@ -51,6 +51,10 @@ export abstract class ImmutableListBuilderCore<T> implements IList<T> {
|
|
|
51
51
|
return this._list.count;
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
+
get length(): number {
|
|
55
|
+
return this._list.count;
|
|
56
|
+
}
|
|
57
|
+
|
|
54
58
|
get isReadOnly(): boolean {
|
|
55
59
|
return false;
|
|
56
60
|
}
|
|
@@ -192,6 +196,16 @@ export abstract class ImmutableListBuilderCore<T> implements IList<T> {
|
|
|
192
196
|
this._list.copyTo(array, arrayIndex);
|
|
193
197
|
}
|
|
194
198
|
|
|
199
|
+
/** Detached shallow copy (FR-055). */
|
|
200
|
+
toArray(): T[] {
|
|
201
|
+
return this._list.toArray();
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
/** Zero-copy live read-only view over the builder's backing array (FR-056). */
|
|
205
|
+
asReadOnlyJsArray(): readonly T[] {
|
|
206
|
+
return this._list.asReadOnlyJsArray();
|
|
207
|
+
}
|
|
208
|
+
|
|
195
209
|
toJSON(): T[] {
|
|
196
210
|
return this._list.toArray();
|
|
197
211
|
}
|