* Creates a JSON replacer function that handles Map, Set, and circular references. * This replacer can be used with JSON.stringify to safely serialize complex objects. * * @returns {Function} A replacer function for JSON.stringify that: * - Converts Map instances to plain objects * -
()
| 500 | * // Output: {"name":"test","map":{"key":"value"},"self":"[Circular]"} |
| 501 | */ |
| 502 | static getCircularReplacer() { |
| 503 | const seen = new WeakSet(); |
| 504 | return (key, value) => { |
| 505 | if (Utils.isMap(value)) { |
| 506 | return Object.fromEntries(value); |
| 507 | } |
| 508 | if (Utils.isSet(value)) { |
| 509 | return Array.from(value); |
| 510 | } |
| 511 | if (typeof value === 'object' && value !== null) { |
| 512 | if (seen.has(value)) { |
| 513 | return '[Circular]'; |
| 514 | } |
| 515 | seen.add(value); |
| 516 | } |
| 517 | return value; |
| 518 | }; |
| 519 | } |
| 520 | |
| 521 | /** |
| 522 | * Gets a nested property value from an object using dot notation. |
no test coverage detected