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

@wolf-tui/css-parser

v1.3.5

Published

CSS/SCSS/Less/Stylus parser and code generator for wolfie

Readme

@wolf-tui/css-parser

CSS/SCSS/LESS/Stylus parser and code generator for wolf-tui.

Overview

This package transforms CSS files into JavaScript objects compatible with wolf-tui's styling system. It handles:

  • Parsing — CSS to style objects
  • Preprocessing — SCSS, LESS, Stylus compilation
  • Tailwind CSS — JIT compilation with OKLCH shim
  • Code generation — JavaScript/TypeScript output

Note: This is an internal package. Most users should use @wolf-tui/plugin which wraps this functionality.

CLI Usage

# Parse a CSS file
wolf-css input.css -o output.js

# Parse SCSS
wolf-css styles.scss -o output.js

# With options
wolf-css input.css -o output.js --mode module --camelCase

CLI Options

| Option | Description | | -------------- | -------------------------------------- | | -o, --output | Output file path | | --mode | 'module' (CSS Modules) or 'global' | | --camelCase | Convert class names to camelCase | | --minify | Minify output |


Programmatic API

Parsing

parseCSS(css, options?)

Parse CSS string to style objects.

import { parseCSS } from '@wolf-tui/css-parser'

const styles = parseCSS(`
  .container {
    flex-direction: column;
    padding: 1rem;
  }
  .title {
    color: green;
    font-weight: bold;
  }
`)

// Result:
// {
//   container: { flexDirection: 'column', padding: 4 },
//   title: { color: 'green', fontWeight: 'bold' }
// }

Options

interface CSSParserOptions {
	/** Source filename (for error messages) */
	filename?: string
	/** Convert class names to camelCase */
	camelCaseClasses?: boolean
}

parse(css)

Low-level CSS parser. Returns AST.

import { parse } from '@wolf-tui/css-parser'

const ast = parse('.box { color: red; }')

parseRule(rule)

Parse a single CSS rule.

import { parseRule } from '@wolf-tui/css-parser'

const style = parseRule('flex-direction: column; padding: 1rem;')
// { flexDirection: 'column', padding: 4 }

Preprocessing

compile(css, lang, filename?)

Compile CSS/SCSS/LESS/Stylus to plain CSS.

import { compile } from '@wolf-tui/css-parser'

const result = await compile(scssCode, 'scss', 'styles.scss')
console.log(result.css)

detectLanguage(filename)

Detect preprocessor from file extension.

import { detectLanguage } from '@wolf-tui/css-parser'

detectLanguage('styles.scss') // 'scss'
detectLanguage('styles.less') // 'less'
detectLanguage('styles.styl') // 'stylus'
detectLanguage('styles.css') // 'css'

compileScss(code, options?)

Compile SCSS specifically.

import { compileScss } from '@wolf-tui/css-parser'

const result = await compileScss(`
  $primary: green;
  .title { color: $primary; }
`)

compileLess(code, options?)

Compile LESS specifically.

compileStylus(code, options?)

Compile Stylus specifically.


Tailwind CSS

tailwind.compile(candidates, options?)

Compile Tailwind utilities.

import { tailwind } from '@wolf-tui/css-parser'

const css = await tailwind.compile(['flex-col', 'p-4', 'text-green-500'])

The Tailwind integration includes a custom OKLCH shim that enables native OKLCH color support. This polyfill intercepts Tailwind's color output and converts OKLCH colors to sRGB hex values compatible with terminal rendering.


Code Generation

generateJavaScript(styles, options?)

Generate JavaScript code from parsed styles.

import { parseCSS, generateJavaScript } from '@wolf-tui/css-parser'

const styles = parseCSS('.box { padding: 1rem; }')
const js = generateJavaScript(styles, {
	mode: 'module',
	camelCaseClasses: true,
})

// Output:
// export default {
//   box: { padding: 4 }
// }

Options

interface CodeGeneratorOptions {
	/** 'module' for CSS Modules, 'global' for registerStyles() */
	mode?: 'module' | 'global'
	/** Convert class names to camelCase */
	camelCaseClasses?: boolean
	/** Tailwind metadata for JIT */
	metadata?: TailwindMetadata
	/** Target framework */
	framework?: 'react' | 'vue' | 'angular'
}

