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

@ninna-ui/utils

v0.4.1

Published

Shared utility functions for Ninna UI — cn (class merging), composeRefs, createContext, keyboard constants, and SSR helpers.

Readme

@ninna-ui/utils

Shared utility functions for the Ninna-UI design system — class merging, ref composition, type-safe context, and SSR helpers.

License: MIT

Shared utility functions used across all Ninna UI component packages. Core utilities (cn, KEYS, canUseDOM) are pure functions with no React dependency. React-aware utilities (createContext, composeRefs) use React as an optional peer dependency.

Installation

pnpm add @ninna-ui/utils

Exports

cn(...inputs) — Class Name Merger

Combines Tailwind CSS classes with intelligent conflict resolution. Built on clsx + tailwind-merge.

import { cn } from '@ninna-ui/utils';

cn('px-4 py-2', 'px-6');              // "py-2 px-6" — px-4 overridden
cn('text-red-500', false && 'hidden'); // "text-red-500"
cn('rounded-md', undefined, 'p-4');    // "rounded-md p-4"

composeRefs(...refs) — Ref Composition

Combines multiple React refs into a single ref callback. Essential for forwardRef components that also use internal refs.

import { composeRefs } from '@ninna-ui/utils';

const Component = forwardRef((props, forwardedRef) => {
  const internalRef = useRef(null);
  return <div ref={composeRefs(forwardedRef, internalRef)} />;
});

composeEventHandlers(external, internal) — Event Handler Composition

Chains event handlers so both external (user-provided) and internal handlers run. Respects event.preventDefault().

import { composeEventHandlers } from '@ninna-ui/utils';

<button onClick={composeEventHandlers(props.onClick, handleInternalClick)} />

createContext(name) — Type-Safe Context

Creates a React context with a required provider. Throws a helpful error if consumed outside its provider.

import { createContext } from '@ninna-ui/utils';

const [FormProvider, useFormContext] = createContext<FormContextValue>('FormControl');

KEYS — Keyboard Constants

Standard keyboard key constants for accessible event handling:

import { KEYS } from '@ninna-ui/utils';

KEYS.ENTER      // "Enter"
KEYS.ESCAPE     // "Escape"
KEYS.SPACE      // " "
KEYS.ARROW_UP   // "ArrowUp"
KEYS.ARROW_DOWN // "ArrowDown"
KEYS.TAB        // "Tab"

canUseDOM / getOwnerWindow — SSR Safety

Runtime checks for safe DOM access in server-side rendering contexts:

import { canUseDOM, getOwnerWindow } from '@ninna-ui/utils';

if (canUseDOM) {
  // Safe to access window, document
}

const win = getOwnerWindow(element); // Get the owner window of a DOM element

Architecture Rules

  • React is optionalcn, KEYS, canUseDOM are pure; createContext and composeRefs require React
  • No DOM APIs — Must work in SSR contexts (canUseDOM is a check, not a usage)
  • No @ninna-ui/* imports — This is a leaf dependency
  • No side effects — All functions are pure

Related Packages

License

MIT