append.js 412 B

123456789101112131415161718
  1. 'use strict';
  2. var extend = require('deep-extend');
  3. var EOL = require('os').EOL;
  4. module.exports = function (to, contents, options) {
  5. options = extend({
  6. trimEnd: true,
  7. separator: EOL
  8. }, options || {});
  9. var currentContents = this.read(to);
  10. if (options.trimEnd) {
  11. currentContents = currentContents.replace(/\s+$/, '');
  12. }
  13. this.write(to, currentContents + options.separator + contents);
  14. };