klsx 0.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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Walter Purcaro
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,112 @@
1
+ # KLSX
2
+
3
+ A simple replacement for [clsx](https://github.com/lukeed/clsx) **_you may not actually need_** (see [benchmark](#benchmark)).
4
+
5
+ Developed as a case study.
6
+
7
+ ## Installation
8
+
9
+ To install dependencies:
10
+
11
+ ```bash
12
+ bun install
13
+ ```
14
+
15
+ To build:
16
+
17
+ ```bash
18
+ bun run build
19
+ ```
20
+
21
+ ## Testing
22
+
23
+ To run test suite:
24
+
25
+ ```bash
26
+ bun test
27
+ ```
28
+
29
+ To run benchmark suite:
30
+
31
+ ```bash
32
+ bun bench
33
+ ```
34
+
35
+ ## Usage
36
+
37
+ Using the function name `klsx`:
38
+
39
+ ```typescript
40
+ import { klsx } from 'klsx'
41
+
42
+ klsx('foo', 'bar') // -> "foo bar"
43
+ klsx('foo', { bar: true, bux: false }, 'baz') // -> "foo bar baz"
44
+ klsx('foo', [0, 'bar', [{ bux: null, baz: 'I am not empty' }, undefined], 'bax']) // -> "foo bar baz bax"
45
+ ```
46
+
47
+ Using its short alias `cn`:
48
+
49
+ ```typescript
50
+ import { cn } from 'klsx'
51
+
52
+ cn('foo', 'bar') // -> "foo bar"
53
+ cn('foo', { bar: true, bux: false }, 'baz') // -> "foo bar baz"
54
+ cn('foo', [0, 'bar', [{ bux: null, baz: 'I am not empty' }, undefined], 'bax']) // -> "foo bar baz bax"
55
+ ```
56
+
57
+ ## Case Study
58
+
59
+ _Coming soon..._
60
+
61
+ ## Benchmark
62
+
63
+ Results of 10ms tests in [Bun](https://bun.com) v1.3.2 _(tl;dr: **KLSX is the fastest, but the gap is negligible**)_:
64
+
65
+ ```bash
66
+ Benchmark (short strings)
67
+ ┌───┬────────────┬──────────────────┬──────────────────┬────────────────────────┬────────────────────────┬─────────┐
68
+ │ │ Task name │ Latency avg (ns) │ Latency med (ns) │ Throughput avg (ops/s) │ Throughput med (ops/s) │ Samples │
69
+ ├───┼────────────┼──────────────────┼──────────────────┼────────────────────────┼────────────────────────┼─────────┤
70
+ │ 0 │ KLSX │ 56.46 ± 0.68% │ 42.00 ± 1.00 │ 20554389 ± 0.13% │ 23809524 ± 580720 │ 177109 │
71
+ │ 1 │ classix │ 58.41 ± 4.33% │ 42.00 ± 1.00 │ 20227141 ± 0.13% │ 23809524 ± 580720 │ 171195 │
72
+ │ 2 │ clsx │ 55.72 ± 0.28% │ 42.00 ± 1.00 │ 20357130 ± 0.13% │ 23809524 ± 580720 │ 179455 │
73
+ │ 3 │ classnames │ 58.06 ± 4.55% │ 42.00 ± 1.00 │ 20150251 ± 0.13% │ 23809524 ± 580720 │ 172248 │
74
+ └───┴────────────┴──────────────────┴──────────────────┴────────────────────────┴────────────────────────┴─────────┘
75
+
76
+ Benchmark (long strings)
77
+ ┌───┬────────────┬──────────────────┬──────────────────┬────────────────────────┬────────────────────────┬─────────┐
78
+ │ │ Task name │ Latency avg (ns) │ Latency med (ns) │ Throughput avg (ops/s) │ Throughput med (ops/s) │ Samples │
79
+ ├───┼────────────┼──────────────────┼──────────────────┼────────────────────────┼────────────────────────┼─────────┤
80
+ │ 0 │ KLSX │ 135.32 ± 5.93% │ 125.00 ± 0.00 │ 9377312 ± 0.19% │ 8000000 ± 0 │ 73900 │
81
+ │ 1 │ classix │ 174.34 ± 0.75% │ 125.00 ± 0.00 │ 6765287 ± 0.20% │ 8000000 ± 0 │ 57360 │
82
+ │ 2 │ clsx │ 222.94 ± 6.05% │ 167.00 ± 1.00 │ 5421387 ± 0.20% │ 5988024 ± 36072 │ 44855 │
83
+ │ 3 │ classnames │ 147.47 ± 0.53% │ 125.00 ± 0.00 │ 7482902 ± 0.13% │ 8000000 ± 0 │ 67812 │
84
+ └───┴────────────┴──────────────────┴──────────────────┴────────────────────────┴────────────────────────┴─────────┘
85
+
86
+ Benchmark (objects)
87
+ ┌───┬────────────┬──────────────────┬──────────────────┬────────────────────────┬────────────────────────┬─────────┐
88
+ │ │ Task name │ Latency avg (ns) │ Latency med (ns) │ Throughput avg (ops/s) │ Throughput med (ops/s) │ Samples │
89
+ ├───┼────────────┼──────────────────┼──────────────────┼────────────────────────┼────────────────────────┼─────────┤
90
+ │ 0 │ KLSX │ 98.96 ± 1.29% │ 83.00 ± 0.00 │ 11274574 ± 0.10% │ 12048193 ± 0 │ 101049 │
91
+ │ 1 │ clsx │ 105.39 ± 0.68% │ 83.00 ± 0.00 │ 10986267 ± 0.13% │ 12048193 ± 0 │ 94887 │
92
+ │ 2 │ classnames │ 97.48 ± 0.42% │ 83.00 ± 0.00 │ 11183838 ± 0.11% │ 12048193 ± 0 │ 102591 │
93
+ └───┴────────────┴──────────────────┴──────────────────┴────────────────────────┴────────────────────────┴─────────┘
94
+
95
+ Benchmark (arrays)
96
+ ┌───┬────────────┬──────────────────┬──────────────────┬────────────────────────┬────────────────────────┬─────────┐
97
+ │ │ Task name │ Latency avg (ns) │ Latency med (ns) │ Throughput avg (ops/s) │ Throughput med (ops/s) │ Samples │
98
+ ├───┼────────────┼──────────────────┼──────────────────┼────────────────────────┼────────────────────────┼─────────┤
99
+ │ 0 │ KLSX │ 91.37 ± 0.71% │ 83.00 ± 0.00 │ 11628447 ± 0.08% │ 12048193 ± 0 │ 109448 │
100
+ │ 1 │ clsx │ 140.18 ± 9.28% │ 125.00 ± 0.00 │ 8325415 ± 0.16% │ 8000000 ± 0 │ 71340 │
101
+ │ 2 │ classnames │ 137.70 ± 0.34% │ 125.00 ± 0.00 │ 7673930 ± 0.11% │ 8000000 ± 0 │ 72624 │
102
+ └───┴────────────┴──────────────────┴──────────────────┴────────────────────────┴────────────────────────┴─────────┘
103
+
104
+ Benchmark (mixed)
105
+ ┌───┬────────────┬──────────────────┬──────────────────┬────────────────────────┬────────────────────────┬─────────┐
106
+ │ │ Task name │ Latency avg (ns) │ Latency med (ns) │ Throughput avg (ops/s) │ Throughput med (ops/s) │ Samples │
107
+ ├───┼────────────┼──────────────────┼──────────────────┼────────────────────────┼────────────────────────┼─────────┤
108
+ │ 0 │ KLSX │ 120.19 ± 6.40% │ 125.00 ± 41.00 │ 9823538 ± 0.16% │ 8000000 ± 3904762 │ 83200 │
109
+ │ 1 │ clsx │ 150.46 ± 6.24% │ 125.00 ± 0.00 │ 7441597 ± 0.13% │ 8000000 ± 0 │ 66465 │
110
+ │ 2 │ classnames │ 179.99 ± 5.99% │ 167.00 ± 0.00 │ 6080521 ± 0.13% │ 5988024 ± 0 │ 55558 │
111
+ └───┴────────────┴──────────────────┴──────────────────┴────────────────────────┴────────────────────────┴─────────┘
112
+ ```
@@ -0,0 +1,4 @@
1
+ //#region src/cn.d.ts
2
+ declare function cn(...args: ClsnValue[]): string;
3
+ //#endregion
4
+ export { cn as clsn, cn, cn as default };
package/dist/index.js ADDED
@@ -0,0 +1 @@
1
+ function e(t){let n=``;for(let r of t)if(r){if(typeof r==`string`)n=n?n+` `+r:r;else if(typeof r==`object`)if(Array.isArray(r)){let t=e(r);t&&(n=n?n+` `+t:t)}else for(let e in r)r[e]&&(n=n?n+` `+e:e)}return n}function t(...t){return e(t)}export{t as clsn,t as cn,t as default};
package/package.json ADDED
@@ -0,0 +1,72 @@
1
+ {
2
+ "name": "klsx",
3
+ "type": "module",
4
+ "version": "0.1.0",
5
+ "description": "Same as clsx but \"maybe\" better",
6
+ "author": {
7
+ "name": "Walter Purcaro",
8
+ "url": "https://github.com/vuolter"
9
+ },
10
+ "license": "MIT",
11
+ "repository": {
12
+ "type": "git",
13
+ "url": "git+https://github.com/vuolter/klsx.git"
14
+ },
15
+ "keywords": [
16
+ "cn",
17
+ "cx",
18
+ "klsx",
19
+ "clsx",
20
+ "classix",
21
+ "classname",
22
+ "classnames",
23
+ "bun"
24
+ ],
25
+ "exports": {
26
+ ".": "./dist/index.js",
27
+ "./package.json": "./package.json"
28
+ },
29
+ "main": "./dist/index.js",
30
+ "module": "./dist/index.js",
31
+ "types": "./dist/index.d.ts",
32
+ "files": [
33
+ "dist"
34
+ ],
35
+ "engines": {
36
+ "node": ">=18"
37
+ },
38
+ "url": "https://github.com/vuolter/klsx",
39
+ "scripts": {
40
+ "build": "bun typecheck && tsdown",
41
+ "format": "prettier . --cache --experimental-cli --write",
42
+ "lint": "eslint --cache --cache-location ./node_modules/.cache/eslint --cache-strategy content --concurrency auto --fix .",
43
+ "typecheck": "tsgo",
44
+ "bench": "bun ./tests/bench",
45
+ "postinstall": "npm install --force --ignore-scripts --package-lock-only --silent"
46
+ },
47
+ "devDependencies": {
48
+ "@eslint/js": "^9.39.1",
49
+ "@prettier/plugin-oxc": "^0.0.5",
50
+ "@socketsecurity/bun-security-scanner": "^1.1.1",
51
+ "@types/bun": "^1.3.2",
52
+ "@typescript/native-preview": "^7.0.0-dev.20251120.1",
53
+ "classix": "^2.2.6",
54
+ "classnames": "^2.5.1",
55
+ "clsx": "^2.1.1",
56
+ "eslint": "^9.39.1",
57
+ "eslint-config-prettier": "^10.1.8",
58
+ "eslint-import-resolver-typescript": "^4.4.4",
59
+ "eslint-plugin-import-x": "^4.16.1",
60
+ "eslint-plugin-perfectionist": "^4.15.1",
61
+ "eslint-plugin-regexp": "^2.10.0",
62
+ "eslint-plugin-security": "^3.0.1",
63
+ "eslint-plugin-sonarjs": "^3.0.5",
64
+ "eslint-plugin-tsdoc": "^0.5.0",
65
+ "eslint-plugin-unicorn": "^62.0.0",
66
+ "globals": "^16.5.0",
67
+ "prettier": "^3.6.2",
68
+ "tinybench": "^5.1.0",
69
+ "tsdown": "^0.16.6",
70
+ "typescript-eslint": "^8.47.0"
71
+ }
72
+ }