klsx 0.2.2 → 0.3.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/README.md CHANGED
@@ -44,27 +44,27 @@ klsx(['foo', ['bar', true && 'baz']])
44
44
  // => "foo bar baz"
45
45
  ```
46
46
 
47
- or importing the short alias `cn`:
47
+ or importing the short alias `kx`:
48
48
 
49
49
  ### React
50
50
 
51
51
  ```jsx
52
52
  import React, { useState } from 'react';
53
- import { cn } from 'klsx'
53
+ import { kx } from 'klsx'
54
54
 
55
55
  const MyComponent = () => {
56
56
  const [isActive, setIsActive] = useState(false);
57
57
  return (
58
58
  <div>
59
- <div className={cn('base-class', isActive ? 'active' : 'inactive')}>
59
+ <div className={kx('base-class', isActive ? 'active' : 'inactive')}>
60
60
  {/* ... */}
61
61
  </div>
62
62
 
63
- <div className={cn('base-class', {'active': isActive, 'inactive': !isActive})}>
63
+ <div className={kx('base-class', {'active': isActive, 'inactive': !isActive})}>
64
64
  {/* ... */}
65
65
  </div>
66
66
 
67
- <div className={cn('base-class', [isActive && 'active', !isActive && 'inactive'])}>
67
+ <div className={kx('base-class', [isActive && 'active', !isActive && 'inactive'])}>
68
68
  {/* ... */}
69
69
  </div>
70
70
  </div>
@@ -72,26 +72,73 @@ const MyComponent = () => {
72
72
  };
73
73
  ```
74
74
 
75
+ ### Migrate from `clsx`
76
+
77
+ Just replace every `c` with a `k`, as in the example below.
78
+
79
+ From:
80
+
81
+ ```typescript
82
+ // clsx
83
+
84
+ import { clsx, type ClassValue } from "clsx"
85
+ import { twMerge } from "tailwind-merge"
86
+
87
+ export function cn(...inputs: ClassValue[]) {
88
+ return twMerge(clsx(inputs))
89
+ }
90
+ ```
91
+
92
+ To:
93
+
94
+ ```typescript
95
+ // KLSX
96
+
97
+ import { klsx, type KlassValue } from "klsx"
98
+ import { twMerge } from "tailwind-merge"
99
+
100
+ export function cn(...inputs: ClassValue[]) {
101
+ return twMerge(klsx(inputs))
102
+ }
103
+ ```
104
+
75
105
  ## Integrations
76
106
 
77
107
  ### Tailwind CSS
78
108
 
79
- <details open>
80
- <summary>
81
- Visual Studio Code
82
- </summary>
109
+ #### Visual Studio Code
83
110
 
84
- 1. Install the [Tailwind CSS IntelliSense](https://marketplace.visualstudio.com/items?itemName=bradlc.vscode-tailwindcss) extension.
111
+ 1. Install the [Tailwind CSS IntelliSense](https://marketplace.visualstudio.com/items?itemName=bradlc.vscode-tailwindcss) extension:
112
+
113
+ ```bash
114
+ code --install-extension bradlc.vscode-tailwindcss
115
+ ```
85
116
 
86
117
  2. Update your [`settings.json`](https://code.visualstudio.com/docs/getstarted/settings) configuration with:
87
118
 
88
119
  ```json
89
120
  {
90
- "tailwindCSS.classFunctions": ["klsx", "cn"]
121
+ "tailwindCSS.classFunctions": ["klsx", "kx"]
91
122
  }
92
123
  ```
93
124
 
94
- </details>
125
+ #### Prettier
126
+
127
+ 1. Install the [prettier-plugin-tailwindcss](https://www.npmjs.com/package/prettier-plugin-tailwindcss) plugin:
128
+
129
+ ```bash
130
+ bun add -D prettier prettier-plugin-tailwindcss
131
+ ```
132
+
133
+ 2. Update your `prettier.config.js` configuration to handle `klsx`:
134
+
135
+ ```javascript
136
+ /** @type {import('prettier').Config & import('prettier-plugin-tailwindcss').PluginOptions} */
137
+ export default {
138
+ plugins: ["prettier-plugin-tailwindcss"],
139
+ tailwindFunctions: ['klsx', 'kx']
140
+ }
141
+ ```
95
142
 
96
143
  ### ESLint
97
144
 
@@ -103,7 +150,7 @@ bun add -D eslint eslint-plugin-clsx
103
150
 
104
151
  2. Update your `eslint.config.js` configuration to handle `klsx`:
105
152
 
106
- ```typescript
153
+ ```javascript
107
154
  import { defineConfig } from 'eslint/config'
108
155
  import clsx from 'eslint-plugin-clsx'
109
156
 
@@ -111,7 +158,7 @@ export default defineConfig({
111
158
  plugins: { clsx },
112
159
  settings: {
113
160
  clsxOptions: {
114
- klsx: ['default', 'klsx', 'cn'],
161
+ klsx: ['default', 'klsx', 'kx'],
115
162
  },
116
163
  },
117
164
  })
@@ -144,7 +191,3 @@ Run benchmark suite:
144
191
  ```bash
145
192
  bun bench
146
193
  ```
147
-
148
- ## Case Study
149
-
150
- _Coming soon..._
package/dist/index.d.ts CHANGED
@@ -1,4 +1,9 @@
1
- //#region src/cn.d.ts
2
- declare function cn(...args: KlsxValue[]): string;
1
+ //#region src/types.d.ts
2
+ type KlassObject = Record<string, boolean | unknown>;
3
+ type KlassArray = KlassValue[];
4
+ type KlassValue = bigint | boolean | KlassArray | KlassObject | null | number | string | undefined;
3
5
  //#endregion
4
- export { cn, cn as default, cn as klsx };
6
+ //#region src/kx.d.ts
7
+ declare function kx(...args: KlassValue[]): string;
8
+ //#endregion
9
+ export { type KlassArray, type KlassObject, type KlassValue, kx as default, kx as klsx, kx };
package/dist/index.js CHANGED
@@ -1 +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 cn,t as default,t as klsx};
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 default,t as klsx,t as kx};
package/package.json CHANGED
@@ -1,22 +1,54 @@
1
1
  {
2
2
  "name": "klsx",
3
- "version": "0.2.2",
3
+ "version": "0.3.0",
4
+ "type": "module",
5
+ "description": "Same as clsx but \"maybe\" better",
4
6
  "author": {
5
7
  "name": "Walter Purcaro",
6
8
  "url": "https://github.com/vuolter"
7
9
  },
10
+ "license": "MIT",
8
11
  "repository": {
9
12
  "type": "git",
10
13
  "url": "git+https://github.com/vuolter/klsx.git"
11
14
  },
15
+ "url": "https://github.com/vuolter/klsx",
16
+ "keywords": [
17
+ "cn",
18
+ "cx",
19
+ "kx",
20
+ "klsx",
21
+ "clsx",
22
+ "class",
23
+ "classix",
24
+ "classname",
25
+ "classnames",
26
+ "bun"
27
+ ],
28
+ "files": [
29
+ "dist"
30
+ ],
12
31
  "main": "./dist/index.js",
13
32
  "module": "./dist/index.js",
33
+ "types": "./dist/index.d.ts",
34
+ "exports": {
35
+ ".": "./dist/index.js",
36
+ "./package.json": "./package.json"
37
+ },
38
+ "scripts": {
39
+ "build": "bun compile && tsdown",
40
+ "format": "prettier . --cache --experimental-cli --write",
41
+ "lint": "eslint --cache --cache-location ./node_modules/.cache/eslint --cache-strategy content --concurrency auto --fix .",
42
+ "compile": "tsgo",
43
+ "bench": "bun ./tests/bench",
44
+ "postinstall": "npm install --force --ignore-scripts --package-lock-only --silent"
45
+ },
14
46
  "devDependencies": {
15
47
  "@eslint/js": "^9.39.1",
16
- "@prettier/plugin-oxc": "^0.0.5",
48
+ "@prettier/plugin-oxc": "^0.1.2",
17
49
  "@socketsecurity/bun-security-scanner": "^1.1.1",
18
50
  "@types/bun": "^1.3.3",
19
- "@typescript/native-preview": "^7.0.0-dev.20251123.1",
51
+ "@typescript/native-preview": "^7.0.0-dev.20251201.1",
20
52
  "classix": "^2.2.6",
21
53
  "classnames": "^2.5.1",
22
54
  "clsx": "^2.1.1",
@@ -31,44 +63,13 @@
31
63
  "eslint-plugin-tsdoc": "^0.5.0",
32
64
  "eslint-plugin-unicorn": "^62.0.0",
33
65
  "globals": "^16.5.0",
34
- "prettier": "^3.6.2",
35
- "tinybench": "^5.1.0",
36
- "tsdown": "^0.16.6",
37
- "typescript-eslint": "^8.47.0"
66
+ "prettier": "^3.7.3",
67
+ "tinybench": "^6.0.0",
68
+ "tsdown": "^0.17.0-beta.5",
69
+ "typescript-eslint": "^8.48.0"
38
70
  },
39
- "exports": {
40
- ".": "./dist/index.js",
41
- "./package.json": "./package.json"
42
- },
43
- "description": "Same as clsx but \"maybe\" better",
44
71
  "engines": {
45
72
  "node": ">=18"
46
73
  },
47
- "files": [
48
- "dist"
49
- ],
50
- "keywords": [
51
- "cn",
52
- "cx",
53
- "klsx",
54
- "clsx",
55
- "class",
56
- "classix",
57
- "classname",
58
- "classnames",
59
- "bun"
60
- ],
61
- "license": "MIT",
62
- "scripts": {
63
- "build": "bun typecheck && tsdown",
64
- "format": "prettier . --cache --experimental-cli --write",
65
- "lint": "eslint --cache --cache-location ./node_modules/.cache/eslint --cache-strategy content --concurrency auto --fix .",
66
- "typecheck": "tsgo",
67
- "bench": "bun ./tests/bench",
68
- "postinstall": "npm install --force --ignore-scripts --package-lock-only --silent"
69
- },
70
- "sideEffects": false,
71
- "type": "module",
72
- "types": "./dist/index.d.ts",
73
- "url": "https://github.com/vuolter/klsx"
74
+ "sideEffects": false
74
75
  }