@fable-org/fable-library-js 1.4.3 → 1.6.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.d.ts CHANGED
@@ -1,32 +1,27 @@
1
1
  import { Continuation, Continuations } from "./AsyncBuilder.js";
2
- import { CancellationToken } from "./AsyncBuilder.js";
3
- import { IAsync } from "./AsyncBuilder.js";
4
- import { IAsyncContext } from "./AsyncBuilder.js";
2
+ import { Async, IAsyncContext, CancellationToken } from "./AsyncBuilder.js";
5
3
  import { FSharpChoice$2_$union } from "./Choice.js";
6
- export declare class Async<_T> {
7
- }
8
- export declare function makeAsync<T>(body: IAsync<T>): IAsync<T>;
9
- export declare function invoke<T>(computation: IAsync<T>, ctx: IAsyncContext<T>): void;
10
- export declare function callThenInvoke<T, U>(ctx: IAsyncContext<T>, result1: U, part2: (x: U) => IAsync<T>): void;
11
- export declare function bind<T, U>(ctx: IAsyncContext<T>, part1: IAsync<U>, part2: (x: U) => IAsync<T>): void;
4
+ export declare function makeAsync<T>(body: Async<T>): Async<T>;
5
+ export declare function invoke<T>(computation: Async<T>, ctx: IAsyncContext<T>): void;
6
+ export declare function callThenInvoke<T, U>(ctx: IAsyncContext<T>, result1: U, part2: (x: U) => Async<T>): void;
7
+ export declare function bind<T, U>(ctx: IAsyncContext<T>, part1: Async<U>, part2: (x: U) => Async<T>): void;
12
8
  export declare function createCancellationToken(arg?: boolean | number): CancellationToken;
13
9
  export declare function cancel(token: CancellationToken): void;
14
10
  export declare function cancelAfter(token: CancellationToken, ms: number): void;
15
11
  export declare function isCancellationRequested(token: CancellationToken): boolean;
16
12
  export declare function throwIfCancellationRequested(token: CancellationToken): void;
17
- export declare function startChild<T>(computation: IAsync<T>, ms?: number): IAsync<IAsync<T>>;
13
+ export declare function startChild<T>(computation: Async<T>, ms?: number): Async<Async<T>>;
18
14
  export declare function awaitPromise<T>(p: Promise<T>): (ctx: IAsyncContext<T>) => void;
19
15
  export declare function cancellationToken(): (ctx: IAsyncContext<CancellationToken>) => void;
20
16
  export declare const defaultCancellationToken: CancellationToken;
21
- export declare function catchAsync<T>(work: IAsync<T>): (ctx: IAsyncContext<FSharpChoice$2_$union<T, Error>>) => void;
17
+ export declare function catchAsync<T>(work: Async<T>): (ctx: IAsyncContext<FSharpChoice$2_$union<T, Error>>) => void;
22
18
  export declare function fromContinuations<T>(f: (conts: Continuations<T>) => void): (ctx: IAsyncContext<T>) => void;
23
- export declare function ignore<T>(computation: IAsync<T>): (ctx: IAsyncContext<undefined>) => void;
24
- export declare function parallel<T>(computations: Iterable<IAsync<T>>): (ctx: IAsyncContext<Awaited<T>[]>) => void;
25
- export declare function sequential<T>(computations: Iterable<IAsync<T>>): (ctx: IAsyncContext<T[]>) => void;
19
+ export declare function ignore<T>(computation: Async<T>): (ctx: IAsyncContext<undefined>) => void;
20
+ export declare function parallel<T>(computations: Iterable<Async<T>>): (ctx: IAsyncContext<Awaited<T>[]>) => void;
21
+ export declare function sequential<T>(computations: Iterable<Async<T>>): (ctx: IAsyncContext<T[]>) => void;
26
22
  export declare function sleep(millisecondsDueTime: number): (ctx: IAsyncContext<void>) => void;
27
23
  export declare function runSynchronously(): never;
28
- export declare function start<T>(computation: IAsync<T>, cancellationToken?: CancellationToken): void;
29
- export declare function startImmediate<T>(computation: IAsync<T>, cancellationToken?: CancellationToken): void;
30
- export declare function startWithContinuations<T>(computation: IAsync<T>, continuation?: Continuation<T> | CancellationToken, exceptionContinuation?: Continuation<any>, cancellationContinuation?: Continuation<any>, cancelToken?: CancellationToken): void;
31
- export declare function startAsPromise<T>(computation: IAsync<T>, cancellationToken?: CancellationToken): Promise<T>;
32
- export default Async;
24
+ export declare function start<T>(computation: Async<T>, cancellationToken?: CancellationToken): void;
25
+ export declare function startImmediate<T>(computation: Async<T>, cancellationToken?: CancellationToken): void;
26
+ export declare function startWithContinuations<T>(computation: Async<T>, continuation?: Continuation<T> | CancellationToken, exceptionContinuation?: Continuation<any>, cancellationContinuation?: Continuation<any>, cancelToken?: CancellationToken): void;
27
+ export declare function startAsPromise<T>(computation: Async<T>, cancellationToken?: CancellationToken): Promise<T>;
package/Async.js CHANGED
@@ -1,13 +1,8 @@
1
1
  import { OperationCanceledError, Trampoline } from "./AsyncBuilder.js";
