@fable-org/fable-library-js 1.10.0 → 2.0.0-beta.2

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.js CHANGED
@@ -183,7 +183,7 @@ export function where(predicate, array) {
183
183
  }
184
184
  export function indexOf(array, item_1, start, count, eq) {
185
185
  const start_1 = defaultArg(start, 0) | 0;
186
- const end$0027 = defaultArg(map_1((c) => (start_1 + c), count), array.length) | 0;
186
+ const end$0027 = defaultArg(map_1((c) => ((start_1 + c) | 0), count), array.length) | 0;
187
187
  const loop = (i_mut) => {
188
188
  loop: while (true) {
189
189
  const i = i_mut;
@@ -339,11 +339,11 @@ export function addRangeInPlace(range, array) {
339
339
  }
340
340
  }
341
341
  export function insertRangeInPlace(index, range, array) {
342
- let index_1;
343
342
  let i = index;
344
343
  const enumerator = getEnumerator(range);
345
344
  try {
346
345
  while (enumerator["System.Collections.IEnumerator.MoveNext"]()) {
346
+ let index_1;
347
347
  const x = enumerator["System.Collections.Generic.IEnumerator`1.get_Current"]();
348
348
  (index_1 = (i | 0), array.splice(index_1, 0, x));
349
349
  i = ((i + 1) | 0);
@@ -646,29 +646,29 @@ export function setSlice(target, lower, upper, source) {
646
646
  }
647
647
  }
648
648
  export function sortInPlaceBy(projection, xs, comparer) {
649
- xs.sort((x, y) => comparer.Compare(projection(x), projection(y)));
649
+ xs.sort((x, y) => (comparer.Compare(projection(x), projection(y)) | 0));
650
650
  }
651
651
  export function sortInPlace(xs, comparer) {
652
- xs.sort((x, y) => comparer.Compare(x, y));
652
+ xs.sort((x, y) => (comparer.Compare(x, y) | 0));
653
653
  }
654
654
  export function sort(xs, comparer) {
655
655
  const xs_1 = xs.slice();
656
- xs_1.sort((x, y) => comparer.Compare(x, y));
656
+ xs_1.sort((x, y) => (comparer.Compare(x, y) | 0));
657
657
  return xs_1;
658
658
  }
659
659
  export function sortBy(projection, xs, comparer) {
660
660
  const xs_1 = xs.slice();
661
- xs_1.sort((x, y) => comparer.Compare(projection(x), projection(y)));
661
+ xs_1.sort((x, y) => (comparer.Compare(projection(x), projection(y)) | 0));
662
662
  return xs_1;
663
663
  }
664
664
  export function sortDescending(xs, comparer) {
665
665
  const xs_1 = xs.slice();
666
- xs_1.sort((x, y) => (comparer.Compare(x, y) * -1));
666
+ xs_1.sort((x, y) => ((comparer.Compare(x, y) * -1) | 0));
667
667
  return xs_1;
668
668
  }
669
669
  export function sortByDescending(projection, xs, comparer) {
670
670
  const xs_1 = xs.slice();
671
- xs_1.sort((x, y) => (comparer.Compare(projection(x), projection(y)) * -1));
671
+ xs_1.sort((x, y) => ((comparer.Compare(projection(x), projection(y)) * -1) | 0));
672
672
  return xs_1;
673
673
  }
674
674
  export function sortWith(comparer, xs) {
package/Async.d.ts CHANGED
@@ -20,8 +20,7 @@ export declare function ignore<T>(computation: Async<T>): (ctx: IAsyncContext<un
20
20
  export declare function parallel<T>(computations: Iterable<Async<T>>): (ctx: IAsyncContext<Awaited<T>[]>) => void;
21
21
  export declare function sequential<T>(computations: Iterable<Async<T>>): (ctx: IAsyncContext<T[]>) => void;
22
22
  export declare function sleep(millisecondsDueTime: number): (ctx: IAsyncContext<void>) => void;
23
- export declare function runSynchronously(): never;
24
23
  export declare function start<T>(computation: Async<T>, cancellationToken?: CancellationToken): void;
25
24
  export declare function startImmediate<T>(computation: Async<T>, cancellationToken?: CancellationToken): void;
26
- export declare function startWithContinuations<T>(computation: Async<T>, continuation?: Continuation<T> | CancellationToken, exceptionContinuation?: Continuation<any>, cancellationContinuation?: Continuation<any>, cancelToken?: CancellationToken): void;
25
+ export declare function startWithContinuations<T>(computation: Async<T>, continuation: Continuation<T>, exceptionContinuation: Continuation<any>, cancellationContinuation: Continuation<any>, cancelToken?: CancellationToken): void;
27
26
  export declare function startAsPromise<T>(computation: Async<T>, cancellationToken?: CancellationToken): Promise<T>;
package/Async.js CHANGED
@@ -124,25 +124,18 @@ export function sleep(millisecondsDueTime) {
124
124
  });
125
125
  });
126
126
  }
127
- export function runSynchronously() {
128
- throw new Error("Asynchronous code cannot be run synchronously in JS");
129
- }
130
127
  export function start(computation, cancellationToken) {
131
- return startWithContinuations(computation, cancellationToken);
128
+ return startWithContinuations(computation, emptyContinuation, function (err) { throw err; }, emptyContinuation, cancellationToken);
132
129
  }
133
130
  export function startImmediate(computation, cancellationToken) {
134
131
  return start(computation, cancellationToken);
135
132
  }
136
133
  export function startWithContinuations(computation, continuation, exceptionContinuation, cancellationContinuation, cancelToken) {
137
- if (typeof continuation !== "function") {
138
- cancelToken = continuation;
139
- continuation = undefined;
140
- }
141
134
  const trampoline = new Trampoline();
142
135
  computation({
143
136
  onSuccess: continuation ? continuation : emptyContinuation,
144
- onError: exceptionContinuation ? exceptionContinuation : emptyContinuation,
145
- onCancel: cancellationContinuation ? cancellationContinuation : emptyContinuation,
137
+ onError: exceptionContinuation,
138
+ onCancel: cancellationContinuation,
146
139
  cancelToken: cancelToken ? cancelToken : defaultCancellationToken,
147
140
  trampoline,
148
141
  });
package/BigInt.d.ts CHANGED
@@ -80,6 +80,8 @@ export declare function fromChar(c: string): bigint;
80
80
  export declare function fromString(s: string): bigint;
81
81
  export declare function fromByteArray(bytes: ArrayLike<uint8>): bigint;
82
82
  export declare function toByteArray(value: bigint): number[];
83
+ export declare function toIntN_unchecked(bits: number, x: bigint, signed: boolean): bigint;
84
+ export declare function toIntN(bits: number, x: bigint, signed: boolean): bigint;
83
85
  export declare function toInt8(x: bigint): int8;
84
86
  export declare function toUInt8(x: bigint): uint8;
85
87
  export declare function toInt16(x: bigint): int16;
@@ -92,7 +94,19 @@ export declare function toInt128(x: bigint): int128;
92
94
  export declare function toUInt128(x: bigint): uint128;
93
95
  export declare function toNativeInt(x: bigint): nativeint;
94
96
  export declare function toUNativeInt(x: bigint): unativeint;
95
- export declare function toFloat16(x: bigint): float32;
97
+ export declare function toInt8_unchecked(x: bigint): int8;
98
+ export declare function toUInt8_unchecked(x: bigint): uint8;
99
+ export declare function toInt16_unchecked(x: bigint): int16;
100
+ export declare function toUInt16_unchecked(x: bigint): uint16;
101
+ export declare function toInt32_unchecked(x: bigint): int32;
102
+ export declare function toUInt32_unchecked(x: bigint): uint32;
103
+ export declare function toInt64_unchecked(x: bigint): int64;
104
+ export declare function toUInt64_unchecked(x: bigint): uint64;
105
+ export declare function toInt128_unchecked(x: bigint): int128;
106
+ export declare function toUInt128_unchecked(x: bigint): uint128;
107
+ export declare function toNativeInt_unchecked(x: bigint): nativeint;
108
+ export declare function toUNativeInt_unchecked(x: bigint): unativeint;
109
+ export declare function toFloat16(x: bigint): float16;
96
110
  export declare function toFloat32(x: bigint): float32;
97
111
  export declare function toFloat64(x: bigint): float64;
98
112
  export declare function toDecimal(x: bigint): decimal;
package/BigInt.js CHANGED
@@ -95,18 +95,41 @@ export function fromByteArray(bytes) {
95
95
  export function toByteArray(value) {
96
96
  return toSignedBytes(value, isBigEndian);
97
97
  }
98
- export function toInt8(x) { return Number(BigInt.asIntN(8, x)); }
99
- export function toUInt8(x) { return Number(BigInt.asUintN(8, x)); }
100
- export function toInt16(x) { return Number(BigInt.asIntN(16, x)); }
101
- export function toUInt16(x) { return Number(BigInt.asUintN(16, x)); }
102
- export function toInt32(x) { return Number(BigInt.asIntN(32, x)); }
103
- export function toUInt32(x) { return Number(BigInt.asUintN(32, x)); }
104
- export function toInt64(x) { return BigInt.asIntN(64, x); }
105
- export function toUInt64(x) { return BigInt.asUintN(64, x); }
106
- export function toInt128(x) { return BigInt.asIntN(128, x); }
107
- export function toUInt128(x) { return BigInt.asUintN(128, x); }
108
- export function toNativeInt(x) { return BigInt.asIntN(64, x); }
109
- export function toUNativeInt(x) { return BigInt.asUintN(64, x); }
98
+ export function toIntN_unchecked(bits, x, signed) {
99
+ return signed ? BigInt.asIntN(bits, x) : BigInt.asUintN(bits, x);
100
+ }
101
+ export function toIntN(bits, x, signed) {
102
+ let higher_bits = abs(x) >> BigInt(bits);
103
+ if (higher_bits !== 0n) {
104
+ const s = signed ? "a signed" : "an unsigned";
105
+ throw new Error(`Value was either too large or too small for ${s} ${bits}-bit integer.`);
106
+ }
107
+ return signed ? BigInt.asIntN(bits, x) : BigInt.asUintN(bits, x);
108
+ }
109
+ export function toInt8(x) { return Number(toIntN(8, x, true)); }
110
+ export function toUInt8(x) { return Number(toIntN(8, x, false)); }
111
+ export function toInt16(x) { return Number(toIntN(16, x, true)); }
112
+ export function toUInt16(x) { return Number(toIntN(16, x, false)); }
113
+ export function toInt32(x) { return Number(toIntN(32, x, true)); }
114
+ export function toUInt32(x) { return Number(toIntN(32, x, false)); }
115
+ export function toInt64(x) { return toIntN(64, x, true); }
116
+ export function toUInt64(x) { return toIntN(64, x, false); }
117
+ export function toInt128(x) { return toIntN(128, x, true); }
118
+ export function toUInt128(x) { return toIntN(128, x, false); }
119
+ export function toNativeInt(x) { return toIntN(64, x, true); }
120
+ export function toUNativeInt(x) { return toIntN(64, x, false); }
121
+ export function toInt8_unchecked(x) { return Number(toIntN_unchecked(8, x, true)); }
122
+ export function toUInt8_unchecked(x) { return Number(toIntN_unchecked(8, x, false)); }
123
+ export function toInt16_unchecked(x) { return Number(toIntN_unchecked(16, x, true)); }
124
+ export function toUInt16_unchecked(x) { return Number(toIntN_unchecked(16, x, false)); }
125
+ export function toInt32_unchecked(x) { return Number(toIntN_unchecked(32, x, true)); }
126
+ export function toUInt32_unchecked(x) { return Number(toIntN_unchecked(32, x, false)); }
127
+ export function toInt64_unchecked(x) { return toIntN_unchecked(64, x, true); }
128
+ export function toUInt64_unchecked(x) { return toIntN_unchecked(64, x, false); }
129
+ export function toInt128_unchecked(x) { return toIntN_unchecked(128, x, true); }
130
+ export function toUInt128_unchecked(x) { return toIntN_unchecked(128, x, false); }
131
+ export function toNativeInt_unchecked(x) { return toIntN_unchecked(64, x, true); }
132
+ export function toUNativeInt_unchecked(x) { return toIntN_unchecked(64, x, false); }
110
133
  export function toFloat16(x) { return Number(x); }
111
134
  export function toFloat32(x) { return Number(x); }
112
135
  export function toFloat64(x) { return Number(x); }
package/CHANGELOG.md CHANGED
@@ -7,6 +7,23 @@ 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.2 - 2025-03-03
11
+
12
+ * [JS/TS] Fix #4049: decimal/bigint to integer conversion checks (by @ncave)
13
+ * [JS/TS] Fix `decimal` to `char` conversion checks (by @ManngelMaxime)
14
+ * [JS/TS] Propagate non-captured exception when running `Async.Start` or `Async.StartImmediate` (by @MangelMaxime)
15
+ * [JS/TS] Remove `Async.RunSynchronously` (by @MangelMaxime)
16
+ * [JS/TS] Change signature of `startWithContinuations` to always require all its arguments (by @MangelMaxime)
17
+ * [JS/TS] Fix short `DateTime` and `DateTimeOffset` short format strings (by @MangelMaxime)
18
+ * [JS/TS] Add `C` and `c` format for numeric types (by @MangelMaxime)
19
+ * [JS/TS] Add `B` and `b` format for numeric types (by @MangelMaxime)
20
+ * [JS/TS] Add `n` format for numeric types (by @MangelMaxime)
21
+ * [JS/TS] Fix numeric formats (by @MangelMaxime)
22
+
23
+ ## 2.0.0-beta.1 - 2025-02-16
24
+
25
+ * Compiled with Fable 5.0.0-alpha.10
26
+
10
27
  ## 1.10.0 - 2025-01-23
11
28
 
12
29
  ### Added
@@ -55,7 +72,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
55
72
 
56
73
  * [JS/TS] Fix escaping of `{` and `}` in FormattableString (#3890) (by @roboz0r)
57
74
  * [JS/TS] Fix `uri.Host` to return the host name without the port (by @MangelMaxime)
58
- * [JS/TS] Fix TypeScript compilation by resolving type of `jsOptions` (#3894) (by @ManngelMaxime)
75
+ * [JS/TS] Fix TypeScript compilation by resolving type of `jsOptions` (#3894) (by @MangelMaxime)
59
76
 
60
77
  ## 1.4.3 - 2024-09-04
61
78
 
package/Date.d.ts CHANGED
@@ -16,7 +16,6 @@ export declare function kind(value: IDateTime): number;
16
16
  export declare function unixEpochMillisecondsToTicks(ms: number, offset: number): int64;
17
17
  export declare function ticksToUnixEpochMilliseconds(ticks: number | bigint): number;
18
18
  export declare function dateOffsetToString(offset: number): string;
19
- export declare function dateToHalfUTCString(date: IDateTime, half: "first" | "second"): string;
20
19
  export declare function toString(date: IDateTime | IDateTimeOffset, format?: string, _provider?: any): string;
21
20
  export declare function DateTime(value: number, kind?: DateKind): IDateTime;
22
21
  export declare function fromTicks(ticks: number | bigint, kind?: DateKind): IDateTime;
package/Date.js CHANGED
@@ -91,9 +91,8 @@ function dateToStringWithCustomFormat(date, format, utc) {
91
91
  result += shortDays[dayOfWeek(localizedDate)];
92
92
  break;
93
93
  case 4:
94
- result += longDays[dayOfWeek(localizedDate)];
95
- break;
96
94
  default:
95
+ result += longDays[dayOfWeek(localizedDate)];
97
96
  break;
98
97
  }
99
98
  break;
@@ -112,6 +111,9 @@ function dateToStringWithCustomFormat(date, format, utc) {
112
111
  // DateTime(1, 2, 3, 4, 5, 6, DateTimeKind.Utc).ToString("fffff") => 00000
113
112
  result += ("" + millisecond(localizedDate)).padEnd(tokenLength, "0");
114
113
  }
114
+ else {
115
+ throw "Input string was not in a correct format.";
116
+ }
115
117
  break;
116
118
  case "F":
117
119
  tokenLength = parseRepeatToken(format, cursorPos, "F");
@@ -132,13 +134,14 @@ function dateToStringWithCustomFormat(date, format, utc) {
132
134
  result += padWithZeros(value, 3);
133
135
  }
134
136
  }
137
+ else {
138
+ throw "Input string was not in a correct format.";
139
+ }
135
140
  break;
136
141
  case "g":
137
142
  tokenLength = parseRepeatToken(format, cursorPos, "g");
138
143
  cursorPos += tokenLength;
139
- if (tokenLength <= 2) {
140
- result += "A.D.";
141
- }
144
+ result += "A.D.";
142
145
  break;
143
146
  case "h":
144
147
  tokenLength = parseRepeatToken(format, cursorPos, "h");
@@ -149,11 +152,10 @@ function dateToStringWithCustomFormat(date, format, utc) {
149
152
  result += h1Value ? h1Value : 12;
150
153
  break;
151
154
  case 2:
155
+ default:
152
156
  const h2Value = hour(localizedDate) % 12;
153
157
  result += padWithZeros(h2Value ? h2Value : 12, 2);
154
158
  break;
155
- default:
156
- break;
157
159
  }
158
160
  break;
159
161
  case "H":
@@ -164,9 +166,8 @@ function dateToStringWithCustomFormat(date, format, utc) {
164
166
  result += hour(localizedDate);
165
167
  break;
166
168
  case 2:
167
- result += padWithZeros(hour(localizedDate), 2);
168
- break;
169
169
  default:
170
+ result += padWithZeros(hour(localizedDate), 2);
170
171
  break;
171
172
  }
172
173
  break;
@@ -198,9 +199,8 @@ function dateToStringWithCustomFormat(date, format, utc) {
198
199
  result += minute(localizedDate);
199
200
  break;
200
201
  case 2:
201
- result += padWithZeros(minute(localizedDate), 2);
202
- break;
203
202
  default:
203
+ result += padWithZeros(minute(localizedDate), 2);
204
204
  break;
205
205
  }
206
206
  break;
@@ -218,9 +218,8 @@ function dateToStringWithCustomFormat(date, format, utc) {
218
218
  result += shortMonths[month(localizedDate) - 1];
219
219
  break;
220
220
  case 4:
221
- result += longMonths[month(localizedDate) - 1];
222
- break;
223
221
  default:
222
+ result += longMonths[month(localizedDate) - 1];
224
223
  break;
225
224
  }
226
225
  break;
@@ -232,9 +231,8 @@ function dateToStringWithCustomFormat(date, format, utc) {
232
231
  result += second(localizedDate);
233
232
  break;
234
233
  case 2:
235
- result += padWithZeros(second(localizedDate), 2);
236
- break;
237
234
  default:
235
+ result += padWithZeros(second(localizedDate), 2);
238
236
  break;
239
237
  }
240
238
  break;
@@ -246,9 +244,8 @@ function dateToStringWithCustomFormat(date, format, utc) {
246
244
  result += localizedDate.getHours() < 12 ? "A" : "P";
247
245
  break;
248
246
  case 2:
249
- result += localizedDate.getHours() < 12 ? "AM" : "PM";
250
- break;
251
247
  default:
248
+ result += localizedDate.getHours() < 12 ? "AM" : "PM";
252
249
  break;
253
250
  }
254
251
  break;
@@ -262,16 +259,8 @@ function dateToStringWithCustomFormat(date, format, utc) {
262
259
  case 2:
263
260
  result += padWithZeros(localizedDate.getFullYear() % 100, 2);
264
261
  break;
265
- case 3:
266
- result += padWithZeros(localizedDate.getFullYear(), 3);
267
- break;
268
- case 4:
269
- result += padWithZeros(localizedDate.getFullYear(), 4);
270
- break;
271
- case 5:
272
- result += padWithZeros(localizedDate.getFullYear(), 5);
273
- break;
274
262
  default:
263
+ result += padWithZeros(localizedDate.getFullYear(), tokenLength);
275
264
  break;
276
265
  }
277
266
  break;
@@ -365,12 +354,6 @@ export function dateOffsetToString(offset) {
365
354
  padWithZeros(hours, 2) + ":" +
366
355
  padWithZeros(minutes, 2);
367
356
  }
368
- export function dateToHalfUTCString(date, half) {
369
- const str = date.toISOString();
370
- return half === "first"
371
- ? str.substring(0, str.indexOf("T"))
372
- : str.substring(str.indexOf("T") + 1, str.length - 1);
373
- }
374
357
  function dateToISOString(d, utc) {
375
358
  if (utc) {
376
359
  return d.toISOString();
@@ -399,10 +382,10 @@ function dateToStringWithOffset(date, format) {
399
382
  }
400
383
  else if (format.length === 1) {
401
384
  switch (format) {
402
- case "D":
403
- case "d": return dateToHalfUTCString(d, "first");
404
- case "T":
405
- case "t": return dateToHalfUTCString(d, "second");
385
+ case "D": return dateToString_D(d);
386
+ case "d": return dateToString_d(d);
387
+ case "T": return dateToString_T(toUniversalTime(d));
388
+ case "t": return dateToString_t(toUniversalTime(d));
406
389
  case "O":
407
390
  case "o": return dateToISOStringWithOffset(d, (date.offset ?? 0));
408
391
  default: throw new Error("Unrecognized Date print format");
@@ -412,6 +395,26 @@ function dateToStringWithOffset(date, format) {
412
395
  return dateToStringWithCustomFormat(d, format, true);
413
396
  }
414
397
  }
398
+ function dateToString_D(date) {
399
+ return longDays[dayOfWeek(date)]
400
+ + ", " + padWithZeros(day(date), 2)
401
+ + " " + longMonths[month(date) - 1]
402
+ + " " + year(date);
403
+ }
404
+ function dateToString_d(date) {
405
+ return padWithZeros(month(date), 2)
406
+ + "/" + padWithZeros(day(date), 2)
407
+ + "/" + year(date);
408
+ }
409
+ function dateToString_T(date) {
410
+ return padWithZeros(hour(date), 2)
411
+ + ":" + padWithZeros(minute(date), 2)
412
+ + ":" + padWithZeros(second(date), 2);
413
+ }
414
+ function dateToString_t(date) {
415
+ return padWithZeros(hour(date), 2)
416
+ + ":" + padWithZeros(minute(date), 2);
417
+ }
415
418
  function dateToStringWithKind(date, format) {
416
419
  const utc = date.kind === 1 /* DateKind.UTC */;
417
420
  if (typeof format !== "string") {
@@ -419,12 +422,10 @@ function dateToStringWithKind(date, format) {
419
422
  }
420
423
  else if (format.length === 1) {
421
424
  switch (format) {
422
- case "D":
423
- case "d":
424
- return utc ? dateToHalfUTCString(date, "first") : date.toLocaleDateString();
425
- case "T":
426
- case "t":
427
- return utc ? dateToHalfUTCString(date, "second") : date.toLocaleTimeString();
425
+ case "D": return dateToString_D(date);
426
+ case "d": return dateToString_d(date);
427
+ case "T": return dateToString_T(date);
428
+ case "t": return dateToString_t(date);
428
429
  case "O":
429
430
  case "o":
430
431
  return dateToISOString(date, utc);
package/Decimal.d.ts CHANGED
@@ -1,5 +1,7 @@
1
1
  import Decimal from "./lib/big.js";
2
2
  import { FSharpRef } from "./Types.js";
3
+ import { int8, uint8, int16, uint16, int32, uint32, float16, float32, float64 } from "./Int32.js";
4
+ import { int64, uint64, int128, uint128, nativeint, unativeint } from "./BigInt.js";
3
5
  export default Decimal;
4
6
  export type decimal = Decimal;
5
7
  export declare const get_Zero: Decimal;
@@ -39,6 +41,22 @@ export declare function toString(x: Decimal): string;
39
41
  export declare function tryParse(str: string, defValue: FSharpRef<Decimal>): boolean;
40
42
  export declare function parse(str: string): Decimal;
41
43
  export declare function toNumber(x: Decimal): number;
44
+ export declare function toChar(x: Decimal): string;
45
+ export declare function toInt8(x: Decimal): int8;
46
+ export declare function toUInt8(x: Decimal): uint8;
47
+ export declare function toInt16(x: Decimal): int16;
48
+ export declare function toUInt16(x: Decimal): uint16;
49
+ export declare function toInt32(x: Decimal): int32;
50
+ export declare function toUInt32(x: Decimal): uint32;
51
+ export declare function toInt64(x: Decimal): int64;
52
+ export declare function toUInt64(x: Decimal): uint64;
53
+ export declare function toInt128(x: Decimal): int128;
54
+ export declare function toUInt128(x: Decimal): uint128;
55
+ export declare function toNativeInt(x: Decimal): nativeint;
56
+ export declare function toUNativeInt(x: Decimal): unativeint;
57
+ export declare function toFloat16(x: Decimal): float16;
58
+ export declare function toFloat32(x: Decimal): float32;
59
+ export declare function toFloat64(x: Decimal): float64;
42
60
  export declare function fromIntArray(bits: ArrayLike<number>): Decimal;
43
61
  export declare function fromInts(low: number, mid: number, high: number, signExp: number): Decimal;
44
62
  export declare function fromParts(low: number, mid: number, high: number, isNegative: boolean, scale: number): Decimal;
package/Decimal.js CHANGED
@@ -2,6 +2,8 @@ import Decimal from "./lib/big.js";
2
2
  import { symbol } from "./Numeric.js";
3
3
  import { FSharpRef } from "./Types.js";
4
4
  import { combineHashCodes } from "./Util.js";
5
+ import { fromDecimal } from "./BigInt.js";
6
+ import * as bigInt from "./BigInt.js";
5
7
  Decimal.prototype.GetHashCode = function () {
6
8
  return combineHashCodes([this.s, this.e].concat(this.c));
7
9
  };
@@ -113,6 +115,28 @@ export function parse(str) {
113
115
  export function toNumber(x) {
114
116
  return +x;
115
117
  }
118
+ export function toChar(x) {
119
+ const n = toNumber(x);
120
+ if (n < 0 || n > 65535 || isNaN(n)) {
121
+ throw new Error("Value was either too large or too small for a character.");
122
+ }
123
+ return String.fromCharCode(n);
124
+ }
125
+ export function toInt8(x) { return bigInt.toInt8(fromDecimal(x)); }
126
+ export function toUInt8(x) { return bigInt.toUInt8(fromDecimal(x)); }
127
+ export function toInt16(x) { return bigInt.toInt16(fromDecimal(x)); }
128
+ export function toUInt16(x) { return bigInt.toUInt16(fromDecimal(x)); }
129
+ export function toInt32(x) { return bigInt.toInt32(fromDecimal(x)); }
130
+ export function toUInt32(x) { return bigInt.toUInt32(fromDecimal(x)); }
131
+ export function toInt64(x) { return bigInt.toInt64(fromDecimal(x)); }
132
+ export function toUInt64(x) { return bigInt.toUInt64(fromDecimal(x)); }
133
+ export function toInt128(x) { return bigInt.toInt128(fromDecimal(x)); }
134
+ export function toUInt128(x) { return bigInt.toUInt128(fromDecimal(x)); }
135
+ export function toNativeInt(x) { return bigInt.toNativeInt(fromDecimal(x)); }
136
+ export function toUNativeInt(x) { return bigInt.toUNativeInt(fromDecimal(x)); }
137
+ export function toFloat16(x) { return toNumber(x); }
138
+ export function toFloat32(x) { return toNumber(x); }
139
+ export function toFloat64(x) { return toNumber(x); }
116
140
  function decimalToHex(dec, bitSize) {
117
141
  const hex = new Uint8Array(bitSize / 4 | 0);
118
142
  let hexCount = 1;
@@ -5,23 +5,23 @@ export function HashIdentity_FromFunctions(hash, eq) {
5
5
  return eq(x, y);
6
6
  },
7
7
  GetHashCode(x_1) {
8
- return hash(x_1);
8
+ return hash(x_1) | 0;
9
9
  },
10
10
  };
11
11
  }
12
12
  export function HashIdentity_Structural() {
13
- return HashIdentity_FromFunctions(structuralHash, equals);
13
+ return HashIdentity_FromFunctions((obj) => (structuralHash(obj) | 0), equals);
14
14
  }
15
15
  export function HashIdentity_Reference() {
16
- return HashIdentity_FromFunctions(physicalHash, (e, e_1) => (e === e_1));
16
+ return HashIdentity_FromFunctions((obj) => (physicalHash(obj) | 0), (e, e_1) => (e === e_1));
17
17
  }
18
18
  export function ComparisonIdentity_FromFunction(comparer) {
19
19
  return {
20
20
  Compare(x, y) {
21
- return comparer(x, y);
21
+ return comparer(x, y) | 0;
22
22
  },
23
23
  };
24
24
  }
25
25
  export function ComparisonIdentity_Structural() {
26
- return ComparisonIdentity_FromFunction(compare);
26
+ return ComparisonIdentity_FromFunction((e, e_1) => (compare(e, e_1) | 0));
27
27
  }
package/FSharp.Core.js CHANGED
@@ -8,7 +8,7 @@ export const LanguagePrimitives_GenericEqualityComparer = {
8
8
  return equals(x, y);
9
9
  },
10
10
  "System.Collections.IEqualityComparer.GetHashCode4E60E31B"(x_1) {
11
- return structuralHash(x_1);
11
+ return structuralHash(x_1) | 0;
12
12
  },
13
13
  };
14
14
  export const LanguagePrimitives_GenericEqualityERComparer = {
@@ -16,7 +16,7 @@ export const LanguagePrimitives_GenericEqualityERComparer = {
16
16
  return equals(x, y);
17
17
  },
18
18
  "System.Collections.IEqualityComparer.GetHashCode4E60E31B"(x_1) {
19
- return structuralHash(x_1);
19
+ return structuralHash(x_1) | 0;
20
20
  },
21
21
  };
22
22
  export function LanguagePrimitives_FastGenericComparer() {
package/List.d.ts CHANGED
@@ -56,7 +56,7 @@ export declare function foldBack<T, State>(folder: ((arg0: T, arg1: State) => St
56
56
  export declare function foldIndexed<State, T>(folder: ((arg0: int32, arg1: State, arg2: T) => State), state: State, xs: FSharpList<T>): State;
57
57
  export declare function fold2<T1, T2, State>(folder: ((arg0: State, arg1: T1, arg2: T2) => State), state: State, xs: FSharpList<T1>, ys: FSharpList<T2>): State;
58
58
  export declare function foldBack2<T1, T2, State>(folder: ((arg0: T1, arg1: T2, arg2: State) => State), xs: FSharpList<T1>, ys: FSharpList<T2>, state: State): State;
59
- export declare function unfold<State, T>(gen: ((arg0: State) => Option<[T, State]>), state: State): FSharpList<T>;
59
+ export declare function unfold<State, T>(generator: ((arg0: State) => Option<[T, State]>), state: State): FSharpList<T>;
60
60
  export declare function iterate<$a>(action: ((arg0: $a) => void), xs: FSharpList<$a>): void;
61
61
  export declare function iterate2<$a, $b>(action: ((arg0: $a, arg1: $b) => void), xs: FSharpList<$a>, ys: FSharpList<$b>): void;
62
62
  export declare function iterateIndexed<$a>(action: ((arg0: int32, arg1: $a) => void), xs: FSharpList<$a>): void;
package/List.js CHANGED
@@ -261,7 +261,7 @@ export function isEmpty(xs) {
261
261
  return FSharpList__get_IsEmpty(xs);
262
262
  }
263
263
  export function length(xs) {
264
- return FSharpList__get_Length(xs);
264
+ return FSharpList__get_Length(xs) | 0;
265
265
  }
266
266
  export function head(xs) {
267
267
  return FSharpList__get_Head(xs);
@@ -403,12 +403,12 @@ export function fold2(folder, state, xs, ys) {
403
403
  export function foldBack2(folder, xs, ys, state) {
404
404
  return foldBack2_1(folder, toArray(xs), toArray(ys), state);
405
405
  }
406
- export function unfold(gen, state) {
406
+ export function unfold(generator, state) {
407
407
  const loop = (acc_mut, node_mut) => {
408
- let t;
409
408
  loop: while (true) {
410
409
  const acc = acc_mut, node = node_mut;
411
- const matchValue = gen(acc);
410
+ let t;
411
+ const matchValue = generator(acc);
412
412
  if (matchValue != null) {
413
413
  acc_mut = value_1(matchValue)[1];
414
414
  node_mut = ((t = (new FSharpList(value_1(matchValue)[0], undefined)), (node.tail = t, t)));
@@ -462,7 +462,6 @@ export function ofArray(xs) {
462
462
  return ofArrayWithTail(xs, FSharpList_get_Empty());
463
463
  }
464
464
  export function ofSeq(xs) {
465
- let xs_3, t;
466
465
  if (isArrayLike(xs)) {
467
466
  return ofArray(xs);
468
467
  }
@@ -475,6 +474,7 @@ export function ofSeq(xs) {
475
474
  const enumerator = getEnumerator(xs);
476
475
  try {
477
476
  while (enumerator["System.Collections.IEnumerator.MoveNext"]()) {
477
+ let xs_3, t;
478
478
  const x = enumerator["System.Collections.Generic.IEnumerator`1.get_Current"]();
479
479
  node = ((xs_3 = node, (t = (new FSharpList(x, undefined)), (xs_3.tail = t, t))));
480
480
  }
@@ -522,7 +522,6 @@ export function concat(lists) {
522
522
  return FSharpList__get_Tail(root);
523
523
  }
524
524
  export function scan(folder, state, xs) {
525
- let xs_4, t_2;
526
525
  const root = FSharpList_get_Empty();
527
526
  let node;
528
527
  const t = new FSharpList(state, undefined);
@@ -531,6 +530,7 @@ export function scan(folder, state, xs) {
531
530
  let acc = state;
532
531
  let xs_3 = xs;
533
532
  while (!FSharpList__get_IsEmpty(xs_3)) {
533
+ let xs_4, t_2;
534
534
  acc = folder(acc, FSharpList__get_Head(xs_3));
535
535
  node = ((xs_4 = node, (t_2 = (new FSharpList(acc, undefined)), (xs_4.tail = t_2, t_2))));
536
536
  xs_3 = FSharpList__get_Tail(xs_3);
@@ -547,13 +547,13 @@ export function append(xs, ys) {
547
547
  return fold((acc, x) => FSharpList_Cons_305B8EAC(x, acc), ys, reverse(xs));
548
548
  }
549
549
  export function collect(mapping, xs) {
550
- let xs_1, t;
551
550
  const root = FSharpList_get_Empty();
552
551
  let node = root;
553
552
  let ys = xs;
554
553
  while (!FSharpList__get_IsEmpty(ys)) {
555
554
  let zs = mapping(FSharpList__get_Head(ys));
556
555
  while (!FSharpList__get_IsEmpty(zs)) {
556
+ let xs_1, t;
557
557
  node = ((xs_1 = node, (t = (new FSharpList(FSharpList__get_Head(zs), undefined)), (xs_1.tail = t, t))));
558
558
  zs = FSharpList__get_Tail(zs);
559
559
  }
@@ -602,9 +602,9 @@ export function map2(mapping, xs, ys) {
602
602
  }
603
603
  export function mapIndexed2(mapping, xs, ys) {
604
604
  const loop = (i_mut, acc_mut, xs_1_mut, ys_1_mut) => {
605
- let t;
606
605
  loop: while (true) {
607
606
  const i = i_mut, acc = acc_mut, xs_1 = xs_1_mut, ys_1 = ys_1_mut;
607
+ let t;
608
608
  if (FSharpList__get_IsEmpty(xs_1) ? true : FSharpList__get_IsEmpty(ys_1)) {
609
609
  return acc;
610
610
  }
@@ -626,9 +626,9 @@ export function mapIndexed2(mapping, xs, ys) {
626
626
  }
627
627
  export function map3(mapping, xs, ys, zs) {
628
628
  const loop = (acc_mut, xs_1_mut, ys_1_mut, zs_1_mut) => {
629
- let t;
630
629
  loop: while (true) {
631
630
  const acc = acc_mut, xs_1 = xs_1_mut, ys_1 = ys_1_mut, zs_1 = zs_1_mut;
631
+ let t;
632
632
  if ((FSharpList__get_IsEmpty(xs_1) ? true : FSharpList__get_IsEmpty(ys_1)) ? true : FSharpList__get_IsEmpty(zs_1)) {
633
633
  return acc;
634
634
  }
@@ -841,10 +841,10 @@ export function contains(value, xs, eq) {
841
841
  return tryFindIndex((v) => eq.Equals(value, v), xs) != null;
842
842
  }
843
843
  export function initialize(n, f) {
844
- let xs, t;
845
844
  const root = FSharpList_get_Empty();
846
845
  let node = root;
847
846
  for (let i = 0; i <= (n - 1); i++) {
847
+ let xs, t;
848
848
  node = ((xs = node, (t = (new FSharpList(f(i), undefined)), (xs.tail = t, t))));
849
849
  }
850
850
  const xs_2 = node;
@@ -937,16 +937,16 @@ export function sortWith(comparer, xs) {
937
937
  return ofArray(arr);
938
938
  }
939
939
  export function sort(xs, comparer) {
940
- return sortWith((x, y) => comparer.Compare(x, y), xs);
940
+ return sortWith((x, y) => (comparer.Compare(x, y) | 0), xs);
941
941
  }
942
942
  export function sortBy(projection, xs, comparer) {
943
- return sortWith((x, y) => comparer.Compare(projection(x), projection(y)), xs);
943
+ return sortWith((x, y) => (comparer.Compare(projection(x), projection(y)) | 0), xs);
944
944
  }
945
945
  export function sortDescending(xs, comparer) {
946
- return sortWith((x, y) => (comparer.Compare(x, y) * -1), xs);
946
+ return sortWith((x, y) => ((comparer.Compare(x, y) * -1) | 0), xs);
947
947
  }
948
948
  export function sortByDescending(projection, xs, comparer) {
949
- return sortWith((x, y) => (comparer.Compare(projection(x), projection(y)) * -1), xs);
949
+ return sortWith((x, y) => ((comparer.Compare(projection(x), projection(y)) * -1) | 0), xs);
950
950
  }
951
951
  export function sum(xs, adder) {
952
952
  return fold((acc, x) => adder.Add(acc, x), adder.GetZero(), xs);
@@ -1041,9 +1041,9 @@ export function take(count, xs) {
1041
1041
  throw new Error((SR_inputMustBeNonNegative + "\\nParameter name: ") + "count");
1042
1042
  }
1043
1043
  const loop = (i_mut, acc_mut, xs_1_mut) => {
1044
- let t;
1045
1044
  loop: while (true) {
1046
1045
  const i = i_mut, acc = acc_mut, xs_1 = xs_1_mut;
1046
+ let t;
1047
1047
  if (i <= 0) {
1048
1048
  return acc;
1049
1049
  }
@@ -1067,9 +1067,9 @@ export function take(count, xs) {
1067
1067
  }
1068
1068
  export function takeWhile(predicate, xs) {
1069
1069
  const loop = (acc_mut, xs_1_mut) => {
1070
- let t;
1071
1070
  loop: while (true) {
1072
1071
  const acc = acc_mut, xs_1 = xs_1_mut;
1072
+ let t;
1073
1073
  if (FSharpList__get_IsEmpty(xs_1)) {
1074
1074
  return acc;
1075
1075
  }
@@ -1092,9 +1092,9 @@ export function takeWhile(predicate, xs) {
1092
1092
  }
1093
1093
  export function truncate(count, xs) {
1094
1094
  const loop = (i_mut, acc_mut, xs_1_mut) => {
1095
- let t;
1096
1095
  loop: while (true) {
1097
1096
  const i = i_mut, acc = acc_mut, xs_1 = xs_1_mut;
1097
+ let t;
1098
1098
  if (i <= 0) {
1099
1099
  return acc;
1100
1100
  }
package/Map.js CHANGED
@@ -45,7 +45,7 @@ export function MapTreeNode$2__get_Right(_) {
45
45
  return _.right;
46
46
  }
47
47
  export function MapTreeNode$2__get_Height(_) {
48
- return _.h;
48
+ return _.h | 0;
49
49
  }
50
50
  export function MapTreeModule_empty() {
51
51
  return undefined;
@@ -72,7 +72,7 @@ export function MapTreeModule_sizeAux(acc_mut, m_mut) {
72
72
  }
73
73
  }
74
74
  export function MapTreeModule_size(x) {
75
- return MapTreeModule_sizeAux(0, x);
75
+ return MapTreeModule_sizeAux(0, x) | 0;
76
76
  }
77
77
  export function MapTreeModule_mk(l, k, v, r) {
78
78
  let mn, mn_1;
@@ -1223,7 +1223,7 @@ export function FSharpMap__Partition(m, predicate) {
1223
1223
  return [FSharpMap_$ctor(m.comparer, patternInput[0]), FSharpMap_$ctor(m.comparer, patternInput[1])];
1224
1224
  }
1225
1225
  export function FSharpMap__get_Count(m) {
1226
- return MapTreeModule_size(m.tree);
1226
+ return MapTreeModule_size(m.tree) | 0;
1227
1227
  }
1228
1228
  export function FSharpMap__ContainsKey(m, key) {
1229
1229
  return MapTreeModule_mem(m.comparer, key, m.tree);
@@ -1264,7 +1264,7 @@ export function FSharpMap__ToArray(m) {
1264
1264
  return MapTreeModule_toArray(m.tree);
1265
1265
  }
1266
1266
  export function FSharpMap__ComputeHashCode(this$) {
1267
- const combineHash = (x, y) => (((x << 1) + y) + 631);
1267
+ const combineHash = (x, y) => ((((x << 1) + y) + 631) | 0);
1268
1268
  let res = 0;
1269
1269
  const enumerator = getEnumerator(this$);
1270
1270
  try {
@@ -1392,5 +1392,5 @@ export function empty(comparer) {
1392
1392
  return FSharpMap_Empty(comparer);
1393
1393
  }
1394
1394
  export function count(table) {
1395
- return FSharpMap__get_Count(table);
1395
+ return FSharpMap__get_Count(table) | 0;
1396
1396
  }
package/MapUtil.js CHANGED
@@ -6,6 +6,7 @@ const CaseRules = {
6
6
  SnakeCase: 2,
7
7
  SnakeCaseAllCaps: 3,
8
8
  KebabCase: 4,
9
+ LowerAll: 5,
9
10
  };
10
11
  function dashify(str, separator) {
11
12
  return str.replace(/[a-z]?[A-Z]/g, (m) => m.length === 1
@@ -22,6 +23,8 @@ function changeCase(str, caseRule) {
22
23
  return dashify(str, "_").toUpperCase();
23
24
  case CaseRules.KebabCase:
24
25
  return dashify(str, "-");
26
+ case CaseRules.LowerAll:
27
+ return str.toLowerCase();
25
28
  case CaseRules.None:
26
29
  default:
27
30
  return str;
package/Numeric.d.ts CHANGED
@@ -11,9 +11,10 @@ export interface CustomNumeric extends IComparable<Numeric> {
11
11
  }
12
12
  export type Numeric = number | bigint | CustomNumeric;
13
13
  export declare function isNumeric(x: any): any;
14
+ export declare function isIntegral(x: Numeric): boolean;
14
15
  export declare function compare(x: Numeric, y: number): number;
15
16
  export declare function multiply(x: Numeric, y: number): Numeric;
16
- export declare function toFixed(x: Numeric, dp?: number): string | bigint;
17
- export declare function toPrecision(x: Numeric, sd?: number): string | bigint;
17
+ export declare function toFixed(x: Numeric, dp?: number): string;
18
+ export declare function toPrecision(x: Numeric, sd?: number): string;
18
19
  export declare function toExponential(x: Numeric, dp?: number): string | bigint;
19
20
  export declare function toHex(x: Numeric): string;
package/Numeric.js CHANGED
@@ -2,6 +2,10 @@ export const symbol = Symbol("numeric");
2
2
  export function isNumeric(x) {
3
3
  return typeof x === "number" || typeof x === "bigint" || x?.[symbol];
4
4
  }
5
+ export function isIntegral(x) {
6
+ // Not perfect, because in JS we can't distinguish between 1.0 and 1
7
+ return typeof x === "number" && Number.isInteger(x) || typeof x === "bigint";
8
+ }
5
9
  export function compare(x, y) {
6
10
  if (typeof x === "number") {
7
11
  return x < y ? -1 : (x > y ? 1 : 0);
@@ -29,7 +33,7 @@ export function toFixed(x, dp) {
29
33
  return x.toFixed(dp);
30
34
  }
31
35
  else if (typeof x === "bigint") {
32
- return x;
36
+ return x.toString();
33
37
  }
34
38
  else {
35
39
  return x[symbol]().toFixed(dp);
@@ -40,7 +44,7 @@ export function toPrecision(x, sd) {
40
44
  return x.toPrecision(sd);
41
45
  }
42
46
  else if (typeof x === "bigint") {
43
- return x;
47
+ return x.toString();
44
48
  }
45
49
  else {
46
50
  return x[symbol]().toPrecision(sd);
package/Random.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { class_type } from "./Reflection.js";
2
- import { fromFloat64, op_Addition, toInt32, toFloat64, compare, fromInt32, toInt64 } from "./BigInt.js";
2
+ import { fromFloat64, op_Addition, toInt32_unchecked, toFloat64, compare, fromInt32, toInt64_unchecked } from "./BigInt.js";
3
3
  import { Operators_IsNull } from "./FSharp.Core.js";
4
4
  import { item, fill, setItem } from "./Array.js";
5
5
  function Native_random() {
@@ -33,13 +33,13 @@ export class NonSeeded {
33
33
  constructor() {
34
34
  }
35
35
  Next0() {
36
- return Native_randomNext(0, 2147483647);
36
+ return Native_randomNext(0, 2147483647) | 0;
37
37
  }
38
38
  Next1(maxValue) {
39
- return Native_randomNext(0, maxValue);
39
+ return Native_randomNext(0, maxValue) | 0;
40
40
  }
41
41
  Next2(minValue, maxValue) {
42
- return Native_randomNext(minValue, maxValue);
42
+ return Native_randomNext(minValue, maxValue) | 0;
43
43
  }
44
44
  NextDouble() {
45
45
  return Native_random();
@@ -103,8 +103,8 @@ export class Seeded {
103
103
  if (minValue > maxValue) {
104
104
  throw new Error("minValue must be less than maxValue");
105
105
  }
106
- const range = toInt64(fromInt32(maxValue - minValue));
107
- return ((compare(range, toInt64(fromInt32(2147483647))) <= 0) ? (~~(Seeded__Sample(this$) * toFloat64(range)) + minValue) : ~~toInt32(toInt64(op_Addition(toInt64(fromFloat64(Seeded__GetSampleForLargeRange(this$) * toFloat64(range))), toInt64(fromInt32(minValue)))))) | 0;
106
+ const range = toInt64_unchecked(fromInt32(maxValue - minValue));
107
+ return ((compare(range, toInt64_unchecked(fromInt32(2147483647))) <= 0) ? (~~(Seeded__Sample(this$) * toFloat64(range)) + minValue) : ~~toInt32_unchecked(toInt64_unchecked(op_Addition(toInt64_unchecked(fromFloat64(Seeded__GetSampleForLargeRange(this$) * toFloat64(range))), toInt64_unchecked(fromInt32(minValue)))))) | 0;
108
108
  }
109
109
  NextDouble() {
110
110
  const this$ = this;
package/Range.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { compare } from "./Util.js";
2
2
  import { unfold, delay } from "./Seq.js";
3
- import { toUInt64, toInt64, op_Addition, fromZero } from "./BigInt.js";
3
+ import { toUInt64_unchecked, toInt64_unchecked, op_Addition, fromZero } from "./BigInt.js";
4
4
  import { op_Addition as op_Addition_1, fromParts } from "./Decimal.js";
5
5
  export function makeRangeStepFunction(step, stop, zero, add) {
6
6
  const stepComparedWithZero = compare(step, zero) | 0;
@@ -27,16 +27,16 @@ export function rangeDouble(start, step, stop) {
27
27
  return integralRangeStep(start, step, stop, 0, (x, y) => (x + y));
28
28
  }
29
29
  export function rangeInt64(start, step, stop) {
30
- return integralRangeStep(start, step, stop, 0n, (x, y) => toInt64(op_Addition(x, y)));
30
+ return integralRangeStep(start, step, stop, 0n, (x, y) => toInt64_unchecked(op_Addition(x, y)));
31
31
  }
32
32
  export function rangeUInt64(start, step, stop) {
33
- return integralRangeStep(start, step, stop, 0n, (x, y) => toUInt64(op_Addition(x, y)));
33
+ return integralRangeStep(start, step, stop, 0n, (x, y) => toUInt64_unchecked(op_Addition(x, y)));
34
34
  }
35
35
  export function rangeChar(start, stop) {
36
36
  const intStop = ~~stop.charCodeAt(0) | 0;
37
- return delay(() => unfold((c) => {
38
- if (c <= intStop) {
39
- return [String.fromCharCode(c), c + 1];
37
+ return delay(() => unfold((i) => {
38
+ if (i <= intStop) {
39
+ return [String.fromCharCode(i & 0xFFFF), i + 1];
40
40
  }
41
41
  else {
42
42
  return undefined;
package/Seq.js CHANGED
@@ -144,7 +144,6 @@ export function Enumerator_concat(sources) {
144
144
  return Enumerator_alreadyFinished();
145
145
  }
146
146
  }, () => {
147
- let copyOfStruct;
148
147
  if (!started) {
149
148
  started = true;
150
149
  }
@@ -154,6 +153,7 @@ export function Enumerator_concat(sources) {
154
153
  else {
155
154
  let res = undefined;
156
155
  while (res == null) {
156
+ let copyOfStruct;
157
157
  const outerOpt_1 = outerOpt;
158
158
  const innerOpt_1 = innerOpt;
159
159
  if (outerOpt_1 != null) {
@@ -1176,16 +1176,16 @@ export function sortWith(comparer, xs) {
1176
1176
  });
1177
1177
  }
1178
1178
  export function sort(xs, comparer) {
1179
- return sortWith((x, y) => comparer.Compare(x, y), xs);
1179
+ return sortWith((x, y) => (comparer.Compare(x, y) | 0), xs);
1180
1180
  }
1181
1181
  export function sortBy(projection, xs, comparer) {
1182
- return sortWith((x, y) => comparer.Compare(projection(x), projection(y)), xs);
1182
+ return sortWith((x, y) => (comparer.Compare(projection(x), projection(y)) | 0), xs);
1183
1183
  }
1184
1184
  export function sortDescending(xs, comparer) {
1185
- return sortWith((x, y) => (comparer.Compare(x, y) * -1), xs);
1185
+ return sortWith((x, y) => ((comparer.Compare(x, y) * -1) | 0), xs);
1186
1186
  }
1187
1187
  export function sortByDescending(projection, xs, comparer) {
1188
- return sortWith((x, y) => (comparer.Compare(projection(x), projection(y)) * -1), xs);
1188
+ return sortWith((x, y) => ((comparer.Compare(projection(x), projection(y)) * -1) | 0), xs);
1189
1189
  }
1190
1190
  export function sum(xs, adder) {
1191
1191
  return fold((acc, x) => adder.Add(acc, x), adder.GetZero(), xs);
package/Seq2.js CHANGED
@@ -32,7 +32,7 @@ export function countBy(projection, xs, comparer) {
32
32
  const key = projection(enumerator["System.Collections.Generic.IEnumerator`1.get_Current"]());
33
33
  let matchValue;
34
34
  let outArg = 0;
35
- matchValue = [tryGetValue(dict, key, new FSharpRef(() => outArg, (v) => {
35
+ matchValue = [tryGetValue(dict, key, new FSharpRef(() => (outArg | 0), (v) => {
36
36
  outArg = (v | 0);
37
37
  })), outArg];
38
38
  if (matchValue[0]) {
package/Set.js CHANGED
@@ -42,7 +42,7 @@ export function SetTreeNode$1__get_Right(_) {
42
42
  return _.right;
43
43
  }
44
44
  export function SetTreeNode$1__get_Height(_) {
45
- return _.h;
45
+ return _.h | 0;
46
46
  }
47
47
  export function SetTreeModule_empty() {
48
48
  return undefined;
@@ -69,7 +69,7 @@ export function SetTreeModule_countAux(t_mut, acc_mut) {
69
69
  }
70
70
  }
71
71
  export function SetTreeModule_count(s) {
72
- return SetTreeModule_countAux(s, 0);
72
+ return SetTreeModule_countAux(s, 0) | 0;
73
73
  }
74
74
  export function SetTreeModule_mk(l, k, r) {
75
75
  let tn, tn_1;
@@ -1517,7 +1517,7 @@ export function FSharpSet__Remove(s, value) {
1517
1517
  return FSharpSet_$ctor(FSharpSet__get_Comparer(s), SetTreeModule_remove(FSharpSet__get_Comparer(s), value, FSharpSet__get_Tree(s)));
1518
1518
  }
1519
1519
  export function FSharpSet__get_Count(s) {
1520
- return SetTreeModule_count(FSharpSet__get_Tree(s));
1520
+ return SetTreeModule_count(FSharpSet__get_Tree(s)) | 0;
1521
1521
  }
1522
1522
  export function FSharpSet__Contains(s, value) {
1523
1523
  return SetTreeModule_mem(FSharpSet__get_Comparer(s), value, FSharpSet__get_Tree(s));
@@ -1598,7 +1598,7 @@ export function FSharpSet_Equality(a, b) {
1598
1598
  return SetTreeModule_compare(FSharpSet__get_Comparer(a), FSharpSet__get_Tree(a), FSharpSet__get_Tree(b)) === 0;
1599
1599
  }
1600
1600
  export function FSharpSet_Compare(a, b) {
1601
- return SetTreeModule_compare(FSharpSet__get_Comparer(a), FSharpSet__get_Tree(a), FSharpSet__get_Tree(b));
1601
+ return SetTreeModule_compare(FSharpSet__get_Comparer(a), FSharpSet__get_Tree(a), FSharpSet__get_Tree(b)) | 0;
1602
1602
  }
1603
1603
  export function FSharpSet__get_Choose(x) {
1604
1604
  return SetTreeModule_choose(FSharpSet__get_Tree(x));
@@ -1696,7 +1696,7 @@ export function map(mapping, set$, comparer) {
1696
1696
  return FSharpSet__Map(set$, mapping, comparer);
1697
1697
  }
1698
1698
  export function count(set$) {
1699
- return FSharpSet__get_Count(set$);
1699
+ return FSharpSet__get_Count(set$) | 0;
1700
1700
  }
1701
1701
  export function ofList(elements, comparer) {
1702
1702
  return FSharpSet_$ctor(comparer, SetTreeModule_ofSeq(comparer, elements));
package/String.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { toString as dateToString } from "./Date.js";
2
- import { compare as numericCompare, isNumeric, multiply, toExponential, toFixed, toHex, toPrecision } from "./Numeric.js";
2
+ import { compare as numericCompare, isNumeric, isIntegral, multiply, toExponential, toFixed, toHex, toPrecision } from "./Numeric.js";
3
3
  import { escape } from "./RegExp.js";
4
4
  import { toString } from "./Types.js";
5
5
  const fsFormatRegExp = /(^|[^%])%([0+\- ]*)(\*|\d+)?(?:\.(\d+))?(\w)/g;
@@ -276,6 +276,17 @@ export function fsFormat(str) {
276
276
  }
277
277
  };
278
278
  }
279
+ function splitIntAndDecimalPart(value) {
280
+ let [repInt, repDecimal] = value.split(".");
281
+ repDecimal === undefined && (repDecimal = "");
282
+ return {
283
+ integral: repInt,
284
+ decimal: repDecimal
285
+ };
286
+ }
287
+ function thousandSeparate(value) {
288
+ return value.replace(/\B(?=(\d{3})+(?!\d))/g, ",");
289
+ }
279
290
  export function format(str, ...args) {
280
291
  let str2;
281
292
  if (typeof str === "object") {
@@ -291,39 +302,99 @@ export function format(str, ...args) {
291
302
  throw new Error("Index must be greater or equal to zero and less than the arguments' length.");
292
303
  }
293
304
  let rep = args[idx];
305
+ let parts;
294
306
  if (isNumeric(rep)) {
295
- precision = precision == null ? null : parseInt(precision, 10);
307
+ precision = precision == "" ? null : parseInt(precision, 10);
296
308
  switch (format) {
309
+ case "b":
310
+ case "B":
311
+ if (!isIntegral(rep)) {
312
+ throw new Error("Format specifier was invalid.");
313
+ }
314
+ rep = (rep >>> 0).toString(2).replace(/^0+/, "").padStart(precision || 1, "0");
315
+ break;
316
+ case "c":
317
+ case "C":
318
+ const isNegative = isLessThan(rep, 0);
319
+ if (isLessThan(rep, 0)) {
320
+ rep = multiply(rep, -1);
321
+ }
322
+ precision = precision == null ? 2 : precision;
323
+ rep = toFixed(rep, precision);
324
+ parts = splitIntAndDecimalPart(rep);
325
+ rep = "¤" + thousandSeparate(parts.integral) + "." + padRight(parts.decimal, precision, "0");
326
+ if (isNegative) {
327
+ rep = "(" + rep + ")";
328
+ }
329
+ break;
330
+ case "d":
331
+ case "D":
332
+ if (!isIntegral(rep)) {
333
+ throw new Error("Format specifier was invalid.");
334
+ }
335
+ rep = String(rep);
336
+ if (precision != null) {
337
+ if (rep.startsWith("-")) {
338
+ rep = "-" + padLeft(rep.substring(1), precision, "0");
339
+ }
340
+ else {
341
+ rep = padLeft(rep, precision, "0");
342
+ }
343
+ }
344
+ break;
345
+ case "e":
346
+ case "E":
347
+ rep = precision != null ? toExponential(rep, precision) : toExponential(rep);
348
+ break;
297
349
  case "f":
298
350
  case "F":
299
351
  precision = precision != null ? precision : 2;
300
352
  rep = toFixed(rep, precision);
353
+ if (precision > 0) {
354
+ parts = splitIntAndDecimalPart(rep);
355
+ rep = parts.integral + "." + padRight(parts.decimal, precision, "0");
356
+ }
301
357
  break;
302
358
  case "g":
303
359
  case "G":
304
360
  rep = precision != null ? toPrecision(rep, precision) : toPrecision(rep);
361
+ // TODO: Check why some numbers are formatted with decimal part
362
+ rep = trimEnd(trimEnd(rep, "0"), ".");
305
363
  break;
306
- case "e":
307
- case "E":
308
- rep = precision != null ? toExponential(rep, precision) : toExponential(rep);
364
+ case "n":
365
+ case "N":
366
+ precision = precision != null ? precision : 2;
367
+ rep = toFixed(rep, precision);
368
+ parts = splitIntAndDecimalPart(rep);
369
+ rep = thousandSeparate(parts.integral) + "." + padRight(parts.decimal, precision, "0");
309
370
  break;
310
371
  case "p":
311
372
  case "P":
312
373
  precision = precision != null ? precision : 2;
313
- rep = toFixed(multiply(rep, 100), precision) + " %";
314
- break;
315
- case "d":
316
- case "D":
317
- rep = precision != null ? padLeft(String(rep), precision, "0") : String(rep);
374
+ rep = toFixed(multiply(rep, 100), precision);
375
+ parts = splitIntAndDecimalPart(rep);
376
+ rep = thousandSeparate(parts.integral) + "." + padRight(parts.decimal, precision, "0") + " %";
318
377
  break;
378
+ case "r":
379
+ case "R":
380
+ throw new Error("The round-trip format is not supported by Fable");
319
381
  case "x":
320
382
  case "X":
321
- rep = precision != null ? padLeft(toHex(rep), precision, "0") : toHex(rep);
383
+ if (!isIntegral(rep)) {
384
+ throw new Error("Format specifier was invalid.");
385
+ }
386
+ precision = precision != null ? precision : 2;
387
+ rep = padLeft(toHex(rep), precision, "0");
322
388
  if (format === "X") {
323
389
  rep = rep.toUpperCase();
324
390
  }
325
391
  break;
326
392
  default:
393
+ // If we have format and were not able to handle it throw
394
+ // See: https://learn.microsoft.com/en-us/dotnet/standard/base-types/standard-numeric-format-strings#standard-format-specifiers
395
+ if (format) {
396
+ throw new Error("Format specifier was invalid.");
397
+ }
327
398
  if (pattern) {
328
399
  let sign = "";
329
400
  rep = pattern.replace(/([0#,]+)(\.[0#]+)?/, (_, intPart, decimalPart) => {
@@ -19,13 +19,13 @@ export function Comparer$1_$ctor_47C913C(comparison) {
19
19
  return new Comparer$1(comparison);
20
20
  }
21
21
  export function Comparer$1_get_Default() {
22
- return Comparer$1_$ctor_47C913C(compare);
22
+ return Comparer$1_$ctor_47C913C((e, e_1) => (compare(e, e_1) | 0));
23
23
  }
24
24
  export function Comparer$1_Create_47C913C(comparison) {
25
25
  return Comparer$1_$ctor_47C913C(comparison);
26
26
  }
27
27
  export function Comparer$1__Compare_5BDDA0(_, x, y) {
28
- return _.comparison(x, y);
28
+ return _.comparison(x, y) | 0;
29
29
  }
30
30
  export class EqualityComparer$1 {
31
31
  constructor(equals, getHashCode) {
@@ -48,7 +48,7 @@ export function EqualityComparer$1_$ctor_Z6EE254AB(equals, getHashCode) {
48
48
  return new EqualityComparer$1(equals, getHashCode);
49
49
  }
50
50
  export function EqualityComparer$1_get_Default() {
51
- return EqualityComparer$1_$ctor_Z6EE254AB(equals_1, structuralHash);
51
+ return EqualityComparer$1_$ctor_Z6EE254AB(equals_1, (obj) => (structuralHash(obj) | 0));
52
52
  }
53
53
  export function EqualityComparer$1_Create_Z6EE254AB(equals, getHashCode) {
54
54
  return EqualityComparer$1_$ctor_Z6EE254AB(equals, getHashCode);
@@ -57,7 +57,7 @@ export function EqualityComparer$1__Equals_5BDDA0(_, x, y) {
57
57
  return _.equals(x, y);
58
58
  }
59
59
  export function EqualityComparer$1__GetHashCode_2B595(_, x) {
60
- return _.getHashCode(x);
60
+ return _.getHashCode(x) | 0;
61
61
  }
62
62
  export class Stack$1 {
63
63
  constructor(initialContents, initialCount) {
@@ -107,7 +107,7 @@ export function Stack$1__Ensure_Z524259A4(_, newSize) {
107
107
  }
108
108
  }
109
109
  export function Stack$1__get_Count(_) {
110
- return _.count;
110
+ return _.count | 0;
111
111
  }
112
112
  export function Stack$1__Pop(_) {
113
113
  _.count = ((_.count - 1) | 0);
@@ -203,7 +203,7 @@ export function Queue$1_$ctor_BB573A(xs) {
203
203
  return Queue$1_$ctor_Z3B4C077E(arr, arr.length);
204
204
  }
205
205
  export function Queue$1__get_Count(_) {
206
- return _.count;
206
+ return _.count | 0;
207
207
  }
208
208
  export function Queue$1__Enqueue_2B595(_, value) {
209
209
  if (_.count === Queue$1__size(_)) {
@@ -288,10 +288,10 @@ export function Queue$1__CopyTo_Z3B4C077E(_, target, start) {
288
288
  }
289
289
  }
290
290
  export function Queue$1__size(this$) {
291
- return this$.contents.length;
291
+ return this$.contents.length | 0;
292
292
  }
293
293
  export function Queue$1__toIndex_Z524259A4(this$, i) {
294
- return (this$.head + i) % Queue$1__size(this$);
294
+ return ((this$.head + i) % Queue$1__size(this$)) | 0;
295
295
  }
296
296
  export function Queue$1__ensure_Z524259A4(this$, requiredSize) {
297
297
  const newBuffer = fill(new Array(requiredSize), 0, requiredSize, null);
package/Types.js CHANGED
@@ -19,7 +19,7 @@ export function seqToString(self) {
19
19
  }
20
20
  export function toString(x, callStack = 0) {
21
21
  if (x != null && typeof x === "object") {
22
- if (typeof x.toString === "function") {
22
+ if (typeof x.toString === "function" && x.toString !== Object.prototype.toString) {
23
23
  return x.toString();
24
24
  }
25
25
  else if (Symbol.iterator in x) {
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "private": false,
4
4
  "type": "module",
5
5
  "name": "@fable-org/fable-library-js",
6
- "version": "1.10.0",
6
+ "version": "2.0.0-beta.2",
7
7
  "description": "Core library used by F# projects compiled with fable.io",
8
8
  "author": "Fable Contributors",
9
9
  "license": "MIT",