ajquery.js/ajquery.cjs

50 lines
1.3 KiB
JavaScript
Raw Permalink Normal View History

2024-08-29 23:29:03 +00:00
/**
2024-08-30 00:46:25 +00:00
* AJQuery - The fastest, most lightweight, least dependency jQuery alternative,
* now typed, Ai-enhanced, and better than ever!
2024-08-29 23:29:03 +00:00
* @typedef AJQuery
* @prop {AJQuerySelector} $
* @prop {AJQuerySelectorAll} $$
*/
/**
* Select first matching element, just like console $
* @callback AJQuerySelector
* @param {String} cssSelector
* @param {ParentNode} [$parent=document]
*/
/**
* Select all matching child elements as a JS Array, just like console $$
* @callback AJQuerySelectorAll
* @param {String} cssSelector
* @param {ParentNode} [$parent=document]
*/
/** @type {AJQuery} */
//@ts-ignore
var AJQuery = ("object" === typeof module && exports) || {};
(function (window, AJQuery) {
"use strict";
/** @type {AJQuerySelector} */
AJQuery.$ = function (cssSelector, $parent = document) {
let $child = $parent.querySelector(cssSelector);
return $child;
};
/** @type {AJQuerySelectorAll} */
AJQuery.$$ = function (cssSelector, $parent = document) {
let nodeList = $parent.querySelectorAll(cssSelector);
let $children = Array.from(nodeList);
return $children;
};
Object.assign(window, AJQuery);
//@ts-ignore
window.AJQuery = AJQuery;
})(globalThis.window || {}, AJQuery);
if ("object" === typeof module) {
module.exports = AJQuery;
}