This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function stringifyMaxDepth (obj, depth = 1) { | |
// recursion limited by depth arg | |
if (!obj || typeof obj !== 'object') return JSON.stringify(obj) | |
let curDepthResult = '"<?>"' // too deep | |
if (depth > 0) { | |
curDepthResult = Object.keys(obj) | |
.map( (key) => { | |
let val = stringifyMaxDepth(obj[key], depth - 1) | |
if (val === undefined) val = 'null' |