@decentralized-identity/ion-cli
Version:
A Command Line Interface (CLI) to make working with the ION network and using ION DIDs easy peasy lemon squeezy.
21 lines (20 loc) • 697 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const ESCAPE_REGEX = /"/g;
/**
* Class for serializing objects to a JSON string and escaping.
*/
class Output {
/**
* Stringify's the @param object and then optionally escapes
* all double quotes using a backslash.
* @param object to serialize and escape.
* @param [escape] indicating whether the output should be escaped.
* @returns the JSON string optionally escaped.
*/
static toJson(object, escape) {
const json = JSON.stringify(object, null, 2);
return escape ? json.replace(ESCAPE_REGEX, '\\\"') : json;
}
}
exports.default = Output;