@fable-org/fable-library-ts 2.0.0-beta.4 → 2.0.0-beta.6
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.ts +253 -247
- package/Async.ts +13 -12
- package/AsyncBuilder.ts +10 -11
- package/BigInt.ts +6 -6
- package/BitConverter.ts +3 -3
- package/Boolean.ts +3 -2
- package/CHANGELOG.md +14 -0
- package/Char.ts +38 -35
- package/Choice.ts +36 -12
- package/CollectionUtil.ts +4 -4
- package/Date.ts +67 -62
- package/DateOffset.ts +47 -56
- package/DateOnly.ts +8 -8
- package/Decimal.ts +9 -9
- package/Double.ts +3 -2
- package/Encoding.ts +1 -1
- package/Event.ts +3 -3
- package/FSharp.Collections.ts +31 -13
- package/FSharp.Core.CompilerServices.ts +4 -4
- package/FSharp.Core.ts +34 -34
- package/Global.ts +44 -2
- package/Guid.ts +7 -6
- package/Int32.ts +20 -17
- package/List.ts +57 -56
- package/Long.ts +6 -5
- package/MailboxProcessor.ts +8 -7
- package/Map.ts +67 -65
- package/MapUtil.ts +5 -5
- package/MutableMap.ts +32 -20
- package/MutableSet.ts +12 -12
- package/Native.ts +3 -3
- package/Numeric.ts +1 -1
- package/Observable.ts +3 -3
- package/Option.ts +3 -3
- package/Random.ts +34 -34
- package/Range.ts +7 -7
- package/Reflection.ts +73 -40
- package/RegExp.ts +5 -3
- package/Result.ts +31 -27
- package/Seq.ts +56 -54
- package/Seq2.ts +14 -14
- package/Set.ts +81 -80
- package/String.ts +41 -38
- package/System.Collections.Generic.ts +45 -25
- package/System.Text.ts +12 -12
- package/System.ts +366 -0
- package/TimeOnly.ts +10 -10
- package/TimeSpan.ts +11 -11
- package/Timer.ts +2 -2
- package/Types.ts +1 -19
- package/Uri.ts +13 -10
- package/Util.ts +74 -26
- package/package.json +1 -1
- package/tsconfig.json +18 -5
- package/SystemException.ts +0 -7
package/Util.ts
CHANGED
|
@@ -1,14 +1,40 @@
|
|
|
1
1
|
export type Nullable<T> = T | null | undefined;
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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];
|
|
9
35
|
|
|
10
36
|
export interface IDateTime extends Date {
|
|
11
|
-
kind?:
|
|
37
|
+
kind?: DateTimeKind;
|
|
12
38
|
}
|
|
13
39
|
|
|
14
40
|
export interface IDateTimeOffset extends Date {
|
|
@@ -32,28 +58,54 @@ export interface IDisposable {
|
|
|
32
58
|
}
|
|
33
59
|
|
|
34
60
|
export interface IComparer<T> {
|
|
35
|
-
Compare(x:
|
|
61
|
+
Compare(x: T, y: T): number;
|
|
36
62
|
}
|
|
37
63
|
|
|
38
64
|
export interface IEqualityComparer<T> {
|
|
39
|
-
Equals(x:
|
|
65
|
+
Equals(x: T, y: T): boolean;
|
|
40
66
|
GetHashCode(x: T): number;
|
|
41
67
|
}
|
|
42
68
|
|
|
43
|
-
export interface ICollection<T> extends
|
|
69
|
+
export interface ICollection<T> extends IEnumerable<T> {
|
|
44
70
|
readonly Count: number;
|
|
45
71
|
readonly IsReadOnly: boolean;
|
|
46
72
|
Add(item: T): void;
|
|
47
73
|
Clear(): void;
|
|
48
74
|
Contains(item: T): boolean;
|
|
49
|
-
CopyTo(array: T
|
|
75
|
+
CopyTo(array: MutableArray<T>, arrayIndex: number): void;
|
|
50
76
|
Remove(item: T): boolean;
|
|
51
77
|
}
|
|
52
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
|
+
|
|
53
101
|
export function isArrayLike<T>(x: T | ArrayLike<T> | Iterable<T>): x is T[] {
|
|
54
102
|
return Array.isArray(x) || ArrayBuffer.isView(x);
|
|
55
103
|
}
|
|
56
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
|
+
|
|
57
109
|
export function isIterable<T>(x: T | ArrayLike<T> | Iterable<T>): x is Iterable<T> {
|
|
58
110
|
return x != null && typeof x === "object" && Symbol.iterator in x;
|
|
59
111
|
}
|
|
@@ -110,7 +162,8 @@ export interface IEnumerable<T> extends Iterable<T> {
|
|
|
110
162
|
}
|
|
111
163
|
|
|
112
164
|
export class Enumerable<T> implements IEnumerable<T> {
|
|
113
|
-
|
|
165
|
+
private en: IEnumerator<T>;
|
|
166
|
+
constructor(en: IEnumerator<T>) { this.en = en; }
|
|
114
167
|
public GetEnumerator(): IEnumerator<T> { return this.en; }
|
|
115
168
|
public "System.Collections.IEnumerable.GetEnumerator"(): IEnumerator<any> { return this.en; }
|
|
116
169
|
[Symbol.iterator]() {
|
|
@@ -125,7 +178,8 @@ export class Enumerable<T> implements IEnumerable<T> {
|
|
|
125
178
|
|
|
126
179
|
export class Enumerator<T> implements IEnumerator<T> {
|
|
127
180
|
private current: T = defaultOf();
|
|
128
|
-
|
|
181
|
+
private iter: Iterator<T>;
|
|
182
|
+
constructor(iter: Iterator<T>) { this.iter = iter; }
|
|
129
183
|
public ["System.Collections.Generic.IEnumerator`1.get_Current"]() {
|
|
130
184
|
return this.current;
|
|
131
185
|
}
|
|
@@ -138,7 +192,7 @@ export class Enumerator<T> implements IEnumerator<T> {
|
|
|
138
192
|
return !cur.done;
|
|
139
193
|
}
|
|
140
194
|
public ["System.Collections.IEnumerator.Reset"]() {
|
|
141
|
-
throw new
|
|
195
|
+
throw new Exception("JS iterators cannot be reset");
|
|
142
196
|
}
|
|
143
197
|
public Dispose() {
|
|
144
198
|
return;
|
|
@@ -230,7 +284,7 @@ export function comparerFromEqualityComparer<T>(comparer: IEqualityComparer<T>):
|
|
|
230
284
|
|
|
231
285
|
export function assertEqual<T>(actual: T, expected: T, msg?: string): void {
|
|
232
286
|
if (!equals(actual, expected)) {
|
|
233
|
-
throw Object.assign(new
|
|
287
|
+
throw Object.assign(new Exception(msg || `Expected: ${expected} - Actual: ${actual}`), {
|
|
234
288
|
actual,
|
|
235
289
|
expected,
|
|
236
290
|
});
|
|
@@ -239,7 +293,7 @@ export function assertEqual<T>(actual: T, expected: T, msg?: string): void {
|
|
|
239
293
|
|
|
240
294
|
export function assertNotEqual<T>(actual: T, expected: T, msg?: string): void {
|
|
241
295
|
if (equals(actual, expected)) {
|
|
242
|
-
throw Object.assign(new
|
|
296
|
+
throw Object.assign(new Exception(msg || `Expected: ${expected} - Actual: ${actual}`), {
|
|
243
297
|
actual,
|
|
244
298
|
expected,
|
|
245
299
|
});
|
|
@@ -286,8 +340,8 @@ export function dateOffset(date: IDateTime | IDateTimeOffset): number {
|
|
|
286
340
|
const date1 = date as IDateTimeOffset;
|
|
287
341
|
return typeof date1.offset === "number"
|
|
288
342
|
? date1.offset
|
|
289
|
-
: ((date as IDateTime).kind ===
|
|
290
|
-
? 0 : date.getTimezoneOffset() * -
|
|
343
|
+
: ((date as IDateTime).kind === DateTimeKind.Utc
|
|
344
|
+
? 0 : date.getTimezoneOffset() * -60_000);
|
|
291
345
|
}
|
|
292
346
|
|
|
293
347
|
export function int16ToString(i: number, radix?: number) {
|
|
@@ -462,13 +516,7 @@ export function physicalEquals<T>(x: T, y: T): boolean {
|
|
|
462
516
|
return x === y;
|
|
463
517
|
}
|
|
464
518
|
|
|
465
|
-
export function
|
|
466
|
-
if (x == null) { return y == null; }
|
|
467
|
-
if (y == null) { return false; }
|
|
468
|
-
return equals(x, y);
|
|
469
|
-
}
|
|
470
|
-
|
|
471
|
-
export function equals<T>(x: T, y: T): boolean {
|
|
519
|
+
export function equals<T>(x: Nullable<T>, y: Nullable<T>): boolean {
|
|
472
520
|
if (x === y) {
|
|
473
521
|
return true;
|
|
474
522
|
} else if (x == null) {
|
|
@@ -917,7 +965,7 @@ export function curry20<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,
|
|
|
917
965
|
}
|
|
918
966
|
|
|
919
967
|
// More performant method to copy arrays, see #2352
|
|
920
|
-
export function copyToArray<T>(source: T
|
|
968
|
+
export function copyToArray<T>(source: MutableArray<T>, sourceIndex: number, target: MutableArray<T>, targetIndex: number, count: number): void {
|
|
921
969
|
if (ArrayBuffer.isView(source) && ArrayBuffer.isView(target)) {
|
|
922
970
|
(target as any).set((source as any).subarray(sourceIndex, sourceIndex + count), targetIndex);
|
|
923
971
|
} else {
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"private": false,
|
|
4
4
|
"type": "module",
|
|
5
5
|
"name": "@fable-org/fable-library-ts",
|
|
6
|
-
"version": "2.0.0-beta.
|
|
6
|
+
"version": "2.0.0-beta.6",
|
|
7
7
|
"description": "Core library used by F# projects compiled with fable.io",
|
|
8
8
|
"author": "Fable Contributors",
|
|
9
9
|
"license": "MIT",
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
92
|
-
|
|
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. */
|