@fable-org/fable-library-ts 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 (55) hide show
  1. package/Array.ts +1385 -1378
  2. package/Async.ts +13 -12
  3. package/AsyncBuilder.ts +10 -11
  4. package/BigInt.ts +6 -6
  5. package/BitConverter.ts +3 -3
  6. package/Boolean.ts +3 -2
  7. package/CHANGELOG.md +12 -0
  8. package/Char.ts +38 -35
  9. package/Choice.ts +326 -301
  10. package/CollectionUtil.ts +4 -4
  11. package/Date.ts +67 -62
  12. package/DateOffset.ts +48 -57
  13. package/DateOnly.ts +8 -8
  14. package/Decimal.ts +9 -9
  15. package/Double.ts +3 -2
  16. package/Encoding.ts +1 -1
  17. package/Event.ts +3 -3
  18. package/FSharp.Collections.ts +53 -34
  19. package/FSharp.Core.CompilerServices.ts +38 -37
  20. package/FSharp.Core.ts +186 -185
  21. package/Global.ts +80 -37
  22. package/Guid.ts +7 -6
  23. package/Int32.ts +20 -17
  24. package/List.ts +1429 -1417
  25. package/Long.ts +6 -5
  26. package/MailboxProcessor.ts +8 -7
  27. package/Map.ts +1550 -1552
  28. package/MapUtil.ts +5 -5
  29. package/MutableMap.ts +358 -345
  30. package/MutableSet.ts +250 -249
  31. package/Native.ts +19 -11
  32. package/Numeric.ts +1 -1
  33. package/Observable.ts +3 -3
  34. package/Option.ts +10 -4
  35. package/Random.ts +196 -194
  36. package/Range.ts +57 -56
  37. package/Reflection.ts +73 -40
  38. package/RegExp.ts +5 -3
  39. package/Result.ts +201 -196
  40. package/Seq.ts +1517 -1525
  41. package/Seq2.ts +130 -129
  42. package/Set.ts +1955 -1955
  43. package/String.ts +41 -38
  44. package/System.Collections.Generic.ts +401 -380
  45. package/System.Text.ts +204 -203
  46. package/System.ts +366 -0
  47. package/TimeOnly.ts +10 -10
  48. package/TimeSpan.ts +11 -11
  49. package/Timer.ts +2 -2
  50. package/Types.ts +1 -19
  51. package/Uri.ts +13 -10
  52. package/Util.ts +77 -21
  53. package/package.json +22 -22
  54. package/tsconfig.json +18 -5
  55. package/SystemException.ts +0 -7
package/String.ts CHANGED
@@ -1,7 +1,8 @@
1
- import { toString as dateToString } from "./Date.js";
2
- import { compare as numericCompare, isNumeric, isIntegral, multiply, Numeric, toExponential, toFixed, toHex, toPrecision } from "./Numeric.js";
3
- import { escape } from "./RegExp.js";
4
- import { toString } from "./Types.js";
1
+ import { toString as dateToString } from "./Date.ts";
2
+ import { compare as numericCompare, isNumeric, isIntegral, multiply, Numeric, toExponential, toFixed, toHex, toPrecision } from "./Numeric.ts";
3
+ import { escape } from "./RegExp.ts";
4
+ import { toString } from "./Types.ts";
5
+ import { Exception } from "./Util.ts";
5
6
 
6
7
  const fsFormatRegExp = /(^|[^%])%([0+\- ]*)(\*|\d+)?(?:\.(\d+))?(\w)/g;
7
8
  const interpolateRegExp = /(?:(^|[^%])%([0+\- ]*)(\d+)?(?:\.(\d+))?(\w))?%P\(\)/g;
@@ -11,14 +12,16 @@ function isLessThan(x: Numeric, y: number) {
11
12
  return numericCompare(x, y) < 0;
12
13
  }
13
14
 
14
- const enum StringComparison {
15
- CurrentCulture = 0,
16
- CurrentCultureIgnoreCase = 1,
17
- InvariantCulture = 2,
18
- InvariantCultureIgnoreCase = 3,
19
- Ordinal = 4,
20
- OrdinalIgnoreCase = 5,
21
- }
15
+ export const StringComparison = {
16
+ CurrentCulture: 0,
17
+ CurrentCultureIgnoreCase: 1,
18
+ InvariantCulture: 2,
19
+ InvariantCultureIgnoreCase: 3,
20
+ Ordinal: 4,
21
+ OrdinalIgnoreCase: 5,
22
+ } as const;
23
+
24
+ export type StringComparison = typeof StringComparison[keyof typeof StringComparison];
22
25
 
