Skip to content

Commit

Permalink
Fix integer output in TOML format (#1458)
Browse files Browse the repository at this point in the history
  • Loading branch information
slathrop authored and erquhart committed Jun 26, 2018
1 parent 5f7deb5 commit 5a93f04
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/formats/__tests__/tomlFormatter.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import tomlFormatter from '../toml';

describe('tomlFormatter', () => {
it('should output TOML integer values without decimals', () => {
expect(
tomlFormatter.toFile({ testFloat: 123.456, testInteger: 789, title: 'TOML' })
).toEqual(
[
'testFloat = 123.456',
'testInteger = 789',
'title = "TOML"'
].join('\n')
);
});
});
4 changes: 4 additions & 0 deletions src/formats/toml.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ const outputReplacer = (key, value) => {
if (value instanceof AssetProxy) {
return `${ value.path }`;
}
if (Number.isInteger(value)) {
// Return the string representation of integers so tomlify won't render with tenths (".0")
return value.toString();
}
// Return `false` to use default (`undefined` would delete key).
return false;
};
Expand Down

0 comments on commit 5a93f04

Please sign in to comment.