PHP 8.2.30
Preview: repeat.js Size: 1.07 KB
//opt/alt/alt-nodejs9/root/lib/node_modules/npm/node_modules/cli-table2/node_modules/lodash/string/repeat.js

var baseToString = require('../internal/baseToString');

/* Native method references for those with the same name as other `lodash` methods. */
var nativeFloor = Math.floor,
    nativeIsFinite = global.isFinite;

/**
 * Repeats the given string `n` times.
 *
 * @static
 * @memberOf _
 * @category String
 * @param {string} [string=''] The string to repeat.
 * @param {number} [n=0] The number of times to repeat the string.
 * @returns {string} Returns the repeated string.
 * @example
 *
 * _.repeat('*', 3);
 * // => '***'
 *
 * _.repeat('abc', 2);
 * // => 'abcabc'
 *
 * _.repeat('abc', 0);
 * // => ''
 */
function repeat(string, n) {
  var result = '';
  string = baseToString(string);
  n = +n;
  if (n < 1 || !string || !nativeIsFinite(n)) {
    return result;
  }
  // Leverage the exponentiation by squaring algorithm for a faster repeat.
  // See https://en.wikipedia.org/wiki/Exponentiation_by_squaring for more details.
  do {
    if (n % 2) {
      result += string;
    }
    n = nativeFloor(n / 2);
    string += string;
  } while (n);

  return result;
}

module.exports = repeat;

Directory Contents

Dirs: 0 × Files: 23

Name Size Perms Modified Actions
680 B lrw-r--r-- 2021-09-28 11:28:35
Edit Download
494 B lrw-r--r-- 2021-09-28 11:28:35
Edit Download
1.06 KB lrw-r--r-- 2021-09-28 11:28:35
Edit Download
1.05 KB lrw-r--r-- 2021-09-28 11:28:35
Edit Download
1.84 KB lrw-r--r-- 2021-09-28 11:28:35
Edit Download
1.11 KB lrw-r--r-- 2021-09-28 11:28:35
Edit Download
649 B lrw-r--r-- 2021-09-28 11:28:35
Edit Download
1.28 KB lrw-r--r-- 2021-09-28 11:28:35
Edit Download
654 B lrw-r--r-- 2021-09-28 11:28:35
Edit Download
664 B lrw-r--r-- 2021-09-28 11:28:35
Edit Download
1.50 KB lrw-r--r-- 2021-09-28 11:28:35
Edit Download
1.07 KB lrw-r--r-- 2021-09-28 11:28:35
Edit Download
626 B lrw-r--r-- 2021-09-28 11:28:35
Edit Download
690 B lrw-r--r-- 2021-09-28 11:28:35
Edit Download
974 B lrw-r--r-- 2021-09-28 11:28:35
Edit Download
8.89 KB lrw-r--r-- 2021-09-28 11:28:35
Edit Download
1.36 KB lrw-r--r-- 2021-09-28 11:28:35
Edit Download
1.32 KB lrw-r--r-- 2021-09-28 11:28:35
Edit Download
1.05 KB lrw-r--r-- 2021-09-28 11:28:35
Edit Download
1.08 KB lrw-r--r-- 2021-09-28 11:28:35
Edit Download
3.18 KB lrw-r--r-- 2021-09-28 11:28:35
Edit Download
1.06 KB lrw-r--r-- 2021-09-28 11:28:35
Edit Download
1.16 KB lrw-r--r-- 2021-09-28 11:28:35
Edit Download

If ZipArchive is unavailable, a .tar will be created (no compression).