@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/Int32.ts
ADDED
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import { FSharpRef } from "./Types.js";
|
|
2
|
+
|
|
3
|
+
export type int8 = number;
|
|
4
|
+
export type uint8 = number;
|
|
5
|
+
export type int16 = number;
|
|
6
|
+
export type uint16 = number;
|
|
7
|
+
export type int32 = number;
|
|
8
|
+
export type uint32 = number;
|
|
9
|
+
|
|
10
|
+
export type float16 = number;
|
|
11
|
+
export type float32 = number;
|
|
12
|
+
export type float64 = number;
|
|
13
|
+
|
|
14
|
+
export enum NumberStyles {
|
|
15
|
+
// None = 0x00000000,
|
|
16
|
+
// AllowLeadingWhite = 0x00000001,
|
|
17
|
+
// AllowTrailingWhite = 0x00000002,
|
|
18
|
+
// AllowLeadingSign = 0x00000004,
|
|
19
|
+
// AllowTrailingSign = 0x00000008,
|
|
20
|
+
// AllowParentheses = 0x00000010,
|
|
21
|
+
// AllowDecimalPoint = 0x00000020,
|
|
22
|
+
// AllowThousands = 0x00000040,
|
|
23
|
+
// AllowExponent = 0x00000080,
|
|
24
|
+
// AllowCurrencySymbol = 0x00000100,
|
|
25
|
+
AllowHexSpecifier = 0x00000200,
|
|
26
|
+
|
|
27
|
+
// Integer = AllowLeadingWhite | AllowTrailingWhite | AllowLeadingSign,
|
|
28
|
+
// HexNumber = AllowLeadingWhite | AllowTrailingWhite | AllowHexSpecifier,
|
|
29
|
+
// Number = AllowLeadingWhite | AllowTrailingWhite | AllowLeadingSign |
|
|
30
|
+
// AllowTrailingSign | AllowDecimalPoint | AllowThousands,
|
|
31
|
+
// Float = AllowLeadingWhite | AllowTrailingWhite | AllowLeadingSign |
|
|
32
|
+
// AllowDecimalPoint | AllowExponent,
|
|
33
|
+
// Currency = AllowLeadingWhite | AllowTrailingWhite | AllowLeadingSign | AllowTrailingSign |
|
|
34
|
+
// AllowParentheses | AllowDecimalPoint | AllowThousands | AllowCurrencySymbol,
|
|
35
|
+
// Any = AllowLeadingWhite | AllowTrailingWhite | AllowLeadingSign | AllowTrailingSign |
|
|
36
|
+
// AllowParentheses | AllowDecimalPoint | AllowThousands | AllowCurrencySymbol | AllowExponent,
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function validResponse(regexMatch: RegExpExecArray, radix: number) {
|
|
40
|
+
const [/*all*/, sign, prefix, digits] = regexMatch;
|
|
41
|
+
return {
|
|
42
|
+
sign: sign || "",
|
|
43
|
+
prefix: prefix || "",
|
|
44
|
+
digits,
|
|
45
|
+
radix,
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function getRange(unsigned: boolean, bitsize: number): [number, number] {
|
|
50
|
+
switch (bitsize) {
|
|
51
|
+
case 8: return unsigned ? [0, 255] : [-128, 127];
|
|
52
|
+
case 16: return unsigned ? [0, 65535] : [-32768, 32767];
|
|
53
|
+
case 32: return unsigned ? [0, 4294967295] : [-2147483648, 2147483647];
|
|
54
|
+
default: throw new Error("Invalid bit size.");
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function getInvalidDigits(radix: number): RegExp {
|
|
59
|
+
switch (radix) {
|
|
60
|
+
case 2: return /[^0-1]/;
|
|
61
|
+
case 8: return /[^0-7]/;
|
|
62
|
+
case 10: return /[^0-9]/;
|
|
63
|
+
case 16: return /[^0-9a-fA-F]/;
|
|
64
|
+
default:
|
|
65
|
+
throw new Error("Invalid Base.");
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export function getPrefix(radix: number): string {
|
|
70
|
+
switch (radix) {
|
|
71
|
+
case 2: return "0b";
|
|
72
|
+
case 8: return "0o";
|
|
73
|
+
case 10: return "";
|
|
74
|
+
case 16: return "0x";
|
|
75
|
+
default: return "";
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export function getRadix(prefix: string, style: number) {
|
|
80
|
+
if (style & NumberStyles.AllowHexSpecifier) {
|
|
81
|
+
return 16;
|
|
82
|
+
} else {
|
|
83
|
+
switch (prefix) {
|
|
84
|
+
case "0b": case "0B": return 2;
|
|
85
|
+
case "0o": case "0O": return 8;
|
|
86
|
+
case "0x": case "0X": return 16;
|
|
87
|
+
default: return 10;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export function isValid(str: string, style: number, radix?: number) {
|
|
93
|
+
const integerRegex = /^\s*([\+\-])?(0[xXoObB])?([0-9a-fA-F]+)\s*$/;
|
|
94
|
+
const res = integerRegex.exec(str.replace(/_/g, ""));
|
|
95
|
+
if (res != null) {
|
|
96
|
+
const [/*all*/, /*sign*/, prefix, digits] = res;
|
|
97
|
+
radix = radix || getRadix(prefix, style);
|
|
98
|
+
const invalidDigits = getInvalidDigits(radix);
|
|
99
|
+
if (!invalidDigits.test(digits)) {
|
|
100
|
+
return validResponse(res, radix);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
return null;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export function parse(str: string, style: number, unsigned: boolean, bitsize: number, radix?: number): number {
|
|
107
|
+
const res = isValid(str, style, radix);
|
|
108
|
+
if (res != null) {
|
|
109
|
+
let v = Number.parseInt(res.sign + res.digits, res.radix);
|
|
110
|
+
if (!Number.isNaN(v)) {
|
|
111
|
+
const [umin, umax] = getRange(true, bitsize);
|
|
112
|
+
if (!unsigned && res.radix !== 10 && v >= umin && v <= umax) {
|
|
113
|
+
v = v << (32 - bitsize) >> (32 - bitsize);
|
|
114
|
+
}
|
|
115
|
+
const [min, max] = getRange(unsigned, bitsize);
|
|
116
|
+
if (v >= min && v <= max) {
|
|
117
|
+
return v;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
throw new Error(`The input string ${str} was not in a correct format.`);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
export function tryParse(str: string, style: number, unsigned: boolean, bitsize: number, defValue: FSharpRef<number>): boolean {
|
|
125
|
+
try {
|
|
126
|
+
defValue.contents = parse(str, style, unsigned, bitsize);
|
|
127
|
+
return true;
|
|
128
|
+
} catch {
|
|
129
|
+
return false;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
export function op_UnaryNegation_Int8(x: number) {
|
|
134
|
+
return x === -128 ? x : -x;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
export function op_UnaryNegation_Int16(x: number) {
|
|
138
|
+
return x === -32768 ? x : -x;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
export function op_UnaryNegation_Int32(x: number) {
|
|
142
|
+
return x === -2147483648 ? x : -x;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
export function divRem(x: number, y: number): [number, number];
|
|
146
|
+
export function divRem(x: number, y: number, out: FSharpRef<number>): number;
|
|
147
|
+
export function divRem(x: number, y: number, out?: FSharpRef<number>): number | [number, number] {
|
|
148
|
+
const div = ~~(x / y);
|
|
149
|
+
const rem = x % y;
|
|
150
|
+
if (out === void 0) {
|
|
151
|
+
return [div, rem];
|
|
152
|
+
} else {
|
|
153
|
+
out.contents = rem;
|
|
154
|
+
return div;
|
|
155
|
+
}
|
|
156
|
+
}
|