safe-flat is a JavaScript/TypeScript utility library designed for safely flattening and unflattening deeply nested objects. Its primary function, `flatten`, converts a multi-level object into a single-level object, using a configurable delimiter (defaulting to '.'). A key feature is its robust handling of circular references, which it replaces with the `[Circular]` string during flattening to prevent infinite recursion and serialization issues. The companion function, `unflatten`, reconstructs the original nested object structure from a flattened representation, treating `[Circular]` markers as literal string values. The current stable version, 2.1.0, is distributed with TypeScript types, enhancing developer experience. It appears to have a stable, though infrequent, release cadence, focusing on reliability for object serialization and deserialization tasks by mitigating common pitfalls like circular references.
npm install safe-flatVerified import paths — ran on the pinned version, not inferred.
Demonstrates how to flatten a nested object (including circular references) and then unflatten it back, using both default and custom delimiters.
Be aware of this design choice. If true circular reference reconstruction is required, `safe-flat` is not the appropriate tool; consider a custom serialization/deserialization solution.
Always ensure the `delimiter` argument to `unflatten` is identical to the one used for `flatten`.
For specific serialization needs of complex types beyond standard JSON primitives and circular reference handling, additional pre- or post-processing steps or a different library might be necessary.
Verify that the `delimiter` argument passed to `unflatten` is the same as the one used for `flatten`. Inspect the flattened object's keys to ensure they follow the expected delimited path format.
No fix within `safe-flat` itself. If true circular reference restoration is a requirement, an alternative serialization/deserialization strategy or library must be used.
No dependency data recorded yet.