{"id":13437957,"url":"https://github.com/postcss/postcss-js","last_synced_at":"2025-05-14T15:05:44.697Z","repository":{"id":1974283,"uuid":"44200483","full_name":"postcss/postcss-js","owner":"postcss","description":"PostCSS for React Inline Styles, Free Style and other CSS-in-JS","archived":false,"fork":false,"pushed_at":"2024-07-18T14:20:48.000Z","size":813,"stargazers_count":658,"open_issues_count":3,"forks_count":24,"subscribers_count":16,"default_branch":"main","last_synced_at":"2025-04-25T04:24:29.180Z","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/postcss.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","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},"funding":{"open_collective":"postcss","github":"ai"}},"created_at":"2015-10-13T19:44:56.000Z","updated_at":"2025-03-22T10:00:53.000Z","dependencies_parsed_at":"2023-07-05T20:02:55.338Z","dependency_job_id":"d63d4061-c737-40dd-a703-4d143bf99cbb","html_url":"https://github.com/postcss/postcss-js","commit_stats":{"total_commits":148,"total_committers":14,"mean_commits":"10.571428571428571","dds":"0.18918918918918914","last_synced_commit":"b3db658b932b42f6ac14ca0b1d50f50c4569805b"},"previous_names":[],"tags_count":18,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/postcss%2Fpostcss-js","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/postcss%2Fpostcss-js/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/postcss%2Fpostcss-js/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/postcss%2Fpostcss-js/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/postcss","download_url":"https://codeload.github.com/postcss/postcss-js/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251342723,"owners_count":21574244,"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-31T03:01:01.661Z","updated_at":"2025-05-14T15:05:44.661Z","avatar_url":"https://github.com/postcss.png","language":"JavaScript","readme":"# PostCSS JS\n\n\u003cimg align=\"right\" width=\"135\" height=\"95\"\n     title=\"Philosopher’s stone, logo of PostCSS\"\n     src=\"https://postcss.org/logo-leftp.svg\"\u003e\n\n[PostCSS] for CSS-in-JS and styles in JS objects.\n\nFor example, to use [Stylelint] or [RTLCSS] plugins in your workflow.\n\n\u003ca href=\"https://evilmartians.com/?utm_source=postcss-js\"\u003e\n  \u003cimg src=\"https://evilmartians.com/badges/sponsored-by-evil-martians.svg\"\n       alt=\"Sponsored by Evil Martians\" width=\"236\" height=\"54\"\u003e\n\u003c/a\u003e\n\n[Stylelint]: https://github.com/stylelint/stylelint\n[PostCSS]:   https://github.com/postcss/postcss\n[RTLCSS]:    https://github.com/MohammadYounes/rtlcss\n\n\n## Usage\n\n### Processing\n\n```js\nconst postcssJs = require('postcss-js')\nconst autoprefixer = require('autoprefixer')\n\nconst prefixer = postcssJs.sync([ autoprefixer ])\n\nconst style = prefixer({\n  userSelect: 'none'\n})\n\nstyle //=\u003e {\n      //     WebkitUserSelect: 'none',\n      //        MozUserSelect: 'none',\n      //         msUserSelect: 'none',\n      //           userSelect: 'none'\n      //   }\n```\n\n\n### Compile CSS-in-JS to CSS\n\n```js\nconst postcss = require('postcss')\nconst postcssJs = require('postcss-js')\n\nconst style = {\n  top: 10,\n  '\u0026:hover': {\n    top: 5\n  }\n};\n\npostcss().process(style, { parser: postcssJs }).then( (result) =\u003e {\n  result.css //=\u003e top: 10px;\n             //   \u0026:hover { top: 5px; }\n})\n```\n\n\n### Compile CSS to CSS-in-JS\n\n```js\nconst postcss = require('postcss')\nconst postcssJs = require('postcss-js')\n\nconst css  = '--text-color: #DD3A0A; @media screen { z-index: 1; color: var(--text-color) }'\nconst root = postcss.parse(css)\n\npostcssJs.objectify(root) //=\u003e {\n                          //     '--text-color': '#DD3A0A',\n                          //     '@media screen': {\n                          //       zIndex: '1',\n                          //       color: 'var(--text-color)'\n                          //     }\n                          //   }\n```\n\n\n## API\n\n### `sync(plugins): function`\n\nCreate PostCSS processor with simple API, but with only sync PostCSS plugins\nsupport.\n\nProcessor is just a function, which takes one style object and return other.\n\n\n### `async(plugins): function`\n\nSame as `sync`, but also support async plugins.\n\nReturned processor will return Promise.\n\n\n### `parse(obj): Root`\n\nParse CSS-in-JS style object to PostCSS `Root` instance.\n\nIt converts numbers to pixels and parses\n[Free Style] like selectors and at-rules:\n\n```js\n{\n    '@media screen': {\n        '\u0026:hover': {\n            top: 10\n        }\n    }\n}\n```\n\nThis methods use Custom Syntax name convention, so you can use it like this:\n\n```js\npostcss().process(obj, { parser: postcssJs })\n```\n\n\n### `objectify(root): object`\n\nConvert PostCSS `Root` instance to CSS-in-JS style object.\n\n\n## Troubleshoot\n\nWebpack may need some extra config for some PostCSS plugins.\n\n\n### `Module parse failed`\n\nAutoprefixer and some other plugins\nneed a [json-loader](https://github.com/webpack/json-loader) to import data.\n\nSo, please install this loader and add to webpack config:\n\n```js\nloaders: [\n  {\n    test: /\\.json$/,\n    loader: \"json-loader\"\n  }\n]\n```\n","funding_links":["https://opencollective.com/postcss","https://github.com/sponsors/ai"],"categories":["Uncategorized","JavaScript","Code Design"],"sub_categories":["Uncategorized","CSS / Style"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpostcss%2Fpostcss-js","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpostcss%2Fpostcss-js","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpostcss%2Fpostcss-js/lists"}