Gathering detailed insights and metrics for css-to-react-native-transform
Gathering detailed insights and metrics for css-to-react-native-transform
Gathering detailed insights and metrics for css-to-react-native-transform
Gathering detailed insights and metrics for css-to-react-native-transform
transform-css-to-js
A utility to convert your CSS into JS or React Native compatible styles.
@startupjs/css-to-react-native-transform
Convert CSS text to a React Native stylesheet object
react-native-linear-gradient-degree
Transform css linear-gradient degree to start and end coordinates in react-native-linear-gradient or expo-linear-gradient
babel-plugin-react-native-classname-to-dynamic-style
Transform JSX className property to dynamic style property in React Native. The plugin is used to match style objects containing parsed CSS media queries with React Native.
Turn valid CSS into React Native Stylesheet objects.
npm install css-to-react-native-transform
Typescript
Module System
90.2
Supply Chain
98.1
Quality
74.8
Maintenance
100
Vulnerability
99.1
License
JavaScript (100%)
Total Downloads
2,276,428
Last Day
1,815
Last Week
13,155
Last Month
39,983
Last Year
445,725
MIT License
97 Stars
307 Commits
19 Forks
2 Watchers
49 Branches
3 Contributors
Updated on Jun 17, 2025
Minified
Minified + Gzipped
Latest Version
2.1.0
Package Id
css-to-react-native-transform@2.1.0
Unpacked Size
191.02 kB
Size
24.75 kB
File Count
34
Published on
Jun 22, 2024
Cumulative downloads
Total Downloads
Last Day
798.5%
1,815
Compared to previous day
Last Week
61.9%
13,155
Compared to previous week
Last Month
-21.4%
39,983
Compared to previous month
Last Year
6.4%
445,725
Compared to previous year
3
A lightweight wrapper on top of css-to-react-native to allow valid CSS to be turned into React Native Stylesheet objects.
To keep things simple it only transforms class selectors (e.g. .myClass {}
) and grouped class selectors (e.g. .myClass, .myOtherClass {}
). Parsing of more complex selectors can be added as a new feature behind a feature flag (e.g. transform(css, { parseAllSelectors: true })
) in the future if needed.
Example:
1.myClass { 2 font-size: 18px; 3 line-height: 24px; 4 color: red; 5} 6 7.other { 8 padding: 1rem; 9}
is transformed to:
1{ 2 myClass: { 3 fontSize: 18, 4 lineHeight: 24, 5 color: "red" 6 }, 7 other: { 8 paddingBottom: 16, 9 paddingLeft: 16, 10 paddingRight: 16, 11 paddingTop: 16 12 } 13}
1import transform from "css-to-react-native-transform"; 2// or const transform = require("css-to-react-native-transform").default; 3 4transform(` 5 .foo { 6 color: #f00; 7 } 8`);
↓ ↓ ↓ ↓ ↓ ↓
1{ 2 foo: { 3 color: "#f00"; 4 } 5}
ignoreRule
option1transform( 2 ` 3 .foo { 4 color: red; 5 } 6 .bar { 7 font-size: 12px; 8 } 9`, 10 { 11 ignoreRule: (selector) => { 12 if (selector === ".foo") { 13 return true; 14 } 15 }, 16 }, 17);
↓ ↓ ↓ ↓ ↓ ↓
1{ 2 bar: { 3 fontSize: 12; 4 } 5}
Parsing the CSS Modules (ICSS) :export is supported. The :export
is often used to share variables from CSS or from a preprocessor like Sass/Less/Stylus to Javascript:
1transform(` 2 .foo { 3 color: #f00; 4 } 5 6 :export { 7 myProp: #fff; 8 } 9`);
↓ ↓ ↓ ↓ ↓ ↓
1{ 2 foo: { 3 color: "#f00"; 4 }, 5 myProp: "#fff"; 6}
The API and parsed syntax for CSS Media Queries might change in the future
1transform( 2 ` 3 .container { 4 background-color: #f00; 5 } 6 7 @media (orientation: landscape) { 8 .container { 9 background-color: #00f; 10 } 11 } 12`, 13 { parseMediaQueries: true }, 14);
↓ ↓ ↓ ↓ ↓ ↓
1{ 2 __mediaQueries: { 3 "@media (orientation: landscape)": [{ 4 expressions: [ 5 { 6 feature: "orientation", 7 modifier: undefined, 8 value: "landscape", 9 }, 10 ], 11 inverse: false, 12 type: "all", 13 }], 14 }, 15 container: { 16 backgroundColor: "#f00", 17 }, 18 "@media (orientation: landscape)": { 19 container: { 20 backgroundColor: "#00f", 21 }, 22 }, 23}
You can also speficy a platform as the media query type ("android", "dom", "ios", "macos", "web", "windows"):
1transform( 2 ` 3 .container { 4 background-color: #f00; 5 } 6 7 @media android and (orientation: landscape) { 8 .container { 9 background-color: #00f; 10 } 11 } 12`, 13 { parseMediaQueries: true }, 14);
When CSS Viewport Units are used, a special __viewportUnits
feature flag is added to the result. This is done so that the implementation that transforms viewport units to pixels knows that the style object has viewport units inside it, and can avoid doing extra work if the style object does not contain any viewport units.
1transform(`.foo { font-size: 1vh; }`);
↓ ↓ ↓ ↓ ↓ ↓
1{ 2 __viewportUnits: true, 3 foo: { 4 fontSize: "1vh"; 5 } 6}
rem
unit the root element font-size
is currently set to 16 pixels. A
setting needs to be implemented to allow the user to define the root element
font-size
.box-shadow
shorthand, and this converts into
shadow-
properties. Note that these only work on iOS.This library has the following packages as dependencies:
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
SAST tool detected but not run on all commits
Details
Reason
7 existing vulnerabilities detected
Details
Reason
Found 0/4 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
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-06-30
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