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

tailwind-ts-gen

v1.0.0

Published

Generate TS/JS constants with Tailwind CSS class names.

Downloads

6

Readme

tailwind-ts-gen

GitHub Workflow Status Version MIT License

PRs Welcome Code of Conduct

Generate TS/JS constants with Tailwind CSS class names for better IntelliSense and autocompletion/autosuggestion.

Installation & usage

tailwind-ts-gen only support Tailwind CSS used with PostCSS.

Install the package:

yarn add postcss tailwindcss tailwind-ts-gen

Then:

yarn tw2ts --out tailwind.ts tailwind.css

It will generate a tailwind.ts file based on --out option with all of the classes from tailwind.css file.

Assuming your tailwind.css file looks like this:

@import "tailwindcss/base";

@import "tailwindcss/components";

@import "tailwindcss/utilities";

Don't forget to configure PostCSS with postcss-import plugin. Otherwise tailwind-ts-gen won't be able to find any Tailwind CSS classes.

The generated file will look similarity to:

/**
 * @file Tailwind CSS class names exported as const variables.
 *       Auto-generated file. Do not modify.
 * @author tailwind-ts-gen
 */

/** Constant for `container` */
export const container = 'container';
// ... etc
/** Constant for `bg-gray-100` */
export const bg_gray_100 = 'bg-gray-100';
/** Constant for `bg-gray-200` */
export const bg_gray_200 = 'bg-gray-200';
/** Constant for `bg-gray-300` */
export const bg_gray_300 = 'bg-gray-300';
// ... etc
/** Constant for `hover:font-bold` */
export const hover_font_bold = 'hover:font-bold';
// ... etc

Additionally:

  • You can use both .ts and .js extensions for the generate file.
  • You can specify multiple input files eg: tw2ts --out output.ts input1.css input2.css.
  • You can use SASS, SCSS, LESS and other extensions for input files as long as PostCSS is configured to understand them.
  • If you pass relative file for --out or for input files, it will be resolved based on current working directory.
  • If you have prettier installed the generated code will be prettified. You can use --prettier-config to specify custom Prettier configuration, otherwise it will be inferred.
  • You can specify path to custom PostCSS config with --postcss-config.

tw2ts -h

tw2ts <input...>

Generate file with Tailwind CSS class names. If Prettier config file and
Prettier package is available, it will be used to format the generated file.

You can pass multiple input files - class names from all of them, will be
extracted to a single file specified by -o, --out option.

Positionals:
  input  CSS/SASS/LESS file with Tailwind CSS imports.                  [string]

Options:
  --version          Show version number                               [boolean]
  --out, -o          Path to an output file with generated code.
                                                             [string] [required]
  --postcss-config   Path to PostCSS config file.                       [string]
  --prettier-config  Path to Prettier config file.                      [string]
  --help             Show help                                         [boolean]