npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

generate-custom-properties

v0.2.0

Published

A cli for generating CSS Custom Properties from a JSON file

Downloads

1

Readme

Generate Custom Properties

A utility for generating CSS Custom Properties from a JSON file

Get Started

Installation

npm i -D generate-custom-properties

Usage:

$ generate-properties [flags]

Flags

--in

Input file that will be used as the configuration for the design tokens that are generated. Default file is properties.config.json.

--out

Output file that will be generated with the design tokens. Default file is properties.css.

Configuration

The configuration file defaults to properties.config.json and can also be changes throught the --in flag.

At the moment the only supported configuration file type is JSON.

Handling Output

:Root

Any content nested within root will be declared in the css file as :root

Utilities

By default all properties on the root level will create a new utlity class

Input:

{
   "alternate":{
      "colors":{
         "primary":"orange"
      },
      "font-size":{
         "large":"5em"
      }
   }
}

Output:

.alternate {
   --colors--primary: orange;
   --font-size--large: 5em;
}

Data Attributes

To create custom data attribute, separate the attribute name and the value with :

Example: attribute-name:value

Input:

{
   "theme:dark-mode":{
      "colors":{
         "primary":"black",
         "secondary":"white"
      }
   }
}

Output:

[data-theme="dark-mode"] {
  --colors--primary: black;
  --colors--secondary: white;
}

Example

properties.config.json

{
   "root":{
      "colors":{
         "primary":"red",
         "secondary":"blue",
         "link":{
            "idle":"orange",
            "hovered":"tomato"
         }
      },
      "breakpoints":{
         "small":"768px",
         "medium":"1024px",
         "large":"1440px"
      },
      "font-size":{
         "h1":"48px",
         "h2":"36px",
         "h3":"24px"
      }
   },
   "winter":{
      "colors":{
         "primary":"green",
         "secondary":"white"
      }
   },
   "summer":{
      "colors":{
         "primary":"orange",
         "link":{
            "hovered":"purple"
         }
      }
   },
   "theme:dark-mode":{
      "colors":{
         "primary":"black",
         "secondary":"white"
      }
   },
   "theme:high-contrast":{
      "font-size":{
         "h1":"75px",
         "h2":"40px",
         "h3":"24px"
      }
   },
   "state:open":{
      "colors":{
         "primary":"blue"
      }
   }
}

properties.css

:root {
  --colors--primary: red;
  --colors--secondary: blue;
  --colors--link--idle: orange;
  --colors--link--hovered: tomato;
  --breakpoints--small: 768px;
  --breakpoints--medium: 1024px;
  --breakpoints--large: 1440px;
  --font-size--h1: 48px;
  --font-size--h2: 36px;
  --font-size--h3: 24px;
}

.winter {
  --colors--primary: green;
  --colors--secondary: white;
}

.summer {
  --colors--primary: orange;
  --colors--link--hovered: purple;
}

[data-theme="dark-mode"] {
  --colors--primary: black;
  --colors--secondary: white;
}

[data-theme="high-contrast"] {
  --font-size--h1: 75px;
  --font-size--h2: 40px;
  --font-size--h3: 24px;
}

[data-state="open"] {
  --colors--primary: blue;
}