string.prototype.repeat
Advanced tools
Comparing version 0.1.0 to 0.2.0
{ | ||
"name": "string.prototype.repeat", | ||
"version": "0.1.0", | ||
"version": "0.2.0", | ||
"description": "A robust & optimized `String.prototype.repeat` polyfill, based on the ECMAScript 6 specification.", | ||
@@ -5,0 +5,0 @@ "homepage": "http://mths.be/repeat", |
@@ -1,2 +0,2 @@ | ||
# ES6 `String.prototype.repeat` polyfill [![Build status](https://travis-ci.org/mathiasbynens/String.prototype.repeat.png?branch=master)](https://travis-ci.org/mathiasbynens/String.prototype.repeat) | ||
# ES6 `String.prototype.repeat` polyfill [![Build status](https://travis-ci.org/mathiasbynens/String.prototype.repeat.svg?branch=master)](https://travis-ci.org/mathiasbynens/String.prototype.repeat) | ||
@@ -35,3 +35,3 @@ A robust & optimized ES3-compatible polyfill for [the `String.prototype.repeat` method in ECMAScript 6](http://people.mozilla.org/~jorendorff/es6-draft.html#sec-string.prototype.repeat). | ||
| [![twitter/mathias](http://gravatar.com/avatar/24e08a9ea84deb17ae121074d0f17125?s=70)](http://twitter.com/mathias "Follow @mathias on Twitter") | | ||
| [![twitter/mathias](https://gravatar.com/avatar/24e08a9ea84deb17ae121074d0f17125?s=70)](https://twitter.com/mathias "Follow @mathias on Twitter") | | ||
|---| | ||
@@ -38,0 +38,0 @@ | [Mathias Bynens](http://mathiasbynens.be/) | |
@@ -1,5 +0,14 @@ | ||
/*! http://mths.be/repeat v0.1.0 by @mathias */ | ||
/*! http://mths.be/repeat v0.2.0 by @mathias */ | ||
if (!String.prototype.repeat) { | ||
(function() { | ||
'use strict'; // needed to support `apply`/`call` with `undefined`/`null` | ||
var defineProperty = (function() { | ||
// IE 8 only supports `Object.defineProperty` on DOM elements | ||
try { | ||
var object = {}; | ||
var $defineProperty = Object.defineProperty; | ||
var result = $defineProperty(object, object, object) && $defineProperty; | ||
} catch(error) {} | ||
return result; | ||
}()); | ||
var repeat = function(count) { | ||
@@ -19,13 +28,16 @@ if (this == null) { | ||
} | ||
if (n == 0) { | ||
return ''; | ||
} | ||
var result = ''; | ||
while (n--) { | ||
result += string; | ||
while (n) { | ||
if (n % 2 == 1) { | ||
result += string; | ||
} | ||
if (n > 1) { | ||
string += string; | ||
} | ||
n >>= 1; | ||
} | ||
return result; | ||
}; | ||
if (Object.defineProperty) { | ||
Object.defineProperty(String.prototype, 'repeat', { | ||
if (defineProperty) { | ||
defineProperty(String.prototype, 'repeat', { | ||
'value': repeat, | ||
@@ -32,0 +44,0 @@ 'configurable': true, |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
4551
50