npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

baeunjs

v1.0.4

Published

A lightweight library for DOM manipulation, state management, and SPA routing.

Readme

BaeunJS

A lightweight JavaScript library for DOM manipulation, state management, and hash-based SPA routing. BaeunJS provides a simple way to build small to medium-sized Single Page Applications (SPAs).


Features

  • elem: Create DOM elements with attributes, event listeners, and children.
  • stateManager: Manage application state with localStorage and reactive callbacks.
  • hashRouter: Build hash-based routing for SPAs without server-side configurations.

Installation

Install BaeunJS using NPM:

npm install baeunjs

Or include it via a script tag:

<script src="https://unpkg.com/baeunjs"></script>

Usage

1. DOM Manipulation with elem

The elem function simplifies the creation of DOM elements.

import { elem } from "baeunjs";

// Create a div with attributes and children
const myDiv = elem("div", { class: "container", id: "my-div" }, [
  elem("h1", {}, "Hello, World!"),
  elem("button", { onclick: () => alert("Clicked!") }, "Click Me"),
]);

document.body.appendChild(myDiv);

2. State Management with stateManager

The stateManager provides an easy way to manage application state and listen for changes.

import { stateManager } from "baeunjs";

// Set a value
stateManager.set("user", { name: "Alice", age: 25 });

// Get a value
const user = stateManager.get("user");
console.log(user.name); // Alice

// Update a value
stateManager.update("user", (current) => ({
  ...current,
  age: current.age + 1,
}));

// Listen for changes
stateManager.onChange("user", (newUser) => {
  console.log("User updated:", newUser);
});

3. SPA Routing with hashRouter

The hashRouter enables hash-based SPA routing with no server-side configuration.

import { hashRouter, elem } from "baeunjs";

// Define routes
const routes = {
  "/": () => elem("div", {}, "Home Page"),
  "/about": () => elem("div", {}, "About Page"),
  "*": () => elem("div", {}, "404 Page Not Found"),
};

// Initialize the router
hashRouter(routes);

// Add navigation links
document.body.appendChild(
  elem("nav", {}, [
    elem("a", { href: "#/" }, "Home"),
    elem("a", { href: "#/about" }, "About"),
  ])
);

API Reference

elem(tagName, options, children)

Create a DOM element.

| Parameter | Type | Description | |--------------|-------------------------------------|--------------------------------------| | tagName | string | The name of the element tag. | | options | Record<string, any> (optional) | Attributes and event listeners. | | children | string | number | HTMLElement[] | Children elements or text content. | | Returns | HTMLElement | The created DOM element. |


stateManager

A utility for managing application state.

Methods

| Method | Description | |-------------------|-------------------------------------------------| | set(key, value) | Save a value to localStorage. | | get(key) | Retrieve a value from localStorage. | | update(key, fn) | Update a value based on the current state. | | remove(key) | Remove a specific key from localStorage. | | clear() | Clear all stored state values. | | onChange(key, callback) | Listen for changes to a specific key. |


hashRouter(routes, appId)

Create a hash-based SPA router.

| Parameter | Type | Description | |------------|-------------------------------------|---------------------------------------------------| | routes | Record<string, () => HTMLElement>| A map of routes to components. | | appId | string (optional, default: "app")| The ID of the container where components render. |

| Returns | () => void | A function to manually trigger the router. |


Example Project

Create a simple SPA using BaeunJS:

import { elem, hashRouter, stateManager } from "baeunjs";

const routes = {
  "/": () => elem("div", {}, "Welcome to Home Page!"),
  "/counter": () => {
    const count = stateManager.get("count") || 0;

    const incrementButton = elem("button", {
      onclick: () => {
        const updatedCount = stateManager.update("count", (c) => (c || 0) + 1);
        countText.textContent = `Count: ${updatedCount}`;
      },
    }, "Increment");

    const countText = elem("p", {}, `Count: ${count}`);

    return elem("div", {}, [countText, incrementButton]);
  },
  "*": () => elem("div", {}, "404 Not Found"),
};

// Initialize the router
hashRouter(routes);

License

MIT License. See LICENSE for more information.