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

@seanchas116/cssvalue

v0.0.5

Published

A CSS value parser / serializer

Downloads

111

Readme

@seanchas116/cssvalue

npm version License: MIT

A TypeScript library for parsing and serializing CSS property values with strong typing support.

🎨 Try the Interactive Demo →

Features

  • Parse CSS values into strongly-typed JavaScript objects
  • Serialize back to CSS with toString() methods
  • Full TypeScript support with comprehensive type definitions
  • CSS spec compliant parsing following official CSS specifications
  • Bidirectional transformation - parse and serialize without data loss

Installation

Using npm/yarn/pnpm

npm install @seanchas116/cssvalue
# or
yarn add @seanchas116/cssvalue
# or
pnpm add @seanchas116/cssvalue

Supported CSS Properties

  • Background - Full support for complex background values including layers, gradients, and images
  • Border - Parse border shorthand and individual border properties
  • Box Shadow - Support for multiple shadows with blur, spread, and inset
  • Colors - HEX, RGB, RGBA, HSL, HSLA, OKLCH, and CSS Color Module Level 5 color spaces
  • Dimensions - Lengths, percentages, and calc() expressions
  • Font Family - Parse font family lists with proper quoting
  • Gradients - Linear and radial gradients with color stops
  • Position - CSS position values with keywords and offsets
  • URLs - Parse url() functions with proper escaping

Usage

Basic Example

import {
  cssParser,
  Background,
  BackgroundLayer,
  URL,
  Position,
  Dimension,
  HexColor,
} from "@seanchas116/cssvalue";

// Parse a complex background value
const background = cssParser.background.tryParse(
  'center / contain no-repeat url("foo.svg"), #eee 35% url("bar.png")',
);

// Work with strongly-typed objects
const expected = new Background({
  layers: [
    new BackgroundLayer({
      position: new Position("center", "center"),
      size: "contain",
      repeatStyle: ["no-repeat"],
      image: new URL("foo.svg"),
    }),
    new BackgroundLayer({
      position: new Position(
        { from: "left", offset: new Dimension(35, "%") },
        "center",
      ),
      image: new URL("bar.png"),
    }),
  ],
  color: new HexColor("#eee"),
});

// Serialize back to CSS
background.toString(); // => 'center / contain no-repeat url("foo.svg"), #eee 35% url("bar.png")'

Parsing Colors

import {
  cssParser,
  RGBColor,
  HSLColor,
  OKLCHColor,
} from "@seanchas116/cssvalue";

// Parse different color formats
const rgb = cssParser.color.tryParse("rgb(255 128 0 / 0.5)");
const hsl = cssParser.color.tryParse("hsl(210deg 50% 40%)");
const oklch = cssParser.color.tryParse("oklch(0.7 0.2 150)");

// Create colors programmatically
const color = new RGBColor({ r: 1, g: 0.5, b: 0, a: 0.5 });
color.toString(); // => "rgba(255,128,0,0.5)"

Working with Gradients

import { cssParser, LinearGradient, HexColor } from "@seanchas116/cssvalue";

const gradient = cssParser.gradient.tryParse(
  "linear-gradient(45deg, red 0%, blue 50%, green 100%)",
);

// Modify gradient stops
gradient.stops[0].color = new HexColor("#ff0000");
gradient.toString(); // => "linear-gradient(45deg, #ff0000 0%, blue 50%, green 100%)"

Box Shadows

import {
  cssParser,
  BoxShadow,
  Dimension,
  RGBColor,
} from "@seanchas116/cssvalue";

const shadows = cssParser.boxShadow.tryParse(
  "0 4px 6px rgba(0, 0, 0, 0.1), inset 0 2px 4px #00000020",
);

// Create shadows programmatically
const shadow = new BoxShadow({
  offsetX: new Dimension(0, "px"),
  offsetY: new Dimension(4, "px"),
  blurRadius: new Dimension(6, "px"),
  color: new RGBColor({ r: 0, g: 0, b: 0, a: 0.1 }),
});

API Reference

Parser Methods

All parsers are available through the cssParser object:

  • cssParser.background.tryParse(value: string) - Parse CSS background
  • cssParser.border.tryParse(value: string) - Parse CSS border
  • cssParser.boxShadow.tryParse(value: string) - Parse CSS box-shadow
  • cssParser.color.tryParse(value: string) - Parse CSS color
  • cssParser.dimension.tryParse(value: string) - Parse CSS dimension
  • cssParser.gradient.tryParse(value: string) - Parse CSS gradient
  • cssParser.fontFamily.tryParse(value: string) - Parse CSS font-family
  • cssParser.position.tryParse(value: string) - Parse CSS position

Type Classes

Each CSS value type is represented by a class with a toString() method:

  • Background, BackgroundLayer - Background properties
  • Border, BorderStyle - Border properties
  • BoxShadow - Box shadow effects
  • Color, HexColor, RGBColor, HSLColor, OKLCHColor - Color values
  • Dimension - Length and percentage values
  • LinearGradient, RadialGradient - Gradient functions
  • Position - Position values
  • URL - URL references

Development

This project uses PNPM workspaces and Turbo for monorepo management.

Prerequisites

  • Node.js 18+
  • PNPM 8+

Setup

# Install dependencies
pnpm install

# Run tests for all packages
pnpm test

# Run tests for a specific package
pnpm --filter @seanchas116/cssvalue test

# Run linter
pnpm lint

# Build all packages
pnpm build

# Build a specific package
pnpm --filter @seanchas116/cssvalue build

Interactive Demo

Try the live demo at cssvalue.vercel.app or run it locally:

# Start the demo development server
pnpm --filter demo dev

# Open http://localhost:5173 in your browser

The demo provides:

  • Live parsing of CSS values as you type
  • Support for all parser types (background, border, color, gradients, etc.)
  • Pretty-printed output showing the parsed JavaScript objects
  • Instant feedback on parsing errors

Project Structure

.
├── packages/
│   ├── cssvalue/        # Main CSS value parsing library
│   └── demo/            # Interactive web demo (React + Vite)
├── pnpm-workspace.yaml  # PNPM workspace configuration
├── turbo.json          # Turbo build configuration
└── README.md           # This file

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

MIT - See LICENSE file for details

Author

Ryohei Ikegami (@seanchas116)