UNPKG

roc

Version:

Build modern web applications easily

39 lines (30 loc) 1.17 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = toBoolean; var _chalk = require('chalk'); var _chalk2 = _interopRequireDefault(_chalk); var _lodash = require('lodash'); var _style = require('../helpers/style'); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } /** * Given an input the function will return a boolean. * * @param {object} input - The input to be converted. * @param {boolean} defaultValue - Default value to use if conversion fails. * @param {string} name - The name of of what is converted. * * @returns {bool} - The converted result. */ function toBoolean(input, defaultValue, name) { if ((0, _lodash.isBoolean)(input)) { return input; } if (input === 'true' || input === 'false') { return input === 'true'; } console.log((0, _style.feedbackMessage)((0, _style.warningLabel)('Warning', 'Conversion Failed'), `Invalid value given for ${ _chalk2.default.bold(name) }. Will use the default ${ _chalk2.default.bold(defaultValue) }.`)); return defaultValue; } //# sourceMappingURL=to-boolean.js.map