MCPcopy Create free account
hub / github.com/npm/cli / deref

Function deref

lib/utils/cmd-list.js:148–177  ·  view source on GitHub ↗
(c)

Source from the content-addressed store, hash-verified

146}
147
148const deref = (c) => {
149 if (!c) {
150 return
151 }
152
153 // Translate camelCase to snake-case (i.e. installTest to install-test)
154 if (c.match(/[A-Z]/)) {
155 c = c.replace(/([A-Z])/g, m => '-' + m.toLowerCase())
156 }
157
158 // if they asked for something exactly we are done
159 if (commands.includes(c)) {
160 return c
161 }
162
163 // if they asked for a direct alias
164 if (aliases[c]) {
165 return aliases[c]
166 }
167
168 const abbrevs = abbrev(commands.concat(Object.keys(aliases)))
169
170 // first deref the abbrev,
171 // if there is one then resolve any aliases so `npm install-cl` will resolve to `install-clean` then to `ci`
172 let a = abbrevs[c]
173 while (aliases[a]) {
174 a = aliases[a]
175 }
176 return a
177}
178
179module.exports = {
180 aliases,

Callers 4

cmdMethod · 0.85
#loadMethod · 0.85
cmdComplFunction · 0.85
execMethod · 0.85

Calls 1

replaceMethod · 0.80

Tested by

no test coverage detected