'use strict';

var from          = require('es5-ext/array/from')
  , iterable      = require('es5-ext/iterable/validate-object')
  , stringifiable = require('es5-ext/object/validate-stringifiable')
  , repeat        = require('es5-ext/string/#/repeat')
  , strip         = require('./strip');

module.exports = function (rows/*, options*/) {
	var options = Object(arguments[1]), cols = [];
	return from(iterable(rows), function (row, index) {
		return from(iterable(row), function (str, index) {
			var col = cols[index], strLength;
			if (!col) col = cols[index] = { width: 0 };
			str = stringifiable(str);
			strLength = strip(str).length;
			if (strLength > col.width) col.width = strLength;
			return { str: str, length: strLength };
		});
	}).map(function (row) {
		return row.map(function (item, index) {
			var pad = repeat.call(' ', cols[index].width - item.length);
			return item.str + pad;
		}).join((options.sep == null) ? ' | ' : options.sep);
	}).join('\n') + '\n';
};

@@ -378,16 +378,54 @@
 , cols =
+ %5B%5D%0A%09  , colsOptions = options.cols %7C%7C
  %5B%5D;%0A%09re
@@ -857,86 +857,289 @@
  pad
- = repeat.call(' ', cols%5Bindex%5D.width - item.length);%0A%09%09%09return item.str + pad
+, align = 'left', colOptions = colsOptions && colsOptions%5Bindex%5D;%0A%09%09%09align = (colOptions && (colOptions.align === 'right')) ? 'right' : 'left';%0A%09%09%09pad = repeat.call(' ', cols%5Bindex%5D.width - item.length);%0A%09%09%09if (align === 'left') return item.str + pad;%0A%09%09%09else return pad + item.str
 ;%0A%09%09

Allow to customize allign per column