This file contains hidden or 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 compactify(ugly) { | |
// Step 1: JSON stringify with indentation (4 spaces) | |
const first_pass = JSON.stringify(JSON.parse(ugly), null, 4) | |
// Step 2: Put comma-sep. numbers on same line | |
const comma_num_newline_ptn = /,\n +((\d\.)?\d+)/g | |
const num_same_line = first_pass.replace(comma_num_newline_ptn, ', $1') | |
// Step 3: Put flat arrays on same line | |
const flat_array_ptn = /\[\n\s+(([\d.]+, )+[\d.]+)\n\s+\]/g |