html-spec-tags
Version:
All HTML tags supported by the current spec. With types!
40 lines (39 loc) • 1.33 kB
JavaScript
import { getObjectTypedEntries } from '@augment-vir/common';
import { htmlSpecConstructorsByTagName } from './html.js';
import { mathmlSpecConstructorsByTagName } from './mathml.js';
import { svgSpecConstructorsByTagName } from './svg.js';
const constructorEntries = [
getObjectTypedEntries(htmlSpecConstructorsByTagName).map(([tagName, constructor,]) => {
return [
constructor,
tagName,
];
}),
getObjectTypedEntries(mathmlSpecConstructorsByTagName).map(([tagName, constructor,]) => {
return [
constructor,
tagName,
];
}),
getObjectTypedEntries(svgSpecConstructorsByTagName).map(([tagName, constructor,]) => {
return [
constructor,
tagName,
];
}),
].flat();
/** @category Tag */
export const specTagNameByConstructor = new Map(constructorEntries);
/**
* Get a spec tag name from the given constructor. Note that some constructors match multiple tags
* so you might get an unexpected output here.
*
* @category Tag
*/
export function getSpecTagNameFromConstructor(constructor) {
const tagName = specTagNameByConstructor.get(constructor);
if (!tagName) {
throw new TypeError(`'${constructor.name}' is not a valid spec tag name constructor.`);
}
return tagName;
}