https://github.com/jasonnutter/less-js-vars
Utility to parse less variables into JavaScript variables.
https://github.com/jasonnutter/less-js-vars
Last synced: about 1 year ago
JSON representation
Utility to parse less variables into JavaScript variables.
- Host: GitHub
- URL: https://github.com/jasonnutter/less-js-vars
- Owner: jasonnutter
- License: mit
- Created: 2017-04-23T16:19:12.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2017-04-23T18:10:37.000Z (about 9 years ago)
- Last Synced: 2025-03-16T05:16:37.832Z (over 1 year ago)
- Language: JavaScript
- Homepage:
- Size: 35.2 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# @jasonnutter/less-js-vars
Utility to parse Less variables into JavaScript variables.
## Installation
```sh
yarn add @jasonnutter/less-js-vars --save
npm install @jasonnutter/less-js-vars --save
```
## Usage
Assumes that your code has extracted the raw text of the `less` file, e.g. using [raw-loader](https://github.com/webpack-contrib/raw-loader) or [fs.readFile](https://nodejs.org/api/fs.html#fs_fs_readfile_file_options_callback).
Variable names will be in [camelCase](https://lodash.com/docs/4.17.4#camelCase).
`colors.less`:
```less
@white: #fff;
@black-color: #000;
```
`raw-loader`:
```js
import lessJsVars from '@jasonnutter/less-js-vars';
import colors from '!!raw-loader!./colors.less';
const parsedColors = lessJsVars(colors);
console.log(parsedColors.white);
console.log(parsedColors.blackColor);
```
`fs.readFile`:
```js
import lessJsVars from '@jasonnutter/less-js-vars';
import fs from 'fs';
fs.readFile('./colors.less', 'utf8', (err, colors) => {
const parsedColors = lessJsVars(colors);
console.log(parsedColors.white);
console.log(parsedColors.blackColor);
});
```
## Prior Art
Inspired by [less-vars-to-js](https://www.npmjs.com/package/less-vars-to-js).