@lou.codes/iterables
Version:
🔁 Iterable and AsyncIterable utils
23 lines (22 loc) • 753 B
JavaScript
import { createIterableIterator } from "./createIterableIterator.js";
/**
* Yields all entries of an object (including symbols).
*
* @category Generators
* @example
* ```typescript
* const entries = objectEntries({ a: 1, b: 2 });
* entries.next(); // { value: ["a", 1], done: false }
* entries.next(); // { value: ["b", 2], done: false }
* entries.next(); // { value: undefined, done: true }
* ```
* @param input Object to get entries from.
* @returns Iterable with entries of the given object (including symbols).
*/
export const objectToEntries = input =>
createIterableIterator(function* () {
// eslint-disable-next-line functional/no-loop-statements
for (const key of Reflect.ownKeys(input)) {
yield [key, input[key]];
}
});