generateTypeScript(styles, options?)

Generate TypeScript with type declarations.


Property Mapping

mapPropertyName(cssProperty)

Map CSS property to wolf-tui property.

import { mapPropertyName } from '@wolf-tui/css-parser'

mapPropertyName('flex-direction') // 'flexDirection'
mapPropertyName('padding-left') // 'paddingLeft'

isValidProperty(property)

Check if property is supported.

import { isValidProperty } from '@wolf-tui/css-parser'

isValidProperty('flex-direction') // true
isValidProperty('box-shadow') // false

Value Parsing

parseNumeric(value)

Parse numeric CSS value to terminal cells.

import { parseNumeric } from '@wolf-tui/css-parser'

parseNumeric('1rem') // 4
parseNumeric('8px') // 2
parseNumeric('2ch') // 2
parseNumeric('50%') // '50%' (preserved)
parseNumeric('50vw') // '50vw' (preserved)

Unit Conversions

| Unit | Conversion | | ------ | --------------------------------- | | px | value / 4 | | rem | value × 4 (1rem = 16px = 4 cells) | | em | Same as rem | | ch | 1:1 (character width) | | pt | (value × 1.333) / 4 | | pc | value × 4 | | in | value × 24 | | cm | (value × 37.8) / 4 | | mm | (value × 3.78) / 4 | | % | Preserved as string | | vw | Preserved as string | | vh | Preserved as string | | vmin | Preserved as string | | vmax | Preserved as string |

parseColor(value)

Parse CSS color to terminal-compatible format.

import { parseColor } from '@wolf-tui/css-parser'

parseColor('red') // 'red'
parseColor('#ff0000') // '#ff0000'
parseColor('rgb(255, 0, 0)') // '#ff0000'
parseColor('oklch(0.7 0.15 30)') // '#...' (converted to hex)

Supported formats:

  • Named colors (140+ CSS colors → ANSI mapping)
  • Hex: #fff, #ffffff
  • RGB: rgb(255, 0, 0), rgb(255 0 0 / 0.5)
  • RGBA: rgba(255, 0, 0, 0.5)
  • HSL: hsl(0, 100%, 50%)
  • OKLCH: oklch(0.7 0.15 30) (via colorjs.io)
  • LAB, LCH: Converted to sRGB hex

parseBorderStyle(value)

Parse border-style to cli-boxes style.

import { parseBorderStyle } from '@wolf-tui/css-parser'

parseBorderStyle('solid') // 'single'
parseBorderStyle('double') // 'double'
parseBorderStyle('dashed') // 'classic'
parseBorderStyle('dotted') // 'classic'

Utilities

scanCandidates(code)

Scan code for Tailwind class candidates.

import { scanCandidates } from '@wolf-tui/css-parser'

const candidates = scanCandidates(`
  <div class="flex-col p-4 text-green-500">
`)
// ['flex-col', 'p-4', 'text-green-500']

inlineStyles(styles, className)

Inline styles directly into JSX props.

import { inlineStyles } from '@wolf-tui/css-parser'

const inlined = inlineStyles(parsedStyles, 'container')
// { flexDirection: 'column', padding: 4 }

Types

ParsedStyles

Map of class names to style objects.

type ParsedStyles = Record<string, Record<string, unknown>>

PreprocessorType

type PreprocessorType = 'css' | 'scss' | 'sass' | 'less' | 'stylus'

PreprocessorResult

interface PreprocessorResult {
	css: string
	metadata?: TailwindMetadata
	watchFiles?: string[]
}

Integration with @wolf-tui/plugin

The plugin uses this package internally:

// @wolf-tui/plugin internals
import {
	compile,
	detectLanguage,
	parseCSS,
	generateJavaScript,
} from '@wolf-tui/css-parser'

async function transform(code, id) {
	const lang = detectLanguage(id)
	const compiled = await compile(code, lang, id)
	const styles = parseCSS(compiled.css)
	return generateJavaScript(styles, { mode: 'module' })
}

Supported Properties

See @wolf-tui/plugin README for the full list of supported CSS properties.

License

MIT