MCPcopy Create free account
hub / github.com/nodejs/node / getArrayOrObject

Function getArrayOrObject

deps/npm/lib/utils/display.js:86–100  ·  view source on GitHub ↗
(items)

Source from the content-addressed store, hash-verified

84const isPlainObject = (v) => v && typeof v === 'object' && !Array.isArray(v)
85
86const getArrayOrObject = (items) => {
87 if (items.length) {
88 const foundNonObject = items.find(o => !isPlainObject(o))
89 // Non-objects and arrays cant be merged, so just return the first item
90 if (foundNonObject) {
91 return foundNonObject
92 }
93 // We use objects with 0,1,2,etc keys to merge array
94 if (items.every((o, i) => Object.hasOwn(o, i))) {
95 return Object.assign([], ...items)
96 }
97 }
98 // Otherwise its an object with all object items merged together
99 return Object.assign({}, ...items.filter(o => isPlainObject(o)))
100}
101
102const redactValue = (obj) => JSON.parse(redactLog(JSON.stringify(obj)))
103

Callers 1

getJsonBufferFunction · 0.85

Calls 5

isPlainObjectFunction · 0.85
everyMethod · 0.80
assignMethod · 0.80
findMethod · 0.65
filterMethod · 0.65

Tested by

no test coverage detected