Skip to content

Commit

Permalink
diffAsString: Take an options object instead of just format
Browse files Browse the repository at this point in the history
  • Loading branch information
papandreou committed Oct 30, 2023
1 parent 5dc9f4d commit ba1534a
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
4 changes: 2 additions & 2 deletions README.md
Expand Up @@ -48,12 +48,12 @@ You can also ask for the diff with ANSI codes, or in HTML format:
const ansiDiff = uninspected.diffAsString(
{ foo: 'bar' },
{ foo: 'baz' },
'ansi'
{ format: 'ansi' }
);
const htmlDiff = uninspected.diffAsString(
{ foo: 'bar' },
{ foo: 'baz' },
'html'
{ format: 'html' }
);
```

Expand Down
4 changes: 2 additions & 2 deletions lib/uninspected.js
Expand Up @@ -88,8 +88,8 @@ function renderDiff(a, b, format) {
}
}

uninspected.diffAsString = (a, b, format) =>
renderDiff(a, b, format || 'text').toString();
uninspected.diffAsString = (a, b, { format = 'text' } = {}) =>
renderDiff(a, b, format).toString();

uninspected.diff = (a, b) => {
uninspected.log(renderDiff(a, b));
Expand Down
6 changes: 5 additions & 1 deletion test/uninspected.js
Expand Up @@ -87,7 +87,11 @@ describe('uninspected', () => {

it('should render a diff in ansi format if requested', () => {
expect(
uninspected.diffAsString({ foo: 'bar' }, { foo: 'baz' }, 'ansi'),
uninspected.diffAsString(
{ foo: 'bar' },
{ foo: 'baz' },
{ format: 'ansi' }
),
'to equal',
'{\n' +
" \x1b[90m\x1b[38;5;242mfoo\x1b[39m: \x1b[36m'bar'\x1b[39m \x1b[31m\x1b[1m//\x1b[22m\x1b[39m \x1b[31m\x1b[1mshould equal\x1b[22m\x1b[39m \x1b[36m'baz'\x1b[39m\n" +
Expand Down

0 comments on commit ba1534a

Please sign in to comment.