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

@degreesign/ui

v1.0.8

Published

DegreeSign UI Controls

Readme

DegreeSign UI functions

A lightweight TypeScript library for managing UI elements in web applications.

Setup

Install the package via npm:

npm install @degreesign/ui

OR use in browsers through CDN

<script src="https://cdn.jsdelivr.net/npm/@degreesign/[email protected]/dist/browser/degreesign.min.js"></script>

Usage

Import the functions from the @degreesign/ui package in your TypeScript or JavaScript project:

import { selectElement, selectAll, showElement, hideElement, repeatElements } from '@degreesign/ui';

Below are the available functions and their usage examples.

Functions

selectElement(id: string, parent?: Element) => HTMLElement

Selects a single DOM element by its CSS selector, optionally within a parent element.

Parameters:

  • id: The CSS selector (e.g., #myId, .myClass) of the element to select.
  • parent (optional): The parent element to search within. Defaults to document.

Returns: An HTMLElement.

Example:

// Select an element by ID
const myDiv = selectElement('#myDiv');
myDiv.textContent = 'Hello, World!';

// Select an element within a specific parent
const parent = selectElement('.container');
const child = selectElement('.child', parent);
child.style.color = 'blue';

selectAll(id: string, parent?: Element) => NodeListOf<Element>

Selects all DOM elements matching a CSS selector, optionally within a parent element.

Parameters:

  • id: The CSS selector (e.g., .myClass, div) to select elements.
  • parent (optional): The parent element to search within. Defaults to document.

Returns: A NodeListOf<Element>.

Example:

// Select all elements with a class
const items = selectAll('.item');
items.forEach(item => item.style.backgroundColor = 'lightgray');

// Select all divs within a parent
const parent = selectElement('#parent');
const divs = selectAll('div', parent);
divs.forEach(div => div.classList.add('highlight'));

showElement(element: HTMLElement) => void

Sets an element's display style to flex, making it visible.

Parameters:

  • element: The HTMLElement to show.

Example:

const myDiv = selectElement('#myDiv');
showElement(myDiv); // Displays the element with flex layout

hideElement(element: HTMLElement) => void

Sets an element's display style to none, hiding it.

Parameters:

  • element: The HTMLElement to hide.

Example:

const myDiv = selectElement('#myDiv');
hideElement(myDiv); // Hides the element

repeatElements({ children?: NodeListOf<Element>, parent: Element, targetCount: number }) => void

Repeats or removes child elements within a parent to match a target count by cloning or removing the first child.

Parameters:

  • children (optional): A NodeListOf<Element> containing the child elements to repeat or remove.
  • parent: The parent Element where children will be added or removed.
  • targetCount: The desired number of child elements.

Example:

// HTML structure:
// <div id="parent">
//   <div class="child">Item</div>
// </div>

// Repeat child elements to a total of 5
const parent = selectElement('#parent');
const children = selectAll('.child', parent);
repeatElements({ parent, children, targetCount: 5 });
// Result: 5 child divs inside #parent

// Reduce to 2 child elements
repeatElements({ parent, children: selectAll('.child', parent), targetCount: 2 });
// Result: 2 child divs inside #parent

Error Handling

The repeatElements function includes error handling to catch and log issues when manipulating elements. For example, if the children NodeList is invalid or cloning fails, an error will be logged to the console.

Contributing

Contributions are welcome! Please open an issue or submit a pull request at https://github.com/DegreeSign/ds_ui.

License

This project is licensed under the MIT License. See the LICENSE file for details.