cssfmt

package
v1.5.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 10, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package cssfmt provides CSS formatting, minification, and validation.

Package cssfmt provides CSS formatting, minification, validation, and parsing. It supports configurable indentation, property sorting, rule sorting, and comment removal.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Format

func Format(input string, opts ...Option) string

Format formats CSS input with proper indentation.

func Minify

func Minify(input string) string

Minify removes unnecessary whitespace from CSS.

func RemoveComments

func RemoveComments(input string) string

RemoveComments removes CSS comments from input.

Types

type Declaration

type Declaration struct {
	Property string
	Value    string
}

Declaration represents a CSS property: value pair.

func ParseDeclarations

func ParseDeclarations(input string) []Declaration

ParseDeclarations parses CSS declarations from a string.

type Option

type Option func(*Options)

Option is a functional option for Format.

func WithIndent

func WithIndent(indent string) Option

WithIndent sets the indentation string.

func WithSortProps

func WithSortProps() Option

WithSortProps enables alphabetical property sorting.

func WithSortRules

func WithSortRules() Option

WithSortRules enables alphabetical selector sorting.

type Options

type Options struct {
	Indent    string // Indentation (default: "  ")
	SortProps bool   // Sort properties alphabetically
	SortRules bool   // Sort selectors alphabetically
}

Options configures the CSS formatter.

type Rule

type Rule struct {
	Selector     string
	Declarations []Declaration
	IsAtRule     bool
	AtRuleBody   string
}

Rule represents a CSS rule (selector + declarations).

func Parse

func Parse(input string) []Rule

Parse parses CSS input into rules.

type ValidateResult

type ValidateResult struct {
	Valid   bool   `json:"valid"`
	Error   string `json:"error,omitempty"`
	Message string `json:"message,omitempty"`
}

ValidateResult represents CSS validation output.

func Validate

func Validate(input string) ValidateResult

Validate performs basic CSS syntax validation.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL