@fable-org/fable-library-ts 2.0.0-beta.3 → 2.0.0-beta.5
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/Array.ts +1385 -1378
- package/Async.ts +13 -12
- package/AsyncBuilder.ts +10 -11
- package/BigInt.ts +6 -6
- package/BitConverter.ts +3 -3
- package/Boolean.ts +3 -2
- package/CHANGELOG.md +12 -0
- package/Char.ts +38 -35
- package/Choice.ts +326 -301
- package/CollectionUtil.ts +4 -4
- package/Date.ts +67 -62
- package/DateOffset.ts +48 -57
- package/DateOnly.ts +8 -8
- package/Decimal.ts +9 -9
- package/Double.ts +3 -2
- package/Encoding.ts +1 -1
- package/Event.ts +3 -3
- package/FSharp.Collections.ts +53 -34
- package/FSharp.Core.CompilerServices.ts +38 -37
- package/FSharp.Core.ts +186 -185
- package/Global.ts +80 -37
- package/Guid.ts +7 -6
- package/Int32.ts +20 -17
- package/List.ts +1429 -1417
- package/Long.ts +6 -5
- package/MailboxProcessor.ts +8 -7
- package/Map.ts +1550 -1552
- package/MapUtil.ts +5 -5
- package/MutableMap.ts +358 -345
- package/MutableSet.ts +250 -249
- package/Native.ts +19 -11
- package/Numeric.ts +1 -1
- package/Observable.ts +3 -3
- package/Option.ts +10 -4
- package/Random.ts +196 -194
- package/Range.ts +57 -56
- package/Reflection.ts +73 -40
- package/RegExp.ts +5 -3
- package/Result.ts +201 -196
- package/Seq.ts +1517 -1525
- package/Seq2.ts +130 -129
- package/Set.ts +1955 -1955
- package/String.ts +41 -38
- package/System.Collections.Generic.ts +401 -380
- package/System.Text.ts +204 -203
- package/System.ts +366 -0
- package/TimeOnly.ts +10 -10
- package/TimeSpan.ts +11 -11
- package/Timer.ts +2 -2
- package/Types.ts +1 -19
- package/Uri.ts +13 -10
- package/Util.ts +77 -21
- package/package.json +22 -22
- package/tsconfig.json +18 -5
- package/SystemException.ts +0 -7
package/Async.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Continuation, Continuations } from "./AsyncBuilder.
|
|
3
|
-
import { Async, IAsyncContext, CancellationToken } from "./AsyncBuilder.
|
|
4
|
-
import { protectedCont, protectedBind, protectedReturn } from "./AsyncBuilder.
|
|
5
|
-
import { FSharpChoice$2_$union, Choice_makeChoice1Of2, Choice_makeChoice2Of2 } from "./Choice.
|
|
6
|
-
import {
|
|
1
|
+
import { OperationCanceledException, Trampoline } from "./AsyncBuilder.ts";
|
|
2
|
+
import { Continuation, Continuations } from "./AsyncBuilder.ts";
|
|
3
|
+
import { Async, IAsyncContext, CancellationToken } from "./AsyncBuilder.ts";
|
|
4
|
+
import { protectedCont, protectedBind, protectedReturn } from "./AsyncBuilder.ts";
|
|
5
|
+
import { FSharpChoice$2_$union, Choice_makeChoice1Of2, Choice_makeChoice2Of2 } from "./Choice.ts";
|
|
6
|
+
import { TimeoutException_$ctor } from "./System.ts";
|
|
7
|
+
import { Exception } from "./Util.ts";
|
|
7
8
|
|
|
8
9
|
function emptyContinuation<T>(_x: T) {
|
|
9
10
|
// NOP
|
|
@@ -53,7 +54,7 @@ export function isCancellationRequested(token: CancellationToken) {
|
|
|
53
54
|
|
|
54
55
|
export function throwIfCancellationRequested(token: CancellationToken) {
|
|
55
56
|
if (token != null && token.isCancelled) {
|
|
56
|
-
throw new
|
|
57
|
+
throw new Exception("Operation is cancelled");
|
|
57
58
|
}
|
|
58
59
|
}
|
|
59
60
|
|
|
@@ -62,11 +63,11 @@ function throwAfter(millisecondsDueTime: number): Async<void> {
|
|
|
62
63
|
let tokenId: number;
|
|
63
64
|
const timeoutId = setTimeout(() => {
|
|
64
65
|
ctx.cancelToken.removeListener(tokenId);
|
|
65
|
-
ctx.onError(
|
|
66
|
+
ctx.onError(TimeoutException_$ctor());
|
|
66
67
|
}, millisecondsDueTime);
|
|
67
68
|
tokenId = ctx.cancelToken.addListener(() => {
|
|
68
69
|
clearTimeout(timeoutId);
|
|
69
|
-
ctx.onCancel(new
|
|
70
|
+
ctx.onCancel(new OperationCanceledException());
|
|
70
71
|
});
|
|
71
72
|
});
|
|
72
73
|
}
|
|
@@ -93,7 +94,7 @@ export function startChild<T>(computation: Async<T>, ms?: number): Async<Async<T
|
|
|
93
94
|
export function awaitPromise<T>(p: Promise<T>) {
|
|
94
95
|
return fromContinuations((conts: Continuations<T>) =>
|
|
95
96
|
p.then(conts[0]).catch((err) =>
|
|
96
|
-
(err instanceof
|
|
97
|
+
(err instanceof OperationCanceledException
|
|
97
98
|
? conts[2] : conts[1])(err)));
|
|
98
99
|
}
|
|
99
100
|
|
|
@@ -104,7 +105,7 @@ export function cancellationToken() {
|
|
|
104
105
|
export const defaultCancellationToken = new CancellationToken();
|
|
105
106
|
|
|
106
107
|
export function catchAsync<T>(work: Async<T>) {
|
|
107
|
-
return protectedCont((ctx: IAsyncContext<FSharpChoice$2_$union<T,
|
|
108
|
+
return protectedCont((ctx: IAsyncContext<FSharpChoice$2_$union<T, Exception>>) => {
|
|
108
109
|
work({
|
|
109
110
|
onSuccess: (x) => ctx.onSuccess(Choice_makeChoice1Of2(x)),
|
|
110
111
|
onError: (ex) => ctx.onSuccess(Choice_makeChoice2Of2(ex)),
|
|
@@ -154,7 +155,7 @@ export function sleep(millisecondsDueTime: number) {
|
|
|
154
155
|
}, millisecondsDueTime);
|
|
155
156
|
tokenId = ctx.cancelToken.addListener(() => {
|
|
156
157
|
clearTimeout(timeoutId);
|
|
157
|
-
ctx.onCancel(new
|
|
158
|
+
ctx.onCancel(new OperationCanceledException());
|
|
158
159
|
});
|
|
159
160
|
});
|
|
160
161
|
}
|
package/AsyncBuilder.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { ensureErrorOrException } from
|
|
2
|
-
import { IDisposable } from "./Util.js";
|
|
1
|
+
import { Exception, ensureErrorOrException, IDisposable } from "./Util.ts";
|
|
3
2
|
|
|
4
3
|
export interface AsyncReplyChannel<Reply> {
|
|
5
4
|
reply(value: Reply): void
|
|
@@ -9,8 +8,8 @@ export type Continuation<T> = (x: T) => void;
|
|
|
9
8
|
|
|
10
9
|
export type Continuations<T> = [
|
|
11
10
|
Continuation<T>,
|
|
12
|
-
Continuation<
|
|
13
|
-
Continuation<
|
|
11
|
+
Continuation<Exception>,
|
|
12
|
+
Continuation<OperationCanceledException>
|
|
14
13
|
];
|
|
15
14
|
|
|
16
15
|
export class CancellationToken implements IDisposable {
|
|
@@ -53,10 +52,10 @@ export class CancellationToken implements IDisposable {
|
|
|
53
52
|
}
|
|
54
53
|
}
|
|
55
54
|
|
|
56
|
-
export class
|
|
57
|
-
constructor() {
|
|
58
|
-
super("The operation was canceled");
|
|
59
|
-
Object.setPrototypeOf(this,
|
|
55
|
+
export class OperationCanceledException extends Exception {
|
|
56
|
+
constructor(msg?: string) {
|
|
57
|
+
super(msg ?? "The operation was canceled");
|
|
58
|
+
// Object.setPrototypeOf(this, OperationCanceledException.prototype);
|
|
60
59
|
}
|
|
61
60
|
}
|
|
62
61
|
|
|
@@ -79,8 +78,8 @@ export class Trampoline {
|
|
|
79
78
|
|
|
80
79
|
export interface IAsyncContext<T> {
|
|
81
80
|
onSuccess: Continuation<T>;
|
|
82
|
-
onError: Continuation<
|
|
83
|
-
onCancel: Continuation<
|
|
81
|
+
onError: Continuation<Exception>;
|
|
82
|
+
onCancel: Continuation<OperationCanceledException>;
|
|
84
83
|
|
|
85
84
|
cancelToken: CancellationToken;
|
|
86
85
|
trampoline: Trampoline;
|
|
@@ -91,7 +90,7 @@ export type Async<T> = (x: IAsyncContext<T>) => void;
|
|
|
91
90
|
export function protectedCont<T>(f: Async<T>) {
|
|
92
91
|
return (ctx: IAsyncContext<T>) => {
|
|
93
92
|
if (ctx.cancelToken.isCancelled) {
|
|
94
|
-
ctx.onCancel(new
|
|
93
|
+
ctx.onCancel(new OperationCanceledException());
|
|
95
94
|
} else if (ctx.trampoline.incrementAndCheck()) {
|
|
96
95
|
ctx.trampoline.hijack(() => {
|
|
97
96
|
try {
|
package/BigInt.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { FSharpRef } from "./Types.
|
|
2
|
-
import { int8, uint8, int16, uint16, int32, uint32, float16, float32, float64 } from "./Int32.
|
|
3
|
-
import { decimal, fromParts, truncate } from "./Decimal.
|
|
4
|
-
import { bigintHash } from "./Util.
|
|
1
|
+
import { FSharpRef } from "./Types.ts";
|
|
2
|
+
import { int8, uint8, int16, uint16, int32, uint32, float16, float32, float64 } from "./Int32.ts";
|
|
3
|
+
import { decimal, fromParts, truncate } from "./Decimal.ts";
|
|
4
|
+
import { Exception, bigintHash } from "./Util.ts";
|
|
5
5
|
|
|
6
6
|
const isBigEndian = false;
|
|
7
7
|
|
|
@@ -138,7 +138,7 @@ export function toIntN(bits: number, x: bigint, signed: boolean): bigint {
|
|
|
138
138
|
let higher_bits = abs(x) >> BigInt(bits);
|
|
139
139
|
if (higher_bits !== 0n) {
|
|
140
140
|
const s = signed ? "a signed" : "an unsigned";
|
|
141
|
-
throw new
|
|
141
|
+
throw new Exception(`Value was either too large or too small for ${s} ${bits}-bit integer.`);
|
|
142
142
|
}
|
|
143
143
|
return signed ? BigInt.asIntN(bits, x) : BigInt.asUintN(bits, x);
|
|
144
144
|
}
|
|
@@ -338,7 +338,7 @@ function toSignedBytes(x: bigint, isBigEndian: boolean): Uint8Array {
|
|
|
338
338
|
|
|
339
339
|
function fromSignedBytes(bytes: ArrayLike<uint8>, isBigEndian: boolean) {
|
|
340
340
|
if (bytes == null) {
|
|
341
|
-
throw new
|
|
341
|
+
throw new Exception("bytes is null");
|
|
342
342
|
}
|
|
343
343
|
const len = bytes.length;
|
|
344
344
|
const first = isBigEndian ? 0 : len - 1;
|
package/BitConverter.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { uint8, int16, uint16, int32, uint32, float32, float64 } from "./Int32.
|
|
2
|
-
import { int64, uint64 } from "./BigInt.
|
|
3
|
-
import { char } from "./Char.
|
|
1
|
+
import { uint8, int16, uint16, int32, uint32, float32, float64 } from "./Int32.ts";
|
|
2
|
+
import { int64, uint64 } from "./BigInt.ts";
|
|
3
|
+
import { char } from "./Char.ts";
|
|
4
4
|
|
|
5
5
|
const littleEndian = true;
|
|
6
6
|
|
package/Boolean.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { FSharpRef } from "./Types.
|
|
1
|
+
import { FSharpRef } from "./Types.ts";
|
|
2
|
+
import { Exception } from "./Util.ts";
|
|
2
3
|
|
|
3
4
|
export function tryParse(str: string, defValue: FSharpRef<boolean>): boolean {
|
|
4
5
|
if (str != null && str.match(/^\s*true\s*$/i)) {
|
|
@@ -17,6 +18,6 @@ export function parse(str: string): boolean {
|
|
|
17
18
|
if (tryParse(str, defValue)) {
|
|
18
19
|
return defValue.contents;
|
|
19
20
|
} else {
|
|
20
|
-
throw new
|
|
21
|
+
throw new Exception(`String '${str}' was not recognized as a valid Boolean.`)
|
|
21
22
|
}
|
|
22
23
|
}
|
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## Unreleased
|
|
9
9
|
|
|
10
|
+
## 2.0.0-beta.5 - 2025-11-19
|
|
11
|
+
|
|
12
|
+
### Changed
|
|
13
|
+
|
|
14
|
+
* [JS/TS] Replace the deprecated `substr` method with `slice` (by @Thorium)
|
|
15
|
+
|
|
16
|
+
## 2.0.0-beta.4 - 2025-07-25
|
|
17
|
+
|
|
18
|
+
### Added
|
|
19
|
+
|
|
20
|
+
* [JS/TS] Initial support for Nullable Reference Types (by @ncave)
|
|
21
|
+
|
|
10
22
|
## 2.0.0-beta.3 - 2025-03-14
|
|
11
23
|
|
|
12
24
|
### Fixed
|
package/Char.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import * as Unicode from "./Unicode.13.0.0.
|
|
1
|
+
import * as Unicode from "./Unicode.13.0.0.ts";
|
|
2
|
+
import { Exception } from "./Util.ts";
|
|
2
3
|
|
|
3
4
|
export type char = string;
|
|
4
5
|
|
|
@@ -32,38 +33,40 @@ function getCategoryFunc() {
|
|
|
32
33
|
};
|
|
33
34
|
}
|
|
34
35
|
|
|
35
|
-
export const
|
|
36
|
-
UppercaseLetter,
|
|
37
|
-
LowercaseLetter,
|
|
38
|
-
TitlecaseLetter,
|
|
39
|
-
ModifierLetter,
|
|
40
|
-
OtherLetter,
|
|
41
|
-
NonSpacingMark,
|
|
42
|
-
SpacingCombiningMark,
|
|
43
|
-
EnclosingMark,
|
|
44
|
-
DecimalDigitNumber,
|
|
45
|
-
LetterNumber,
|
|
46
|
-
OtherNumber,
|
|
47
|
-
SpaceSeparator,
|
|
48
|
-
LineSeparator,
|
|
49
|
-
ParagraphSeparator,
|
|
50
|
-
Control,
|
|
51
|
-
Format,
|
|
52
|
-
Surrogate,
|
|
53
|
-
PrivateUse,
|
|
54
|
-
ConnectorPunctuation,
|
|
55
|
-
DashPunctuation,
|
|
56
|
-
OpenPunctuation,
|
|
57
|
-
ClosePunctuation,
|
|
58
|
-
InitialQuotePunctuation,
|
|
59
|
-
FinalQuotePunctuation,
|
|
60
|
-
OtherPunctuation,
|
|
61
|
-
MathSymbol,
|
|
62
|
-
CurrencySymbol,
|
|
63
|
-
ModifierSymbol,
|
|
64
|
-
OtherSymbol,
|
|
65
|
-
OtherNotAssigned,
|
|
66
|
-
}
|
|
36
|
+
export const UnicodeCategory = {
|
|
37
|
+
UppercaseLetter: 0,
|
|
38
|
+
LowercaseLetter: 1,
|
|
39
|
+
TitlecaseLetter: 2,
|
|
40
|
+
ModifierLetter: 3,
|
|
41
|
+
OtherLetter: 4,
|
|
42
|
+
NonSpacingMark: 5,
|
|
43
|
+
SpacingCombiningMark: 6,
|
|
44
|
+
EnclosingMark: 7,
|
|
45
|
+
DecimalDigitNumber: 8,
|
|
46
|
+
LetterNumber: 9,
|
|
47
|
+
OtherNumber: 10,
|
|
48
|
+
SpaceSeparator: 11,
|
|
49
|
+
LineSeparator: 12,
|
|
50
|
+
ParagraphSeparator: 13,
|
|
51
|
+
Control: 14,
|
|
52
|
+
Format: 15,
|
|
53
|
+
Surrogate: 16,
|
|
54
|
+
PrivateUse: 17,
|
|
55
|
+
ConnectorPunctuation: 18,
|
|
56
|
+
DashPunctuation: 19,
|
|
57
|
+
OpenPunctuation: 20,
|
|
58
|
+
ClosePunctuation: 21,
|
|
59
|
+
InitialQuotePunctuation: 22,
|
|
60
|
+
FinalQuotePunctuation: 23,
|
|
61
|
+
OtherPunctuation: 24,
|
|
62
|
+
MathSymbol: 25,
|
|
63
|
+
CurrencySymbol: 26,
|
|
64
|
+
ModifierSymbol: 27,
|
|
65
|
+
OtherSymbol: 28,
|
|
66
|
+
OtherNotAssigned: 29,
|
|
67
|
+
} as const;
|
|
68
|
+
|
|
69
|
+
export type UnicodeCategory = typeof UnicodeCategory[keyof typeof UnicodeCategory];
|
|
67
70
|
|
|
68
71
|
const isControlMask = 1 << UnicodeCategory.Control;
|
|
69
72
|
const isDigitMask = 1 << UnicodeCategory.DecimalDigitNumber;
|
|
@@ -108,7 +111,7 @@ function charCodeAt(s: string, index: number) {
|
|
|
108
111
|
if (index >= 0 && index < s.length) {
|
|
109
112
|
return s.charCodeAt(index);
|
|
110
113
|
} else {
|
|
111
|
-
throw new
|
|
114
|
+
throw new Exception("Index out of range.");
|
|
112
115
|
}
|
|
113
116
|
}
|
|
114
117
|
|
|
@@ -217,6 +220,6 @@ export function parse(input: string) {
|
|
|
217
220
|
if (input.length === 1) {
|
|
218
221
|
return input[0];
|
|
219
222
|
} else {
|
|
220
|
-
throw new
|
|
223
|
+
throw new Exception("String must be exactly one character long.");
|
|
221
224
|
}
|
|
222
225
|
}
|