https://github.com/aneldev/dyna-stringify
Stringify object with circular references with custom text.
https://github.com/aneldev/dyna-stringify
Last synced: 12 months ago
JSON representation
Stringify object with circular references with custom text.
- Host: GitHub
- URL: https://github.com/aneldev/dyna-stringify
- Owner: aneldev
- License: mit
- Created: 2020-02-13T07:30:34.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2022-12-12T01:49:25.000Z (over 3 years ago)
- Last Synced: 2025-06-21T18:05:35.994Z (12 months ago)
- Language: JavaScript
- Size: 3.83 MB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 23
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# About
Stringify object with circular references.
# Usage
```
// Minimal usage
dynaStringify(value);
dynaStringify(value, {spaces: 2});
dynaStringify(value, {spaces: 2, circularText: '!REF'});
// Extensive with callback for the reference text
dynaStringify(
value,
{
spaces: 2,
circularText: value => {
if (value.customerId) return `!RefCustId:${value.customerId}`;
return '!Ref',
}
}
);
```
# Syntax
_In Typescript_
```
dynaStringify = (
value: any,
options?: {
spaces?: number;
circularText?: string | ((value: any) => string);
},
): string;
```
# Example
```
const value = {
name: 'John',
age: 32,
cars: ['VW', 'Plymouth'],
};
value.cars.push(value);
```
The
`dynaStringify(value, {spaces: 2})`
returns
```
{
"name": "John",
"age": 32,
"cars": [
"VW",
"Plymouth",
"[CircularRef]"
]
}
```