@augment-vir/core 31.33.1 → 31.34.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.
@@ -1,4 +1,11 @@
1
1
  import JSON5 from 'json5';
2
+ /**
3
+ * Internal sentinel used to preserve `undefined` values through JSON5 serialization. Chosen to be
4
+ * extremely unlikely to appear in real user content. If it _does_ appear naturally it will be
5
+ * incorrectly replaced (very low probability).
6
+ */
7
+ const undefinedSentinel = '__@@augment-vir-undefined-sentinel@@__';
8
+ const undefinedSentinelStringRegExp = new RegExp(`['"]${undefinedSentinel}['"]`);
2
9
  /**
3
10
  * Converts the input into a string. Tries first with JSON5 and, if that fails, falls back to a
4
11
  * regular `.toString()` conversion.
@@ -10,7 +17,15 @@ import JSON5 from 'json5';
10
17
  */
11
18
  export function stringify(input) {
12
19
  try {
13
- return JSON5.stringify(input);
20
+ const json5String = JSON5.stringify(input,
21
+ // Use a replacer to turn undefined into a unique string so the key is kept.
22
+ (_key, value) => {
23
+ if (value === undefined) {
24
+ return undefinedSentinel;
25
+ }
26
+ return value;
27
+ });
28
+ return json5String.split(undefinedSentinelStringRegExp).join('undefined');
14
29
  }
15
30
  catch {
16
31
  return String(input);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@augment-vir/core",
3
- "version": "31.33.1",
3
+ "version": "31.34.1",
4
4
  "description": "Core augment-vir augments. Use @augment-vir/common instead.",
5
5
  "homepage": "https://github.com/electrovir/augment-vir",
6
6
  "bugs": {