1
0
mirror of https://github.com/S2-/securerandomstring.git synced 2025-08-03 02:40:04 +02:00

rename module

This commit is contained in:
s2
2015-04-25 16:27:22 +02:00
parent 7f2802fac8
commit de3c06d844
4 changed files with 14 additions and 14 deletions

View File

@@ -0,0 +1,26 @@
var crypto = require('crypto');
function srs(options, cb) {
if (typeof(options) === 'function') {
cb = options;
options = {};
} else {
options = options || {};
}
var length = options['length'] || 32;
crypto.randomBytes(length, function(ex, buf) {
if (ex) throw ex;
var string = buf.toString('base64');
if (options.urlsafe) {
string = string.replace(/\//g,'_').replace(/\+/g,'-');
}
cb(string.substr(0, length));
});
};
module.exports = srs;