
Security News
Browserslist-rs Gets Major Refactor, Cutting Binary Size by Over 1MB
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
custom-properties
Advanced tools
I use this module to display a documentation of my CSS Custom Properties defined in the :root
. It runs in the browser runtime, maps the document.styleSheets object and returns an array of custom properties.
yarn add custom-properties
npm install custom-properties --save
Custom Properties for the examples.
:root {
--all-color-white: #hex,
--all-color-grey-400: #hex,
--all-color-grey-200: #hex,
--all-color-grey-100: #hex,
--all-color-grey-300: #hex,
--all-color-red-100: #hex,
--all-color-red-400: #hex,
--all-color-red-300: #hex,
--all-color-red-200: #hex,
}
In the custom property --all-color-grey
all
is index 0
color
is index 1
grey
is index 2
So, let's group all the custom properties by the sortIndex 2
import customProperties from 'custom-properties'
const allWithPrefix = customProperties.get('--all')
const properties = customProperties.groupIndex(allWithPrefix, 2)
/*
{
white: [
'--all-color-white',
],
grey: [
'--all-color-grey-400',
'--all-color-grey-200',
'--all-color-grey-100',
'--all-color-grey-300',
],
red: [
'--all-color-red-100',
'--all-color-red-400',
'--all-color-red-300',
'--all-color-red-200',
]
}
*/
Sometimes, I need to sort the shades of colors to show in the documentation, it can be made with the sortIndex
parameter
import customProperties from 'custom-properties'
const allWithPrefix = customProperties.get('--all')
const properties = customProperties.groupIndex(allWithPrefix, 2, 3)
/*
{
white: [
'--all-color-white',
],
grey: [
'--all-color-grey-400',
'--all-color-grey-300',
'--all-color-grey-200',
'--all-color-grey-100',
],
red: [
'--all-color-red-400',
'--all-color-red-300',
'--all-color-red-200',
'--all-color-red-100',
]
}
*/
FAQs
A helper to get CSS Custom Properties defined in the :root rule
The npm package custom-properties receives a total of 3 weekly downloads. As such, custom-properties popularity was classified as not popular.
We found that custom-properties demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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.
Security News
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
Research
Security News
Eight new malicious Firefox extensions impersonate games, steal OAuth tokens, hijack sessions, and exploit browser permissions to spy on users.
Security News
The official Go SDK for the Model Context Protocol is in development, with a stable, production-ready release expected by August 2025.