{"name":"tcompare","version":"6.0.1-4","description":"A comprehensive comparison library, for use in test frameworks","author":{"name":"Isaac Z. Schlueter","email":"i@izs.me","url":"https://izs.me"},"license":"BlueOak-1.0.0","type":"module","exports":{"./package.json":{"import":"./package.json","require":"./package.json"},".":{"import":{"types":"./dist/mjs/index.d.ts","default":"./dist/mjs/index.js"},"require":{"types":"./dist/cjs/index.d.ts","default":"./dist/cjs/index.js"}}},"dependencies":{"diff":"^5.1.0"},"scripts":{"snap":"tap","test":"tap","prepare":"tsc -p tsconfig/cjs.json && tsc -p tsconfig/esm.json && bash scripts/fixup.sh","pretest":"npm run prepare","presnap":"npm run prepare","format":"prettier --write . --loglevel warn --ignore-path ../../.prettierignore --cache","typedoc":"typedoc --tsconfig tsconfig/esm.json ./src/*.ts"},"tap":{"coverage-map":"map.js"},"engines":{"node":">=16"},"repository":{"type":"git","url":"git+https://github.com/tapjs/tapjs.git"},"_id":"tcompare@6.0.1-4","readme":"# tcompare\n\nA comprehensive comparison library, for use in test frameworks.\nWalks an object once, generating both a simple true/false result,\nas well as a string representation of both the actual and\nexpected values (highlighting just the parts that differ) and a\npatch-style diff string.\n\n## USAGE\n\n```ts\n// require() is fine too\nimport {\n  match,\n  same,\n  strict,\n  has,\n  hasStrict,\n  matchStrict,\n  matchOnly,\n  matchOnlyStrict,\n} from 'tcompare'\nimport type { Result } from 'tcompare'\n\nconst result: Result = match(object, pattern)\nif (!result.match) {\n  console.log(`item did not match pattern`)\n  console.log(result.diff)\n} else {\n  console.log(`it's a match!`)\n}\n\n// raw classes exported also\nimport { MatchOnly } from 'tcompare'\nconst mo = new MatchOnly({ a: 1, b: 2 }, { expect: { a: Number } })\nconst diff: string = mo.print()\nconsole.log(mo.match) // false\nconsole.log(diff)\n/*\n--- expected\n+++ actual\n@@ -1,2 +1,3 @@\n Object {\n+  \"b\": 2,\n }\n*/\n```\n\n- `indent` - String to indent each nested level. Defaults to `'  '`.## METHODS\n\nEach method corresponds to an exported class. Except for\n`format()` (which returns a string), they all return a `Result`\nobject. (That is, `{diff:string, match:boolean}`.)\n\n- `format(object, [options])` - No comparisons performed. Just print out the\n  object. Returns just the formatted string.\n- `same(object, pattern, [options])` - Deep equivalence. Ensure\n  that all items in the pattern are found in the object, and vice\n  versa, matching loosely (so, for example `1` will match with\n  `'1'`).\n- `strict(object, pattern, [options])` - Deep equality. Ensure\n  that all items in the pattern are found in the object, and vice\n  versa, matching strictly (so, for example `1` will not match\n  with `'1'`). Objects must have the same constructors, and all\n  fields will be matched recursively using the same `strict`\n  test.\n- `has(object, pattern, [options])` - Ensure that all items in\n  the pattern are found in the object, but ignore additional\n  items found in the object, matching loosely. Classes only need\n  to match loosely, so a plain JavaScript object can be used to\n  check for fields on a class instance.\n- `hasStrict(object, pattern, [options])` - Ensure that all items\n  in the pattern are found in the object, but ignore additional\n  items found in the object, matching strictly. Constructors do\n  _not_ have to match between objects, but if `constructor` is\n  set as an ownProperty on the pattern object, then it will be\n  checked for strict equality.\n- `match(object, pattern, [options])` - Verify that all items in\n  `pattern` are found in `object`, and that they match in an\n  extremely loose way. This is the loosest possible algorithm,\n  allowing cases where we just want to verify that an object\n  contains a few important properties. In summary:\n  - If the object and pattern are loosely equal, then pass\n  - If the object and the pattern are both Regular Expressions,\n    Date objects or Buffers, then pass if they represent\n    equivalent values.\n  - If the pattern is a RegExp, cast object to a string, and\n    test against the RegExp.\n  - If both are Strings, pass if pattern appears in object. (\n  - If pattern is a function, and object is an instance of that\n    function, then pass. (This also applies to Symbol, Number,\n    String, etc.)\n  - If pattern and object are collections (object, map, set,\n    array or iterable), then compare their contents. Each type\n    of collection can only match its same type, with the\n    exception of non-Set iterables (including `arguments`\n    objects), which are cast to Arrays.\n- `matchOnly(object, pattern, [options])` - Same comparison\n  testing as `match()`, but will fail if the `object` has any\n  properties that are not present in the `pattern`.\n- `matchStrict(object, pattern, [options])` - Same comparison\n  testing as `match()`, but will fail when two values are\n  equivalent but not strictly equal. (That is, when\n  `a == b && !(a === b)`.)\n- `matchOnlyStrict(object, pattern, [options])` - Same comparison\n  testing as `matchOnly()`, but will fail when two values are\n  equivalent but not strictly equal. (That is, when\n  `a == b && !(a === b)`.)\n\nThere are classes exported to correspond to each of these. All of these are\ninstantiated like `new Format(object, options)`. An `expect` option is\nrequired for all classes except `Format`. Call `obj.print()` on the resulting\nobject to generate a diff. Once the diff (or format) is generated, it'll have\na `match` boolean member.\n\n## Classes\n\nThe exported classes should usually not be used directly, and\ntheir implementation details are subject to change as needed\nbetween versions.\n\nThe class heirarchy is:\n\n```\nFormat\n+-- Same\n    +-- Strict\n    +-- Has\n    |   +-- HasStrict (uses Strict.prototype.test)\n    |   +-- Match\n    |       +-- MatchStrict (fails if a==b && a!==b)\n    +-- MatchOnly (uses Match.prototype.test)\n    +-- MatchOnlyStrict (uses MatchStrict.prototype.test)\n```\n\nIn order to compare or print an object, instantiate one of the\nclasses, and call then the `print()` method, which will return\nthe diff or formatted value. The `match` boolean property will\nbe set after calling `print()`. If the objects match, then the\nreturned `diff` will also be an empty string.\n\n## OPTIONS\n\n### `FormatOptions` type\n\nEvery method and class can take the following options.\n\n- `sort` - Set to `true` to sort object keys. This is important when\n  serializing in a deterministic way.\n\n- `style` - Set to `pretty` for a very human-readable style of object printing.\n  Set to `js` for a copy-and-paste friendly valid JavaScript output. Set to\n  `tight` for a minimal white-space js format. Default is `pretty`. Example:\n\n  ```\n  // pretty style\n  Object {\n    \"myMap\": Map {\n      Object {\n        \"a\": 1,\n      } => Object {\n        \"b\": 2,\n      }\n    }\n  }\n\n  // js style\n  {\n    \"myMap\": new Map([\n      [{\n        \"a\": 1,\n      }, {\n        \"b\": 2,\n      }]\n    ])\n  }\n\n  // tight style\n  {\"myMap\":new Map([[{\"a\":1,},{\"b\":2,}],]),}\n  ```\n\n  Note that `tight` is not suitable for comparisons, only formatting.\n\n- `bufferChunkSize` - The number of bytes to show per line when\n  printing long `Buffer` objects. Defaults to 32.\n\n- `indent` - String to indent each nested level. Defaults to `'  '`.\n\n- `includeEnumerable` - Set to `true` to walk over _all_\n  enumerable properties of a given object when comparing or\n  formatting, rather than the default of only showing enumerable\n  own-properties. Note that calling getter functions may be\n  hazardous, as they may trigger side-effects.\n\n- `includeGetters` - Set to `true` to walk over all enumerable\n  getters on an object's prototype (but not from further down the\n  prototype chain), in addition to own-properties. This is useful\n  in cases where you want to compare or print an object with\n  enumerable getters that return internal values in a read-only\n  manner. Note that calling getter functions can be hazardous, as\n  they may trigger side-effects.\n\n### `SameOptions` type\n\nComparison classes also take the following options.\n\n- `expect` - required. The pattern object to compare against.\n- `diffContext` - Optional, default 10. Number of lines of\n  context to show in diff output.\n\n## Circular References\n\nCircular references are displayed using YAML-like references, in\norder to determine _which_ item is circularly referenced.\n\nWhen doing comparisons, a pattern and object will be considered\nmatching if they contain the _same_ circularity. So, for example,\nif a pattern refers to itself, then an object should refer to\nitself as well.\n\n```js\nconst a = { list: [], b: {} }\na.list.push(a)\na.list.push(a.b)\na.b.a = a\nconsole.log(format(a))\n\n/*\n&ref_1 Object {\n  \"list\": Array [\n    <*ref_1>,\n    Object {\n      \"a\": <*ref_1>,\n    },\n  ],\n  \"b\": Object {\n    \"a\": <*ref_1>,\n  },\n}\n*/\n```\n\nNote that circular references are never going to be valid\nJavaScript, even when using the `js` style.\n\n### Caveat: Circularity Between Pattern and Object Gets Weird\n\nIt's possible to get strange output when an object and pattern\nrefer to one another.\n\n```js\nimport { same } from 'tcompare'\n\nconst a = {}\na.o = a\nconst b = { o: a }\n\nconsole.error(same(a, b).diff)\n\n// produces this confusing output:\n/*\n--- expected\n+++ actual\n@@ -1,5 +1,3 @@\n &ref_1 Object {\n-  \"o\": &ref_1 Object {\n-    \"o\": <*ref_1>,\n-  },\n+  \"o\": <*ref_1>,\n }\n*/\n```\n\nThe more correct output would be something like:\n\n```\n--- expected\n+++ actual\n@@ -1,5 +1,3 @@\n &ref_1 Object {\n-  \"o\": &ref_2 Object {\n-    \"o\": <*ref_2>,\n-  },\n+  \"o\": <*ref_1>,\n }\n```\n\nHowever, this requires tracking IDs in a much more complicated\nway, being aware of whether the object is being read as an\npattern object or test object when determining its reference ID.\n\nSince this is a relatively unusual thing to happen, and only\naffects the output (but still properly detects whether it should\nbe treated as a match or not), it will likely not be addressed.\n","readmeFilename":"README.md","gitHead":"e3de44331a26fc39bba46e5dfb8f5989d8ef5f20","bugs":{"url":"https://github.com/tapjs/tapjs/issues"},"homepage":"https://github.com/tapjs/tapjs#readme","_nodeVersion":"18.16.0","_npmVersion":"9.8.1","dist":{"integrity":"sha512-0WYZco+UNYL+qgexaP66FJaZVolhPbORzCbEnEBdhq91AN5PiQbp9f/ZMnA2Eo5QiUr+2cPTbbuhzUS6WQb1Vw==","shasum":"1e96fc3f9be0b5a52041d7117115e36b15eeaf14","tarball":"http://registry-npm.ywwl.com/tcompare/download/tcompare-6.0.1-4.tgz","fileCount":93,"unpackedSize":448935,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIEGpM4WVe89ExWUFgTkWHMpnQy2roEVtHa7UYh8oVYOeAiBdmbNPAfw9oHh8NWaHxv5G+Xl4hhScX0uC8bns8vmNlw=="}],"size":70346,"noattachment":false,"key":"/tcompare/-/tcompare-6.0.1-4.tgz"},"_npmUser":{"name":"isaacs","email":"i@izs.me"},"directories":{},"maintainers":[{"name":"isaacs","email":"i@izs.me"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/tcompare_6.0.1-4_1693117014970_0.5214803373628849"},"_hasShrinkwrap":false,"publish_time":1693117015162,"_cnpm_publish_time":1693117015162,"dist-tags":{"latest":"9.3.2","pre":"6.1.0"}}