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

@ts0/style

v0.1.0-beta.0

Published

Safe inline CSS validation and serialization for untrusted styles.

Readme

@ts0/style

Beta. Until v1 a release can break the previous one, with no migration path.

Validate inline CSS and serialize it to a style attribute. The package has zero runtime dependencies and works in the browser, on the server, and in Edge runtimes.

Install with pnpm add @ts0/[email protected].

Vanilla JavaScript

import { styleAttribute } from "@ts0/style"

/** @param {Pick<HTMLElement, "setAttribute">} element */
function paintPreview(element) {
  const style = styleAttribute({ backgroundColor: "tomato", width: 120 })
  if (style) {
    element.setAttribute("style", style)
  }
}

export { paintPreview }

React

sanitizeStyle returns a frozen map with canonical CSS property names. Map those names to the React style props your component uses. The same mapping works in a host component registered with @ts0/react.

import { sanitizeStyle, type StyleDeclarations } from "@ts0/style"

function Preview({ authored }: { authored: string | StyleDeclarations }) {
  const css = sanitizeStyle(authored)
  const background = css?.["background-color"]
  return (
    <div
      style={{
        backgroundColor:
          typeof background === "string" ? background : undefined,
        width: css?.width ?? undefined,
      }}
    />
  )
}

export { Preview }

Policies and limits

Styles are declaration maps with one value per canonical property. Standard property names normalize to lowercase kebab case. Custom properties keep their case. CSS strings reject duplicate canonical names, including aliases such as backgroundColor and background-color. Map aliases resolve in enumeration order, with the last value kept. Supply a single declaration per property when you need the map to convey your intent regardless of key order.

The default policy accepts property names from Webref and CSS custom properties. Resource-capable properties and custom properties accept plain values without quotes or functions. All declarations reject resource URLs, escapes, comments, control characters, and unbalanced delimiters. A custom policy receives validated declarations and can keep, rewrite, or omit them. Both the input and the returned declarations must pass the same safety checks.

import { styleAttribute, type StylePolicy } from "@ts0/style"

const colorOnly: StylePolicy = (declarations) => ({
  color: declarations.color ?? null,
})

const style = styleAttribute("color: red; width: 10px", {
  policy: colorOnly,
  maxDeclarations: 8,
  maxLength: 256,
})

export { style }

sanitizeStyle and defaultStylePolicy return declarations or null. formatStyle serializes declarations with structural validation and adds px to nonzero numbers for dimensional properties. styleAttribute combines sanitization and formatting. Empty styles serialize to undefined. Invalid inputs throw StyleError with a code. The default ceilings are 128 declarations and 16,384 characters. Options can lower either ceiling.

Run pnpm style:sync in this package to regenerate the property lists from its pinned Webref dataset.

See style policy by package for the DOM, React, and UI SDK contracts.