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

@crown3/cx

v2.0.0

Published

<p align="center"> <a href="https://github.com/crown3"><img alt="Author Info" src="https://img.shields.io/badge/-Made%20by%20Crown3-grey?logo=c&style=flat-square"></a> <a href="https://github.com/crown3"><img alt="Author Info" src="https://img.badgesize.i

Downloads

8

Readme

CX

cx is a TypeScript utility that contains conditional processing, can process both CSS Module and native CSS className (Inspired by classNames/bind)

cx('a', true, { c: true })
// => 'a c'  just like classNames function

// But when you bind styles in cx and the first argument is arr
import styles from './style.module.css'
import classNames from '@crown3/cx'
const cx = classNames.bind(styles)
cx(['a', { b: true }], 'c', { d: true }, [{ e: true }])
// => 'a-module-class b-module-class c d e

Getting Started

# via npm
npm install @crown3/cx

# or Yarn
yarn add @crown3/cx

Use with TypeScript

import classNames, { CX } from '@crown3/cx'
import styles from './demo.module.css'

const cx: CX = classNames.bind(styles)
cx(['hello'], 'world')
// => 'hello-module-class world'

Or in JavaScript

import { classNames } from '@crown3/cx'
import styles from './demo.module.css'

const cx = classNames.bind(styles)

Documentation

Only when you bind this to CSS Module styles and the first argument is array, cx will handle all arguments in this array as CSS Module (Others are still handled as normal CSS styles)

  • Note: If you bind a CSS Module but the first argument isn't array, cx will handle all arguments as normal CSS styles
  • The processing logic of the arguments is similar with classNames/bind, all arguments will do a conditionally handle and if the result is true, the key will be output
    • But there's a little different with classNames/bind in handling CSS Module styles, when the class name doesn't exist in the CSS Module, cx will ignore this instead of returning it as a string like classNames/bind
// mock a CSS Module styles
import classNames from '@crown3/cx'

const cx = classNames
cx([{ a: true, b: false }], 'c', undefined, null) // => 'a c'

// But when you bind styles
const styles = { a: 'a1', b: 'b2' }
const cx = classNames.bind(styles)

cx(['a', { b: true }]) // => 'a1 b2'
// But if first arg isn't array, cx will handle all arguments as normal css, even if you bind styles
cx('a', ['b']) // => 'a b'

// the arguments can accept any number of items which can be a string, boolean, number, array or Object
// If the value associated with a given key is falsy, the key won't be included in the output
cx(['a', { b: true }, [{ b: true }, 'c']], 'a', ['b'], [{ c: true }])
// => 'a1 b2 b2 a b c'
// Note: there hasn't 'cx' in our output, because the Module styles doesn't have the 'c' key

// Even using it like this
cx(
  [
    {
      toString() {
        return 'a'
      },
    },
    {
      toString() {
        return 'c'
      },
    },
  ],
  {
    toString() {
      return 'b'
    },
  }
)
// => 'a1 b'

License

@crown3/cx is licensed under a MIT License.