UNPKG

vike

Version:

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

18 lines (17 loc) • 989 B
export { assertOnBeforeRenderHookReturn }; import { assertUsage } from '../utils/assert.js'; import { isPlainObject } from '../utils/isPlainObject.js'; import { assertPageContextProvidedByUser } from './assertPageContextProvidedByUser.js'; import { assertHookReturnedObject } from './assertHookReturnedObject.js'; import pc from '@brillout/picocolors'; function assertOnBeforeRenderHookReturn(hookReturnValue, hookFilePath) { if (hookReturnValue === undefined || hookReturnValue === null) { return; } const errPrefix = `The onBeforeRender() hook defined by ${hookFilePath}`; assertUsage(isPlainObject(hookReturnValue), `${errPrefix} should return a plain JavaScript object, ${pc.cyan('undefined')}, or ${pc.cyan('null')}`); assertHookReturnedObject(hookReturnValue, ['pageContext'], errPrefix); if (hookReturnValue.pageContext) { assertPageContextProvidedByUser(hookReturnValue['pageContext'], { hookName: 'onBeforeRender', hookFilePath }); } }