Skip to content

Commit a92b2e2

Browse files
committed
added getAll combination with isSelectors and extended
1 parent edb0bc7 commit a92b2e2

File tree

2 files changed

+57
-6
lines changed

2 files changed

+57
-6
lines changed

lib/utils/options/selectorLibrary.js

+22-6
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,6 @@ class SelectorLibrary {
6161
/**
6262
* gets all selectors
6363
*
64-
* @todo add combination with isSelectors and extended
65-
*
6664
* @param {getAllOptions} [options]
6765
* @return {String | Object} returns either a regex string or an object with elements, depends on the setted options
6866
*/
@@ -125,14 +123,32 @@ class SelectorLibrary {
125123
}
126124

127125
return result;
128-
}
126+
} // !options.extended
127+
128+
// reset result
129+
result = {};
129130

130-
// if it is extended
131131
if (options.origValues) {
132-
return this.selectors;
132+
result = this.selectors;
133+
} else {
134+
result = this.compressedSelectors;
133135
}
134136

135-
return this.compressedSelectors;
137+
if (options.isSelectors) {
138+
let modifiedResult = {};
139+
140+
for (let value in result) {
141+
if (result.hasOwnProperty(value)) {
142+
let char = result[value].typeChar;
143+
144+
modifiedResult[char + value] = result[value];
145+
}
146+
}
147+
148+
result = modifiedResult;
149+
}
150+
151+
return result;
136152
}
137153

138154
/**

test/rcs/selectorLibrary.spec.js

+35
Original file line numberDiff line numberDiff line change
@@ -158,5 +158,40 @@ describe('rcs selector library', () => {
158158

159159
done();
160160
});
161+
162+
it('should get all extended with selectors', done => {
163+
const cssObject = rcs.selectorLibrary.getAll({
164+
isSelectors: true,
165+
extended: true
166+
});
167+
168+
expect(cssObject['.test']).to.be.an('object');
169+
expect(cssObject['.test'].type).to.equal('class');
170+
expect(cssObject['.test'].compressedSelector).to.equal('a');
171+
172+
expect(cssObject['#id']).to.be.an('object');
173+
expect(cssObject['#id'].type).to.equal('id');
174+
expect(cssObject['#id'].compressedSelector).to.equal('b');
175+
176+
done();
177+
});
178+
179+
it('should get all normal with selectors', done => {
180+
const cssObject = rcs.selectorLibrary.getAll({
181+
origValues: false,
182+
isSelectors: true,
183+
extended: true
184+
});
185+
186+
expect(cssObject['.a']).to.be.an('object');
187+
expect(cssObject['.a'].type).to.equal('class');
188+
expect(cssObject['.a'].modifiedSelector).to.equal('test');
189+
190+
expect(cssObject['#b']).to.be.an('object');
191+
expect(cssObject['#b'].type).to.equal('id');
192+
expect(cssObject['#b'].modifiedSelector).to.equal('id');
193+
194+
done();
195+
});
161196
});
162197
});

0 commit comments

Comments
 (0)