UNPKG

yini-parser

Version:

Node.js parser for YINI — a clean, structured INI alternative with types, simple section nesting, comments, and strict mode.

47 lines (46 loc) 1.84 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.printObject = exports.printJSON = exports.toPrettyJSON = exports.devPrint = exports.debugPrint = void 0; /** * This file contains general system helper functions (utils). * @note More specific YINI helper functions should go into yiniHelpers.ts-file. */ const util_1 = __importDefault(require("util")); const env_1 = require("../config/env"); const debugPrint = (str = '') => { (0, env_1.isDebug)() && console.debug('DEBUG: ' + str); }; exports.debugPrint = debugPrint; const devPrint = (str = '') => { (0, env_1.isDev)() && !(0, env_1.isTestEnv)() && console.log('DEV: ' + str); }; exports.devPrint = devPrint; const toPrettyJSON = (obj) => { const str = JSON.stringify(obj, null, 4); return str; }; exports.toPrettyJSON = toPrettyJSON; /** Pretty-prints a JavaScript object as formatted JSON to the console. * Strict JSON, all keys are enclosed in ", etc. */ const printJSON = (obj) => { if ((0, env_1.isProdEnv)() || ((0, env_1.isTestEnv)() && !(0, env_1.isDebug)())) return; const str = (0, exports.toPrettyJSON)(obj); console.log(str); }; exports.printJSON = printJSON; /** * Print a full JavaScript object in a human-readable way (not as JSON). * Not strict JSON, and shows functions, symbols, getters/setters, and class names. * @param isColors If true, the output is styled with ANSI color codes. */ const printObject = (obj, isColors = true) => { if ((0, env_1.isProdEnv)() || ((0, env_1.isTestEnv)() && !(0, env_1.isDebug)())) return; console.log(util_1.default.inspect(obj, { depth: null, colors: isColors })); }; exports.printObject = printObject;