@augment-vir/common
Version:
A collection of augments, helpers types, functions, and classes for any JavaScript environment.
34 lines (33 loc) • 738 B
JavaScript
import JSON5 from 'json5';
/**
* Creates a JSON compatible version of the value given. Under the hood this is actually the same as
* {@link copyThroughJson}.
*
* @category JSON : Common
* @category Package : @augment-vir/common
* @example
*
* ```ts
* import {jsonify} from '@augment-vir/common';
*
* // `result` is `{b: 'b'}`
* const result = jsonify({
* map: new Map([
* [
* 'q',
* 'r',
* ],
* [
* 's',
* 't',
* ],
* ]),
* b: 'b',
* });
* ```
*
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
*/
export function jsonify(value) {
return JSON5.parse(JSON5.stringify(value));
}