@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.
- package/Array.ts +1362 -0
- package/Async.ts +207 -0
- package/AsyncBuilder.ts +222 -0
- package/BigInt.ts +337 -0
- package/BitConverter.ts +165 -0
- package/Boolean.ts +22 -0
- package/CHANGELOG.md +15 -0
- package/Char.ts +222 -0
- package/Choice.ts +300 -0
- package/Date.ts +495 -0
- package/DateOffset.ts +324 -0
- package/DateOnly.ts +146 -0
- package/Decimal.ts +250 -0
- package/Double.ts +55 -0
- package/Encoding.ts +170 -0
- package/Event.ts +119 -0
- package/FSharp.Collections.ts +34 -0
- package/FSharp.Core.CompilerServices.ts +37 -0
- package/FSharp.Core.ts +86 -0
- package/Global.ts +37 -0
- package/Guid.ts +143 -0
- package/Int32.ts +156 -0
- package/List.ts +1417 -0
- package/Long.ts +49 -0
- package/MailboxProcessor.ts +125 -0
- package/Map.ts +1552 -0
- package/MapUtil.ts +120 -0
- package/MutableMap.ts +344 -0
- package/MutableSet.ts +248 -0
- package/Native.ts +11 -0
- package/Numeric.ts +80 -0
- package/Observable.ts +156 -0
- package/Option.ts +137 -0
- package/README.md +3 -0
- package/Random.ts +196 -0
- package/Range.ts +56 -0
- package/Reflection.ts +539 -0
- package/RegExp.ts +143 -0
- package/Result.ts +196 -0
- package/Seq.ts +1526 -0
- package/Seq2.ts +129 -0
- package/Set.ts +1955 -0
- package/String.ts +589 -0
- package/System.Collections.Generic.ts +380 -0
- package/System.Text.ts +137 -0
- package/SystemException.ts +7 -0
- package/TimeOnly.ts +131 -0
- package/TimeSpan.ts +194 -0
- package/Timer.ts +80 -0
- package/Types.ts +231 -0
- package/Unicode.13.0.0.ts +4 -0
- package/Uri.ts +206 -0
- package/Util.ts +928 -0
- package/lib/big.d.ts +338 -0
- package/lib/big.js +1054 -0
- package/package.json +24 -0
- package/tsconfig.json +103 -0
package/Long.ts
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { getPrefix, isValid } from "./Int32.js";
|
|
2
|
+
import { fromString } from "./BigInt.js";
|
|
3
|
+
import { FSharpRef } from "./Types.js";
|
|
4
|
+
|
|
5
|
+
function getMaxValue(unsigned: boolean, radix: number, isNegative: boolean) {
|
|
6
|
+
switch (radix) {
|
|
7
|
+
case 2: return unsigned ?
|
|
8
|
+
"1111111111111111111111111111111111111111111111111111111111111111" :
|
|
9
|
+
(isNegative ? "1000000000000000000000000000000000000000000000000000000000000000"
|
|
10
|
+
: "111111111111111111111111111111111111111111111111111111111111111");
|
|
11
|
+
case 8: return unsigned ?
|
|
12
|
+
"1777777777777777777777" :
|
|
13
|
+
(isNegative ? "1000000000000000000000" : "777777777777777777777");
|
|
14
|
+
case 10: return unsigned ?
|
|
15
|
+
"18446744073709551615" :
|
|
16
|
+
(isNegative ? "9223372036854775808" : "9223372036854775807");
|
|
17
|
+
case 16: return unsigned ?
|
|
18
|
+
"FFFFFFFFFFFFFFFF" :
|
|
19
|
+
(isNegative ? "8000000000000000" : "7FFFFFFFFFFFFFFF");
|
|
20
|
+
default: throw new Error("Invalid radix.");
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function parse(str: string, style: number, unsigned: boolean, _bitsize: number, radix?: number) {
|
|
25
|
+
const res = isValid(str, style, radix);
|
|
26
|
+
if (res != null) {
|
|
27
|
+
const lessOrEqual = (x: string, y: string) => {
|
|
28
|
+
const len = Math.max(x.length, y.length);
|
|
29
|
+
return x.padStart(len, "0") <= y.padStart(len, "0");
|
|
30
|
+
};
|
|
31
|
+
const isNegative = res.sign === "-";
|
|
32
|
+
const maxValue = getMaxValue(unsigned || res.radix !== 10, res.radix, isNegative);
|
|
33
|
+
if (lessOrEqual(res.digits.toUpperCase(), maxValue)) {
|
|
34
|
+
str = getPrefix(res.radix) + res.digits;
|
|
35
|
+
str = isNegative ? res.sign + str : str;
|
|
36
|
+
return fromString(str);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
throw new Error(`The input string ${str} was not in a correct format.`);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function tryParse(str: string, style: number, unsigned: boolean, bitsize: number, defValue: FSharpRef<bigint>) {
|
|
43
|
+
try {
|
|
44
|
+
defValue.contents = parse(str, style, unsigned, bitsize);
|
|
45
|
+
return true;
|
|
46
|
+
} catch {
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { defaultCancellationToken } from "./Async.js";
|
|
2
|
+
import { fromContinuations } from "./Async.js";
|
|
3
|
+
import { startImmediate } from "./Async.js";
|
|
4
|
+
import { IAsync } from "./AsyncBuilder.js";
|
|
5
|
+
import { Continuation, Continuations } from "./AsyncBuilder.js";
|
|
6
|
+
import { CancellationToken } from "./AsyncBuilder.js";
|
|
7
|
+
|
|
8
|
+
class QueueCell<Msg> {
|
|
9
|
+
public value: Msg;
|
|
10
|
+
public next?: QueueCell<Msg>;
|
|
11
|
+
|
|
12
|
+
constructor(message: Msg) {
|
|
13
|
+
this.value = message;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
class MailboxQueue<Msg> {
|
|
18
|
+
private firstAndLast?: [QueueCell<Msg>, QueueCell<Msg>];
|
|
19
|
+
|
|
20
|
+
public add(message: Msg) {
|
|
21
|
+
const itCell = new QueueCell(message);
|
|
22
|
+
if (this.firstAndLast) {
|
|
23
|
+
this.firstAndLast[1].next = itCell;
|
|
24
|
+
this.firstAndLast = [this.firstAndLast[0], itCell];
|
|
25
|
+
} else {
|
|
26
|
+
this.firstAndLast = [itCell, itCell];
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
public tryGet() {
|
|
31
|
+
if (this.firstAndLast) {
|
|
32
|
+
const value = this.firstAndLast[0].value;
|
|
33
|
+
if (this.firstAndLast[0].next) {
|
|
34
|
+
this.firstAndLast = [this.firstAndLast[0].next, this.firstAndLast[1]];
|
|
35
|
+
} else {
|
|
36
|
+
delete this.firstAndLast;
|
|
37
|
+
}
|
|
38
|
+
return value;
|
|
39
|
+
}
|
|
40
|
+
return void 0;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export type MailboxBody<Msg> = (m: MailboxProcessor<Msg>) => IAsync<void>;
|
|
45
|
+
|
|
46
|
+
export interface AsyncReplyChannel<Reply> {
|
|
47
|
+
reply: (r: Reply) => void;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export class MailboxProcessor<Msg> {
|
|
51
|
+
public body: MailboxBody<Msg>;
|
|
52
|
+
public cancellationToken: CancellationToken;
|
|
53
|
+
public messages: MailboxQueue<Msg>;
|
|
54
|
+
|
|
55
|
+
public continuation?: Continuation<Msg>;
|
|
56
|
+
|
|
57
|
+
constructor(body: MailboxBody<Msg>, cancellationToken?: CancellationToken) {
|
|
58
|
+
this.body = body;
|
|
59
|
+
this.cancellationToken = cancellationToken || defaultCancellationToken;
|
|
60
|
+
this.messages = new MailboxQueue<Msg>();
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function __processEvents<Msg>($this: MailboxProcessor<Msg>) {
|
|
65
|
+
if ($this.continuation) {
|
|
66
|
+
const value = $this.messages.tryGet();
|
|
67
|
+
if (value) {
|
|
68
|
+
const cont = $this.continuation;
|
|
69
|
+
delete $this.continuation;
|
|
70
|
+
cont(value);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export function startInstance<Msg>($this: MailboxProcessor<Msg>) {
|
|
76
|
+
startImmediate($this.body($this), $this.cancellationToken);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export function receive<Msg>($this: MailboxProcessor<Msg>) {
|
|
80
|
+
return fromContinuations((conts: Continuations<Msg>) => {
|
|
81
|
+
if ($this.continuation) {
|
|
82
|
+
throw new Error("Receive can only be called once!");
|
|
83
|
+
}
|
|
84
|
+
$this.continuation = conts[0];
|
|
85
|
+
__processEvents($this);
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export function post<Msg>($this: MailboxProcessor<Msg>, message: Msg) {
|
|
90
|
+
$this.messages.add(message);
|
|
91
|
+
__processEvents($this);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export function postAndAsyncReply<Reply, Msg>(
|
|
95
|
+
$this: MailboxProcessor<Msg>,
|
|
96
|
+
buildMessage: (c: AsyncReplyChannel<Reply>) => Msg,
|
|
97
|
+
) {
|
|
98
|
+
let result: Reply;
|
|
99
|
+
let continuation: Continuation<Reply>;
|
|
100
|
+
function checkCompletion() {
|
|
101
|
+
if (result !== void 0 && continuation !== void 0) {
|
|
102
|
+
continuation(result);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
const reply = {
|
|
106
|
+
reply: (res: Reply) => {
|
|
107
|
+
result = res;
|
|
108
|
+
checkCompletion();
|
|
109
|
+
},
|
|
110
|
+
};
|
|
111
|
+
$this.messages.add(buildMessage(reply));
|
|
112
|
+
__processEvents($this);
|
|
113
|
+
return fromContinuations((conts: Continuations<Reply>) => {
|
|
114
|
+
continuation = conts[0];
|
|
115
|
+
checkCompletion();
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export function start<Msg>(body: MailboxBody<Msg>, cancellationToken?: CancellationToken) {
|
|
120
|
+
const mbox = new MailboxProcessor(body, cancellationToken);
|
|
121
|
+
startInstance(mbox);
|
|
122
|
+
return mbox;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
export default MailboxProcessor;
|