diff options
Diffstat (limited to 'node_modules/es5-ext/string/#/repeat')
-rw-r--r-- | node_modules/es5-ext/string/#/repeat/implement.js | 9 | ||||
-rw-r--r-- | node_modules/es5-ext/string/#/repeat/index.js | 5 | ||||
-rw-r--r-- | node_modules/es5-ext/string/#/repeat/is-implemented.js | 8 | ||||
-rw-r--r-- | node_modules/es5-ext/string/#/repeat/shim.js | 22 |
4 files changed, 44 insertions, 0 deletions
diff --git a/node_modules/es5-ext/string/#/repeat/implement.js b/node_modules/es5-ext/string/#/repeat/implement.js new file mode 100644 index 000000000..7066b7b49 --- /dev/null +++ b/node_modules/es5-ext/string/#/repeat/implement.js @@ -0,0 +1,9 @@ +"use strict"; + +if (!require("./is-implemented")()) { + Object.defineProperty(String.prototype, "repeat", + { value: require("./shim"), +configurable: true, +enumerable: false, + writable: true }); +} diff --git a/node_modules/es5-ext/string/#/repeat/index.js b/node_modules/es5-ext/string/#/repeat/index.js new file mode 100644 index 000000000..99d44b2ef --- /dev/null +++ b/node_modules/es5-ext/string/#/repeat/index.js @@ -0,0 +1,5 @@ +"use strict"; + +module.exports = require("./is-implemented")() + ? String.prototype.repeat + : require("./shim"); diff --git a/node_modules/es5-ext/string/#/repeat/is-implemented.js b/node_modules/es5-ext/string/#/repeat/is-implemented.js new file mode 100644 index 000000000..e8e02409c --- /dev/null +++ b/node_modules/es5-ext/string/#/repeat/is-implemented.js @@ -0,0 +1,8 @@ +"use strict"; + +var str = "foo"; + +module.exports = function () { + if (typeof str.repeat !== "function") return false; + return str.repeat(2) === "foofoo"; +}; diff --git a/node_modules/es5-ext/string/#/repeat/shim.js b/node_modules/es5-ext/string/#/repeat/shim.js new file mode 100644 index 000000000..7b8d8fbed --- /dev/null +++ b/node_modules/es5-ext/string/#/repeat/shim.js @@ -0,0 +1,22 @@ +/* eslint no-bitwise: "off" */ + +// Thanks: http://www.2ality.com/2014/01/efficient-string-repeat.html + +"use strict"; + +var value = require("../../../object/valid-value") + , toInteger = require("../../../number/to-integer"); + +module.exports = function (count) { + var str = String(value(this)), result; + count = toInteger(count); + if (count < 0) throw new RangeError("Count must be >= 0"); + if (!isFinite(count)) throw new RangeError("Count must be < ∞"); + if (!count) return ""; + if (count === 1) return str; + + result = ""; + if (count & 1) result += str; + while ((count >>>= 1)) str += str; + return result + str; +}; |