@fable-org/fable-library-ts 1.4.2 → 1.5.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/CHANGELOG.md CHANGED
@@ -7,6 +7,23 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## Unreleased
9
9
 
10
+ ## 1.5.0 - 2024-09-19
11
+
12
+ ### Added
13
+
14
+ * [JS/TS] Add support for `OrdinalIgnoreCase` overload for `String.EndsWith` (#3892) (by @goswinr)
15
+ * [JS/TS] Add `uri.Port`, `uri.IsDefaultPort` (by @MangelMaxime)
16
+
17
+ ### Fixed
18
+
19
+ * [JS/TS] Fix escaping of `{` and `}` in FormattableString (#3890) (by @roboz0r)
20
+ * [JS/TS] Fix `uri.Host` to return the host name without the port (by @MangelMaxime)
21
+ * [JS/TS] Fix TypeScript compilation by resolving type of `jsOptions` (#3894) (by @ManngelMaxime)
22
+
23
+ ## 1.4.3 - 2024-09-04
24
+
25
+ * [JS/TS] Fixed Decimal comparisons (#3884) (by @ncave)
26
+
10
27
  ## 1.4.2 - 2024-06-13
11
28
 
12
29
  ### Fixed
package/Date.ts CHANGED
@@ -524,7 +524,6 @@ export function parseRaw(input: string): [Date, Offset] {
524
524
 
525
525
  if (isNaN(date.getTime())) {
526
526
  // Try to check strings JS Date cannot parse (see #1045, #1422)
527
- // tslint:disable-next-line:max-line-length
528
527
  const m = /^\s*(\d+[^\w\s:]\d+[^\w\s:]\d+)?\s*(\d+:\d+(?::\d+(?:\.\d+)?)?)?\s*([AaPp][Mm])?\s*(Z|[+-]([01]?\d):?([0-5]?\d)?)?\s*$/.exec(input);
529
528
  if (m != null) {
530
529
  let baseDate: Date;
package/Decimal.ts CHANGED
@@ -44,16 +44,16 @@ export function equals(x: Decimal, y: Decimal) {
44
44
  }
45
45
 
46
46
  export function abs(x: Decimal) { return x.abs(); }
47
- export function sign(x: Decimal): number { return x < get_Zero ? -1 : x > get_Zero ? 1 : 0; }
47
+ export function sign(x: Decimal): number { return x.lt(get_Zero) ? -1 : x.gt(get_Zero) ? 1 : 0; }
48
48
 
49
- export function max(x: Decimal, y: Decimal): Decimal { return x > y ? x : y; }
50
- export function min(x: Decimal, y: Decimal): Decimal { return x < y ? x : y; }
49
+ export function max(x: Decimal, y: Decimal): Decimal { return x.gt(y) ? x : y; }
50
+ export function min(x: Decimal, y: Decimal): Decimal { return x.lt(y) ? x : y; }
51
51
 
52
- export function maxMagnitude(x: Decimal, y: Decimal): Decimal { return abs(x) > abs(y) ? x : y; }
53
- export function minMagnitude(x: Decimal, y: Decimal): Decimal { return abs(x) < abs(y) ? x : y; }
52
+ export function maxMagnitude(x: Decimal, y: Decimal): Decimal { return abs(x).gt(abs(y)) ? x : y; }
53
+ export function minMagnitude(x: Decimal, y: Decimal): Decimal { return abs(x).lt(abs(y)) ? x : y; }
54
54
 
55
55
  export function clamp(x: Decimal, min: Decimal, max: Decimal): Decimal {
56
- return x < min ? min : x > max ? max : x;
56
+ return x.lt(min) ? min : x.gt(max) ? max : x;
57
57
  }
58
58
 
59
59
  export function round(x: Decimal, digits: number = 0) {
package/RegExp.ts CHANGED
@@ -48,7 +48,6 @@ export function matches(reg: RegExp, input: string, startAt = 0) {
48
48
  const matches: RegExpExecArray[] = [];
49
49
  let m: RegExpExecArray | null;
50
50
  let lastMatchIndex = -1;
51
- // tslint:disable-next-line:no-conditional-assignment
52
51
  while ((m = reg.exec(input)) != null) {
53
52
  // It can happen even global regex get stuck, see #2845
54
53
  if (m.index === lastMatchIndex) {
package/String.ts CHANGED
@@ -64,12 +64,25 @@ export function compareTo(x: string, y: string) {
64
64
  }
65
65
 
66
66
  export function startsWith(str: string, pattern: string, ic: number) {
67
+ if (ic === StringComparison.Ordinal) { // to avoid substring allocation
68
+ return str.startsWith(pattern);
69
+ }
67
70
  if (str.length >= pattern.length) {
68
71
  return cmp(str.substr(0, pattern.length), pattern, ic) === 0;
69
72
  }
70
73
  return false;
71
74
  }
72
75
 
76
+ export function endsWith(str: string, pattern: string, ic: number) {
77
+ if (ic === StringComparison.Ordinal) { // to avoid substring allocation
78
+ return str.endsWith(pattern);
79
+ }
80
+ if (str.length >= pattern.length) {
81
+ return cmp(str.substr(str.length - pattern.length, pattern.length), pattern, ic) === 0;
82
+ }
83
+ return false;
84
+ }
85
+
73
86
  export function indexOfAny(str: string, anyOf: string[], ...args: number[]) {
74
87
  if (str == null || str === "") {
75
88
  return -1;
@@ -87,7 +100,7 @@ export function indexOfAny(str: string, anyOf: string[], ...args: number[]) {
87
100
  }
88
101
  const endIndex = startIndex + length
89
102
  const anyOfAsStr = "".concat.apply("", anyOf);
90
- for (let i=startIndex; i<endIndex; i++) {
103
+ for (let i = startIndex; i < endIndex; i++) {
91
104
  if (anyOfAsStr.indexOf(str[i]) > -1) {
92
105
  return i;
93
106
  }
@@ -374,10 +387,6 @@ export function format(str: string | object, ...args: any[]) {
374
387
  });
375
388
  }
376
389
 
377
- export function endsWith(str: string, search: string) {
378
- const idx = str.lastIndexOf(search);
379
- return idx >= 0 && idx === str.length - search.length;
380
- }
381
390
 
382
391
  export function initialize(n: number, f: (i: number) => string) {
383
392
  if (n < 0) {
@@ -587,7 +596,11 @@ export function fmtWith(fmts: string[]) {
587
596
  }
588
597
 
589
598
  export function getFormat(s: FormattableString) {
599
+ const strs = s.strs.map((value) => value.replace(/{/g, '{{').replace(/}/g, '}}'));
600
+
590
601
  return s.fmts
591
- ? s.strs.reduce((acc, newPart, index) => acc + `{${String(index - 1) + s.fmts![index - 1]}}` + newPart)
592
- : s.strs.reduce((acc, newPart, index) => acc + `{${index - 1}}` + newPart);
602
+ ? strs
603
+ .reduce((acc, newPart, index) => acc + `{${String(index - 1) + s.fmts![index - 1]}}` + newPart)
604
+ : strs
605
+ .reduce((acc, newPart, index) => acc + `{${index - 1}}` + newPart);
593
606
  }
package/TimeSpan.ts CHANGED
@@ -1,4 +1,3 @@
1
- // tslint:disable:max-line-length
2
1
  import { FSharpRef } from "./Types.js";
3
2
  import { comparePrimitives, padLeftAndRightWithZeros, padWithZeros } from "./Util.js";
4
3
  import { toInt64, fromFloat64 } from "./BigInt.js";
package/Types.ts CHANGED
@@ -199,7 +199,7 @@ export function isPromise(x: any) {
199
199
  return x instanceof Promise;
200
200
  }
201
201
 
202
- export function ensureErrorOrException(e: any) {
202
+ export function ensureErrorOrException(e: any): any {
203
203
  // Exceptionally admitting promises as errors for compatibility with React.suspense (see #3298)
204
204
  return (isException(e) || isPromise(e)) ? e : new Error(String(e));
205
205
  }
package/Uri.ts CHANGED
@@ -26,7 +26,6 @@ export class Uri {
26
26
 
27
27
  private static isAbsoluteUri(uri: string): boolean {
28
28
  try {
29
- // tslint:disable-next-line no-unused-expression
30
29
  new URL(uri);
31
30
  return true;
32
31
  } catch {
@@ -178,7 +177,13 @@ export class Uri {
178
177
  }
179
178
 
180
179
  get host() {
181
- return this.asUrl().host;
180
+ const host = this.asUrl().host;
181
+
182
+ if (host.includes(":")) {
183
+ return host.split(":")[0];
184
+ } else {
185
+ return host;
186
+ }
182
187
  }
183
188
 
184
189
  get absolutePath() {
@@ -189,6 +194,20 @@ export class Uri {
189
194
  return this.asUrl().search;
190
195
  }
191
196
 
197
+ get isDefaultPort() {
198
+ return this.port === 80;
199
+ }
200
+
201
+ get port() {
202
+ const port = this.asUrl().port;
203
+
204
+ if (port === "") {
205
+ return 80;
206
+ } else {
207
+ return parseInt(port);
208
+ }
209
+ }
210
+
192
211
  get pathAndQuery() {
193
212
  const url = this.asUrl();
194
213
  return url.pathname + url.search;
package/Util.ts CHANGED
@@ -1,5 +1,3 @@
1
- // tslint:disable:ban-types
2
-
3
1
  // Don't change, this corresponds to DateTime.Kind enum values in .NET
4
2
  export const enum DateKind {
5
3
  Unspecified = 0,
@@ -590,8 +588,8 @@ export function createObj(fields: Iterable<[string, any]>) {
590
588
  return obj;
591
589
  }
592
590
 
593
- export function jsOptions(mutator: (x: object) => void): object {
594
- const opts = {};
591
+ export function jsOptions<T>(mutator: (x: T) => void): T {
592
+ const opts = {} as T;
595
593
  mutator(opts);
596
594
  return opts;
597
595
  }
package/lib/big.js CHANGED
@@ -1,5 +1,4 @@
1
1
  // Adapted from https://github.com/MikeMcl/big.js/blob/0f94dc9110d55c4f324a47ba6a2e832ce23ac589/big.mjs
2
- /* tslint:disable */
3
2
 
4
3
  var P = {};
5
4
 
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.4.2",
6
+ "version": "1.5.0",
7
7
  "description": "Core library used by F# projects compiled with fable.io",
8
8
  "author": "Fable Contributors",
9
9
  "license": "MIT",