roc
Version:
Build modern web applications easily
79 lines (63 loc) • 2.15 kB
JavaScript
;
exports.__esModule = true;
exports.pad = pad;
exports.addPadding = addPadding;
exports.toCliFlag = toCliFlag;
exports.getDefaultValue = getDefaultValue;
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
require('source-map-support/register');
var _stripAnsi = require('strip-ansi');
var _stripAnsi2 = _interopRequireDefault(_stripAnsi);
var _lodash = require('lodash');
/**
* 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) {
var 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 - _stripAnsi2['default'](string).length);
}
/**
* Takes a configuration path array and convertes it to a cli flag.
*
* @param {string[]} configPaths - The configuration path, a array consiting of properties.
*
* @returns {string} - The cli flag to set the given configuration option.
*/
function toCliFlag(configPaths) {
// Runtime should be added directly
if (configPaths[0] === 'runtime') {
configPaths.shift();
}
return '--' + configPaths.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 || _lodash.isString(object) && !object || _lodash.isPlainObject(object) && Object.keys(object).length === 0) {
return null;
}
return JSON.stringify(object);
}
//# sourceMappingURL=helpers.js.map