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.
Files changed (211) hide show
  1. package/dist/system/char-members.d.ts +51 -0
  2. package/dist/system/char-members.js +108 -0
  3. package/dist/system/collections/array-helpers.d.ts +28 -0
  4. package/dist/system/collections/array-helpers.js +105 -0
  5. package/dist/system/collections/hash-core.d.ts +5 -0
  6. package/dist/system/collections/hash-core.js +24 -0
  7. package/dist/system/collections/helpers.d.ts +16 -3
  8. package/dist/system/collections/helpers.js +28 -2
  9. package/dist/system/collections/immutable-list-builder-core.d.ts +7 -2
  10. package/dist/system/collections/immutable-list-builder-core.js +11 -0
  11. package/dist/system/collections/immutable-list-core.d.ts +8 -0
  12. package/dist/system/collections/immutable-list-core.js +19 -1
  13. package/dist/system/collections/immutable-storage.d.ts +2 -0
  14. package/dist/system/collections/immutable-storage.js +6 -1
  15. package/dist/system/collections/index.d.ts +2 -0
  16. package/dist/system/collections/index.js +2 -0
  17. package/dist/system/collections/interfaces.d.ts +13 -0
  18. package/dist/system/collections/list.d.ts +3 -0
  19. package/dist/system/collections/list.js +8 -11
  20. package/dist/system/collections/read-only-list.d.ts +11 -0
  21. package/dist/system/collections/read-only-list.js +26 -1
  22. package/dist/system/collections/sorted-list.d.ts +5 -0
  23. package/dist/system/collections/sorted-list.js +12 -1
  24. package/dist/system/collections/string-comparer.d.ts +14 -0
  25. package/dist/system/collections/string-comparer.js +45 -0
  26. package/dist/system/decimal-parsing.d.ts +12 -0
  27. package/dist/system/decimal-parsing.js +86 -0
  28. package/dist/system/exceptions/index.d.ts +1 -0
  29. package/dist/system/exceptions/index.js +1 -0
  30. package/dist/system/exceptions/throw-error.d.ts +7 -0
  31. package/dist/system/exceptions/throw-error.js +9 -0
  32. package/dist/system/index.d.ts +5 -0
  33. package/dist/system/index.js +5 -0
  34. package/dist/system/int64.d.ts +6 -0
  35. package/dist/system/int64.js +18 -9
  36. package/dist/system/integer-division.d.ts +12 -4
  37. package/dist/system/integer-division.js +19 -2
  38. package/dist/system/json/contract-name.d.ts +2 -1
  39. package/dist/system/json/contract-name.js +3 -2
  40. package/dist/system/json/converters.d.ts +15 -52
  41. package/dist/system/json/converters.js +33 -317
  42. package/dist/system/json/dictionary-keys.js +1 -3
  43. package/dist/system/json/index.d.ts +1 -1
  44. package/dist/system/json/index.js +1 -1
  45. package/dist/system/json/json-serializer.d.ts +12 -1
  46. package/dist/system/json/json-serializer.js +29 -1
  47. package/dist/system/json/json-text-writer.d.ts +17 -0
  48. package/dist/system/json/json-text-writer.js +175 -0
  49. package/dist/system/json/null-reads.d.ts +2 -1
  50. package/dist/system/json/null-reads.js +3 -1
  51. package/dist/system/json/number-from-string.d.ts +2 -0
  52. package/dist/system/json/number-from-string.js +24 -6
  53. package/dist/system/json/numeric-converters.d.ts +4 -4
  54. package/dist/system/json/numeric-converters.js +46 -8
  55. package/dist/system/json/numeric-enum-members.d.ts +3 -3
  56. package/dist/system/json/numeric-enum-members.js +2 -4
  57. package/dist/system/json/spec-plans.d.ts +102 -0
  58. package/dist/system/json/spec-plans.js +312 -0
  59. package/dist/system/json/types.d.ts +15 -9
  60. package/dist/system/lazy.d.ts +15 -0
  61. package/dist/system/lazy.js +43 -0
  62. package/dist/system/linq/grouping.d.ts +12 -0
  63. package/dist/system/linq/grouping.js +42 -0
  64. package/dist/system/linq/index.d.ts +4 -3
  65. package/dist/system/linq/index.js +3 -2
  66. package/dist/system/linq/linq.js +20 -1
  67. package/dist/system/linq/lookup.d.ts +17 -0
  68. package/dist/system/linq/lookup.js +20 -0
  69. package/dist/system/linq/operators.d.ts +35 -5
  70. package/dist/system/linq/operators.js +82 -31
  71. package/dist/system/linq/terminals.d.ts +41 -2
  72. package/dist/system/linq/terminals.js +122 -2
  73. package/dist/system/linq/types.d.ts +48 -4
  74. package/dist/system/math.d.ts +7 -0
  75. package/dist/system/math.js +14 -0
  76. package/dist/system/number-members.d.ts +10 -0
  77. package/dist/system/number-members.js +25 -0
  78. package/dist/system/number-parsing.d.ts +16 -4
  79. package/dist/system/number-parsing.js +21 -4
  80. package/dist/system/string-builder.d.ts +30 -0
  81. package/dist/system/string-builder.js +86 -0
  82. package/dist/system/task-completion-source.d.ts +37 -0
  83. package/dist/system/task-completion-source.js +81 -0
  84. package/dist-unchecked/system/char-members.d.ts +51 -0
  85. package/dist-unchecked/system/char-members.js +108 -0
  86. package/dist-unchecked/system/collections/array-helpers.d.ts +28 -0
  87. package/dist-unchecked/system/collections/array-helpers.js +105 -0
  88. package/dist-unchecked/system/collections/hash-core.d.ts +5 -0
  89. package/dist-unchecked/system/collections/hash-core.js +24 -0
  90. package/dist-unchecked/system/collections/helpers.d.ts +16 -3
  91. package/dist-unchecked/system/collections/helpers.js +28 -2
  92. package/dist-unchecked/system/collections/immutable-list-builder-core.d.ts +7 -2
  93. package/dist-unchecked/system/collections/immutable-list-builder-core.js +11 -0
  94. package/dist-unchecked/system/collections/immutable-list-core.d.ts +8 -0
  95. package/dist-unchecked/system/collections/immutable-list-core.js +19 -1
  96. package/dist-unchecked/system/collections/immutable-storage.d.ts +2 -0
  97. package/dist-unchecked/system/collections/immutable-storage.js +6 -1
  98. package/dist-unchecked/system/collections/index.d.ts +2 -0
  99. package/dist-unchecked/system/collections/index.js +2 -0
  100. package/dist-unchecked/system/collections/interfaces.d.ts +13 -0
  101. package/dist-unchecked/system/collections/list.d.ts +3 -0
  102. package/dist-unchecked/system/collections/list.js +8 -11
  103. package/dist-unchecked/system/collections/read-only-list.d.ts +11 -0
  104. package/dist-unchecked/system/collections/read-only-list.js +26 -1
  105. package/dist-unchecked/system/collections/sorted-list.d.ts +5 -0
  106. package/dist-unchecked/system/collections/sorted-list.js +12 -1
  107. package/dist-unchecked/system/collections/string-comparer.d.ts +14 -0
  108. package/dist-unchecked/system/collections/string-comparer.js +45 -0
  109. package/dist-unchecked/system/decimal-parsing.d.ts +12 -0
  110. package/dist-unchecked/system/decimal-parsing.js +86 -0
  111. package/dist-unchecked/system/exceptions/index.d.ts +1 -0
  112. package/dist-unchecked/system/exceptions/index.js +1 -0
  113. package/dist-unchecked/system/exceptions/throw-error.d.ts +7 -0
  114. package/dist-unchecked/system/exceptions/throw-error.js +9 -0
  115. package/dist-unchecked/system/index.d.ts +5 -0
  116. package/dist-unchecked/system/index.js +5 -0
  117. package/dist-unchecked/system/int64.d.ts +6 -0
  118. package/dist-unchecked/system/int64.js +18 -9
  119. package/dist-unchecked/system/integer-division.d.ts +12 -4
  120. package/dist-unchecked/system/integer-division.js +19 -2
  121. package/dist-unchecked/system/json/contract-name.d.ts +2 -1
  122. package/dist-unchecked/system/json/contract-name.js +3 -2
  123. package/dist-unchecked/system/json/converters.d.ts +15 -52
  124. package/dist-unchecked/system/json/converters.js +33 -317
  125. package/dist-unchecked/system/json/dictionary-keys.js +1 -3
  126. package/dist-unchecked/system/json/index.d.ts +1 -1
  127. package/dist-unchecked/system/json/index.js +1 -1
  128. package/dist-unchecked/system/json/json-serializer.d.ts +12 -1
  129. package/dist-unchecked/system/json/json-serializer.js +29 -1
  130. package/dist-unchecked/system/json/json-text-writer.d.ts +17 -0
  131. package/dist-unchecked/system/json/json-text-writer.js +175 -0
  132. package/dist-unchecked/system/json/null-reads.d.ts +2 -1
  133. package/dist-unchecked/system/json/null-reads.js +3 -1
  134. package/dist-unchecked/system/json/number-from-string.d.ts +2 -0
  135. package/dist-unchecked/system/json/number-from-string.js +24 -6
  136. package/dist-unchecked/system/json/numeric-converters.d.ts +4 -4
  137. package/dist-unchecked/system/json/numeric-converters.js +46 -8
  138. package/dist-unchecked/system/json/numeric-enum-members.d.ts +3 -3
  139. package/dist-unchecked/system/json/numeric-enum-members.js +2 -4
  140. package/dist-unchecked/system/json/spec-plans.d.ts +102 -0
  141. package/dist-unchecked/system/json/spec-plans.js +312 -0
  142. package/dist-unchecked/system/json/types.d.ts +15 -9
  143. package/dist-unchecked/system/lazy.d.ts +15 -0
  144. package/dist-unchecked/system/lazy.js +43 -0
  145. package/dist-unchecked/system/linq/grouping.d.ts +12 -0
  146. package/dist-unchecked/system/linq/grouping.js +42 -0
  147. package/dist-unchecked/system/linq/index.d.ts +4 -3
  148. package/dist-unchecked/system/linq/index.js +3 -2
  149. package/dist-unchecked/system/linq/linq.js +20 -1
  150. package/dist-unchecked/system/linq/lookup.d.ts +17 -0
  151. package/dist-unchecked/system/linq/lookup.js +20 -0
  152. package/dist-unchecked/system/linq/operators.d.ts +35 -5
  153. package/dist-unchecked/system/linq/operators.js +82 -31
  154. package/dist-unchecked/system/linq/terminals.d.ts +41 -2
  155. package/dist-unchecked/system/linq/terminals.js +122 -2
  156. package/dist-unchecked/system/linq/types.d.ts +48 -4
  157. package/dist-unchecked/system/math.d.ts +7 -0
  158. package/dist-unchecked/system/math.js +14 -0
  159. package/dist-unchecked/system/number-members.d.ts +10 -0
  160. package/dist-unchecked/system/number-members.js +25 -0
  161. package/dist-unchecked/system/number-parsing.d.ts +16 -4
  162. package/dist-unchecked/system/number-parsing.js +21 -4
  163. package/dist-unchecked/system/string-builder.d.ts +30 -0
  164. package/dist-unchecked/system/string-builder.js +86 -0
  165. package/dist-unchecked/system/task-completion-source.d.ts +37 -0
  166. package/dist-unchecked/system/task-completion-source.js +81 -0
  167. package/package.json +1 -1
  168. package/src/system/char-members.ts +131 -0
  169. package/src/system/collections/array-helpers.ts +139 -0
  170. package/src/system/collections/hash-core.ts +31 -0
  171. package/src/system/collections/helpers.ts +39 -4
  172. package/src/system/collections/immutable-list-builder-core.ts +16 -2
  173. package/src/system/collections/immutable-list-core.ts +23 -1
  174. package/src/system/collections/immutable-storage.ts +8 -1
  175. package/src/system/collections/index.ts +2 -0
  176. package/src/system/collections/interfaces.ts +16 -0
  177. package/src/system/collections/list.ts +10 -15
  178. package/src/system/collections/read-only-list.ts +35 -1
  179. package/src/system/collections/sorted-list.ts +15 -1
  180. package/src/system/collections/string-comparer.ts +57 -0
  181. package/src/system/decimal-parsing.ts +109 -0
  182. package/src/system/exceptions/index.ts +1 -0
  183. package/src/system/exceptions/throw-error.ts +9 -0
  184. package/src/system/index.ts +5 -0
  185. package/src/system/int64.ts +27 -10
  186. package/src/system/integer-division.ts +43 -6
  187. package/src/system/json/contract-name.ts +3 -2
  188. package/src/system/json/converters.ts +38 -526
  189. package/src/system/json/dictionary-keys.ts +6 -4
  190. package/src/system/json/index.ts +1 -1
  191. package/src/system/json/json-serializer.ts +42 -1
  192. package/src/system/json/json-text-writer.ts +224 -0
  193. package/src/system/json/null-reads.ts +3 -1
  194. package/src/system/json/number-from-string.ts +31 -6
  195. package/src/system/json/numeric-converters.ts +60 -8
  196. package/src/system/json/numeric-enum-members.ts +4 -6
  197. package/src/system/json/spec-plans.ts +524 -0
  198. package/src/system/json/types.ts +15 -9
  199. package/src/system/lazy.ts +62 -0
  200. package/src/system/linq/grouping.ts +77 -0
  201. package/src/system/linq/index.ts +14 -0
  202. package/src/system/linq/linq.ts +23 -1
  203. package/src/system/linq/lookup.ts +34 -0
  204. package/src/system/linq/operators.ts +109 -17
  205. package/src/system/linq/terminals.ts +161 -2
  206. package/src/system/linq/types.ts +66 -3
  207. package/src/system/math.ts +19 -0
  208. package/src/system/number-members.ts +29 -0
  209. package/src/system/number-parsing.ts +24 -4
  210. package/src/system/string-builder.ts +117 -0
  211. 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
