{"id":13393504,"url":"https://github.com/styled-components/css-to-react-native","last_synced_at":"2025-05-14T00:05:34.662Z","repository":{"id":46934024,"uuid":"73301774","full_name":"styled-components/css-to-react-native","owner":"styled-components","description":"Convert CSS text to a React Native stylesheet object","archived":false,"fork":false,"pushed_at":"2024-08-25T08:05:45.000Z","size":561,"stargazers_count":1154,"open_issues_count":10,"forks_count":81,"subscribers_count":38,"default_branch":"master","last_synced_at":"2025-05-04T21:04:48.377Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/styled-components.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-11-09T16:34:37.000Z","updated_at":"2025-05-03T03:48:46.000Z","dependencies_parsed_at":"2024-09-20T04:45:29.778Z","dependency_job_id":null,"html_url":"https://github.com/styled-components/css-to-react-native","commit_stats":{"total_commits":129,"total_committers":21,"mean_commits":6.142857142857143,"dds":"0.39534883720930236","last_synced_commit":"ae1e7beef42ba2a971a53d9522db669eea6f6b21"},"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/styled-components%2Fcss-to-react-native","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/styled-components%2Fcss-to-react-native/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/styled-components%2Fcss-to-react-native/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/styled-components%2Fcss-to-react-native/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/styled-components","download_url":"https://codeload.github.com/styled-components/css-to-react-native/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252596399,"owners_count":21773844,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-30T17:00:54.518Z","updated_at":"2025-05-14T00:05:34.621Z","avatar_url":"https://github.com/styled-components.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"# css-to-react-native\n\nConverts CSS text to a React Native stylesheet object.\n\n[Try it here](https://csstox.surge.sh)\n\n```css\nfont-size: 18px;\nline-height: 24px;\ncolor: red;\n```\n\n```js\n{\n  fontSize: 18,\n  lineHeight: 24,\n  color: 'red',\n}\n```\n\nConverts all number-like values to numbers, and string-like to strings.\n\nAutomatically converts indirect values to their React Native equivalents.\n\n```css\ntext-shadow-offset: 10px 5px;\nfont-variant: small-caps;\ntransform: translate(10px, 5px) scale(5);\n```\n\n```js\n{\n  textShadowOffset: { width: 10, height: 5 },\n  fontVariant: ['small-caps'],\n  // Fixes backwards transform order\n  transform: [\n    { translateY: 5 },\n    { translateX: 10 },\n    { scale: 5 },\n  ]\n}\n```\n\nAlso allows shorthand values.\n\n```css\nfont: bold 14px/16px \"Helvetica\";\nmargin: 5px 7px 2px;\n```\n\n```js\n{\n  fontFamily: 'Helvetica',\n  fontSize: 14,\n  fontWeight: 'bold',\n  fontStyle: 'normal',\n  fontVariant: [],\n  lineHeight: 16,\n  marginTop: 5,\n  marginRight: 7,\n  marginBottom: 2,\n  marginLeft: 7,\n}\n```\n\nShorthands will only accept values that are supported in React, so `background` will only accept a colour, `backgroundColor`\n\nThere is also support for the `box-shadow` shorthand, and this converts into `shadow-` properties. Note that these only work on iOS.\n\n#### Shorthand Notes\n\n`border{Top,Right,Bottom,Left}` shorthands are not supported, because `borderStyle` cannot be applied to individual border sides.\n\n# API\n\nThe 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.\n\n```js\nimport transform from 'css-to-react-native';\n// or const transform = require('css-to-react-native').default;\n\ntransform([\n  ['font', 'bold 14px/16px \"Helvetica\"'],\n  ['margin', '5px 7px 2px'],\n  ['border-left-width', '5px'],\n]); // =\u003e { fontFamily: 'Helvetica', ... }\n```\n\nWe 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.)\n\nFor implementors, there is also a few extra APIs available.\n\nThese are for specific use-cases, and most people should just be using the API above.\n\n```js\nimport { getPropertyName, getStylesForProperty } from 'css-to-react-native';\n\ngetPropertyName('border-width'); // =\u003e 'borderWidth'\ngetStylesForProperty('borderWidth', '1px 0px 2px 0px'); // =\u003e { borderTopWidth: 1, ... }\n```\n\nShould 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`.\n\n```js\ntransform([['border-radius', '50px']], ['borderRadius']);\n// { borderRadius: 50 } rather than { borderTopLeft: ... }\n```\n\nThis can also be done by passing a third argument, `false` to `getStylesForProperty`.\n\n## License\n\nLicensed under the MIT License, Copyright © 2019 Krister Kari, Jacob Parker, and Maximilian Stoiber.\n\nSee [LICENSE.md](./LICENSE.md) for more information.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstyled-components%2Fcss-to-react-native","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstyled-components%2Fcss-to-react-native","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstyled-components%2Fcss-to-react-native/lists"}