§ ast-loose-compare examples

§ Table of Contents

§ Quick Take

import { strict as assert } from "assert";
import looseCompare from "ast-loose-compare";

assert.equal(
  looseCompare(
    {
      a: {
        b: "d",
        c: [],
        e: "f",
        g: "h",
      },
    },
    {
      a: {
        b: "d",
        c: [],
      },
    }
  ),
  true
);

§ More Examples

import { strict as assert } from "assert";
import looseCompare from "ast-loose-compare";

assert.equal(
  looseCompare(
    { a: "1", b: "2", c: "3" },
    { a: "1", b: "2" }
  ),
  true
);
// true, because second (smallObj) is subset of (or equal) first (bigObj).

assert.equal(
  looseCompare(
    { a: "1", b: "2" },
    { a: "1", b: "2", c: "3" }
  ),
  false
);
// false, because second (smallObj) is not a subset (or equal) to first (bigObj).

assert.equal(
  looseCompare(["a", "b", "c"], ["a", "b"]),
  true
);
// true, because second is a subset of first

assert.equal(
  looseCompare(["a", "b"], ["a", "b", "c"]),
  false
);
// false, because second is not a subset of first

assert.equal(
  looseCompare("aaaaa\nbbbbb", "aaaaa\nbbbbb"),
  true
);
// true, because strings are equal

assert.equal(looseCompare({ a: "a" }), undefined);
// the second argument is missing

§ Empty Values

import { strict as assert } from "assert";
import looseCompare from "ast-loose-compare";

// both values are empty - they trim() to zero-length
assert.equal(
  looseCompare(
    {
      a: "a",
      b: "\n \n\n",
    },
    {
      a: "a",
      b: "\t\t \t",
    }
  ),
  true
);