{"id":13727005,"url":"https://github.com/askirmas/postcss-d-ts","last_synced_at":"2025-04-10T19:42:11.109Z","repository":{"id":40675273,"uuid":"284886815","full_name":"askirmas/postcss-d-ts","owner":"askirmas","description":"PostCSS plugin to generate `.d.ts` of all used CSS classes and ids in imported stylesheets","archived":false,"fork":false,"pushed_at":"2023-01-07T23:15:23.000Z","size":6173,"stargazers_count":32,"open_issues_count":46,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-09T09:21:35.005Z","etag":null,"topics":["css","css-modules","dts","postcss-plugin","sass","typescript","typing"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/postcss-d-ts","language":"TypeScript","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/askirmas.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-08-04T05:35:05.000Z","updated_at":"2024-11-06T21:58:18.000Z","dependencies_parsed_at":"2023-02-08T03:15:37.268Z","dependency_job_id":null,"html_url":"https://github.com/askirmas/postcss-d-ts","commit_stats":null,"previous_names":["askirmas/postcss-plugin-d-ts"],"tags_count":21,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/askirmas%2Fpostcss-d-ts","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/askirmas%2Fpostcss-d-ts/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/askirmas%2Fpostcss-d-ts/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/askirmas%2Fpostcss-d-ts/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/askirmas","download_url":"https://codeload.github.com/askirmas/postcss-d-ts/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248281415,"owners_count":21077423,"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":["css","css-modules","dts","postcss-plugin","sass","typescript","typing"],"created_at":"2024-08-03T01:03:35.292Z","updated_at":"2025-04-10T19:42:11.086Z","avatar_url":"https://github.com/askirmas.png","language":"TypeScript","funding_links":[],"categories":["TypeScript"],"sub_categories":[],"readme":"# [postcss-d-ts](https://github.com/askirmas/postcss-d-ts) [\u003cimg src=\"https://raw.githubusercontent.com/askirmas/postcss-d-ts/master/images/postcss-d-ts.svg\" alt=\"logo\" height=\"51px\" align=\"right\" /\u003e](https://github.com/askirmas/postcss-d-ts)\n\n[PostCSS] plugin to generate [`.d.ts`] of all used CSS classes and ids in imported stylesheets\n\n[![build@ci](https://github.com/askirmas/postcss-d-ts/workflows/build/badge.svg)](https://github.com/askirmas/postcss-d-ts/actions)\n[![codecov](https://codecov.io/gh/askirmas/postcss-d-ts/branch/master/graph/badge.svg?token=TFJ9TMJ3YJ)](https://codecov.io/gh/askirmas/postcss-d-ts)\n[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=askirmas_postcss-d-ts\u0026metric=alert_status)](https://sonarcloud.io/dashboard?id=askirmas_postcss-d-ts)\n[![Maintainability](https://api.codeclimate.com/v1/badges/f6a1ef03e39733e2827c/maintainability)](https://codeclimate.com/github/askirmas/postcss-d-ts/maintainability)\n[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/askirmas/postcss-d-ts/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/askirmas/postcss-d-ts/?branch=master)\n[![DeepScan grade](https://deepscan.io/api/teams/13158/projects/16299/branches/346523/badge/grade.svg)](https://deepscan.io/dashboard#view=project\u0026tid=13158\u0026pid=16299\u0026bid=346523)\n[![CodeFactor](https://www.codefactor.io/repository/github/askirmas/postcss-d-ts/badge)](https://www.codefactor.io/repository/github/askirmas/postcss-d-ts)\n\n[![dependencies Status](https://status.david-dm.org/gh/askirmas/postcss-d-ts.svg)](https://david-dm.org/askirmas/postcss-d-ts)\n[![version](https://img.shields.io/npm/v/postcss-d-ts)](https://www.npmjs.com/package/postcss-d-ts)\n[![license](https://img.shields.io/npm/l/postcss-d-ts)](https://github.com/askirmas/postcss-d-ts/blob/master/LICENSE)\n\n\u003cp align=\"center\"\u003e\u003ca href=\"https://github.com/askirmas/postcss-d-ts/blob/master/images/postcss-d-ts.gif\"\u003e\u003cimg src=\"https://raw.githubusercontent.com/askirmas/postcss-d-ts/master/images/postcss-d-ts.gif\"/\u003e\u003c/a\u003e\u003c/p\u003e\n\n## Goal\n\nProvide [contract](https://en.wikipedia.org/wiki/Design_by_contract) between JS and CSS.\n\n## Installation and setup\n\n```bash\nnpm install postcss-d-ts\n```\n\n```diff\n// postcss.config.js\nmodule.exports = {\n\tplugins: [\n\t  \"postcss-preset-env\",\n  \t...\n+\t  \"postcss-d-ts\"  // or \"postcss-d-ts/dist/7\" for postcss v7\n\t]\n}\n```\n\nCheck [postcss#usage](https://github.com/postcss/postcss#Usage) for details.\n\n## Features\n\n### Languages \u003cimg src=\"https://raw.githubusercontent.com/askirmas/postcss-d-ts/master/images/postcss-d-ts.frameworks.gif\" width=\"50%\" align=\"right\"/\u003e\n\nLanguage agnostic because of PostCss philosophy\n\n\u003cbr clear=\"all\"/\u003e\n\n### CSS libraries/frameworks\n\nIn [./\\_\\_typing\\_\\_/](https://github.com/askirmas/postcss-d-ts/blob/master/__typing__/) results of applying to some popular libraries: [bootstrap v3](https://github.com/askirmas/postcss-d-ts/blob/master/__typing__/bootstrap3.SHOULD.d.ts), [bootstrap v4](https://github.com/askirmas/postcss-d-ts/blob/master/__typing__/bootstrap4.SHOULD.d.ts), [material v10](https://github.com/askirmas/postcss-d-ts/blob/master/__typing__/material10.SHOULD.d.ts), [tailwind v2](https://github.com/askirmas/postcss-d-ts/commit/9514c9e62539127ffd9eaf85fb014efe2daec793#diff-f4d033574661830df6b3d15cfd8d47b76c2ed02cc525b1934242dcff8fc816c0).\n\n## Applyment \u003cimg src=\"https://raw.githubusercontent.com/askirmas/postcss-d-ts/master/images/postcss-d-ts.full.gif\" width=\"50%\" align=\"right\"/\u003e\n\nCSS content:\n\n```css\n/* some.css or some.module.css */\n.class1 { ... }\n.class2 { ... }\n```\n\nGenerated declaration from template (i.e. default *[./src/\\_css-template.d.ts](https://github.com/askirmas/postcss-d-ts/blob/master/src/_css-template.d.ts)*):\n\n```typescript\ndeclare const identifiersMap: CssIdentifiersMap\n\nexport default identifiersMap\n\nexport type CssIdentifiersMap = {\n  \"class1\": string|undefined\n  \"class2\": string|undefined\n}\n```\n\nThus, in Component (i.e. React): *[./\\_\\_recipes\\_\\_/pages/module.tsx](https://github.com/askirmas/postcss-d-ts/blob/master/__recipes__/pages/module.tsx)*\n\n```tsx\nimport moduleClasses from \"./some.module.css\"\n\nconst {\n  class1,\n  class2,\n  //@ts-expect-error - we have only .class1 and .class2\n  class3\n} = moduleClasses\n\nconst Component = () =\u003e \u003cdiv className={`${class1} ${class2}`}/\u003e\n```\n\nor  *[./\\_\\_recipes\\_\\_/pages/button.tsx](https://github.com/askirmas/postcss-d-ts/blob/master/__recipes__/pages/button.tsx)*\n\n```tsx\n// Ordinary CSS\nimport type { CssIdentifiersMap } from \"./some.css\"\n// I.e. with help of https://www.npmjs.com/package/react-classnaming\nimport classNaming from \"react-classnaming\"\n\nconst {\n  class1,\n  class2,\n  //@ts-expect-error - we have only .class1 and .class2\n  class3\n} = {} as CssIdentifiersMap\n\nconst classNames = classNaming()\n\nconst Component() =\u003e \u003cdiv {...classNames({class1, class2})} /\u003e\n```\n\n\u003e [`npm install react-classnaming`](https://github.com/askirmas/react-classnaming)\n\n## Options\n\n### `template: string`\n\nLocal path to a custom template for declarations generating.\n\n- Default: *[./src/\\_css-template.d.ts](https://github.com/askirmas/postcss-d-ts/blob/master/src/_css-template.d.ts)*\n\n```typescript\ndeclare const identifiersMap: CssIdentifiersMap\n\nexport default identifiersMap\n\nexport type CssIdentifiersMap = {\n  \"__identifier__\": string|undefined\n}\n```\n\n- Example: *[./\\_\\_func\\_\\_/template--custom\\_path/template.d.ts](https://github.com/askirmas/postcss-d-ts/blob/master/__func__/template--custom_path/)*\n\n```typescript\nimport type { CSSProperties } from \"react\";\ninterface Styled {\n  __identifier__: Record\u003cstring, CSSProperties\u003e;\n}\ndeclare const styled: Styled;\nexport default styled;\nexport declare const __identifier__: CSSProperties;\n```\n\n### `identifierKeyword: string`\nThe word in `d.ts` template to be replaced with CSS classes, ids, etc.\n\n```diff\n// postcss.config.js\nmodule.exports = {\n  plugins: {\n    \"postcss-d-ts\": {\n+     identifierKeyword: \"data\"\n    }\n  }\n}\n```\n\n```diff\n// _css-template.d.ts\nexport type CssIdentifiersMap = {\n-  \"__identifier__\": string|undefined\n+  \"data\": string|undefined\n}\n```\n\n### `checkMode: boolean `\n\nThrow an error instead of declaration file rewrite. By default, this mode is on for `NODE_ENV === 'production'`\n\n### Other options\n\nFull list in different formats\n\n- [JSON schema](https://code.visualstudio.com/docs/languages/json#_json-schemas-and-settings): [./\\_\\_recipes\\_\\_/next\\_9/postcss.config.json](https://github.com/askirmas/postcss-d-ts/blob/299955b1335037b759dd2a0960db9df2816bd326/__recipes__/next_9/postcss.config.json):\n  - https://askirmas.github.io/postcss-d-ts/schema.json\n  - *\u003cu\u003e./node_modules/postcss-d-ts/dist/schema.json\u003c/u\u003e*\n  - For all config file replace `schema.json` with `postconfig.schema.json`\n\n- TypeScript\n\n```typescript\nimport { Options } from \"postcss-d-ts/dist/options.types\"\n```\n\n- JSDoc: [./\\_\\_recipes\\_\\_/next\\_10/postcss.config.js](https://github.com/askirmas/postcss-d-ts/blob/master/__recipes__/next_10/postcss.config.js)\n\n```javascript\n/** @type {{\n *  plugins: Array\u003c\n*    [\"postcss-d-ts\", import(\"postcss-d-ts/dist/options.types\").Options]\n *  \u003e\n * }}\n */\nmodule.exports = {\n  plugins: [\n    [\"postcss-d-ts\", {}]\n  ]\n}\n```\n\n## Additional notes\n\n### CLI\n\nSimply install [`postcss-cli`] and add it to `npm scripts` with desired options: [example@cra](https://github.com/askirmas/postcss-d-ts/blob/f9f07f009a02db69d9332bdd029a95420ce1a6d9/__recipes__/create-react-app/package.json#L23) and another:\n\n```json\n// package.json\n{\n  \"scripts\": {\n    \"postcss-d-ts\": \"postcss --use postcss-d-ts styles/index.css --watch \u003e /dev/null\"\n  }\n}\n```\n\n### With `create-react-app`\n\nYou need to launch [postcss] as a separate process.  See commit https://github.com/askirmas/postcss-d-ts/commit/f9f07f009a02db69d9332bdd029a95420ce1a6d9 as an additional option how to establish\n\n[postcss]: https://github.com/postcss/postcss\n\n[postcss]: https://github.com/postcss/postcss\n[`postcss`]: https://github.com/postcss/postcss-cli\n[`postcss-cli`]: https://www.npmjs.com/package/postcss-cli\n[`.d.ts`]: https://www.typescriptlang.org/docs/handbook/declaration-files/templates/module-d-ts.html\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faskirmas%2Fpostcss-d-ts","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faskirmas%2Fpostcss-d-ts","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faskirmas%2Fpostcss-d-ts/lists"}