UNPKG

vike

Version:

(Replaces Next.js/Nuxt) 🔨 Composable framework to build advanced applications with flexibility and stability.

21 lines (20 loc) • 744 B
export { assertHookReturnedObject }; import { assert, assertUsage } from '../utils/assert.js'; import { stringifyStringArray } from '../utils/stringifyStringArray.js'; function assertHookReturnedObject(obj, keysExpected, errPrefix) { assert(!errPrefix.endsWith(' ')); const keysUnknown = []; const keys = Object.keys(obj); for (const key of keys) { if (!keysExpected.includes(key)) { keysUnknown.push(key); } } assertUsage(keysUnknown.length === 0, [ errPrefix, 'returned an object with following unknown keys:', stringifyStringArray(keysUnknown) + '.', 'Only following keys are allowed:', stringifyStringArray(keysExpected) + '.', ].join(' ')); }