steveukx / properties

Properties reader for Node.js
MIT License
77 stars 33 forks source link

Allow to write without sections #25

Closed Andreas-Schoenefeldt closed 4 years ago

Andreas-Schoenefeldt commented 5 years ago

Hi Guys,

my project is using the properties files for translations, but without sections. It would be great, if I could dissable the sections on write in a way.

I provided https://github.com/steveukx/properties/pull/24 for this - please review and merge at your convenience, if you deem this usefull.

Thx a lot! Andreas

JoeFirebaugh commented 4 years ago

I would like to see that feature included, but for those of you that see this before it's included, this works well:

let lines = [];
properties.each((key, value) => {
    lines.push(key + "=" + value);
});
fs.writeFileSync('/path/to/file.properties', lines.join('\n'));
LeonardoPortoTR commented 4 years ago

That would be awesome to have as an option

steveukx commented 4 years ago

Hi, apologies for the slow response to this - there is an option now available in version 2.1.1 on npm that adds this functionality:

const propertiesReader = require('properties-reader');
const props = propertiesReader(filePath, 'utf-8', { writer: { saveSections: false } });

await props.save(outputFilePath);
Andreas-Schoenefeldt commented 2 years ago

It works, thx a lot! 👍