UNPKG

element-vir

Version:

Heroic. Reactive. Declarative. Type safe. Web components without compromise.

50 lines (49 loc) 1.4 kB
import { AssertionError, check } from '@augment-vir/assert'; import { getObjectTypedKeys, wrapInTry } from '@augment-vir/common'; const expectedStaticProperties = getObjectTypedKeys({ assign: '', assignedInputs: '', cssVars: '', elementOptions: '', events: '', hostClasses: '', init: '', InputsType: '', render: '', slotNames: '', testIds: '', StateType: '', styles: '', tagName: '', UpdateStateType: '', }); /** * Asserts that the given input is a declarative element definition. * * @category Util * @see {@link isDeclarativeElementDefinition} */ export function assertDeclarativeElementDefinition(input, failMessage) { if (!check.isFunction(input)) { throw new AssertionError('Input is not a declarative element constructor', failMessage); } expectedStaticProperties.forEach((expectedProperty) => { if (!check.hasKey(input, expectedProperty)) { throw new AssertionError(`missing prop '${expectedProperty}'`, failMessage); } }); } /** * Checks that the given input is a declarative element definition. * * @category Util * @see {@link assertDeclarativeElementDefinition} */ export function isDeclarativeElementDefinition(input) { return wrapInTry(() => { assertDeclarativeElementDefinition(input); return true; }, { fallbackValue: false, }); }