1 | ;
|
2 |
|
3 | var EOL = require('os').EOL;
|
4 |
|
5 | module.exports = function (to, contents, options) {
|
6 | options = {
|
7 | trimEnd: true,
|
8 | separator: EOL,
|
9 | ...options
|
10 | };
|
11 |
|
12 | if (!this.exists(to) && options.create) {
|
13 | this.write(to, contents);
|
14 | return;
|
15 | }
|
16 |
|
17 | var currentContents = this.read(to);
|
18 | if (options.trimEnd) {
|
19 | currentContents = currentContents.replace(/\s+$/, '');
|
20 | }
|
21 |
|
22 | this.write(to, currentContents + options.separator + contents);
|
23 | };
|