separator.js 745 B

123456789101112131415161718192021222324252627282930313233
  1. import chalk from 'chalk';
  2. import figures from 'figures';
  3. /**
  4. * Separator object
  5. * Used to space/separate choices group
  6. * @constructor
  7. * @param {String} line Separation line content (facultative)
  8. */
  9. export default class Separator {
  10. constructor(line) {
  11. this.type = 'separator';
  12. this.line = chalk.dim(line || new Array(15).join(figures.line));
  13. }
  14. /**
  15. * Helper function returning false if object is a separator
  16. * @param {Object} obj object to test against
  17. * @return {Boolean} `false` if object is a separator
  18. */
  19. static exclude(obj) {
  20. return obj.type !== 'separator';
  21. }
  22. /**
  23. * Stringify separator
  24. * @return {String} the separator display string
  25. */
  26. toString() {
  27. return this.line;
  28. }
  29. }