@fable-org/fable-library-ts 2.0.0-rc.4 → 2.0.0-rc.5

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,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## Unreleased
9
9
 
10
+ ## 2.0.0-rc.5 - 2026-03-31
11
+
12
+ ### Fixed
13
+
14
+ * [JS/TS] Improve `Regex.Escape` and `Regex.Unescape` handling (by @MangelMaxime)
15
+ * [JS/TS] Fixed quotation for union string cases (by @MangelMaxime)
16
+
10
17
  ## 2.0.0-rc.4 - 2026-03-19
11
18
 
12
19
  ### Fixed
package/RegExp.ts CHANGED
@@ -22,11 +22,20 @@ export function create(pattern: string, options = 0) {
22
22
  // From http://stackoverflow.com/questions/3446170/escape-string-for-use-in-javascript-regex
23
23
 
24
24
  export function escape(str: string) {
25
- return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&");
25
+ // Matches the characters escaped by .NET's Regex.Escape.
26
+ // Note:
27
+ //
28
+ // .NET also escapes space and # (relevant for IgnorePatternWhitespace mode),
29
+ // but JS unicode-mode regex rejects \ and \# as invalid escapes, and we don't
30
+ // support IgnorePatternWhitespace, so we omit them.
31
+ //
32
+ // .NET does not escape ] and } but JS unicode-mode regex rejects bare ] and }
33
+ // as invalid, so we escape them too for compatibility.
34
+ return str.replace(/[$()*+.?[\\\^{|}\]]/g, "\\$&");
26
35
  }
27
36
 
28
37
  export function unescape(str: string) {
29
- return str.replace(/\\([\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|])/g, "$1");
38
+ return str.replace(/\\([$()*+.?[\\\^{|}\]])/g, "$1");
30
39
  }
31
40
 
32
41
  export function isMatch(reg: RegExp, input: string, startAt = 0) {
package/String.ts CHANGED
@@ -344,7 +344,11 @@ export function format(str: string | object, ...args: any[]) {
344
344
  precision = precision == null ? 2 : precision;
345
345
  rep = toFixed(rep, precision);
346
346
  parts = splitIntAndDecimalPart(rep);
347
- rep = "¤" + thousandSeparate(parts.integral) + "." + padRight(parts.decimal, precision, "0");
347
+ if (precision > 0) {
348
+ rep = "¤" + thousandSeparate(parts.integral) + "." + padRight(parts.decimal, precision, "0");
349
+ } else {
350
+ rep = "¤" + thousandSeparate(parts.integral);
351
+ }
348
352
  if (isNegative) {
349
353
  rep = "(" + rep + ")";
350
354
  }
@@ -382,13 +386,21 @@ export function format(str: string | object, ...args: any[]) {
382
386
  precision = precision != null ? precision : 2;
383
387
  rep = toFixed(rep, precision);
384
388
  parts = splitIntAndDecimalPart(rep);
385
- rep = thousandSeparate(parts.integral) + "." + padRight(parts.decimal, precision, "0");
389
+ if (precision > 0) {
390
+ rep = thousandSeparate(parts.integral) + "." + padRight(parts.decimal, precision, "0");
391
+ } else {
392
+ rep = thousandSeparate(parts.integral);
393
+ }
386
394
  break;
387
395
  case "p": case "P":
388
396
  precision = precision != null ? precision : 2;
389
397
  rep = toFixed(multiply(rep, 100), precision)
390
398
  parts = splitIntAndDecimalPart(rep);
391
- rep = thousandSeparate(parts.integral) + "." + padRight(parts.decimal, precision, "0") + " %";
399
+ if (precision > 0) {
400
+ rep = thousandSeparate(parts.integral) + "." + padRight(parts.decimal, precision, "0") + " %";
401
+ } else {
402
+ rep = thousandSeparate(parts.integral) + " %";
403
+ }
392
404
  break;
393
405
  case "r": case "R":
394
406
  throw new Exception("The round-trip format is not supported by Fable");
package/Types.ts CHANGED
@@ -39,16 +39,23 @@ export function toString(x: any, callStack = 0): string {
39
39
  }
40
40
 
41
41
  export function unionToString(name: string, fields: any[]) {
42
+ function unionFieldToString(x: any): string {
43
+ if (typeof x === "string") {
44
+ return '"' + x + '"';
45
+ }
46
+ return toString(x);
47
+ }
48
+
42
49
  if (fields.length === 0) {
43
50
  return name;
44
51
  } else {
45
52
  let fieldStr;
46
53
  let withParens = true;
47
54
  if (fields.length === 1) {
48
- fieldStr = toString(fields[0]);
55
+ fieldStr = unionFieldToString(fields[0]);
49
56
  withParens = fieldStr.indexOf(" ") >= 0;
50
57
  } else {
51
- fieldStr = fields.map((x: any) => toString(x)).join(", ");
58
+ fieldStr = fields.map((x: any) => unionFieldToString(x)).join(", ");
52
59
  }
53
60
  return name + (withParens ? " (" : " ") + fieldStr + (withParens ? ")" : "");
54
61
  }
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-rc.4",
6
+ "version": "2.0.0-rc.5",
7
7
  "description": "Core library used by F# projects compiled with fable.io",
8
8
  "author": "Fable Contributors",
9
9
  "license": "MIT",