@fable-org/fable-library-ts 1.4.3 → 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,19 @@ 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
+
10
23
  ## 1.4.3 - 2024-09-04
11
24
 
12
25
  * [JS/TS] Fixed Decimal comparisons (#3884) (by @ncave)
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/Uri.ts CHANGED
@@ -177,7 +177,13 @@ export class Uri {
177
177
  }
178
178
 
179
179
  get host() {
180
- 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
+ }
181
187
  }
182
188
 
183
189
  get absolutePath() {
@@ -188,6 +194,20 @@ export class Uri {
188
194
  return this.asUrl().search;
189
195
  }
190
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
+
191
211
  get pathAndQuery() {
192
212
  const url = this.asUrl();
193
213
  return url.pathname + url.search;
package/Util.ts CHANGED
@@ -588,8 +588,8 @@ export function createObj(fields: Iterable<[string, any]>) {
588
588
  return obj;
589
589
  }
590
590
 
591
- export function jsOptions(mutator: (x: object) => void): object {
592
- const opts = {};
591
+ export function jsOptions<T>(mutator: (x: T) => void): T {
592
+ const opts = {} as T;
593
593
  mutator(opts);
594
594
  return opts;
595
595
  }
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.3",
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",