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

Function cleanData

deps/npm/lib/commands/view.js:390–414  ·  view source on GitHub ↗
(obj, wholePackument)

Source from the content-addressed store, hash-verified

388}
389
390function cleanData (obj, wholePackument) {
391 // JSON formatted output (JSON or specific attributes from packument)
392 const data = obj.reduce((acc, cur) => {
393 if (cur) {
394 Object.entries(cur).forEach(([k, v]) => {
395 acc[k] ||= {}
396 Object.keys(v).forEach((t) => {
397 acc[k][t] = cur[k][t]
398 })
399 })
400 }
401 return acc
402 }, {})
403
404 if (wholePackument) {
405 const cleaned = Object.entries(data).reduce((acc, [k, v]) => {
406 acc[k] = v[Queryable.ALL]
407 return acc
408 }, {})
409 log.silly('view', cleaned)
410 return cleaned
411 }
412
413 return data
414}
415
416// return whatever was printed
417function showFields ({ data, version, fields, json }) {

Callers 1

#viewPackageMethod · 0.85

Calls 4

reduceMethod · 0.80
forEachMethod · 0.65
keysMethod · 0.65
entriesMethod · 0.45

Tested by

no test coverage detected