UNPKG

roc

Version:

Build modern web applications easily

139 lines (122 loc) 3.84 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); exports.error = error; exports.warning = warning; exports.ok = ok; exports.info = info; exports.errorLabel = errorLabel; exports.warningLabel = warningLabel; exports.okLabel = okLabel; exports.infoLabel = infoLabel; exports.feedbackMessage = feedbackMessage; var _chalk = require('chalk'); var _chalk2 = _interopRequireDefault(_chalk); var _redent = require('redent'); var _redent2 = _interopRequireDefault(_redent); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } /** * Formats a string suitable for error output. * * @param {string} text - The text to format for errors. * * @returns {string} - The formatted text. */ function error(text) { return _chalk2.default.red(text); } /** * Formats a string suitable for warnings. * * @param {string} text - The text to format for warnings. * * @returns {string} - The formatted text. */ function warning(text) { return _chalk2.default.yellow(text); } /** * Formats a string suitable for confirmations. * * @param {string} text - The text to format for confirmations. * * @returns {string} - The formatted text. */ function ok(text) { return _chalk2.default.green(text); } /** * Formats a string suitable for info messages. * * @param {string} text - The text to format for info messages. * * @returns {string} - The formatted text. */ function info(text) { return _chalk2.default.cyan(text); } /** * Formats a string suitable for error labels. * * @param {string} label - The label to format for error labels. * @param {string} text - The text to format for error labels. * * @returns {string} - The formatted text. */ function errorLabel(label, text) { const infoText = text ? ` ${ error(text) }` : ''; return _chalk2.default.bgRed(_chalk2.default.white(` ${ label } `)) + infoText; } /** * Formats a string suitable for warning labels. * * @param {string} label - The label to format for warning labels. * @param {string} text - The text to format for warning labels. * * @returns {string} - The formatted text. */ function warningLabel(label, text) { const infoText = text ? ` ${ warning(text) }` : ''; return _chalk2.default.bgYellow(_chalk2.default.black(` ${ label } `)) + infoText; } /** * Formats a string suitable for confirmation labels. * * @param {string} label - The label to format for confirmation labels. * @param {string} text - The text to format for confirmation labels. * * @returns {string} - The formatted text. */ function okLabel(label, text) { const infoText = text ? ` ${ ok(text) }` : ''; return _chalk2.default.bgGreen(_chalk2.default.white(` ${ label } `)) + infoText; } /** * Formats a string suitable for info labels. * * @param {string} label - The label to format for info labels. * @param {string} text - The text to format for info labels. * * @returns {string} - The formatted text. */ function infoLabel(label, text) { const infoText = text ? ` ${ info(text) }` : ''; return _chalk2.default.bgCyan(_chalk2.default.black(` ${ label } `)) + infoText; } /** * Build a feedback message to be printed to the console. * * @param {string} label - The label to use, should be the output from one of the label functions. * @param {string} message - The message related to the feedback message. * @param {string} location - Where the message occurred. * * @returns {string} - The formatted text. */ function feedbackMessage(label, message, location) { const locationMessage = location ? `\n${ _chalk2.default.gray('Occurred in ' + _chalk2.default.underline(location)) }\n` : ''; return label + (0, _redent2.default)(` ${ message } ${ locationMessage }`, 2); } //# sourceMappingURL=style.js.map