Last active
August 29, 2015 14:19
-
-
Save jeff-hager-dev/47c23fde77d82568fc5b to your computer and use it in GitHub Desktop.
Some Helper functions for NodeJS
This file contains hidden or 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
module.exports = { | |
removeWhitespace: function(str){ | |
return str.replace(/\s+/g, ''); | |
}, | |
randomNumber: function(max, min){ | |
return Math.floor(Math.random() * max) + min; | |
}, | |
stringRepeater: function (str, rptCnt) { | |
return new Array(rptCnt).join(str); | |
}, | |
stringFormat: function(format) { | |
var args = Array.prototype.slice.call(arguments, 1); | |
return format.replace(/{(\d+)}/g, function(match, number) { | |
return typeof args[number] != 'undefined' | |
? args[number] | |
: match | |
; | |
}); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment