@lightsound/cn 0.1.0 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -2
- package/README.md +26 -63
- package/dist/index.js +1 -1
- package/package.json +10 -3
package/LICENSE
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
MIT License
|
|
2
2
|
|
|
3
|
-
Copyright (c)
|
|
3
|
+
Copyright (c) 2025 lightsound
|
|
4
4
|
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
6
|
of this software and associated documentation files (the "Software"), to deal
|
|
@@ -19,4 +19,3 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
19
19
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
20
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
21
|
SOFTWARE.
|
|
22
|
-
|
package/README.md
CHANGED
|
@@ -3,27 +3,42 @@
|
|
|
3
3
|
A tiny, **blazing fast** utility for constructing `className` strings conditionally.
|
|
4
4
|
|
|
5
5
|
[](https://www.npmjs.com/package/@lightsound/cn)
|
|
6
|
-
[](https://github.com/lightsound/cn/actions/workflows/ci.yml)
|
|
7
|
+
[](https://bundlephobia.com/package/@lightsound/cn)
|
|
7
8
|
[](./LICENSE)
|
|
8
9
|
|
|
9
10
|
## Features
|
|
10
11
|
|
|
11
|
-
- **Blazing Fast**: Up to
|
|
12
|
-
- **Tiny**: ~
|
|
12
|
+
- **Blazing Fast**: Up to 26% faster than `clsx/lite`
|
|
13
|
+
- **Tiny**: ~130B gzipped (smaller than clsx/lite!)
|
|
13
14
|
- **TypeScript**: Full type support out of the box
|
|
14
15
|
- **Simple API**: Strings only - no objects, no arrays, maximum performance
|
|
15
16
|
- **Zero Dependencies**: No external dependencies
|
|
16
17
|
|
|
18
|
+
## Why @lightsound/cn?
|
|
19
|
+
|
|
20
|
+
| Feature | @lightsound/cn | clsx/lite | clsx |
|
|
21
|
+
| --------------- | -------------- | --------- | ----- |
|
|
22
|
+
| Strings only | ✅ | ✅ | ❌ |
|
|
23
|
+
| Objects support | ❌ | ❌ | ✅ |
|
|
24
|
+
| Arrays support | ❌ | ❌ | ✅ |
|
|
25
|
+
| Size (gzip) | ~130B | ~139B | ~239B |
|
|
26
|
+
| Performance | ⚡⚡⚡ | ⚡⚡ | ⚡ |
|
|
27
|
+
|
|
28
|
+
If you only use string-based class composition (the most common pattern with Tailwind CSS), `@lightsound/cn` provides the best performance.
|
|
29
|
+
|
|
17
30
|
## Benchmarks
|
|
18
31
|
|
|
19
|
-
|
|
32
|
+
> Benchmarks are run on every CI build. See the [latest CI run](https://github.com/lightsound/cn/actions/workflows/ci.yml) for up-to-date results.
|
|
20
33
|
|
|
21
|
-
|
|
22
|
-
|
|
|
23
|
-
|
|
|
24
|
-
|
|
|
25
|
-
|
|
|
26
|
-
|
|
|
34
|
+
<!-- BENCHMARK_START -->
|
|
35
|
+
| Test Case | @lightsound/cn | clsx/lite | Improvement |
|
|
36
|
+
| --------- | -------------- | --------- | ----------- |
|
|
37
|
+
| 2 strings | 52.31 ns | 67.05 ns | **22% faster** |
|
|
38
|
+
| 3 strings | 52.07 ns | 70.71 ns | **26% faster** |
|
|
39
|
+
| 5 strings | 68.33 ns | 87.32 ns | **22% faster** |
|
|
40
|
+
| 10 strings | 104.29 ns | 139.06 ns | **25% faster** |
|
|
41
|
+
<!-- BENCHMARK_END -->
|
|
27
42
|
|
|
28
43
|
## Installation
|
|
29
44
|
|
|
@@ -65,46 +80,6 @@ cn("foo", false, null, undefined, 0, "", "bar");
|
|
|
65
80
|
// => 'foo bar'
|
|
66
81
|
```
|
|
67
82
|
|
|
68
|
-
## Real-world Example (Tailwind CSS)
|
|
69
|
-
|
|
70
|
-
```typescript
|
|
71
|
-
import { cn } from "@lightsound/cn";
|
|
72
|
-
|
|
73
|
-
interface ButtonProps {
|
|
74
|
-
variant?: "primary" | "secondary";
|
|
75
|
-
size?: "sm" | "md" | "lg";
|
|
76
|
-
disabled?: boolean;
|
|
77
|
-
className?: string;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
function Button({
|
|
81
|
-
variant = "primary",
|
|
82
|
-
size = "md",
|
|
83
|
-
disabled,
|
|
84
|
-
className,
|
|
85
|
-
}: ButtonProps) {
|
|
86
|
-
return (
|
|
87
|
-
<button
|
|
88
|
-
className={cn(
|
|
89
|
-
"inline-flex items-center justify-center rounded-md font-medium",
|
|
90
|
-
"transition-colors focus-visible:outline-none focus-visible:ring-2",
|
|
91
|
-
variant === "primary" && "bg-blue-500 text-white hover:bg-blue-600",
|
|
92
|
-
variant === "secondary" &&
|
|
93
|
-
"bg-gray-200 text-gray-900 hover:bg-gray-300",
|
|
94
|
-
size === "sm" && "h-8 px-3 text-sm",
|
|
95
|
-
size === "md" && "h-10 px-4 text-base",
|
|
96
|
-
size === "lg" && "h-12 px-6 text-lg",
|
|
97
|
-
disabled && "pointer-events-none opacity-50",
|
|
98
|
-
className
|
|
99
|
-
)}
|
|
100
|
-
disabled={disabled}
|
|
101
|
-
>
|
|
102
|
-
Click me
|
|
103
|
-
</button>
|
|
104
|
-
);
|
|
105
|
-
}
|
|
106
|
-
```
|
|
107
|
-
|
|
108
83
|
## API
|
|
109
84
|
|
|
110
85
|
### `cn(...classes)`
|
|
@@ -119,21 +94,9 @@ Combines class names into a single string. Only accepts strings - non-string val
|
|
|
119
94
|
|
|
120
95
|
- `string` - The combined class names separated by spaces
|
|
121
96
|
|
|
122
|
-
## Why @lightsound/cn?
|
|
123
|
-
|
|
124
|
-
| Feature | @lightsound/cn | clsx | clsx/lite |
|
|
125
|
-
| --------------- | -------------- | ----- | --------- |
|
|
126
|
-
| Strings only | ✅ | ❌ | ✅ |
|
|
127
|
-
| Objects support | ❌ | ✅ | ❌ |
|
|
128
|
-
| Arrays support | ❌ | ✅ | ❌ |
|
|
129
|
-
| Size (gzip) | ~139B | ~239B | ~149B |
|
|
130
|
-
| Performance | ⚡⚡⚡ | ⚡⚡ | ⚡⚡ |
|
|
131
|
-
|
|
132
|
-
If you only use string-based class composition (the most common pattern with Tailwind CSS), `@lightsound/cn` provides the best performance.
|
|
133
|
-
|
|
134
97
|
## Compatibility with clsx/lite
|
|
135
98
|
|
|
136
|
-
`@lightsound/cn` is designed as a faster, drop-in replacement for `clsx/lite
|
|
99
|
+
`@lightsound/cn` is designed as a faster, drop-in replacement for `clsx/lite`:
|
|
137
100
|
|
|
138
101
|
```typescript
|
|
139
102
|
// Before
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
function e(){
|
|
1
|
+
function e(){var a=0,l=arguments.length,s="",n;for(;a<l;a++)if(n=arguments[a])s=s?s+" "+n:n;return s}export{e as default,e as cn};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lightsound/cn",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "A tiny, blazing fast utility for constructing className strings conditionally",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -23,7 +23,11 @@
|
|
|
23
23
|
"test": "bun test",
|
|
24
24
|
"test:watch": "bun test --watch",
|
|
25
25
|
"bench": "bun run bench/index.ts",
|
|
26
|
-
"
|
|
26
|
+
"bench:ci": "bun run bench/ci.ts",
|
|
27
|
+
"check-size": "bun run scripts/check-size.ts",
|
|
28
|
+
"update-readme": "bun run scripts/update-readme.ts",
|
|
29
|
+
"prepublishOnly": "bun run build && bun run test",
|
|
30
|
+
"prepare": "husky"
|
|
27
31
|
},
|
|
28
32
|
"keywords": [
|
|
29
33
|
"classnames",
|
|
@@ -46,9 +50,12 @@
|
|
|
46
50
|
},
|
|
47
51
|
"homepage": "https://github.com/lightsound/cn#readme",
|
|
48
52
|
"devDependencies": {
|
|
53
|
+
"@commitlint/cli": "^20.2.0",
|
|
54
|
+
"@commitlint/config-conventional": "^20.2.0",
|
|
49
55
|
"@types/bun": "^1.3.4",
|
|
50
56
|
"@typescript/native-preview": "^7.0.0-dev.20251213.1",
|
|
51
|
-
"clsx": "
|
|
57
|
+
"clsx": "*",
|
|
58
|
+
"husky": "^9.1.7",
|
|
52
59
|
"mitata": "^1.0.34"
|
|
53
60
|
}
|
|
54
61
|
}
|