const showNumber = (lineInfo) => { const first = lineInfo.line[0]; return first === ' ' || first === '@' || first === '-' || first === '+'; } const htmlEncode = require('js-htmlencode') const construct = (data) => { const diffs = data.diffs for (let diffLineIndex in diffs.lines) { diffs.lines[diffLineIndex].line = htmlEncode(diffs.lines[diffLineIndex].line) } let result = ` ` for (let lineInfo of diffs.lines) { result += ` ` } result += `
Old    ${diffs.old}
   New ${diffs.new}
${showNumber(lineInfo) ? lineInfo['num-old'] : '  '} ${showNumber(lineInfo) ? lineInfo['num-new'] : '  '}
${lineInfo.line}
` return result; } onmessage = function (e) { const result = construct(e.data); postMessage(result) }