UNPKG

@kwiz/common

Version:

KWIZ common utilities and helpers for M365 platform

93 lines 3.3 kB
import { configInfo, SetDependencies } from './_dependencies'; import { ConsoleLogger } from './utils/consolelogger'; /** @deprecated should only be used for 3rd party packages. main project must call config and mark it as sideEffects */ export class CommonConfig { constructor() { } static get i() { return configInfo; } } var unconfigured = true; /** @deprecated should only be used for 3rd party packages. main project must call config and mark it as sideEffects */ export class CommonLogger { constructor(name) { this.instance = null; this.name = name; } get i() { if (this.instance === null || this.instance.context.prefix !== configInfo.ProjectName) { if (unconfigured) console.warn('@kwiz/common not configured yet! Call config before this code runs.'); this.instance = ConsoleLogger.get(this.name, configInfo.ProjectName); } return this.instance; } ; debug(message) { return this.i.debug(message); } info(message) { return this.i.info(message); } log(message) { return this.i.log(message); } /** output a message when debug is off */ warn(message) { return this.i.warn(message); } /** output a message when debug is off */ error(message) { return this.i.error(message); } /** output a message when debug is off */ trace(message) { return this.i.trace(message); } /**start timer on a label, call timeEnd with the same label to print out the time that passed */ time(label) { return this.i.time(label); } /**start timer on a label, call timeEnd with the same label to print out the time that passed */ timeEnd(label) { return this.i.timeEnd(label); } /**prints an array or dictionary to the console inside a group */ table(data, groupLabel, groupCollapsed) { return this.i.table(data, groupLabel, groupCollapsed); } /**prints a JSON object to the console inside a group */ json(data, groupLabel, groupCollapsed) { return this.i.json(data, groupLabel, groupCollapsed); } /**prints an XML object to the console inside a group. If data is string that looks like an XML - will try to parse it. */ xml(data, groupLabel, groupCollapsed) { return this.i.xml(data, groupLabel, groupCollapsed); } /** render messages inside a group, and closes the group when done. if a label is not provided - a group will not be rendered */ group(renderContent, label, collapsed) { return this.i.group(renderContent, label, collapsed); } groupSync(label, renderContent, options) { return this.i.groupSync(label, renderContent); } async groupAsync(label, renderContent, options) { return this.i.groupAsync(label, renderContent); } } var unconfigured = true; ; export function config(params) { SetDependencies(params); unconfigured = false; const GetLogger = (name) => { return ConsoleLogger.get(name, configInfo.ProjectName); }; return { GetLogger: GetLogger, /** @deprecated call GetLogger instead */ logger: GetLogger, configInfo }; } //# sourceMappingURL=config.js.map