import { Attribute , Element } from "parse5" ; export const getAttribute = ( node , name ) : Attribute | undefined => node . attrs . find ( ( attr ) => attr . name === name ) ; export const getAttributeValue = ( node , name ) : string | undefined => getAttribute ( node , name ) ?. value ; export const getClassNames = ( node , matcher ? ) : string [ ] => { const classNames = getAttributeValue ( node , "class" ) ?. split ( " " ) || [ ] ; return matcher ? classNames . filter ( ( name ) => typeof matcher === "string" ? name . startsWith ( matcher ) : name . match ( matcher ) ) : classNames ; } ; export const getClassNameIntersect = < T extends string > ( node , toCompare ) : T [ ] => getClassNames ( node ) . filter ( ( name ) : name is T => toCompare . includes ( name as T ) ) ; export const hasClassName = ( node , className ) : boolean => getClassNames ( node ) . some ( ( name ) => name === className ) ; export const hasClassNameIntersect = ( node , toCompare ) : boolean => getClassNames ( node ) . some ( ( name ) => toCompare . includes ( name ) ) ; export const getAttributeIfTag = ( node , tagNames , attr ) : string | undefined => tagNames . includes ( node . tagName ) ? getAttributeValue ( node , attr ) : undefined ; export const hasRelIntersect = ( node , toCompare ) : boolean => Boolean ( getAttributeValue ( node , "rel" ) ?. split ( " " ) . some ( ( name ) => toCompare . includes ( name ) ) ) ; export const getRelIntersect = ( node , toCompare ) : string [ ] => getAttributeValue ( node , "rel" ) ?. split ( " " ) . filter ( ( name ) => toCompare . includes ( name ) ) || [ ] ;