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

v3.0.1

Published

This is the repo for creating a Class Name Filter Sorter

Downloads

78

Readme

Class Names - Evaluator Filter Sorter

This library is one that was created to have a set of functions that are good at removing duplicate class names based on the class name that is being used. It does this in a series of steps.

This is how things would work if this series of classes were passed in.

 const status = 'red'

  cnEFS(
    'border-blue-500',  
    status === 'red' && 'border-red-500',
   'border-2'
   status === 'red' && 'border-4',
   'border-dotted',
   status === 'red' && 'border-solid',   
  )
  1. Evaluate classes using clsx.
//  clsx output
 ['border-blue-500', 'border-red-500', 'border-2', 'border-4', 'border-dotted', 'border-solid'] 
  1. Filter and sort classes based on duplicates with last being one being created.
//  cnEFS filtering and sorting output
 ['border-4','border-solid','border-red-500', ] 
  1. Create new string from there.
//  cnEFS final output
 'border-4 border-solid border-red-500' 

Theory

The way this works is that it tries to find out what type of classes you are using. Then it stores it's name in a map with it's value type when a similar class comes along it then replaces it's value type with one that is appropriate.

This library supports many different class types. The most common being

Single word

   group

Type-value and type-subtype-value

type    value
border- solid

type    subtype value 
scroll-  p-     0
    

Block Element Modifier

block  element
card   __stat

block  element modifier 
card   __stat   --1

Single Word Classes

When it comes to sorting no matter which framework you are using single word classes will always be come before any other classes. This is strange but sorting and filtering are linked because of the nature of storage. Single word classes are always the most important ones so they should go first.

When it comes to single word classes there are two kinds.

  • Framework based
  • Non framework based

Framework based classes are filtered are based on the function that is built for that library. Let's say that relative and absolute are conflicting with each other but we are using windiCN_EFS() then which ever one came last will be preserved. This is done because windi-cn-efs knows that absolute and relative are associated with the position property. This type of relationship is expressed with something called a filter object. This object is one that knows which classes need to be replaced with the other. The key is kind of class the value is the set of classes associated with that kind.

Non framework based single word classes are assumed to be needed by the developer. This means that they will not be filtered through at all. Instead they will be left alone. When using windiCN_EFS() it will always be replaced with a version of the same class with a that is a type-value or type-subtype-value and the reverse will happen as well.

Usage

Each function is tailored to a specific framework.

  • cnEFS() can deal with tagify, type-value and type-subtype-value classes.
  • bootstrapCN_EFS() can deal with bem, bootstrap-based type-value, and type-subtype-value classes.
  • windiCN_EFS() can only deal with these tailwind/windi-based classes.
    • type-value
    • type-subtype-value
    • arbitrary properties.
    • variant
    • variant-groups
  import {windiCN_EFS} from "@code-fixer/cn-efs"

   const fixedClasses = windiCN_EFS(
    {
      'border-red-500': false,
      'border-blue-500': true,
      'border-green-500': false,
    }
   )
  import {cnEFS} from "@code-fixer/cn-efs"

   const fixedClasses = cnEFS(
    {
      'bg-red-500': false,
      'bg-blue-500': true,
      'bg-green-500': true,
      'ma-2': true, 
      'mr-4': true, 
    }
   )

Contributions

To contribute to this library fork this branch. If you have an issue go to cn-efs issues.

Recommendations

This library can be used alongside.

Class Variance Authority

For most CSS frameworks cnEFS() is the recommended solution. For Tailwind Windi and most UnoCSS frameworks windiCN_EFS() is the one.