From d6c20353360ef1eefb56128eeb50ece4f5845372 Mon Sep 17 00:00:00 2001 From: Jakub Mandula Date: Mon, 13 Jun 2016 22:21:47 +0200 Subject: add String.prototype.repeat in older versions of node - see PR #382 --- lib/helpers.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'lib') diff --git a/lib/helpers.js b/lib/helpers.js index 832732f5..c7957e08 100644 --- a/lib/helpers.js +++ b/lib/helpers.js @@ -1,3 +1,18 @@ +/** Define the String.prototype.repeat if it is not implemented.... See PR #382 +*/ +if(typeof String.prototype.repeat === "undefined") { + String.prototype.repeat = function(num) { + if(typeof num ==="undefined") { + num = 0; + } + var text = ""; + for(var i = 0; i < num; i++){ + text += this.toString(); + } + return text; + }; +} + /** * * @namespace faker.helpers -- cgit v1.2.3