Fix integer output in TOML format (#1458)

This commit is contained in:
Steve Lathrop 2018-06-26 16:28:35 -04:00 committed by Shawn Erquhart
parent a2cacac0e5
commit e5b8af9f4d
2 changed files with 19 additions and 0 deletions

View File

@ -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')
);
});
});

View File

@ -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;
};