2
2
  import { CancellationToken } from "./AsyncBuilder.js";
3
- import { protectedCont } from "./AsyncBuilder.js";
4
- import { protectedBind } from "./AsyncBuilder.js";
5
- import { protectedReturn } from "./AsyncBuilder.js";
3
+ import { protectedCont, protectedBind, protectedReturn } from "./AsyncBuilder.js";
6
4
  import { Choice_makeChoice1Of2, Choice_makeChoice2Of2 } from "./Choice.js";
7
5
  import { TimeoutException } from "./SystemException.js";
8
- // Implemented just for type references
9
- export class Async {
10
- }
11
6
  function emptyContinuation(_x) {
12
7
  // NOP
13
8
  }
@@ -155,4 +150,3 @@ export function startWithContinuations(computation, continuation, exceptionConti
155
150
  export function startAsPromise(computation, cancellationToken) {
156
151
  return new Promise((resolve, reject) => startWithContinuations(computation, resolve, reject, reject, cancellationToken ? cancellationToken : defaultCancellationToken));
157
152
  }
158
- export default Async;
package/AsyncBuilder.d.ts CHANGED
@@ -39,21 +39,21 @@ export interface IAsyncContext<T> {
39
39
  cancelToken: CancellationToken;
40
40
  trampoline: Trampoline;
41
41
  }
42
- export type IAsync<T> = (x: IAsyncContext<T>) => void;
43
- export declare function protectedCont<T>(f: IAsync<T>): (ctx: IAsyncContext<T>) => void;
44
- export declare function protectedBind<T, U>(computation: IAsync<T>, binder: (x: T) => IAsync<U>): (ctx: IAsyncContext<U>) => void;
42
+ export type Async<T> = (x: IAsyncContext<T>) => void;
43
+ export declare function protectedCont<T>(f: Async<T>): (ctx: IAsyncContext<T>) => void;
44
+ export declare function protectedBind<T, U>(computation: Async<T>, binder: (x: T) => Async<U>): (ctx: IAsyncContext<U>) => void;
45
45
  export declare function protectedReturn<T>(value: T): (ctx: IAsyncContext<T>) => void;
46
46
  export declare class AsyncBuilder {
47
- Bind<T, U>(computation: IAsync<T>, binder: (x: T) => IAsync<U>): (ctx: IAsyncContext<U>) => void;
48
- Combine<T>(computation1: IAsync<void>, computation2: IAsync<T>): (ctx: IAsyncContext<T>) => void;
49
- Delay<T>(generator: () => IAsync<T>): (ctx: IAsyncContext<T>) => void;
50
- For<T>(sequence: Iterable<T>, body: (x: T) => IAsync<void>): IAsync<void>;
51
- Return<T>(value?: T): (ctx: IAsyncContext<T | undefined>) => void;
52
- ReturnFrom<T>(computation: IAsync<T>): IAsync<T>;
53
- TryFinally<T>(computation: IAsync<T>, compensation: () => void): (ctx: IAsyncContext<T>) => void;
54
- TryWith<T>(computation: IAsync<T>, catchHandler: (e: any) => IAsync<T>): (ctx: IAsyncContext<T>) => void;
55
- Using<T extends IDisposable, U>(resource: T, binder: (x: T) => IAsync<U>): (ctx: IAsyncContext<U>) => void;
56
- While(guard: () => boolean, computation: IAsync<void>): IAsync<void>;
47
+ Bind<T, U>(computation: Async<T>, binder: (x: T) => Async<U>): (ctx: IAsyncContext<U>) => void;
48
+ Combine<T>(computation1: Async<void>, computation2: Async<T>): (ctx: IAsyncContext<T>) => void;
49
+ Delay<T>(generator: () => Async<T>): (ctx: IAsyncContext<T>) => void;
50
+ For<T>(sequence: Iterable<T>, body: (x: T) => Async<void>): Async<void>;
51
+ Return<T>(value: T): (ctx: IAsyncContext<T>) => void;
52
+ ReturnFrom<T>(computation: Async<T>): Async<T>;
53
+ TryFinally<T>(computation: Async<T>, compensation: () => void): (ctx: IAsyncContext<T>) => void;
54
+ TryWith<T>(computation: Async<T>, catchHandler: (e: any) => Async<T>): (ctx: IAsyncContext<T>) => void;
55
+ Using<T extends IDisposable, U>(resource: T, binder: (x: T) => Async<U>): (ctx: IAsyncContext<U>) => void;
56
+ While(guard: () => boolean, computation: Async<void>): Async<void>;
57
57
  Zero(): (ctx: IAsyncContext<void>) => void;
58
58
  }
59
59
  export declare const singleton: AsyncBuilder;
package/CHANGELOG.md CHANGED
@@ -7,6 +7,29 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## Unreleased
9
9
 
10
+ ## 1.6.0 - 2024-10-02
11
+
12
+ ### Removed
13
+
14
+ * Remove `Async` (from `Async.ts`) class (by @MangelMaxime)
15
+
16
+ ### Changed
17
+
18
+ * Renamed `IAsync` to `Async` in `AsyncBuilder.ts` (#3906) (by @ncave)
19
+
20
+ ## 1.5.0 - 2024-09-19
21
+
22
+ ### Added
23
+
24
+ * [JS/TS] Add support for `OrdinalIgnoreCase` overload for `String.EndsWith` (#3892) (by @goswinr)
25
+ * [JS/TS] Add `uri.Port`, `uri.IsDefaultPort` (by @MangelMaxime)
26
+
27
+ ### Fixed
28
+
29
+ * [JS/TS] Fix escaping of `{` and `}` in FormattableString (#3890) (by @roboz0r)
30
+ * [JS/TS] Fix `uri.Host` to return the host name without the port (by @MangelMaxime)
31
+ * [JS/TS] Fix TypeScript compilation by resolving type of `jsOptions` (#3894) (by @ManngelMaxime)
32
+
10
33
  ## 1.4.3 - 2024-09-04
11
34
 
12
35
  * [JS/TS] Fixed Decimal comparisons (#3884) (by @ncave)
@@ -1,4 +1,4 @@
1
- import { IAsync } from "./AsyncBuilder.js";
1
+ import { Async } from "./AsyncBuilder.js";
2
2
  import { Continuation } from "./AsyncBuilder.js";
3
3
  import { CancellationToken } from "./AsyncBuilder.js";
4
4
  declare class MailboxQueue<Msg> {
@@ -6,7 +6,7 @@ declare class MailboxQueue<Msg> {
6
6
  add(message: Msg): void;
7
7
  tryGet(): Msg | undefined;
8
8
  }
9
- export type MailboxBody<Msg> = (m: MailboxProcessor<Msg>) => IAsync<void>;
9
+ export type MailboxBody<Msg> = (m: MailboxProcessor<Msg>) => Async<void>;
10
10
  export interface AsyncReplyChannel<Reply> {
11
11
  reply: (r: Reply) => void;
12
12
  }
package/String.d.ts CHANGED
@@ -2,6 +2,7 @@ export declare function compare(...args: any[]): number;
2
2
  export declare function compareOrdinal(x: string, y: string): number;
3
3
  export declare function compareTo(x: string, y: string): number;
4
4
  export declare function startsWith(str: string, pattern: string, ic: number): boolean;
5
+ export declare function endsWith(str: string, pattern: string, ic: number): boolean;
5
6
  export declare function indexOfAny(str: string, anyOf: string[], ...args: number[]): number;
6
7
  export type IPrintfFormatContinuation = (f: (x: string) => any) => any;
7
8
  export interface IPrintfFormat {
@@ -16,7 +17,6 @@ export declare function toText(arg: IPrintfFormat | string): any;
16
17
  export declare function toFail(arg: IPrintfFormat | string): any;
17
18
  export declare function fsFormat(str: string): (cont: (...args: any[]) => any) => any;
18
19
  export declare function format(str: string | object, ...args: any[]): string;
19
- export declare function endsWith(str: string, search: string): boolean;
20
20
  export declare function initialize(n: number, f: (i: number) => string): string;
21
21
  export declare function insert(str: string, startIndex: number, value: string): string;
22
22
  export declare function isNullOrEmpty(str: string | any): boolean;
package/String.js CHANGED
@@ -58,11 +58,23 @@ export function compareTo(x, y) {
58
58
  return cmp(x, y, 0 /* StringComparison.CurrentCulture */);
59
59
  }
60
60
  export function startsWith(str, pattern, ic) {
61
+ if (ic === 4 /* StringComparison.Ordinal */) { // to avoid substring allocation
62
+ return str.startsWith(pattern);
63
+ }
61
64
  if (str.length >= pattern.length) {
62
65
  return cmp(str.substr(0, pattern.length), pattern, ic) === 0;
63
66
  }
64
67
  return false;
65
68
  }
69
+ export function endsWith(str, pattern, ic) {
70
+ if (ic === 4 /* StringComparison.Ordinal */) { // to avoid substring allocation
71
+ return str.endsWith(pattern);
72
+ }
73
+ if (str.length >= pattern.length) {
74
+ return cmp(str.substr(str.length - pattern.length, pattern.length), pattern, ic) === 0;
75
+ }
76
+ return false;
77
+ }
66
78
  export function indexOfAny(str, anyOf, ...args) {
67
79
  if (str == null || str === "") {
68
80
  return -1;
@@ -361,10 +373,6 @@ export function format(str, ...args) {
361
373
  return rep;
362
374
  });
363
375
  }
364
- export function endsWith(str, search) {
365
- const idx = str.lastIndexOf(search);
366
- return idx >= 0 && idx === str.length - search.length;
367
- }
368
376
  export function initialize(n, f) {
369
377
  if (n < 0) {
370
378
  throw new Error("String length must be non-negative");
@@ -537,7 +545,10 @@ export function fmtWith(fmts) {
537
545
  return (strs, ...args) => ({ strs, args, fmts });
538
546
  }
539
547
  export function getFormat(s) {
548
+ const strs = s.strs.map((value) => value.replace(/{/g, '{{').replace(/}/g, '}}'));
540
549
  return s.fmts
541
- ? s.strs.reduce((acc, newPart, index) => acc + `{${String(index - 1) + s.fmts[index - 1]}}` + newPart)
542
- : s.strs.reduce((acc, newPart, index) => acc + `{${index - 1}}` + newPart);
550
+ ? strs
551
+ .reduce((acc, newPart, index) => acc + `{${String(index - 1) + s.fmts[index - 1]}}` + newPart)
552
+ : strs
553
+ .reduce((acc, newPart, index) => acc + `{${index - 1}}` + newPart);
543
554
  }
package/Uri.d.ts CHANGED
@@ -22,6 +22,8 @@ export declare class Uri {
22
22
  get host(): string;
23
23
  get absolutePath(): string;
24
24
  get query(): string;
25
+ get isDefaultPort(): boolean;
26
+ get port(): number;
25
27
  get pathAndQuery(): string;
26
28
  get fragment(): string;
27
29
  get originalString(): string;
package/Uri.js CHANGED
@@ -119,7 +119,13 @@ export class Uri {
119
119
  return protocol.slice(0, protocol.length - 1);
120
120
  }
121
121
  get host() {
122
- return this.asUrl().host;
122
+ const host = this.asUrl().host;
123
+ if (host.includes(":")) {
124
+ return host.split(":")[0];
125
+ }
126
+ else {
127
+ return host;
128
+ }
123
129
  }
124
130
  get absolutePath() {
125
131
  return this.asUrl().pathname;
@@ -127,6 +133,18 @@ export class Uri {
127
133
  get query() {
128
134
  return this.asUrl().search;
129
135
  }
136
+ get isDefaultPort() {
137
+ return this.port === 80;
138
+ }
139
+ get port() {
140
+ const port = this.asUrl().port;
141
+ if (port === "") {
142
+ return 80;
143
+ }
144
+ else {
145
+ return parseInt(port);
146
+ }
147
+ }
130
148
  get pathAndQuery() {
131
149
  const url = this.asUrl();
132
150
  return url.pathname + url.search;
package/Util.d.ts CHANGED
@@ -161,7 +161,7 @@ export declare function max<T>(comparer: (x: T, y: T) => number, x: T, y: T): T;
161
161
  export declare function clamp<T>(comparer: (x: T, y: T) => number, value: T, min: T, max: T): T;
162
162
  export declare function createAtom<T>(value: T): (<Args extends [] | [T]>(...args: Args) => Args extends [] ? T : void);
163
163
  export declare function createObj(fields: Iterable<[string, any]>): any;
164
- export declare function jsOptions(mutator: (x: object) => void): object;
164
+ export declare function jsOptions<T>(mutator: (x: T) => void): T;
165
165
  export declare function round(value: number, digits?: number): number;
166
166
  export declare function sign(x: number): number;
167
167
  export declare function unescapeDataString(s: string): string;
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "private": false,
4
4
  "type": "module",
5
5
  "name": "@fable-org/fable-library-js",
6
- "version": "1.4.3",
6
+ "version": "1.6.0",
7
7
  "description": "Core library used by F# projects compiled with fable.io",
8
8
  "author": "Fable Contributors",
9
9
  "license": "MIT",