Installations
npm install babel-plugin-transform-jsx-classnames
Developer Guide
Typescript
No
Module System
CommonJS
Min. Node Version
>= 8.0
Node Version
18.16.0
NPM Version
9.5.1
Score
77.3
Supply Chain
99.5
Quality
75.5
Maintenance
100
Vulnerability
100
License
Releases
Unable to fetch releases
Contributors
Unable to fetch Contributors
Languages
JavaScript (100%)
Developer
gtournie
Download Statistics
Total Downloads
6,012
Last Day
2
Last Week
28
Last Month
65
Last Year
3,530
GitHub Statistics
5 Stars
8 Commits
1 Forks
3 Watching
1 Branches
1 Contributors
Bundle Size
4.77 kB
Minified
1.93 kB
Minified + Gzipped
Package Meta Information
Latest Version
1.2.2
Package Id
babel-plugin-transform-jsx-classnames@1.2.2
Unpacked Size
366.06 kB
Size
85.23 kB
File Count
24
NPM Version
9.5.1
Node Version
18.16.0
Publised On
21 Jun 2023
Total Downloads
Cumulative downloads
Total Downloads
6,012
Last day
-80%
2
Compared to previous day
Last week
64.7%
28
Compared to previous week
Last month
51.2%
65
Compared to previous month
Last year
218%
3,530
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
babel-plugin-transform-jsx-classnames
className and styleName on steroids 💪
Usage
Allow you to write jsx classNames in a simpler way, without having to worry about importing a helper (like clsx or classnames). className
or styleName
attributes take any number of arguments which can be a string, an array or an object (if the value associated with a given key is falsy, that key won't be included in the output). See examples
Install
When babel-plugin-transform-jsx-classnames cannot resolve className
/ styleName
during compilation, it imports a helper function (read build time resolution). Therefore, you must install babel-plugin-react-css-modules as a direct dependency of the project.
1$ npm install babel-plugin-transform-jsx-classnames --save
1{ 2 plugins: [ 3 ['transform-jsx-classnames', { 4 // default options 5 dedupe: false, 6 attributes: ['className', 'styleName'] 7 }] 8 ] 9}
Note: ⚠️ If you're using
babel-plugin-react-css-modules
, ensure you're addingtransform-jsx-classnames
before
Build time resolution
The plugin will try to resolve the className
/ styleName
during the compilation (className={"foo", { active: true }}
) and fallback to runtime if not possible (className={_cx("bar", { disabled: props.disabled })}
- a tiny helper (256B minified) will be included automatically.
Runtime helper
The runtime helper is similar to the clsx package. See examples.
dedupe
Dedupe behaves like the classname dedupe version. Way faster though. Its speed is similar to classnames
in no dedupe version.
The only difference you'll find will be with full numeric classNames: output will always spit numbers first (ex: className={"a", 12}
=> className="12 a"
). It shouldn't be a big deal though, as using numeric values for classNames is pretty rare and order only matters in a very few specific cases.
Performance
See benchmark dir.
Examples
Build time
1<div className={"foo", "bar"}> 2→ <div className="foo bar"></div> 3 4<div className={'foo', { bar: true }}> 5→ <div className="foo bar"></div> 6 7<div className={{ 'foo-bar': true }}> 8→ <div className="foo-bar"></div> 9 10<div className={{ 'foo-bar': false }}> 11→ <div className=""></div> 12 13<div className={{ foo: true }, { bar: true }, ["foobar", "duck"]}> 14→ <div className="foo bar foobar duck"></div> 15 16<div className={'foo', { bar: true, duck: false }, 'baz', { quux: true }}> 17→ <div className="foo bar baz quux"></div> 18 19<!-- styleName --> 20<div styleName={"foo", "bar"}> 21→ <div styleName="foo bar"></div> 22 23<!-- Dedupe --> 24<div className={'foo foo', 'bar', { bar: true, foo: false }}> 25→ <div className="bar"></div> 26 27<!-- No change --> 28<div className={props.active ? "foo" : "bar"}> 29→ <div className={props.active ? "foo" : "bar"}></div>
Runtime
When className
/ styleName
can't be resolved at compilation.
1<div className={"foo", { active: props.active }}> 2→ <div className={_cx("foo", { active: props.active })}></div> 3 4<div className={{ foo: true, [`btn-${props.type}`]: true }}> 5→ <div className={_cx({ foo: true, [`btn-${props.type}`]: true })}></div> 6 7<div className={"foo", props.active && getClassName()}> 8→ <div className={_cx("foo", props.active && getClassName())}></div>
Send some love
You like this package?
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no SAST tool detected
Details
- Warn: no pull requests merged into dev branch
Reason
Found 0/8 approved changesets -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Reason
82 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-67hx-6x53-jw92
- Warn: Project is vulnerable to: GHSA-v88g-cgmw-v5xw
- Warn: Project is vulnerable to: GHSA-93q8-gq69-wqmw
- Warn: Project is vulnerable to: GHSA-fwr7-v2mv-hh25
- Warn: Project is vulnerable to: GHSA-pp7h-53gx-mx7r
- Warn: Project is vulnerable to: GHSA-qwcr-r2fm-qrc7
- Warn: Project is vulnerable to: GHSA-cwfw-4gq5-mrqx
- Warn: Project is vulnerable to: GHSA-g95f-p29q-9xw4
- Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg
- Warn: Project is vulnerable to: GHSA-x9w5-v3q2-3rhw
- Warn: Project is vulnerable to: GHSA-w8qv-6jwh-64r5
- Warn: Project is vulnerable to: GHSA-pxg6-pf52-xh8x
- Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275
- Warn: Project is vulnerable to: GHSA-9vvw-cc9w-f27h
- Warn: Project is vulnerable to: GHSA-gxpj-cx7g-858c
- Warn: Project is vulnerable to: GHSA-w573-4hg7-7wgq
- Warn: Project is vulnerable to: GHSA-vh7m-p724-62c2
- Warn: Project is vulnerable to: GHSA-r9p9-mrjm-926w
- Warn: Project is vulnerable to: GHSA-434g-2637-qmqr
- Warn: Project is vulnerable to: GHSA-49q7-c7j4-3p7m
- Warn: Project is vulnerable to: GHSA-977x-g7h5-7qgw
- Warn: Project is vulnerable to: GHSA-f7q4-pwc6-w24p
- Warn: Project is vulnerable to: GHSA-fc9h-whq2-v747
- Warn: Project is vulnerable to: GHSA-j4f2-536g-r55m
- Warn: Project is vulnerable to: GHSA-r7qp-cfhv-p84w
- Warn: Project is vulnerable to: GHSA-74fj-2j2h-c42q
- Warn: Project is vulnerable to: GHSA-pw2r-vq6v-hr8c
- Warn: Project is vulnerable to: GHSA-jchw-25xp-jwwc
- Warn: Project is vulnerable to: GHSA-cxjh-pqwp-8mfp
- Warn: Project is vulnerable to: GHSA-6x33-pw7p-hmpq
- Warn: Project is vulnerable to: GHSA-qqgx-2p2h-9c37
- Warn: Project is vulnerable to: GHSA-896r-f27r-55mw
- Warn: Project is vulnerable to: GHSA-9c47-m6qq-7p4h
- Warn: Project is vulnerable to: GHSA-7x7c-qm48-pq9c
- Warn: Project is vulnerable to: GHSA-rc3x-jf5g-xvc5
- Warn: Project is vulnerable to: GHSA-76p3-8jx3-jpfq
- Warn: Project is vulnerable to: GHSA-3rfm-jhwj-7488
- Warn: Project is vulnerable to: GHSA-hhq3-ff78-jv3g
- Warn: Project is vulnerable to: GHSA-jf85-cpcp-j695
- Warn: Project is vulnerable to: GHSA-fvqr-27wr-82fm
- Warn: Project is vulnerable to: GHSA-4xc9-xhrj-v574
- Warn: Project is vulnerable to: GHSA-x5rq-j2xg-h7qm
- Warn: Project is vulnerable to: GHSA-p6mc-m468-83gw
- Warn: Project is vulnerable to: GHSA-29mw-wpgm-hmr9
- Warn: Project is vulnerable to: GHSA-35jh-r3h4-6jhm
- Warn: Project is vulnerable to: GHSA-82v2-mx6x-wq7q
- Warn: Project is vulnerable to: GHSA-952p-6rrq-rcjv
- Warn: Project is vulnerable to: GHSA-f8q6-p94x-37v3
- Warn: Project is vulnerable to: GHSA-vh95-rmgr-6w4m
- Warn: Project is vulnerable to: GHSA-xvch-5gv4-984h
- Warn: Project is vulnerable to: GHSA-w9mr-4mfr-499f
- Warn: Project is vulnerable to: GHSA-q75g-2496-mxpp
- Warn: Project is vulnerable to: GHSA-6fx8-h7jm-663j
- Warn: Project is vulnerable to: GHSA-hj48-42vr-x3v9
- Warn: Project is vulnerable to: GHSA-hrpp-h998-j3pp
- Warn: Project is vulnerable to: GHSA-p8p7-x288-28g6
- Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw
- Warn: Project is vulnerable to: GHSA-hxcc-f52p-wc94
- Warn: Project is vulnerable to: GHSA-fxwf-4rqh-v8g3
- Warn: Project is vulnerable to: GHSA-25hc-qcg6-38wj
- Warn: Project is vulnerable to: GHSA-xfhh-g9f5-x4m4
- Warn: Project is vulnerable to: GHSA-qm95-pgcg-qqfq
- Warn: Project is vulnerable to: GHSA-cqmj-92xf-r6r9
- Warn: Project is vulnerable to: GHSA-vx3p-948g-6vhq
- Warn: Project is vulnerable to: GHSA-3jfq-g458-7qm9
- Warn: Project is vulnerable to: GHSA-r628-mhmh-qjhw
- Warn: Project is vulnerable to: GHSA-9r2w-394v-53qc
- Warn: Project is vulnerable to: GHSA-5955-9wpr-37jh
- Warn: Project is vulnerable to: GHSA-qq89-hq3f-393p
- Warn: Project is vulnerable to: GHSA-f5x3-32g6-xq36
- Warn: Project is vulnerable to: GHSA-4wf5-vphf-c2xc
- Warn: Project is vulnerable to: GHSA-72xf-g2v4-qvf3
- Warn: Project is vulnerable to: GHSA-mgfv-m47x-4wqp
- Warn: Project is vulnerable to: GHSA-5v72-xg48-5rpm
- Warn: Project is vulnerable to: GHSA-72mh-269x-7mh5
- Warn: Project is vulnerable to: GHSA-h4j5-c7cj-74xg
- Warn: Project is vulnerable to: GHSA-c4w7-xm78-47vh
- Warn: Project is vulnerable to: GHSA-2j2x-2gpw-g8fm
- Warn: Project is vulnerable to: GHSA-ww39-953v-wcq6
- Warn: Project is vulnerable to: GHSA-43f8-2h32-f4cj
- Warn: Project is vulnerable to: GHSA-4vvj-4cpr-p986
- Warn: Project is vulnerable to: GHSA-j8xg-fqg3-53r7
Score
1.7
/10
Last Scanned on 2025-01-27
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn MoreOther packages similar to babel-plugin-transform-jsx-classnames
babel-plugin-transform-jsx-class
Support classnames with directive.
@alita/babel-transform-jsx-class
Support classnames with directive.
@maccman/babel-plugin-transform-jsx-classnames
className and styleName on steroids
jsx-css-module-transforms
A babel plugin to transform string classnames into css-module classnames