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

cfuse

v0.1.1

Published

_description_

Downloads

9

Readme

cfuse

npm version npm downloads bundle JSDocs License javascript_code style

A utility for constructing className strings conditionally.

This module is available in the following formats:

  • ES Module: dist/cfuse.mjs
  • CommonJS: dist/cfuse.cjs

Install

$ npm install --save cfuse

Usage

import cfuse from "cfuse";

// Concatenates multiple strings, including only truthy values
console.log(cfuse("Introduction", true && "Chapter 1", "Chapter 2"));
// result: "Introduction Chapter 1 Chapter 2"

// Extracts keys from objects where the values are truthy
console.log(cfuse({ title: "Learning", subtitle: false, section: true }));
// result: "title section"

// Flattens and concatenates elements from arrays, ignoring falsy values
console.log(cfuse(["Introduction", null, false, "Chapter 1"]));
// result: "Introduction Chapter 1"

// Handles nested arrays, flattening and concatenating truthy values
console.log(cfuse(["Introduction"], ["Part A", null, false, "Chapter 1"], [["Appendix", [["Section 1"], "Section 2"]]]));
// result: "Introduction Part A Chapter 1 Appendix Section 1 Section 2"

// Combines various input types, including strings, objects, and arrays
console.log(cfuse(
  "Start",
  [true && "Middle", { key1: false, key2: true }, ["Subsection", ["Detail"]]],
  "End"
// result: "Start Middle key2 Subsection Detail End"
));

// Processes all types of truthy and falsy values, including null, empty strings, NaN, zero, and more
console.log(cfuse({
  nullValue: null,
  emptyString: "",
  invalidNumber: Number.NaN,
  zeroValue: 0,
  negativeZeroValue: -0,
  falseValue: false,
  undefinedValue: undefined,
  nonEmptyString: "Valid String",
  whitespaceString: " ",
  functionValue: Object.prototype.toString,
  emptyObject: {},
  nonEmptyObject: { a: 1, b: 2 },
  emptyList: [],
  nonEmptyList: [1, 2, 3],
  positiveNumber: 1,
}));
// result: "Valid String  functionValue emptyObject nonEmptyObject emptyList nonEmptyList positiveNumber"

API

cfuse(...inputs)

Returns: String

Parameters

  • inputs: Mixed
    • The cfuse function accepts any number of arguments. Each argument can be of type Object, Array, Boolean, String, Number, null, or undefined.

Description

The cfuse function concatenates values from the provided arguments into a single string. Falsy values (e.g., false, null, undefined, 0, NaN, "", and empty arrays/objects) are ignored. The function processes the arguments in the following manner:

  • Strings: Included directly.
  • Objects: Includes the keys where the corresponding values are truthy.
  • Arrays: Flattens nested arrays and includes all truthy elements.
  • Other types (Boolean, Number): Converts truthy values to strings and ignores falsy values.

Examples

// Examples with different types of inputs

console.log(cfuse(true, false, "", null, undefined, 0, Number.NaN));
// => ''

console.log(cfuse("Hello", "World", 123, { key: "value" }, [true, "Array"]));
// => 'Hello World 123 key Array'

License

MIT License © 2023-PRESENT Kirk Lin