UNPKG

roc

Version:

Build modern web applications easily

79 lines (66 loc) 2.31 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); exports.pad = pad; exports.addPadding = addPadding; exports.toCliOption = toCliOption; exports.getDefaultValue = getDefaultValue; var _stripAnsi = require('strip-ansi'); var _stripAnsi2 = _interopRequireDefault(_stripAnsi); var _lodash = require('lodash'); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } /** * Returns a string to pad with. * * @param {number} length - The desired length of the generated string. * @param {string} [character=" "] - The character to repat. * * @returns {string} - A string matching the input. */ function pad(length) { let character = arguments.length <= 1 || arguments[1] === undefined ? ' ' : arguments[1]; return Array(length + 1).join(character); } /** * Pads a string to a given length with spaces. * * @param {string} string - The string to be padded. * @param {number} length - The desired length of the new string. * * @returns {string} - A string matching the input. */ function addPadding(string, length) { string = string || ''; return string + pad(length - (0, _stripAnsi2.default)(string).length); } /** * Takes a configuration path array and convertes it to a cli option. * * @param {string[]} configPaths - The configuration path, a array consiting of properties. * * @returns {string} - The cli option to set the given configuration option. */ function toCliOption(configPaths) { // Runtime should be added directly const paths = configPaths[0] === 'runtime' ? configPaths.slice(1) : configPaths; return '--' + paths.join('-'); } /** * Converts an object to a string. * * @param {Object} object - The object to convert to a string. * * @returns {string|null} - The converted object or null if the object is empty. */ function getDefaultValue(object) { if (Array.isArray(object) && !object.length || (0, _lodash.isString)(object) && !object || (0, _lodash.isPlainObject)(object) && Object.keys(object).length === 0) { return null; } // Make sure we get something sensible when having a RegExp if ((0, _lodash.isRegExp)(object)) { return object.toString(); } return JSON.stringify(object); } //# sourceMappingURL=helpers.js.map