{"id":30063387,"url":"https://github.com/huygn/tailwind-unit-replace","last_synced_at":"2025-08-08T04:22:51.743Z","repository":{"id":57376387,"uuid":"398556554","full_name":"huygn/tailwind-unit-replace","owner":"huygn","description":"Helpers to replace TailwindCSS's default REM based units with anything like PX or EM.","archived":false,"fork":false,"pushed_at":"2023-07-01T08:00:41.000Z","size":22,"stargazers_count":10,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-07-04T09:17:17.361Z","etag":null,"topics":["css","nodejs","tailwind","tailwindcss"],"latest_commit_sha":null,"homepage":"http://npm.im/tailwind-unit-replace","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/huygn.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":"2021-08-21T12:50:16.000Z","updated_at":"2024-07-16T23:38:45.000Z","dependencies_parsed_at":"2022-09-26T21:50:59.305Z","dependency_job_id":null,"html_url":"https://github.com/huygn/tailwind-unit-replace","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/huygn/tailwind-unit-replace","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/huygn%2Ftailwind-unit-replace","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/huygn%2Ftailwind-unit-replace/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/huygn%2Ftailwind-unit-replace/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/huygn%2Ftailwind-unit-replace/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/huygn","download_url":"https://codeload.github.com/huygn/tailwind-unit-replace/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/huygn%2Ftailwind-unit-replace/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":269060471,"owners_count":24353152,"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","status":"online","status_checked_at":"2025-08-06T02:00:09.910Z","response_time":99,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["css","nodejs","tailwind","tailwindcss"],"created_at":"2025-08-08T04:22:49.164Z","updated_at":"2025-08-08T04:22:51.733Z","avatar_url":"https://github.com/huygn.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# tailwind-unit-replace\n\n[![npm version](https://badge.fury.io/js/tailwind-unit-replace.svg)](https://badge.fury.io/js/tailwind-unit-replace)\n[![CI](https://github.com/huygn/tailwind-unit-replace/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/huygn/tailwind-unit-replace/actions/workflows/ci.yml)\n\nHelpers to replace Tailwind's default unit (`rem`) with whatever possible, be it `em`, `px` .etc.\n\nLet's face it, Tailwind's default `rem` unit works great for websites \u0026 apps. But if you're building components library or plugins, chances are you'd like your plugin's size/spacing to stay fixed as desired (in `px`) or dynamically based on it's closest ancestor (like `em`). This repo aims to make it possible without hassles.\n\n## Install\n\n```sh\nnpm i -D tailwind-unit-replace\n```\n\n## Usage\n\n```javascript\nconst { replaceTailwindUnit, toEM, toPX } = require('tailwind-unit-replace')\n\nconst config = { ... } // your custom Tailwind config\n\nmodule.exports = replaceTailwindUnit({\n  exclude: ['fontFamily'],\n  replacer: toEM // or `toPX` to convert to pixel (16-based)\n})(config)\n```\n\nIf you'd like to replace unit with a more flexible value, you can write a custom `replacer` - take a look at [toEM](./src/extras.ts)'s implementation, for example this is how I did in another project:\n\n```typescript\nfunction replacer(value: string) {\n  return value.replace(remUnitRegex, (match, remDigit) =\u003e {\n    const amount = Number(remDigit);\n    if (Number.isNaN(amount)) return match;\n    return `calc(var(--root-font-size) * ${amount})`;\n  });\n}\n```\n\n`replacer` function will be called on each config (deeply nested) string value, and is expected to return a string value which will be applied to the final replaced Tailwind config.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhuygn%2Ftailwind-unit-replace","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhuygn%2Ftailwind-unit-replace","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhuygn%2Ftailwind-unit-replace/lists"}