@fable-org/fable-library-ts 1.0.0-beta-001

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 (57) hide show
  1. package/Array.ts +1362 -0
  2. package/Async.ts +207 -0
  3. package/AsyncBuilder.ts +222 -0
  4. package/BigInt.ts +337 -0
  5. package/BitConverter.ts +165 -0
  6. package/Boolean.ts +22 -0
  7. package/CHANGELOG.md +15 -0
  8. package/Char.ts +222 -0
  9. package/Choice.ts +300 -0
  10. package/Date.ts +495 -0
  11. package/DateOffset.ts +324 -0
  12. package/DateOnly.ts +146 -0
  13. package/Decimal.ts +250 -0
  14. package/Double.ts +55 -0
  15. package/Encoding.ts +170 -0
  16. package/Event.ts +119 -0
  17. package/FSharp.Collections.ts +34 -0
  18. package/FSharp.Core.CompilerServices.ts +37 -0
  19. package/FSharp.Core.ts +86 -0
  20. package/Global.ts +37 -0
  21. package/Guid.ts +143 -0
  22. package/Int32.ts +156 -0
  23. package/List.ts +1417 -0
  24. package/Long.ts +49 -0
  25. package/MailboxProcessor.ts +125 -0
  26. package/Map.ts +1552 -0
  27. package/MapUtil.ts +120 -0
  28. package/MutableMap.ts +344 -0
  29. package/MutableSet.ts +248 -0
  30. package/Native.ts +11 -0
  31. package/Numeric.ts +80 -0
  32. package/Observable.ts +156 -0
  33. package/Option.ts +137 -0
  34. package/README.md +3 -0
  35. package/Random.ts +196 -0
  36. package/Range.ts +56 -0
  37. package/Reflection.ts +539 -0
  38. package/RegExp.ts +143 -0
  39. package/Result.ts +196 -0
  40. package/Seq.ts +1526 -0
  41. package/Seq2.ts +129 -0
  42. package/Set.ts +1955 -0
  43. package/String.ts +589 -0
  44. package/System.Collections.Generic.ts +380 -0
  45. package/System.Text.ts +137 -0
  46. package/SystemException.ts +7 -0
  47. package/TimeOnly.ts +131 -0
  48. package/TimeSpan.ts +194 -0
  49. package/Timer.ts +80 -0
  50. package/Types.ts +231 -0
  51. package/Unicode.13.0.0.ts +4 -0
  52. package/Uri.ts +206 -0
  53. package/Util.ts +928 -0
  54. package/lib/big.d.ts +338 -0
  55. package/lib/big.js +1054 -0
  56. package/package.json +24 -0
  57. package/tsconfig.json +103 -0
