All files repeat.js

100% Statements 5/5
100% Branches 2/2
100% Functions 2/2
100% Lines 5/5
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37                                                        1x 15x 5x   10x     5x  
/**
 * @module repeat
 * @description
 * Returns a repeated string given a multiplier.
 * ## Install
 * Install all functions of strman
 * ```sh
 * yarn add strman
 * ```
 * or just the repeat function
 * ```sh
 * yarn add strman.repeat
 * ```
 * ## Usage
 * ```javascript
 * import { repeat } from 'strman'
 * // OR
 * import repeat from 'strman.repeat'
 * ```
 * @param {String} value - The String!.
 * @param {Number} multiplier - Number of repeats.
 * @example
 * const title = 'strman'
 * repeat(title, 5)
 * // => 'strmanstrmanstrmanstrmanstrman'
 * @returns {String} - The String repeated!
 */
 
const repeat = (initialValue, multiplier, current) => {
  if (multiplier < 2) {
    return current
  }
  return repeat(initialValue, multiplier - 1, `${current}${initialValue}`)
}
 
export default (value, multiplier) => repeat(value, multiplier, value)