Skip to content

Commit

Permalink
refactor: simplify diff formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Aug 10, 2023
1 parent 2ed5b67 commit 8e6cabc
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
8 changes: 4 additions & 4 deletions src/diff.ts
Expand Up @@ -81,15 +81,15 @@ export class DiffEntry {
toJSON() {
switch (this.type) {
case "added": {
return `[+] Added ${this.key}`;
return `Added \`${this.key}\``;
}
case "removed": {
return `[-] Removed ${this.key}`;
return `Removed \`${this.key}\``;
}
case "changed": {
return `[~] Changed ${this.key} from ${
return `Changed \`${this.key}\` from \`${
this.oldValue?.toString() || "-"
} to ${this.newValue.toString()}`;
}\` to \`${this.newValue.toString()}\``;
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions test/index.test.ts
Expand Up @@ -102,9 +102,9 @@ describe("diff", () => {

expect(diff(obj1, obj2)).toMatchInlineSnapshot(`
[
"[-] Removed nested.y",
"[~] Changed nested.bar.baz from \\"123\\" to 123",
"[+] Added nested.x",
"Removed \`nested.y\`",
"Changed \`nested.bar.baz\` from \`\\"123\\"\` to \`123\`",
"Added \`nested.x\`",
]
`);
});
Expand Down

0 comments on commit 8e6cabc

Please sign in to comment.