mirror of
https://github.com/S2-/securerandomstring.git
synced 2025-08-02 02:10:05 +02:00
Refactor: encapsulate code that will be shared with the sync version.
This commit is contained in:
@@ -12,15 +12,19 @@ function srs(options, cb) {
|
||||
crypto.randomBytes(length, function(ex, buf) {
|
||||
if (ex) throw ex;
|
||||
|
||||
cb(_finish(buf));
|
||||
});
|
||||
|
||||
function _finish (buf) {
|
||||
var string = buf.toString('base64');
|
||||
if (options.urlsafe) {
|
||||
string = string.replace(/\//g,'_').replace(/\+/g,'-');
|
||||
}
|
||||
|
||||
cb(string.substr(0, length));
|
||||
});
|
||||
return string.substr(0, length);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
module.exports = srs;
|
||||
|
Reference in New Issue
Block a user