23
26
  function cmp(x: string, y: string, ic: boolean | StringComparison) {
24
27
  function isIgnoreCase(i: boolean | StringComparison) {
@@ -48,10 +51,10 @@ export function compare(...args: any[]): number {
48
51
  case 2: return cmp(args[0], args[1], false);
49
52
  case 3: return cmp(args[0], args[1], args[2]);
50
53
  case 4: return cmp(args[0], args[1], args[2] === true);
51
- case 5: return cmp(args[0].substr(args[1], args[4]), args[2].substr(args[3], args[4]), false);
52
- case 6: return cmp(args[0].substr(args[1], args[4]), args[2].substr(args[3], args[4]), args[5]);
53
- case 7: return cmp(args[0].substr(args[1], args[4]), args[2].substr(args[3], args[4]), args[5] === true);
54
- default: throw new Error("String.compare: Unsupported number of parameters");
54
+ case 5: return cmp(args[0].slice(args[1], args[1] + args[4]), args[2].slice(args[3], args[3] + args[4]), false);
55
+ case 6: return cmp(args[0].slice(args[1], args[1] + args[4]), args[2].slice(args[3], args[3] + args[4]), args[5]);
56
+ case 7: return cmp(args[0].slice(args[1], args[1] + args[4]), args[2].slice(args[3], args[3] + args[4]), args[5] === true);
57
+ default: throw new Exception("String.compare: Unsupported number of parameters");
55
58
  }
56
59
  }
57
60
 
@@ -68,7 +71,7 @@ export function startsWith(str: string, pattern: string, ic: boolean | StringCom
68
71
  return str.startsWith(pattern);
69
72
  }
70
73
  if (str.length >= pattern.length) {
71
- return cmp(str.substr(0, pattern.length), pattern, ic) === 0;
74
+ return cmp(str.slice(0, pattern.length), pattern, ic) === 0;
72
75
  }
73
76
  return false;
74
77
  }
@@ -78,7 +81,7 @@ export function endsWith(str: string, pattern: string, ic: boolean | StringCompa
78
81
  return str.endsWith(pattern);
79
82
  }
80
83
  if (str.length >= pattern.length) {
81
- return cmp(str.substr(str.length - pattern.length, pattern.length), pattern, ic) === 0;
84
+ return cmp(str.slice(-pattern.length), pattern, ic) === 0;
82
85
  }
83
86
  return false;
84
87
  }
@@ -89,14 +92,14 @@ export function indexOfAny(str: string, anyOf: string[], ...args: number[]) {
89
92
  }
90
93
  const startIndex = (args.length > 0) ? args[0] : 0;
91
94
  if (startIndex < 0) {
92
- throw new Error("Start index cannot be negative");
95
+ throw new Exception("Start index cannot be negative");
93
96
  }
94
97
  const length = (args.length > 1) ? args[1] : str.length - startIndex;
95
98
  if (length < 0) {
96
- throw new Error("Length cannot be negative");
99
+ throw new Exception("Length cannot be negative");
97
100
  }
98
101
  if (startIndex + length > str.length) {
99
- throw new Error("Invalid startIndex and length");
102
+ throw new Exception("Invalid startIndex and length");
100
103
  }
101
104
  const endIndex = startIndex + length
102
105
  const anyOfAsStr = "".concat.apply("", anyOf);
