import repeat from './repeat.js';

export default function(str, length, padchar, align) {
  const c = padchar || ' ',
        s = str + '',
        n = length - s.length;

  return n <= 0 ? s
    : align === 'left' ? repeat(c, n) + s
    : align === 'center' ? repeat(c, ~~(n/2)) + s + repeat(c, Math.ceil(n/2))
    : s + repeat(c, n);
}
