Gathering detailed insights and metrics for css-to-react-native
Gathering detailed insights and metrics for css-to-react-native
Gathering detailed insights and metrics for css-to-react-native
Gathering detailed insights and metrics for css-to-react-native
@types/css-to-react-native
TypeScript definitions for css-to-react-native
css-to-rn.macro
Convert CSS to React Native style sheet at build time with babel macros
css-to-react-native-transform
Convert CSS text to a React Native stylesheet object
taro-css-to-react-native
Convert CSS text to a React Native stylesheet object
Convert CSS text to a React Native stylesheet object
npm install css-to-react-native
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
1,141 Stars
202 Commits
79 Forks
39 Watching
6 Branches
108 Contributors
Updated on 06 Nov 2024
JavaScript (100%)
Cumulative downloads
Total Downloads
Last day
-3.2%
1,129,564
Compared to previous day
Last week
2.4%
5,825,346
Compared to previous week
Last month
8.6%
24,652,437
Compared to previous month
Last year
-2.8%
285,367,051
Compared to previous year
Converts CSS text to a React Native stylesheet object.
1font-size: 18px; 2line-height: 24px; 3color: red;
1{ 2 fontSize: 18, 3 lineHeight: 24, 4 color: 'red', 5}
Converts all number-like values to numbers, and string-like to strings.
Automatically converts indirect values to their React Native equivalents.
1text-shadow-offset: 10px 5px; 2font-variant: small-caps; 3transform: translate(10px, 5px) scale(5);
1{ 2 textShadowOffset: { width: 10, height: 5 }, 3 fontVariant: ['small-caps'], 4 // Fixes backwards transform order 5 transform: [ 6 { translateY: 5 }, 7 { translateX: 10 }, 8 { scale: 5 }, 9 ] 10}
Also allows shorthand values.
1font: bold 14px/16px "Helvetica"; 2margin: 5px 7px 2px;
1{ 2 fontFamily: 'Helvetica', 3 fontSize: 14, 4 fontWeight: 'bold', 5 fontStyle: 'normal', 6 fontVariant: [], 7 lineHeight: 16, 8 marginTop: 5, 9 marginRight: 7, 10 marginBottom: 2, 11 marginLeft: 7, 12}
Shorthands will only accept values that are supported in React, so background
will only accept a colour, backgroundColor
There is also support for the box-shadow
shorthand, and this converts into shadow-
properties. Note that these only work on iOS.
border{Top,Right,Bottom,Left}
shorthands are not supported, because borderStyle
cannot be applied to individual border sides.
The API is mostly for implementors. However, the main API may be useful for non-implementors. The main API is an array of [property, value]
tuples.
1import transform from 'css-to-react-native'; 2// or const transform = require('css-to-react-native').default; 3 4transform([ 5 ['font', 'bold 14px/16px "Helvetica"'], 6 ['margin', '5px 7px 2px'], 7 ['border-left-width', '5px'], 8]); // => { fontFamily: 'Helvetica', ... }
We don't provide a way to get these style tuples in this library, so you'll need to do that yourself. I expect most people will use postCSS or another CSS parser. You should try avoid getting these with string.split
, as that has a lot of edge cases (colons and semi-colons appearing in comments etc.)
For implementors, there is also a few extra APIs available.
These are for specific use-cases, and most people should just be using the API above.
1import { getPropertyName, getStylesForProperty } from 'css-to-react-native'; 2 3getPropertyName('border-width'); // => 'borderWidth' 4getStylesForProperty('borderWidth', '1px 0px 2px 0px'); // => { borderTopWidth: 1, ... }
Should you wish to opt-out of transforming certain shorthands, an array of property names in camelCase can be passed as a second argument to transform
.
1transform([['border-radius', '50px']], ['borderRadius']); 2// { borderRadius: 50 } rather than { borderTopLeft: ... }
This can also be done by passing a third argument, false
to getStylesForProperty
.
Licensed under the MIT License, Copyright © 2019 Krister Kari, Jacob Parker, and Maximilian Stoiber.
See LICENSE.md for more information.
No vulnerabilities found.
Reason
all changesets reviewed
Reason
no binaries found in the repo
Reason
license file 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
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
46 existing vulnerabilities detected
Details
Score
Last Scanned on 2024-11-18
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