Registry / serialization / css-gradient-parser

css-gradient-parser

JSON →
library0.0.18jsnpmunverified

css-gradient-parser is a JavaScript/TypeScript library designed to parse CSS gradient strings, specifically developed to extend gradient feature support within the Vercel Satori library. Currently at version 0.0.18, it provides distinct functions for parsing linear, radial, and conic gradients, including their `repeating` variations. As a pre-1.0 project, its release cadence is likely irregular, with features and API potentially evolving rapidly. Its primary differentiator is its targeted integration with Satori, aiming to bridge the gap in gradient rendering capabilities for server-side image generation, though it can be used independently for general CSS gradient parsing needs.

serialization
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

The library primarily uses named exports and is designed for ES modules, especially given its Node.js >= 16 requirement.

import { parseLinearGradient } from 'css-gradient-parser';

Only named exports are available; there is no default export.

import { parseRadialGradient } from 'css-gradient-parser';

TypeScript types are shipped, so direct import allows for type inference and checking.

import { parseConicGradient } from 'css-gradient-parser';

Demonstrates how to parse various CSS gradient types (linear, radial, conic, repeating) using their respective functions and logs the structured output.

import { parseLinearGradient, parseRadialGradient, parseConicGradient } from 'css-gradient-parser'; const linearGradientStr = 'linear-gradient(to right, red, blue 50%, yellow)'; const radialGradientStr = 'radial-gradient(circle at top left, white, black 80%)'; const conicGradientStr = 'conic-gradient(from 90deg at 25% 75%, red, orange, yellow, green, blue, indigo, violet)'; const repeatingLinearGradientStr = 'repeating-linear-gradient(45deg, red, red 5px, blue 5px, blue 10px)'; console.log('Parsing linear gradient:', linearGradientStr); const linearResult = parseLinearGradient(linearGradientStr); console.log(JSON.stringify(linearResult, null, 2)); console.log('\nParsing radial gradient:', radialGradientStr); const radialResult = parseRadialGradient(radialGradientStr); console.log(JSON.stringify(radialResult, null, 2)); console.log('\nParsing conic gradient:', conicGradientStr); const conicResult = parseConicGradient(conicGradientStr); console.log(JSON.stringify(conicResult, null, 2)); console.log('\nParsing repeating linear gradient:', repeatingLinearGradientStr); const repeatingLinearResult = parseLinearGradient(repeatingLinearGradientStr); console.log(JSON.stringify(repeatingLinearResult, null, 2));
Debug
Known footguns
gotchaAs a pre-1.0 release (version 0.0.18), the API is subject to breaking changes in minor or even patch versions. Consult the project's changelog for updates.
gotchaThe library is specifically designed to provide parsing capabilities for Vercel Satori. While generally usable, it might have specific behaviors, limitations, or edge cases optimized for Satori's rendering pipeline that may not be ideal for other use cases.
gotchaThe package's `engines` field specifies `node: ">=16"`. Running in older Node.js versions or highly constrained legacy browser environments without proper transpilation may lead to unexpected errors or lack of functionality.
Upgrade
Version history

Breaking-change detection hasn't run for this library yet.

Audit
Security & dependencies

CVE tracking and dependency tree are planned for a later release.

Agent activity
0 hits · last 30 days

No traffic data recorded yet.

Resources