UNPKG

@newdash/newdash

Version:

javascript/typescript utility library

43 lines (42 loc) 1.2 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.repeat = void 0; const toInteger_1 = __importDefault(require("./toInteger")); const isIterateeCall_1 = __importDefault(require("./.internal/isIterateeCall")); const toString_1 = __importDefault(require("./toString")); const baseRepeat_1 = __importDefault(require("./.internal/baseRepeat")); /** * Repeats the given string `n` times. * * @since 5.7.0 * @category String * @param str The string to repeat. * @param n The number of times to repeat the string. * @returns Returns the repeated string. * @example * * ```js * repeat('*', 3) * // => '***' * * repeat('abc', 2) * // => 'abcabc' * * repeat('abc', 0) * // => '' * ``` */ function repeat(str, n = 1, guard) { if ((guard ? (0, isIterateeCall_1.default)(str, n, guard) : n === undefined)) { n = 1; } else { n = (0, toInteger_1.default)(n); } return (0, baseRepeat_1.default)((0, toString_1.default)(str), n); } exports.repeat = repeat; exports.default = repeat;