@fable-org/fable-library-ts 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/Date.ts CHANGED
@@ -55,7 +55,7 @@ function parseNextChar(format: string, pos: number) {
55
55
  return format.charCodeAt(pos + 1);
56
56
  }
57
57
 
58
- function parseQuotedString(format: string, pos: number) : [string, number] {
58
+ function parseQuotedString(format: string, pos: number): [string, number] {
59
59
  let beginPos = pos;
60
60
  // Get the character used to quote the string
61
61
  const quoteChar = format[pos];
@@ -114,9 +114,8 @@ function dateToStringWithCustomFormat(date: Date, format: string, utc: boolean)
114
114
  result += shortDays[dayOfWeek(localizedDate)];
115
115
  break;
116
116
  case 4:
117
- result += longDays[dayOfWeek(localizedDate)];
118
- break;
119
117
  default:
118
+ result += longDays[dayOfWeek(localizedDate)];
120
119
  break;
121
120
  }
122
121
  break;
@@ -132,7 +131,9 @@ function dateToStringWithCustomFormat(date: Date, format: string, utc: boolean)
132
131
  // milliseconds provided to it.
133
132
  // This is to have the same behavior as .NET when doing:
134
133
  // DateTime(1, 2, 3, 4, 5, 6, DateTimeKind.Utc).ToString("fffff") => 00000
135
- result += (""+millisecond(localizedDate)).padEnd(tokenLength, "0");
134
+ result += ("" + millisecond(localizedDate)).padEnd(tokenLength, "0");
135
+ } else {
136
+ throw "Input string was not in a correct format.";
136
137
  }
137
138
  break;
138
139
  case "F":
@@ -152,14 +153,14 @@ function dateToStringWithCustomFormat(date: Date, format: string, utc: boolean)
152
153
  if (value != 0) {
153
154
  result += padWithZeros(value, 3);
154
155
  }
156
+ } else {
157
+ throw "Input string was not in a correct format.";
155
158
  }
156
159
  break;
157
160
  case "g":
158
161
  tokenLength = parseRepeatToken(format, cursorPos, "g");
159
162
  cursorPos += tokenLength;
160
- if (tokenLength <= 2) {
161
- result += "A.D.";
162
- }
163
+ result += "A.D.";
163
164
  break;
164
165
  case "h":
165
166
  tokenLength = parseRepeatToken(format, cursorPos, "h");
@@ -170,11 +171,10 @@ function dateToStringWithCustomFormat(date: Date, format: string, utc: boolean)
170
171
  result += h1Value ? h1Value : 12;
171
172
  break;
172
173
  case 2:
174
+ default:
173
175
  const h2Value = hour(localizedDate) % 12;
174
176
  result += padWithZeros(h2Value ? h2Value : 12, 2);
175
177
  break;
176
- default:
177
- break;
178
178
  }
179
179
  break;
180
180
  case "H":
@@ -185,9 +185,8 @@ function dateToStringWithCustomFormat(date: Date, format: string, utc: boolean)
185
185
  result += hour(localizedDate);
186
186
  break;
187
187
  case 2:
188
- result += padWithZeros(hour(localizedDate), 2);
189
- break;
190
188
  default:
189
+ result += padWithZeros(hour(localizedDate), 2);
191
190
  break;
192
191
  }
193
192
  break;
@@ -219,9 +218,8 @@ function dateToStringWithCustomFormat(date: Date, format: string, utc: boolean)
219
218
  result += minute(localizedDate);
220
219
  break;
221
220
  case 2:
222
- result += padWithZeros(minute(localizedDate), 2);
223
- break;
224
221
  default:
222
+ result += padWithZeros(minute(localizedDate), 2);
225
223
  break;
226
224
  }
227
225
  break;
@@ -239,9 +237,8 @@ function dateToStringWithCustomFormat(date: Date, format: string, utc: boolean)
239
237
  result += shortMonths[month(localizedDate) - 1];
240
238
  break;
241
239
  case 4:
242
- result += longMonths[month(localizedDate) - 1];
243
- break;
244
240
  default:
241
+ result += longMonths[month(localizedDate) - 1];
245
242
  break;
246
243
  }
247
244
  break;
@@ -253,9 +250,8 @@ function dateToStringWithCustomFormat(date: Date, format: string, utc: boolean)
253
250
  result += second(localizedDate);
254
251
  break;
255
252
  case 2:
256
- result += padWithZeros(second(localizedDate), 2);
257
- break;
258
253
  default:
254
+ result += padWithZeros(second(localizedDate), 2);
259
255
  break;
260
256
  }
261
257
  break;
@@ -267,9 +263,8 @@ function dateToStringWithCustomFormat(date: Date, format: string, utc: boolean)
267
263
  result += localizedDate.getHours() < 12 ? "A" : "P";
