Installations
npm install @maccman/babel-plugin-transform-jsx-classnames
Developer Guide
Typescript
Yes
Module System
CommonJS
Min. Node Version
>= 8.0
Node Version
12.18.3
NPM Version
6.14.6
Score
77.2
Supply Chain
99.5
Quality
75
Maintenance
100
Vulnerability
100
License
Releases
Unable to fetch releases
Contributors
Unable to fetch Contributors
Languages
JavaScript (100%)
Developer
gtournie
Download Statistics
Total Downloads
1,274
Last Day
2
Last Week
4
Last Month
18
Last Year
564
GitHub Statistics
5 Stars
8 Commits
1 Forks
3 Watching
1 Branches
1 Contributors
Bundle Size
4.16 kB
Minified
1.77 kB
Minified + Gzipped
Package Meta Information
Latest Version
1.1.1
Package Id
@maccman/babel-plugin-transform-jsx-classnames@1.1.1
Unpacked Size
362.74 kB
Size
86.30 kB
File Count
24
NPM Version
6.14.6
Node Version
12.18.3
Total Downloads
Cumulative downloads
Total Downloads
1,274
Last day
0%
2
Compared to previous day
Last week
300%
4
Compared to previous week
Last month
350%
18
Compared to previous month
Last year
109.7%
564
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 classNamess in a simpler way, without having to worry about importing a helper (like classnames). classNames
or styleNames
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 classNames
/ styleNames
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
Add to .babelrc
:
1{ 2 plugins: ['transform-jsx-classnames'] 3}
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 classNames
/ styleNames
during the compilation (classNames={"foo", { active: true }}
) and fallback to runtime if not possible (classNames={_cx("foo", { active: props.active })}
- a tiny helper (~0.3Ko) will be included automatically.
Runtime helper
The runtime helper is very similar to the classnames package. It actually behaves like its dedupe version.
The only difference you'll find will be with full numeric classNamess: output will always spit numbers first (ex: classNames={"a", 12}
=> classNames="12 a"
). It shouldn't be a big deal though, as using numeric values for classNamess is pretty rare and order only matters in a very few specific cases.
Performance & dedupe
Dedupe has been optimized a lot and its performance is very similar to classnames (in no dedupe mode). It's even better in some cases.
Examples
Build time
1<div classNames={"foo", "bar"}> 2→ <div classNames="foo bar"></div> 3 4<div classNames={'foo', { bar: true }}> 5→ <div classNames="foo bar"></div> 6 7<div classNames={{ 'foo-bar': true }}> 8→ <div classNames="foo-bar"></div> 9 10<div classNames={{ 'foo-bar': false }}> 11→ <div classNames=""></div> 12 13<div classNames={{ foo: true }, { bar: true }, ["foobar", "duck"]}> 14→ <div classNames="foo bar foobar duck"></div> 15 16<div classNames={'foo', { bar: true, duck: false }, 'baz', { quux: true }}> 17→ <div classNames="foo bar baz quux"></div> 18 19<!-- styleNames --> 20<div styleNames={"foo", "bar"}> 21→ <div styleNames="foo bar"></div> 22 23<!-- Dedupe --> 24<div classNames={'foo foo', 'bar', { bar: true, foo: false }}> 25→ <div classNames="bar"></div> 26 27<!-- No change --> 28<div classNames={props.active ? "foo" : "bar"}> 29→ <div classNames={props.active ? "foo" : "bar"}></div>
Runtime
When classNames
/ styleNames
can't be resolved at compilation.
1<div classNames={"foo", { active: props.active }}> 2→ <div classNames={_cx("foo", { active: props.active })}></div> 3 4<div classNames={{ foo: true, [`btn-${props.type}`]: true }}> 5→ <div classNames={_cx({ foo: true, [`btn-${props.type}`]: true })}></div> 6 7<div classNames={"foo", props.active && getClassName()}> 8→ <div classNames={_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 More