That's pretty much what that include file does, but with "dqs" rather than "$". I'm not a fan of using the $ as it might confuse others that you're using JQuery.
$ is what I would expect and prefer, because it’s what I’ve been using in my browser dev tools for over fifteen years (ah, Firebug; fond reminiscences). If your document doesn’t use the names, you’ll get implementations roughly equivalent to these:
function $(selector, element = document) {
return element.querySelector(selector);
}
function $$(selector, element = document) {
return Array.from(element.querySelectorAll(selector));
}
Reference on more magic available in the console (there’s a lot of good stuff):
You'll have to do this in addition to one of the previously discussed solutions if you want something like document.qsA since document isn't an HTMLElement.
These days? This is what we were using 10 years ago before React came about! It works fine, but performance can be a problem in large apps as handlebars just naively recreates entire DOM trees rather than diffing.
That's wild, never really looked into it, reminds me how a C programmer thinks. I'm mostly backend but get involved with frontend every now and then. Tried to avoid Angular and React but now trying to teach myself Angular. AngularJS was nice. Angular sucks, very complicated for doing the same things I can do with vanilla HTML/CSS/JS, but that's what companies seem to be hiring for.
I've been a solo dev as well. But unless you're going to live forever, the code should be maintainable by someone else. You can be a solo dev that's impossible to ever work with, or you can maintain good practices so that other people can play along as well.
https://github.com/no-gravity/dqs.js
Which turns document.querySelector('.some .thing') into dqs('.some .thing').
The other one is Handlebars:
https://github.com/handlebars-lang/handlebars.js/
Which I use for all my frontend templating needs.