mirror of
https://github.com/S2-/securerandomstring.git
synced 2025-08-03 10:50:04 +02:00
Improve Readme and code stylign
* Alphabetic options added into Readme.md * Add empty space after 'if' in new option validation
This commit is contained in:
12
README.md
12
README.md
@@ -34,7 +34,19 @@ srs({length: 256}, function(err, sr) {
|
|||||||
console.log(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
|
## Error handling
|
||||||
|
|
||||||
|
|
||||||
|
@@ -26,9 +26,10 @@ function srs(options, cb) {
|
|||||||
|
|
||||||
function _finish (buf) {
|
function _finish (buf) {
|
||||||
var string = buf.toString('base64');
|
var string = buf.toString('base64');
|
||||||
if (alphanumeric === true){
|
if (alphanumeric === true) {
|
||||||
string = string.replace(/[\W_]+/g,'');
|
string = string.replace(/[\W_]+/g,'');
|
||||||
}else{
|
}
|
||||||
|
else {
|
||||||
string = string.replace(/\//g,'_').replace(/\+/g,'-');
|
string = string.replace(/\//g,'_').replace(/\+/g,'-');
|
||||||
}
|
}
|
||||||
return string.substr(0, length);
|
return string.substr(0, length);
|
||||||
|
Reference in New Issue
Block a user