Skip to content

Commit

Permalink
Merge pull request #11 from evert/debugger
Browse files Browse the repository at this point in the history
Nice debugger output
  • Loading branch information
evert authored Dec 14, 2018
2 parents 4518419 + 3f829d9 commit 8b77efa
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Changelog
* Added `toSource()` and `fromSource()` methods to easily get access to the
underlying bigint.
* `Money.value` is now private.

* Nice v8 debugger output. Shows the currency + the symbol.

0.2.0 (2018-12-12)
------------------
Expand Down
11 changes: 11 additions & 0 deletions src/money.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,4 +196,15 @@ export class Money {
return m;

}

/**
* This function creates custom output in console.log statements.
*/
[Symbol.for('nodejs.util.inspect.custom')](): string {

// The 4-digit choice is arbitrary. Might revise this.
return this.toFixed(4) + ' ' + this.currency;

}

}
10 changes: 10 additions & 0 deletions test/money.ts
Original file line number Diff line number Diff line change
Expand Up @@ -335,4 +335,14 @@ describe('Money class', () => {

});

describe('Debug output', () => {

it('should return a meaningful value', () => {

const m = new Money(1, 'USD');
expect((<any> m)[Symbol.for('nodejs.util.inspect.custom')]()).to.equal('1.0000 USD');

});

});
});

0 comments on commit 8b77efa

Please sign in to comment.