@fable-org/fable-library-ts 1.9.0 → 1.11.0

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/Async.ts CHANGED
@@ -159,12 +159,14 @@ export function sleep(millisecondsDueTime: number) {
159
159
  });
160
160
  }
161
161
 
162
- export function runSynchronously(): never {
163
- throw new Error("Asynchronous code cannot be run synchronously in JS");
164
- }
165
-
166
162
  export function start<T>(computation: Async<T>, cancellationToken?: CancellationToken) {
167
- return startWithContinuations(computation, cancellationToken);
163
+ return startWithContinuations(
164
+ computation,
165
+ emptyContinuation,
166
+ function (err) { throw err },
167
+ emptyContinuation,
168
+ cancellationToken
169
+ );
168
170
  }
169
171
 
170
172
  export function startImmediate<T>(computation: Async<T>, cancellationToken?: CancellationToken) {
@@ -173,19 +175,16 @@ export function startImmediate<T>(computation: Async<T>, cancellationToken?: Can
173
175
 
174
176
  export function startWithContinuations<T>(
175
177
  computation: Async<T>,
176
- continuation?: Continuation<T> | CancellationToken,
177
- exceptionContinuation?: Continuation<any>,
178
- cancellationContinuation?: Continuation<any>,
178
+ continuation: Continuation<T>,
179
+ exceptionContinuation: Continuation<any>,
180
+ cancellationContinuation: Continuation<any>,
179
181
  cancelToken?: CancellationToken) {
180
- if (typeof continuation !== "function") {
181
- cancelToken = continuation as CancellationToken;
182
- continuation = undefined;
183
- }
182
+
184
183
  const trampoline = new Trampoline();
185
184
  computation({
186
185
  onSuccess: continuation ? continuation as Continuation<T> : emptyContinuation,
187
- onError: exceptionContinuation ? exceptionContinuation : emptyContinuation,
188
- onCancel: cancellationContinuation ? cancellationContinuation : emptyContinuation,
186
+ onError: exceptionContinuation,
187
+ onCancel: cancellationContinuation,
189
188
  cancelToken: cancelToken ? cancelToken : defaultCancellationToken,
190
189
  trampoline,
191
190
  });
package/CHANGELOG.md CHANGED
@@ -7,20 +7,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## Unreleased
9
9
 
10
- ## 1.9.0 - 2025-01-09
11
-
12
- ### Added
13
-
14
- * [JS/TS] Add new `TimSpan` overload support coming from .NET 9 (by @MangelMaxime)
10
+ ## 1.11.0- 2025-04-26
15
11
 
16
12
  ### Fixed
17
13
 
18
- * [JS/TS] Fix `DateTimeOffset.ToLocalTime` (by @MangelMaxime)
19
-
20
- ## 1.8.0 - 2024-11-19
21
-
22
- * [JS/TS] Fix `h` in `DateTime.ToString` (@MangelMaxime)
23
- * [JS/TS] Fix `hh` in `DateTime.ToString` (@MangelMaxime)
14
+ * [JS/TS] Propagate non-captured exception when running `Async.Start` or `Async.StartImmediate` (by @MangelMaxime)
15
+ * [JS/TS] Remove `Async.RunSynchronously` (by @MangelMaxime)
16
+ * [JS/TS] Change signature of `startWithContinuations` to always require all its arguments (by @MangelMaxime)
24
17
 
25
18
  ## 1.7.0 - 2024-11-19
26
19
 
package/Choice.ts CHANGED
@@ -1,6 +1,5 @@
1
1
  import { Union } from "./Types.js";
2
2
  import { union_type, TypeInfo } from "./Reflection.js";
3
- import { int32 } from "./Int32.js";
4
3
  import { Option, some } from "./Option.js";
5
4
 
6
5
  export type FSharpChoice$2_$union<T1, T2> =
@@ -282,8 +281,8 @@ export function Choice_makeChoice2Of2<T2, a>(x: T2): FSharpChoice$2_$union<a, T2
282
281
  }
283
282
 
284
283
  export function Choice_tryValueIfChoice1Of2<T1, T2>(x: FSharpChoice$2_$union<T1, T2>): Option<T1> {
285
- if ((x.tag as int32) === /* Choice1Of2 */ 0) {
286
- return some(x.fields[0] as any);
284
+ if (x.tag === /* Choice1Of2 */ 0) {
285
+ return some(x.fields[0]);
287
286
  }
288
287
  else {
289
288
  return undefined;
@@ -291,8 +290,8 @@ export function Choice_tryValueIfChoice1Of2<T1, T2>(x: FSharpChoice$2_$union<T1,
291
290
  }
292
291
 
293
292
  export function Choice_tryValueIfChoice2Of2<T1, T2>(x: FSharpChoice$2_$union<T1, T2>): Option<T2> {
294
- if ((x.tag as int32) === /* Choice2Of2 */ 1) {
295
- return some(x.fields[0] as any);
293
+ if (x.tag === /* Choice2Of2 */ 1) {
294
+ return some(x.fields[0]);
296
295
  }
297
296
  else {
298
297
  return undefined;
package/Date.ts CHANGED
@@ -166,12 +166,10 @@ function dateToStringWithCustomFormat(date: Date, format: string, utc: boolean)
166
166
  cursorPos += tokenLength;
167
167
  switch (tokenLength) {
168
168
  case 1:
169
- const h1Value = hour(localizedDate) % 12;
170
- result += h1Value ? h1Value : 12;
169
+ result += hour(localizedDate) % 12
171
170
  break;
172
171
  case 2:
173
- const h2Value = hour(localizedDate) % 12;
174
- result += padWithZeros(h2Value ? h2Value : 12, 2);
172
+ result += padWithZeros(hour(localizedDate) % 12, 2);
175
173
  break;
176
174
  default:
177
175
  break;
package/DateOffset.ts CHANGED
@@ -166,10 +166,6 @@ export function toUniversalTime(date: IDateTimeOffset): Date {
166
166
  }
167
167
 
168
168
  export function toLocalTime(date: IDateTimeOffset): Date {
169
- return DateTime(date.getTime() + offset(now()), DateKind.Local);
170
- }
171
-
172
- export function localDateTime(date: IDateTimeOffset) : Date {
173
169
  return DateTime(date.getTime(), DateKind.Local);
174
170
  }
175
171
 
package/Result.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { Union } from "./Types.js";
2
2
  import { union_type, TypeInfo } from "./Reflection.js";
3
- import { int32 } from "./Int32.js";
4
3
  import { equals } from "./Util.js";
4
+ import { int32 } from "./Int32.js";
5
5
  import { FSharpList, empty, singleton } from "./List.js";
6
6
  import { Option, some } from "./Option.js";
7
7
 
@@ -36,34 +36,34 @@ export function FSharpResult$2_$reflection(gen0: TypeInfo, gen1: TypeInfo): Type
36
36
  }
37
37
 
38
38
  export function Result_Map<a, b, c>(mapping: ((arg0: a) => b), result: FSharpResult$2_$union<a, c>): FSharpResult$2_$union<b, c> {
39
- if ((result.tag as int32) === /* Ok */ 0) {
40
- return FSharpResult$2_Ok<b, c>(mapping(result.fields[0] as any));
39
+ if (result.tag === /* Ok */ 0) {
40
+ return FSharpResult$2_Ok<b, c>(mapping(result.fields[0]));
41
41
  }
42
42
  else {
43
- return FSharpResult$2_Error<b, c>(result.fields[0] as any);
43
+ return FSharpResult$2_Error<b, c>(result.fields[0]);
44
44
  }
45
45
  }
46
46
 
47
47
  export function Result_MapError<a, b, c>(mapping: ((arg0: a) => b), result: FSharpResult$2_$union<c, a>): FSharpResult$2_$union<c, b> {
48
- if ((result.tag as int32) === /* Ok */ 0) {
49
- return FSharpResult$2_Ok<c, b>(result.fields[0] as any);
48
+ if (result.tag === /* Ok */ 0) {
49
+ return FSharpResult$2_Ok<c, b>(result.fields[0]);
50
50
  }
51
51
  else {
52
- return FSharpResult$2_Error<c, b>(mapping(result.fields[0] as any));
52
+ return FSharpResult$2_Error<c, b>(mapping(result.fields[0]));
53
53
  }
54
54
  }
55
55
 
56
56
  export function Result_Bind<a, b, c>(binder: ((arg0: a) => FSharpResult$2_$union<b, c>), result: FSharpResult$2_$union<a, c>): FSharpResult$2_$union<b, c> {
57
- if ((result.tag as int32) === /* Ok */ 0) {
58
- return binder(result.fields[0] as any);
57
+ if (result.tag === /* Ok */ 0) {
58
+ return binder(result.fields[0]);
59
59
  }
60
60
  else {
61
- return FSharpResult$2_Error<b, c>(result.fields[0] as any);
61
+ return FSharpResult$2_Error<b, c>(result.fields[0]);
62
62
  }
63
63
  }
64
64
 
65
65
  export function Result_IsOk<a, b>(result: FSharpResult$2_$union<a, b>): boolean {
66
- if ((result.tag as int32) === /* Ok */ 0) {
66
+ if (result.tag === /* Ok */ 0) {
67
67
  return true;
68
68
  }
69
69
  else {
@@ -72,7 +72,7 @@ export function Result_IsOk<a, b>(result: FSharpResult$2_$union<a, b>): boolean
72
72
  }
73
73
 
74
74
  export function Result_IsError<a, b>(result: FSharpResult$2_$union<a, b>): boolean {
75
- if ((result.tag as int32) === /* Ok */ 0) {
75
+ if (result.tag === /* Ok */ 0) {
76
76
  return false;
77
77
  }
78
78
  else {
@@ -81,8 +81,8 @@ export function Result_IsError<a, b>(result: FSharpResult$2_$union<a, b>): boole
81
81
  }
82
82
 
83
83
  export function Result_Contains<a, b>(value: a, result: FSharpResult$2_$union<a, b>): boolean {
84
- if ((result.tag as int32) === /* Ok */ 0) {
85
- return equals(result.fields[0] as any, value);
84
+ if (result.tag === /* Ok */ 0) {
85
+ return equals(result.fields[0], value);
86
86
  }
87
87
  else {
88
88
  return false;
@@ -90,7 +90,7 @@ export function Result_Contains<a, b>(value: a, result: FSharpResult$2_$union<a,
90
90
  }
91
91
 
92
92
  export function Result_Count<a, b>(result: FSharpResult$2_$union<a, b>): int32 {
93
- if ((result.tag as int32) === /* Ok */ 0) {
93
+ if (result.tag === /* Ok */ 0) {
94
94
  return 1;
95
95
  }
96
96
  else {
@@ -99,8 +99,8 @@ export function Result_Count<a, b>(result: FSharpResult$2_$union<a, b>): int32 {
99
99
  }
100
100
 
101
101
  export function Result_DefaultValue<a, b>(defaultValue: a, result: FSharpResult$2_$union<a, b>): a {
102
- if ((result.tag as int32) === /* Ok */ 0) {
103
- return result.fields[0] as any;
102
+ if (result.tag === /* Ok */ 0) {
103
+ return result.fields[0];
104
104
  }
105
105
  else {
106
106
  return defaultValue;
@@ -108,17 +108,17 @@ export function Result_DefaultValue<a, b>(defaultValue: a, result: FSharpResult$
108
108
  }
109
109
 
110
110
  export function Result_DefaultWith<b, a>(defThunk: ((arg0: b) => a), result: FSharpResult$2_$union<a, b>): a {
111
- if ((result.tag as int32) === /* Ok */ 0) {
112
- return result.fields[0] as any;
111
+ if (result.tag === /* Ok */ 0) {
112
+ return result.fields[0];
113
113
  }
114
114
  else {
115
- return defThunk(result.fields[0] as any);
115
+ return defThunk(result.fields[0]);
116
116
  }
117
117
  }
118
118
 
119
119
  export function Result_Exists<a, b>(predicate: ((arg0: a) => boolean), result: FSharpResult$2_$union<a, b>): boolean {
120
- if ((result.tag as int32) === /* Ok */ 0) {
121
- return predicate(result.fields[0] as any);
120
+ if (result.tag === /* Ok */ 0) {
121
+ return predicate(result.fields[0]);
122
122
  }
123
123
  else {
124
124
  return false;
@@ -126,8 +126,8 @@ export function Result_Exists<a, b>(predicate: ((arg0: a) => boolean), result: F
126
126
  }
127
127
 
128
128
  export function Result_Fold<a, b, s>(folder: ((arg0: s, arg1: a) => s), state: s, result: FSharpResult$2_$union<a, b>): s {
129
- if ((result.tag as int32) === /* Ok */ 0) {
130
- return folder(state, result.fields[0] as any);
129
+ if (result.tag === /* Ok */ 0) {
130
+ return folder(state, result.fields[0]);
131
131
  }
132
132
  else {
133
133
  return state;
@@ -135,8 +135,8 @@ export function Result_Fold<a, b, s>(folder: ((arg0: s, arg1: a) => s), state: s
135
135
  }
136
136
 
137
137
  export function Result_FoldBack<a, b, s>(folder: ((arg0: a, arg1: s) => s), result: FSharpResult$2_$union<a, b>, state: s): s {
138
- if ((result.tag as int32) === /* Ok */ 0) {
139
- return folder(result.fields[0] as any, state);
138
+ if (result.tag === /* Ok */ 0) {
139
+ return folder(result.fields[0], state);
140
140
  }
141
141
  else {
142
142
  return state;
@@ -144,8 +144,8 @@ export function Result_FoldBack<a, b, s>(folder: ((arg0: a, arg1: s) => s), resu
144
144
  }
145
145
 
146
146
  export function Result_ForAll<a, b>(predicate: ((arg0: a) => boolean), result: FSharpResult$2_$union<a, b>): boolean {
147
- if ((result.tag as int32) === /* Ok */ 0) {
148
- return predicate(result.fields[0] as any);
147
+ if (result.tag === /* Ok */ 0) {
148
+ return predicate(result.fields[0]);
149
149
  }
150
150
  else {
151
151
  return true;
@@ -153,14 +153,14 @@ export function Result_ForAll<a, b>(predicate: ((arg0: a) => boolean), result: F
153
153
  }
154
154
 
155
155
  export function Result_Iterate<a, b>(action: ((arg0: a) => void), result: FSharpResult$2_$union<a, b>): void {
156
- if ((result.tag as int32) === /* Ok */ 0) {
157
- action(result.fields[0] as any);
156
+ if (result.tag === /* Ok */ 0) {
157
+ action(result.fields[0]);
158
158
  }
159
159
  }
160
160
 
161
161
  export function Result_ToArray<a, b>(result: FSharpResult$2_$union<a, b>): a[] {
162
- if ((result.tag as int32) === /* Ok */ 0) {
163
- return [result.fields[0] as any];
162
+ if (result.tag === /* Ok */ 0) {
163
+ return [result.fields[0]];
164
164
  }
165
165
  else {
166
166
  return [];
@@ -168,8 +168,8 @@ export function Result_ToArray<a, b>(result: FSharpResult$2_$union<a, b>): a[] {
168
168
  }
169
169
 
170
170
  export function Result_ToList<a, b>(result: FSharpResult$2_$union<a, b>): FSharpList<a> {
171
- if ((result.tag as int32) === /* Ok */ 0) {
172
- return singleton(result.fields[0] as any);
171
+ if (result.tag === /* Ok */ 0) {
172
+ return singleton(result.fields[0]);
173
173
  }
174
174
  else {
175
175
  return empty<a>();
@@ -177,8 +177,8 @@ export function Result_ToList<a, b>(result: FSharpResult$2_$union<a, b>): FSharp
177
177
  }
178
178
 
179
179
  export function Result_ToOption<a, b>(result: FSharpResult$2_$union<a, b>): Option<a> {
180
- if ((result.tag as int32) === /* Ok */ 0) {
181
- return some(result.fields[0] as any);
180
+ if (result.tag === /* Ok */ 0) {
181
+ return some(result.fields[0]);
182
182
  }
183
183
  else {
184
184
  return undefined;
@@ -186,8 +186,8 @@ export function Result_ToOption<a, b>(result: FSharpResult$2_$union<a, b>): Opti
186
186
  }
187
187
 
188
188
  export function Result_ToValueOption<a, b>(result: FSharpResult$2_$union<a, b>): Option<a> {
189
- if ((result.tag as int32) === /* Ok */ 0) {
190
- return some(result.fields[0] as any);
189
+ if (result.tag === /* Ok */ 0) {
190
+ return some(result.fields[0]);
191
191
  }
192
192
  else {
193
193
  return undefined;
package/TimeSpan.ts CHANGED
@@ -35,24 +35,20 @@ export function fromTicks(ticks: number | bigint) {
35
35
  return Number(BigInt(ticks) / 10000n);
36
36
  }
37
37
 
38
- export function fromDays(d: number, h: number = 0, m: bigint = 0n, s: bigint = 0n, ms: bigint = 0n) {
39
- return create(d, h, Number(m), Number(s), Number(ms));
38
+ export function fromDays(d: number) {
39
+ return create(d, 0, 0, 0);
40
40
  }
41
41
 
42
- export function fromHours(h: number, m: bigint = 0n, s: bigint = 0n, ms: bigint = 0n) {
43
- return create(0, h, Number(m), Number(s), Number(ms));
42
+ export function fromHours(h: number) {
43
+ return create(h, 0, 0);
44
44
  }
45
45
 
46
- export function fromMinutes(m: number | bigint, s: bigint = 0n, ms: bigint = 0n) {
47
- return create(0, 0, Number(m), Number(s), Number(ms));
46
+ export function fromMinutes(m: number) {
47
+ return create(0, m, 0);
48
48
  }
49
49
 
50
- export function fromSeconds(s: number | bigint, ms: bigint = 0n) {
51
- return create(0, 0, 0, Number(s), Number(ms));
52
- }
53
-
54
- export function fromMilliseconds(ms: number | bigint) {
55
- return Number(ms);
50
+ export function fromSeconds(s: number) {
51
+ return create(0, 0, s);
56
52
  }
57
53
 
58
54
  export function days(ts: TimeSpan) {
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": "1.9.0",
6
+ "version": "1.11.0",
7
7
  "description": "Core library used by F# projects compiled with fable.io",
8
8
  "author": "Fable Contributors",
9
9
  "license": "MIT",