0.2.0 • Published 6 years ago
sass-var v0.2.0
sass-var
sass-var provides a Sass variable generator with Node.js.
Installation
npm install sass-var
Usage
Basic
const sassVar = require('sass-var');
sassVar.generate('string', 'foo'); // '$string:foo;'
sassVar.generate('boolean', true); // '$boolean:true;'
sassVar.generate('number', 46); // '$number:46;'
sassVar.generate('null', null); // '$null:null;'
sassVar.generate('array', [1, 2, 3]); // '$array:(1,2,3);'
sassVar.generate('object', { bar: 'baz' }); // '$object:(bar:baz);'
Advanced
/* variables.json
{
"string": "foo",
"number": 46,
"boolean": true,
"null": null,
"array": [1, 2, 3],
"object": {
"bar": "baz"
}
}
*/
const sassVar = require('sass-var');
const variables = require('./variables.json');
Object.keys(variables)
.map(key => sassVar.generate(key, variables[key]))
.join('')
// '$string:foo;$number:46;$boolean:true;$null:null;$array:(1,2,3);$object:(bar:baz);'
API
sassVar.generate(name: string, value: any): string
Returns a Sass variable, which of name is name
and of value is value
.
Throws an error when undefined
is specified as value
.
Contributing
You should follow the steps below.
- Fork the repository
- Create a feature branch:
git checkout -b add-new-feature
- Commit your changes:
git commit -am 'Add new feature'
- Push the branch:
git push origin add-new-feature
- Send us a pull request
License
The library is available as open source under the terms of the MIT License.