clsx
2.1.1 · 23 Apr 2024MIT179.1M / weekRepositoryHomepagenpmAtom feed
14 stable releases, newest first, by release line. Notes are quoted as the maintainers published them.
- 2.x · latest line
2.1.1
23 Apr 2024(types) Include
bigintinClassValuetype: (#96): 3d960ab
Accommodates recent@types/reactchanges toReactNode.
Thank you @ViliamKopecky~!
Patches
(types) Include
bigintinClassValuetype: (#96): 3d960ab
Accommodates recent@types/reactchanges toReactNode.
Thank you @ViliamKopecky~!
Chores
Full Changelog: v2.1.0...v2.1.1
2.1.0
29 Dec 2023Add new
clsx/litesubmodule forstring-only usage: 1a49142This is a 140b version of
clsxthat is ideal for Tailwind and/or React contexts, which typically follow thisclsxusage pattern:clsx('foo bar', props.maybe && 'conditional classes', props.className);Important: This
clsx/litemodule ignores all non-string arguments and is therefore not a 1:1 replacement forclsxitself!import { clsx } from 'clsx'; import { clsx as lite } from 'clsx/lite'; // strings-only usage is identical clsx('foo', null, 'bar', true && 'baz'); //=> "foo bar baz" lite('foo', null, 'bar', true && 'baz'); //=> "foo bar baz" // clsx/lite ignores all non-strings clsx('foo', { a: true, b: false, c: true }); //=> "foo a c" lite('foo', { a: true, b: false, c: true }); //=> "foo"
2.0.1
29 Dec 2023(perf) Cache
arguments.length&array.lengthfor 6% performance gain (#26): deff09b
Adds 5 bytes (+2%) for ~3% avg performance gain
Thank you @jalalazimi
Patches
(perf) Cache
arguments.length&array.lengthfor 6% performance gain (#26): deff09b
Adds 5 bytes (+2%) for ~3% avg performance gain
Thank you @jalalazimi
Chores
Full Changelog: v2.0.0...v2.0.1
2.0.0
15 Jul 2023- Breaking
Add
"exports"map for native ESM support (#57): 3ec8e9f, 0949868
Also supports TypeScript'snode16/nodenextmodule resolution
Maintains CommonJS support (with fixed TS definitions)
Thank you @remcohaszing~!
Breaking
- Breaking
Add
"exports"map for native ESM support (#57): 3ec8e9f, 0949868
Also supports TypeScript'snode16/nodenextmodule resolution
Maintains CommonJS support (with fixed TS definitions)
Thank you @remcohaszing~!
Chores
Full Changelog: v1.2.1...v2.0.0
- 1.x
1.2.1
6 Jul 2022Ensure CommonJS and UMD entrypoints have the named
clsxexport too
Patches
Ensure CommonJS and UMD entrypoints have the named
clsxexport too
Chores
Full Changelog: v1.2.0...v1.2.1
1.2.0
2 Jul 2022Add named
clsxexport alias (#43, #44): 56ab81f
Thank you @danikaze~!
This is purely an alias for the default export so that TypeScript users can avoid theesModuleInteropsetting. In other words, the followimportstatements are effectively identical, but the latter is preferred by TypeScript:import clsx from 'clsx'; // or import { clsx } from 'clsx';Important: Just to reiterate, both still work!
Features
Add named
clsxexport alias (#43, #44): 56ab81f
Thank you @danikaze~!
This is purely an alias for the default export so that TypeScript users can avoid theesModuleInteropsetting. In other words, the followimportstatements are effectively identical, but the latter is preferred by TypeScript:import clsx from 'clsx'; // or import { clsx } from 'clsx';Important: Just to reiterate, both still work!
Chores
Full Changelog: v1.1.1...v1.2.0
1.1.1
30 May 2020Remove needless spacer on string/number condition: ff11464
Remove unnecessary recursive caller for object keys: f43dd23
Note: This is a performance-related patch only!Across all benchmarks, this version of
clsxis ~1M ops/sec faster thanclsx@1.1.0....It also happens to be 1 byte (gzip) smaller 😅🎉Patches
Remove needless spacer on string/number condition: ff11464
Remove unnecessary recursive caller for object keys: f43dd23
Guard all
toValcalls with truthy assertions: 4fa8811, 019ec02Reorder
typeofchecks for common case: 08a5a7f
Benchmarks
Run on Node.js v10.13.0.You may find updated browser benchmarks here.
The snippet below is comparing
clsx@1.1.1(this version) to the previous version, and toclassnamesfor ballpark comparison. All candidates are functionally identical!# Strings classnames x 3,992,284 ops/sec ±1.64% (94 runs sampled) clsx@1.1.0 x 11,253,372 ops/sec ±0.35% (96 runs sampled) clsx@1.1.1 x 12,784,134 ops/sec ±0.42% (97 runs sampled) # Objects classnames x 3,772,978 ops/sec ±0.46% (96 runs sampled) clsx@1.1.0 x 7,288,178 ops/sec ±0.31% (96 runs sampled) clsx@1.1.1 x 9,412,010 ops/sec ±0.42% (95 runs sampled) # Arrays classnames x 1,665,275 ops/sec ±1.83% (93 runs sampled) clsx@1.1.0 x 8,340,174 ops/sec ±0.53% (96 runs sampled) clsx@1.1.1 x 9,141,916 ops/sec ±0.42% (95 runs sampled) # Nested Arrays classnames x 1,164,706 ops/sec ±1.60% (95 runs sampled) clsx@1.1.0 x 6,284,485 ops/sec ±0.58% (90 runs sampled) clsx@1.1.1 x 7,165,151 ops/sec ±0.47% (91 runs sampled) # Nested Arrays w/ Objects classnames x 1,597,180 ops/sec ±1.49% (93 runs sampled) clsx@1.1.0 x 6,345,248 ops/sec ±0.21% (95 runs sampled) clsx@1.1.1 x 7,651,411 ops/sec ±0.56% (95 runs sampled) # Mixed classnames x 2,129,199 ops/sec ±1.46% (94 runs sampled) clsx@1.1.0 x 6,557,515 ops/sec ±0.73% (91 runs sampled) clsx@1.1.1 x 8,119,210 ops/sec ±0.42% (93 runs sampled) # Mixed (Bad Data) classnames x 1,166,577 ops/sec ±0.84% (94 runs sampled) clsx@1.1.0 x 2,018,654 ops/sec ±0.15% (98 runs sampled) clsx@1.1.1 x 2,238,939 ops/sec ±0.34% (95 runs sampled)
1.1.0
3 Feb 2020Use
Array.isArrayfor properArraytype-checking (#17): 0d6023aThis prevents an object with a truthy
pushkey from being treated as an Array. While (likely) rare, this produced an incorrect result.Important: Because of this change, Internet Explorer 8 (and older) are no longer supported.If you happen to require support for these browsers, please continue to use the
1.0.xversion range.
Minor / Patch
Use
Array.isArrayfor properArraytype-checking (#17): 0d6023aThis prevents an object with a truthy
pushkey from being treated as an Array. While (likely) rare, this produced an incorrect result.Important: Because of this change, Internet Explorer 8 (and older) are no longer supported.If you happen to require support for these browsers, please continue to use the
1.0.xversion range.
1.0.4
6 Apr 2019Ignore function arguments: 4aff569
Separate Array and Object loops: 91f5e68
While this did add ~20 bytes to the package (which is a 10% size increase), it made any Array interactions 200% to 600% faster! 🎉 Below is a performance comparison between
clsx@1.0.3andclsx@1.0.4running on Node v10.13.0:# Strings clsx (prev) x 10,661,038 ops/sec ±0.46% (92 runs sampled) clsx x 11,066,632 ops/sec ±0.23% (96 runs sampled) # Objects clsx (prev) x 6,934,269 ops/sec ±0.23% (94 runs sampled) clsx x 7,147,168 ops/sec ±0.30% (95 runs sampled) # Arrays clsx (prev) x 1,681,568 ops/sec ±0.32% (97 runs sampled) clsx x 7,922,225 ops/sec ±0.18% (95 runs sampled) # Nested Arrays clsx (prev) x 940,741 ops/sec ±0.33% (96 runs sampled) clsx x 6,132,222 ops/sec ±0.49% (95 runs sampled) # Nested Arrays w/ Objects clsx (prev) x 1,428,975 ops/sec ±0.15% (95 runs sampled) clsx x 5,156,844 ops/sec ±0.22% (95 runs sampled) # Mixed clsx (prev) x 2,198,907 ops/sec ±0.34% (98 runs sampled) clsx x 5,577,715 ops/sec ±0.20% (93 runs sampled) # Mixed (Bad Data) clsx (prev) x 1,038,752 ops/sec ±0.32% (94 runs sampled) clsx x 1,887,010 ops/sec ±0.14% (96 runs sampled)
Patches
Ignore function arguments: 4aff569
Separate Array and Object loops: 91f5e68
While this did add ~20 bytes to the package (which is a 10% size increase), it made any Array interactions 200% to 600% faster! 🎉 Below is a performance comparison between
clsx@1.0.3andclsx@1.0.4running on Node v10.13.0:# Strings clsx (prev) x 10,661,038 ops/sec ±0.46% (92 runs sampled) clsx x 11,066,632 ops/sec ±0.23% (96 runs sampled) # Objects clsx (prev) x 6,934,269 ops/sec ±0.23% (94 runs sampled) clsx x 7,147,168 ops/sec ±0.30% (95 runs sampled) # Arrays clsx (prev) x 1,681,568 ops/sec ±0.32% (97 runs sampled) clsx x 7,922,225 ops/sec ±0.18% (95 runs sampled) # Nested Arrays clsx (prev) x 940,741 ops/sec ±0.33% (96 runs sampled) clsx x 6,132,222 ops/sec ±0.49% (95 runs sampled) # Nested Arrays w/ Objects clsx (prev) x 1,428,975 ops/sec ±0.15% (95 runs sampled) clsx x 5,156,844 ops/sec ±0.22% (95 runs sampled) # Mixed clsx (prev) x 2,198,907 ops/sec ±0.34% (98 runs sampled) clsx x 5,577,715 ops/sec ±0.20% (93 runs sampled) # Mixed (Bad Data) clsx (prev) x 1,038,752 ops/sec ±0.32% (94 runs sampled) clsx x 1,887,010 ops/sec ±0.14% (96 runs sampled)
1.0.2
3 Feb 2019Allow
undefinedin TypeScript definitions (#6): af56fa4
Thank you @chulanovskyi!
1.0.0
25 Dec 2018- 0.0.x
0.0.1
24 Dec 2018
A whole project to check? Paste its package.json in the dependency check: every deprecated, outdated or vulnerable dependency, with what to upgrade to. Free, no account.