Comparing version 1.6.1 to 1.6.2
27
index.js
@@ -5,14 +5,19 @@ var inherits = require('inherits') | ||
this.tfError = Error.call(this) | ||
this.tfType = type | ||
this.tfValue = value | ||
var message | ||
Object.defineProperty(this, 'message', { | ||
get: function () { | ||
if (message) return message | ||
message = tfErrorString(type, value) | ||
if (arguments.length === 1 && typeof type === 'string') { | ||
this.message = type | ||
} else { | ||
this.tfType = type | ||
this.tfValue = value | ||
return message | ||
} | ||
}) | ||
var message | ||
Object.defineProperty(this, 'message', { | ||
get: function () { | ||
if (message) return message | ||
message = tfErrorString(type, value) | ||
return message | ||
} | ||
}) | ||
} | ||
} | ||
@@ -226,3 +231,3 @@ | ||
quacksLike: function quacksLike (type) { | ||
function quacksLike (value, strict) { | ||
function quacksLike (value) { | ||
return type === getValueTypeName(value) | ||
@@ -229,0 +234,0 @@ } |
{ | ||
"name": "typeforce", | ||
"version": "1.6.1", | ||
"version": "1.6.2", | ||
"description": "Another biased type checking solution for Javascript", | ||
@@ -5,0 +5,0 @@ "author": "Daniel Cousens", |
@@ -69,6 +69,6 @@ # typeforce | ||
var fastType = typeforce.compile(type) | ||
// fastType => { | ||
// fastType => typeforce.object({ | ||
// foo: typeforce.Number, | ||
// bar: typeforce.maybe(typeforce.String) | ||
// } | ||
// }) | ||
@@ -75,0 +75,0 @@ // use strictness for recursive types to enforce whitelisting properties |
@@ -45,2 +45,29 @@ /* global describe, it */ | ||
}) | ||
describe('custom errors', function () { | ||
var err = new typeforce.TfTypeError('custom error') | ||
var everFailingType = function () { throw new typeforce.TfTypeError('custom error') } | ||
it('has the custom message', function () { | ||
assert(err.message === 'custom error') | ||
}) | ||
it('is instance of TfTypeError', function () { | ||
assert(err instanceof typeforce.TfTypeError) | ||
}) | ||
it('assert.throws knows how to handle it', function () { | ||
assert.throws(function () { | ||
typeforce(everFailingType, 'value') | ||
}, new RegExp('custom error')) | ||
}) | ||
it('is caught in oneOf', function () { | ||
assert(!typeforce.oneOf(everFailingType)('value')) | ||
}) | ||
it('does not break oneOf', function () { | ||
assert(!typeforce.oneOf(everFailingType, typeforce.string)('value')) | ||
}) | ||
}) | ||
}) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
199748
9517