1
0
mirror of https://github.com/S2-/securerandomstring.git synced 2025-08-02 10:20:05 +02:00

add urlsafe parameter

This commit is contained in:
s2
2015-04-22 23:48:08 +02:00
parent e343e69895
commit 25af4ef420
3 changed files with 12 additions and 1 deletions

View File

@@ -13,6 +13,10 @@ function securerandomstring(options, cb) {
if (ex) throw ex;
var string = buf.toString('base64');
if (options.urlsafe) {
string = string.replace(/\//g,'_').replace(/\+/g,'-');
}
cb(string.substr(0, length));
});

View File

@@ -1,6 +1,6 @@
{
"name": "securerandomstring",
"version": "0.0.2",
"version": "0.0.3",
"description": "Generates a secure random string with a given length",
"main": "lib/securerandomstring.js",
"scripts": {

View File

@@ -50,4 +50,11 @@ securerandomstring({length: 256}, function(sr) {
);
});
securerandomstring({length: 256, urlsafe: true}, function(sr) {
test('generate a urlsafe random string 256 chars long',
sr.length,
256
);
});