Security News
Node.js EOL Versions CVE Dubbed the "Worst CVE of the Year" by Security Experts
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
vanilla-dom-router
Advanced tools
When bundling and shipping Vanilla JavaScript, often we require only specific modules to be specific pages. This could mean registering event handlers, times, basically everything that would panic when run in other pages.
DOM Router supports matching modules(functions, more specifically) against routes. It requires a route(either a string or a regular expression in string form) and a bootstrapping function.
The bootstrapping function could initialize timers, register event handlers and perform page specific operations.
Only exact matches are accepted.
For example, if /foo
is registered,
only http://example.com/foo and not http://example.com/foo/bar
Routes are normalized by removing trailing slash.
So /foo
is the same as /foo/
Sometimes routes will have variable fields. These
cases can be represented with a regular expression rule.
For example, Reddit's subreddit
route, www.reddit.com/r/<subreddit-name>
), can be matched with
/r/[A-Z,a-z,0-9]+/
(assuming subreddit names are alphanumerical)
This function will get executed when window.location.pathname
matches
the any one of the registered routes. Generally, this function should be
used to set up register handlers, initialize timers, etc.
import Router from 'vanilla-dom-router';
// Initialize router
const router = new Router();
const settingsRoute = '/settings';
const profileRoute = '/r/[A-Z,a-z,0-9]+/';
const settings = () => {
let form = document.getElementById('form');
const submit = () => {
alert('Settings updated');
};
form.addEbentListener('submit', submit, true);
};
const profile = () => {
let form = document.getElementById('form');
const submit = () => {
alert('profile updated');
};
form.addEbentListener('submit', submit, true);
};
router.register(settingsRoute, settings);
router.register(profileRoute, profile);
try {
router.router();
} catch (e) {
console.log(e);
}
FAQs
Lightweight vanilla JavaScript DOM router
The npm package vanilla-dom-router receives a total of 0 weekly downloads. As such, vanilla-dom-router popularity was classified as not popular.
We found that vanilla-dom-router demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.