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

stylelint-scales

v5.0.0

Published

A Stylelint plugin pack to enforce numeric scales

Downloads

1,535

Readme

stylelint-scales

NPM version Actions Status NPM Downloads

A Stylelint plugin pack to enforce numeric scales.

Installation

npm install stylelint-scales --save-dev

Usage

Add stylelint-scales to your Stylelint config plugins array, then add the rules you need to the rules list. All rules from stylelint-scales need to be namespaced with scales.

Like so:

{
  "plugins": ["stylelint-scales"],
  "rules": {
    "scales/alpha-values": [80, 90],
    "scales/border-widths": [{ "scale": [1, 2], "units": ["px"] }],
    "scales/font-sizes": [
      [
        { "scale": [1, 1.5, 2], "units": ["em", "rem"] },
        { "scale": [12, 14, 16], "units": ["px"] }
      ],
      {
        "ignoreFunctionArguments": {
          "clamp": [1]
        }
      }
    ],
    "scales/font-weights": [400, 600],
    "scales/line-heights": [1, 1.5],
    "scales/radii": [{ "scale": [2, 4], "units": ["px"] }],
    "scales/space": [{ "scale": [0.5, 1, 2, 4], "units": ["rem"] }]
  }
}

To enforce this:

p {
  border: 1px solid hsl(var(--accent) / 90%));
  border-radius: 2px;
  font-size: clamp(1rem, 0.23rem + 1.5vw, 12px);
  font-weight: 400;
  line-height: 1.5;
  margin-block: 2rem;
}

This plugin can automatically fix all the scales.

List of rules

  • alpha-values: Specify a scale for alpha values (Autofixable).
  • border-widths: Specify a scale for border widths (Autofixable).
  • font-sizes: Specify a scale for font sizes (Autofixable).
  • font-weights: Specify a scale for font weights (Autofixable).
  • letter-spacings: Specify a scale for letter spacings (Autofixable).
  • line-heights: Specify a scale for line heights (Autofixable).
  • radii: Specify a scale for radii (Autofixable).
  • sizes: Specify a scale for sizes (Autofixable).
  • space: Specify a scale for space (Autofixable).
  • word-spacings: Specify a scale for word spacings (Autofixable).
  • z-indices: Specify a scale for z-indices (Autofixable).

Ref: Styled System Keys Reference

You and the designers should define the scales together. You'll want to strike a balance between code consistency and design flexibility.

Why?

This plugin can help you create:

  • a consistent look and feel for your websites
  • efficient collaboration between you and the designers

When designers review websites in the browser, they generally use relative terms. For example, "The space between that heading and that paragraph feels too tight, can we make it bigger?"

You can then pick the next value on the scale and be confident that it'll be consistent with the overall design.

Why not use variables?

While you can achieve something similar with variables, with this plugin you:

  1. Avoid the cognitive load of abstracted variable names. Colours benefit from human-readable names, whereas it's typically easier to work directly with numeric values. If you use a numeric value that isn't on the scale, the plugin will automatically fix it.
  2. Enforce code and design consistency with one mechanism. You likely already use Stylelint for code consistency, for example using the unit-allowed-list to enforce consistent units. By using this plugin, you avoid adding a second mechanism (variables) to ensure design consistency for numeric values.
  3. Can use the same approach across projects. The plugin is agnostic of the styling technology, whether that's styled-components, SCSS or vanilla CSS.
  4. Remove the need to translate values from design tools into variables. You can copy and paste code from design tools like Figma and Sketch without alteration.

License

The MIT License.