utils.js 537 B

12345678910111213141516171819202122232425
  1. 'use strict';
  2. /**
  3. * Creates a string with the same length as `numSpaces` parameter
  4. **/
  5. exports.indent = function indent(numSpaces) {
  6. return new Array(numSpaces+1).join(' ');
  7. };
  8. /**
  9. * Gets the string length of the longer index in a hash
  10. **/
  11. exports.getMaxIndexLength = function(input) {
  12. var maxWidth = 0;
  13. Object.getOwnPropertyNames(input).forEach(function(key) {
  14. // Skip undefined values.
  15. if (input[key] === undefined) {
  16. return;
  17. }
  18. maxWidth = Math.max(maxWidth, key.length);
  19. });
  20. return maxWidth;
  21. };