shelving
Version:
Toolkit for using data in JavaScript.
32 lines (31 loc) • 891 B
JavaScript
import { isArray } from "./array.js";
import { isIterable } from "./iterate.js";
import { isSet } from "./set.js";
/** Extract the key from an object entry. */
export function getEntryKey([k]) {
return k;
}
/** Extract the value from an object entry. */
export function getEntryValue([, v]) {
return v;
}
/** Yield the keys of an iterable set of entries. */
export function* getEntryKeys(input) {
for (const [k] of input)
yield k;
}
/** Yield the values of an iterable set of entries. */
export function* getEntryValues(input) {
for (const [, v] of input)
yield v;
}
export function* getEntries(...input) {
for (const entries of input) {
if (isArray(entries) || isSet(entries))
yield* entries.entries();
else if (isIterable(entries))
yield* entries;
else
yield* Object.entries(entries);
}
}