Fix integer output in TOML format (#1458)
This commit is contained in:
committed by
Shawn Erquhart
parent
a2cacac0e5
commit
e5b8af9f4d
15
src/formats/__tests__/tomlFormatter.spec.js
Normal file
15
src/formats/__tests__/tomlFormatter.spec.js
Normal 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')
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
@ -11,6 +11,10 @@ const outputReplacer = (key, value) => {
|
|||||||
if (value instanceof AssetProxy) {
|
if (value instanceof AssetProxy) {
|
||||||
return `${ value.path }`;
|
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` to use default (`undefined` would delete key).
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user