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 🙏

© 2026 – Pkg Stats / Ryan Hefner

json-styler

v1.0.0

Published

json-styler is a Node.js library that allows developers to generate CSS utility and colour classes using JSON configuration files.

Readme

json-styler

json-styler is a Node.js library that allows developers to generate CSS utility and colour classes using JSON configuration files.

It helps reduce repetitive CSS and speeds up development by generating structured, customizable classes automatically.


Installation

npm install json-styler

Table of Contents


Generating Utility Classes

You can generate utility classes using the cssUtils method.

const styleJson = require("json-styler");

styleJson.cssUtils("test.json", "style.css");

// Replace "test.json" and "style.css" with your own file paths.

Note: The generated CSS is not automatically formatted. You may use a formatter like Prettier to format the output.

JSON Structure

[
  {
    "class": "bg-",
    "property": "background-color",
    "values": ["red", "blue"]
  }
]

TypeScript Type Definition

type Utils = {
  class: string;
  property: string;
  values: string[];
}[];

Output Example

The above configuration generates:

.bg-red {
  background-color: red;
}

.bg-blue {
  background-color: blue;
}

The class field acts as a prefix before each value.


Generating Colour Classes

Colour classes can be generated using the convertToColours method.

const styleJson = require("json-styler");

styleJson.convertToColours("test.json", "style.css");

// Replace file paths as needed.

Example JSON Configuration

[
  {
    "class": "yellow",
    "hex": "#e9f238",
    "addBackground": true,
    "defaultMode": 500,
    "modes": [100, 500],
    "addBorder": true,
    "intensity": 3,
    "prefixBackground": "bg",
    "prefixBorder": "br"
  }
]

Some properties are optional.


TypeScript Type Definition

type Colours = {
  class: string;
  hex: string;
  modes?: number[] | false;
  addBackground: boolean;
  addBorder: boolean;
  defaultMode?: number;
  intensity: number;
  prefixBackground?: string;
  prefixBorder?: string;
};

Default Values

If optional properties are not provided, the following defaults are used:

| Property | Default Value | | ---------------- | --------------------------------------------- | | modes | [100, 200, 300, 400, 500, 600, 700, 800, 900] | | defaultMode | 500 | | prefixBackground | "background" | | prefixBorder | "border" |


Generated CSS Example

With the example JSON above, the generated CSS (after formatting) would look like:

.yellow {
    color: #e9f238
}

.yellow-100 {
    color: #ffff50
}

.bg-yellow {
    background-color: #e9f238
}

.bg-yellow-100 {
    background-color: #ffff50
}

.br-yellow {
    border-color: #e9f238
}

.br-yellow-100 {
    border-color: #ffff50
}

A separate class is not generated for the default mode. The base class (e.g., .yellow) contains the default mode value.


License and Dependencies

This module is licensed under the BSD-3-Clause license.

Dependencies

Dev Dependencies