Skip to content

Commit

Permalink
use pad instead of repeat in cli help table
Browse files Browse the repository at this point in the history
  • Loading branch information
kbrsh committed Dec 24, 2019
1 parent 06521d6 commit 1eace08
Show file tree
Hide file tree
Showing 8 changed files with 100 additions and 46 deletions.
18 changes: 9 additions & 9 deletions packages/moon-browser/dist/moon-browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -384,13 +384,21 @@
}
}

/**
* Logs an error message to the console.
* @param {string} message
*/
function error(message) {
console.error("[Moon] ERROR: " + message);
}
/**
* Pads a string with spaces on the left to match a certain length.
*
* @param {string} string
* @param {number} length
* @returns {string} padded string
*/

function pad(string, length) {
var remaining = length - string.length;

Expand All @@ -400,6 +408,7 @@

return string;
}

/**
* Formats lines surrounding a certain index in a string.
*
Expand All @@ -408,7 +417,6 @@
* @returns {string} formatted lines
*/


function format(input, index) {
var lines = input.split("\n");
var lineNumber = 1;
Expand Down Expand Up @@ -448,14 +456,6 @@
}
}

/**
* Logs an error message to the console.
* @param {string} message
*/
function error(message) {
console.error("[Moon] ERROR: " + message);
}

/**
* Compiles a JavaScript file with Moon syntax.
*
Expand Down
2 changes: 1 addition & 1 deletion packages/moon-browser/dist/moon-browser.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

48 changes: 41 additions & 7 deletions packages/moon-cli/dist/moon-cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,28 @@
(function () {
"use strict";

/**
* Logs an error message to the console.
* @param {string} message
*/
/**
* Pads a string with spaces on the left to match a certain length.
*
* @param {string} string
* @param {number} length
* @returns {string} padded string
*/

function pad(string, length) {
var remaining = length - string.length;

for (var i = 0; i < remaining; i++) {
string = " " + string;
}

return string;
}

var fs = require("fs");

var path = require("path");
Expand Down Expand Up @@ -59,13 +81,25 @@
}

function table(object) {
var keys = Object.keys(object);
var max = Math.max.apply(null, keys.map(function (key) {
return key.length;
}));
return keys.map(function (key) {
return "\t" + key + " ".repeat(max - key.length + 3) + object[key];
}).join("\n");
var output = "";
var separator = "";
var keyLengthMax = 0;

for (var key in object) {
var keyLength = key.length;

if (keyLength > keyLengthMax) {
keyLengthMax = keyLength;
}
}

for (var _key in object) {
var value = object[_key];
output += separator + "\t" + _key + pad(value, keyLengthMax - _key.length + value.length + 3);
separator = "\n";
}

return output;
}

function replace(content, sub, subNewString) {
Expand Down
Loading

0 comments on commit 1eace08

Please sign in to comment.