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

@code-fixer-23/cn-efs

v2.2.4

Published

This is the repo for creating a Class Name Filter Sorter

Downloads

8

Readme

cn-efs

This library is a library has a set of functions that are created to Evaluate, Filter and Sort Class Names. They are called class name evaluate, filter sorters or cnEFS's.

What each function does is.

  1. Evaluate each class name passed to it using clsx.
  2. Breaks apart and filter each class for duplicates based on conventions.
  3. Reassemble each of the class that were kept in Step 2.
  4. Return string with only the classes that were identical but on the right.

Each function only works on specific classes. If you don't have the correct string then it will be filtered out.

Only lowercased words are ignored.

Unless it's not supposed to exist along side of another one. This is decided by the kind of cnEFS you are using.

Sorting

This library will sort your classes based on which type of class it is or how it was filtered. This is done as a way to support better debugging. Know that single word classes will always be put before utility ones.

Usage

The following sections will show you how to use each of the functions. This is based on what conventions or framework you are using. When using this library remember to use it on components where you will deal with conflicting classes.

BEM, CUBE, Tachyons

import { cnEFS } from "@code-fixer-23/cn-efs"

export function ErrorComponent({status}) {
   
  const filteredClasses =  cnEFS(
         "card",
          "card--md",
         "card--lg",
         "bg-primary"
          {
            "bg-red-500": status === "error",
            "bg-blue-500": status === "success",
          }
   )

   return <div className={filteredClasses}>
   { status === "error" && "Error"}
   </div>
    
}

cnEFS() is a function that will preserve and filter out conflicting.

  • BEM elements and modifiers.
  • Tagify classes. ma5 or ma6.
  • Classes that include the word ary like this text-primary or text-primary-400.
  • Utility classes that look like this border-1 border-red border-dashed.

Warning if you are using CUBE CSS convention don't do this.

---
import {cnEFS} from "@code-fixer-23/cn-efs"

const {class:$class} = Astro.props

---
<div class={cnEFS("[word] [border-1] border-gray-500", $class)}>

</div>

DO this.

---
import {cnEFS} from "@code-fixer-23/cn-efs"

const {class:$class} = Astro.props
---
<div class:list={["[word] [border-1]", cnEFS("border-gray-500", $class)]}>

</div>

All the symbols will be filtered out of the string.

Bootstrap

import {bootstrapCN_EFS} from "@code-fixer-23/cn-efs"

@Component({
   template:`
      <div [class]="filteredClasses">
      Hello World
      </div>
   `
})
class HelloWorld {
   
   @Input()
    status = "warning"
 
 filteredClasses = bootstrapCN_EFS(
   "bg-primary",
   this.status === "idle" && "bg-primary-emphasis",
   "text-warning-subtle-hover",
   this.status === "warning" && "text-warning" 
) 

}



bootstrapCN_EFS() is a function that will preserve and filter out conflicting classes that abide by the Bootstrap CSS Framework.

Warning If you are using Bootstrap don't add any breakpoints when configuring. I tried to make this library work with out this (?<breakpoint>-(?:sm|md|lg|xl|xxl)) regex but could not. I know that most people like to stick to the defaults. This should be a small problem but if you want to help me please talk to the bootstrap people or be a part of this discussion.

Tailwind, Windi


<script setup>
import { tailwindOrWindiCN_EFS } from "@code-fixer-23/cn-efs"

const {class:$class} = useAttrs()

const sortedClasses = tailwindOrWindiCN_EFS(
   "border", 
   "border-gray-500", 
   $class
) 
</script>

<template>
<div :class="sortedClasses">
   Hello World
</div>
</template>

tailwindOrWindiCN_EFS() is a function that will preserve and filter out conflicting classes that abide by the Tailwind and Windi CSS Framework. It filters out conflicts between variants, states and breakpoints for each utility class. It resolves conflicts between important and not important values.

Limitations

This library can only filter out classes that look identical to each other. It does not resolve conflicts based on symbols like.

  • [&:focus]: vs focus: arbitrary variant vs regular variant
  • text-gray-500 vs [color:#6b7280] utility vs arbitrary property.

I have decided to do this because I don't think it's good practice to write utility classes inconsistently.

We also don't have a cache. When React rerenders all of the work will all be redone again.

Recommendations

I recommend that you also use this library with.