What is css-gradient-parser?
The css-gradient-parser is a JavaScript library that allows you to parse CSS gradient strings into a structured format. This can be useful for applications that need to manipulate or analyze CSS gradients programmatically.
What are css-gradient-parser's main functionalities?
Parse CSS Gradient Strings
This feature allows you to parse a CSS gradient string into an object that represents the gradient's structure. The code sample demonstrates how to use the `parse` function to convert a linear gradient string into a structured format.
const { parse } = require('css-gradient-parser');
const gradient = 'linear-gradient(to right, red, blue)';
const parsedGradient = parse(gradient);
console.log(parsedGradient);
Other packages similar to css-gradient-parser
gradient-parser
The gradient-parser package is similar to css-gradient-parser in that it also parses CSS gradient strings into a structured format. However, gradient-parser is more widely used and has a more extensive set of features for handling different types of gradients.
css-gradient
The css-gradient package provides utilities for working with CSS gradients, including parsing and generating gradient strings. It offers a broader range of functionalities compared to css-gradient-parser, such as generating gradient strings from objects.
css-gradient-parser
This lib intends to give a parser for satori so that we can handle more gradient features
API
parseLinearGradient
interface LinearOrientation {
type: 'directional' | 'angular'
value: string
}
interface LinearResult {
orientation: LinearOrientation
repeating: boolean
stops: ColorStop[]
}
parseRadialGradient
type ValueType = 'keyword' | 'length'
interface RadialResult {
shape: 'circle' | 'ellipse'
repeating: boolean
size: {
type: ValueType
value: string
}[]
position: {
x: { type: ValueType, value: string }
y: { type: ValueType, value: string }
}
stops: ColorStop[]
}
parseConicGradient
type RectColorSpace = 'srgb' | 'srgb-linear' | 'lab' | 'oklab' | 'xyz' | 'xyz-d50' | 'xyz-d65'
type PolarColorSpace = 'hsl' | 'hwb' | 'lch' | 'oklch'
type HueInterpolationMethod = `${'shorter' | 'longer' | 'increasing' | 'decreasing'} hue`
interface ConicGradient {
angle: string
repeating: boolean
position: string
color?: Color
stops: ColorStop[]
}
type Color = {
space: RectColorSpace | PolarColorSpace
method?: HueInterpolationMethod
}
LICENSE
MIT