Just a fast way to test tag names incase someone needs it.
First create a case insensitive set. So you don't need to worry about case when testing a string.
Answer borrowed from Jonas Wilms
class CaseInsensitiveSet extends Set {
constructor(values){
super(Array.from(values, it => it.toLowerCase()));
};
add(str) {
return super.add(str.toLowerCase());
};
has(str) {
return super.has(str.toLowerCase());
};
delete(str) {
return super.delete(str.toLowerCase());
};
};
Then create a set using his new class and all the tag name. Don't worry all current tags are here.
var TagNames = new CaseInsensitiveSet(`a,abbr,acronym,abbr,address,applet,embed,object,area,article
,aside,audio,b,base,basefont,bdi,bdo,big,blockquote,body,br,button,canvas,caption,center,cite
,code,col,colgroup,data,datalist,dd,del,details,dfn,dialog,dir,ul,div,dl,dt,em,embed,fieldset
,figcaption,figure,font,footer,form,frame,frameset,h1 to <h6>,head,header,hr,html,i,iframe,img
,input,ins,kbd,label,legend,li,link,main,map,mark,meta,meter,nav,noframes,noscript,object,ol
,optgroup,option,output,p,param,picture,pre,progress,q,rp,rt,ruby,s,samp,script,section,select
,small,source,span,strike,del,s,strong,style,sub,summary,sup,svg,table,tbody,td,template,textarea
,tfoot,th,thead,time,title,tr,track,tt,u,ul,var,video,wbr`.split(","));
Ok now you can use the built in has function to get the result in O(1).
TagNames.has("A")
// returns true
TagNames.has("a")
// returns true
TagNames.has("tAblE")
// returns true
IsValid
and compareStr
to each element?