From 1fe60316a81d46503745e3ce3ca3c735b94588a0 Mon Sep 17 00:00:00 2001 From: Stephen Pair Date: Sat, 24 Aug 2013 00:42:31 -0400 Subject: [PATCH] add encodedData.isValid() --- util/EncodedData.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/util/EncodedData.js b/util/EncodedData.js index c8ee33c..7fb2d53 100644 --- a/util/EncodedData.js +++ b/util/EncodedData.js @@ -42,6 +42,16 @@ function ClassSpec(b) { this.withEncoding('binary'); }; + // Boolean protocol for testing if valid + EncodedData.prototype.isValid = function() { + try { + this.validate(); + return true; + } catch(e) { + return false; + } + }; + // subclasses can override to do more stuff EncodedData.prototype.validate = function() { this._validate();