typeson-registry 14.2.0 → 14.2.1

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.
@@ -2423,11 +2423,51 @@
2423
2423
  test: function test(x) {
2424
2424
  return toStringTag(x) === 'Number' && _typeof(x) === 'object';
2425
2425
  },
2426
- replace: Number,
2427
- // convert to primitive number
2426
+ // `_encapsulate`'s nested-replace guard (`_stateObj.replaced`)
2427
+ // means a bare `NaN`/`Infinity`/`-Infinity`/`-0` returned here
2428
+ // would skip the sentinel treatment the bare `nan`/`infinity`/
2429
+ // `negativeZero` type specs normally give those values (since
2430
+ // we're already inside this spec's own `replace()`) -- JSON
2431
+ // can't represent them, so they'd otherwise silently become
2432
+ // `null` (or lose their sign, for `-0`). Encode them the same
2433
+ // way those specs do, directly, rather than relying on that
2434
+ // nested pass.
2435
+ replace: function replace(o) {
2436
+ var n = o.valueOf();
2437
+ if (Number.isNaN(n)) {
2438
+ return 'NaN';
2439
+ }
2440
+ if (n === Infinity) {
2441
+ return 'Infinity';
2442
+ }
2443
+ if (n === -Infinity) {
2444
+ return '-Infinity';
2445
+ }
2446
+ if (Object.is(n, -0)) {
2447
+ // A plain `0` here would be indistinguishable from a
2448
+ // genuine positive `0` once round-tripped through JSON
2449
+ // (which can't represent the sign), so this needs its
2450
+ // own sentinel too, same as the others above.
2451
+ return '-0';
2452
+ }
2453
+ return n;
2454
+ },
2455
+ // Revive to an objectified number
2428
2456
  revive: function revive(n) {
2457
+ if (n === 'NaN') {
2458
+ return new Number(NaN);
2459
+ }
2460
+ if (n === 'Infinity') {
2461
+ return new Number(Infinity);
2462
+ }
2463
+ if (n === '-Infinity') {
2464
+ return new Number(-Infinity);
2465
+ }
2466
+ if (n === '-0') {
2467
+ return new Number(-0);
2468
+ }
2429
2469
  return new Number(n);
2430
- } // Revive to an objectified number
2470
+ }
2431
2471
  }
2432
2472
  };
2433
2473