klsx 0.2.2 → 0.3.1

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
@@ -37,61 +37,110 @@ import { klsx } from 'klsx'
37
37
  klsx('foo', 'bar', 'baz')
38
38
  // => "foo bar baz"
39
39
 
40
- klsx({foo: 'string', bar: true, bux: null }, 'baz')
40
+ klsx({ foo: 'string', bar: true, bux: null }, 'baz')
41
41
  // => "foo bar baz"
42
42
 
43
43
  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
- import React, { useState } from 'react';
53
- import { cn } from 'klsx'
52
+ import React, { useState } from 'react'
53
+ import { kx } from 'klsx'
54
54
 
55
55
  const MyComponent = () => {
56
- const [isActive, setIsActive] = useState(false);
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
- </div>
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
- </div>
66
-
67
- <div className={cn('base-class', [isActive && 'active', !isActive && 'inactive'])}>
65
+ </div>
66
+
67
+ <div
68
+ className={kx('base-class', [isActive && 'active', !isActive && 'inactive'])}
69
+ >
68
70
  {/* ... */}
69
- </div>
71
+ </div>
70
72
  </div>
71
- );
72
- };
73
+ )
74
+ }
75
+ ```
76
+
77
+ ### Migrate from `clsx`
78
+
79
+ Just replace every `c` with a `k`, as in the example below.
80
+
81
+ From:
82
+
83
+ ```typescript
84
+ // clsx
85
+
86
+ import { clsx, type ClassValue } from 'clsx'
87
+ import { twMerge } from 'tailwind-merge'
88
+
89
+ export function cn(...inputs: ClassValue[]) {
90
+ return twMerge(clsx(inputs))
91
+ }
92
+ ```
93
+
94
+ To:
95
+
96
+ ```typescript
97
+ // KLSX
98
+
99
+ import { klsx, type KlassValue } from 'klsx'
100
+ import { twMerge } from 'tailwind-merge'
101
+
102
+ export function cn(...inputs: KlassValue[]) {
103
+ return twMerge(klsx(inputs))
104
+ }
73
105
  ```
74
106
 
75
107
  ## Integrations
76
108
 
77
109
  ### Tailwind CSS
78
110
 
79
- <details open>
80
- <summary>
81
- Visual Studio Code
82
- </summary>
111
+ #### Visual Studio Code
83
112
 
84
- 1. Install the [Tailwind CSS IntelliSense](https://marketplace.visualstudio.com/items?itemName=bradlc.vscode-tailwindcss) extension.
113
+ 1. Install the [Tailwind CSS IntelliSense](https://marketplace.visualstudio.com/items?itemName=bradlc.vscode-tailwindcss) extension:
114
+
115
+ ```bash
116
+ code --install-extension bradlc.vscode-tailwindcss
117
+ ```
85
118
 
86
119
  2. Update your [`settings.json`](https://code.visualstudio.com/docs/getstarted/settings) configuration with:
87
120
 
88
121
  ```json
89
122
  {
90
- "tailwindCSS.classFunctions": ["klsx", "cn"]
123
+ "tailwindCSS.classFunctions": ["klsx", "kx"]
91
124
  }
92
125
  ```
93
126
 
94
- </details>
127
+ #### Prettier
128
+
129
+ 1. Install the [prettier-plugin-tailwindcss](https://www.npmjs.com/package/prettier-plugin-tailwindcss) plugin:
130
+
131
+ ```bash
132
+ bun add -D prettier prettier-plugin-tailwindcss
133
+ ```
134
+
135
+ 2. Update your `prettier.config.js` configuration to handle `klsx`:
136
+
137
+ ```javascript
138
+ /** @type {import('prettier').Config & import('prettier-plugin-tailwindcss').PluginOptions} */
139
+ export default {
140
+ plugins: ['prettier-plugin-tailwindcss'],
141
+ tailwindFunctions: ['klsx', 'kx'],
142
+ }
143
+ ```
95
144
 
96
145
  ### ESLint
97
146
 
@@ -103,7 +152,7 @@ bun add -D eslint eslint-plugin-clsx
103
152
 
104
153
  2. Update your `eslint.config.js` configuration to handle `klsx`:
105
154
 
106
- ```typescript
155
+ ```javascript
107
156
  import { defineConfig } from 'eslint/config'
108
157
  import clsx from 'eslint-plugin-clsx'
109
158
 
@@ -111,7 +160,7 @@ export default defineConfig({
111
160
  plugins: { clsx },
112
161
  settings: {
113
162
  clsxOptions: {
114
- klsx: ['default', 'klsx', 'cn'],
163
+ klsx: ['default', 'klsx', 'kx'],
115
164
  },
116
165
  },
117
166
  })
@@ -144,7 +193,3 @@ Run benchmark suite:
144
193
  ```bash
145
194
  bun bench
146
195
  ```
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.1",
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
  }