@fable-org/fable-library-js 2.0.0-beta.3 → 2.0.0-beta.5

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 (98) hide show
  1. package/Array.js +64 -60
  2. package/Async.js +8 -7
  3. package/AsyncBuilder.js +6 -6
  4. package/BigInt.js +3 -3
  5. package/Boolean.js +2 -1
  6. package/CHANGELOG.md +12 -0
  7. package/Char.js +64 -31
  8. package/CollectionUtil.js +3 -3
  9. package/Date.js +50 -46
  10. package/DateOffset.js +38 -48
  11. package/DateOnly.js +6 -6
  12. package/Decimal.js +4 -4
  13. package/Double.js +2 -1
  14. package/FSharp.Collections.js +28 -10
  15. package/FSharp.Core.js +19 -19
  16. package/Global.js +21 -0
  17. package/Guid.js +5 -4
  18. package/Int32.js +17 -17
  19. package/List.js +74 -63
  20. package/Long.js +3 -2
  21. package/MailboxProcessor.js +2 -1
  22. package/Map.js +39 -42
  23. package/MapUtil.js +4 -4
  24. package/MutableMap.js +22 -10
  25. package/MutableSet.js +3 -3
  26. package/Native.js +9 -3
  27. package/Option.js +10 -2
  28. package/Random.js +13 -12
  29. package/Range.js +2 -2
  30. package/Reflection.js +16 -16
  31. package/RegExp.js +4 -3
  32. package/Seq.js +38 -46
  33. package/Set.js +41 -42
  34. package/String.js +44 -35
  35. package/System.Collections.Generic.js +22 -6
  36. package/System.Text.js +8 -8
  37. package/System.js +283 -0
  38. package/TimeOnly.js +6 -6
  39. package/TimeSpan.js +5 -5
  40. package/Types.js +1 -17
  41. package/Uri.js +25 -19
  42. package/Util.js +32 -9
  43. package/package.json +23 -23
  44. package/Array.d.ts +0 -123
  45. package/Async.d.ts +0 -26
  46. package/AsyncBuilder.d.ts +0 -59
  47. package/BigInt.d.ts +0 -129
  48. package/BitConverter.d.ts +0 -27
  49. package/Boolean.d.ts +0 -3
  50. package/Char.d.ts +0 -65
  51. package/Choice.d.ts +0 -121
  52. package/CollectionUtil.d.ts +0 -7
  53. package/ConditionalWeakTable.d.ts +0 -9
  54. package/Date.d.ts +0 -69
  55. package/DateOffset.d.ts +0 -64
  56. package/DateOnly.d.ts +0 -18
  57. package/Decimal.d.ts +0 -63
  58. package/Double.d.ts +0 -11
  59. package/Encoding.d.ts +0 -12
  60. package/Event.d.ts +0 -31
  61. package/FSharp.Collections.d.ts +0 -7
  62. package/FSharp.Core.CompilerServices.d.ts +0 -12
  63. package/FSharp.Core.d.ts +0 -31
  64. package/Global.d.ts +0 -24
  65. package/Guid.d.ts +0 -10
  66. package/Int32.d.ts +0 -28
  67. package/List.d.ts +0 -143
  68. package/Long.d.ts +0 -3
  69. package/MailboxProcessor.d.ts +0 -25
  70. package/Map.d.ts +0 -178
  71. package/MapUtil.d.ts +0 -12
  72. package/MutableMap.d.ts +0 -52
  73. package/MutableSet.d.ts +0 -39
  74. package/Native.d.ts +0 -2
  75. package/Numeric.d.ts +0 -20
  76. package/Observable.d.ts +0 -32
  77. package/Option.d.ts +0 -28
  78. package/Random.d.ts +0 -37
  79. package/Range.d.ts +0 -12
  80. package/Reflection.d.ts +0 -119
  81. package/RegExp.d.ts +0 -10
  82. package/Result.d.ts +0 -37
  83. package/Seq.d.ts +0 -165
  84. package/Seq2.d.ts +0 -18
  85. package/Set.d.ts +0 -190
  86. package/String.d.ts +0 -58
  87. package/System.Collections.Generic.d.ts +0 -79
  88. package/System.Text.d.ts +0 -39
  89. package/SystemException.d.ts +0 -5
  90. package/SystemException.js +0 -5
  91. package/TimeOnly.d.ts +0 -15
  92. package/TimeSpan.d.ts +0 -35
  93. package/Timer.d.ts +0 -19
  94. package/Types.d.ts +0 -58
  95. package/Unicode.13.0.0.d.ts +0 -2
  96. package/Uri.d.ts +0 -31
  97. package/Util.d.ts +0 -210
  98. package/lib/big.d.ts +0 -5
