πŸ“„ File detail

utils/objectGroupBy.ts

🧩 .tsπŸ“ 19 linesπŸ’Ύ 511 bytesπŸ“ text
← Back to All Files

🎯 Use case

This file lives under β€œutils/”, which covers cross-cutting helpers (shell, tempfiles, settings, messages, process input, …). On the API surface it exposes objectGroupBy β€” mainly functions, hooks, or classes. What the file header says: https://tc39.es/ecma262/multipage/fundamental-objects.html#sec-object.groupby.

Generated from folder role, exports, dependency roots, and inline comments β€” not hand-reviewed for every path.

🧠 Inline summary

https://tc39.es/ecma262/multipage/fundamental-objects.html#sec-object.groupby

πŸ“€ Exports (heuristic)

  • objectGroupBy

πŸ–₯️ Source preview

/**
 * https://tc39.es/ecma262/multipage/fundamental-objects.html#sec-object.groupby
 */
export function objectGroupBy<T, K extends PropertyKey>(
  items: Iterable<T>,
  keySelector: (item: T, index: number) => K,
): Partial<Record<K, T[]>> {
  const result = Object.create(null) as Partial<Record<K, T[]>>
  let index = 0
  for (const item of items) {
    const key = keySelector(item, index++)
    if (result[key] === undefined) {
      result[key] = []
    }
    result[key].push(item)
  }
  return result
}