UNPKG

@woosh/meep-engine

Version:

Pure JavaScript game engine. Fully featured and production ready.

22 lines (16 loc) 481 B
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; }