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

z-index-token-enforcer

v1.0.14

Published

Enforce z-index token usage across Stylelint, ESLint, and CLI.

Readme

z-index-token-enforcer

A multi-tool enforcer to ensure your team uses design tokens (CSS variables) for z-index properties, using a structured layering system instead of magic numbers.

example tokens:

:root {
    /* ... global layers ... */
    --z-base: 0; /* Default stacking context */
    --z-toasts: 100; 
    --z-overlays: 200; 
    --z-popups: 300; 

    /* Internal relations */
    --z-bottom: -10;
    --z-top: 10;
}

Why?

As explained in the article "The Value of z-index", using literal numbers for z-index leads to:

  1. Unpredictability: No one knows what 100 means compared to 99.
  2. Maintenance Hell: Changing one value requires checking all other files.
  3. Complexity: Hard to manage stacking contexts without a clear hierarchy.

By forcing the use of tokens (e.g., z-index: var(--z-overlay)), you ensure the team follows a shared design system.


How it works

The enforcer ensures that every z-index property in your codebase follows a strict token-based system, regardless of how you write your styles.

❌ Invalid Syntax (Will cause errors)

Literal numbers are strictly forbidden to prevent "magic number" battles:

In CSS / SCSS:

  • z-index: 100;
  • z-index: 99999;

In JavaScript / React (Inline Styles & CSS-in-JS):

  • zIndex: 100
  • const styles = { zIndex: '9999' }
  • styled.div z-index: 50; `` (Styled Components / Emotion)

✅ Valid Syntax

Values must be CSS variables (tokens) that represent the functional layer:

In CSS / SCSS:

  • z-index: var(--z-modal);
  • z-index: calc(var(--z-overlay) + 1);
  • z-index: auto; (and other keywords: inherit, initial, unset, revert)

In JavaScript / React:

  • zIndex: "var(--z-modal)"
  • zIndex: "auto"
  • const Overlay = styled.div z-index: var(--z-overlay); ``

Note on prefixing: By default, the enforcer looks for the --z- prefix (e.g., --z-header). You can customize this in the options.

Installation

npm install z-index-token-enforcer --save-dev

One Tool, Three Ways to Enforce

This package provides a unified logic to check for z-index tokens across your entire stack.

1. Stylelint Plugin (Recommended for CSS/SCSS)

If you haven't set up Stylelint yet, follow the Stylelint Getting Started guide.

Config (.stylelintrc.json):

{
  "plugins": ["z-index-token-enforcer"],
  "rules": {
    "z-index-token-enforcer/only-tokens": [true, { "prefix": "--z-" }]
  }
}

2. ESLint Plugin (For CSS-in-JS / React)

If you haven't set up ESLint yet, follow the ESLint Getting Started guide.

Config (.eslintrc.json):

{
  "plugins": ["z-index-token-enforcer"],
  "rules": {
    "z-index-token-enforcer/only-tokens": ["error", { "prefix": "--z-" }]
  }
}

3. CLI Scanner (For quick checks or CI/CD)

The CLI scanner allows you to quickly scan any files or directories for invalid z-index values.

Scan all files in the project:

npx z-index-token-enforcer "**/*"

Scan only CSS files in a specific directory:

npx z-index-token-enforcer "src/**/*.css"

With custom prefix:

npx z-index-token-enforcer "**/*.css" --prefix=--custom-

Note: You use the package name (z-index-token-enforcer) to run the scanner via npx.