Skip to content

Commit

Permalink
doc: update README
Browse files Browse the repository at this point in the history
  • Loading branch information
leeonon committed Sep 21, 2023
1 parent 9023bdc commit 62dc2f5
Showing 1 changed file with 88 additions and 1 deletion.
89 changes: 88 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,89 @@
# extract-style-variable
Extract variables from the style file, support css, less, scss

Translate variables from CSS and Less files using [PostCSS](https://github.com/postcss/postcss).

> ⚠️ The tool is not perfect and is intended for learning and reference only. it is not recommended for use in projects.
## Usage

[demo](https://codesandbox.io/p/sandbox/ti-qu-cssbian-liang-vbic18)

```sh
npm install extract-style-variable
```

```ts
const path = require("path");
const { getStyleVariable } = require("extract-style-variable");

const src = path.resolve(__dirname, "styles/index.css");
const result = getStyleVariable({ path: src });
console.log("result", result);
```

Output Results:

```ts
[
{
key: ':root--color-red',
prop: '--color-red',
value: '"red"',
comment: '--color-red'
},
{
key: ':root--color-blue',
prop: '--color-blue',
value: '"blue"',
comment: null
},
{
key: ':root--color-green',
prop: '--color-green',
value: '"green"',
comment: null
},
{
key: ':root--nvaHeight',
prop: '--nvaHeight',
value: '20rem',
comment: null
},
{
key: 'body--fontSize',
prop: '--fontSize',
value: '12px',
comment: 'body normal font size'
},
{
key: '#main--main-color',
prop: '--main-color',
value: '"yellow"',
comment: '* main color example'
},
{
key: '.name.age--age-color',
prop: '--age-color',
value: '#8855ff',
comment: null
},
{
key: 'ul li--li-color',
prop: '--li-color',
value: 'wheat',
comment: null
},
{
key: ':root--themeColor',
prop: '--themeColor',
value: '#6622dd',
comment: null
},
{
key: ':root--aThemeColor',
prop: '--aThemeColor',
value: '#8855ff',
comment: null
}
]
``

0 comments on commit 62dc2f5

Please sign in to comment.