@fable-org/fable-library-js 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.js CHANGED
@@ -18,10 +18,19 @@ export function create(pattern, options = 0) {
18
18
  }
19
19
  // From http://stackoverflow.com/questions/3446170/escape-string-for-use-in-javascript-regex
20
20
  export function escape(str) {
21
- return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&");
21
+ // Matches the characters escaped by .NET's Regex.Escape.
22
+ // Note:
23
+ //
24
+ // .NET also escapes space and # (relevant for IgnorePatternWhitespace mode),
25
+ // but JS unicode-mode regex rejects \ and \# as invalid escapes, and we don't
26
+ // support IgnorePatternWhitespace, so we omit them.
27
+ //
28
+ // .NET does not escape ] and } but JS unicode-mode regex rejects bare ] and }
29
+ // as invalid, so we escape them too for compatibility.
30
+ return str.replace(/[$()*+.?[\\\^{|}\]]/g, "\\$&");
22
31
  }
23
32
  export function unescape(str) {
24
- return str.replace(/\\([\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|])/g, "$1");
33
+ return str.replace(/\\([$()*+.?[\\\^{|}\]])/g, "$1");
25
34
  }
26
35
  export function isMatch(reg, input, startAt = 0) {
27
36
  reg.lastIndex = startAt;
package/String.js CHANGED
@@ -331,7 +331,12 @@ export function format(str, ...args) {
331
331
  precision = precision == null ? 2 : precision;
332
332
  rep = toFixed(rep, precision);
333
333
  parts = splitIntAndDecimalPart(rep);
334
- rep = "¤" + thousandSeparate(parts.integral) + "." + padRight(parts.decimal, precision, "0");
334
+ if (precision > 0) {
335
+ rep = "¤" + thousandSeparate(parts.integral) + "." + padRight(parts.decimal, precision, "0");
336
+ }
337
+ else {
338
+ rep = "¤" + thousandSeparate(parts.integral);
339
+ }
335
340
  if (isNegative) {
336
341
  rep = "(" + rep + ")";
337
342
  }
@@ -375,14 +380,24 @@ export function format(str, ...args) {
375
380
  precision = precision != null ? precision : 2;
376
381
  rep = toFixed(rep, precision);
377
382
  parts = splitIntAndDecimalPart(rep);
378
- rep = thousandSeparate(parts.integral) + "." + padRight(parts.decimal, precision, "0");
383
+ if (precision > 0) {
384
+ rep = thousandSeparate(parts.integral) + "." + padRight(parts.decimal, precision, "0");
385
+ }
386
+ else {
387
+ rep = thousandSeparate(parts.integral);
388
+ }
379
389
  break;
380
390
  case "p":
381
391
  case "P":
382
392
  precision = precision != null ? precision : 2;
383
393
  rep = toFixed(multiply(rep, 100), precision);
384
394
  parts = splitIntAndDecimalPart(rep);
385
- rep = thousandSeparate(parts.integral) + "." + padRight(parts.decimal, precision, "0") + " %";
395
+ if (precision > 0) {
396
+ rep = thousandSeparate(parts.integral) + "." + padRight(parts.decimal, precision, "0") + " %";
397
+ }
398
+ else {
399
+ rep = thousandSeparate(parts.integral) + " %";
400
+ }
386
401
  break;
387
402
  case "r":
388
403
  case "R":
package/Types.js CHANGED
@@ -36,6 +36,12 @@ export function toString(x, callStack = 0) {
36
36
  return String(x);
37
37
  }
38
38
  export function unionToString(name, fields) {
39
+ function unionFieldToString(x) {
40
+ if (typeof x === "string") {
41
+ return '"' + x + '"';
42
+ }
43
+ return toString(x);
44
+ }
39
45
  if (fields.length === 0) {
40
46
  return name;
41
47
  }
@@ -43,11 +49,11 @@ export function unionToString(name, fields) {
43
49
  let fieldStr;
44
50
  let withParens = true;
45
51
  if (fields.length === 1) {
46
- fieldStr = toString(fields[0]);
52
+ fieldStr = unionFieldToString(fields[0]);
47
53
  withParens = fieldStr.indexOf(" ") >= 0;
48
54
  }
49
55
  else {
50
- fieldStr = fields.map((x) => toString(x)).join(", ");
56
+ fieldStr = fields.map((x) => unionFieldToString(x)).join(", ");
51
57
  }
52
58
  return name + (withParens ? " (" : " ") + fieldStr + (withParens ? ")" : "");
53
59
  }
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": "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",