Skip to content

Commit 6ed375a

Browse files
committed
Merge pull request #119 from csscomb/tg/get-config
Add getConfig() method (#103)
2 parents a5c2221 + 492e7ea commit 6ed375a

2 files changed

Lines changed: 75 additions & 0 deletions

File tree

lib/csscomb.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,27 @@ var Comb = function() {
3838

3939
Comb.prototype = {
4040

41+
/**
42+
* Get one of configuration files from `config` directory
43+
* @param {String} name Config's name: 'csscomb', 'zen' or 'yandex'
44+
* @returns {Object} Configuration object
45+
*/
46+
getConfig: function(name) {
47+
name = name || 'csscomb';
48+
49+
if (typeof name !== 'string') {
50+
throw new Error('Config name should be a string');
51+
}
52+
53+
if (['csscomb', 'zen', 'yandex'].indexOf(name) < 0) {
54+
var message = name + ' is not a valid config name. Try one of ' +
55+
'the following: \'csscomb\', \'zen\' or \'yandex\'.';
56+
throw new Error(message);
57+
}
58+
59+
return require('../config/' + name + '.json');
60+
},
61+
4162
/**
4263
* Loads configuration from JSON.
4364
* Activates and configures required options.

test/get-config.js

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
var Comb = require('../lib/csscomb');
2+
var assert = require('assert');
3+
4+
describe('csscomb methods', function() {
5+
var comb = new Comb();
6+
7+
it('getConfig()', function() {
8+
var config = require('../config/csscomb.json');
9+
10+
assert.equal(comb.getConfig(), config);
11+
});
12+
13+
it('getConfig(number)', function() {
14+
assert.throws(function() {
15+
comb.getConfig(16);
16+
});
17+
});
18+
19+
it('getConfig(boolean)', function() {
20+
assert.throws(function() {
21+
comb.getConfig(true);
22+
});
23+
});
24+
25+
it('getConfig(empty string)', function() {
26+
var config = require('../config/csscomb.json');
27+
28+
assert.equal(comb.getConfig(''), config);
29+
});
30+
31+
it('getConfig(invalid string)', function() {
32+
assert.throws(function() {
33+
comb.getConfig('nani');
34+
});
35+
});
36+
37+
it('getConfig(csscomb)', function() {
38+
var config = require('../config/csscomb.json');
39+
40+
assert.equal(comb.getConfig('csscomb'), config);
41+
});
42+
43+
it('getConfig(zen)', function() {
44+
var config = require('../config/zen.json');
45+
46+
assert.equal(comb.getConfig('zen'), config);
47+
});
48+
49+
it('getConfig(yandex)', function() {
50+
var config = require('../config/yandex.json');
51+
52+
assert.equal(comb.getConfig('yandex'), config);
53+
});
54+
});

0 commit comments

Comments
 (0)