Skip to content

Commit bee0de2

Browse files
committed
Change API to remove postCSS dependency
1 parent aafd2b3 commit bee0de2

File tree

4 files changed

+186
-194
lines changed

4 files changed

+186
-194
lines changed

README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,11 @@ The API is mostly for implementors. However, the main API may be useful for non-
7777
import transform from 'css-to-react-native';
7878
// or const transform = require('css-to-react-native').default;
7979

80-
transform(`
81-
font: bold 14/16 "Helvetica";
82-
margin: 5 7 2;
83-
`); // => { fontFamily: 'Helvetica', ... }
80+
transform([
81+
['font', 'bold 14/16 "Helvetica"'],
82+
['margin', '5 7 2'],
83+
['border-left-width', '5'],
84+
]); // => { fontFamily: 'Helvetica', ... }
8485
```
8586

8687
For implementors, there is also,

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
"dependencies": {
3333
"css-color-list": "0.0.1",
3434
"fbjs": "^0.8.5",
35-
"nearley": "^2.7.7",
36-
"postcss": "^5.2.5"
35+
"nearley": "^2.7.7"
3736
}
3837
}

src/index.js

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
/* eslint-disable no-param-reassign */
2-
const postcss = require('postcss');
32
const nearley = require('nearley');
43
const camelizeStyleName = require('fbjs/lib/camelizeStyleName');
54
const grammar = require('./grammar');
@@ -42,16 +41,9 @@ export const getStylesForProperty = (propName, inputValue) => {
4241

4342
export const getPropertyName = camelizeStyleName;
4443

45-
const getStylesForDecl = decl =>
46-
getStylesForProperty(getPropertyName(decl.prop), decl.value);
47-
48-
export default (css) => {
49-
const root = postcss.parse(css);
50-
51-
const decls = [];
52-
root.walkDecls((decl) => { decls.push(decl); });
53-
54-
const style = decls.reduce((accum, decl) => Object.assign(accum, getStylesForDecl(decl)), {});
55-
56-
return style;
57-
};
44+
export default rules => rules.reduce((accum, rule) => (
45+
Object.assign(accum, getStylesForProperty(
46+
getPropertyName(rule[0]),
47+
rule[1],
48+
))
49+
), {});

0 commit comments

Comments
 (0)