getEntryKey()function
Extract the key from an object entry.
getEntryKey([k]: Entry<K, T>): K
An entry is a readonly [key, value] pair — the shape produced by Map.entries(), Object.entries(), and Array.entries(). These helpers provide a uniform way to iterate, extract, and type entries across all of those sources.
import { getEntries, getEntryKeys, getEntryValues } from "shelving/util";
const obj = { a: 1, b: 2 };
const map = new Map([["c", 3], ["d", 4]]);
const arr = [10, 20, 30];
const set = new Set(["x", "y"]);
// getEntries accepts objects, Maps, arrays, Sets, or any Entry iterable — including multiple at once.
for (const [k, v] of getEntries(obj, map)) { /* ... */ }
for (const [i, v] of getEntries(arr)) { /* ... */ }
for (const [k] of getEntries(set)) { /* ... */ } // Sets yield [value, value] entries
for (const k of getEntryKeys(getEntries(obj))) { /* k = "a", "b" */ }
for (const v of getEntryValues(getEntries(map))) { /* v = 3, 4 */ }import { getEntryKey, getEntryValue } from "shelving/util";
const entry = ["name", "Alice"] as const;
getEntryKey(entry); // "name"
getEntryValue(entry); // "Alice"EntryObject to convert entries back to object typesimport type { Entry, EntryObject } from "shelving/util";
type E = Entry<"status", "active" | "inactive">;
type O = EntryObject<E>; // { status: "active" | "inactive" }Extract the key from an object entry.
getEntryKey([k]: Entry<K, T>): K
Extract the value from an object entry.
getEntryValue([, v]: Entry<K, T>): T
Yield the keys of an iterable set of entries.
getEntryKeys(input: Iterable<Entry<K, T>>): Iterable<K>
Yield the values of an iterable set of entries.
getEntryValues(input: Iterable<Entry<K, T>>): Iterable<T>
Yield the entries from one or more entry-yielding sources (sets, objects, maps, arrays, or iterables of entries).
getEntries(...input: (ImmutableSet<K & T> | Partial<ImmutableObject<K, T>> | Iterable<Entry<K, T>>)[]): Iterable<Entry<K, T>>
getEntries(...input: (ImmutableArray<T> | ImmutableSet<K & T> | Iterable<Entry<K, T>>)[]): Iterable<Entry<K, T>>
getEntries(...input: (ImmutableSet<K & T> | Iterable<Entry<K, T>>)[]): Iterable<Entry<K, T>>
Single key/value entry from a map-like object.
readonly [K, T]
Extract the key type from an Entry.
X extends Entry<infer Y, unknown> ? Y : never
Extract the value type from an Entry.
X extends Entry<unknown, infer Y> ? Y : never
Turn an Entry type back into an object with a single property. i.e. EntryObject<Entry<"a", string>> produces { a: string }
{ readonly [E in T as E[0]]: E[1] }