UNPKG

@tatumio/tatum

Version:

Tatum JS SDK

111 lines (105 loc) 14.9 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.TatumDevelopmentLogger = void 0; const chalk_1 = __importDefault(require("chalk")); const env_1 = require("../../util/env"); const logger_types_1 = require("./logger.types"); class TatumDevelopmentLogger { static isWelcomeDisabled() { const anyGlobal = globalThis; return !!anyGlobal[TatumDevelopmentLogger.DISABLE_WELCOME]; } static disableWelcome() { const anyGlobal = globalThis; anyGlobal[TatumDevelopmentLogger.DISABLE_WELCOME] = true; } constructor(options = {}) { this.logger = console; this._trace = chalk_1.default.gray; this._debug = chalk_1.default.gray; this._info = chalk_1.default.white; this._warn = chalk_1.default.bold.yellow; this._error = chalk_1.default.bold.red; this._DEBUG = chalk_1.default.bgGray.white(' DEBUG '); this._INFO = chalk_1.default.bgCyan.gray(' INFO '); this._WARN = chalk_1.default.bgYellowBright.black(' WARN '); this._ERROR = chalk_1.default.bgRedBright.bold.yellow(' ERROR '); const defaultOptions = { welcome: env_1.EnvUtils.isDevelopment() && !TatumDevelopmentLogger.isWelcomeDisabled(), level: logger_types_1.LogLevel.INFO, }; this.options = { ...defaultOptions, ...options }; if (this.options.welcome) { this.welcome(); TatumDevelopmentLogger.disableWelcome(); } } welcome() { this.logger.log([LOGO, WELCOME_MESSAGES[Math.floor(Math.random() * WELCOME_MESSAGES.length)]].join('\n')); } trace(...args) { if (this.options.level > logger_types_1.LogLevel.TRACE) return; this.logger.trace(this._trace(...args)); } debug(...args) { if (this.options.level > logger_types_1.LogLevel.DEBUG) return; this.logger.debug(this._DEBUG, this._debug(...args)); } info(...args) { if (this.options.level > logger_types_1.LogLevel.INFO) return; this.logger.info(this._INFO, this._info(...args)); } warn(...args) { if (this.options.level > logger_types_1.LogLevel.WARN) return; this.logger.warn(this._WARN, this._warn(...args)); } error(...args) { if (this.options.level > logger_types_1.LogLevel.ERROR) return; this.logger.error(this._ERROR, this._error(...args)); } } exports.TatumDevelopmentLogger = TatumDevelopmentLogger; TatumDevelopmentLogger.DISABLE_WELCOME = '__TTM_DISABLE_WELCOME__'; const LOGO = `--------------------------------------------------------------------------------             ttLLLLLLLLff                                                     ffffffffff11ttLLLLLLLLff                                                     LLLLLLLLLL1111fffffffftt  ,,,,,,  ,,,,,,,,,,,,  ,,,,    ,,,,  ,,,,      ,,,, fffffffffftt1111ii        ::ii::  ::iiiiiiii;;  ii::    ::;;  ;;ii,,    ::ii           ffLLLL11        ;;;;ii      ::ii      ii::    ::;;  ;;ii::  ,,iiii           ffLLLL11      ,,ii,,ii::    ::ii      ii::    ::;;  ;;;;ii,,::;;ii           ffLLLL11      ;;ii::ii;;    ::ii      ii::    ::;;  ;;;;;;;;ii::ii           ffLLLL11    ,,ii;;;;;;ii,,  ::ii      ii::    ::;;  ;;;;,,ii;;,,ii           ffLLLL11    ::;;      ;;::  ::ii      ::iiiiiiii::  ;;;;  ;;;  ,ii --------------------------------------------------------------------------------`; const WELCOME = 'Hi! 👋 Welcome to Tatum, the Javascript SDK for Web3.'; const WELCOME_MESSAGES = [ ` ${WELCOME} Visit our docs to see how Tatum will help you launch projects fast: ${chalk_1.default.blueBright('https://co.tatum.io/docs')} `, ` ${WELCOME} Kick start by making your first RPC call: ${chalk_1.default.blueBright('https://co.tatum.io/start')} `, ` ${WELCOME} Possibilities are endless - see what apps you can build with Tatum: ${chalk_1.default.blueBright('https://co.tatum.io/apps')} `, ` ${WELCOME} ${chalk_1.default.bold('FREE Testnet Tokens')}: Explore Tatum's Faucets available for over 5 chains: ${chalk_1.default.blueBright('https://co.tatum.io/faucets')} `, ]; //# sourceMappingURL=logger.development.js.map