Gathering detailed insights and metrics for babel-plugin-transform-cssobj-jsx
Gathering detailed insights and metrics for babel-plugin-transform-cssobj-jsx
npm install babel-plugin-transform-cssobj-jsx
Typescript
Module System
Node Version
NPM Version
JavaScript (100%)
Total Downloads
1,504
Last Day
1
Last Week
3
Last Month
14
Last Year
131
1 Stars
25 Commits
2 Watching
1 Branches
1 Contributors
Minified
Minified + Gzipped
Latest Version
2.1.0
Package Id
babel-plugin-transform-cssobj-jsx@2.1.0
Size
3.00 kB
NPM Version
3.10.9
Node Version
6.9.1
Cumulative downloads
Total Downloads
Last day
0%
1
Compared to previous day
Last week
-70%
3
Compared to previous week
Last month
27.3%
14
Compared to previous month
Last year
-20.6%
131
Compared to previous year
1
7
Babel plugin to transform class names into cssobj localized names, easily transform existing code into cssobj.
1npm install --save-dev babel-plugin-transform-cssobj-jsx
.babelrc
:1{ 2 "plugins": ["transform-cssobj-jsx"] 3}
Wrap your JSX in result.mapClass()
1const style = cssobj(obj) 2 3const html = style.mapClass( 4 <div className='container'> 5 <div className={func()}> 6 <p className='!news item active'> </p></div></div> 7)
Which transform into below code:
1const html = ( 2 <div className={style.mapClass('container')}> 3 <div className={style.mapClass(func())}> 4 <p className={style.mapClass('!news item active')}> </p></div></div> 5)
Note: According to cssobj mapClass
rule, the !news
will become news
and not localized (aka keep AS IS).
This plugin transform the below formats:
result.mapClass(JSX)
result.mapName(JSX) (alias of result.mapClass)
mapName(JSX) (function reference of result.mapClass)
If your existing code already has the form, .e.g:
1// existing code, you don't want below to transform
2myObj.mapClass(<div className='abc'>should not be transformed</div>)
You have two way to escape the transform
Change the original method call as myObj['mapClass']
, that way this plugin don't touch it
Pass plugin option mapName
to use other name rather than mapClass
1{ 2 "plugins": [ ["transform-cssobj-jsx", {"mapName": "makeLocal"}] ] 3}
Then you can use makeLocal
instead of mapClass
, as a alias property of cssobj result
Notice: makeLocal
must not exists in result object to avoid conflict
1// below will be transformed, using alias property 2style.makeLocal( <div className='nav'></div> ) 3// <div className={ style.mapClass('nav') }></div> 4 5// your existing code keep untouched 6myObj.mapClass( <div className='abc'> )
If you discard the cssobj result part, then the mapName
is not alias, it's a real function
Notice: makeLocal
must exists in your scope, it will be kept as real function
1// makeLocal is not alias, it's have to be assigned 2const makeLocal = style.mapClass 3 4// will inject to className, shorter code 5makeLocal( <div className='nav'></div> ) 6// <div className={ makeLocal('nav') }></div>
See, all the className have a shorter code, that reduced the bundle size and have better pref
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
Reason
Found 0/25 approved changesets -- score normalized to 0
Reason
no SAST tool detected
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Score
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