{"id":19412955,"url":"https://github.com/dielduarte/style-extractor","last_synced_at":"2026-03-16T09:04:16.138Z","repository":{"id":63268474,"uuid":"562872536","full_name":"dielduarte/style-extractor","owner":"dielduarte","description":"Extract all inline CSS from your HTML generating a css file for it.","archived":false,"fork":false,"pushed_at":"2022-11-26T19:28:03.000Z","size":77,"stargazers_count":6,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-04-08T00:10:12.177Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dielduarte.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-11-07T12:44:04.000Z","updated_at":"2023-08-22T19:20:14.000Z","dependencies_parsed_at":"2023-01-23T00:15:48.740Z","dependency_job_id":null,"html_url":"https://github.com/dielduarte/style-extractor","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dielduarte%2Fstyle-extractor","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dielduarte%2Fstyle-extractor/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dielduarte%2Fstyle-extractor/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dielduarte%2Fstyle-extractor/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dielduarte","download_url":"https://codeload.github.com/dielduarte/style-extractor/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223952297,"owners_count":17230851,"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-11-10T12:29:30.984Z","updated_at":"2026-03-16T09:04:16.087Z","avatar_url":"https://github.com/dielduarte.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Style Extractor\n\nExtract all inline CSS from your HTML generating a css file for it.\n\n## How to use\n\n- First install the lib\n\n  ```bash\n  npm install --save style-extractor\n  ```\n\n- Import the lib and use it\n\n  ```js\n  import { extractStyle } from 'style-extractor';\n\n  const { html, css } = extractStyle(`html input here`)\n  \n  console.log(html, css)\n  ```\n\n  ### Options\n\n  | Option | Values  | Default |\n  |---|---|---|\n  | strategy: Strategy  |  Strategy.atomic \\| Strategy.scoped | Strategy.atomic |\n  | classPrefix: string  |  string value | es-  |\n\n  To configure the options you can pass an object as a second parameter, example:\n\n  ```js\n\n  import { extractStyle } from 'style-extractor';\n  import type { Strategy } from 'style-extractor';\n\n  const { html, css } = extractStyle(\n    `html input here`,\n    { \n      strategy: Strategy.scoped, \n      classPrefix: 'my-prefix-' \n    }\n  )\n\n  console.log(html, css)\n  ```\n\n## Strategies\n\n### Scoped\n  For each inline style attribute found, the lib will generate a unique class with the whole value.\n  \n  e.g\n\n  Given the input:\n\n  ```html\n   \u003cdiv style=\"width: 100%;border: red;\"\u003e\n    \u003cstyle\u003e\n      h1 { line-height: 20px; }\n    \u003c/style\u003e\n    \u003ch1 style=\"color: white; font-size: 14px;\"\u003etitle\u003c/h1\u003e  \n  \u003c/div\u003e\n  ```\n\n  The HTML output would be:\n\n  ```html\n    \u003cdiv class=\"es-chrTOf\"\u003e\n      \u003ch1 class=\"es-dfoHTq\"\u003etitle\u003c/h1\u003e  \n    \u003c/div\u003e\n  ```\n\n  and the CSS output would be:\n\n  ```css\n  .es-chrTOf { width: 100%;border: red; }\n  h1 { line-height: 20px; }\n  .es-dfoHTq { color: white; font-size: 14px; }\n  ```\n\n### Atomic\n  For each css declaration found, the lib will create a unique class and reuse the class on all elements that also have the same css declaration value.\n\n\n  e.g\n\n  Given the input:\n\n  ```html\n   \u003cdiv style=\"width: 100%;border: red;\"\u003e\n    \u003cstyle\u003e\n      h1 { line-height: 20px; }\n    \u003c/style\u003e\n    \u003ch1 style=\"color: white; font-size: 14px;\"\u003etitle\u003c/h1\u003e  \n  \u003c/div\u003e\n  ```\n\n  The HTML output would be:\n\n  ```html\n   \u003cdiv class=\"es-cwtpWi es-gSvEpd\"\u003e\n    \u003ch1 class=\"es-jTfyaK es-dhZwgM\"\u003etitle\u003c/h1\u003e  \n  \u003c/div\u003e\n  ```\n\n  and the CSS output would be:\n\n  ```css\n   .es-cwtpWi { width:100%}\n   .es-gSvEpd { border:red}\n   h1 { line-height: 20px; }\n   .es-jTfyaK { color:white}\n   .es-dhZwgM { font-size:14px}\n  ```\n\n\n@TODOS\n\n- [ ] Option to create file in disk\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdielduarte%2Fstyle-extractor","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdielduarte%2Fstyle-extractor","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdielduarte%2Fstyle-extractor/lists"}