html-spec-tags
Advanced tools
Comparing version 2.1.0 to 2.2.0
@@ -1,5 +0,5 @@ | ||
import { Constructor } from 'type-fest'; | ||
import { HtmlSpecTagName } from './html'; | ||
import { MathmlSpecTagName } from './mathml'; | ||
import { SvgSpecTagName } from './svg'; | ||
import { PropertyValueType } from '@augment-vir/common'; | ||
import { HtmlSpecTagName, htmlSpecConstructorsByTagName } from './html'; | ||
import { MathmlSpecTagName, mathmlSpecConstructorsByTagName } from './mathml'; | ||
import { SvgSpecTagName, svgSpecConstructorsByTagName } from './svg'; | ||
/** All possible spec tag names in a single array. */ | ||
@@ -9,2 +9,4 @@ export declare const allSpecTagNames: ReadonlyArray<SpecTagName>; | ||
export type SpecTagName = HtmlSpecTagName | SvgSpecTagName | MathmlSpecTagName; | ||
/** Any of the possible spec tag name constructors. */ | ||
export type SpecTagNameConstructor = PropertyValueType<typeof htmlSpecConstructorsByTagName> | PropertyValueType<typeof mathmlSpecConstructorsByTagName> | PropertyValueType<typeof svgSpecConstructorsByTagName>; | ||
/** | ||
@@ -22,3 +24,3 @@ * Get the constructor for the given tag name. Since there are some duplicate tag names, the | ||
*/ | ||
export declare function getTagNameConstructor(tagName: SpecTagName): Constructor<Element>; | ||
export declare function getSpecTagNameConstructor(tagName: SpecTagName): SpecTagNameConstructor; | ||
/** Type guards the input as a valid spec tag name. */ | ||
@@ -30,1 +32,6 @@ export declare function isSpecTagName(input: unknown): input is SpecTagName; | ||
export declare function ensureSpecTagName(input: unknown): SpecTagName; | ||
/** | ||
* Get a spec tag name from the given constructor. Note that some constructors match multiple tags | ||
* so you might get an unexpected output here. | ||
*/ | ||
export declare function getSpecTagNameFromConstructor(constructor: SpecTagNameConstructor): SpecTagName; |
@@ -6,2 +6,3 @@ import { isTruthy, typedArrayIncludes, wrapInTry } from '@augment-vir/common'; | ||
import { allSvgSpecTagNames, svgSpecConstructorsByTagName } from './svg'; | ||
import { specTagNameByConstructor } from './tag-name-by-constructor'; | ||
/** All possible spec tag names in a single array. */ | ||
@@ -25,3 +26,3 @@ export const allSpecTagNames = Array.from(new Set([ | ||
*/ | ||
export function getTagNameConstructor(tagName) { | ||
export function getSpecTagNameConstructor(tagName) { | ||
const constructor = htmlSpecConstructorsByTagName[tagName] || | ||
@@ -69,1 +70,12 @@ svgSpecConstructorsByTagName[tagName] || | ||
} | ||
/** | ||
* Get a spec tag name from the given constructor. Note that some constructors match multiple tags | ||
* so you might get an unexpected output here. | ||
*/ | ||
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; | ||
} |
{ | ||
"name": "html-spec-tags", | ||
"version": "2.1.0", | ||
"version": "2.2.0", | ||
"description": "All HTML tags supported by the current spec. With types!", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
60792
18
1403