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

str-merge

v1.0.0

Published

String utilities and conflict conditionals (includes tailwind-merge).

Downloads

62

Readme

string-merge

String utilities and conflict conditionals (includes tailwind-merge).

Installation

using bun

bun add string-merge

using pnpm

pnpm add string-merge

using npm

npm i string-merge

Usage

cnx

import { cnx } from "string-merge";

// allows receiving Arrays and Objects
const className = cnx(["", baz, foo !== "foo" && bar], { "": !props }, "");

// ""
cnx(Boolean, Object, undefined, null, "", 0, NaN);


cnx(["foo", 0, false, "bar"])
// "foo bar"

cnx("hello", true && "foo", false && "bar")
// "hello foo"

cnx(["foo"], ["", 0, false, "bar"], [["baz", [["hello"], "there"]]])
// "foo bar baz hello there"

cnx("foo", [1 && "bar", { baz: false, bat: null }, ["hello", ["world"]]], "cya")
// "foo bar hello world cya"

cn

import { cn } from "string-merge";

<div
  className={
    cn(
      "bg-black/60 dark:bg-white/60 text-white dark:text-black",
      { "font-extrabold border-0": true }
      )
  }
/>

cvx

import { cvx, twMerge, type VariantsType } from "string-merge";

const classes = cvx({
  assign: "bg-muted rounded-sm px-2 border flex items-center justify-center", // assign values that is definitely returned
  variants: {
    variant: {
      bold: "font-bold",
      italic: "font-italic",
      semibold: "font-semibold",
      light: "font-light",
    },
    color: {
      blue: "text-blue-600",
      green: "text-green-700",
      red: "text-red-500",
      purple: "text-purple-500",
    },
    size: {
      sm: "h-4",
      md: "h-6",
      lg: "h-10",
      xl: "h-14",
    },
  },
  // determine the variance value by default
  defaultVariants: {
    variant: "bold",
    color: "blue",
    size: "lg",
  },
});

type MyVariantsType = VariantsType<typeof classes>;
interface ClnProps extends MyVariantsType {
  unstyled?: boolean;
  className?: string;
}
export function clN(props: ClnProps) {
  const { className, unstyled, ...rest } = props;
  return { className: twMerge(!unstyled && classes({ ...rest }), className) };
}

then:

export function CvxDemo(props: ClnProps) {
  const { className, color, size, variant, unstyled } = props;
  return (
    <div className="flex flex-col gap-4">
      <div {...clN(props)}>MY COMPONENT</div>

      <div className={classes()}>MY COMPONENT</div>

      <div className={classes({ color: "red", size: "lg" })}>MY COMPONENT</div>

      <div
        className={twMerge(
          classes({ color: "red", size: "md" }),
          "bg-black/60 dark:bg-white/60 text-white dark:text-black font-extrabold border-0",
        )}
      >
        MY COMPONENT
      </div>
    </div>
  );
}

Link

Repository Documentation

License

MIT License

© ilkhoeri