@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
package/BigInt.ts ADDED
@@ -0,0 +1,337 @@
1
+ import { FSharpRef } from "./Types.js";
2
+ import { int8, uint8, int16, uint16, int32, uint32, float16, float32, float64 } from "./Int32.js";
3
+ import { decimal, fromParts, truncate } from "./Decimal.js";
4
+ import { bigintHash } from "./Util.js";
5
+
6
+ const isBigEndian = false;
7
+
8
+ export type int64 = bigint;
9
+ export type uint64 = bigint;
10
+ export type int128 = bigint;
11
+ export type uint128 = bigint;
12
+ export type nativeint = bigint;
13
+ export type unativeint = bigint;
14
+
15
+ (BigInt.prototype as any).toJSON = function () {
16
+ return `${this.toString()}`;
17
+ };
18
+
19
+ const zero: bigint = 0n;
20
+ const one: bigint = 1n;
21
+ const two: bigint = 2n;
22
+ const minusOne: bigint = -1n;
23
+
24
+ export function isBigInt(x: any): boolean {
25
+ return typeof x === "bigint";
26
+ }
27
+
28
+ export function hash(x: bigint): int32 {
29
+ return bigintHash(x);
30
+ }
31
+
32
+ export function equals(x: bigint, y: bigint): boolean {
33
+ return x === y;
34
+ }
35
+
36
+ export function compare(x: bigint, y: bigint): int32 {
37
+ return x < y ? -1 : x > y ? 1 : 0;
38
+ }
39
+
40
+ export function abs(x: bigint): bigint { return x < zero ? -x : x; }
41
+ export function sign(x: bigint): int32 { return x < zero ? -1 : x > zero ? 1 : 0; }
42
+
43
+ export function max(x: bigint, y: bigint): bigint { return x > y ? x : y; }
44
+ export function min(x: bigint, y: bigint): bigint { return x < y ? x : y; }
45
+
46
+ export function maxMagnitude(x: bigint, y: bigint): bigint { return abs(x) > abs(y) ? x : y; }
47
+ export function minMagnitude(x: bigint, y: bigint): bigint { return abs(x) < abs(y) ? x : y; }
48
+
49
+ export function clamp(x: bigint, min: bigint, max: bigint): bigint {
50
+ return x < min ? min : x > max ? max : x;
51
+ }
52
+
53
+ export function add(x: bigint, y: bigint): bigint { return x + y }
54
+ export function subtract(x: bigint, y: bigint): bigint { return x - y }
55
+ export function multiply(x: bigint, y: bigint): bigint { return x * y }
56
+ export function divide(x: bigint, y: bigint): bigint { return x / y }
57
+ export function remainder(x: bigint, y: bigint): bigint { return x % y }
58
+ export function negate(x: bigint): bigint { return -x }
59
+
60
+ export function op_UnaryNegation(x: bigint): bigint { return -x; }
61
+ export function op_LogicalNot(x: bigint): bigint { return ~x; }
62
+ export function op_UnaryPlus(x: bigint): bigint { return x; }
63
+
64
+ export function op_Addition(x: bigint, y: bigint): bigint { return x + y; }
65
+ export function op_Subtraction(x: bigint, y: bigint): bigint { return x - y; }
66
+ export function op_Multiply(x: bigint, y: bigint): bigint { return x * y; }
67
+ export function op_Division(x: bigint, y: bigint): bigint { return x / y; }
68
+ export function op_Modulus(x: bigint, y: bigint): bigint { return x % y; }
69
+
70
+ export function op_RightShift(x: bigint, n: int32): bigint { return x >> BigInt(n); }
71
+ export function op_LeftShift(x: bigint, n: int32): bigint { return x << BigInt(n); }
72
+ export function op_BitwiseAnd(x: bigint, y: bigint): bigint { return x & y; }
73
+ export function op_BitwiseOr(x: bigint, y: bigint): bigint { return x | y; }
74
+ export function op_ExclusiveOr(x: bigint, y: bigint): bigint { return x ^ y; }
75
+
76
+ export function op_LessThan(x: bigint, y: bigint): boolean { return x < y; }
77
+ export function op_LessThanOrEqual(x: bigint, y: bigint): boolean { return x <= y; }
78
+ export function op_GreaterThan(x: bigint, y: bigint): boolean { return x > y; }
79
+ export function op_GreaterThanOrEqual(x: bigint, y: bigint): boolean { return x >= y; }
80
+ export function op_Equality(x: bigint, y: bigint): boolean { return x === y; }
81
+ export function op_Inequality(x: bigint, y: bigint): boolean { return x !== y; }
82
+
83
+ export function get_Zero(): bigint { return zero; }
84
+ export function get_One(): bigint { return one; }
85
+ export function get_MinusOne(): bigint { return minusOne; }
86
+ export function get_IsZero(x: bigint): boolean { return x === zero; }
87
+ export function get_IsOne(x: bigint): boolean { return x === one; }
88
+ export function get_IsEven(x: bigint): boolean { return isEvenInteger(x); }
89
+ export function get_IsPowerOfTwo(x: bigint): boolean { return isPow2(x); }
90
+ export function get_Sign(x: bigint): int32 { return sign(x); }
91
+
92
+ export function isNegative(x: bigint): boolean { return x < zero; }
93
+ export function isPositive(x: bigint): boolean { return x > zero; }
94
+ export function isEvenInteger(x: bigint): boolean { return (x % two) === zero; }
95
+ export function isOddInteger(x: bigint): boolean { return (x % two) !== zero; }
96
+ export function isPow2(x: bigint): boolean { return (x & (x - one)) === zero }
97
+
98
+ export function fromZero(): bigint { return zero; }
99
+ export function fromOne(): bigint { return one; }
100
+
101
+ export function fromInt8(n: int8): bigint { return BigInt(n); }
102
+ export function fromUInt8(n: uint8): bigint { return BigInt(n); }
103
+ export function fromInt16(n: int16): bigint { return BigInt(n); }
104
+ export function fromUInt16(n: uint16): bigint { return BigInt(n); }
105
+ export function fromInt32(n: int32): bigint { return BigInt(n); }
106
+ export function fromUInt32(n: uint32): bigint { return BigInt(n); }
107
+ export function fromInt64(n: int64): bigint { return n; }
108
+ export function fromUInt64(n: uint64): bigint { return n; }
109
+ export function fromInt128(n: int128): bigint { return n; }
110
+ export function fromUInt128(n: uint128): bigint { return n; }
111
+ export function fromNativeInt(n: nativeint): bigint { return n; }
112
+ export function fromUNativeInt(n: unativeint): bigint { return n; }
113
+
114
+ export function fromFloat16(n: float16): bigint { return BigInt(Math.trunc(n)); }
115
+ export function fromFloat32(n: float32): bigint { return BigInt(Math.trunc(n)); }
116
+ export function fromFloat64(n: float64): bigint { return BigInt(Math.trunc(n)); }
117
+
118
+ export function fromDecimal(d: decimal): bigint { return BigInt(truncate(d).toString()); }
119
+
120
+ export function fromBigInt(x: bigint): bigint { return x }
121
+ export function fromBoolean(b: boolean): bigint { return BigInt(b); }
122
+ export function fromChar(c: string): bigint { return BigInt(c.charCodeAt(0)); }
123
+ export function fromString(s: string): bigint { return BigInt(s); }
124
+
125
+ export function fromByteArray(bytes: ArrayLike<uint8>): bigint {
126
+ return fromSignedBytes(bytes, isBigEndian);
127
+ }
128
+
129
+ export function toByteArray(value: bigint): number[] {
130
+ return toSignedBytes(value, isBigEndian) as any as number[];
131
+ }
132
+
133
+ export function toInt8(x: bigint): int8 { return Number(BigInt.asIntN(8, x)); }
134
+ export function toUInt8(x: bigint): uint8 { return Number(BigInt.asUintN(8, x)); }
135
+ export function toInt16(x: bigint): int16 { return Number(BigInt.asIntN(16, x)); }
136
+ export function toUInt16(x: bigint): uint16 { return Number(BigInt.asUintN(16, x)); }
137
+ export function toInt32(x: bigint): int32 { return Number(BigInt.asIntN(32, x)); }
138
+ export function toUInt32(x: bigint): uint32 { return Number(BigInt.asUintN(32, x)); }
139
+ export function toInt64(x: bigint): int64 { return BigInt.asIntN(64, x); }
140
+ export function toUInt64(x: bigint): uint64 { return BigInt.asUintN(64, x); }
141
+ export function toInt128(x: bigint): int128 { return BigInt.asIntN(128, x); }
142
+ export function toUInt128(x: bigint): uint128 { return BigInt.asUintN(128, x); }
143
+ export function toNativeInt(x: bigint): nativeint { return BigInt.asIntN(64, x); }
144
+ export function toUNativeInt(x: bigint): unativeint { return BigInt.asUintN(64, x); }
145
+
146
+ export function toFloat16(x: bigint): float32 { return Number(x); }
147
+ export function toFloat32(x: bigint): float32 { return Number(x); }
148
+ export function toFloat64(x: bigint): float64 { return Number(x); }
149
+
150
+ export function toDecimal(x: bigint): decimal {
151
+ const low = Number(BigInt.asUintN(32, x))
152
+ const mid = Number(BigInt.asUintN(32, x >> 32n))
153
+ const high = Number(BigInt.asUintN(32, x >> 64n))
154
+ const isNegative = x < zero;
155
+ const scale = 0;
156
+ return fromParts(low, mid, high, isNegative, scale)
157
+ }
158
+
159
+ export function toBigInt(x: bigint): bigint { return x; }
160
+ export function toBoolean(x: bigint): boolean { return x !== zero; }
161
+
162
+ export function toChar(x: bigint): string {
163
+ return String.fromCharCode(toUInt16(x))
164
+ }
165
+
166
+ export function toString(x: bigint): string { return x.toString(); }
167
+
168
+ export function tryParse(s: string, res: FSharpRef<bigint>): boolean {
169
+ try {
170
+ res.contents = BigInt(s);
171
+ return true;
172
+ }
173
+ catch (err: any) {
174
+ return false;
175
+ }
176
+ }
177
+
178
+ export function parse(s: string): bigint {
179
+ return BigInt(s);
180
+ }
181
+
182
+ export function pow(x: bigint, n: int32): bigint {
183
+ return x ** BigInt(n);
184
+ }
185
+
186
+ export function modPow(x: bigint, e: bigint, m: bigint): bigint {
187
+ return (x ** e) % m;
188
+ }
189
+
190
+ export function divRem(x: bigint, y: bigint): [bigint, bigint];
191
+ export function divRem(x: bigint, y: bigint, out: FSharpRef<bigint>): bigint;
192
+ export function divRem(x: bigint, y: bigint, out?: FSharpRef<bigint>): bigint | [bigint, bigint] {
193
+ const div = x / y;
194
+ const rem = x % y;
195
+ if (out === void 0) {
196
+ return [div, rem];
197
+ } else {
198
+ out.contents = rem;
199
+ return div;
200
+ }
201
+ }
202
+
203
+ export function greatestCommonDivisor(x: bigint, y: bigint): bigint {
204
+ while (y > zero) {
205
+ const q = x / y;
206
+ const r = x - q * y;
207
+ x = y;
208
+ y = r;
209
+ }
210
+ return x;
211
+ }
212
+
213
+ export function getBitLength(x: bigint): int64 {
214
+ return fromFloat64(x === zero ? 1 : log2(abs(x)) + 1);
215
+ }
216
+
217
+ export function log2(x: bigint): float64 {
218
+ const n = Number(x);
219
+ if (Number.isFinite(n))
220
+ return Math.log2(n); // fast path
221
+ if (x < zero) return Number.NaN;
222
+ let shift = one;
223
+ while (x >= (one << shift)) {
224
+ shift = shift << one;
225
+ }
226
+ let log = zero;
227
+ while (shift > one) {
228
+ shift = shift >> one;
229
+ if (x >= (one << shift)) {
230
+ log = log + shift;
231
+ x = x >> shift;
232
+ }
233
+ }
234
+ return Number(log);
235
+ }
236
+
237
+ export function log10(x: bigint): float64 {
238
+ return log2(x) * Math.log10(2);
239
+ }
240
+
241
+ export function ln(x: bigint): float64 {
242
+ return log2(x) * Math.log(2);
243
+ }
244
+
245
+ export function log(x: bigint, base: float64): float64 {
246
+ return log2(x) / Math.log2(base);
247
+ }
248
+
249
+ export function ilog2(x: bigint): bigint {
250
+ return BigInt(log2(x));
251
+ }
252
+
253
+ // export function copySign
254
+ // export function createChecked
255
+ // export function createSaturating
256
+ // export function createTruncating
257
+ // export function getByteCount
258
+ // export function leadingZeroCount
259
+ // export function popCount
260
+ // export function rotateLeft
261
+ // export function rotateRight
262
+ // export function trailingZeroCount
263
+ // export function tryFormat
264
+ // export function tryWriteBytes
265
+
266
+ // -------------------------------------------------
267
+ // Binary serialization
268
+ // -------------------------------------------------
269
+
270
+ const hexCodes = new Uint8Array([48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 97, 98, 99, 100, 101, 102]);
271
+
272
+ function fromHexCode(code: number): number {
273
+ if (48 <= code && code <= 57) return code - 48;
274
+ if (97 <= code && code <= 102) return code - 97 + 10;
275
+ if (65 <= code && code <= 70) return code - 65 + 10;
276
+ throw Error(`Invalid hex code: ${code}`);
277
+ }
278
+
279
+ function toSignedBytes(x: bigint, isBigEndian: boolean): Uint8Array {
280
+ const isNeg = x < 0n;
281
+ if (isNeg) {
282
+ const len = log2(-x);
283
+ const bits = len + (8 - len % 8);
284
+ const pow2 = (1n << BigInt(bits));
285
+ x = x + pow2; // two's complement
286
+ }
287
+ const hex = x.toString(16);
288
+ const len = hex.length;
289
+ const odd = len % 2;
290
+ const first = hex.charCodeAt(0);
291
+ const isLow = 48 <= first && first <= 55; // 0..7
292
+ const start = (isNeg && isLow) || (!isNeg && !isLow) ? 1 : 0;
293
+ const bytes = new Uint8Array(start + (len + odd) / 2);
294
+ const inc = isBigEndian ? 1 : -1;
295
+ let pos = isBigEndian ? 0 : bytes.length - 1;
296
+ if (start > 0) {
297
+ bytes[pos] = isNeg ? 255 : 0;
298
+ pos += inc;
299
+ }
300
+ if (odd > 0) {
301
+ bytes[pos] = fromHexCode(first);
302
+ pos += inc;
303
+ }
304
+ for (let i = odd; i < len; i += 2, pos += inc) {
305
+ const a = fromHexCode(hex.charCodeAt(i));
306
+ const b = fromHexCode(hex.charCodeAt(i + 1));
307
+ bytes[pos] = (a << 4) | b;
308
+ }
309
+ return bytes;
310
+ }
311
+
312
+ function fromSignedBytes(bytes: ArrayLike<uint8>, isBigEndian: boolean) {
313
+ if (bytes == null) {
314
+ throw new Error("bytes is null");
315
+ }
316
+ const len = bytes.length;
317
+ const first = isBigEndian ? 0 : len - 1;
318
+ const isNeg = bytes[first] > 127;
319
+ const codes = new Uint16Array(len * 2 + 2);
320
+ codes[0] = 48; // 0
321
+ codes[1] = 120; // x
322
+ const inc = isBigEndian ? 1 : -1;
323
+ let pos = isBigEndian ? 0 : len - 1;
324
+ for (let i = 0; i < bytes.length; i++, pos += inc) {
325
+ const byte = bytes[pos];
326
+ codes[2 * i + 2] = hexCodes[byte >> 4];
327
+ codes[2 * i + 3] = hexCodes[byte & 15];
328
+ }
329
+ const str = String.fromCharCode.apply(null, codes as any as number[]);
330
+ let x = BigInt(str);
331
+ if (isNeg) {
332
+ const bits = len * 8;
333
+ const pow2 = (1n << BigInt(bits));
334
+ x = x - pow2; // two's complement
335
+ }
336
+ return x;
337
+ }
@@ -0,0 +1,165 @@
1
+ import { uint8, int16, uint16, int32, uint32, float32, float64 } from "./Int32.js";
2
+ import { int64, uint64 } from "./BigInt.js";
3
+ import { char } from "./Char.js";
4
+
5
+ const littleEndian = true;
6
+
7
+ export function isLittleEndian() {
8
+ return littleEndian;
9
+ }
10
+
11
+ export function getBytesBoolean(value: boolean) {
12
+ const bytes = new Uint8Array(1);
13
+ const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
14
+ view.setUint8(0, value ? 1 : 0);
15
+ return bytes;
16
+ }
17
+
18
+ export function getBytesChar(value: char) {
19
+ const bytes = new Uint8Array(2);
20
+ const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
21
+ view.setUint16(0, value.charCodeAt(0), littleEndian);
22
+ return bytes;
23
+ }
24
+
25
+ export function getBytesInt16(value: int16) {
26
+ const bytes = new Uint8Array(2);
27
+ const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
28
+ view.setInt16(0, value, littleEndian);
29
+ return bytes;
30
+ }
31
+
32
+ export function getBytesInt32(value: int32) {
33
+ const bytes = new Uint8Array(4);
34
+ const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
35
+ view.setInt32(0, value, littleEndian);
36
+ return bytes;
37
+ }
38
+
39
+ export function getBytesInt64(value: int64) {
40
+ const bytes = new Uint8Array(8);
41
+ const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
42
+ view.setBigInt64(0, value, littleEndian);
43
+ return bytes;
44
+ }
45
+
46
+ export function getBytesUInt16(value: uint16) {
47
+ const bytes = new Uint8Array(2);
48
+ const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
49
+ view.setUint16(0, value, littleEndian);
50
+ return bytes;
51
+ }
52
+
53
+ export function getBytesUInt32(value: uint32) {
54
+ const bytes = new Uint8Array(4);
55
+ const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
56
+ view.setUint32(0, value, littleEndian);
57
+ return bytes;
58
+ }
59
+
60
+ export function getBytesUInt64(value: uint64) {
61
+ const bytes = new Uint8Array(8);
62
+ const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
63
+ view.setBigUint64(0, value, littleEndian);
64
+ return bytes;
65
+ }
66
+
67
+ export function getBytesSingle(value: float32) {
68
+ const bytes = new Uint8Array(4);
69
+ const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
70
+ view.setFloat32(0, value, littleEndian);
71
+ return bytes;
72
+ }
73
+
74
+ export function getBytesDouble(value: float64) {
75
+ const bytes = new Uint8Array(8);
76
+ const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
77
+ view.setFloat64(0, value, littleEndian);
78
+ return bytes;
79
+ }
80
+
81
+ export function int64BitsToDouble(value: int64): float64 {
82
+ const buffer = new ArrayBuffer(8);
83
+ const view = new DataView(buffer);
84
+ view.setBigInt64(0, value, littleEndian);
85
+ return view.getFloat64(0, littleEndian);
86
+ }
87
+
88
+ export function doubleToInt64Bits(value: float64): int64 {
89
+ const buffer = new ArrayBuffer(8);
90
+ const view = new DataView(buffer);
91
+ view.setFloat64(0, value, littleEndian);
92
+ return view.getBigInt64(0, littleEndian);
93
+ }
94
+
95
+ export function toBoolean(bytes: ArrayLike<uint8>, offset: int32): boolean {
96
+ const array = ArrayBuffer.isView(bytes) ? bytes : Uint8Array.from(bytes);
97
+ const view = new DataView(array.buffer, array.byteOffset, array.byteLength);
98
+ return view.getUint8(offset) === 1 ? true : false;
99
+ }
100
+
101
+ export function toChar(bytes: ArrayLike<uint8>, offset: int32): char {
102
+ const array = ArrayBuffer.isView(bytes) ? bytes : Uint8Array.from(bytes);
103
+ const view = new DataView(array.buffer, array.byteOffset, array.byteLength);
104
+ const code = view.getUint16(offset, littleEndian);
105
+ return String.fromCharCode(code);
106
+ }
107
+
108
+ export function toInt16(bytes: ArrayLike<uint8>, offset: int32): int16 {
109
+ const array = ArrayBuffer.isView(bytes) ? bytes : Uint8Array.from(bytes);
110
+ const view = new DataView(array.buffer, array.byteOffset, array.byteLength);
111
+ return view.getInt16(offset, littleEndian);
112
+ }
113
+
114
+ export function toInt32(bytes: ArrayLike<uint8>, offset: int32): int32 {
115
+ const array = ArrayBuffer.isView(bytes) ? bytes : Uint8Array.from(bytes);
116
+ const view = new DataView(array.buffer, array.byteOffset, array.byteLength);
117
+ return view.getInt32(offset, littleEndian);
118
+ }
119
+
120
+ export function toInt64(bytes: ArrayLike<uint8>, offset: int32): int64 {
121
+ const array = ArrayBuffer.isView(bytes) ? bytes : Uint8Array.from(bytes);
122
+ const view = new DataView(array.buffer, array.byteOffset, array.byteLength);
123
+ return view.getBigInt64(offset, littleEndian);
124
+ }
125
+
126
+ export function toUInt16(bytes: ArrayLike<uint8>, offset: int32): uint16 {
127
+ const array = ArrayBuffer.isView(bytes) ? bytes : Uint8Array.from(bytes);
128
+ const view = new DataView(array.buffer, array.byteOffset, array.byteLength);
129
+ return view.getUint16(offset, littleEndian);
130
+ }
131
+
132
+ export function toUInt32(bytes: ArrayLike<uint8>, offset: int32): uint32 {
133
+ const array = ArrayBuffer.isView(bytes) ? bytes : Uint8Array.from(bytes);
134
+ const view = new DataView(array.buffer, array.byteOffset, array.byteLength);
135
+ return view.getUint32(offset, littleEndian);
136
+ }
137
+
138
+ export function toUInt64(bytes: ArrayLike<uint8>, offset: int32): uint64 {
139
+ const array = ArrayBuffer.isView(bytes) ? bytes : Uint8Array.from(bytes);
140
+ const view = new DataView(array.buffer, array.byteOffset, array.byteLength);
141
+ return view.getBigUint64(offset, littleEndian);
142
+ }
143
+
144
+ export function toSingle(bytes: ArrayLike<uint8>, offset: int32): float32 {
145
+ const array = ArrayBuffer.isView(bytes) ? bytes : Uint8Array.from(bytes);
146
+ const view = new DataView(array.buffer, array.byteOffset, array.byteLength);
147
+ return view.getFloat32(offset, littleEndian);
148
+ }
149
+
150
+ export function toDouble(bytes: ArrayLike<uint8>, offset: int32): float64 {
151
+ const array = ArrayBuffer.isView(bytes) ? bytes : Uint8Array.from(bytes);
152
+ const view = new DataView(array.buffer, array.byteOffset, array.byteLength);
153
+ return view.getFloat64(offset, littleEndian);
154
+ }
155
+
156
+ export function toString(bytes: ArrayLike<uint8>, offset?: int32, count?: int32): string {
157
+ const array = ArrayBuffer.isView(bytes) ? bytes : Uint8Array.from(bytes);
158
+ let buffer = new Uint8Array(array.buffer, array.byteOffset, array.byteLength);
159
+ if (offset != null && count != null) {
160
+ buffer = buffer.subarray(offset, offset + count);
161
+ } else if (offset != null) {
162
+ buffer = buffer.subarray(offset);
163
+ }
164
+ return Array.from(buffer).map((b) => ("0" + b.toString(16)).slice(-2)).join("-");
165
+ }
package/Boolean.ts ADDED
@@ -0,0 +1,22 @@
1
+ import { FSharpRef } from "./Types.js"
2
+
3
+ export function tryParse(str: string, defValue: FSharpRef<boolean>): boolean {
4
+ if (str.match(/^\s*true\s*$/i)) {
5
+ defValue.contents = true;
6
+ return true;
7
+ } else if (str.match(/^\s*false\s*$/i)) {
8
+ defValue.contents = false;
9
+ return true;
10
+ }
11
+ return false;
12
+ }
13
+
14
+ export function parse(str: string): boolean {
15
+ const defValue = new FSharpRef(false);
16
+
17
+ if (tryParse(str, defValue)) {
18
+ return defValue.contents;
19
+ } else {
20
+ throw new Error(`String '${str}' was not recognized as a valid Boolean.`)
21
+ }
22
+ }
package/CHANGELOG.md ADDED
@@ -0,0 +1,15 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## Unreleased
9
+
10
+ ## 1.0.0-beta-001 - 2024-02-12
11
+
12
+ ### Changed
13
+
14
+ * Separate `Result` from `Choice`
15
+ * Released as part of Fable 4.12.0