All Downloads are FREE. Search and download functionalities are using the official Maven repository.

polyfills.StringRepeat.js Maven / Gradle / Ivy

The newest version!
if (!String.prototype.repeat) {
  String.prototype.repeat = function (count) {
	    'use strict';
	    if (this == null) {
	      throw new TypeError('can\'t convert ' + this + ' to object');
	    }
	    var str = '' + this;
	    count = +count;
	    if (count != count) {
	      count = 0;
	    }
	    if (count < 0) {
	      throw new RangeError('repeat count must be non-negative');
	    }
	    if (count == Infinity) {
	      throw new RangeError('repeat count must be less than infinity');
	    }
	    count = Math.floor(count);
	    if (str.length == 0 || count == 0) {
	      return '';
	    }
	    if (str.length * count >= 1 << 28) {
	      throw new RangeError('repeat count must not overflow maximum string size');
	    }
	    var rpt = '';
	    for (var i = 0; i < count; i++) {
	      rpt += str;
	    }
	    return rpt;
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy