import { NotImplementedError } from '../extensions/index.js';

/**
 * Create a repeating string based on the given parameters
 *  
 * @param {String} str string to repeat
 * @param {Object} options options object 
 * @return {String} repeating string
 * 
 *
 * @example
 * 
 * repeater('STRING', { repeatTimes: 3, separator: '**', 
 * addition: 'PLUS', additionRepeatTimes: 3, additionSeparator: '00' })
 * => 'STRINGPLUS00PLUS00PLUS**STRINGPLUS00PLUS00PLUS**STRINGPLUS00PLUS00PLUS'
 *
 */
export default function repeater(str, options) {
  let res = str;
  let res1 = str;
  if(options.hasOwnProperty('addition')){
    let add = options.addition;
    for(let k = 0; k < (options.additionRepeatTimes ? options.additionRepeatTimes - 1 : 0); k++)
      add += (options.additionSeparator ? options.additionSeparator : '|') + options.addition;
    
    res1 += add;
    res += add;
  }
  for(let i = 0; i < (options.repeatTimes ? options.repeatTimes - 1 : 0); i++)
    res += (options.separator ? options.separator : '+') + res1;
  return res;
}