268
264
  break;
269
265
  case 2:
270
- result += localizedDate.getHours() < 12 ? "AM" : "PM";
271
- break;
272
266
  default:
267
+ result += localizedDate.getHours() < 12 ? "AM" : "PM";
273
268
  break;
274
269
  }
275
270
  break;
@@ -283,16 +278,8 @@ function dateToStringWithCustomFormat(date: Date, format: string, utc: boolean)
283
278
  case 2:
284
279
  result += padWithZeros(localizedDate.getFullYear() % 100, 2);
285
280
  break;
286
- case 3:
287
- result += padWithZeros(localizedDate.getFullYear(), 3);
288
- break;
289
- case 4:
290
- result += padWithZeros(localizedDate.getFullYear(), 4);
291
- break;
292
- case 5:
293
- result += padWithZeros(localizedDate.getFullYear(), 5);
294
- break;
295
281
  default:
282
+ result += padWithZeros(localizedDate.getFullYear(), tokenLength);
296
283
  break;
297
284
  }
298
285
  break;
@@ -393,13 +380,6 @@ export function dateOffsetToString(offset: number) {
393
380
  padWithZeros(minutes, 2);
394
381
  }
395
382
 
396
- export function dateToHalfUTCString(date: IDateTime, half: "first" | "second") {
397
- const str = date.toISOString();
398
- return half === "first"
399
- ? str.substring(0, str.indexOf("T"))
400
- : str.substring(str.indexOf("T") + 1, str.length - 1);
401
- }
402
-
403
383
  function dateToISOString(d: IDateTime, utc: boolean) {
404
384
  if (utc) {
405
385
  return d.toISOString();
@@ -428,8 +408,10 @@ function dateToStringWithOffset(date: IDateTimeOffset, format?: string) {
428
408
  return d.toISOString().replace(/\.\d+/, "").replace(/[A-Z]|\.\d+/g, " ") + dateOffsetToString((date.offset ?? 0));
429
409
  } else if (format.length === 1) {
430
410
  switch (format) {
431
- case "D": case "d": return dateToHalfUTCString(d, "first");
432
- case "T": case "t": return dateToHalfUTCString(d, "second");
411
+ case "D": return dateToString_D(d);
412
+ case "d": return dateToString_d(d);
413
+ case "T": return dateToString_T(toUniversalTime(d));
414
+ case "t": return dateToString_t(toUniversalTime(d));
433
415
  case "O": case "o": return dateToISOStringWithOffset(d, (date.offset ?? 0));
434
416
  default: throw new Error("Unrecognized Date print format");
435
417
  }
@@ -438,16 +420,40 @@ function dateToStringWithOffset(date: IDateTimeOffset, format?: string) {
438
420
  }
439
421
  }
440
422
 
423
+ function dateToString_D(date: IDateTime) {
424
+ return longDays[dayOfWeek(date)]
425
+ + ", " + padWithZeros(day(date), 2)
426
+ + " " + longMonths[month(date) - 1]
427
+ + " " + year(date);
428
+ }
429
+
430
+ function dateToString_d(date: IDateTime) {
431
+ return padWithZeros(month(date), 2)
432
+ + "/" + padWithZeros(day(date), 2)
433
+ + "/" + year(date);
434
+ }
435
+
436
+ function dateToString_T(date: IDateTime) {
437
+ return padWithZeros(hour(date), 2)
438
+ + ":" + padWithZeros(minute(date), 2)
439
+ + ":" + padWithZeros(second(date), 2);
440
+ }
441
+
442
+ function dateToString_t(date: IDateTime) {
443
+ return padWithZeros(hour(date), 2)
444
+ + ":" + padWithZeros(minute(date), 2);
445
+ }
446
+
441
447
  function dateToStringWithKind(date: IDateTime, format?: string) {
442
448
  const utc = date.kind === DateKind.UTC;
443
449
  if (typeof format !== "string") {
444
450
  return utc ? date.toUTCString() : date.toLocaleString();
445
451
  } else if (format.length === 1) {
446
452
  switch (format) {
447
- case "D": case "d":
448
- return utc ? dateToHalfUTCString(date, "first") : date.toLocaleDateString();
449
- case "T": case "t":
450
- return utc ? dateToHalfUTCString(date, "second") : date.toLocaleTimeString();
453
+ case "D": return dateToString_D(date);
454
+ case "d": return dateToString_d(date);
455
+ case "T": return dateToString_T(date);
456
+ case "t": return dateToString_t(date);
451
457
  case "O": case "o":
452
458
  return dateToISOString(date, utc);
453
459
  default:
package/Decimal.ts CHANGED
@@ -2,6 +2,9 @@ import Decimal, { BigSource } from "./lib/big.js";
2
2
  import { Numeric, symbol } from "./Numeric.js";
3
3
  import { FSharpRef } from "./Types.js";
4
4
  import { combineHashCodes } from "./Util.js";
5
+ import { int8, uint8, int16, uint16, int32, uint32, float16, float32, float64 } from "./Int32.js";
6
+ import { fromDecimal, int64, uint64, int128, uint128, nativeint, unativeint } from "./BigInt.js";
7
+ import * as bigInt from "./BigInt.js";
5
8
 
6
9
  Decimal.prototype.GetHashCode = function () {
7
10
  return combineHashCodes([this.s, this.e].concat(this.c))
@@ -139,10 +142,35 @@ export function parse(str: string): Decimal {
139
142
  }
140
143
  }
141
144
 
142
- export function toNumber(x: Decimal) {
145
+ export function toNumber(x: Decimal): number {
143
146
  return +x;
144
147
  }
145
148
 
149
+ export function toChar(x: Decimal): string {
150
+ const n = toNumber(x);
151
+ if (n < 0 || n > 65535 || isNaN(n)) {
152
+ throw new Error("Value was either too large or too small for a character.");
153
+ }
154
+ return String.fromCharCode(n);
155
+ }
156
+
157
+ export function toInt8(x: Decimal): int8 { return bigInt.toInt8(fromDecimal(x)); }
158
+ export function toUInt8(x: Decimal): uint8 { return bigInt.toUInt8(fromDecimal(x)); }
159
+ export function toInt16(x: Decimal): int16 { return bigInt.toInt16(fromDecimal(x)); }
160
+ export function toUInt16(x: Decimal): uint16 { return bigInt.toUInt16(fromDecimal(x)); }
161
+ export function toInt32(x: Decimal): int32 { return bigInt.toInt32(fromDecimal(x)); }
162
+ export function toUInt32(x: Decimal): uint32 { return bigInt.toUInt32(fromDecimal(x)); }
163
+ export function toInt64(x: Decimal): int64 { return bigInt.toInt64(fromDecimal(x)); }
164
+ export function toUInt64(x: Decimal): uint64 { return bigInt.toUInt64(fromDecimal(x)); }
165
+ export function toInt128(x: Decimal): int128 { return bigInt.toInt128(fromDecimal(x)); }
166
+ export function toUInt128(x: Decimal): uint128 { return bigInt.toUInt128(fromDecimal(x)); }
167
+ export function toNativeInt(x: Decimal): nativeint { return bigInt.toNativeInt(fromDecimal(x)); }
168
+ export function toUNativeInt(x: Decimal): unativeint { return bigInt.toUNativeInt(fromDecimal(x)); }
169
+
170
+ export function toFloat16(x: Decimal): float16 { return toNumber(x); }
171
+ export function toFloat32(x: Decimal): float32 { return toNumber(x); }
172
+ export function toFloat64(x: Decimal): float64 { return toNumber(x); }
173
+
146
174
  function decimalToHex(dec: Uint8Array, bitSize: number) {
147
175
  const hex = new Uint8Array(bitSize / 4 | 0);
148
176
  let hexCount = 1;
@@ -1,34 +1,34 @@
1
- import { int32 } from "./Int32.js";
2
- import { compare, IComparer, physicalHash, equals, structuralHash, IEqualityComparer } from "./Util.js";
3
-
4
- export function HashIdentity_FromFunctions<T>(hash: ((arg0: T) => int32), eq: ((arg0: T, arg1: T) => boolean)): IEqualityComparer<T> {
5
- return {
6
- Equals(x: T, y: T): boolean {
7
- return eq(x, y);
8
- },
9
- GetHashCode(x_1: T): int32 {
10
- return hash(x_1);
11
- },
12
- };
13
- }
14
-
15
- export function HashIdentity_Structural<T>(): IEqualityComparer<T> {
16
- return HashIdentity_FromFunctions<T>(structuralHash, equals);
17
- }
18
-
19
- export function HashIdentity_Reference<T>(): IEqualityComparer<T> {
20
- return HashIdentity_FromFunctions<T>(physicalHash, (e: T, e_1: T): boolean => (e === e_1));
21
- }
22
-
23
- export function ComparisonIdentity_FromFunction<T>(comparer: ((arg0: T, arg1: T) => int32)): IComparer<T> {
24
- return {
25
- Compare(x: T, y: T): int32 {
26
- return comparer(x, y);
27
- },
28
- };
29
- }
30
-
31
- export function ComparisonIdentity_Structural<T>(): IComparer<T> {
32
- return ComparisonIdentity_FromFunction<T>(compare);
33
- }
34
-
1
+ import { int32 } from "./Int32.js";
2
+ import { compare, IComparer, physicalHash, equals, structuralHash, IEqualityComparer } from "./Util.js";
3
+
4
+ export function HashIdentity_FromFunctions<T>(hash: ((arg0: T) => int32), eq: ((arg0: T, arg1: T) => boolean)): IEqualityComparer<T> {
5
+ return {
6
+ Equals(x: T, y: T): boolean {
7
+ return eq(x, y);
8
+ },
9
+ GetHashCode(x_1: T): int32 {
10
+ return hash(x_1) | 0;
11
+ },
12
+ };
13
+ }
14
+
15
+ export function HashIdentity_Structural<T>(): IEqualityComparer<T> {
16
+ return HashIdentity_FromFunctions<T>((obj: T): int32 => (structuralHash(obj) | 0), equals);
17
+ }
18
+
19
+ export function HashIdentity_Reference<T>(): IEqualityComparer<T> {
20
+ return HashIdentity_FromFunctions<T>((obj: T): int32 => (physicalHash(obj) | 0), (e: T, e_1: T): boolean => (e === e_1));
21
+ }
22
+
23
+ export function ComparisonIdentity_FromFunction<T>(comparer: ((arg0: T, arg1: T) => int32)): IComparer<T> {
24
+ return {
25
+ Compare(x: T, y: T): int32 {
26
+ return comparer(x, y) | 0;
27
+ },
28
+ };
29
+ }
30
+
31
+ export function ComparisonIdentity_Structural<T>(): IComparer<T> {
32
+ return ComparisonIdentity_FromFunction<T>((e: T, e_1: T): int32 => (compare(e, e_1) | 0));
33
+ }
34
+
@@ -1,37 +1,37 @@
1
- import { class_type, TypeInfo } from "./Reflection.js";
2
- import { addRangeInPlace } from "./Array.js";
3
- import { toList } from "./Seq.js";
4
- import { FSharpList } from "./List.js";
5
-
6
- export class ListCollector$1<T> {
7
- readonly collector: T[];
8
- constructor() {
9
- this.collector = [];
10
- }
11
- }
12
-
13
- export function ListCollector$1_$reflection(gen0: TypeInfo): TypeInfo {
14
- return class_type("Microsoft.FSharp.Core.CompilerServices.ListCollector`1", [gen0], ListCollector$1);
15
- }
16
-
17
- export function ListCollector$1_$ctor<T>(): ListCollector$1<T> {
18
- return new ListCollector$1();
19
- }
20
-
21
- export function ListCollector$1__Add_2B595<T>(this$: ListCollector$1<T>, value: T): void {
22
- void (this$.collector.push(value));
23
- }
24
-
25
- export function ListCollector$1__AddMany_BB573A<T>(this$: ListCollector$1<T>, values: Iterable<T>): void {
26
- addRangeInPlace(values, this$.collector);
27
- }
28
-
29
- export function ListCollector$1__AddManyAndClose_BB573A<T>(this$: ListCollector$1<T>, values: Iterable<T>): FSharpList<T> {
30
- addRangeInPlace(values, this$.collector);
31
- return toList<T>(this$.collector);
32
- }
33
-
34
- export function ListCollector$1__Close<T>(this$: ListCollector$1<T>): FSharpList<T> {
35
- return toList<T>(this$.collector);
36
- }
37
-
1
+ import { class_type, TypeInfo } from "./Reflection.js";
2
+ import { addRangeInPlace } from "./Array.js";
3
+ import { toList } from "./Seq.js";
4
+ import { FSharpList } from "./List.js";
5
+
6
+ export class ListCollector$1<T> {
7
+ readonly collector: T[];
8
+ constructor() {
9
+ this.collector = [];
10
+ }
11
+ }
12
+
13
+ export function ListCollector$1_$reflection(gen0: TypeInfo): TypeInfo {
14
+ return class_type("Microsoft.FSharp.Core.CompilerServices.ListCollector`1", [gen0], ListCollector$1);
15
+ }
16
+
17
+ export function ListCollector$1_$ctor<T>(): ListCollector$1<T> {
18
+ return new ListCollector$1();
19
+ }
20
+
21
+ export function ListCollector$1__Add_2B595<T>(this$: ListCollector$1<T>, value: T): void {
22
+ void (this$.collector.push(value));
23
+ }
24
+
25
+ export function ListCollector$1__AddMany_BB573A<T>(this$: ListCollector$1<T>, values: Iterable<T>): void {
26
+ addRangeInPlace(values, this$.collector);
27
+ }
28
+
29
+ export function ListCollector$1__AddManyAndClose_BB573A<T>(this$: ListCollector$1<T>, values: Iterable<T>): FSharpList<T> {
30
+ addRangeInPlace(values, this$.collector);
31
+ return toList<T>(this$.collector);
32
+ }
33
+
34
+ export function ListCollector$1__Close<T>(this$: ListCollector$1<T>): FSharpList<T> {
35
+ return toList<T>(this$.collector);
36
+ }
37
+