Comparing version
@@ -50,4 +50,8 @@ var deprecate = require('deprecate') | ||
Base.prototype.or = function (fallback) { | ||
return this.isValid ? this : new this.constructor(fallback) | ||
Base.prototype.or = function (Opt, fallback) { | ||
if (typeof Opt !== 'function') { | ||
fallback = Opt | ||
Opt = this.constructor | ||
} | ||
return this.isValid ? this : new Opt(fallback) | ||
} | ||
@@ -54,0 +58,0 @@ |
{ | ||
"name": "stdopt", | ||
"version": "9.1.0", | ||
"version": "9.2.0", | ||
"description": "Wrap and validate optional values", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -1,2 +0,2 @@ | ||
var { nothing } = require('../') | ||
var { opt, nothing } = require('../') | ||
var test = require('tape') | ||
@@ -7,4 +7,6 @@ | ||
t.equal(nothing().value(), null) | ||
t.equal(opt().or(nothing).value(), null) | ||
t.equal(nothing(0).or(opt, 1).value(), 1) | ||
t.throws(() => nothing(0).value(), /Value 0 cannot be parsed as nothing/) | ||
t.end() | ||
}) |
26799
0.63%409
1.49%