+ }
@@ -0,0 +1,51 @@
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
+ /** `char.IsLetter(c)`. */
8
+ export declare function charIsLetter(c: string): boolean;
9
+ /** `char.IsDigit(c)`: a decimal digit of any script. */
10
+ export declare function charIsDigit(c: string): boolean;
11
+ /** `char.IsLetterOrDigit(c)`. */
12
+ export declare function charIsLetterOrDigit(c: string): boolean;
13
+ /** `char.IsNumber(c)`: a decimal digit, a letter number or another number. */
14
+ export declare function charIsNumber(c: string): boolean;
15
+ /** `char.IsUpper(c)`. */
16
+ export declare function charIsUpper(c: string): boolean;
17
+ /** `char.IsLower(c)`. */
18
+ export declare function charIsLower(c: string): boolean;
19
+ /** `char.IsPunctuation(c)`. */
20
+ export declare function charIsPunctuation(c: string): boolean;
21
+ /** `char.IsSymbol(c)`. */
22
+ export declare function charIsSymbol(c: string): boolean;
23
+ /** `char.IsSeparator(c)`. */
24
+ export declare function charIsSeparator(c: string): boolean;
25
+ /** `char.IsControl(c)`. */
26
+ export declare function charIsControl(c: string): boolean;
27
+ /** `char.IsWhiteSpace(c)`. */
28
+ export declare function charIsWhiteSpace(c: string): boolean;
29
+ /** `char.IsAscii(c)`: a code unit below U+0080. */
30
+ export declare function charIsAscii(c: string): boolean;
31
+ /** `char.IsAsciiDigit(c)`: `0`-`9`. */
32
+ export declare function charIsAsciiDigit(c: string): boolean;
33
+ /** `char.IsAsciiLetterLower(c)`: `a`-`z`. */
34
+ export declare function charIsAsciiLetterLower(c: string): boolean;
35
+ /** `char.IsAsciiLetterUpper(c)`: `A`-`Z`. */
36
+ export declare function charIsAsciiLetterUpper(c: string): boolean;
37
+ /** `char.IsAsciiLetter(c)`: `a`-`z` or `A`-`Z`. */
38
+ export declare function charIsAsciiLetter(c: string): boolean;
39
+ /** `char.IsAsciiLetterOrDigit(c)`. */
40
+ export declare function charIsAsciiLetterOrDigit(c: string): boolean;
41
+ /** `char.IsAsciiHexDigitLower(c)`: `0`-`9` or `a`-`f`. */
42
+ export declare function charIsAsciiHexDigitLower(c: string): boolean;
43
+ /** `char.IsAsciiHexDigitUpper(c)`: `0`-`9` or `A`-`F`. */
44
+ export declare function charIsAsciiHexDigitUpper(c: string): boolean;
45
+ /** `char.IsAsciiHexDigit(c)`: `0`-`9`, `a`-`f` or `A`-`F`. */
46
+ export declare function charIsAsciiHexDigit(c: string): boolean;
47
+ /**
48
+ * `char.IsBetween(c, min, max)`: .NET computes `(uint)(c - min) <= (uint)(max - min)`
49
+ * by code unit, so the range wraps around when `min > max`.
50
+ */
51
+ export declare function charIsBetween(c: string, min: string, max: string): boolean;
@@ -0,0 +1,108 @@
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
+ const LETTER = /^\p{L}$/u;
8
+ const DIGIT = /^\p{Nd}$/u;
9
+ const LETTER_OR_DIGIT = /^[\p{L}\p{Nd}]$/u;
10
+ const NUMBER = /^\p{N}$/u;
11
+ const UPPER = /^\p{Lu}$/u;
12
+ const LOWER = /^\p{Ll}$/u;
13
+ const PUNCTUATION = /^\p{P}$/u;
14
+ const SYMBOL = /^\p{S}$/u;
15
+ const SEPARATOR = /^\p{Z}$/u;
16
+ const CONTROL = /^\p{Cc}$/u;
17
+ /** U+0009-U+000D and U+0085 are white space in .NET beyond the Unicode separators (`\s` also admits U+FEFF). */
18
+ const WHITE_SPACE = /^[\p{Z}\t-\r\u0085]$/u;
19
+ /** `char.IsLetter(c)`. */
20
+ export function charIsLetter(c) {
21
+ return LETTER.test(c);
22
+ }
23
+ /** `char.IsDigit(c)`: a decimal digit of any script. */
24
+ export function charIsDigit(c) {
25
+ return DIGIT.test(c);
26
+ }
27
+ /** `char.IsLetterOrDigit(c)`. */
28
+ export function charIsLetterOrDigit(c) {
29
+ return LETTER_OR_DIGIT.test(c);
30
+ }
31
+ /** `char.IsNumber(c)`: a decimal digit, a letter number or another number. */
32
+ export function charIsNumber(c) {
33
+ return NUMBER.test(c);
34
+ }
35
+ /** `char.IsUpper(c)`. */
36
+ export function charIsUpper(c) {
37
+ return UPPER.test(c);
38
+ }
39
+ /** `char.IsLower(c)`. */
40
+ export function charIsLower(c) {
41
+ return LOWER.test(c);
42
+ }
43
+ /** `char.IsPunctuation(c)`. */
44
+ export function charIsPunctuation(c) {
45
+ return PUNCTUATION.test(c);
46
+ }
47
+ /** `char.IsSymbol(c)`. */
48
+ export function charIsSymbol(c) {
49
+ return SYMBOL.test(c);
50
+ }
51
+ /** `char.IsSeparator(c)`. */
52
+ export function charIsSeparator(c) {
53
+ return SEPARATOR.test(c);
54
+ }
55
+ /** `char.IsControl(c)`. */
56
+ export function charIsControl(c) {
57
+ return CONTROL.test(c);
58
+ }
59
+ /** `char.IsWhiteSpace(c)`. */
60
+ export function charIsWhiteSpace(c) {
61
+ return WHITE_SPACE.test(c);
62
+ }
63
+ /** `char.IsAscii(c)`: a code unit below U+0080. */
64
+ export function charIsAscii(c) {
65
+ return c.charCodeAt(0) < 0x80;
66
+ }
67
+ /** `char.IsAsciiDigit(c)`: `0`-`9`. */
68
+ export function charIsAsciiDigit(c) {
69
+ return c >= "0" && c <= "9";
70
+ }
71
+ /** `char.IsAsciiLetterLower(c)`: `a`-`z`. */
72
+ export function charIsAsciiLetterLower(c) {
73
+ return c >= "a" && c <= "z";
74
+ }
75
+ /** `char.IsAsciiLetterUpper(c)`: `A`-`Z`. */
76
+ export function charIsAsciiLetterUpper(c) {
77
+ return c >= "A" && c <= "Z";
78
+ }
79
+ /** `char.IsAsciiLetter(c)`: `a`-`z` or `A`-`Z`. */
80
+ export function charIsAsciiLetter(c) {
81
+ return charIsAsciiLetterLower(c) || charIsAsciiLetterUpper(c);
82
+ }
83
+ /** `char.IsAsciiLetterOrDigit(c)`. */
84
+ export function charIsAsciiLetterOrDigit(c) {
85
+ return charIsAsciiLetter(c) || charIsAsciiDigit(c);
86
+ }
87
+ /** `char.IsAsciiHexDigitLower(c)`: `0`-`9` or `a`-`f`. */
88
+ export function charIsAsciiHexDigitLower(c) {
89
+ return charIsAsciiDigit(c) || (c >= "a" && c <= "f");
90
+ }
91
+ /** `char.IsAsciiHexDigitUpper(c)`: `0`-`9` or `A`-`F`. */
92
+ export function charIsAsciiHexDigitUpper(c) {
93
+ return charIsAsciiDigit(c) || (c >= "A" && c <= "F");
94
+ }
95
+ /** `char.IsAsciiHexDigit(c)`: `0`-`9`, `a`-`f` or `A`-`F`. */
96
+ export function charIsAsciiHexDigit(c) {
97
+ return charIsAsciiHexDigitLower(c) || charIsAsciiHexDigitUpper(c);
98
+ }
99
+ /**
100
+ * `char.IsBetween(c, min, max)`: .NET computes `(uint)(c - min) <= (uint)(max - min)`
101
+ * by code unit, so the range wraps around when `min > max`.
102
+ */
103
+ export function charIsBetween(c, min, max) {
104
+ const start = min.charCodeAt(0);
105
+ const offset = (c.charCodeAt(0) - start) >>> 0;
106
+ const width = (max.charCodeAt(0) - start) >>> 0;
107
+ return offset <= width;
108
+ }
@@ -0,0 +1,28 @@
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 } from "./default-comparer.ts";
8
+ /** Primitives other than `NaN` compare by `===`, which `Array#indexOf` uses. */
9
+ export declare function isIdentityComparable(value: unknown): boolean;
10
+ /**
11
+ * Sorts `items` in place (stable) with `comparison` or `Comparer<T>.Default`; a comparison
12
+ * that throws surfaces as `InvalidOperationException`, as `Array.Sort` reports it.
13
+ */
14
+ export declare function sortInPlace<T>(items: T[], comparison?: ComparisonArgument<T>): void;
15
+ /** `Array.Sort(array)`, `Array.Sort(array, comparison | comparer)`, `span.Sort(...)`. */
16
+ export declare function sortArray<T>(array: T[] | null | undefined, comparison?: ComparisonArgument<T>): void;
17
+ /** `Array.Sort(keys, items, comparer?)`: both arrays are permuted by the order of the keys. */
18
+ export declare function sortArrayByKeys<K, V>(keys: K[] | null | undefined, items: V[] | null | undefined, comparison?: ComparisonArgument<K>): void;
19
+ /**
20
+ * `Array.IndexOf(array, value, start?)` and the span search: `EqualityComparer<T>.Default`
21
+ * semantics (a record, a decimal or a date compares by value, `NaN` finds `NaN`). A string
22
+ * receiver, which a `ReadOnlySpan<char>` over text is, searches its characters.
23
+ */
24
+ export declare function arrayIndexOf<T>(array: readonly T[] | string, value: T, start?: number): number;
25
+ /** `Array.LastIndexOf(array, value)` and the span search; see {@link arrayIndexOf}. */
26
+ export declare function arrayLastIndexOf<T>(array: readonly T[] | string, value: T): number;
27
+ /** `span.Contains(value)` and `array.Contains(value)`; see {@link arrayIndexOf}. */
28
+ export declare function arrayContains<T>(array: readonly T[] | string, value: T): boolean;
@@ -0,0 +1,105 @@
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 { comparisonOf, elementEquals } from "./default-comparer.js";
8
+ import { throwArgumentNull, throwArrayTooSmall, throwCompareFailed, throwIndexAtMostCount, } from "./throw-helpers.js";
9
+ /** Primitives other than `NaN` compare by `===`, which `Array#indexOf` uses. */
10
+ export function isIdentityComparable(value) {
11
+ return typeof value !== "object" && !Number.isNaN(value);
12
+ }
13
+ /**
14
+ * Sorts `items` in place (stable) with `comparison` or `Comparer<T>.Default`; a comparison
15
+ * that throws surfaces as `InvalidOperationException`, as `Array.Sort` reports it.
16
+ */
17
+ export function sortInPlace(items, comparison) {
18
+ const compare = comparisonOf(comparison);
19
+ try {
20
+ items.sort(compare);
21
+ }
22
+ catch (error) {
23
+ throwCompareFailed(error);
24
+ }
25
+ }
26
+ /** `Array.Sort(array)`, `Array.Sort(array, comparison | comparer)`, `span.Sort(...)`. */
27
+ export function sortArray(array, comparison) {
28
+ if (array === null || array === undefined) {
29
+ throwArgumentNull("array");
30
+ }
31
+ if (array.length > 1) {
32
+ sortInPlace(array, comparison);
33
+ }
34
+ }
35
+ /** `Array.Sort(keys, items, comparer?)`: both arrays are permuted by the order of the keys. */
36
+ export function sortArrayByKeys(keys, items, comparison) {
37
+ if (keys === null || keys === undefined) {
38
+ throwArgumentNull("keys");
39
+ }
40
+ if (items === null || items === undefined) {
41
+ sortArray(keys, comparison);
42
+ return;
43
+ }
44
+ if (items.length < keys.length) {
45
+ throwArrayTooSmall();
46
+ }
47
+ const compare = comparisonOf(comparison);
48
+ const order = keys.map((_, index) => index);
49
+ try {
50
+ order.sort((a, b) => compare(keys[a], keys[b]));
51
+ }
52
+ catch (error) {
53
+ throwCompareFailed(error);
54
+ }
55
+ const sortedKeys = order.map((index) => keys[index]);
56
+ const sortedItems = order.map((index) => items[index]);
57
+ sortedKeys.forEach((key, index) => {
58
+ keys[index] = key;
59
+ items[index] = sortedItems[index];
60
+ });
61
+ }
62
+ /**
63
+ * `Array.IndexOf(array, value, start?)` and the span search: `EqualityComparer<T>.Default`
64
+ * semantics (a record, a decimal or a date compares by value, `NaN` finds `NaN`). A string
65
+ * receiver, which a `ReadOnlySpan<char>` over text is, searches its characters.
66
+ */
67
+ export function arrayIndexOf(array, value, start) {
68
+ const from = start ?? 0;
69
+ if (typeof array === "string") {
70
+ return array.indexOf(value, from);
71
+ }
72
+ if (from >>> 0 > array.length) {
73
+ throwIndexAtMostCount();
74
+ }
75
+ if (isIdentityComparable(value)) {
76
+ return array.indexOf(value, from);
77
+ }
78
+ for (let position = from; position < array.length; position++) {
79
+ if (elementEquals(array[position], value)) {
80
+ return position;
81
+ }
82
+ }
83
+ return -1;
84
+ }
85
+ /** `Array.LastIndexOf(array, value)` and the span search; see {@link arrayIndexOf}. */
86
+ export function arrayLastIndexOf(array, value) {
87
+ if (typeof array === "string") {
88
+ return array.lastIndexOf(value);
89
+ }
90
+ if (isIdentityComparable(value)) {
91
+ return array.lastIndexOf(value);
92
+ }
93
+ for (let position = array.length - 1; position >= 0; position--) {
94
+ if (elementEquals(array[position], value)) {
95
+ return position;
96
+ }
97
+ }
98
+ return -1;
99
+ }
100
+ /** `span.Contains(value)` and `array.Contains(value)`; see {@link arrayIndexOf}. */
101
+ export function arrayContains(array, value) {
102
+ return typeof array === "string"
103
+ ? array.includes(value)
104
+ : arrayIndexOf(array, value) >= 0;
105
+ }
@@ -30,6 +30,11 @@ export declare class HashCore<K, V> {
30
30
  findKey(key: K): K | undefined;
31
31
  /** Stores `value` under `key`: `true` when inserted; an overwrite keeps the entry's position. */
32
32
  set(key: K, value: V): boolean;
33
+ /**
34
+ * Appends `element` to the array stored under `key`, storing a new array when there is none:
35
+ * a `get` and a `set` in one lookup, for the groupings of `groupBy`, `toLookup` and `join`.
36
+ */
37
+ append<E>(this: HashCore<K, E[]>, key: K, element: E): void;
33
38
  delete(key: K): boolean;
34
39
  clear(): void;
35
40
  /** An O(n) copy: same comparer, same enumeration order. */
@@ -71,6 +71,30 @@ export class HashCore {
71
71
  this._bucketOf(this._hash(key)).push(key);
72
72
  return true;
73
73
  }
74
+ /**
75
+ * Appends `element` to the array stored under `key`, storing a new array when there is none:
76
+ * a `get` and a `set` in one lookup, for the groupings of `groupBy`, `toLookup` and `join`.
77
+ */
78
+ append(key, element) {
79
+ const entries = this._entries;
80
+ if (this._direct(key)) {
81
+ const bucket = entries.get(key);
82
+ if (bucket === undefined) {
83
+ entries.set(key, [element]);
84
+ }
85
+ else {
86
+ bucket.push(element);
87
+ }
88
+ return;
89
+ }
90
+ const stored = this._find(key);
91
+ if (!isMissing(stored)) {
92
+ entries.get(stored).push(element);
93
+ return;
94
+ }
95
+ entries.set(key, [element]);
96
+ this._bucketOf(this._hash(key)).push(key);
97
+ }
74
98
  delete(key) {
75
99
  if (this._direct(key)) {
76
100
  return this._entries.delete(key);
@@ -1,4 +1,4 @@
1
- import type { IList, Span } from "./interfaces.ts";
1
+ import type { IList, IReadOnlyList, Span } from "./interfaces.ts";
2
2
  import { List } from "./list.ts";
3
3
  /** `arr[^n]` on a native array (`T[]`, `JsArray<T>`): always checked. */
4
4
  export declare function fromEnd<T>(array: readonly T[], n: number): T;
@@ -10,8 +10,21 @@ export declare function isIterable(value: unknown): value is Iterable<unknown>;
10
10
  * `null` otherwise.
11
11
  */
12
12
  export declare function asArray(value: unknown): unknown[] | null;
13
- /** `list.AsJsArray()`: the backing array itself; `ArgumentNullException` for `null`. */
13
+ /**
14
+ * `list.AsJsArray()`: the backing array itself; `ArgumentNullException` for `null`.
15
+ * Contract (mirroring `CollectionsMarshal.AsSpan`): do not add or remove elements
16
+ * through the writable view while the `List` is being enumerated (it bypasses `_version`).
17
+ */
14
18
  export declare function asJsArray<T>(list: List<T> | null | undefined): T[];
19
+ /**
20
+ * `list.AsReadOnlyJsArray()`: a read-only view `readonly T[]` over the list's
21
+ * backing array; `ArgumentNullException` for `null`. Zero-copy and live for
22
+ * runtime array-backed list kinds (and native arrays); a shallow snapshot copy
23
+ * (`Array.from(list)`) when `ReadOnlyList` wraps a custom `IList`, when the
24
+ * receiver lacks `asReadOnlyJsArray()` (such as a user `IReadOnlyList` class),
25
+ * and for older immutable versions sharing a grown store.
26
+ */
27
+ export declare function asReadOnlyJsArray<T>(list: IReadOnlyList<T> | readonly T[] | null | undefined): readonly T[];
15
28
  /** `list.AsSpan()` / `CollectionsMarshal.AsSpan(list)`: the backing array; empty for `null`. */
16
29
  export declare function asSpan<T>(list: List<T> | null | undefined): Span<T>;
17
30
  /** `list.AsReadOnlySpan()`: the backing array, read-only; empty for `null`. */
@@ -26,4 +39,4 @@ export declare function asReadOnlySpan<T>(list: List<T> | null | undefined): Rea
26
39
  * collection descriptor), so an object that is not a list fails at its first use instead
27
40
  * of at the cast.
28
41
  */
29
- export declare function asList<T>(value: unknown, targetType: string): IList<T> | null;
42
+ export declare function asList<T>(value: unknown, targetType: string): (IList<T> & IReadOnlyList<T>) | null;
@@ -33,13 +33,37 @@ export function asArray(value) {
33
33
  }
34
34
  return value instanceof List && value.isFixedSize ? value._items : null;
35
35
  }
36
- /** `list.AsJsArray()`: the backing array itself; `ArgumentNullException` for `null`. */
36
+ /**
37
+ * `list.AsJsArray()`: the backing array itself; `ArgumentNullException` for `null`.
38
+ * Contract (mirroring `CollectionsMarshal.AsSpan`): do not add or remove elements
39
+ * through the writable view while the `List` is being enumerated (it bypasses `_version`).
40
+ */
37
41
  export function asJsArray(list) {
38
42
  if (list === null || list === undefined) {
39
43
  throwArgumentNull("list");
40
44
  }
41
45
  return list._items;
42
46
  }
47
+ /**
48
+ * `list.AsReadOnlyJsArray()`: a read-only view `readonly T[]` over the list's
49
+ * backing array; `ArgumentNullException` for `null`. Zero-copy and live for
50
+ * runtime array-backed list kinds (and native arrays); a shallow snapshot copy
51
+ * (`Array.from(list)`) when `ReadOnlyList` wraps a custom `IList`, when the
52
+ * receiver lacks `asReadOnlyJsArray()` (such as a user `IReadOnlyList` class),
53
+ * and for older immutable versions sharing a grown store.
54
+ */
55
+ export function asReadOnlyJsArray(list) {
56
+ if (list === null || list === undefined) {
57
+ throwArgumentNull("list");
58
+ }
59
+ if (Array.isArray(list)) {
60
+ return list;
61
+ }
62
+ if (typeof list.asReadOnlyJsArray === "function") {
63
+ return list.asReadOnlyJsArray();
64
+ }
65
+ return Array.from(list);
66
+ }
43
67
  /** `list.AsSpan()` / `CollectionsMarshal.AsSpan(list)`: the backing array; empty for `null`. */
44
68
  export function asSpan(list) {
45
69
  return list === null || list === undefined ? [] : list._items;
@@ -65,7 +89,9 @@ export function asList(value, targetType) {
65
89
  if (isPrimitive(value)) {
66
90
  throw invalidCast(value, targetType);
67
91
  }
68
- return Array.isArray(value) ? List.adopt(value, { fixedSize: true }) : value;
92
+ return Array.isArray(value)
93
+ ? List.adopt(value, { fixedSize: true })
94
+ : value;
69
95
  }
70
96
  function isPrimitive(value) {
71
97
  const type = typeof value;