MCPcopy Index your code
hub / github.com/nodejs/node / printHuman

Method printHuman

deps/npm/lib/commands/fund.js:92–147  ·  view source on GitHub ↗
(fundingInfo)

Source from the content-addressed store, hash-verified

90 }
91
92 printHuman (fundingInfo) {
93 const unicode = this.npm.config.get('unicode')
94 const seenUrls = new Map()
95
96 const tree = obj => archy(obj, '', { unicode })
97
98 const result = depth({
99 tree: fundingInfo,
100
101 // composes human readable package name and creates a new archy item for readable output
102 visit: ({ name, version, funding }) => {
103 const [fundingSource] = [].concat(normalizeFunding(funding)).filter(isValidFunding)
104 const { url } = fundingSource || {}
105 const pkgRef = getPrintableName({ name, version })
106
107 if (!url) {
108 return { label: pkgRef }
109 }
110 let item
111 if (seenUrls.has(url)) {
112 item = seenUrls.get(url)
113 item.label += `${this.npm.chalk.dim(',')} ${pkgRef}`
114 return null
115 }
116 item = {
117 label: tree({
118 label: this.npm.chalk.blue(url),
119 nodes: [pkgRef],
120 }).trim(),
121 }
122
123 // stacks all packages together under the same item
124 seenUrls.set(url, item)
125 return item
126 },
127
128 // puts child nodes back into returned archy output while also filtering out missing items
129 leave: (item, children) => {
130 if (item) {
131 item.nodes = children.filter(Boolean)
132 }
133
134 return item
135 },
136
137 // turns tree-like object return by libnpmfund into children to be properly read by treeverse
138 getChildren: node =>
139 Object.keys(node.dependencies || {}).map(key => ({
140 name: key,
141 ...node.dependencies[key],
142 })),
143 })
144
145 const res = tree(result)
146 return res
147 }
148
149 async openFundingUrl ({ path, tree, spec, fundingSourceNumber }) {

Callers 1

execMethod · 0.95

Calls 11

getPrintableNameFunction · 0.85
concatMethod · 0.80
blueMethod · 0.80
getMethod · 0.65
filterMethod · 0.65
hasMethod · 0.65
mapMethod · 0.65
keysMethod · 0.65
depthFunction · 0.50
treeFunction · 0.50
setMethod · 0.45

Tested by

no test coverage detected