element-vir
Version:
Heroic. Reactive. Declarative. Type safe. Web components without compromise.
31 lines (30 loc) • 1.12 kB
JavaScript
import { check } from '@augment-vir/assert';
/**
* Checks if properties can be read off of the input at all.
*
* This exists instead of `check.hasKey` because `check.hasKey` costs roughly a microsecond per call
* (it runs its attempts through a `try`/`catch`), and the predicates below run on every
* interpolated value of every template on every render.
*
* @category Internal
*/
export function canHoldProperties(value) {
return !!value && (typeof value === 'object' || typeof value === 'function');
}
/**
* Checks if the input is an instance of {@link MinimalDefinitionWithInputs}.
*
* @category Internal
*/
export function isMinimalDefinitionWithInputs(value) {
return canHoldProperties(value) && !!value._elementVirIsMinimalDefinitionWithInputs;
}
/**
* Checks if the input is an object that has a `tagName` property. Used inside of the HTML tagged
* template functions for checking if interpolated values should be treated as element tags.
*
* @category Internal
*/
export function hasTagName(value) {
return canHoldProperties(value) && check.isString(value.tagName) && !!value.tagName;
}