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

Method write

deps/npm/lib/utils/format-search-stream.js:96–157  ·  view source on GitHub ↗
(data)

Source from the content-addressed store, hash-verified

94 }
95
96 write (data) {
97 if (!filter(data, this.#exclude)) {
98 return
99 }
100 // Normalize
101 const pkg = {
102 authors: data.maintainers.map((m) => `${strip(m.username)}`).join(' '),
103 publisher: strip(data.publisher?.username || ''),
104 date: data.date ? data.date.toISOString().slice(0, 10) : 'prehistoric',
105 description: strip(data.description ?? ''),
106 keywords: [],
107 name: strip(data.name),
108 version: data.version,
109 }
110 if (Array.isArray(data.keywords)) {
111 pkg.keywords = data.keywords.map(strip)
112 } else if (typeof data.keywords === 'string') {
113 pkg.keywords = strip(data.keywords.replace(/[,\s]+/, ' ')).split(' ')
114 }
115
116 let output
117 if (this.#parseable) {
118 output = [pkg.name, pkg.description, pkg.author, pkg.date, pkg.version, pkg.keywords]
119 .filter(Boolean)
120 .map(col => ('' + col).replace(/\t/g, ' ')).join('\t')
121 return super.write(output)
122 }
123
124 const keywords = pkg.keywords.map(k => {
125 if (this.#args.includes(k)) {
126 return this.#chalk.cyan(k)
127 } else {
128 return k
129 }
130 }).join(' ')
131
132 const description = this.#highlight(pkg.description)
133 let name
134 if (this.#args.includes(pkg.name)) {
135 name = this.#chalk.cyan(pkg.name)
136 } else {
137 name = this.#highlight(pkg.name)
138 name = this.#chalk.blue(name)
139 }
140
141 if (description.length) {
142 output = `${name}\n${description}\n`
143 } else {
144 output = `${name}\n`
145 }
146 if (pkg.publisher) {
147 output += `Version ${this.#chalk.blue(pkg.version)} published ${this.#chalk.blue(pkg.date)} by ${this.#chalk.blue(pkg.publisher)}\n`
148 } else {
149 output += `Version ${this.#chalk.blue(pkg.version)} published ${this.#chalk.blue(pkg.date)} by ${this.#chalk.yellow('???')}\n`
150 }
151 output += `Maintainers: ${pkg.authors}\n`
152 if (keywords) {
153 output += `Keywords: ${keywords}\n`

Callers

nothing calls this directly

Calls 12

#highlightMethod · 0.95
stripFunction · 0.85
includesMethod · 0.80
blueMethod · 0.80
yellowMethod · 0.80
filterFunction · 0.70
mapMethod · 0.65
sliceMethod · 0.65
filterMethod · 0.65
joinMethod · 0.45
splitMethod · 0.45
writeMethod · 0.45

Tested by

no test coverage detected