package/CollectionUtil.js CHANGED
@@ -1,4 +1,4 @@
1
- import { equals, isArrayLike } from "./Util.js";
1
+ import { Exception, equals, isArrayLike } from "./Util.js";
2
2
  export function count(col) {
3
3
  if (typeof col["System.Collections.Generic.ICollection`1.get_Count"] === "function") {
4
4
  return col["System.Collections.Generic.ICollection`1.get_Count"](); // collection
@@ -32,7 +32,7 @@ export function isReadOnly(col) {
32
32
  }
33
33
  else {
34
34
  if (isArrayLike(col)) {
35
- return ArrayBuffer.isView(col); // true for typed arrays, false for other arrays
35
+ return false; // array, resize array
36
36
  }
37
37
  else {
38
38
  if (typeof col.size === "number") {
@@ -105,7 +105,7 @@ export function add(col, item) {
105
105
  col.set(item[0], item[1]); // map
106
106
  }
107
107
  else {
108
- throw new Error("An item with the same key has already been added. Key: " + item[0]);
108
+ throw new Exception("An item with the same key has already been added. Key: " + item[0]);
109
109
  }
110
110
  }
111
111
  else {
package/Date.js CHANGED
@@ -8,7 +8,7 @@
8
8
  * Basically; invariant: date.getTime() always return UTC time.
9
9
  */
10
10
  import { toInt64, toFloat64 } from "./BigInt.js";
11
- import { compareDates, dateOffset, padWithZeros } from "./Util.js";
11
+ import { Exception, compareDates, DateTimeKind, dateOffset, padWithZeros } from "./Util.js";
12
12
  const shortDays = [
13
13
  "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
14
14
  ];
@@ -56,7 +56,7 @@ function parseQuotedString(format, pos) {
56
56
  }
57
57
  else {
58
58
  // This means that '\' is the last character in the string.
59
- throw new Error("Invalid string format");
59
+ throw new Exception("Invalid string format");
60
60
  }
61
61
  }
62
62
  else {
@@ -65,7 +65,7 @@ function parseQuotedString(format, pos) {
65
65
  }
66
66
  if (!foundQuote) {
67
67
  // We could not find the matching quote
68
- throw new Error(`Invalid string format could not find matching quote for ${quoteChar}`);
68
+ throw new Exception(`Invalid string format could not find matching quote for ${quoteChar}`);
69
69
  }
70
70
  return [result, pos - beginPos + 1];
71
71
  }
@@ -73,7 +73,7 @@ function dateToStringWithCustomFormat(date, format, utc) {
73
73
  let cursorPos = 0;
74
74
  let tokenLength = 0;
75
75
  let result = "";
76
- const localizedDate = utc ? DateTime(date.getTime(), 1 /* DateKind.UTC */) : date;
76
+ const localizedDate = utc ? DateTime(date.getTime(), DateTimeKind.Utc) : date;
77
77
  while (cursorPos < format.length) {
78
78
  const token = format[cursorPos];
79
79
  switch (token) {
@@ -176,14 +176,14 @@ function dateToStringWithCustomFormat(date, format, utc) {
176
176
  cursorPos += tokenLength;
177
177
  switch (tokenLength) {
178
178
  case 1:
179
- switch (kind(localizedDate)) {
180
- case 1 /* DateKind.UTC */:
179
+ switch (getKind(localizedDate)) {
180
+ case DateTimeKind.Utc:
181
181
  result += "Z";
182
182
  break;
183
- case 2 /* DateKind.Local */:
183
+ case DateTimeKind.Local:
184
184
  result += dateOffsetToString(localizedDate.getTimezoneOffset() * -60000);
185
185
  break;
186
- case 0 /* DateKind.Unspecified */:
186
+ case DateTimeKind.Unspecified:
187
187
  break;
188
188
  }
189
189
  break;
@@ -268,14 +268,14 @@ function dateToStringWithCustomFormat(date, format, utc) {
268
268
  tokenLength = parseRepeatToken(format, cursorPos, "z");
269
269
  cursorPos += tokenLength;
270
270
  let utcOffsetText = "";
271
- switch (kind(localizedDate)) {
272
- case 1 /* DateKind.UTC */:
271
+ switch (getKind(localizedDate)) {
272
+ case DateTimeKind.Utc:
273
273
  utcOffsetText = "+00:00";
274
274
  break;
275
- case 2 /* DateKind.Local */:
275
+ case DateTimeKind.Local:
276
276
  utcOffsetText = dateOffsetToString(localizedDate.getTimezoneOffset() * -60000);
277
277
  break;
278
- case 0 /* DateKind.Unspecified */:
278
+ case DateTimeKind.Unspecified:
279
279
  utcOffsetText = dateOffsetToString(toLocalTime(localizedDate).getTimezoneOffset() * -60000);
280
280
  break;
281
281
  }
@@ -315,7 +315,7 @@ function dateToStringWithCustomFormat(date, format, utc) {
315
315
  result += dateToStringWithCustomFormat(localizedDate, String.fromCharCode(nextChar), utc);
316
316
  }
317
317
  else {
318
- throw new Error("Invalid format string");
318
+ throw new Exception("Invalid format string");
319
319
  }
320
320
  break;
321
321
  case "\\":
@@ -325,7 +325,7 @@ function dateToStringWithCustomFormat(date, format, utc) {
325
325
  result += String.fromCharCode(nextChar2);
326
326
  }
327
327
  else {
328
- throw new Error("Invalid format string");
328
+ throw new Exception("Invalid format string");
329
329
  }
330
330
  break;
331
331
  default:
@@ -336,8 +336,8 @@ function dateToStringWithCustomFormat(date, format, utc) {
336
336
  }
337
337
  return result;
338
338
  }
339
- export function kind(value) {
340
- return value.kind || 0;
339
+ export function getKind(value) {
340
+ return value.kind ?? DateTimeKind.Unspecified;
341
341
  }
342
342
  export function unixEpochMillisecondsToTicks(ms, offset) {
343
343
  return toInt64(((BigInt(ms) + 62135596800000n) + BigInt(offset)) * 10000n);
@@ -360,7 +360,7 @@ function dateToISOString(d, utc) {
360
360
  }
361
361
  else {
362
362
  // JS Date is always local
363
- const printOffset = d.kind == null ? true : d.kind === 2 /* DateKind.Local */;
363
+ const printOffset = d.kind == null ? true : d.kind === DateTimeKind.Local;
364
364
  return padWithZeros(d.getFullYear(), 4) + "-" +
365
365
  padWithZeros(d.getMonth() + 1, 2) + "-" +
366
366
  padWithZeros(d.getDate(), 2) + "T" +
@@ -388,7 +388,7 @@ function dateToStringWithOffset(date, format) {
388
388
  case "t": return dateToString_t(toUniversalTime(d));
389
389
  case "O":
390
390
  case "o": return dateToISOStringWithOffset(d, (date.offset ?? 0));
391
- default: throw new Error("Unrecognized Date print format");
391
+ default: throw new Exception("Unrecognized Date print format");
392
392
  }
393
393
  }
394
394
  else {
@@ -416,7 +416,7 @@ function dateToString_t(date) {
416
416
  + ":" + padWithZeros(minute(date), 2);
417
417
  }
418
418
  function dateToStringWithKind(date, format) {
419
- const utc = date.kind === 1 /* DateKind.UTC */;
419
+ const utc = date.kind === DateTimeKind.Utc;
420
420
  if (typeof format !== "string") {
421
421
  return utc ? date.toUTCString() : date.toLocaleString();
422
422
  }
@@ -430,7 +430,7 @@ function dateToStringWithKind(date, format) {
430
430
  case "o":
431
431
  return dateToISOString(date, utc);
432
432
  default:
433
- throw new Error("Unrecognized Date print format");
433
+ throw new Exception("Unrecognized Date print format");
434
434
  }
435
435
  }
436
436
  else {
@@ -444,24 +444,28 @@ export function toString(date, format, _provider) {
444
444
  }
445
445
  export function DateTime(value, kind) {
446
446
  const d = new Date(value);
447
- d.kind = (kind == null ? 0 /* DateKind.Unspecified */ : kind) | 0;
447
+ d.kind = (kind == null ? DateTimeKind.Unspecified : kind);
448
448
  return d;
449
449
  }
450
450
  export function fromTicks(ticks, kind) {
451
- kind = kind != null ? kind : 2 /* DateKind.Local */; // better default than Unspecified
451
+ kind = kind != null ? kind : DateTimeKind.Local; // better default than Unspecified
452
452
  let date = DateTime(ticksToUnixEpochMilliseconds(ticks), kind);
453
453
  // Ticks are local to offset (in this case, either UTC or Local/Unknown).
454
454
  // If kind is anything but UTC, that means that the tick number was not
455
455
  // in utc, thus getTime() cannot return UTC, and needs to be shifted.
456
- if (kind !== 1 /* DateKind.UTC */) {
456
+ if (kind !== DateTimeKind.Utc) {
457
457
  date = DateTime(date.getTime() - dateOffset(date), kind);
458
458
  }
459
459
  return date;
460
460
  }
461
+ export function fromDateTime(dateOnly, timeOnly, kind) {
462
+ const d = DateTime(dateOnly.getTime() + timeOnly, kind);
463
+ return DateTime(d.getTime() - dateOffset(d), kind);
464
+ }
461
465
  export function fromDateTimeOffset(date, kind) {
462
466
  switch (kind) {
463
- case 1 /* DateKind.UTC */: return DateTime(date.getTime(), 1 /* DateKind.UTC */);
464
- case 2 /* DateKind.Local */: return DateTime(date.getTime(), 2 /* DateKind.Local */);
467
+ case DateTimeKind.Utc: return DateTime(date.getTime(), DateTimeKind.Utc);
468
+ case DateTimeKind.Local: return DateTime(date.getTime(), DateTimeKind.Local);
465
469
  default:
466
470
  const d = DateTime(date.getTime() + (date.offset ?? 0), kind);
467
471
  return DateTime(d.getTime() - dateOffset(d), kind);
@@ -472,15 +476,15 @@ export function getTicks(date) {
472
476
  }
473
477
  export function minValue() {
474
478
  // This is "0001-01-01T00:00:00.000Z", actual JS min value is -8640000000000000
475
- return DateTime(-62135596800000, 1 /* DateKind.UTC */);
479
+ return DateTime(-62135596800000, DateTimeKind.Utc);
476
480
  }
477
481
  export function maxValue() {
478
482
  // This is "9999-12-31T23:59:59.999Z", actual JS max value is 8640000000000000
479
- return DateTime(253402300799999, 1 /* DateKind.UTC */);
483
+ return DateTime(253402300799999, DateTimeKind.Utc);
480
484
  }
481
485
  export function parseRaw(input) {
482
486
  function fail() {
483
- throw new Error(`The string is not a valid Date: ${input}`);
487
+ throw new Exception(`The string is not a valid Date: ${input}`);
484
488
  }
485
489
  if (input == null || input.trim() === "") {
486
490
  fail();
@@ -556,8 +560,8 @@ export function parse(str, detectUTC = false) {
556
560
  // .NET always parses DateTime as Local if there's offset info (even "Z")
557
561
  // Newtonsoft.Json uses UTC if the offset is "Z"
558
562
  const kind = offset != null
559
- ? (detectUTC && offset === "Z" ? 1 /* DateKind.UTC */ : 2 /* DateKind.Local */)
560
- : 0 /* DateKind.Unspecified */;
563
+ ? (detectUTC && offset === "Z" ? DateTimeKind.Utc : DateTimeKind.Local)
564
+ : DateTimeKind.Unspecified;
561
565
  return DateTime(date.getTime(), kind);
562
566
  }
563
567
  export function tryParse(v, defValue) {
@@ -570,11 +574,11 @@ export function tryParse(v, defValue) {
570
574
  }
571
575
  }
572
576
  export function create(year, month, day, h = 0, m = 0, s = 0, ms = 0, kind) {
573
- const date = kind === 1 /* DateKind.UTC */
577
+ const date = kind === DateTimeKind.Utc
574
578
  ? new Date(Date.UTC(year, month - 1, day, h, m, s, ms))
575
579
  : new Date(year, month - 1, day, h, m, s, ms);
576
580
  if (year <= 99) {
577
- if (kind === 1 /* DateKind.UTC */) {
581
+ if (kind === DateTimeKind.Utc) {
578
582
  date.setUTCFullYear(year, month - 1, day);
579
583
  }
580
584
  else {
@@ -583,15 +587,15 @@ export function create(year, month, day, h = 0, m = 0, s = 0, ms = 0, kind) {
583
587
  }
584
588
  const dateValue = date.getTime();
585
589
  if (isNaN(dateValue)) {
586
- throw new Error("The parameters describe an unrepresentable Date.");
590
+ throw new Exception("The parameters describe an unrepresentable Date.");
587
591
  }
588
592
  return DateTime(dateValue, kind);
589
593
  }
590
594
  export function now() {
591
- return DateTime(Date.now(), 2 /* DateKind.Local */);
595
+ return DateTime(Date.now(), DateTimeKind.Local);
592
596
  }
593
597
  export function utcNow() {
594
- return DateTime(Date.now(), 1 /* DateKind.UTC */);
598
+ return DateTime(Date.now(), DateTimeKind.Utc);
595
599
  }
596
600
  export function today() {
597
601
  return date(now());
@@ -605,10 +609,10 @@ export function daysInMonth(year, month) {
605
609
  : (month >= 8 ? (month % 2 === 0 ? 31 : 30) : (month % 2 === 0 ? 30 : 31));
606
610
  }
607
611
  export function toUniversalTime(date) {
608
- return date.kind === 1 /* DateKind.UTC */ ? date : DateTime(date.getTime(), 1 /* DateKind.UTC */);
612
+ return date.kind === DateTimeKind.Utc ? date : DateTime(date.getTime(), DateTimeKind.Utc);
609
613
  }
610
614
  export function toLocalTime(date) {
611
- return date.kind === 2 /* DateKind.Local */ ? date : DateTime(date.getTime(), 2 /* DateKind.Local */);
615
+ return date.kind === DateTimeKind.Local ? date : DateTime(date.getTime(), DateTimeKind.Local);
612
616
  }
613
617
  export function specifyKind(d, kind) {
614
618
  return create(year(d), month(d), day(d), hour(d), minute(d), second(d), millisecond(d), kind);
@@ -623,28 +627,28 @@ export function date(d) {
623
627
  return create(year(d), month(d), day(d), 0, 0, 0, 0, d.kind);
624
628
  }
625
629
  export function day(d) {
626
- return d.kind === 1 /* DateKind.UTC */ ? d.getUTCDate() : d.getDate();
630
+ return d.kind === DateTimeKind.Utc ? d.getUTCDate() : d.getDate();
627
631
  }
628
632
  export function hour(d) {
629
- return d.kind === 1 /* DateKind.UTC */ ? d.getUTCHours() : d.getHours();
633
+ return d.kind === DateTimeKind.Utc ? d.getUTCHours() : d.getHours();
630
634
  }
631
635
  export function millisecond(d) {
632
- return d.kind === 1 /* DateKind.UTC */ ? d.getUTCMilliseconds() : d.getMilliseconds();
636
+ return d.kind === DateTimeKind.Utc ? d.getUTCMilliseconds() : d.getMilliseconds();
633
637
  }
634
638
  export function minute(d) {
635
- return d.kind === 1 /* DateKind.UTC */ ? d.getUTCMinutes() : d.getMinutes();
639
+ return d.kind === DateTimeKind.Utc ? d.getUTCMinutes() : d.getMinutes();
636
640
  }
637
641
  export function month(d) {
638
- return (d.kind === 1 /* DateKind.UTC */ ? d.getUTCMonth() : d.getMonth()) + 1;
642
+ return (d.kind === DateTimeKind.Utc ? d.getUTCMonth() : d.getMonth()) + 1;
639
643
  }
640
644
  export function second(d) {
641
- return d.kind === 1 /* DateKind.UTC */ ? d.getUTCSeconds() : d.getSeconds();
645
+ return d.kind === DateTimeKind.Utc ? d.getUTCSeconds() : d.getSeconds();
642
646
  }
643
647
  export function year(d) {
644
- return d.kind === 1 /* DateKind.UTC */ ? d.getUTCFullYear() : d.getFullYear();
648
+ return d.kind === DateTimeKind.Utc ? d.getUTCFullYear() : d.getFullYear();
645
649
  }
646
650
  export function dayOfWeek(d) {
647
- return d.kind === 1 /* DateKind.UTC */ ? d.getUTCDay() : d.getDay();
651
+ return d.kind === DateTimeKind.Utc ? d.getUTCDay() : d.getDay();
648
652
  }
649
653
  export function dayOfYear(d) {
650
654
  const _year = year(d);
@@ -657,7 +661,7 @@ export function dayOfYear(d) {
657
661
  }
658
662
  export function add(d, ts) {
659
663
  const newDate = DateTime(d.getTime() + ts, d.kind);
660
- if (d.kind !== 1 /* DateKind.UTC */) {
664
+ if (d.kind !== DateTimeKind.Utc) {
661
665
  const oldTzOffset = d.getTimezoneOffset();
662
666
  const newTzOffset = newDate.getTimezoneOffset();
663
667
  return oldTzOffset !== newTzOffset
package/DateOffset.js CHANGED
@@ -13,8 +13,8 @@
13
13
  * Basically; invariant: date.getTime() always return UTC time.
14
14
  */
15
15
  import { fromFloat64, toFloat64 } from "./BigInt.js";
16
- import DateTime, { create as createDate, dateOffsetToString, daysInMonth, parseRaw, ticksToUnixEpochMilliseconds, unixEpochMillisecondsToTicks } from "./Date.js";
17
- import { compareDates, padWithZeros } from "./Util.js";
16
+ import DateTime, { create as createDate, daysInMonth, parseRaw, ticksToUnixEpochMilliseconds, unixEpochMillisecondsToTicks } from "./Date.js";
17
+ import { Exception, compareDates, DateTimeKind } from "./Util.js";
18
18
  export default function DateTimeOffset(value, offset) {
19
19
  checkOffsetInRange(offset);
20
20
  const d = new Date(value);
@@ -27,29 +27,29 @@ export function offset(value) {
27
27
  function checkOffsetInRange(offset) {
28
28
  if (offset != null && offset !== 0) {
29
29
  if (offset % 60000 !== 0) {
30
- throw new Error("Offset must be specified in whole minutes.");
30
+ throw new Exception("Offset must be specified in whole minutes.");
31
31
  }
32
32
  if (Math.abs(offset / 3600000) > 14) {
33
- throw new Error("Offset must be within plus or minus 14 hours.");
33
+ throw new Exception("Offset must be within plus or minus 14 hours.");
34
34
  }
35
35
  }
36
36
  }
37
37
  export function fromDate(date, offset) {
38
38
  let offset2 = 0;
39
39
  switch (date.kind) {
40
- case 1 /* DateKind.UTC */:
40
+ case DateTimeKind.Utc:
41
41
  if (offset != null && offset !== 0) {
42
- throw new Error("The UTC Offset for Utc DateTime instances must be 0.");
42
+ throw new Exception("The UTC Offset for Utc DateTime instances must be 0.");
43
43
  }
44
44
  offset2 = 0;
45
45
  break;
46
- case 2 /* DateKind.Local */:
46
+ case DateTimeKind.Local:
47
47
  offset2 = date.getTimezoneOffset() * -60000;
48
48
  if (offset != null && offset !== offset2) {
49
- throw new Error("The UTC Offset of the local dateTime parameter does not match the offset argument.");
49
+ throw new Exception("The UTC Offset of the local dateTime parameter does not match the offset argument.");
50
50
  }
51
51
  break;
52
- case 0 /* DateKind.Unspecified */:
52
+ case DateTimeKind.Unspecified:
53
53
  default:
54
54
  if (offset == null) {
55
55
  offset2 = date.getTimezoneOffset() * -60000;
@@ -61,6 +61,9 @@ export function fromDate(date, offset) {
61
61
  }
62
62
  return DateTimeOffset(date.getTime(), offset2);
63
63
  }
64
+ export function fromDateTime(dateOnly, timeOnly, offset) {
65
+ return DateTimeOffset(dateOnly.getTime() - offset + timeOnly, offset);
66
+ }
64
67
  export function fromTicks(ticks, offset) {
65
68
  const ms = ticksToUnixEpochMilliseconds(ticks) - offset;
66
69
  return DateTimeOffset(ms, offset);
@@ -104,85 +107,72 @@ export function create(year, month, day, h, m, s, ms, offset) {
104
107
  ms = 0;
105
108
  }
106
109
  checkOffsetInRange(offset);
107
- let date;
108
- if (offset === 0) {
109
- date = new Date(Date.UTC(year, month - 1, day, h, m, s, ms));
110
- if (year <= 99) {
111
- date.setUTCFullYear(year, month - 1, day);
112
- }
113
- }
114
- else {
115
- const str = padWithZeros(year, 4) + "-" +
116
- padWithZeros(month, 2) + "-" +
117
- padWithZeros(day, 2) + "T" +
118
- padWithZeros(h, 2) + ":" +
119
- padWithZeros(m, 2) + ":" +
120
- padWithZeros(s, 2) + "." +
121
- padWithZeros(ms, 3) +
122
- dateOffsetToString(offset);
123
- date = new Date(str);
110
+ let date = new Date(Date.UTC(year, month - 1, day, h, m, s, ms) - offset);
111
+ if (year <= 99) {
112
+ date.setUTCFullYear(year, month - 1, day);
124
113
  }
125
114
  const dateValue = date.getTime();
126
115
  if (isNaN(dateValue)) {
127
- throw new Error("The parameters describe an unrepresentable Date");
116
+ throw new Exception("The parameters describe an unrepresentable Date");
128
117
  }
129
118
  return DateTimeOffset(dateValue, offset);
130
119
  }
131
120
  export function now() {
132
121
  const date = new Date();
133
122
  const offset = date.getTimezoneOffset() * -60000;
134
- return DateTimeOffset(date.getTime(), offset);
123
+ return DateTimeOffset(date.getTime() - offset, offset);
135
124
  }
136
125
  export function utcNow() {
137
- const date = now();
126
+ const date = new Date();
127
+ // const offset = date.getTimezoneOffset() * -60_000;
138
128
  return DateTimeOffset(date.getTime(), 0);
139
129
  }
140
130
  export function toUniversalTime(date) {
141
- return DateTime(date.getTime(), 1 /* DateKind.UTC */);
131
+ return DateTime(date.getTime(), DateTimeKind.Utc);
142
132
  }
143
133
  export function toLocalTime(date) {
144
- return DateTime(date.getTime() + offset(now()), 2 /* DateKind.Local */);
134
+ return DateTime(date.getTime(), DateTimeKind.Local);
145
135
  }
146
136
  export function localDateTime(date) {
147
- return DateTime(date.getTime(), 2 /* DateKind.Local */);
137
+ return DateTime(date.getTime(), DateTimeKind.Local);
148
138
  }
149
139
  export function timeOfDay(d) {
150
- const d2 = new Date(d.getTime() + (d.offset ?? 0));
140
+ const d2 = new Date(d.getTime() + offset(d));
151
141
  return d2.getUTCHours() * 3600000
152
142
  + d2.getUTCMinutes() * 60000
153
143
  + d2.getUTCSeconds() * 1000
154
144
  + d2.getUTCMilliseconds();
155
145
  }
156
146
  export function date(d) {
157
- const d2 = new Date(d.getTime() + (d.offset ?? 0));
147
+ const d2 = new Date(d.getTime() + offset(d));
158
148
  return createDate(d2.getUTCFullYear(), d2.getUTCMonth() + 1, d2.getUTCDate(), 0, 0, 0, 0);
159
149
  }
160
150
  export function day(d) {
161
- return new Date(d.getTime() + (d.offset ?? 0)).getUTCDate();
151
+ return new Date(d.getTime() + offset(d)).getUTCDate();
162
152
  }
163
153
  export function hour(d) {
164
- return new Date(d.getTime() + (d.offset ?? 0)).getUTCHours();
154
+ return new Date(d.getTime() + offset(d)).getUTCHours();
165
155
  }
166
156
  export function millisecond(d) {
167
- return new Date(d.getTime() + (d.offset ?? 0)).getUTCMilliseconds();
157
+ return new Date(d.getTime() + offset(d)).getUTCMilliseconds();
168
158
  }
169
159
  export function minute(d) {
170
- return new Date(d.getTime() + (d.offset ?? 0)).getUTCMinutes();
160
+ return new Date(d.getTime() + offset(d)).getUTCMinutes();
171
161
  }
172
162
  export function month(d) {
173
- return new Date(d.getTime() + (d.offset ?? 0)).getUTCMonth() + 1;
163
+ return new Date(d.getTime() + offset(d)).getUTCMonth() + 1;
174
164
  }
175
165
  export function second(d) {
176
- return new Date(d.getTime() + (d.offset ?? 0)).getUTCSeconds();
166
+ return new Date(d.getTime() + offset(d)).getUTCSeconds();
177
167
  }
178
168
  export function year(d) {
179
- return new Date(d.getTime() + (d.offset ?? 0)).getUTCFullYear();
169
+ return new Date(d.getTime() + offset(d)).getUTCFullYear();
180
170
  }
181
171
  export function dayOfWeek(d) {
182
- return new Date(d.getTime() + (d.offset ?? 0)).getUTCDay();
172
+ return new Date(d.getTime() + offset(d)).getUTCDay();
183
173
  }
184
174
  export function dayOfYear(d) {
185
- const d2 = new Date(d.getTime() + (d.offset ?? 0));
175
+ const d2 = new Date(d.getTime() + offset(d));
186
176
  const _year = d2.getUTCFullYear();
187
177
  const _month = d2.getUTCMonth() + 1;
188
178
  let _day = d2.getUTCDate();
@@ -192,7 +182,7 @@ export function dayOfYear(d) {
192
182
  return _day;
193
183
  }
194
184
  export function add(d, ts) {
195
- return DateTimeOffset(d.getTime() + ts, (d.offset ?? 0));
185
+ return DateTimeOffset(d.getTime() + ts, offset(d));
196
186
  }
197
187
  export function addDays(d, v) {
198
188
  return add(d, v * 86400000);
@@ -217,10 +207,10 @@ export function addYears(d, v) {
217
207
  const newYear = d.getUTCFullYear() + v;
218
208
  const _daysInMonth = daysInMonth(newYear, newMonth);
219
209
  const newDay = Math.min(_daysInMonth, d.getUTCDate());
220
- return create(newYear, newMonth, newDay, d.getUTCHours(), d.getUTCMinutes(), d.getUTCSeconds(), d.getUTCMilliseconds(), (d.offset ?? 0));
210
+ return create(newYear, newMonth, newDay, d.getUTCHours(), d.getUTCMinutes(), d.getUTCSeconds(), d.getUTCMilliseconds(), offset(d));
221
211
  }
222
212
  export function addMonths(d, v) {
223
- const d2 = new Date(d.getTime() + (d.offset ?? 0));
213
+ const d2 = new Date(d.getTime() + offset(d));
224
214
  let newMonth = d2.getUTCMonth() + 1 + v;
225
215
  let newMonth_ = 0;
226
216
  let yearOffset = 0;
@@ -237,11 +227,11 @@ export function addMonths(d, v) {
237
227
  const newYear = d2.getUTCFullYear() + yearOffset;
238
228
  const _daysInMonth = daysInMonth(newYear, newMonth);
239
229
  const newDay = Math.min(_daysInMonth, d2.getUTCDate());
240
- return create(newYear, newMonth, newDay, d2.getUTCHours(), d2.getUTCMinutes(), d2.getUTCSeconds(), d2.getUTCMilliseconds(), (d.offset ?? 0));
230
+ return create(newYear, newMonth, newDay, d2.getUTCHours(), d2.getUTCMinutes(), d2.getUTCSeconds(), d2.getUTCMilliseconds(), offset(d));
241
231
  }
242
232
  export function subtract(d, that) {
243
233
  return typeof that === "number"
244
- ? DateTimeOffset(d.getTime() - that, (d.offset ?? 0))
234
+ ? DateTimeOffset(d.getTime() - that, offset(d))
245
235
  : d.getTime() - that.getTime();
246
236
  }
247
237
  export function equals(d1, d2) {
package/DateOnly.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { DateTime, getTicks, dayOfYear as Date_dayOfYear, year as Date_year, month as Date_month, day as Date_day, daysInMonth as Date_daysInMonth, ticksToUnixEpochMilliseconds } from "./Date.js";
2
- import { padWithZeros } from "./Util.js";
2
+ import { Exception, DateTimeKind, padWithZeros } from "./Util.js";
3
3
  export function fromUnixMilliseconds(value) {
4
- return DateTime(value, 1 /* DateKind.UTC */);
4
+ return DateTime(value, DateTimeKind.Utc);
5
5
  }
6
6
  export function create(year, month, day) {
7
7
  const d = fromUnixMilliseconds(Date.UTC(year, month - 1, day));
@@ -43,12 +43,12 @@ export function dayOfWeek(d) {
43
43
  export function dayOfYear(d) {
44
44
  return Date_dayOfYear(d);
45
45
  }
46
- export function toDateTime(d, time, kind = 0 /* DateKind.Unspecified */) {
47
- return DateTime(d.getTime() + time + (kind !== 1 /* DateKind.UTC */ ? d.getTimezoneOffset() : 0) * 60000, kind);
46
+ export function toDateTime(d, time, kind = DateTimeKind.Unspecified) {
47
+ return DateTime(d.getTime() + time + (kind !== DateTimeKind.Utc ? d.getTimezoneOffset() : 0) * 60000, kind);
48
48
  }
49
49
  export function toString(d, format = "d", _provider) {
50
50
  if (["d", "o", "O"].indexOf(format) === -1) {
51
- throw new Error("Custom formats are not supported");
51
+ throw new Exception("Custom formats are not supported");
52
52
  }
53
53
  const y = padWithZeros(year(d), 4);
54
54
  const m = padWithZeros(month(d), 2);
@@ -57,7 +57,7 @@ export function toString(d, format = "d", _provider) {
57
57
  }
58
58
  export function parse(str) {
59
59
  function fail() {
60
- throw new Error(`String '${str}' was not recognized as a valid DateOnly.`);
60
+ throw new Exception(`String '${str}' was not recognized as a valid DateOnly.`);
61
61
  }
62
62
  // Allowed separators: . , / -
63
63
  // TODO whitespace alone as the separator
package/Decimal.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import Decimal from "./lib/big.js";
2
2
  import { symbol } from "./Numeric.js";
3
3
  import { FSharpRef } from "./Types.js";
4
- import { combineHashCodes } from "./Util.js";
4
+ import { Exception, combineHashCodes } from "./Util.js";
5
5
  import { fromDecimal } from "./BigInt.js";
6
6
  import * as bigInt from "./BigInt.js";
7
7
  Decimal.prototype.GetHashCode = function () {
@@ -109,7 +109,7 @@ export function parse(str) {
109
109
  return defValue.contents;
110
110
  }
111
111
  else {
112
- throw new Error(`The input string ${str} was not in a correct format.`);
112
+ throw new Exception(`The input string ${str} was not in a correct format.`);
113
113
  }
114
114
  }
115
115
  export function toNumber(x) {
@@ -118,7 +118,7 @@ export function toNumber(x) {
118
118
  export function toChar(x) {
119
119
  const n = toNumber(x);
120
120
  if (n < 0 || n > 65535 || isNaN(n)) {
121
- throw new Error("Value was either too large or too small for a character.");
121
+ throw new Exception("Value was either too large or too small for a character.");
122
122
  }
123
123
  return String.fromCharCode(n);
124
124
  }
@@ -221,7 +221,7 @@ export function getBits(d) {
221
221
  // export function makeRangeStepFunction(step: Decimal, last: Decimal) {
222
222
  // const stepComparedWithZero = step.cmp(get_Zero);
223
223
  // if (stepComparedWithZero === 0) {
224
- // throw new Error("The step of a range cannot be zero");
224
+ // throw new Exception("The step of a range cannot be zero");
225
225
  // }
226
226
  // const stepGreaterThanZero = stepComparedWithZero > 0;
227
227
  // return (x: Decimal) => {
package/Double.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { FSharpRef } from "./Types.js";
2
+ import { Exception } from "./Util.js";
2
3
  export function tryParse(str, defValue) {
3
4
  // TODO: test if value is valid and in range
4
5
  if (str != null && /\S/.test(str)) {
@@ -16,7 +17,7 @@ export function parse(str) {
16
17
  return defValue.contents;
17
18
  }
18
19
  else {
19
- throw new Error(`The input string ${str} was not in a correct format.`);
20
+ throw new Exception(`The input string ${str} was not in a correct format.`);
20
21
  }
21
22
  }
22
23
  // JS Number.isFinite function evals false for NaN
@@ -1,27 +1,45 @@
1
- import { compare, physicalHash, equals, structuralHash } from "./Util.js";
2
- export function HashIdentity_FromFunctions(hash, eq) {
1
+ import { compare, physicalHash, equals as equals_1, structuralHash } from "./Util.js";
2
+ export function HashIdentity_FromFunctions(hasher, equals) {
3
3
  return {
4
- Equals(x, y) {
5
- return eq(x, y);
4
+ GetHashCode(x) {
5
+ return hasher(x) | 0;
6
6
  },
7
- GetHashCode(x_1) {
8
- return hash(x_1) | 0;
7
+ Equals(x_1, y) {
8
+ return (x_1 == null) ? (y == null) : ((y == null) ? false : equals(x_1, y));
9
9
  },
10
10
  };
11
11
  }
12
12
  export function HashIdentity_Structural() {
13
- return HashIdentity_FromFunctions((obj) => (structuralHash(obj) | 0), equals);
13
+ return {
14
+ GetHashCode(x) {
15
+ return structuralHash(x) | 0;
16
+ },
17
+ Equals(x_1, y) {
18
+ return equals_1(x_1, y);
19
+ },
20
+ };
14
21
  }
15
22
  export function HashIdentity_Reference() {
16
- return HashIdentity_FromFunctions((obj) => (physicalHash(obj) | 0), (e, e_1) => (e === e_1));
23
+ return {
24
+ GetHashCode(x) {
25
+ return physicalHash(x) | 0;
26
+ },
27
+ Equals(x_1, y) {
28
+ return equals_1(x_1, y);
29
+ },
30
+ };
17
31
  }
18
32
  export function ComparisonIdentity_FromFunction(comparer) {
19
33
  return {
20
34
  Compare(x, y) {
21
- return comparer(x, y) | 0;
35
+ return ((x == null) ? ((y == null) ? 0 : -1) : ((y == null) ? 1 : comparer(x, y))) | 0;
22
36
  },
23
37
  };
24
38
  }
25
39
  export function ComparisonIdentity_Structural() {
26
- return ComparisonIdentity_FromFunction((e, e_1) => (compare(e, e_1) | 0));
40
+ return {
41
+ Compare(x, y) {
42
+ return compare(x, y) | 0;
43
+ },
44
+ };
27
45
  }