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-tailwind-scale

v0.1.4

Published

A utility to generate spacing scales for Tailwind CSS

Downloads

6

Readme

generate-scale

A utility to generate spacing scales for TailwindCSS.

Installation

npm install generate-tailwind-scale --save-dev

Usage

In you tailwind.config.js file, you can import the package, and generate scales where you need it. Eg.

const generateScale = require("generate-tailwind-scale")

/** @type {import('tailwindcss').Config} */
module.exports = {
    theme: {
        extend: {
            spacing: {
                ...generateScale()
            }
        }
    }
}

Configuration

The generateScale function accepts a configuration object with the following properties:

  • classPrefix (string, optional): Prefix to be added to the class names, default ""
  • classSuffix (string, optional): Suffix to be added to the class names, default ""
  • unit (string, optional): Unit of measurement for the CSS values, default "rem"
  • scale (number, optional): The scale factor from the class name to the CSS value, default 4
  • from (number, optional): The starting value of the scale, default 0
  • to (number, optional): The ending value of the scale, default 256
  • increment (object, optional): Increment configuration, see defaults below

Increment Configuration

The increment configuration object allows you to define how the scale should increment based on the size value. It consists of three parts:

  • default: The default increment value used when no specific conditions are met, default 1
  • below: An object where keys are size thresholds, and values are the increment values to be used for sizes below these thresholds.
  • above: An object where keys are size thresholds, and values are the increment values to be used for sizes above these thresholds.

Example

Given the following increment configuration:

{
  default: 5,
  below: {
    20: 2
  },
  above: {
    50: 10
  }
};

The function will increment the size by:

  • 2 units for sizes below 20.
  • 10 units for sizes above 50.
  • 5 units for sizes between 20 and 50.

Default increment config

The default increment configuration is:

  • 1 unit default
  • 0.5 units for sizes below 5
  • 2 units for sizes above 100
  • 4 units for sizes above 200

Full Example

Here's a full example configuration and usage: const generateScale = require('generate-scale');

const generateScale = require("generate-tailwind-scale")

/** @type {import('tailwindcss').Config} */
module.exports = {
    theme: {
        extend: {
            spacing: {
                ...generateScale(
                    classPrefix: "px",
                    classSuffix: "px",
                    unit: "px"
                    scale: 1,
                    from: 0,
                    to: 100,
                    increment: {
                        default: 5,
                        below: {
                            20: 2
                        },
                        above: {
                            50: 10
                        }
                    }
                )
            }
        }
    }
}

/*
Output:
{
  'w-px0px': '0px',
  'w-px2px': '2px',
  'w-px4px': '4px',
  'w-px6px': '6px',
  'w-px8px': '8px',
  'w-px10px': '10px',
  'w-px12px': '12px',
  'w-px14px': '14px',
  'w-px16px': '16px',
  'w-px18px': '18px',
  'w-px20px': '20px',
  'w-px25px': '25px',
  'w-px30px': '30px',
  'w-px35px': '35px',
  'w-px40px': '40px',
  'w-px45px': '45px',
  'w-px50px': '50px',
  'w-px60px': '60px',
  'w-px70px': '70px',
  'w-px80px': '80px',
  'w-px90px': '90px',
  'w-px100px': '100px'
}
*/

License

MIT