@vicaniddouglas/js_aide 1.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026, vicaniddouglas
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
20
+ ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,172 @@
1
+ # @vicaniddouglas/js_aide
2
+
3
+ A versatile collection of modular JavaScript utility helpers designed to streamline single-page application (SPA) development and general web programming tasks. This library provides a set of independent modules for common functionalities such as routing, input handling, validation, and more.
4
+
5
+ ## Description
6
+
7
+ `@vicaniddouglas/js_aide` bundles frequently needed JavaScript functionalities into a cohesive, easy-to-use package. Each module is designed to be independent, allowing you to import only what you need, reducing bundle size and improving application performance. From dynamic client-side routing to robust input validation and DOM manipulation, this library aims to accelerate your development workflow.
8
+
9
+ ## Features
10
+
11
+ ### `Router`
12
+
13
+ A modern, feature-rich client-side router for Single-Page Applications (SPAs).
14
+
15
+ - History API-based navigation.
16
+ - Supports dynamic route segments (e.g., `/users/:id`).
17
+ - Automatic interception of internal `<a>` tags for seamless SPA navigation.
18
+ - Configurable route guards (`beforeNavigate`) with support for redirects.
19
+ - View lifecycle hooks (`beforeEnter`, `beforeLeave`) directly on DOM elements for managing view transitions and data loading.
20
+ - Parses and exposes URL query parameters and hash fragments.
21
+ - Efficient view toggling, only hiding the previously active view.
22
+
23
+ ### `validator`
24
+
25
+ A module offering various input validation utilities (e.g., email, number, custom regex).
26
+
27
+ ### `inputHandlers`
28
+
29
+ Utilities for enhanced DOM element interaction, such as restricting input to numbers, formatting number inputs, or providing custom select options.
30
+
31
+ ### `requests`
32
+
33
+ Helper functions for making HTTP requests (e.g., `fetch` wrappers for common patterns).
34
+
35
+ ### `dates`
36
+
37
+ Convenience functions for common date and time manipulation tasks.
38
+
39
+ ### `fileManager`
40
+
41
+ Utilities for browser-side file handling (e.g., file uploads, local storage, file type checks).
42
+
43
+ ### `camera`
44
+
45
+ Functions for interacting with device cameras, capturing images or video streams (requires browser API support).
46
+
47
+ ### `figures`
48
+
49
+ Utilities for number formatting, currency (including UGX defaults), and percentages.
50
+
51
+ ### `dependencyManager`
52
+
53
+ A robust manager for dynamically loading CDN-based libraries (like SheetJS or jsPDF) with retry logic and dependency tracking.
54
+
55
+ ## Installation
56
+
57
+ Install the package via npm:
58
+
59
+ ```bash
60
+ npm install @vicaniddouglas/js_aide
61
+ ```
62
+
63
+ Or via yarn:
64
+
65
+ ```bash
66
+ yarn add @vicaniddouglas/js_aide
67
+ ```
68
+
69
+ ## Usage
70
+
71
+ Ensure your project is configured to use ES Modules (e.g., by adding `"type": "module"` to your project's `package.json` or using a bundler).
72
+
73
+ ### Importing Modules
74
+
75
+ You can import specific modules or all of them:
76
+
77
+ ```javascript
78
+ // Import specific modules
79
+ import { Router, validator } from "@vicaniddouglas/js_aide";
80
+
81
+ // Or import all, though generally not recommended for tree-shaking
82
+ // import * => JSAide from '@vicaniddouglas/js_aide';
83
+ ```
84
+
85
+ ### Example: Using the Router
86
+
87
+ ```javascript
88
+ // main.js
89
+ import { Router } from "@vicaniddouglas/js_aide";
90
+
91
+ // Define your routes, mapping paths to DOM element IDs
92
+ const appRoutes = {
93
+ "/": "home-view",
94
+ "/products": "products-list-view",
95
+ "/products/:id": "product-detail-view", // Dynamic segment
96
+ "/profile": "user-profile-view",
97
+ };
98
+
99
+ const router = new Router(appRoutes, "/");
100
+
101
+ // --- Optional: Add a route guard ---
102
+ router.beforeNavigate = async (toPath, navigationContext) => {
103
+ console.log(
104
+ `Attempting to navigate from ${navigationContext.from} to ${toPath}`,
105
+ );
106
+
107
+ // Example: Protect the profile route
108
+ if (toPath.startsWith("/profile")) {
109
+ const isAuthenticated = await checkUserAuthentication(); // Your auth logic
110
+ if (!isAuthenticated) {
111
+ console.warn(
112
+ "Access denied: User not authenticated. Redirecting to login.",
113
+ );
114
+ return "/login"; // Redirect to a login page
115
+ }
116
+ }
117
+ return true; // Allow navigation
118
+ };
119
+
120
+ // --- Optional: Listen for navigation events ---
121
+ window.addEventListener("router:navigated", (event) => {
122
+ const { path, pathname, params, query, hash } = event.detail;
123
+ console.log(`Navigated to: ${path}`);
124
+ console.log("Params:", params); // e.g., { id: '123' } for /products/123
125
+ console.log("Query:", query); // e.g., { search: 'item' } for /search?search=item
126
+ console.log("Hash:", hash); // e.g., '#section1' for /page#section1
127
+ });
128
+
129
+ // --- Example: Define view lifecycle hooks on your DOM elements ---
130
+ // Assuming you have a <div id="product-detail-view"> in your HTML
131
+ const productDetailView = document.getElementById("product-detail-view");
132
+ if (productDetailView) {
133
+ productDetailView.beforeEnter = async (routeParams) => {
134
+ console.log(`Entering product detail view for ID: ${routeParams.id}`);
135
+ // Fetch product data based on routeParams.id
136
+ const product = await fetchProductData(routeParams.id);
137
+ // Render product details into the view
138
+ renderProductDetails(productDetailView, product);
139
+ };
140
+
141
+ productDetailView.beforeLeave = () => {
142
+ console.log("Leaving product detail view. Cleaning up...");
143
+ // Dispose of any event listeners or resources specific to this view
144
+ cleanupProductDetailResources();
145
+ };
146
+ }
147
+
148
+ // Manually navigate (or click an <a> tag)
149
+ router.navigate("/products/123?utm_source=email#overview");
150
+ ```
151
+
152
+ ## Development
153
+
154
+ ### Running Tests
155
+
156
+ We use **Vitest** for unit testing. The library has over 80+ verified tests covering all core modules (Routing, Validation, WebSocket, Dates, etc.).
157
+
158
+ ```bash
159
+ npm test
160
+ ```
161
+
162
+ ### Building for Production
163
+
164
+ Generates minified **ESM**, **IIFE**, and **CJS** bundles in the `dist` folder using esbuild.
165
+
166
+ ```bash
167
+ npm run build
168
+ ```
169
+
170
+ ## License
171
+
172
+ This project is licensed under the [MIT License](LICENSE).