sass-vars-to-js
v0.8.7
Published
variables.scss to [variables Object] converter
Downloads
82
Maintainers
Readme
sass-vars-to-js
variables.scss to [variables Object] converter
About
Sometimes you just need to use SASS variables in JS without incorporating complex logic. And no CSS-module-specific logic behind this.
Important
Not actively maintained
If you want to cooperate or even adopt the project, please let me know.
Installation and Changes
Installation is straightforward:
$ npm install --save-dev sass-vars-to-js
Run tests:
$ npm test
Compile commonjs version with babel:
$ npm run build
Usage
There are two ways of requiring the module:
By default requiring module gets the commonjs version:
var converter = require('node_modules/sass-vars-to-js');
If you prefer (by whatever reasons) ES6 version, you can also try:
import converter from 'node_modules/sass-vars-to-js/src'
Function accepts string - path to a SASS file, containing variables. It returns the object, very similar to the variable definition syntax:
variables.scss
$color-brand-primary: #1711e2;
$color-brand-secondary: #fd0f79;
$footer-bg-color: $color-brand-primary;
colors.js
import converter from 'sass-vars-to-js';
const variables = converter(path/to/variables.scss);
// {
// 'color-brand-primary': '#1711e2',
// 'color-brand-secondary': '#fd0f79',
// 'footer-bg-color': '#1711e2'
// }
const colors = {
brandPrimary: variables['color-brand-primary'],
brandSecondary: variables['color-brand-secondary']
};
Limits of use
Please be aware of current version (0.x - 1.x) limitations:
- maps and other complex stuff is not supported
- sass expressions not supported
- sass functions not supported