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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@sarawebs/sb-utils

v2.0.0

Published

SaraWebs utility functions for web apps and tools

Readme

📦 @sarawebs/sb-utils

A lightweight and reusable utility library from SaraWebs, designed to simplify common frontend tasks like ID generation, dynamic color selection, board creation, and copyright injection.

Useful for internal projects, small web apps, or client dashboards where you want to avoid repetitive code.


✨ Features

  • 🔑 ID Generation Generate prefixed, short unique IDs using crypto.randomUUID().

  • 🖍️ Random Color Picker Select a color from a custom palette or fallback to random HEX.

  • 🎲 2D Board Generator Quickly generate grid-like structures using a callback on each cell.

  • ©️ Dynamic Footer Injection Append a styled copyright notice with your company name and site.


📚 API Reference

import { sb_utils } from '@sarawebs/sb-utils';

// or
import { generateID, getRandomColor, createBoard, addCopyRight } from '@sarawebs/sb-utils';

generateID(prefix?: string): string

Generates a short unique ID (8 characters) with optional prefix. Example:

generateID('todo'); // => 'todo-1a2b3c4d'

getRandomColor(palette?: string[]): string

Returns a random HEX color string.

  • Provide a custom palette array to choose from specific colors.
  • If palette is empty or missing, generates a random hex color.

Example:

getRandomColor(['#ff0000', '#00ff00']); // => '#00ff00'
getRandomColor(); // => '#a1b2c3'

createBoard(rows: number, cols: number, pushFunc: (row, i, j) => void): Array<Array<any>>

Creates a 2D array board with rows and columns, applying pushFunc on each cell.

Example:

const board = createBoard(3, 3, (row, i, j) => {
  row.push({ x: i, y: j });
});

addCopyRight(title?: string)

Appends a styled footer element to the <footer> tag in the DOM.

Example:

addCopyRight('My Dashboard');

🧱 Element Builder

Chainable wrapper for document.createElement that simplifies creating and manipulating DOM elements programmatically.

Useful when you want to avoid manually writing verbose DOM code in dynamic UIs or component builders.

ElementBuilder

new ElementBuilder(tagName)
  .addClass('my-class')
  .setId('element-id')
  .setAttr('data-role', 'item')
  .setText('Click Me')
  .on('click', () => alert('clicked'))
  .append(new ElementBuilder('span').setText('🔔'))
  .build();
Available Methods:

| Method | Description | | ---------------------- | -------------------------------------------------------- | | addClass(...classes) | Adds one or more CSS classes. | | setId(id) | Sets the element's id. | | setText(text) | Sets the element's text content. | | setAttr(name, value) | Sets an attribute. | | on(event, handler) | Attaches an event listener. | | append(child) | Appends a child (also works with other ElementBuilders). | | build() | Returns the final DOM element. |


labelAndInput({ labelText, inputType, id, name, required }): [label, input]

Helper function that returns a <label> and <input> pair as ElementBuilder instances. Great for building forms dynamically.

const [label, input] = labelAndInput({
  labelText: 'Email',
  inputType: 'email',
  id: 'email',
  name: 'email',
  required: true
});

document.body.append(label.build(), input.build());

🌐 Website

Made with ❤️ by SaraWebs


🛠️ Use Cases

  • Internal admin panels
  • Static sites or dashboards
  • Quickly prototyping UI logic
  • Form builders and dynamic DOM components

See the full Changelog for version history.