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

Merge branch 'master' of https://github.com/mrsangrin/secure-random-string into mrsangrin-master

This commit is contained in:
s2
2017-11-26 11:43:05 +01:00
2 changed files with 11 additions and 5 deletions

View File

@@ -34,16 +34,16 @@ srs({length: 256}, function(err, sr) {
console.log(sr); console.log(sr);
}); });
``` ```
### Options: alphabetic ### Options: alphanumeric
Optionally, you can specify a 'alphabetic' option to get a alphabetical chars only. Optionally, you can specify a 'alphanumeric' option to get a alphanumerical chars only.
```javascript ```javascript
// sync // sync
var result = srs({alphabetic: true}); var result = srs({alphanumeric: true});
// async // async
srs({alphabetic: true}, function(err, sr) { srs({alphanumeric: true}, function(err, sr) {
console.log(sr); console.log(sr);
}); });
``` ```
@@ -60,6 +60,7 @@ the async API returns the error to the callback.
## Contributors ## Contributors
[Mark Stosberg](https://github.com/markstos) [Mark Stosberg](https://github.com/markstos)
[Sandro Gomez](https://github.com/mrsangrin)
## License ## License

View File

@@ -50,7 +50,12 @@ srs({length: 256}, function(err, sr) {
); );
}); });
srs({alphanumeric: true}, function(err, sr) {;
test('Must contain alphanumeric only',
sr.match(/^[a-zA-Z0-9_]*$/g)[0] === sr,
true
);
});
// sync tests // sync tests
test('generate a random string 32 chars long (sync)', srs().length, 32); test('generate a random string 32 chars long (sync)', srs().length, 32);
test('generate a random string 1 chars long (sync)', srs({length: 1}).length, 1); test('generate a random string 1 chars long (sync)', srs({length: 1}).length, 1);