2.1.22 • Published 10 months ago
@wmdigi/dom v2.1.22
@wmdigi/dom
A lightweight DOM manipulation and state management library with jQuery-like syntax.
Installation
npm install @wmdigi/dom
yarn add @wmdigi/dom
bun add @wmdigi/domUsage
import { $ } from "@wmdigi/dom";
// DOM Manipulation
$(".button").addClass("active");
$("#main").hide();
$('input[type="text"]').val("Hello");
// Store Management
$.store.user = { name: "John", age: 30 };
$.store.user.name = "Jane"; // Updates only name
// Subscribe to changes
$.store.user.subscribe((user) => {
console.log("User updated:", user);
});
$.store.user.name.subscribe((name) => {
console.log("Name changed to:", name);
});
// Local Storage Store
$.local.theme = "dark"; // Automatically persists to localStorage
console.log($.local.theme); // Reads from localStorage
// Chaining
$(".card").addClass("highlight").attr("data-active", "true").show();
// Event handling
$(".submit-button").on("click", (e) => {
console.log("Button clicked at:", e.clientX, e.clientY);
});
// DOM Ready
$.ready(() => {
console.log("DOM is ready");
});
// Creating elements
$.create('<div class="new">Content</div>').addClass("active");
// Timeout utility with cleanup
const clear = $.timeout(() => {
console.log("Delayed execution");
}, 1000);
// Optional: Cancel timeout
clear();API
DOM Selection
$(selector)- Select elements using CSS selector$(element)- Wrap DOM element$(elements)- Wrap array of DOM elements
Store Management
$.store- Global state store$.local- localStorage-backed store.subscribe(callback)- Subscribe to state changes
DOM Methods
.first- Get first element.array- Get array of elements.val([value])- Get/set input value.text([content])- Get/set text content.html([content])- Get/set HTML content.data([key], [value])- Get/set data attributes.addClass(...classes)- Add classes.removeClass(...classes)- Remove classes.toggleClass(class)- Toggle class.hasClass(class)- Check if element has class.attr(name, [value])- Get/set attribute.on(event, callback)- Add event listener.hide()- Hide elements.show()- Show elements
Utility Methods
$.ready(callback)- DOM ready handler$.create(html)- Create element from HTML$.timeout(callback, ms)- Execute callback after delay with cleanup
Development
# Clone and setup
git clone https://github.com/wmdigi/dom.git
cd dom
bun install
# Build
bun run buildPublishing
# Patch version (1.0.0 -> 1.0.1)
bun pub
# Minor version (1.0.0 -> 1.1.0)
bun pub minor
# Major version (1.0.0 -> 2.0.0)
bun pub majorThe publish script automatically:
- Builds the library
- Commits changes
- Bumps version
- Pushes to git with tags
- Publishes to npm
License
MIT
Contributing
Pull requests welcome. For major changes, please open an issue first.
Credits
Created by Wonder Makers - making the web simpler, one library at a time.
2.1.22
10 months ago
2.1.21
10 months ago
2.1.20
10 months ago
2.1.17
10 months ago
2.1.16
11 months ago
2.1.14
11 months ago
2.1.15
11 months ago
2.1.9
1 year ago
1.1.4
1 year ago
1.1.3
1 year ago
2.1.2
1 year ago
2.1.1
1 year ago
2.1.4
1 year ago
2.1.3
1 year ago
2.1.12
1 year ago
2.1.5
1 year ago
2.1.10
1 year ago
2.1.8
1 year ago
2.1.11
1 year ago
2.1.0
1 year ago
2.0.0
1 year ago
1.1.2
1 year ago
1.1.1
1 year ago
1.1.0
1 year ago
1.0.3
1 year ago
1.0.2
1 year ago
1.0.1
1 year ago
1.0.0
1 year ago