CSScomb can be used in Node.js projects: inside a plugin or as a dev tool.
Workflow can look like this:
// Require:
var Comb = require('csscomb');
var config = require('path/to/config');
// Configure:
var comb = new Comb(config);
// Use:
comb.processPath('style.css');
Create instance's prototype.
Parameters:
{String|Object} config
— config that should be used after creating instance. Should be JSON or one of predefined config's name. Optional.
Example: Create CSScomb instance and configure it using predefined yandex
sort
order
var comb = new Comb('yandex');
// This is shortcut for:
var comb = new Comb();
var config = comb.getConfig('yandex');
comb.configure(config);
Example: Create CSScomb instance and configure it using config object
var config = require('path/to/config');
var comb = new Comb(config);
// This is shortcut for:
var comb = new Comb();
comb.configure(config);
Get one of predefined configs.
Parameters:
{String} name
— config's name. Should be one of the following:csscomb
,zen
oryandex
.
Example: Configure CSScomb using predefined zen
sort order that is slightly
modified.
var config = comb.getConfig('zen');
config['always-semicolon'] = true;
comb.configure(config);
Configure CSScomb.
Parameters:
{Object} config
— valid JSON object.
Example: Create and pass a config object to the method
var config = { 'always-semicolon': true };
comb.configure(config);
Example: Use config stored in a file
var config = require('path/to/.csscomb.json');
comb.configure(config);
See configuration docs for more information.
Comb a file or a directory.
Parameters:
{String} path
— path to file or directory
Warning: This method rewrites the file.
Example: Process one file
comb.processPath('main.scss');
Example: Process whole directory
comb.processPath('assets/css');
Comb all supported files in a directory.
Parameters:
{String} path
— path to a directory
Warning: This method rewrites the files.
Example:
comb.processDirectory('public/css');
Comb one file.
Parameters:
{String} path
— path to a file
If file's syntax is not supported, the file will be ignored.
Warning: This method rewrites the file.
Example:
comb.processFile('print.less');
Comb a stylesheet.
Parameters:
{String} text
— stylesheet that should be combed.{String} syntax
— style's syntax. Optional. Default value iscss
.{String} filename
— file's name that is used to print possible errors. Optional.
Example: Comb a css string
var css = 'a {top: 0; left: 0}';
var combedCSS = comb.processString(css);
Example: Comb a less string
var less = '@color: tomato; a {color: @color}';
var combedLESS = comb.processString(less, 'less');
Get config options that can be detected in a file.
Parameters:
{String} path
— path to stylesheet{Array} options
— list of options to detect. Optional. By default tries to detect all available options.
Example: Configure CSScomb using template file
var config = comb.detectInFile('template.css');
comb.configure(config);
Get config options that can be detected in a string.
Parameters:
{String} string
— stylesheet{Array} options
— list of options to detect. Optional. By default tries to detect all available options.
Example: Configure CSScomb using template stylesheet
var css = 'a {top: 0; left: 0}';
var config = comb.detectInString(css);
comb.configure(config);