Passed
Push — master ( fc2d57...76a657 )
by Barry
01:39
created

findMdpCode.js ➔ findMdpCode   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
c 1
b 0
f 0
nc 3
nop 2
dl 0
loc 13
rs 9.2
1
/** findMdpInsert and findCode functions use a similar layout to return the location and contents
2
  *   .start          => points at the character in the string why the other item starts (ie. comment or code block)
3
  *   .length         => is the overall length of the comment or code block.
4
  *   .internalStart  => points at the character in the string where the internal payload starts
5
  *   .internalLength => is the length of the internal payload
6
  *   .commandString  => is the command string found within the particular item
7
  *   .info           => is a structure containing further info about what was found
8
  * if start is returned as -1 then nothing was found
9
  *
10
  * The internalStart/internaLength defines the internal content which will be replaced. This does not include
11
  * leading and lagging CRLF/LF. So the replacement text is not required to have either leading or lagging line
12
  * endings. However, if the internalLength is negative this means that leading CRLF or LF must be added by the insertion
13
  * routine. The reason for this is that it allows insertions between code fences or mdpInsert pairs which have zero lines
14
  * between them.
15
  *
16
**/
17
18
const {findCode} = require('./findCode.js')
19
20
export function findMdpCode (txt, start) {
21
  // finds the next location of mdpInsert in a code span within txt
22
  let posn = start
23
  let x
24
  while (true) {
25
    x = findCode(txt, posn)
26
    if (x.start === -1 || x.commandString.indexOf('mdpInsert ') !== -1) {
27
      return x
28
    } else {
29
      posn = x.start + x.length
30
    }
31
  }
0 ignored issues
show
Best Practice introduced by
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
32
}
33