Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[breaking] Implement the es-shim-api interface
- Loading branch information
1 parent
b2ee9b1
commit 1b4f196
Showing
7 changed files
with
90 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
/*! https://mths.be/repeat v1.0.0 by @mathias */ | ||
|
||
require('./shim')(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/*! https://mths.be/repeat v1.0.0 by @mathias */ | ||
|
||
'use strict'; | ||
|
||
var RequireObjectCoercible = require('es-abstract/2019/RequireObjectCoercible'); | ||
var ToString = require('es-abstract/2019/ToString'); | ||
var ToInteger = require('es-abstract/2019/ToInteger'); | ||
|
||
module.exports = function repeat(count) { | ||
var O = RequireObjectCoercible(this); | ||
var S = ToString(O); | ||
var n = ToInteger(count); | ||
// Account for out-of-bounds indices | ||
if (n < 0 || n == Infinity) throw RangeError(); | ||
|
||
var result = ''; | ||
while (n) { | ||
if (n % 2 == 1) { | ||
result += string; | ||
} | ||
if (n > 1) { | ||
string += string; | ||
} | ||
n >>= 1; | ||
} | ||
return result; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/*! https://mths.be/repeat v1.0.0 by @mathias */ | ||
|
||
'use strict'; | ||
|
||
var callBind = require('es-abstract/helpers/callBind'); | ||
var define = require('define-properties'); | ||
|
||
var implementation = require('./implementation'); | ||
var getPolyfill = require('./polyfill'); | ||
var shim = require('./shim'); | ||
|
||
var boundRepeat = callBind(getPolyfill()); | ||
|
||
define(boundRepeat, { | ||
getPolyfill: getPolyfill, | ||
implementation: implementation, | ||
shim: shim | ||
}); | ||
|
||
module.exports = boundRepeat; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/*! https://mths.be/repeat v1.0.0 by @mathias */ | ||
|
||
'use strict'; | ||
|
||
var implementation = require('./implementation'); | ||
|
||
module.exports = function getPolyfill() { | ||
return String.prototype.repeat || implementation; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/*! https://mths.be/repeat v1.0.0 by @mathias */ | ||
|
||
'use strict'; | ||
|
||
var define = require('define-properties'); | ||
|
||
var getPolyfill = require('./polyfill'); | ||
|
||
module.exports = function shimRepeat() { | ||
var polyfill = getPolyfill(); | ||
|
||
if (String.prototype.repeat !== polyfill) { | ||
define(String.prototype, { repeat: polyfill }); | ||
} | ||
|
||
return polyfill; | ||
}; |