From e343e69895a38e417b208a81fe48343510cbc187 Mon Sep 17 00:00:00 2001 From: s2 Date: Wed, 22 Apr 2015 21:24:57 +0200 Subject: [PATCH] change api. i don't know what i was thinking. --- lib/securerandomstring.js | 9 +++++++-- package.json | 2 +- tests.js | 8 ++++---- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/lib/securerandomstring.js b/lib/securerandomstring.js index bbaa0c2..d0c8324 100644 --- a/lib/securerandomstring.js +++ b/lib/securerandomstring.js @@ -1,7 +1,12 @@ var crypto = require('crypto'); -function securerandomstring(cb, options) { - options = options || {}; +function securerandomstring(options, cb) { + if (typeof(options) === 'function') { + cb = options; + options = {}; + } else { + options = options || {}; + } var length = options['length'] || 32; crypto.randomBytes(length, function(ex, buf) { diff --git a/package.json b/package.json index 674194b..0ed5752 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "securerandomstring", - "version": "0.0.1", + "version": "0.0.2", "description": "Generates a secure random string with a given length", "main": "lib/securerandomstring.js", "scripts": { diff --git a/tests.js b/tests.js index 2ca9f81..ba371e1 100644 --- a/tests.js +++ b/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', sr.length, 1 ); -}, {length: 1}); +}); -securerandomstring(function(sr) { +securerandomstring({length: 256}, function(sr) { test('generate a random string 256 chars long', sr.length, 256 ); -}, {length: 256}); +});