Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function buildPdfObjectsForOutline (layer, context) {
for (const [i, item] of layer.entries()) {
const prev = layer[i - 1]
const next = layer[i + 1]
const pdfObject = new Map([
[PDFName.of('Title'), PDFHexString.fromText(item.title)],
[PDFName.of('Dest'), PDFName.of(item.destination)],
[PDFName.of('Parent'), item.parentRef]
])
if (prev) {
pdfObject.set(PDFName.of('Prev'), prev.ref)
}
if (next) {
pdfObject.set(PDFName.of('Next'), next.ref)
}
if (item.children.length > 0) {
pdfObject.set(PDFName.of('First'), item.children[0].ref)
pdfObject.set(PDFName.of('Last'), item.children[item.children.length - 1].ref)
pdfObject.set(PDFName.of('Count'), PDFNumber.of(countChildrenOfOutline(item.children)))
}
context.assign(item.ref, PDFDict.fromMapWithContext(pdfObject, context))