{"id":15390619,"url":"https://github.com/solidzoro/js-var-to-css-var","last_synced_at":"2025-04-15T21:38:22.345Z","repository":{"id":65526137,"uuid":"579736755","full_name":"SolidZORO/js-var-to-css-var","owner":"SolidZORO","description":"Generate CSS/LESS variables and TS Types from JS/TS","archived":false,"fork":false,"pushed_at":"2022-12-22T06:42:55.000Z","size":52,"stargazers_count":4,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-11-28T15:50:15.723Z","etag":null,"topics":["convert","css","generator","js","less","plugin","vars","webpack"],"latest_commit_sha":null,"homepage":"","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/SolidZORO.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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":"2022-12-18T18:40:43.000Z","updated_at":"2024-08-29T12:54:45.000Z","dependencies_parsed_at":"2023-01-30T06:01:54.051Z","dependency_job_id":null,"html_url":"https://github.com/SolidZORO/js-var-to-css-var","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SolidZORO%2Fjs-var-to-css-var","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SolidZORO%2Fjs-var-to-css-var/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SolidZORO%2Fjs-var-to-css-var/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SolidZORO%2Fjs-var-to-css-var/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SolidZORO","download_url":"https://codeload.github.com/SolidZORO/js-var-to-css-var/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":228419532,"owners_count":17916768,"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":["convert","css","generator","js","less","plugin","vars","webpack"],"created_at":"2024-10-01T15:07:14.610Z","updated_at":"2024-12-06T05:35:24.088Z","avatar_url":"https://github.com/SolidZORO.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# js-var-to-css-var\n\nGenerate CSS/LESS variables and TS Types from JS/TS.\n\n[![version][npm-img]][npm-url]\n[![license][mit-img]][mit-url]\n[![size][size-img]][size-url]\n[![download][download-img]][download-url]\n\n## Installation\n\n```sh\nyarn add js-var-to-css-var\n```\n\n\n## Usage\n\n\n### for Js\n\n\n```js\nconst jsVarToCssVar = require('js-var-to-css-var');\n\njsVarToCssVar({\n  inputPath: `${CUR_DIR}/styles/style--js-1.js`,\n  //\n  outputCssPath: `${CUR_DIR}/_output--js/style--css-1.css`,\n  outputCssScopeTag: ':root',\n  outputCssDarkScopeTag: ':root.dark',                          // [Optional] \n  outputCssDarkVarSuffix: '--dark',                             // [Optional]\n  //\n  outputLessPath: `${CUR_DIR}/_output--js/style--less-1.less`,  // [Optional]\n  outputLessHeaderImport: `@import './variables.less';`,        // [Optional]\n  outputLessIgnoreCssDarkVar: false,                            // [Optional]\n  \n  //\n  outputTypePath: `${CUR_DIR}/_output--js/style--type-1.ts`,    // [Optional]\n  outputTypeName: 'ITheme1',                                    // [Optional]\n  outputTypeIgnoreCssDarkVar: false,                            // [Optional]\n});\n\n```\n\n\n### for Node CLI\n\n```bash\nTODO\n```\n\n## Result\n\nInput\n\n```js\nexport const THEME_JS_COLOR = {\n  '--color-red': '#f99',\n  '--color-blue': '#1f9cff',\n  '--text-color': '#c70000',\n  '--text-color--dark': '#ffa4a4',\n};\n\nexport const THEME_JS_FONT = {\n  '--font-size-xs': '12px',\n  '--font-size-md': '18px',\n  '--font-size-lg': '24px',\n};\n```\n\nOutput\n\ncss\n\n```css\n:root {\n  --color-red: #f99;\n  --color-blue: #1f9cff;\n  --font-size-xs: 12px;\n  --font-size-md: 18px;\n  --font-size-lg: 24px;\n  --text-color: #c70000;\n}\n\n:root.dark {\n  --text-color: #ffa4a4;\n}\n```\n\nless\n\n```less\n@import './variables.less';\n\n@color-red: #f99;\n@color-blue: #1f9cff;\n@font-size-xs: 12px;\n@font-size-md: 18px;\n@font-size-lg: 24px;\n@text-color: #c70000;\n```\n\ntype\n\n```typescript\nexport type ITheme1 =\n  | '--color-red'\n  | '--color-blue'\n  | '--theme-light'\n  | '--theme-dark'\n  | '--font-size-xs'\n  | '--font-size-md'\n  | '--font-size-lg'\n  | '--text-color'\n```\n\n## Built-in Utils\n\n```typescript jsx\nimport {\n  _getCssVar,\n  _setCssVar,\n  _getCssPxToNumber,\n  IGetCssVarOpts,\n  IgetCssPxToNumberOpts,\n} from 'js-var-to-css-var/lib/utils';\n```\n\n## Real World\n\nsample\n\n```typescript jsx\nimport { IGlobalCssVars } from '@/styles/vars/global-css-vars--type';\nimport { IOverwriteAntdVars } from '@/styles/vars/overwrite-antd-vars--type';\n\ntype IAllCssVars = IGlobalCssVars | IOverwriteAntdVars | string;\n\nexport const _getCssVar = (cssVar: IAllCssVars): string =\u003e {\n  return getComputedStyle(document.documentElement).getPropertyValue(cssVar);\n};\n\n// use _getCssVar Fn\n// _getCssVar('--font    \u003c-- here have IDE hint all css vars\n\n```\n\nwatch `style.ts` file cahnge (use webpack plugin)\n\n```js\nconst WatchFileAndRunCallbackWebpackPlugin = require('watch-file-change-and-run-callback-webpack-plugin');\n\nwebpackConfig.plugins.push(\n  new WatchFileAndRunCallbackWebpackPlugin({\n    matchs: [\n      {\n        filePath: `${SRC_DIR}/styles/vars/global-css-vars.ts`,\n        callback: () =\u003e {\n          syncStyleCssVar(SRC_DIR);\n        },\n      },\n    ],\n  }),\n);\n```\n\n\n## License\n\nMIT © [Jason Feng][author-url]\n\n\u003c!-- badges --\u003e\n\n[author-url]: https://github.com/SolidZORO\n\n\n[mit-img]: https://img.shields.io/npm/l/js-var-to-css-var.svg?style=flat\u0026colorA=000000\u0026colorB=000000\n\n[mit-url]: ./LICENSE\n\n\n[npm-img]: https://img.shields.io/npm/v/js-var-to-css-var?style=flat\u0026colorA=000000\u0026colorB=000000\n\n[npm-url]: https://www.npmjs.com/package/js-var-to-css-var\n\n\n[size-img]: https://img.shields.io/bundlephobia/minzip/js-var-to-css-var?label=bundle\u0026style=flat\u0026colorA=000000\u0026colorB=000000\n\n[size-url]: https://www.npmjs.com/package/js-var-to-css-var\n\n\n[download-img]: https://img.shields.io/npm/dt/js-var-to-css-var.svg?style=flat\u0026colorA=000000\u0026colorB=000000\n\n[download-url]: https://www.npmjs.com/package/js-var-to-css-var\n\n\n[build-img]: https://github.com/SolidZORO/js-var-to-css-var/workflows/badge.svg\n\n[build-url]: https://github.com/SolidZORO/js-var-to-css-var/actions\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsolidzoro%2Fjs-var-to-css-var","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsolidzoro%2Fjs-var-to-css-var","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsolidzoro%2Fjs-var-to-css-var/lists"}