UNPKG

script-launcher

Version:
40 lines (39 loc) 1.28 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var Colors; (function (Colors) { Colors["Red"] = "\u001B[31m"; Colors["Green"] = "\u001B[32m"; Colors["Yellow"] = "\u001B[33m"; Colors["Blue"] = "\u001B[94m"; Colors["Orange"] = "\u001B[38;2;255;165;0m"; Colors["Cyan"] = "\u001B[36m"; Colors["Bold"] = "\u001B[1m"; Colors["Italic"] = "\u001B[3m"; Colors["Dim"] = "\u001B[2m"; Colors["Normal"] = "\u001B[0m"; })(Colors = exports.Colors || (exports.Colors = {})); function stringify(json) { if (typeof json !== 'string') { json = JSON.stringify(json, undefined, 2); } return json.replace(/("(\\u[a-zA-Z0-9]{4}|\\[^u]|[^\\"])*"(\s*:)?|\b(true|false|null)\b|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?)/g, function (match) { var cls = Colors.Yellow; if (/^"/.test(match)) { if (/:$/.test(match)) { cls = Colors.Normal; } else { cls = Colors.Green; } } else if (/true|false/.test(match)) { cls = Colors.Yellow; } else if (/null/.test(match)) { cls = Colors.Dim; } return cls + match + Colors.Normal; }); } exports.stringify = stringify;