maybe-stringify
A Node.js module which will convert data to JSON or, if the conversion is not possible, will return a fallback value.
Installation
npm install maybe-stringify --save
Usage
const maybeStringify = // returns '["test"]' // Default fallback behavior is to return the value as-is,// but this can be overridden. // returns the function as-is since it can't stringify // returns 'something else' // Set `safe` to `false` to make recursive references trigger// the fallback behavior.const recursive = {}recursiveprop = recursive // returns '{"recursive":"[Circular]"}' // returns the object as-is since it can't stringify