vanjs-reactive-element
Version:
A reactive custom element base class for VanJS with any reactivity system
36 lines (35 loc) • 1.42 kB
TypeScript
/**
* Custom converter for property-attribute serialization
* @template T - The property value type
* @example
* const dateConverter: AttributeConverter<Date> = {
* toAttribute: (date) => date?.toISOString() ?? null,
* fromAttribute: (str) => str ? new Date(str) : null
* }
*
* @example
* // Usage in property definition
* static properties = {
* createdAt: {
* type: Date,
* converter: dateConverter,
* reflect: true
* }
* }
*/
export interface AttributeConverter<T = any> {
/** Convert property value to attribute string */
toAttribute: (value: T | null) => string | null;
/** Convert attribute string to property value */
fromAttribute: (value: string | null) => T | null;
}
declare const defaultConverter: AttributeConverter;
declare const booleanConverter: AttributeConverter<boolean>;
declare const numberConverter: AttributeConverter<number>;
declare const stringConverter: AttributeConverter<string>;
declare const objectConverter: AttributeConverter<object>;
declare const arrayConverter: AttributeConverter<any[]>;
declare const converters: Record<string, AttributeConverter<any>>;
declare const camelAndPascalToKebab: (str: string) => string;
declare const kebabToCamel: (str: string) => string;
export { defaultConverter, booleanConverter, numberConverter, stringConverter, objectConverter, arrayConverter, converters, camelAndPascalToKebab, kebabToCamel };