
Research
/Security News
Critical Vulnerability in NestJS Devtools: Localhost RCE via Sandbox Escape
A flawed sandbox in @nestjs/devtools-integration lets attackers run code on your machine via CSRF, leading to full Remote Code Execution (RCE).
@wix/css-property-parser
Advanced tools
A comprehensive TypeScript library for parsing and serializing CSS property values with full MDN specification compliance
A comprehensive TypeScript library for parsing and serializing CSS property values with full MDN specification compliance.
Test all CSS property parsers live in your browser with real-time parsing and examples.
import
) and CommonJS (require
)calc()
, min()
, max()
, clamp()
, gradients, and morenpm install @wix/css-property-parser
import { Width, Height, Margin, Background, Font } from '@wix/css-property-parser';
// Parse CSS values
const width = Width.parse('calc(100% - 20px)');
const background = Background.parse('linear-gradient(45deg, red, blue)');
// Serialize back to CSS
const widthCSS = Width.toCSSValue(width); // "calc(100% - 20px)"
const bgCSS = Background.toCSSValue(background); // "linear-gradient(45deg, red, blue)"
const { Width, Height, Margin, Background, Font } = require('@wix/css-property-parser');
// Parse CSS values
const width = Width.parse('calc(100% - 20px)');
const background = Background.parse('linear-gradient(45deg, red, blue)');
// Serialize back to CSS
const widthCSS = Width.toCSSValue(width); // "calc(100% - 20px)"
const bgCSS = Background.toCSSValue(background); // "linear-gradient(45deg, red, blue)"
import {
Width, Height, Background, Font, Margin, Color, Position,
// Import types for parsed values
WidthValue, HeightValue, BackgroundValue, FontValue, MarginValue,
ColorValue, PositionValue, LengthPercentageValue,
// Import atomic types
CSSLengthValue, CSSPercentageValue, LengthValue, PercentageValue
} from '@wix/css-property-parser';
// Use types for variables
const width: WidthValue | null = Width.parse('100px');
const background: BackgroundValue | null = Background.parse('red');
const margin: MarginValue | null = Margin.parse('10px 20px');
const color: ColorValue | null = Color.parse('#ff0000');
const position: PositionValue | null = Position.parse('absolute');
// Type-safe functions
function processWidth(value: string): WidthValue | null {
return Width.parse(value);
}
function serializeFont(font: FontValue): string {
return Font.toCSSValue(font) || '';
}
// All types are available from the main package for convenience
// This includes both property value types and atomic CSS types
Note: All examples work with both ESM (
import
) and CommonJS (require
). For TypeScript type imports, see Usage section above.
import { Width, Height, Margin, Background, Font } from '@wix/css-property-parser';
// Parse CSS values with advanced features
const width = Width.parse('calc(100% - 20px)');
const height = Height.parse('50vh');
const margin = Margin.parse('10spx 20spx'); // SPX (Scalable-Pixel) support
const background = Background.parse('linear-gradient(45deg, red, blue)');
const font = Font.parse('bold 16px/1.5 "Helvetica Neue", Arial, sans-serif');
// Serialize back to CSS
const widthCSS = Width.toCSSValue(width); // "calc(100% - 20px)"
const heightCSS = Height.toCSSValue(height); // "50vh"
const marginCSS = Margin.toCSSValue(margin); // "10spx 20spx"
const bgCSS = Background.toCSSValue(background); // "linear-gradient(45deg, red, blue)"
const fontCSS = Font.toCSSValue(font); // "bold 16px/1.5 "Helvetica Neue", Arial, sans-serif"
Every property evaluator follows the same consistent API:
interface PropertyEvaluator<T> {
parse(value: string): T | null;
toCSSValue(parsed: T | null): string | null;
}
import { Width, Height, MinWidth, MaxWidth, MinHeight, MaxHeight } from '@wix/css-property-parser';
// Sizing properties support lengths, percentages, and keywords
const width = Width.parse('50%'); // { value: 50, unit: '%' }
const height = Height.parse('auto'); // { keyword: 'auto' }
const minWidth = MinWidth.parse('0'); // { value: 0, unit: 'px' }
import { Margin, Padding, Gap, ColumnGap, RowGap } from '@wix/css-property-parser';
// Shorthand properties expand to constituent parts
const margin = Margin.parse('10px 20px'); // Expands to top/right/bottom/left
const padding = Padding.parse('1em'); // Expands to all sides
const gap = Gap.parse('10px 20px'); // Row and column gaps
import { FontSize, FontWeight, FontFamily, LineHeight, LetterSpacing } from '@wix/css-property-parser';
// Font properties with comprehensive keyword support
const fontSize = FontSize.parse('1.2em'); // { type: 'length', value: 1.2, unit: 'em' }
const fontWeight = FontWeight.parse('bold'); // { type: 'keyword', keyword: 'bold' }
const fontFamily = FontFamily.parse('Arial, sans-serif'); // { type: 'font-list', families: ['Arial', 'sans-serif'] }
const lineHeight = LineHeight.parse('1.5'); // { type: 'number', value: 1.5 } (unitless)
import { Background, Border, Font, TextShadow } from '@wix/css-property-parser';
// Multi-value and shorthand properties
const background = Background.parse('url(bg.jpg) no-repeat center / cover');
const border = Border.parse('2px solid red');
const font = Font.parse('bold 16px/1.4 "Helvetica Neue", Arial, sans-serif');
const textShadow = TextShadow.parse('2px 2px 4px rgba(0,0,0,0.5)');
For parsing individual CSS data types:
import {
LengthEvaluator,
PercentageEvaluator,
Color,
AngleEvaluator,
NumberEvaluator
} from '@wix/css-property-parser';
// Parse individual CSS types
const length = LengthEvaluator.parse('10px'); // { value: 10, unit: 'px' }
const percentage = PercentageEvaluator.parse('50%'); // { value: 50, unit: '%' }
const color = Color.parse('#ff0000'); // { type: 'hex', value: 'ff0000' }
const angle = AngleEvaluator.parse('45deg'); // { value: 45, unit: 'deg' }
import { Width, CssVariable } from '@wix/css-property-parser';
// CSS variables are parsed but not resolved
const width = Width.parse('var(--main-width)');
// Returns: { CSSvariable: '--main-width' }
const widthWithFallback = Width.parse('var(--main-width, 100px)');
// Returns: { CSSvariable: '--main-width', defaultValue: '100px' }
import { Width, FontSize } from '@wix/css-property-parser';
// Calc expressions
const width = Width.parse('calc(100% - 20px)');
// Returns: { expression: '100% - 20px', function: 'calc' }
// Min/max/clamp functions
const fontSize = FontSize.parse('clamp(1rem, 2.5vw, 2rem)');
// Returns: { expression: '1rem, 2.5vw, 2rem', function: 'clamp' }
import { Background } from '@wix/css-property-parser';
const originalValue = 'linear-gradient(45deg, red 0%, blue 100%)';
const parsed = Background.parse(originalValue);
const serialized = Background.toCSSValue(parsed);
console.log(serialized === originalValue); // true
import { FontSize, Color, Margin } from '@wix/css-property-parser';
// Validate design tokens
function validateDesignToken(property: string, value: string): boolean {
switch (property) {
case 'font-size':
return FontSize.parse(value) !== null;
case 'color':
return Color.parse(value) !== null;
case 'margin':
return Margin.parse(value) !== null;
default:
return false;
}
}
import { Width, Height, Background } from '@wix/css-property-parser';
// Parse and transform CSS values
function processStyles(styles: Record<string, string>) {
const processed: Record<string, any> = {};
for (const [property, value] of Object.entries(styles)) {
switch (property) {
case 'width':
processed.width = Width.parse(value);
break;
case 'height':
processed.height = Height.parse(value);
break;
case 'background':
processed.background = Background.parse(value);
break;
}
}
return processed;
}
import { Color, Background } from '@wix/css-property-parser';
// Optimize CSS values
function optimizeColor(value: string): string {
const parsed = Color.parse(value);
if (parsed && parsed.type === 'hex') {
// Convert to shortest hex format
return Color.toCSSValue(parsed);
}
return value;
}
# Run all tests
npm test
# Run tests for specific property
npm test -- width.test.ts
# Run tests with coverage
npm test:coverage
# Watch mode for development
npm test:watch
# Install dependencies
npm install
# Build TypeScript
npm run build
# Build with watch mode
npm run build:watch
# Run development server
npm run dev
Total: 124 CSS Property Evaluators - All evaluators include full MDN compliance, comprehensive test coverage, and TypeScript type definitions.
๐ก Quick Reference: Use
{PropertyName}.parse(value)
to parse and{PropertyName}.toCSSValue(parsed)
to serialize any property below.
angle
, color
, length
, number
, percentage
, string
, time
length-percentage
, css-variable
, blend-mode
width
, height
, min-width
, max-width
, min-height
, max-height
block-size
, inline-size
, min-block-size
, max-block-size
, min-inline-size
, max-inline-size
gap
, column-gap
, row-gap
margin
(shorthand), margin-top
, margin-right
, margin-bottom
, margin-left
, margin-inline-start
, margin-inline-end
padding
(shorthand), padding-top
, padding-right
, padding-bottom
, padding-left
, padding-inline-start
, padding-inline-end
border
, border-color
, border-style
, border-width
border-radius
, border-start-start-radius
, border-start-end-radius
, border-end-start-radius
, border-end-end-radius
border-top
, border-right
, border-bottom
, border-left
border-top-color
, border-right-color
, border-bottom-color
, border-left-color
border-top-style
, border-right-style
, border-bottom-style
, border-left-style
border-top-width
, border-right-width
, border-bottom-width
, border-left-width
border-block
, border-block-start
, border-block-end
border-block-start-color
, border-block-end-color
border-block-start-style
, border-block-end-style
border-block-start-width
, border-block-end-width
border-inline
, border-inline-start
, border-inline-end
border-inline-start-color
, border-inline-end-color
border-inline-start-style
, border-inline-end-style
border-inline-start-width
, border-inline-end-width
font
(shorthand), font-family
, font-size
, font-weight
, font-style
, font-variant
, font-stretch
text-align
, text-transform
, text-decoration
, text-shadow
, text-overflow
, text-indent
line-height
, letter-spacing
white-space
, word-break
, overflow-wrap
, writing-mode
grid-template
(shorthand), grid-template-columns
, grid-template-rows
grid-area
, grid-column
, grid-row
grid-gap
(shorthand), grid-column-gap
, grid-row-gap
display
, overflow
, visibility
background
, color
, opacity
, box-shadow
object-fit
, object-position
position
, z-index
align-items
, align-self
, justify-content
, flex-direction
Shared Evaluator Pattern (8 shared): 95% code reduction through intelligent reuse
CSS Functions: Full support for calc()
, min()
, max()
, clamp()
, var()
, gradients
SPX Units: Wix Scalable-Pixel units for responsive design
Round-Trip Stability: Parse โ serialize โ parse produces identical results
Performance: Optimized parsing with minimal memory footprint
ISC License - see LICENSE file for details.
All evaluators are available as named exports from the main package. Use import { EvaluatorName } from '@wix/css-property-parser'
or const { EvaluatorName } = require('@wix/css-property-parser')
.
Export Name | CSS Property/Type | Description |
---|---|---|
AngleEvaluator | <angle> | CSS angle values (deg, rad, turn, grad) |
BlendMode | mix-blend-mode , background-blend-mode | CSS blend mode keywords |
Color | <color> | CSS color values (hex, rgb, hsl, named, etc.) |
CssVariable | var() | CSS custom properties and variables |
LengthEvaluator | <length> | CSS length values (px, em, rem, vh, etc.) |
LengthPercentage | <length-percentage> | Combined length and percentage values |
NumberEvaluator | <number> | CSS numeric values |
PercentageEvaluator | <percentage> | CSS percentage values |
Position | position | CSS position keywords (static, relative, absolute, fixed, sticky) |
StringEvaluator | <string> | CSS string values |
TimeEvaluator | <time> | CSS time values (s, ms) |
Export Name | CSS Property | Description |
---|---|---|
BlockSize | block-size | Logical block dimension |
Height | height | Element height |
InlineSize | inline-size | Logical inline dimension |
MaxBlockSize | max-block-size | Maximum logical block size |
MaxHeight | max-height | Maximum element height |
MaxInlineSize | max-inline-size | Maximum logical inline size |
MaxWidth | max-width | Maximum element width |
MinBlockSize | min-block-size | Minimum logical block size |
MinHeight | min-height | Minimum element height |
MinInlineSize | min-inline-size | Minimum logical inline size |
MinWidth | min-width | Minimum element width |
Width | width | Element width |
Export Name | CSS Property | Description |
---|---|---|
ColumnGap | column-gap | Gap between columns |
Gap | gap | Gap shorthand (row and column) |
Margin | margin | Margin shorthand (all sides) |
MarginBottom | margin-bottom | Bottom margin |
MarginInlineEnd | margin-inline-end | Logical inline end margin |
MarginInlineStart | margin-inline-start | Logical inline start margin |
MarginLeft | margin-left | Left margin |
MarginRight | margin-right | Right margin |
MarginTop | margin-top | Top margin |
Padding | padding | Padding shorthand (all sides) |
PaddingBottom | padding-bottom | Bottom padding |
PaddingInlineEnd | padding-inline-end | Logical inline end padding |
PaddingInlineStart | padding-inline-start | Logical inline start padding |
PaddingLeft | padding-left | Left padding |
PaddingRight | padding-right | Right padding |
PaddingTop | padding-top | Top padding |
RowGap | row-gap | Gap between rows |
Export Name | CSS Property | Description |
---|---|---|
Border | border | Border shorthand (all sides) |
BorderBlock | border-block | Logical block borders |
BorderBlockEnd | border-block-end | Logical block end border |
BorderBlockEndColor | border-block-end-color | Logical block end border color |
BorderBlockEndStyle | border-block-end-style | Logical block end border style |
BorderBlockEndWidth | border-block-end-width | Logical block end border width |
BorderBlockStart | border-block-start | Logical block start border |
BorderBlockStartColor | border-block-start-color | Logical block start border color |
BorderBlockStartStyle | border-block-start-style | Logical block start border style |
BorderBlockStartWidth | border-block-start-width | Logical block start border width |
BorderBottom | border-bottom | Bottom border |
BorderBottomColor | border-bottom-color | Bottom border color |
BorderBottomStyle | border-bottom-style | Bottom border style |
BorderBottomWidth | border-bottom-width | Bottom border width |
BorderColor | border-color | Border color shorthand |
BorderEndEndRadius | border-end-end-radius | Logical end-end corner radius |
BorderEndStartRadius | border-end-start-radius | Logical end-start corner radius |
BorderInline | border-inline | Logical inline borders |
BorderInlineEnd | border-inline-end | Logical inline end border |
BorderInlineEndColor | border-inline-end-color | Logical inline end border color |
BorderInlineEndStyle | border-inline-end-style | Logical inline end border style |
BorderInlineEndWidth | border-inline-end-width | Logical inline end border width |
BorderInlineStart | border-inline-start | Logical inline start border |
BorderInlineStartColor | border-inline-start-color | Logical inline start border color |
BorderInlineStartStyle | border-inline-start-style | Logical inline start border style |
BorderInlineStartWidth | border-inline-start-width | Logical inline start border width |
BorderLeft | border-left | Left border |
BorderLeftColor | border-left-color | Left border color |
BorderLeftStyle | border-left-style | Left border style |
BorderLeftWidth | border-left-width | Left border width |
BorderRadius | border-radius | Border radius shorthand |
BorderRight | border-right | Right border |
BorderRightColor | border-right-color | Right border color |
BorderRightStyle | border-right-style | Right border style |
BorderRightWidth | border-right-width | Right border width |
BorderStartEndRadius | border-start-end-radius | Logical start-end corner radius |
BorderStartStartRadius | border-start-start-radius | Logical start-start corner radius |
BorderStyle | border-style | Border style shorthand |
BorderTop | border-top | Top border |
BorderTopColor | border-top-color | Top border color |
BorderTopStyle | border-top-style | Top border style |
BorderTopWidth | border-top-width | Top border width |
BorderWidth | border-width | Border width shorthand |
Export Name | CSS Property | Description |
---|---|---|
Font | font | Font shorthand (family, size, weight, style, etc.) |
FontFamily | font-family | Font family stack |
FontSize | font-size | Font size |
FontStretch | font-stretch | Font stretch/width |
FontStyle | font-style | Font style (normal, italic, oblique) |
FontVariant | font-variant | Font variant settings |
FontWeight | font-weight | Font weight (normal, bold, 100-900) |
LetterSpacing | letter-spacing | Spacing between characters |
LineHeight | line-height | Line height/leading |
TextAlign | text-align | Text alignment |
TextDecoration | text-decoration | Text decoration (underline, strikethrough, etc.) |
TextIndent | text-indent | First-line text indentation |
TextOverflow | text-overflow | Text overflow behavior |
TextShadow | text-shadow | Text shadow effects |
TextTransform | text-transform | Text case transformation |
WhiteSpace | white-space | Whitespace handling |
WordBreak | word-break | Word breaking behavior |
WritingMode | writing-mode | Text writing direction |
Export Name | CSS Property | Description |
---|---|---|
Display | display | Display type (block, inline, flex, grid, etc.) |
GridArea | grid-area | Grid area placement |
GridColumn | grid-column | Grid column placement |
GridColumnGap | grid-column-gap | Gap between grid columns |
GridGap | grid-gap | Grid gap shorthand |
GridRow | grid-row | Grid row placement |
GridRowGap | grid-row-gap | Gap between grid rows |
GridTemplate | grid-template | Grid template shorthand |
GridTemplateColumns | grid-template-columns | Grid column track definitions |
GridTemplateRows | grid-template-rows | Grid row track definitions |
Overflow | overflow | Content overflow behavior |
OverflowWrap | overflow-wrap | Long word wrapping behavior |
Export Name | CSS Property | Description |
---|---|---|
Background | background | Background shorthand (image, color, position, etc.) |
BoxShadow | box-shadow | Box shadow effects |
ObjectFit | object-fit | Object fitting behavior |
ObjectPosition | object-position | Object positioning |
Opacity | opacity | Element opacity/transparency |
Visibility | visibility | Element visibility |
ZIndex | z-index | Stacking order |
Export Name | CSS Property | Description |
---|---|---|
AlignItems | align-items | Cross-axis alignment |
AlignSelf | align-self | Individual item cross-axis alignment |
FlexDirection | flex-direction | Flex container direction |
JustifyContent | justify-content | Main-axis alignment |
Total: 124 Evaluator Exports - All evaluators follow the same API pattern: parse(value: string)
and toCSSValue(parsed)
with full TypeScript support.
FAQs
A comprehensive TypeScript library for parsing and serializing CSS property values with full MDN specification compliance
The npm package @wix/css-property-parser receives a total of 189 weekly downloads. As such, @wix/css-property-parser popularity was classified as not popular.
We found that @wix/css-property-parser demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago.ย It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
/Security News
A flawed sandbox in @nestjs/devtools-integration lets attackers run code on your machine via CSRF, leading to full Remote Code Execution (RCE).
Product
Customize license detection with Socketโs new license overlays: gain control, reduce noise, and handle edge cases with precision.
Product
Socket now supports Rust and Cargo, offering package search for all users and experimental SBOM generation for enterprise projects.