// Match an object having at least the expected properties. function matchObjectWithAtLeast(act, exp) { if (!isObject(act)) thrownew MatchError("expected object, got " + quote(act));
for (var key in exp) { if (!(key in act)) thrownew MatchError("expected property " + quote(key) + " not found in " + quote(act)); try {
match(act[key], exp[key]);
} catch (inner) { if (!(inner instanceof MatchError)) { throw inner;
}
inner.message = `matching property "${String(key)}":\n${inner.message}`; throw inner;
}
}
returntrue;
}
// Match an object having all the expected properties and no more. function matchObjectWithExactly(act, exp) {
matchObjectWithAtLeast(act, exp);
for (var key in act) { if (!(key in exp)) { thrownew MatchError("unexpected property " + quote(key));
}
}
returntrue;
}
function matchFunction(act, exp) { if (!isFunction(act)) thrownew MatchError("expected function, got " + quote(act));
if (act !== exp) thrownew MatchError("expected function: " + exp + "\nbut got different function: " + act);
}
function matchArray(act, exp) { if (!isObject(act) || !("length" in act)) thrownew MatchError("expected array-like object, got " + quote(act));
var length = exp.length; if (act.length !== exp.length) thrownew MatchError("expected array-like object of length " + length + ", got " + quote(act));
for (var i = 0; i < length; i++) { if (i in exp) { if (!(i in act)) thrownew MatchError("expected array property " + i + " not found in " + quote(act)); try {
match(act[i], exp[i]);
} catch (inner) { if (!(inner instanceof MatchError)) { throw inner;
}
inner.message = `matching array element [${i}]:\n${inner.message}`; throw inner;
}
}
}
returntrue;
}
function match(act, exp) { if (exp === Pattern.ANY) returntrue;
if (exp instanceof Pattern) return exp.match(act);
if (isAtom(exp)) return matchAtom(act, exp);
if (isArrayLike(exp)) return matchArray(act, exp);
if (isFunction(exp)) return matchFunction(act, exp);
if (isObject(exp)) return matchObjectWithAtLeast(act, exp);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.