Skip to content

Commit 492e7ea

Browse files
committed
Add getConfig() method
1 parent ba20374 commit 492e7ea

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
@@ -37,6 +37,27 @@ var Comb = function() {
3737

3838
Comb.prototype = {
3939

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