@@ -0,0 +1,380 @@
1
+ import { int32 } from "./Int32.js";
2
+ import { IDisposable, disposeSafe, defaultOf, toIterator, IEnumerator, getEnumerator, structuralHash, equals as equals_1, IEqualityComparer, compare, IComparer } from "./Util.js";
3
+ import { class_type, TypeInfo } from "./Reflection.js";
4
+ import { toArray, empty, singleton, append, enumerateWhile, delay } from "./Seq.js";
5
+ import { initialize, copyTo, fill } from "./Array.js";
6
+ import { max } from "./Double.js";
7
+ import { FSharpRef } from "./Types.js";
8
+
9
+ export class Comparer$1<T> implements IComparer<T> {
10
+ readonly comparison: ((arg0: T, arg1: T) => int32);
11
+ constructor(comparison: ((arg0: T, arg1: T) => int32)) {
12
+ this.comparison = comparison;
13
+ }
14
+ Compare(x: T, y: T): int32 {
15
+ const _: Comparer$1<T> = this;
16
+ return _.comparison(x, y) | 0;
17
+ }
18
+ }
19
+
20
+ export function Comparer$1_$reflection(gen0: TypeInfo): TypeInfo {
21
+ return class_type("System.Collections.Generic.Comparer`1", [gen0], Comparer$1);
22
+ }
23
+
24
+ export function Comparer$1_$ctor_47C913C<T>(comparison: ((arg0: T, arg1: T) => int32)): Comparer$1<T> {
25
+ return new Comparer$1(comparison);
26
+ }
27
+
28
+ export function Comparer$1_get_Default<T>(): Comparer$1<T> {
29
+ return Comparer$1_$ctor_47C913C<T>(compare);
30
+ }
31
+
32
+ export function Comparer$1_Create_47C913C<T>(comparison: ((arg0: T, arg1: T) => int32)): Comparer$1<T> {
33
+ return Comparer$1_$ctor_47C913C<T>(comparison);
34
+ }
35
+
36
+ export function Comparer$1__Compare_5BDDA0<T>(_: Comparer$1<T>, x: T, y: T): int32 {
37
+ return _.comparison(x, y);
38
+ }
39
+
40
+ export class EqualityComparer$1<T> implements IEqualityComparer<T> {
41
+ readonly getHashCode: ((arg0: T) => int32);
42
+ readonly equals: ((arg0: T, arg1: T) => boolean);
43
+ constructor(equals: ((arg0: T, arg1: T) => boolean), getHashCode: ((arg0: T) => int32)) {
44
+ this.equals = equals;
45
+ this.getHashCode = getHashCode;
46
+ }
47
+ Equals(x: T, y: T): boolean {
48
+ const _: EqualityComparer$1<T> = this;
49
+ return _.equals(x, y);
50
+ }
51
+ GetHashCode(x: T): int32 {
52
+ const _: EqualityComparer$1<T> = this;
53
+ return _.getHashCode(x) | 0;
54
+ }
55
+ }
56
+
57
+ export function EqualityComparer$1_$reflection(gen0: TypeInfo): TypeInfo {
58
+ return class_type("System.Collections.Generic.EqualityComparer`1", [gen0], EqualityComparer$1);
59
+ }
60
+
61
+ export function EqualityComparer$1_$ctor_Z6EE254AB<T>(equals: ((arg0: T, arg1: T) => boolean), getHashCode: ((arg0: T) => int32)): EqualityComparer$1<T> {
62
+ return new EqualityComparer$1(equals, getHashCode);
63
+ }
64
+
65
+ export function EqualityComparer$1_get_Default<T>(): EqualityComparer$1<T> {
66
+ return EqualityComparer$1_$ctor_Z6EE254AB<T>(equals_1, structuralHash);
67
+ }
68
+
69
+ export function EqualityComparer$1_Create_Z6EE254AB<T>(equals: ((arg0: T, arg1: T) => boolean), getHashCode: ((arg0: T) => int32)): EqualityComparer$1<T> {
70
+ return EqualityComparer$1_$ctor_Z6EE254AB<T>(equals, getHashCode);
71
+ }
72
+
73
+ export function EqualityComparer$1__Equals_5BDDA0<T>(_: EqualityComparer$1<T>, x: T, y: T): boolean {
74
+ return _.equals(x, y);
75
+ }
76
+
77
+ export function EqualityComparer$1__GetHashCode_2B595<T>(_: EqualityComparer$1<T>, x: T): int32 {
78
+ return _.getHashCode(x);
79
+ }
80
+
81
+ export class Stack$1<T> implements Iterable<T> {
82
+ contents: T[];
83
+ count: int32;
84
+ constructor(initialContents: T[], initialCount: int32) {
85
+ this.contents = initialContents;
86
+ this.count = (initialCount | 0);
87
+ }
88
+ GetEnumerator(): IEnumerator<T> {
89
+ const _: Stack$1<T> = this;
90
+ return getEnumerator(delay<T>((): Iterable<T> => {
91
+ let index: int32 = _.count - 1;
92
+ return enumerateWhile<T>((): boolean => (index >= 0), delay<T>((): Iterable<T> => append<T>(singleton<T>(_.contents[index]), delay<T>((): Iterable<T> => {
93
+ index = ((index - 1) | 0);
94
+ return empty<T>();
95
+ }))));
96
+ }));
97
+ }
98
+ [Symbol.iterator](): Iterator<T> {
99
+ return toIterator(getEnumerator(this));
100
+ }
101
+ "System.Collections.IEnumerable.GetEnumerator"(): IEnumerator<any> {
102
+ const this$: Stack$1<T> = this;
103
+ return getEnumerator(this$);
104
+ }
105
+ }
106
+
107
+ export function Stack$1_$reflection(gen0: TypeInfo): TypeInfo {
108
+ return class_type("System.Collections.Generic.Stack`1", [gen0], Stack$1);
109
+ }
110
+
111
+ function Stack$1_$ctor_Z3B4C077E<T>(initialContents: T[], initialCount: int32): Stack$1<T> {
112
+ return new Stack$1(initialContents, initialCount);
113
+ }
114
+
115
+ export function Stack$1_$ctor_Z524259A4<T>(initialCapacity: int32): Stack$1<T> {
116
+ return Stack$1_$ctor_Z3B4C077E<T>(fill(new Array(initialCapacity), 0, initialCapacity, null), 0);
117
+ }
118
+
119
+ export function Stack$1_$ctor<T>(): Stack$1<T> {
120
+ return Stack$1_$ctor_Z524259A4<T>(4);
121
+ }
122
+
123
+ export function Stack$1_$ctor_BB573A<T>(xs: Iterable<T>): Stack$1<T> {
124
+ const arr: T[] = Array.from(xs);
125
+ return Stack$1_$ctor_Z3B4C077E<T>(arr, arr.length);
126
+ }
127
+
128
+ export function Stack$1__Ensure_Z524259A4<T>(_: Stack$1<T>, newSize: int32): void {
129
+ const oldSize: int32 = _.contents.length | 0;
130
+ if (newSize > oldSize) {
131
+ const old: T[] = _.contents;
132
+ _.contents = fill(new Array(max(newSize, oldSize * 2)), 0, max(newSize, oldSize * 2), null);
133
+ copyTo<T>(old, 0, _.contents, 0, _.count);
134
+ }
135
+ }
136
+
137
+ export function Stack$1__get_Count<T>(_: Stack$1<T>): int32 {
138
+ return _.count;
139
+ }
140
+
141
+ export function Stack$1__Pop<T>(_: Stack$1<T>): T {
142
+ _.count = ((_.count - 1) | 0);
143
+ return _.contents[_.count];
144
+ }
145
+
146
+ export function Stack$1__Peek<T>(_: Stack$1<T>): T {
147
+ return _.contents[_.count - 1];
148
+ }
149
+
150
+ export function Stack$1__Contains_2B595<T>(_: Stack$1<T>, x: T): boolean {
151
+ let found = false;
152
+ let i = 0;
153
+ while ((i < _.count) && !found) {
154
+ if (equals_1(x, _.contents[i])) {
155
+ found = true;
156
+ }
157
+ else {
158
+ i = ((i + 1) | 0);
159
+ }
160
+ }
161
+ return found;
162
+ }
163
+
164
+ export function Stack$1__TryPeek_1F3DB691<T>(this$: Stack$1<T>, result: FSharpRef<T>): boolean {
165
+ if (this$.count > 0) {
166
+ result.contents = Stack$1__Peek<T>(this$);
167
+ return true;
168
+ }
169
+ else {
170
+ return false;
171
+ }
172
+ }
173
+
174
+ export function Stack$1__TryPop_1F3DB691<T>(this$: Stack$1<T>, result: FSharpRef<T>): boolean {
175
+ if (this$.count > 0) {
176
+ result.contents = Stack$1__Pop<T>(this$);
177
+ return true;
178
+ }
179
+ else {
180
+ return false;
181
+ }
182
+ }
183
+
184
+ export function Stack$1__Push_2B595<T>(this$: Stack$1<T>, x: T): void {
185
+ Stack$1__Ensure_Z524259A4<T>(this$, this$.count + 1);
186
+ this$.contents[this$.count] = x;
187
+ this$.count = ((this$.count + 1) | 0);
188
+ }
189
+
190
+ export function Stack$1__Clear<T>(_: Stack$1<T>): void {
191
+ _.count = 0;
192
+ fill<T>(_.contents, 0, _.contents.length, defaultOf());
193
+ }
194
+
195
+ export function Stack$1__TrimExcess<T>(this$: Stack$1<T>): void {
196
+ if ((this$.count / this$.contents.length) > 0.9) {
197
+ Stack$1__Ensure_Z524259A4<T>(this$, this$.count);
198
+ }
199
+ }
200
+
201
+ export function Stack$1__ToArray<T>(_: Stack$1<T>): T[] {
202
+ return initialize<T>(_.count, (i: int32): T => _.contents[(_.count - 1) - i]);
203
+ }
204
+
205
+ export class Queue$1<T> implements Iterable<T> {
206
+ contents: T[];
207
+ count: int32;
208
+ head: int32;
209
+ tail: int32;
210
+ constructor(initialContents: T[], initialCount: int32) {
211
+ this.contents = initialContents;
212
+ this.count = (initialCount | 0);
213
+ this.head = 0;
214
+ this.tail = (((initialCount === this.contents.length) ? 0 : initialCount) | 0);
215
+ }
216
+ GetEnumerator(): IEnumerator<T> {
217
+ const _: Queue$1<T> = this;
218
+ return getEnumerator(Queue$1__toSeq<T>(_));
219
+ }
220
+ [Symbol.iterator](): Iterator<T> {
221
+ return toIterator(getEnumerator(this));
222
+ }
223
+ "System.Collections.IEnumerable.GetEnumerator"(): IEnumerator<any> {
224
+ const this$: Queue$1<T> = this;
225
+ return getEnumerator(this$);
226
+ }
227
+ }
228
+
229
+ export function Queue$1_$reflection(gen0: TypeInfo): TypeInfo {
230
+ return class_type("System.Collections.Generic.Queue`1", [gen0], Queue$1);
231
+ }
232
+
233
+ function Queue$1_$ctor_Z3B4C077E<T>(initialContents: T[], initialCount: int32): Queue$1<T> {
234
+ return new Queue$1(initialContents, initialCount);
235
+ }
236
+
237
+ export function Queue$1_$ctor_Z524259A4<T>(initialCapacity: int32): Queue$1<T> {
238
+ if (initialCapacity < 0) {
239
+ throw new Error("capacity is less than 0");
240
+ }
241
+ return Queue$1_$ctor_Z3B4C077E<T>(fill(new Array(initialCapacity), 0, initialCapacity, null), 0);
242
+ }
243
+
244
+ export function Queue$1_$ctor<T>(): Queue$1<T> {
245
+ return Queue$1_$ctor_Z524259A4<T>(4);
246
+ }
247
+
248
+ export function Queue$1_$ctor_BB573A<T>(xs: Iterable<T>): Queue$1<T> {
249
+ const arr: T[] = Array.from(xs);
250
+ return Queue$1_$ctor_Z3B4C077E<T>(arr, arr.length);
251
+ }
252
+
253
+ export function Queue$1__get_Count<T>(_: Queue$1<T>): int32 {
254
+ return _.count;
255
+ }
256
+
257
+ export function Queue$1__Enqueue_2B595<T>(_: Queue$1<T>, value: T): void {
258
+ if (_.count === Queue$1__size<T>(_)) {
259
+ Queue$1__ensure_Z524259A4<T>(_, _.count + 1);
260
+ }
261
+ _.contents[_.tail] = value;
262
+ _.tail = (((_.tail + 1) % Queue$1__size<T>(_)) | 0);
263
+ _.count = ((_.count + 1) | 0);
264
+ }
265
+
266
+ export function Queue$1__Dequeue<T>(_: Queue$1<T>): T {
267
+ if (_.count === 0) {
268
+ throw new Error("Queue is empty");
269
+ }
270
+ const value: T = _.contents[_.head];
271
+ _.head = (((_.head + 1) % Queue$1__size<T>(_)) | 0);
272
+ _.count = ((_.count - 1) | 0);
273
+ return value;
274
+ }
275
+
276
+ export function Queue$1__Peek<T>(_: Queue$1<T>): T {
277
+ if (_.count === 0) {
278
+ throw new Error("Queue is empty");
279
+ }
280
+ return _.contents[_.head];
281
+ }
282
+
283
+ export function Queue$1__TryDequeue_1F3DB691<T>(this$: Queue$1<T>, result: FSharpRef<T>): boolean {
284
+ if (this$.count === 0) {
285
+ return false;
286
+ }
287
+ else {
288
+ result.contents = Queue$1__Dequeue<T>(this$);
289
+ return true;
290
+ }
291
+ }
292
+
293
+ export function Queue$1__TryPeek_1F3DB691<T>(this$: Queue$1<T>, result: FSharpRef<T>): boolean {
294
+ if (this$.count === 0) {
295
+ return false;
296
+ }
297
+ else {
298
+ result.contents = Queue$1__Peek<T>(this$);
299
+ return true;
300
+ }
301
+ }
302
+
303
+ export function Queue$1__Contains_2B595<T>(_: Queue$1<T>, x: T): boolean {
304
+ let found = false;
305
+ let i = 0;
306
+ while ((i < _.count) && !found) {
307
+ if (equals_1(x, _.contents[Queue$1__toIndex_Z524259A4<T>(_, i)])) {
308
+ found = true;
309
+ }
310
+ else {
311
+ i = ((i + 1) | 0);
312
+ }
313
+ }
314
+ return found;
315
+ }
316
+
317
+ export function Queue$1__Clear<T>(_: Queue$1<T>): void {
318
+ _.count = 0;
319
+ _.head = 0;
320
+ _.tail = 0;
321
+ fill<T>(_.contents, 0, Queue$1__size<T>(_), defaultOf());
322
+ }
323
+
324
+ export function Queue$1__TrimExcess<T>(_: Queue$1<T>): void {
325
+ if ((_.count / _.contents.length) > 0.9) {
326
+ Queue$1__ensure_Z524259A4<T>(_, _.count);
327
+ }
328
+ }
329
+
330
+ export function Queue$1__ToArray<T>(_: Queue$1<T>): T[] {
331
+ return toArray<T>(Queue$1__toSeq<T>(_));
332
+ }
333
+
334
+ export function Queue$1__CopyTo_Z3B4C077E<T>(_: Queue$1<T>, target: T[], start: int32): void {
335
+ let i: int32 = start;
336
+ const enumerator: IEnumerator<T> = getEnumerator(Queue$1__toSeq<T>(_));
337
+ try {
338
+ while (enumerator["System.Collections.IEnumerator.MoveNext"]()) {
339
+ const item: T = enumerator["System.Collections.Generic.IEnumerator`1.get_Current"]();
340
+ target[i] = item;
341
+ i = ((i + 1) | 0);
342
+ }
343
+ }
344
+ finally {
345
+ disposeSafe(enumerator as IDisposable);
346
+ }
347
+ }
348
+
349
+ export function Queue$1__size<T>(this$: Queue$1<T>): int32 {
350
+ return this$.contents.length;
351
+ }
352
+
353
+ export function Queue$1__toIndex_Z524259A4<T>(this$: Queue$1<T>, i: int32): int32 {
354
+ return (this$.head + i) % Queue$1__size<T>(this$);
355
+ }
356
+
357
+ export function Queue$1__ensure_Z524259A4<T>(this$: Queue$1<T>, requiredSize: int32): void {
358
+ const newBuffer: T[] = fill(new Array(requiredSize), 0, requiredSize, null);
359
+ if (this$.head < this$.tail) {
360
+ copyTo<T>(this$.contents, this$.head, newBuffer, 0, this$.count);
361
+ }
362
+ else {
363
+ copyTo<T>(this$.contents, this$.head, newBuffer, 0, Queue$1__size<T>(this$) - this$.head);
364
+ copyTo<T>(this$.contents, 0, newBuffer, Queue$1__size<T>(this$) - this$.head, this$.tail);
365
+ }
366
+ this$.head = 0;
367
+ this$.contents = newBuffer;
368
+ this$.tail = (((this$.count === Queue$1__size<T>(this$)) ? 0 : this$.count) | 0);
369
+ }
370
+
371
+ export function Queue$1__toSeq<T>(this$: Queue$1<T>): Iterable<T> {
372
+ return delay<T>((): Iterable<T> => {
373
+ let i = 0;
374
+ return enumerateWhile<T>((): boolean => (i < this$.count), delay<T>((): Iterable<T> => append<T>(singleton<T>(this$.contents[Queue$1__toIndex_Z524259A4<T>(this$, i)]), delay<T>((): Iterable<T> => {
375
+ i = ((i + 1) | 0);
376
+ return empty<T>();
377
+ }))));
378
+ });
379
+ }
380
+
package/System.Text.ts ADDED
@@ -0,0 +1,137 @@
1
+ import { replace, format, substring, isNullOrEmpty, join } from "./String.js";
2
+ import { float64, int32 } from "./Int32.js";
3
+ import { class_type, TypeInfo } from "./Reflection.js";
4
+ import { clear, int32ToString } from "./Util.js";
5
+ import { toString } from "./Types.js";
6
+
7
+ export class StringBuilder {
8
+ readonly buf: string[];
9
+ constructor(value: string, capacity: int32) {
10
+ this.buf = [];
11
+ if (!isNullOrEmpty(value)) {
12
+ void (this.buf.push(value));
13
+ }
14
+ }
15
+ toString(): string {
16
+ const _: StringBuilder = this;
17
+ return join("", _.buf);
18
+ }
19
+ }
20
+
21
+ export function StringBuilder_$reflection(): TypeInfo {
22
+ return class_type("System.Text.StringBuilder", void 0, StringBuilder);
23
+ }
24
+
25
+ export function StringBuilder_$ctor_Z18115A39(value: string, capacity: int32): StringBuilder {
26
+ return new StringBuilder(value, capacity);
27
+ }
28
+
29
+ export function StringBuilder_$ctor_Z524259A4(capacity: int32): StringBuilder {
30
+ return StringBuilder_$ctor_Z18115A39("", capacity);
31
+ }
32
+
33
+ export function StringBuilder_$ctor_Z721C83C5(value: string): StringBuilder {
34
+ return StringBuilder_$ctor_Z18115A39(value, 16);
35
+ }
36
+
37
+ export function StringBuilder_$ctor(): StringBuilder {
38
+ return StringBuilder_$ctor_Z18115A39("", 16);
39
+ }
40
+
41
+ export function StringBuilder__Append_Z721C83C5(x: StringBuilder, s: string): StringBuilder {
42
+ void (x.buf.push(s));
43
+ return x;
44
+ }
45
+
46
+ export function StringBuilder__Append_487EF8FB(x: StringBuilder, s: string, startIndex: int32, count: int32): StringBuilder {
47
+ void (x.buf.push(substring(s, startIndex, count)));
48
+ return x;
49
+ }
50
+
51
+ export function StringBuilder__Append_244C7CD6(x: StringBuilder, c: string): StringBuilder {
52
+ void (x.buf.push(c));
53
+ return x;
54
+ }
55
+
56
+ export function StringBuilder__Append_Z524259A4(x: StringBuilder, o: int32): StringBuilder {
57
+ void (x.buf.push(int32ToString(o)));
58
+ return x;
59
+ }
60
+
61
+ export function StringBuilder__Append_5E38073B(x: StringBuilder, o: float64): StringBuilder {
62
+ void (x.buf.push(o.toString()));
63
+ return x;
64
+ }
65
+
66
+ export function StringBuilder__Append_Z1FBCCD16(x: StringBuilder, o: boolean): StringBuilder {
67
+ void (x.buf.push(toString(o)));
68
+ return x;
69
+ }
70
+
71
+ export function StringBuilder__Append_4E60E31B(x: StringBuilder, o: any): StringBuilder {
72
+ void (x.buf.push(toString(o)));
73
+ return x;
74
+ }
75
+
76
+ export function StringBuilder__Append_Z372E4D23(x: StringBuilder, cs: string[]): StringBuilder {
77
+ void (x.buf.push(cs.join('')));
78
+ return x;
79
+ }
80
+
81
+ export function StringBuilder__Append_43A65C09(x: StringBuilder, s: StringBuilder): StringBuilder {
82
+ void (x.buf.push(toString(s)));
83
+ return x;
84
+ }
85
+
86
+ export function StringBuilder__AppendFormat_433E080(x: StringBuilder, fmt: string, o: any): StringBuilder {
87
+ void (x.buf.push(format(fmt, o)));
88
+ return x;
89
+ }
90
+
91
+ export function StringBuilder__AppendFormat_Z696D8D1B(x: StringBuilder, provider: any, fmt: string, o: any): StringBuilder {
92
+ void (x.buf.push(format(provider, fmt, o)));
93
+ return x;
94
+ }
95
+
96
+ export function StringBuilder__AppendLine(x: StringBuilder): StringBuilder {
97
+ void (x.buf.push("\n"));
98
+ return x;
99
+ }
100
+
101
+ export function StringBuilder__AppendLine_Z721C83C5(x: StringBuilder, s: string): StringBuilder {
102
+ void (x.buf.push(s));
103
+ void (x.buf.push("\n"));
104
+ return x;
105
+ }
106
+
107
+ export function StringBuilder__Replace_Z766F94C0(x: StringBuilder, oldValue: string, newValue: string): StringBuilder {
108
+ for (let i: int32 = x.buf.length - 1; i >= 0; i--) {
109
+ x.buf[i] = replace(x.buf[i], oldValue, newValue);
110
+ }
111
+ return x;
112
+ }
113
+
114
+ export function StringBuilder__Replace_Z384F8060(x: StringBuilder, oldValue: string, newValue: string): StringBuilder {
115
+ for (let i: int32 = x.buf.length - 1; i >= 0; i--) {
116
+ x.buf[i] = replace(x.buf[i], oldValue, newValue);
117
+ }
118
+ return x;
119
+ }
120
+
121
+ export function StringBuilder__get_Length(x: StringBuilder): int32 {
122
+ let len = 0;
123
+ for (let i: int32 = x.buf.length - 1; i >= 0; i--) {
124
+ len = ((len + x.buf[i].length) | 0);
125
+ }
126
+ return len | 0;
127
+ }
128
+
129
+ export function StringBuilder__ToString_Z37302880(x: StringBuilder, firstIndex: int32, length: int32): string {
130
+ return substring(toString(x), firstIndex, length);
131
+ }
132
+
133
+ export function StringBuilder__Clear(x: StringBuilder): StringBuilder {
134
+ clear(x.buf);
135
+ return x;
136
+ }
137
+
@@ -0,0 +1,7 @@
1
+ import { Exception } from "./Types.js";
2
+
3
+ export class SystemException extends Exception {
4
+ }
5
+
6
+ export class TimeoutException extends SystemException {
7
+ }
package/TimeOnly.ts ADDED
@@ -0,0 +1,131 @@
1
+ import { FSharpRef } from "./Types.js";
2
+ import { hours, minutes, seconds, milliseconds } from "./TimeSpan.js";
3
+ import { DateKind, IDateTime, padWithZeros } from "./Util.js";
4
+
5
+ const millisecondsPerDay = 86400000;
6
+
7
+ export function create(h: number = 0, m: number = 0, s: number = 0, ms: number = 0) {
8
+ if (h < 0 || m < 0 || s < 0 || ms < 0)
9
+ throw new Error("The parameters describe an unrepresentable TimeOnly.");
10
+
11
+ return h * 3600000 + m * 60000 + s * 1000 + ms;
12
+ }
13
+
14
+ export function fromTicks(ticks: number | bigint) {
15
+ return Number(BigInt(ticks) / 10000n);
16
+ }
17
+
18
+ export function fromTimeSpan(timeSpan: number) {
19
+ if (timeSpan < 0 || timeSpan >= millisecondsPerDay)
20
+ throw new Error("The TimeSpan describes an unrepresentable TimeOnly.");
21
+
22
+ return timeSpan;
23
+ }
24
+
25
+ export function fromDateTime(d: IDateTime) {
26
+ return d.kind === DateKind.UTC
27
+ ? create(d.getUTCHours(), d.getUTCMinutes(), d.getUTCSeconds(), d.getUTCMilliseconds())
28
+ : create(d.getHours(), d.getMinutes(), d.getSeconds(), d.getMilliseconds());
29
+ }
30
+
31
+ export function maxValue() {
32
+ // This is "23:59:59.999"
33
+ return millisecondsPerDay - 1;
34
+ }
35
+
36
+ export function add(t: number, ts: number, wrappedDays?: FSharpRef<number>) {
37
+ if (wrappedDays === undefined) {
38
+ const t2 = (t + ts) % millisecondsPerDay;
39
+ return t2 < 0 ? millisecondsPerDay + t2 : t2;
40
+ }
41
+
42
+ wrappedDays.contents = ts / millisecondsPerDay;
43
+ let newMs = t + ts % millisecondsPerDay;
44
+
45
+ if (newMs < 0) {
46
+ wrappedDays.contents--;
47
+ newMs += millisecondsPerDay;
48
+ } else {
49
+ if (newMs >= millisecondsPerDay) {
50
+ wrappedDays.contents++;
51
+ newMs -= millisecondsPerDay;
52
+ }
53
+ }
54
+
55
+ return newMs;
56
+ }
57
+
58
+
59
+ export function addHours(t: number, h: number) {
60
+ return add(t, h * 3600000);
61
+ }
62
+
63
+ export function addMinutes(t: number, m: number) {
64
+ return add(t, m * 60000);
65
+ }
66
+
67
+ export function isBetween(t: number, start: number, end: number) {
68
+ return start <= end
69
+ ? (start <= t && end > t)
70
+ : (start <= t || end > t);
71
+ }
72
+
73
+ export function toString(t: number, format = "t", _provider?: any) {
74
+ if (["r", "R", "o", "O", "t", "T"].indexOf(format) === -1) {
75
+ throw new Error("Custom formats are not supported");
76
+ }
77
+
78
+ const base = `${padWithZeros(hours(t), 2)}:${padWithZeros(minutes(t), 2)}`
79
+
80
+ if (format === "t")
81
+ return base;
82
+
83
+ const s = padWithZeros(seconds(t), 2);
84
+ // We're limited to millisecond precision, so the last 4 digits will always be 0
85
+ return `${base}${format === "o" || format === "O" ? `:${s}.${padWithZeros(milliseconds(t), 3)}0000` : `:${s}`}`;
86
+ }
87
+
88
+ export function parse(str: string) {
89
+ // Allowed format types:
90
+ // hh:mm
91
+ // hh:mm:ss
92
+ // hh:mm:ss.fffffff
93
+ const r = /^\s*([0-1]?\d|2[0-3])\s*:\s*([0-5]?\d)(\s*:\s*([0-5]?\d)(\.(\d+))?)?\s*$/.exec(str);
94
+ if (r != null && r[1] != null && r[2] != null) {
95
+ let ms = 0;
96
+ let s = 0;
97
+ const h = +r[1];
98
+ const m = +r[2];
99
+ if (r[4] != null) {
100
+ s = +r[4];
101
+ }
102
+ if (r[6] != null) {
103
+ // Depending on the number of decimals passed, we need to adapt the numbers
104
+ switch (r[6].length) {
105
+ case 1: ms = +r[6] * 100; break;
106
+ case 2: ms = +r[6] * 10; break;
107
+ case 3: ms = +r[6]; break;
108
+ case 4: ms = +r[6] / 10; break;
109
+ case 5: ms = +r[6] / 100; break;
110
+ case 6: ms = +r[6] / 1000; break;
111
+ default: ms = +r[6].substring(0, 7) / 10000; break;
112
+ }
113
+ }
114
+ return create(h, m, s, Math.trunc(ms));
115
+ }
116
+
117
+ throw new Error(`String '${str}' was not recognized as a valid TimeOnly.`);
118
+ }
119
+
120
+ export function tryParse(v: string, defValue: FSharpRef<number>): boolean {
121
+ try {
122
+ defValue.contents = parse(v);
123
+ return true;
124
+ } catch {
125
+ return false;
126
+ }
127
+ }
128
+
129
+ export function op_Subtraction(left: number, right: number) {
130
+ return add(left, -right);
131
+ }