@@ -166,7 +169,7 @@ export function toText(arg: IPrintfFormat | string) {
166
169
 
167
170
  export function toFail(arg: IPrintfFormat | string) {
168
171
  return continuePrint((x: string) => {
169
- throw new Error(x);
172
+ throw new Exception(x);
170
173
  }, arg);
171
174
  }
172
175
 
@@ -246,7 +249,7 @@ function createPrinter(cont: (...args: any[]) => any, _strParts: string[], _matc
246
249
  }
247
250
  else if (padLength === "*") {
248
251
  if (arg < 0) {
249
- throw new Error("Non-negative number required");
252
+ throw new Exception("Non-negative number required");
250
253
  }
251
254
  padArg = arg;
252
255
  continue;
@@ -320,7 +323,7 @@ export function format(str: string | object, ...args: any[]) {
320
323
 
321
324
  return str2.replace(formatRegExp, (_, idx: number, padLength, format, precision, pattern) => {
322
325
  if (idx < 0 || idx >= args.length) {
323
- throw new Error("Index must be greater or equal to zero and less than the arguments' length.")
326
+ throw new Exception("Index must be greater or equal to zero and less than the arguments' length.")
324
327
  }
325
328
  let rep = args[idx];
326
329
  let parts;
@@ -329,7 +332,7 @@ export function format(str: string | object, ...args: any[]) {
329
332
  switch (format) {
330
333
  case "b": case "B":
331
334
  if (!isIntegral(rep)) {
332
- throw new Error("Format specifier was invalid.");
335
+ throw new Exception("Format specifier was invalid.");
333
336
  }
334
337
  rep = (rep >>> 0).toString(2).replace(/^0+/, "").padStart(precision || 1, "0");
335
338
  break;
@@ -348,7 +351,7 @@ export function format(str: string | object, ...args: any[]) {
348
351
  break;
349
352
  case "d": case "D":
350
353
  if (!isIntegral(rep)) {
351
- throw new Error("Format specifier was invalid.");
354
+ throw new Exception("Format specifier was invalid.");
352
355
  }
353
356
  rep = String(rep);
354
357
  if (precision != null) {
@@ -388,10 +391,10 @@ export function format(str: string | object, ...args: any[]) {
388
391
  rep = thousandSeparate(parts.integral) + "." + padRight(parts.decimal, precision, "0") + " %";
389
392
  break;
390
393
  case "r": case "R":
391
- throw new Error("The round-trip format is not supported by Fable");
394
+ throw new Exception("The round-trip format is not supported by Fable");
392
395
  case "x": case "X":
393
396
  if (!isIntegral(rep)) {
394
- throw new Error("Format specifier was invalid.");
397
+ throw new Exception("Format specifier was invalid.");
395
398
  }
396
399
  precision = precision != null ? precision : 2;
397
400
  rep = padLeft(toHex(rep), precision, "0");
@@ -403,7 +406,7 @@ export function format(str: string | object, ...args: any[]) {
403
406
  // If we have format and were not able to handle it throw
404
407
  // See: https://learn.microsoft.com/en-us/dotnet/standard/base-types/standard-numeric-format-strings#standard-format-specifiers
405
408
  if (format) {
406
- throw new Error("Format specifier was invalid.");
409
+ throw new Exception("Format specifier was invalid.");
407
410
  }
408
411
 
409
412
  if (pattern) {
@@ -461,7 +464,7 @@ export function format(str: string | object, ...args: any[]) {
461
464
 
462
465
  export function initialize(n: number, f: (i: number) => string) {
463
466
  if (n < 0) {
464
- throw new Error("String length must be non-negative");
467
+ throw new Exception("String length must be non-negative");
465
468
  }
466
469
  const xs = new Array(n);
467
470
  for (let i = 0; i < n; i++) {
@@ -472,7 +475,7 @@ export function initialize(n: number, f: (i: number) => string) {
472
475
 
473
476
  export function insert(str: string, startIndex: number, value: string) {
474
477
  if (startIndex < 0 || startIndex > str.length) {
475
- throw new Error("startIndex is negative or greater than the length of this instance.");
478
+ throw new Exception("startIndex is negative or greater than the length of this instance.");
476
479
  }
477
480
  return str.substring(0, startIndex) + value + str.substring(startIndex);
478
481
  }
@@ -500,13 +503,13 @@ export function join<T>(delimiter: string, xs: Iterable<T>): string {
500
503
  export function joinWithIndices(delimiter: string, xs: string[], startIndex: number, count: number) {
501
504
  const endIndexPlusOne = startIndex + count;
502
505
  if (endIndexPlusOne > xs.length) {
503
- throw new Error("Index and count must refer to a location within the buffer.");
506
+ throw new Exception("Index and count must refer to a location within the buffer.");
504
507
  }
505
508
  return xs.slice(startIndex, endIndexPlusOne).join(delimiter);
506
509
  }
507
510
 
508
511
  function notSupported(name: string): never {
509
- throw new Error("The environment doesn't support '" + name + "', please use a polyfill.");
512
+ throw new Exception("The environment doesn't support '" + name + "', please use a polyfill.");
510
513
  }
511
514
 
512
515
  export function toBase64String(inArray: ArrayLike<number>) {
@@ -545,10 +548,10 @@ export function padRight(str: string, len: number, ch?: string) {
545
548
 
546
549
  export function remove(str: string, startIndex: number, count?: number) {
547
550
  if (startIndex >= str.length) {
548
- throw new Error("startIndex must be less than length of string");
551
+ throw new Exception("startIndex must be less than length of string");
549
552
  }
550
553
  if (typeof count === "number" && (startIndex + count) > str.length) {
551
- throw new Error("Index and count must refer to a location within the string.");
554
+ throw new Exception("Index and count must refer to a location within the string.");
552
555
  }
553
556
  return str.slice(0, startIndex) + (typeof count === "number" ? str.substr(startIndex + count) : "");
554
557
  }
@@ -563,7 +566,7 @@ export function replicate(n: number, x: string) {
563
566
 
564
567
  export function getCharAtIndex(input: string, index: number) {
565
568
  if (index < 0 || index >= input.length) {
566
- throw new Error("Index was outside the bounds of the array.");
569
+ throw new Exception("Index was outside the bounds of the array.");
567
570
  }
568
571
  return input[index];
569
572
  }
@@ -572,7 +575,7 @@ export function split(str: string, splitters: string[], count?: number, options?
572
575
  count = typeof count === "number" ? count : undefined;
573
576
  options = typeof options === "number" ? options : 0;
574
577
  if (count && count < 0) {
575
- throw new Error("Count cannot be less than zero");
578
+ throw new Exception("Count cannot be less than zero");
576
579
  }
577
580
  if (count === 0) {
578
581
  return [];
@@ -643,7 +646,7 @@ export function filter(pred: (char: string) => boolean, x: string) {
643
646
 
644
647
  export function substring(str: string, startIndex: number, length?: number) {
645
648
  if ((startIndex + (length || 0) > str.length)) {
646
- throw new Error("Invalid startIndex and/or length");
649
+ throw new Exception("Invalid startIndex and/or length");
647
650
  }
648
651
  return length != null ? str.substr(startIndex, length) : str.substr(startIndex);
649
652
  }