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

prettier-plugin-sort-class-names

v3.0.1

Published

Sort classes with prettier

Downloads

554

Readme

prettier-plugin-sort-class-names

Per default it will sort your class names alphabetically.

install

Prettier should already be set up for your project (check prettier docs). After that it is enough to install prettier-plugin-sort-class-names in the same project, it will be applied automatically.

npm i prettier-plugin-sort-class-names --save-dev
# or with yarn
yarn add prettier-plugin-sort-class-names --dev

If you are using yarn 2 (aka Plug'n'Play/PnP, aka "berry"), check the troubleshooting section at the bottom

prettier-plugin-sort-class-names-order

You can create a file prettier-plugin-sort-class-names-order where every line represents a class name. The higher up a class is in the list, the further forward it is sorted. Example:

flex
block
align-items-center

With this sorting-file, a node like

<div class="custom-class md:flex align-items-center block"></div>

will become

<div class="custom-class / block align-items-center md:flex"></div>

existing order-lists

custom prettier options

you can add this options to your prettier config file:

| option | description | default | | ------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------ | | sortClassNamesOrderFile | Path to your custom prettier-plugin-sort-class-names-order file, if you not define anything, it will sort the class names alphabetically. | "prettier-plugin-sort-class-names-order" | | sortClassNamesPrefixes | comma seperated list of your prefixes. Prefixes will be grouped together wenn sorting. | "sm:,md:,lg:,xl:" | | sortClassNamesUnknownClassesSeparator | When your class list contains known (in your order-file) and unknown class names, it will be separated by this char. You can disable this by providing an empty string as option ("") | "/" | | sortClassNamesClassAttributes | Comma separated list of JSX attributes to sort tailwind classes in. | "class,className,tw" | | sortClassNamesSortFunctions | Comma separated list of function names to sort classes in arguments. | "clsx,classNames,cx" |

parser support

Supports

troubleshooting

plugin is not automatically detected with yarn 2

  1. make sure to use prettier.config.js (if you are currently using .prettierrc et al you have to change to the js-variant)
  2. add the plugins section:
module.exports = {
	plugins: [require('prettier-plugin-sort-class-names')],
	// ... your other config-keys like:
	printWidth: 120,
}

check prettier issue #7073 for more information

special thanks

To Acidic9 and his package prettier-plugin-tailwind.

If you want to sort your tailwind class names, you should give this package a shot and come back if you want to extend it with custom class names.