@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/Util.ts CHANGED
@@ -1,12 +1,40 @@
1
- // Don't change, this corresponds to DateTime.Kind enum values in .NET
2
- export const enum DateKind {
3
- Unspecified = 0,
4
- UTC = 1,
5
- Local = 2,
6
- }
1
+ export type Nullable<T> = T | null | undefined;
2
+
3
+ export interface MutableArray<T> extends Iterable<T> {
4
+ readonly length: number;
5
+ [index: number]: T;
6
+ every(predicate: (value: T, index: number, array: this) => unknown, thisArg?: any): boolean;
7
+ fill(value: T, start?: number, end?: number): this;
8
+ filter(predicate: (value: T, index: number, array: this) => unknown, thisArg?: any): this;
9
+ find(predicate: (value: T, index: number, array: this) => unknown, thisArg?: any): T | undefined;
10
+ findIndex(predicate: (value: T, index: number, array: this) => unknown, thisArg?: any): number;
11
+ forEach(callbackfn: (value: T, index: number, array: this) => void, thisArg?: any): void;
12
+ indexOf(searchElement: T, fromIndex?: number): number;
13
+ join(separator?: string): string;
14
+ lastIndexOf(searchElement: T, fromIndex?: number): number;
15
+ reduce(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: this) => T): T;
16
+ reduce(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: this) => T, initialValue: T): T;
17
+ reduce<U>(callbackfn: (previousValue: U, currentValue: T, currentIndex: number, array: this) => U, initialValue: U): U;
18
+ reduceRight(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: this) => T): T;
19
+ reduceRight(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: this) => T, initialValue: T): T;
20
+ reduceRight<U>(callbackfn: (previousValue: U, currentValue: T, currentIndex: number, array: this) => U, initialValue: U): U;
21
+ reverse(): this;
22
+ slice(start?: number, end?: number): this;
23
+ some(predicate: (value: T, index: number, array: this) => unknown, thisArg?: any): boolean;
24
+ sort(compareFn?: (a: T, b: T) => number): this;
25
+ }
26
+
27
+ // Don't change, this corresponds to DateTimeKind.Kind enum values in .NET
28
+ export const DateTimeKind = {
29
+ Unspecified: 0,
30
+ Utc: 1,
31
+ Local: 2,
32
+ } as const;
33
+
34
+ export type DateTimeKind = typeof DateTimeKind[keyof typeof DateTimeKind];
7
35
 
8
36
  export interface IDateTime extends Date {
9
- kind?: DateKind;
37
+ kind?: DateTimeKind;
10
38
  }
11
39
 
