From 31839fea0b30c8af77c99cf987a16428adaf830b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sandro=20Ariel=20Go=CC=81mez=20Araya?= Date: Fri, 24 Nov 2017 10:21:32 -0300 Subject: [PATCH] Improve Readme and code stylign * Alphabetic options added into Readme.md * Add empty space after 'if' in new option validation --- README.md | 12 ++++++++++++ lib/secure-random-string.js | 5 +++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 0f2a4f8..c7ae1ed 100644 --- a/README.md +++ b/README.md @@ -34,7 +34,19 @@ srs({length: 256}, function(err, sr) { console.log(sr); }); ``` +### Options: alphabetic +Optionally, you can specify a 'alphabetic' option to get a alphabetical chars only. + +```javascript +// sync +var result = srs({alphabetic: true}); + +// async +srs({alphabetic: true}, function(err, sr) { + console.log(sr); +}); +``` ## Error handling diff --git a/lib/secure-random-string.js b/lib/secure-random-string.js index e15dbdf..073bedc 100644 --- a/lib/secure-random-string.js +++ b/lib/secure-random-string.js @@ -26,9 +26,10 @@ function srs(options, cb) { function _finish (buf) { var string = buf.toString('base64'); - if (alphanumeric === true){ + if (alphanumeric === true) { string = string.replace(/[\W_]+/g,''); - }else{ + } + else { string = string.replace(/\//g,'_').replace(/\+/g,'-'); } return string.substr(0, length);