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

Function representArray

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

Source from the content-addressed store, hash-verified

514}
515
516function representArray(val, space) {
517 space -= 2
518 let wrap = document.createElement("span")
519 wrap.appendChild(document.createTextNode("["))
520 for (let i = 0; i < val.length; ++i) {
521 if (i) {
522 wrap.appendChild(document.createTextNode(", "))
523 space -= 2
524 }
525 let next = space > 0 && represent(val[i], space)
526 let nextSize = next ? eltSize(next) : 0
527 if (space - nextSize <= 0) {
528 wrap.appendChild(span("etc", "…")).addEventListener("click", () => expandObj(wrap, "array", val))
529 break
530 }
531 space -= nextSize
532 wrap.appendChild(next)
533 }
534 wrap.appendChild(document.createTextNode("]"))
535 return wrap
536}
537
538function representObj(val, space) {
539 let string = typeof val.toString == "function" && val.toString(), m

Callers 1

representFunction · 0.70

Calls 4

eltSizeFunction · 0.85
spanFunction · 0.85
expandObjFunction · 0.85
representFunction · 0.70

Tested by

no test coverage detected