stringWriter.js 655 B

123456789101112131415161718192021222324252627282930
  1. 'use strict';
  2. var utils = require('./utils');
  3. /**
  4. * An object to write any content to a string.
  5. * @constructor
  6. */
  7. var StringWriter = function() {
  8. this.data = [];
  9. };
  10. StringWriter.prototype = {
  11. /**
  12. * Append any content to the current string.
  13. * @param {Object} input the content to add.
  14. */
  15. append: function(input) {
  16. input = utils.transformTo("string", input);
  17. this.data.push(input);
  18. },
  19. /**
  20. * Finalize the construction an return the result.
  21. * @return {string} the generated string.
  22. */
  23. finalize: function() {
  24. return this.data.join("");
  25. }
  26. };
  27. module.exports = StringWriter;