Skip to content

Commit

Permalink
fix: unexpected behavior of length option
Browse files Browse the repository at this point in the history
  • Loading branch information
yukha-dw committed Oct 20, 2022
1 parent 5e8dabb commit 3cbae04
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/randomstring.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ exports.generate = function(options, cb) {

// Handle options
if (typeof options === 'object') {
length = options.length || 32;
length = typeof options.length === 'number' ? options.length : 32;

if (options.charset) {
charset.setType(options.charset);
Expand Down
2 changes: 2 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@ describe("randomstring.generate(options)", function() {

it("accepts length as an optional first argument", function() {
assert.equal(random(10).length, 10);
assert.equal(random(0).length, 0);
});

it("accepts length as an option param", function() {
assert.equal(random({ length: 7 }).length, 7);
assert.equal(random({ length: 0 }).length, 0);
});

it("accepts length as an option param async", function(done) {
Expand Down

0 comments on commit 3cbae04

Please sign in to comment.