@frankhoodbs/css-custom-properties-list v3.0.3
CSS Custom Properties List
A simple utility to fetch and list all CSS Custom Properties (often known as CSS Variables) defined in
the :root selector of stylesheets from the same domain.
Features
- Domain Filtering: Only parses stylesheets from the same domain to avoid cross-origin issues.
- Focus on
:rootSelector: Specifically targets custom properties defined under the:rootselector.
Usage
Import the utility function:
import { cssCustomPropertiesList } from '@frankhoodbs/css-custom-properties-list';To get a list of custom properties from all stylesheets in the document:
const propertiesList = cssCustomPropertiesList(document.styleSheets);
console.log(propertiesList);This will return an array of arrays, where each inner array contains two strings: the custom property name and its value. For example:
[
['--primary-color', '#ff4500'],
['--font-size', '16px']
]Utility Functions
isSameDomain(styleSheet: CSSStyleSheet)
Determines whether a given stylesheet is from the same domain as the current page.
isStyleRule(rule: CSSRule)
Checks if a given rule is a style rule.
cssCustomPropertiesList(styleSheets: StyleSheetList)
The main utility function which accepts a list of stylesheets and returns the custom properties as described above.
1 year ago
6 months ago
6 months ago
7 months ago
7 months ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago