Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/nkt/css-variables-parser
CSS variables parser
https://github.com/nkt/css-variables-parser
css-variables parser postcss
Last synced: 3 months ago
JSON representation
CSS variables parser
- Host: GitHub
- URL: https://github.com/nkt/css-variables-parser
- Owner: nkt
- License: mit
- Created: 2017-02-11T00:01:54.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2023-03-04T04:25:54.000Z (almost 2 years ago)
- Last Synced: 2024-09-21T14:08:42.897Z (4 months ago)
- Topics: css-variables, parser, postcss
- Language: JavaScript
- Homepage:
- Size: 288 KB
- Stars: 8
- Watchers: 1
- Forks: 1
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
CSS Variables Parser
====================[![Build Status](https://circleci.com/gh/nkt/css-variables-parser.svg?style=shield)](https://circleci.com/gh/nkt/css-variables-parser)
Installation
------------```bash
npm install css-variables-parser
```Usage
-----Parse css string
```js
const { parse } = require('css-variables-parser');const variables = parse(':root { --color-primary: red; }');
console.log(variables); // { 'color-primary': 'red' }
```Parse file (not available in browser)
```js
const {
parseFile,
parseFileSync,
parseFileAsync
} = require('css-variables-parser');parseFile('./path/to/file.css', null, (error, variables) => {
console.log({ error, variables });
});const variables = parseFileSync('./path/to/file.css');
parseFileAsync('./path/to/file.css')
.then((variables) => console.log(variables))
.catch((error) => console.error(error));
```There are some options:
```js
const parser = require('css-variables-parser');const variables = parser.parse(css, {
from: 'filename.css',
parser: require('sugarss')
});
```License
-------[MIT](LICENSE)