Skip to content

Add isGradientFunction(name: string): boolean to css-analyzer/values #605

Description

@bartveneman

Context

css-analyzer/values already exports classification helpers like colorFunctions, colorKeywords, and namedColors. There is no equivalent helper for identifying CSS gradient functions.
Consumers currently write inline regex checks like:

/^(repeating-)?(linear|conic|radial)-gradient$/.test(name)

This duplicates knowledge of which function names are gradients and will need updating if new gradient types are standardized (e.g. conic-gradient was added relatively recently).
Proposed API

/** Returns true if `name` is a CSS gradient function name. */
function isGradientFunction(name: string): boolean

Example

import { isGradientFunction } from '@projectwallace/css-analyzer/values'

isGradientFunction('linear-gradient')          // true
isGradientFunction('repeating-radial-gradient') // true
isGradientFunction('conic-gradient')           // true
isGradientFunction('rgb')                      // false
isGradientFunction('url')                      // false

Gradient functions to cover

  • linear-gradient
  • radial-gradient
  • conic-gradient
  • repeating-linear-gradient
  • repeating-radial-gradient
  • repeating-conic-gradient

Motivation

Centralises the list of gradient function names alongside other value-classification constants in this package. Prevents consumers from maintaining inline regexes that may diverge from the actual CSS specification over time.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions