All files / src/modules markdown.js

100% Statements 62/62
100% Branches 12/12
100% Functions 8/8
100% Lines 62/62

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 631x 1x 22x 22x 1x 1x 2x 2x 2x 2x 1x 1x 2x 2x 2x 2x 2x 2x 2x 2x 1x 1x 2x 2x 2x 8x 8x 8x 2x 2x 2x 1x 1x 2x 2x 2x 2x 8x 2x 2x 2x 2x 1x 1x 2x 2x 2x 2x 8x 2x 2x 2x 2x 1x 1x 1x 1x 1x 1x 1x 1x 1x  
export class Markdown {
  constructor(pure) {
    this.pure = pure;
  }
 
  header(num = 1) {
    const head = this.pure.helpers.repeatString({ string: '#', num });
 
    return `${head} ${this.pure.lorem.word()}`;
  }
 
  emphasis(type) {
    const types = ['_', '~', '*', '**'];
    const def = type || types[this.pure.random.number(types.length - 1)];
    const words = this.pure.lorem.words(3).split(' ');
    const position = this.pure.random.number(words.length - 1);
    words[position] = def + words[position] + def;
 
    return words.join(' ');
  }
 
  table(num = 3) {
    const table = ['| head1 | head2 | head3 |', '|:-----:|:-----:|:-----:|'];
 
    for (let i = 0; num > i; i += 1) {
      const line = ['|', this.pure.lorem.words(3).split(' ').join('|'), '|'].join('');
      table.push(line);
    }
 
    return table.join('\n');
  }
 
  orderedList(num = 3) {
    const words = this.pure.lorem.words(num).split(' ');
    const list = [];
 
    words.forEach((word, index) => {
      list.push(`${index + 1}. ${word}`);
    });
 
    return list.join('\n');
  }
 
  unorderedList(num = 3) {
    const words = this.pure.lorem.words(num).split(' ');
    const list = [];
 
    words.forEach(word => {
      list.push(`* ${word}`);
    });
 
    return list.join('\n');
  }
 
  inlineCode() {
    return `\` ${this.pure.lorem.word()} \``;
  }
 
  blockCode() {
    return `\`\`\`javascript\n ${this.pure.lorem.word()} \n\`\`\``;
  }
}