MCPcopy Index your code
hub / github.com/marijnh/Eloquent-JavaScript / representSimpleObj

Function representSimpleObj

src/client/sandbox.mjs:559–592  ·  view source on GitHub ↗
(val, space)

Source from the content-addressed store, hash-verified

557}
558
559function representSimpleObj(val, space) {
560 space -= 2
561 let wrap = document.createElement("span")
562 let name = constructorName(val)
563 if (name) {
564 space -= name.length
565 wrap.appendChild(document.createTextNode(name))
566 }
567 wrap.appendChild(document.createTextNode("{"))
568 try {
569 let first = true
570 for (let prop in val) if (hop(val, prop)) {
571 if (first) {
572 first = false
573 } else {
574 space -= 2
575 wrap.appendChild(document.createTextNode(", "))
576 }
577 let next = space > 0 && represent(val[prop], space)
578 let nextSize = next ? prop.length + 2 + eltSize(next) : 0
579 if (space - nextSize <= 0) {
580 wrap.appendChild(span("etc", "…")).addEventListener("click", () => expandObj(wrap, "obj", val))
581 break
582 }
583 space -= nextSize
584 wrap.appendChild(span("prop", prop + ": "))
585 wrap.appendChild(next)
586 }
587 } catch (e) {
588 wrap.appendChild(document.createTextNode("…"))
589 }
590 wrap.appendChild(document.createTextNode("}"))
591 return wrap
592}
593
594function expandObj(node, type, val) {
595 let wrap = document.createElement("span")

Callers 1

representObjFunction · 0.70

Calls 6

eltSizeFunction · 0.85
spanFunction · 0.85
expandObjFunction · 0.85
constructorNameFunction · 0.70
hopFunction · 0.70
representFunction · 0.70

Tested by

no test coverage detected