All files / src/handlers extract-area.ts

87.5% Statements 14/16
71.43% Branches 5/7
100% Functions 3/3
100% Lines 12/12

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 215x   5x 8x 8x 6x   6x 6x   6x 6x   6x   6x     8x    
import { FileGenerator, Handler } from '@/class'
 
export default function(name, begin, end = begin): Handler {
  const genFile: FileGenerator = async file => {
    if (!file.projectFileExisted) return
    const projectContent = await file.getProjectContent()
 
    let beginIndex = projectContent.indexOf(begin)
    Iif (beginIndex === -1) return
 
    beginIndex += begin.length
    const endIndex = projectContent.indexOf(end, beginIndex)
 
    Iif (endIndex === -1) return
 
    file.addition[name] = projectContent.substring(beginIndex, endIndex)
  }
 
  return new Handler(genFile)
}