UPDATE: this was published as a module on npm
Like in a test...
import assert from 'node:assert/strict'
import test from 'node:test'
import sideBySide from './side-by-side.js'
test('Make sure one object is the same as another', () => {
assert.deepStrictEqual(
object1,
object2,
sideBySide(
['EXPECTED', JSON.stringify(object2, null, 2)],
['ACTUAL', JSON.stringify(object1, null, 2)],
),
)
})
✖ Make sure one object is the same as another (0.606542ms)
AssertionError [ERR_ASSERTION]:
EXPECTED │ ACTUAL
────────────────────────────┼────────────────────────────
{ │ {
"type": "pair", │ "type": "pair",
"value": [ │ "value": [
{ │ {
"type": null, │ "type": null,
"value": "foo" │ "value": "foo"
}, │ },
{ │ {
"type": "pair", │ "type": "pair",
"value": [ │ "value": [
{ │ {
"type": null, │ "type": null,
"value": "bar" │ "value": "bar"
}, │ },
{ │ {
"type": null, │ "type": null,
"value": "baz" │ "value": "baz"
} │ }
], │ ],
"bar": "baz" │ "bar": "baz"
} │ }
], │ ],
"foo": "bar:baz" │ "foo": [
} │ {
│ "type": null,
│ "value": "bar"
│ },
│ {
│ "type": null,
│ "value": "baz"
│ }
│ ]
│ }
Published to npm so I don't need to copy paste the function across repos
https://www.npmjs.com/package/print-adjacent