0.2.0 • Published 6 years ago

sass-var v0.2.0

Weekly downloads
399
License
MIT
Repository
github
Last release
6 years ago

sass-var

npm version Build Status Code Climate Test Coverage

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.

  1. Fork the repository
  2. Create a feature branch: git checkout -b add-new-feature
  3. Commit your changes: git commit -am 'Add new feature'
  4. Push the branch: git push origin add-new-feature
  5. Send us a pull request

License

The library is available as open source under the terms of the MIT License.