diff --git a/README.md b/README.md index 0459eea..8478dd7 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ $ npm install generate-password --save ## Usage -#### `generate(options)` +#### `generate([options])` Generate one password with the given options. Returns a string. @@ -28,7 +28,7 @@ var password = generator.generate({ console.log(password); ``` -#### `generateMultiple(amount, options)` +#### `generateMultiple(amount[, options])` Bulk generate multiple passwords at once, with the same options for all. Returns an array. diff --git a/src/generate.js b/src/generate.js index 4c8e3ef..af318c2 100644 --- a/src/generate.js +++ b/src/generate.js @@ -54,6 +54,7 @@ var generate = function(options, pool) { // Generate a random password. self.generate = function(options) { // Set defaults. + options = options || {}; if (!options.hasOwnProperty('length')) options.length = 10; if (!options.hasOwnProperty('numbers')) options.numbers = false; if (!options.hasOwnProperty('symbols')) options.symbols = false; diff --git a/test/generator.js b/test/generator.js index 331ed91..9f74a6c 100644 --- a/test/generator.js +++ b/test/generator.js @@ -6,6 +6,11 @@ var generator = process.env.JSCOV ? require('../src-cov/generate') : require('.. describe('generate-password', function() { describe('generate()', function() { + it('should accept to be called without the options parameter', function() { + assert.doesNotThrow(function () { + generator.generate(); + }); + }); it('should give password of correct length', function() { var length = 12; @@ -87,11 +92,16 @@ describe('generate-password', function() { }); describe('generateMultiple()', function() { + it('should accept to be called without the options parameter', function() { + assert.doesNotThrow(function () { + generator.generateMultiple(1); + }); + }); // should give right amount it('should give right amount of passwords', function() { var amount = 34; - var passwords = generator.generateMultiple(amount, {}); + var passwords = generator.generateMultiple(amount); assert.equal(passwords.length, amount); });