Skip to content

Instantly share code, notes, and snippets.

@jeff-hager-dev
Last active August 29, 2015 14:19
Show Gist options
  • Save jeff-hager-dev/47c23fde77d82568fc5b to your computer and use it in GitHub Desktop.
Save jeff-hager-dev/47c23fde77d82568fc5b to your computer and use it in GitHub Desktop.
Some Helper functions for NodeJS
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