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

@swiss-ui/utils

v0.1.0

Published

JavaScript/TypeScript utilities for Swiss UI design system

Readme

@swiss-ui/utils

JavaScript/TypeScript utilities for Swiss UI design system.

Installation

npm install @swiss-ui/utils

Modules

cn — Class name merging

Merges CSS class names with support for strings, conditional objects, arrays, and falsy values.

import { cn } from '@swiss-ui/utils/cn'

cn('btn', 'btn--primary')
// 'btn btn--primary'

cn('btn', { 'btn--active': isActive, 'btn--disabled': false })
// 'btn btn--active'  (if isActive is true)

cn('btn', ['btn--sm', undefined, false])
// 'btn btn--sm'

tokens — CSS Custom Properties helpers

Read, write, and generate overrides for design tokens.

import { getCssVar, setCssVar, createThemeVars } from '@swiss-ui/utils/tokens'
import type { SwissToken } from '@swiss-ui/utils/tokens'

// Read computed value at runtime
const primary = getCssVar('--color-text-primary')

// Set on :root
setCssVar('--color-background-primary', '#ffffff')

// Set on a specific element
setCssVar('--color-text-primary', '#000000', myElement)

// Generate inline styles for token overrides
const style = createThemeVars({
  '--color-text-primary': '#1a1a1a',
  '--color-background-primary': '#f5f5f5',
})
// Use as: <div style={style}>...</div>

variants — Component variant resolver

CVA-inspired helper for building type-safe component variants. No dependencies.

import { swiss } from '@swiss-ui/utils/variants'

const button = swiss({
  base: 'swiss-button',
  variants: {
    size: {
      sm: 'swiss-button--sm',
      md: 'swiss-button--md',
      lg: 'swiss-button--lg',
    },
    variant: {
      primary: 'swiss-button--primary',
      ghost: 'swiss-button--ghost',
    },
  },
  compoundVariants: [
    { size: 'sm', variant: 'ghost', class: 'swiss-button--sm-ghost' },
  ],
  defaultVariants: { size: 'md', variant: 'primary' },
})

button()                              // 'swiss-button swiss-button--md swiss-button--primary'
button({ size: 'sm' })               // 'swiss-button swiss-button--sm swiss-button--primary'
button({ size: 'sm', variant: 'ghost' }) // includes 'swiss-button--sm-ghost'

responsive — Breakpoint utilities

Framework-agnostic media query helpers. SSR-safe.

import {
  createMediaQuery,
  matchesBreakpoint,
  onBreakpointChange,
} from '@swiss-ui/utils/responsive'
import type { SwissBreakpoint } from '@swiss-ui/utils/responsive'

// Get a media query string
createMediaQuery('md') // '(min-width: 768px)'

// Synchronous viewport check
if (matchesBreakpoint('lg')) {
  // desktop layout
}

// Subscribe to breakpoint changes
const unsubscribe = onBreakpointChange('md', (matches) => {
  console.log('md breakpoint active:', matches)
})

// Later:
unsubscribe()

Available breakpoints: sm (640px), md (768px), lg (1024px), xl (1280px), 2xl (1536px).

a11y — Accessibility utilities

import {
  generateId,
  getFocusableElements,
  focusTrap,
  isReducedMotion,
} from '@swiss-ui/utils/a11y'

// Generate unique IDs for aria attributes
const labelId = generateId('dialog')  // 'dialog-1'
const descId = generateId()           // 'swiss-2'

// Get all focusable elements inside a container
const focusable = getFocusableElements(modalElement)

// Trap focus inside a modal
const trap = focusTrap(modalElement)
trap.activate()   // moves focus to first focusable element
trap.deactivate() // returns focus to previously focused element

// Respect user motion preferences
if (!isReducedMotion()) {
  startAnimation()
}

dom — DOM helpers

import { setDataTheme, getDataTheme, toggleDataTheme } from '@swiss-ui/utils/dom'

// Set theme
setDataTheme('dark')             // sets data-theme="dark" on :root
setDataTheme('light', myElement) // sets on a specific element

// Read current theme
getDataTheme()         // 'dark' | 'light' | null
getDataTheme(myElement)

// Toggle theme
const newTheme = toggleDataTheme()  // returns 'light' | 'dark'

Tree-shaking

Each module is a separate entry point. Import only what you use:

import { cn } from '@swiss-ui/utils/cn'
import { swiss } from '@swiss-ui/utils/variants'
import { getCssVar } from '@swiss-ui/utils/tokens'

Or import everything from the main entry (bundlers will tree-shake unused exports):

import { cn, swiss, getCssVar } from '@swiss-ui/utils'

License

AGPL-3.0-only