import { assert } from "../../assert.js";

/**
 * @template V
 * @param {Object<V>} object
 * @param {string} key
 * @returns {V}
 * @throws {Error} if such key does not exist
 */
export function validatedObjectValueByKey(object, key) {

    assert.isString(key, 'key');

    const value = object[key];

    if (value === undefined) {
        throw new Error(`Unknown key '${key}', valid keys: [${Object.keys(object).join(', ')}]`);
    }

    return value;
}
