diff --git a/.github/workflows/node.js.yml b/.github/workflows/node.js.yml
new file mode 100644
index 0000000..1e042af
--- /dev/null
+++ b/.github/workflows/node.js.yml
@@ -0,0 +1,24 @@
+name: Node.js CI
+on:
+ push:
+ branches: ['main']
+ pull_request:
+jobs:
+ build:
+ name: 'Node.js build: fmt, clean-install, lint, test'
+ runs-on: ubuntu-latest
+ strategy:
+ matrix:
+ node-version:
+ # - 20.x
+ - latest
+ steps:
+ - uses: actions/checkout@v3
+ - name: Use Node.js ${{ matrix.node-version }}
+ uses: actions/setup-node@v3
+ with:
+ node-version: ${{ matrix.node-version }}
+ - run: npm run fmt
+ - run: npm clean-install
+ - run: npm run lint
+ - run: npm run test
diff --git a/README.md b/README.md
index dbc793c..df40cc0 100644
--- a/README.md
+++ b/README.md
@@ -2,8 +2,8 @@
The fastest, most lightweight, fewest dependency jQuery alternative.
-Development Build: 145B (with comments) \
-Production Build: 103B (min + gz)
+Development Build: 572B (types + comments) \
+Production Build: 146B (min + gz)
## Example Usage
@@ -18,11 +18,15 @@ console.log("innerText:", $("p:nth-child(2").innerText);
### via GitHub
```bash
-my_ver="v2.1.2"
+my_ver="v3.0.0"
mkdir ./vendor/
+
curl -fsSL "https://raw.githubusercontent.com/coolaj86/ajquery.js/${my_ver}/ajquery.js" \
-o ./vendor/ajquery.js
+
+# Lighthouse-optimized
+npx -p uglify-js@3 uglifyjs ./vendor/ajquery.js -o ./vendor/ajquery.min.js
```
```html
@@ -32,7 +36,41 @@ curl -fsSL "https://raw.githubusercontent.com/coolaj86/ajquery.js/${my_ver}/ajqu
### via CDN
```html
-
+
+```
+
+Bundler-optimized:
+
+```html
+
+```
+
+Tree-shaking-optimized:
+
+```html
+
+```
+
+### via NPM
+
+```sh
+npm install --save ajquery@3
+```
+
+#### CommonJS
+
+```js
+let AJQuery = require("ajquery");
+let $ = AJQuery.$;
+let $$ = AJQuery.$$;
+```
+
+#### ESM
+
+```js
+import AJQuery from "ajquery";
+let $ = AJQuery.$;
+let $$ = AJQuery.$$;
```
## API
diff --git a/ajquery.cjs b/ajquery.cjs
new file mode 100644
index 0000000..a80d3a2
--- /dev/null
+++ b/ajquery.cjs
@@ -0,0 +1,47 @@
+/**
+ * @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;
+}
diff --git a/ajquery.js b/ajquery.js
index 0ad0405..caaa8ab 100644
--- a/ajquery.js
+++ b/ajquery.js
@@ -1,7 +1,20 @@
-function $(sel, el) {
- return (el || document).querySelector(sel);
+/**
+ * Select first matching element, just like console $
+ * @param {String} cssSelector
+ * @param {ParentNode} [$parent=document]
+ */
+function $(cssSelector, $parent = document) {
+ let $child = $parent.querySelector(cssSelector);
+ return $child;
}
-function $$(sel, el) {
- return Array.from((el || document).querySelectorAll(sel));
+/**
+ * Select all matching child elements as a JS Array, just like console $$
+ * @param {String} cssSelector
+ * @param {ParentNode} [$parent=document]
+ */
+function $$(cssSelector, $parent = document) {
+ let nodeList = $parent.querySelectorAll(cssSelector);
+ let $children = Array.from(nodeList);
+ return $children;
}
diff --git a/ajquery.mjs b/ajquery.mjs
new file mode 100644
index 0000000..617efe4
--- /dev/null
+++ b/ajquery.mjs
@@ -0,0 +1,32 @@
+/** @import('typed-query-selector/strict') */
+
+let AJQuery = { $, $$ };
+
+/**
+ * AJQuery - The fastest, most lightweight, least dependency jQuery alternative,
+ * now Ai-enhanced, and better than ever!
+ * @namespace AJQuery
+ */
+
+/**
+ * Selects the first element that matches the given selector within the specified parent.
+ * @param {string} sel - The CSS selector to match.
+ * @param {Document|Element} [$parent=document] - The parent element to search within. Defaults to document.
+ */
+function $(sel, $parent = document) {
+ let $child = $parent.querySelector(sel);
+ return $child;
+}
+
+/**
+ * Select all matching child elements from $parent (which is document by default)
+ * @param {String} sel - The CSS selector to match.
+ * @param {Document|Element} [$parent=document] - The parent element to search within. Defaults to document.
+ */
+function $$(sel, $parent = document) {
+ let $children = $parent.querySelectorAll(sel);
+ let children = Array.from($children);
+ return children;
+}
+
+export default AJQuery;
diff --git a/benchmark.js b/benchmark.js
index d6a71d4..58a1710 100644
--- a/benchmark.js
+++ b/benchmark.js
@@ -8,6 +8,8 @@ async function main() {
console.info("Angular: 2517");
await sleep(520);
console.info("React: 3785");
+ await sleep(128);
+ console.info("Vite: 6666");
await sleep(230);
console.info('"Vanilla" JS: 6237');
await sleep(65);
diff --git a/example.html b/example.html
index 5534620..cc0d13a 100644
--- a/example.html
+++ b/example.html
@@ -6,6 +6,18 @@
+
+
+
+
+
+