mirror of
https://github.com/S2-/securerandomstring.git
synced 2025-08-02 18:30:04 +02:00
change api. i don't know what i was thinking.
This commit is contained in:
@@ -1,7 +1,12 @@
|
|||||||
var crypto = require('crypto');
|
var crypto = require('crypto');
|
||||||
|
|
||||||
function securerandomstring(cb, options) {
|
function securerandomstring(options, cb) {
|
||||||
options = options || {};
|
if (typeof(options) === 'function') {
|
||||||
|
cb = options;
|
||||||
|
options = {};
|
||||||
|
} else {
|
||||||
|
options = options || {};
|
||||||
|
}
|
||||||
var length = options['length'] || 32;
|
var length = options['length'] || 32;
|
||||||
|
|
||||||
crypto.randomBytes(length, function(ex, buf) {
|
crypto.randomBytes(length, function(ex, buf) {
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "securerandomstring",
|
"name": "securerandomstring",
|
||||||
"version": "0.0.1",
|
"version": "0.0.2",
|
||||||
"description": "Generates a secure random string with a given length",
|
"description": "Generates a secure random string with a given length",
|
||||||
"main": "lib/securerandomstring.js",
|
"main": "lib/securerandomstring.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
8
tests.js
8
tests.js
@@ -36,18 +36,18 @@ securerandomstring(function(sr) {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
securerandomstring(function(sr) {
|
securerandomstring({length: 1}, function(sr) {
|
||||||
test('generate a random string 1 char long',
|
test('generate a random string 1 char long',
|
||||||
sr.length,
|
sr.length,
|
||||||
1
|
1
|
||||||
);
|
);
|
||||||
}, {length: 1});
|
});
|
||||||
|
|
||||||
securerandomstring(function(sr) {
|
securerandomstring({length: 256}, function(sr) {
|
||||||
test('generate a random string 256 chars long',
|
test('generate a random string 256 chars long',
|
||||||
sr.length,
|
sr.length,
|
||||||
256
|
256
|
||||||
);
|
);
|
||||||
}, {length: 256});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user