{"id":19418009,"url":"https://github.com/americanexpress/css-to-js","last_synced_at":"2025-10-30T14:48:55.732Z","repository":{"id":38173227,"uuid":"239815664","full_name":"americanexpress/css-to-js","owner":"americanexpress","description":"✨ Tool for transforming CSS into JS","archived":false,"fork":false,"pushed_at":"2024-12-16T15:07:40.000Z","size":1255,"stargazers_count":30,"open_issues_count":1,"forks_count":2,"subscribers_count":13,"default_branch":"main","last_synced_at":"2025-04-18T12:24:05.995Z","etag":null,"topics":["converts-css","css","css2js","js","one-app"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/americanexpress.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.txt","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":"CODEOWNERS","security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-02-11T16:55:35.000Z","updated_at":"2024-12-16T15:07:42.000Z","dependencies_parsed_at":"2024-03-14T11:58:14.941Z","dependency_job_id":"3d7c72b3-88d1-4c86-a497-a8f2956a2ac2","html_url":"https://github.com/americanexpress/css-to-js","commit_stats":{"total_commits":30,"total_committers":10,"mean_commits":3.0,"dds":0.4,"last_synced_commit":"fe140f7d1291183fab24b9a438e1858fb5cfb090"},"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/americanexpress%2Fcss-to-js","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/americanexpress%2Fcss-to-js/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/americanexpress%2Fcss-to-js/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/americanexpress%2Fcss-to-js/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/americanexpress","download_url":"https://codeload.github.com/americanexpress/css-to-js/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250636566,"owners_count":21463101,"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":["converts-css","css","css2js","js","one-app"],"created_at":"2024-11-10T13:12:25.126Z","updated_at":"2025-10-30T14:48:50.681Z","avatar_url":"https://github.com/americanexpress.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003ch1 align=\"center\"\u003e\n  \u003cimg src='https://github.com/americanexpress/css-to-js/raw/main/css-to-js.png' alt=\"CSS to JS - One Amex\" width='50%'/\u003e\n\u003c/h1\u003e\n\n[![npm](https://img.shields.io/npm/v/@americanexpress/css-to-js)](https://www.npmjs.com/package/@americanexpress/css-to-js)\n![Health Check](https://github.com/americanexpress/css-to-js/workflows/Health%20Check/badge.svg)\n\n\u003e Tool for transforming CSS into JS\n\n## 👩‍💻 Hiring 👨‍💻\n\nWant to get paid for your contributions to `CSS-to-JS`?\n\u003e Send your resume to oneamex.careers@aexp.com\n\n\u003cbr /\u003e\n  \n## 📖 Table of Contents  \n  \n* [Features](#Features)  \n* [Usage](#Usage)  \n* [API](#API)  \n* [Git Hooks](#Git%20Hooks)  \n* [Contributing](#Contributing)  \n  \n\u003cbr /\u003e  \n  \n## ✨ Features  \n  \n* Converts CSS to JS  \n* Supports multiple input and output formats (inline code, files, directories)  \n* Generates style objects as e6 exports with options to split into separate files  \n* Reverse media query distribution  \n  \n\u003cbr /\u003e  \n  \n## 🤹‍ Usage  \n  \nInstall:   \n```bash  \nnpm install @americanexpress/css-to-js --save-dev  \n```  \n  \nCLI:  \n```bash  \ncss-to-js \u003cinputPath\u003e \u003coutputPath\u003e (--mediaReverse) (--splitFile | --shakeFile)  \n  \nArguments:  \n inputPath   input path to css file or dir of css files outputPath  output path to js file or dir  Options:  \n --help --version --mediaReverse  reverse mediaQuery style properties  --splitFile  generate multiple files with exports for each selector in css file   \n  --shakeFile  generate single file with exports for each selector in css file   \n    \n  If shakeFile or splitFile is not specified, generate single file with single exported object with selectors in css file as keys  \n See API for more details.\n ```  \n  \nNode:   \n```js \nimport { convert } from 'css-to-js';    \n\n//Input CSS string, Outputs JS Object  \nconvert(`.myClass { color: 'red' }`);   \n\n//Input CSS string, Output file exporting JS Object  \nconvert(`.myClass { color: 'red' }`, { outputType: 'file', outputPath: 'outPath' });   \n\n//Input CSS file path, Output file exporting JS Object  \nconvert('absolute-path-to-css-file', { outputType: 'file', outputPath: 'outPath' });  \n  \n//Input CSS file path, Output file exporting multiple JS Objects  \nconvert('absolute-path-to-css-file', { outputType: 'shakeFile', outputPath: 'outPath' });  \n  \n//Input CSS file path, Outputs dir of files exporting single JS Objects (If treeshaking not supported)  \nconvert('absolute-path-to-css-file', { outputType: 'splitFile', outputPath: 'outPath' });  \n  \n//Input Dir path of CSS files, Output array of JS Objects  \nconvert('absolute-path-to-dir');  \n  \n//Input Dir path of CSS files, Output dir of converted files exporting JS Object  \nconvert('absolute-path-to-dir'', { outputType: 'file', outputPath: 'outPath' });  \n  \n```  \n\n## 🎛️ API  \n  \n#### Input and Output type options\n\n##### *Ensure paths are absolute or relative to the root only*\n\n  \n| Convert Function                                                              | Input Type                                     | Output Type(s)                                                                                                                                  |\n|-------------------------------------------------------------------------------|------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------|\n| convert(css);                                                                 | Path to single CSS file or string of CSS code  | JS style object                                                                                                                         |\n| convert(css, { outputType: 'file', outputPath: 'example.js' });               | Path to single CSS file or string of CSS code  | Generated JS file 'example.js' with a default export of a JS style object                                                               |\n| convert(css, { outputType: 'shakeFile', outputPath: 'shakeExample.js' });     | Path to single CSS file or string of CSS code  | Generated JS file 'shakeExample.js' with multiple named exports of JS style objects                                                     |\n| convert(css, { outputType: 'splitFile', outputPath: 'splitExample' });        | Path to single CSS file or string of CSS code  | Generated directory 'splitExample' with multiple files each with a default export of a JS style object                                  |\n| convert(dirPath);                                                             | Path to directory of CSS files                 | Array of JS style objects                                                                                                               |\n| convert(dirPath, { outputType: 'file', outputPath: 'exampleDir' });           | Path to directory of CSS files                 | Generated directory of JS files; Each file has a default export of a JS style object and is named after the corresponding css file      |\n| convert(dirPath, { outputType: 'shakeFile', outputPath: 'shakeExample.js' }); | Path to directory of CSS files                 | Generated directory of JS files; Each file has multiple named exports of JS style objects and is named after the corresponding css file |\n| convert(dirPath, { outputType: 'splitFile', outputPath: 'splitExample' });    | Path to directory of CSS files                 | Generated directory of directories; Each file has a default export of a JS style object and is named after the corresponding css file   |\n \n \n#### File conversion examples\n \n  \n**Sample Input: `nav.css`**  \n```css  \n.class1 {    \n  color: 'red';  \n}  \n.class2 {\n  color: 'blue'; \n}\n```  \n  \n---  \n\n**Example 1: File** - Creates a file with a single object export representing tree of full converted css  \n\n```\nconvert(\n   path.resolve(__dirname, './nav.css'), \n   { \n     outputType: 'file', \n     outputPath: path.resolve(__dirname, '../example1.js') \n   }\n);\n ```\n  \n**Output: `Example1.js`**  \n```js  \nexport default {\n  class1: { color: 'red' },\n  class2: { color: 'blue' },\n};\n```  \n  \n---  \n  \n**Example 2: ShakeFile** - Create file with multiple exports representing each selector of converted css  \n_(Useful for tree-shaking style objects that do not get used)_  \n\n```\nconvert(\n   path.resolve(__dirname, './nav.css'), \n   { \n     outputType: 'shakeFile', \n     outputPath: path.resolve(__dirname, '../example2.js') \n   }\n);\n ```\n  \n**Output: `Example2.js`**  \n```js  \nexport const class1 = { color: 'red' };\nexport const class2 = { color: 'blue' };\n```  \n  \n---  \n  \n**Example 3: SplitFile** - Create multiple files with exports representing each selector of converted css  \n_(Useful for excluding style objects that do not get used if tree-shaking is not implemented)_  \n\n```\nconvert(\n   path.resolve(__dirname, './nav.css'), \n   { \n     outputType: 'splitFile', \n     outputPath: path.resolve(__dirname, '../example3') \n   }\n);\n ```\n  \n**Output: `Example3/`**  \n  \n**`class1.js`**  \n```js  \nexport default { color: 'red' };\n```  \n  \n**`class2.js`**  \n```js  \nexport default { color: 'blue' };\n```  \n  \n#### Media Reverse  \n  \n*Note: `mediaReverse` is always true if output type is `shakeFile` or `splitFile`*  \n  \nSometimes it's useful to have the styles located in media queries distributed into the selector properties rather than be their own property.  \nIf the `mediaReverse` flag is set to true, reverse the positioning of media queries to be inside the property.  \n  \n**`nav.css`**  \n```css  \n.class1 { color: 'red'; }  \n  \n@media (min-width:500px) {    \n  .class1 { color: 'blue'; } \n}  \n@media (min-width:1000px) {    \n  .class1 { color: 'green'; } \n}  \n```  \nIf mediaReverse is not set: \n  \n```\nconvert(\n   path.resolve(__dirname, './nav.css'), \n   { \n     outputType: 'file', \n     outputPath: path.resolve(__dirname, '../example4.js') \n   }\n);\n ```\n\n**`Example4.js`**  \n```js  \nexport default {\n  class1: { color: 'red' },\n  '@media (min-width:500px)': {\n    class2: { color: 'blue' },\n  },\n  '@media (min-width:1000px)': {\n    class2: { color: 'green' },\n  },\n};\n````  \n  \nIf mediaReverse is set to **true**:  \n\n```\nconvert(\n   path.resolve(__dirname, './nav.css'), \n   { \n     outputType: 'file', \n     outputPath: path.resolve(__dirname, '../example4.js'),\n     mediaReverse: true \n   }\n);\n ```\n  \n**`Example4.js`**  \n```js  \nexport default {\n  class1: { color: 'red' },\n  class2: {\n    '@media (min-width:500px)': {\n      color: 'blue',\n    },\n    '@media (min-width:1000px)': {\n      color: 'green',\n    },\n  },\n};\n````  \n  \n  \n\u003cbr /\u003e  \n  \n## 🎣 Git Hooks  \n  \nThese commands will be automatically run during normal git operations like committing code.  \n  \n**`pre-commit`**  \n  \nThis hook runs `npm test` before allowing a commit to be checked in.  \n  \n**`commit-msg`**  \n  \nThis hook verifies that your commit message matches the One Amex conventions. See the **commit  \nmessage** section in the [CONTRIBUTING.md](./CONTRIBUTING.md).  \n  \n\u003cbr /\u003e  \n  \n## 🏆 Contributing\n\nWe welcome Your interest in the American Express Open Source Community on Github.\nAny Contributor to any Open Source Project managed by the American Express Open\nSource Community must accept and sign an Agreement indicating agreement to the\nterms below. Except for the rights granted in this Agreement to American Express\nand to recipients of software distributed by American Express, You reserve all\nright, title, and interest, if any, in and to Your Contributions. Please [fill\nout the Agreement](https://cla-assistant.io/americanexpress/css-to-js).\n\nPlease feel free to open pull requests and see [CONTRIBUTING.md](./CONTRIBUTING.md) for commit formatting details.\n  \n\u003cbr /\u003e  \n  \n## 🗝️ License  \n  \nAny contributions made under this project will be governed by the [Apache License 2.0](./LICENSE.txt).  \n  \n\u003cbr /\u003e  \n  \n## 🗣️ Code of Conduct  \n  \nThis project adheres to the [American Express Community Guidelines](./CODE_OF_CONDUCT.md).  \nBy participating, you are expected to honor these guidelines.  \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Famericanexpress%2Fcss-to-js","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Famericanexpress%2Fcss-to-js","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Famericanexpress%2Fcss-to-js/lists"}