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

Function isFlag

deps/npm/lib/commands/completion.js:280–310  ·  view source on GitHub ↗
(word, cmd, subCmd, npm)

Source from the content-addressed store, hash-verified

278
279// check if the thing is a flag or not.
280const isFlag = (word, cmd, subCmd, npm) => {
281 // shorthands never take args.
282 const split = word.match(/^(-*)((?:no-)+)?(.*)$/)
283 const no = split[2]
284 const conf = split[3]
285
286 // Check custom definitions first
287 const customDefs = getCustomDefinitions(cmd, subCmd, npm)
288
289 // Check if conf is in custom definitions or is an alias
290 let customDef = customDefs.find(d => d.key === conf)
291 if (!customDef) {
292 // Check if conf is an alias for any of the custom definitions
293 for (const def of customDefs) {
294 if (def.alias && Array.isArray(def.alias) && def.alias.includes(conf)) {
295 customDef = def
296 break
297 }
298 }
299 }
300
301 if (customDef) {
302 const { type } = customDef
303 return no ||
304 type === Boolean ||
305 (Array.isArray(type) && type.includes(Boolean))
306 }
307
308 // No custom definitions found, should not reach here in normal flow since configCompl returns empty array when no custom defs exist
309 return false
310}
311
312// complete against the npm commands
313// if they all resolve to the same thing, just return the thing it already is

Callers 2

execMethod · 0.85
configComplFunction · 0.85

Calls 4

getCustomDefinitionsFunction · 0.85
includesMethod · 0.80
matchMethod · 0.65
findMethod · 0.65

Tested by

no test coverage detected