lemmon/clsx 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

lemmon/clsx

最新稳定版本:1.0.0

Composer 安装命令:

composer require lemmon/clsx

包简介

A tiny PHP utility to conditionally build `class` attribute strings, inspired by clsx for JavaScript.

README 文档

README

A tiny PHP utility to conditionally build class attribute strings. Inspired by clsx for JavaScript, it lets you easily compose class names using strings, arrays, and associative arrays.

Installation

Install via Composer:

composer require lemmon/clsx

Usage

echo clsx('foo', true && 'bar', 'baz');
// Output: 'foo bar baz'

echo clsx(['foo', 0, false, 'bar']);
// Output: 'foo bar'

echo clsx(['foo'], ['', 0, false, 'bar'], [['baz', [['hello'], 'there']]], 'bye');
// Output: 'foo bar baz hello there bye'

echo clsx(['foo' => true, 'bar' => false, 'baz' => isSomethingTrue()]);
// Output: 'foo baz'

echo clsx(['foo' => true], ['--special' => 'active']);
// Output: 'foo --special'

API

clsx(...$args): string

Returns a space-separated string of valid class names.

Parameters

  • ...$args: mixed Accepts any number of arguments. Arguments can be:
    • Strings
    • Arrays (flat or nested)
    • Associative arrays (keys are class names, values are booleans or strings)

Note: Falsy values like false, null, 0, '', etc. are discarded. Only truthy values or valid strings are included in the final result.

Example

clsx(true, false, '', null, 0);
// Output: ''

License

MIT © Jakub Pelák

统计信息

  • 总下载量: 112
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-07-23

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固