12
40
  export interface IDateTimeOffset extends Date {
@@ -38,20 +66,46 @@ export interface IEqualityComparer<T> {
38
66
  GetHashCode(x: T): number;
39
67
  }
40
68
 
41
- export interface ICollection<T> extends Iterable<T> {
69
+ export interface ICollection<T> extends IEnumerable<T> {
42
70
  readonly Count: number;
43
71
  readonly IsReadOnly: boolean;
44
72
  Add(item: T): void;
45
73
  Clear(): void;
46
74
  Contains(item: T): boolean;
47
- CopyTo(array: T[], arrayIndex: number): void;
75
+ CopyTo(array: MutableArray<T>, arrayIndex: number): void;
48
76
  Remove(item: T): boolean;
49
77
  }
50
78
 
79
+ // Exception is intentionally not derived from Error, for performance reasons (see #2160)
80
+ export class Exception {
81
+ public message: string;
82
+
83
+ constructor(msg?: string) {
84
+ this.message = msg ?? "";
85
+ }
86
+ }
87
+
88
+ export function isException(x: any) {
89
+ return x instanceof Exception || x instanceof Error;
90
+ }
91
+
92
+ export function isPromise(x: any) {
93
+ return x instanceof Promise;
94
+ }
95
+
96
+ export function ensureErrorOrException(e: any): any {
97
+ // Exceptionally admitting promises as errors for compatibility with React.suspense (see #3298)
98
+ return (isException(e) || isPromise(e)) ? e : new Exception(String(e));
99
+ }
100
+
51
101
  export function isArrayLike<T>(x: T | ArrayLike<T> | Iterable<T>): x is T[] {
52
102
  return Array.isArray(x) || ArrayBuffer.isView(x);
53
103
  }
54
104
 
105
+ export function isMutableArray<T>(x: T | ArrayLike<T> | Iterable<T>): x is MutableArray<T> {
106
+ return Array.isArray(x) || ArrayBuffer.isView(x);
107
+ }
108
+
55
109
  export function isIterable<T>(x: T | ArrayLike<T> | Iterable<T>): x is Iterable<T> {
56
110
  return x != null && typeof x === "object" && Symbol.iterator in x;
57
111
  }
@@ -108,7 +162,8 @@ export interface IEnumerable<T> extends Iterable<T> {
108
162
  }
109
163
 
110
164
  export class Enumerable<T> implements IEnumerable<T> {
111
- constructor(private en: IEnumerator<T>) {}
165
+ private en: IEnumerator<T>;
166
+ constructor(en: IEnumerator<T>) { this.en = en; }
112
167
  public GetEnumerator(): IEnumerator<T> { return this.en; }
113
168
  public "System.Collections.IEnumerable.GetEnumerator"(): IEnumerator<any> { return this.en; }
114
169
  [Symbol.iterator]() {
@@ -123,7 +178,8 @@ export class Enumerable<T> implements IEnumerable<T> {
123
178
 
124
179
  export class Enumerator<T> implements IEnumerator<T> {
125
180
  private current: T = defaultOf();
126
- constructor(private iter: Iterator<T>) { }
181
+ private iter: Iterator<T>;
182
+ constructor(iter: Iterator<T>) { this.iter = iter; }
127
183
  public ["System.Collections.Generic.IEnumerator`1.get_Current"]() {
128
184
  return this.current;
129
185
  }
@@ -136,7 +192,7 @@ export class Enumerator<T> implements IEnumerator<T> {
136
192
  return !cur.done;
137
193
  }
138
194
  public ["System.Collections.IEnumerator.Reset"]() {
139
- throw new Error("JS iterators cannot be reset");
195
+ throw new Exception("JS iterators cannot be reset");
140
196
  }
141
197
  public Dispose() {
142
198
  return;
@@ -228,7 +284,7 @@ export function comparerFromEqualityComparer<T>(comparer: IEqualityComparer<T>):
228
284
 
229
285
  export function assertEqual<T>(actual: T, expected: T, msg?: string): void {
230
286
  if (!equals(actual, expected)) {
231
- throw Object.assign(new Error(msg || `Expected: ${expected} - Actual: ${actual}`), {
287
+ throw Object.assign(new Exception(msg || `Expected: ${expected} - Actual: ${actual}`), {
232
288
  actual,
233
289
  expected,
234
290
  });
@@ -237,7 +293,7 @@ export function assertEqual<T>(actual: T, expected: T, msg?: string): void {
237
293
 
238
294
  export function assertNotEqual<T>(actual: T, expected: T, msg?: string): void {
239
295
  if (equals(actual, expected)) {
240
- throw Object.assign(new Error(msg || `Expected: ${expected} - Actual: ${actual}`), {
296
+ throw Object.assign(new Exception(msg || `Expected: ${expected} - Actual: ${actual}`), {
241
297
  actual,
242
298
  expected,
243
299
  });
@@ -284,8 +340,8 @@ export function dateOffset(date: IDateTime | IDateTimeOffset): number {
284
340
  const date1 = date as IDateTimeOffset;
285
341
  return typeof date1.offset === "number"
286
342
  ? date1.offset
287
- : ((date as IDateTime).kind === DateKind.UTC
288
- ? 0 : date.getTimezoneOffset() * -60000);
343
+ : ((date as IDateTime).kind === DateTimeKind.Utc
344
+ ? 0 : date.getTimezoneOffset() * -60_000);
289
345
  }
290
346
 
291
347
  export function int16ToString(i: number, radix?: number) {
@@ -426,7 +482,7 @@ export function safeHash<T>(x: T): number {
426
482
  return identityHash(x);
427
483
  }
428
484
 
429
- export function equalArraysWith<T>(x: ArrayLike<T>, y: ArrayLike<T>, eq: (x: T, y: T) => boolean): boolean {
485
+ export function equalArraysWith<T>(x: Nullable<ArrayLike<T>>, y: Nullable<ArrayLike<T>>, eq: (x: T, y: T) => boolean): boolean {
430
486
  if (x == null) { return y == null; }
431
487
  if (y == null) { return false; }
432
488
  if (x.length !== y.length) { return false; }
@@ -436,7 +492,7 @@ export function equalArraysWith<T>(x: ArrayLike<T>, y: ArrayLike<T>, eq: (x: T,
436
492
  return true;
437
493
  }
438
494
 
439
- export function equalArrays<T>(x: ArrayLike<T>, y: ArrayLike<T>): boolean {
495
+ export function equalArrays<T>(x: Nullable<ArrayLike<T>>, y: Nullable<ArrayLike<T>>): boolean {
440
496
  return equalArraysWith(x, y, equals);
441
497
  }
442
498
 
@@ -456,11 +512,11 @@ function equalObjects(x: { [k: string]: any }, y: { [k: string]: any }): boolean
456
512
  return true;
457
513
  }
458
514
 
459
- export function physicalEquality<T>(x: T, y: T): boolean {
515
+ export function physicalEquals<T>(x: T, y: T): boolean {
460
516
  return x === y;
461
517
  }
462
518
 
463
- export function equals<T>(x: T, y: T): boolean {
519
+ export function equals<T>(x: Nullable<T>, y: Nullable<T>): boolean {
464
520
  if (x === y) {
465
521
  return true;
466
522
  } else if (x == null) {
@@ -909,7 +965,7 @@ export function curry20<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,
909
965
  }
910
966
 
911
967
  // More performant method to copy arrays, see #2352
912
- export function copyToArray<T>(source: T[], sourceIndex: number, target: T[], targetIndex: number, count: number): void {
968
+ export function copyToArray<T>(source: MutableArray<T>, sourceIndex: number, target: MutableArray<T>, targetIndex: number, count: number): void {
913
969
  if (ArrayBuffer.isView(source) && ArrayBuffer.isView(target)) {
914
970
  (target as any).set((source as any).subarray(sourceIndex, sourceIndex + count), targetIndex);
915
971
  } else {
package/package.json CHANGED
@@ -1,24 +1,24 @@
1
1
  {
2
- "sideEffects": false,
3
- "private": false,
4
- "type": "module",
5
- "name": "@fable-org/fable-library-ts",
6
- "version": "2.0.0-beta.3",
7
- "description": "Core library used by F# projects compiled with fable.io",
8
- "author": "Fable Contributors",
9
- "license": "MIT",
10
- "repository": {
11
- "type": "git",
12
- "url": "git+https://github.com/fable-compiler/Fable.git"
13
- },
14
- "bugs": {
15
- "url": "https://github.com/fable-compiler/Fable/issues"
16
- },
17
- "homepage": "https://fable.io",
18
- "keywords": [
19
- "fable",
20
- "fable-compiler",
21
- "fsharp",
22
- "F#"
23
- ]
2
+ "sideEffects": false,
3
+ "private": false,
4
+ "type": "module",
5
+ "name": "@fable-org/fable-library-ts",
6
+ "version": "2.0.0-beta.5",
7
+ "description": "Core library used by F# projects compiled with fable.io",
8
+ "author": "Fable Contributors",
9
+ "license": "MIT",
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "git+https://github.com/fable-compiler/Fable.git"
13
+ },
14
+ "bugs": {
15
+ "url": "https://github.com/fable-compiler/Fable/issues"
16
+ },
17
+ "homepage": "https://fable.io",
18
+ "keywords": [
19
+ "fable",
20
+ "fable-compiler",
21
+ "fsharp",
22
+ "F#"
23
+ ]
24
24
  }
package/tsconfig.json CHANGED
@@ -1,4 +1,5 @@
1
1
  {
2
+ "$schema": "https://json.schemastore.org/tsconfig",
2
3
  "compilerOptions": {
3
4
  /* Visit https://aka.ms/tsconfig to read more about this file */
4
5
 
@@ -14,6 +15,7 @@
14
15
  "target": "es2020", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
15
16
  // "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
16
17
  // "jsx": "preserve", /* Specify what JSX code is generated. */
18
+ // "libReplacement": true, /* Enable lib replacement. */
17
19
  // "experimentalDecorators": true, /* Enable experimental support for TC39 stage 2 draft decorators. */
18
20
  // "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */
19
21
  // "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h'. */
@@ -35,7 +37,14 @@
35
37
  // "types": [], /* Specify type package names to be included without being referenced in a source file. */
36
38
  // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
37
39
  // "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */
40
+ // "allowImportingTsExtensions": true, /* Allow imports to include TypeScript file extensions. Requires '--moduleResolution bundler' and either '--noEmit' or '--emitDeclarationOnly' to be set. */
41
+ "rewriteRelativeImportExtensions": true, /* Rewrite '.ts', '.tsx', '.mts', and '.cts' file extensions in relative import paths to their JavaScript equivalent in output files. */
42
+ // "resolvePackageJsonExports": true, /* Use the package.json 'exports' field when resolving package imports. */
43
+ // "resolvePackageJsonImports": true, /* Use the package.json 'imports' field when resolving imports. */
44
+ // "customConditions": [], /* Conditions to set in addition to the resolver-specific defaults when resolving imports. */
45
+ // "noUncheckedSideEffectImports": true, /* Check side effect imports. */
38
46
  // "resolveJsonModule": true, /* Enable importing .json files. */
47
+ // "allowArbitraryExtensions": true, /* Enable importing files with any extension, provided a declaration file is present. */
39
48
  // "noResolve": true, /* Disallow 'import's, 'require's or '<reference>'s from expanding the number of files TypeScript should add to a project. */
40
49
 
41
50
  /* JavaScript Support */
@@ -44,7 +53,7 @@
44
53
  // "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from 'node_modules'. Only applicable with 'allowJs'. */
45
54
 
46
55
  /* Emit */
47
- "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */
56
+ // "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */
48
57
  // "declarationMap": true, /* Create sourcemaps for d.ts files. */
49
58
  // "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */
50
59
  // "sourceMap": true, /* Create source map files for emitted JavaScript files. */
@@ -60,16 +69,19 @@
60
69
  // "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */
61
70
  // "inlineSources": true, /* Include source code in the sourcemaps inside the emitted JavaScript. */
62
71
  // "emitBOM": true, /* Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. */
63
- // "newLine": "crlf", /* Set the newline character for emitting files. */
72
+ "newLine": "lf", /* Set the newline character for emitting files. */
64
73
  // "stripInternal": true, /* Disable emitting declarations that have '@internal' in their JSDoc comments. */
65
74
  // "noEmitHelpers": true, /* Disable generating custom helper functions like '__extends' in compiled output. */
66
- // "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */
75
+ "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */
67
76
  // "preserveConstEnums": true, /* Disable erasing 'const enum' declarations in generated code. */
68
77
  // "declarationDir": "./", /* Specify the output directory for generated declaration files. */
69
78
  // "preserveValueImports": true, /* Preserve unused imported values in the JavaScript output that would otherwise be removed. */
70
79
 
71
80
  /* Interop Constraints */
72
81
  // "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */
82
+ // "verbatimModuleSyntax": true, /* Do not transform or elide any imports or exports not marked as type-only, ensuring they are written in the output file's format based on the 'module' setting. */
83
+ // "isolatedDeclarations": true, /* Require sufficient annotation on exports so other tools can trivially generate declaration files. */
84
+ "erasableSyntaxOnly": true, /* Do not allow runtime constructs that are not part of ECMAScript. */
73
85
  // "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */
74
86
  "esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */
75
87
  // "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */
@@ -82,14 +94,15 @@
82
94
  // "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */
83
95
  // "strictBindCallApply": true, /* Check that the arguments for 'bind', 'call', and 'apply' methods match the original function. */
84
96
  // "strictPropertyInitialization": true, /* Check for class properties that are declared but not set in the constructor. */
97
+ // "strictBuiltinIteratorReturn": true, /* Built-in iterators are instantiated with a 'TReturn' type of 'undefined' instead of 'any'. */
85
98
  // "noImplicitThis": true, /* Enable error reporting when 'this' is given the type 'any'. */
86
99
  // "useUnknownInCatchVariables": true, /* Default catch clause variables as 'unknown' instead of 'any'. */
87
100
  // "alwaysStrict": true, /* Ensure 'use strict' is always emitted. */
88
101
  // "noUnusedLocals": true, /* Enable error reporting when local variables aren't read. */
89
102
  // "noUnusedParameters": true, /* Raise an error when a function parameter isn't read. */
90
103
  // "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */
91
- // "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */
92
- // "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */
104
+ "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */
105
+ "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */
93
106
  // "noUncheckedIndexedAccess": true, /* Add 'undefined' to a type when accessed using an index. */
94
107
  // "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an override modifier. */
95
108
  // "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type. */
@@ -1,7 +0,0 @@
1
- import { Exception } from "./Types.js";
2
-
3
- export class SystemException extends Exception {
4
- }
5
-
6
- export class TimeoutException extends SystemException {
7
- }