Skip to content

⬅️ Back to Table of Contents

📄 objectIterators

📊 Analysis Summary

Metric Count
🔧 Functions 3

📚 Table of Contents

🛠️ File Location:

📂 packages/eslint-plugin/src/util/objectIterators.ts

Functions

objectForEachKey(obj: T, callback: (key: keyof T) => void): void

Parameters:

  • obj T
  • callback (key: keyof T) => void

Returns: void

Calls:

  • Object.keys
  • callback
Code
export function objectForEachKey<T extends Record<string, unknown>>(
  obj: T,
  callback: (key: keyof T) => void,
): void {
  const keys = Object.keys(obj);
  for (const key of keys) {
    callback(key);
  }
}

objectMapKey(obj: T, callback: (key: keyof T) => Return): Return[]

Parameters:

  • obj T
  • callback (key: keyof T) => Return

Returns: Return[]

Calls:

  • objectForEachKey
  • values.push
  • callback
Code
export function objectMapKey<T extends Record<string, unknown>, Return>(
  obj: T,
  callback: (key: keyof T) => Return,
): Return[] {
  const values: Return[] = [];
  objectForEachKey(obj, key => {
    values.push(callback(key));
  });
  return values;
}

objectReduceKey(obj: T, callback: (acc: Accumulator, key: keyof T) => Acc…, initial: Accumulator): Accumulator

Parameters:

  • obj T
  • callback (acc: Accumulator, key: keyof T) => Accumulator
  • initial Accumulator

Returns: Accumulator

Calls:

  • objectForEachKey
  • callback
Code
export function objectReduceKey<T extends Record<string, unknown>, Accumulator>(
  obj: T,
  callback: (acc: Accumulator, key: keyof T) => Accumulator,
  initial: Accumulator,
): Accumulator {
  let accumulator = initial;
  objectForEachKey(obj, key => {
    accumulator = callback(accumulator, key);
  });
  return accumulator;
}

Generated by Syntax Scribe