All files / src/plugins repeat.js

90% Statements 9/10
40% Branches 2/5
100% Functions 1/1
88.88% Lines 8/9

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20          2x 3x 3x 3x   3x       3x 12x     3x  
import {toStr} from "../helpers/string/to_string"
import {clip} from "../helpers/number/clip"
import {toInt} from "../helpers/number/to_integer"
import { MAX_SAFE_INTEGER } from "../helpers/number/const"
 
export const repeat = (s, times = 0) => {
    let _s = toStr(s)
    let _times = !times ? _s.length : clip(toInt(times), 0, MAX_SAFE_INTEGER)
    const _origin = _s
 
    Iif (times === 0) {
        return "";
    }
 
    for(let i = 0; i < _times - 1; i++) {
        _s += _origin
    }
 
    return _s
}