with-banner.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. /**
  2. * @param {string} title
  3. * @param {string[]} description
  4. * @param {Date} date
  5. * @param {string[]} content
  6. * @returns {string}
  7. */
  8. const withBanner = (title, description, date, content) => {
  9. return `########################################
  10. # ${title}
  11. # Last Updated: ${date.toISOString()}
  12. # Size: ${content.length}
  13. ${description.map(line => line ? `# ${line}` : '#').join('\n')}
  14. ########################################\n` + content.join('\n') + '\n################# END ###################\n';
  15. };
  16. /**
  17. * @param {string} title
  18. * @param {string[]} description
  19. * @param {Date} date
  20. * @param {string[]} content
  21. * @returns {string[]}
  22. */
  23. const withBannerArray = (title, description, date, content) => {
  24. return [
  25. `########################################`,
  26. `# ${title}`,
  27. `# Last Updated: ${date.toISOString()}`,
  28. `# Size: ${content.length}`,
  29. ...description.map(line => line ? `# ${line}` : '#'),
  30. `########################################`,
  31. ...content,
  32. `################# END ###################`,
  33. ''
  34. ];
  35. };
  36. module.exports.withBanner = withBanner;
  37. module.exports.withBannerArray = withBannerArray;