index.js 401 B

123456789101112131415161718192021222324
  1. 'use strict';
  2. var isFinite = require('is-finite');
  3. module.exports = function (str, n) {
  4. if (typeof str !== 'string') {
  5. throw new TypeError('Expected `input` to be a string');
  6. }
  7. if (n < 0 || !isFinite(n)) {
  8. throw new TypeError('Expected `count` to be a positive finite number');
  9. }
  10. var ret = '';
  11. do {
  12. if (n & 1) {
  13. ret += str;
  14. }
  15. str += str;
  16. } while ((n >>= 1));
  17. return ret;
  18. };