-
- if (minimal) {
- if (JSON.stringify(dumbdiff).length <
- JSON.stringify(my_diff).length) {
- my_diff = dumbdiff;
- }
- }
-
- if (key.length === 0) {
- if (my_diff.length > 1) {
- my_diff = this.sortStanzas(my_diff);
- }
- }
- return my_diff;
- },
-
- // =========================================================================
-
- isStrictlyEqual: function(left, right) {
- /* Recursively compare the (potentially nested) objects left
- * and right */
- var idx, ks, key;
- if (this.isTerminal(left) && this.isTerminal(right)) {
- return (left === right);
- }
- if (this.isTerminal(left) || this.isTerminal(right)) {
- return false;
- }
- if (left instanceof Array && right instanceof Array) {
- if (left.length !== right.length) {
- return false;
- }
- for (idx = 0; idx < left.length; idx++) {
- if (! this.isStrictlyEqual(left[idx], right[idx])) {
- return false;
- }
- }
- return true;
- }
- if (left instanceof Array || right instanceof Array) {
- return false;
- }
- ks = this.computeKeysets(left, right);
- if (ks[1].length !== 0 || ks[2].length !== 0) {
- return false;
- }
- for (idx = 0; idx < ks[0].length; idx++) {
- key = ks[0][idx];
- if (! this.isStrictlyEqual(left[key], right[key])) {
- return false;
- }
- }
- return true;
- },
-
- isTerminal: function(obj) {
- /* Test whether obj will be a terminal node in the tree when
- * serialized as JSON. */
- if (typeof obj === 'string' || typeof obj === 'number' ||
- typeof obj === 'boolean' || obj === null) {
- return true;
- }
- return false;
- },
-
- appendKey: function(stanzas, arr, key) {
- /* Get the appropriate key for appending to the array arr,
- * assuming that stanzas will also be applied, and arr appears
- * at key within the overall structure. */
- key = key !== undefined ? key : [];
- var addition_key = arr.length, prior_key, i;
- for (i = 0; i < stanzas.length; i++) {
- prior_key = stanzas[i][0];
- if (stanzas[i].length > 1 &&
- prior_key.length === key.length + 1 &&
- prior_key[prior_key.length-1] >= addition_key)
- { addition_key = prior_key[prior_key.length-1] + 1; }