diff --git a/lib/change.js b/lib/change.js index 511483d..f03c88e 100644 --- a/lib/change.js +++ b/lib/change.js @@ -86,9 +86,21 @@ function Change(options) { } module.exports = Change; +Change.isChange = function isChange(change) { + if (!change || typeof (change) !== 'object') { + return false; + } + if ((change instanceof Change) || + ((typeof (change.toBer) === 'function') && + (change.modification !== undefined) && + (change.operation !== undefined))) { + return true; + } + return false; +}; Change.compare = function (a, b) { - if (!(a instanceof Change) || !(b instanceof Change)) + if (!Change.isChange(a) || !Change.isChange(b)) throw new TypeError('can only compare Changes'); if (a.operation < b.operation)