MCPcopy
hub / github.com/tj/commander.js / groupItems

Method groupItems

lib/help.js:418–434  ·  view source on GitHub ↗

* Group items by their help group heading. * * @param {Command[] | Option[]} unsortedItems * @param {Command[] | Option[]} visibleItems * @param {Function} getGroup * @returns {Map }

(unsortedItems, visibleItems, getGroup)

Source from the content-addressed store, hash-verified

416 * @returns {Map<string, Command[] | Option[]>}
417 */
418 groupItems(unsortedItems, visibleItems, getGroup) {
419 const result = new Map();
420 // Add groups in order of appearance in unsortedItems.
421 unsortedItems.forEach((item) => {
422 const group = getGroup(item);
423 if (!result.has(group)) result.set(group, []);
424 });
425 // Add items in order of appearance in visibleItems.
426 visibleItems.forEach((item) => {
427 const group = getGroup(item);
428 if (!result.has(group)) {
429 result.set(group, []);
430 }
431 result.get(group).push(item);
432 });
433 return result;
434 }
435
436 /**
437 * Generate the built-in help text.

Callers 2

formatHelpMethod · 0.95
index.test-d.tsFile · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected