Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

custom-properties

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

custom-properties

A helper to get CSS Custom Properties defined in the :root rule

  • 1.0.1
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
2
decreased by-33.33%
Maintainers
1
Weekly downloads
 
Created
Source

custom-properties

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.

Install

yarn add custom-properties

npm install custom-properties --save

Usage

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,
}

groupIndex(customPropertiesArray, groupIndex)

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',
  ]
}
*/

groupIndex(customPropertiesArray, groupIndex, sortIndex)

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

Package last updated on 31 Mar 2018

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc