UNPKG

element-vir

Version:

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

26 lines (25 loc) 935 B
/* eslint-disable @typescript-eslint/no-empty-object-type */ import { defineElement } from './define-element.js'; /** * Wraps {@link defineElement} in a superset of requirements. For example: * * - You could create element definition functions that require all elements to start with a common * prefix, like `vir-`. * - You could create element definition functions that require all elements to have _at least_ a * specified set of input properties. * - Etc. * * @category Element Definition */ export function wrapDefineElement(options) { const { assertInputs, transformInputs } = { assertInputs: options?.assertInputs ?? (() => { }), transformInputs: options?.transformInputs ?? ((inputs) => inputs), }; return (...errorParams) => { return (inputs) => { assertInputs(inputs); return defineElement(...errorParams)(transformInputs(inputs)); }; }; }