I made a slight adjustment that will save you the trouble of having to add [0] to the array if there's really only one instance of that selector.
const$=(selector,context=document)=>{if(/object HTML.*Element/.test(selector.toString())){thrownewError('[utils/dom/$] Passed dom element instead of selector (string).');}if(context.querySelectorAll(selector).length>0){return[...context.querySelectorAll(selector)];}else{returncontext.querySelector(selector);}};
I had it in previous version, but i value having returned array much more than this. Because i often map, i can safely map over array of one element, but it would throw if i dont have it inside the array. Im huge advocate of that.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
That's pretty nifty!
I made a slight adjustment that will save you the trouble of having to add [0] to the array if there's really only one instance of that selector.
I had it in previous version, but i value having returned array much more than this. Because i often map, i can safely map over array of one element, but it would throw if i dont have it inside the array. Im huge advocate of that.