File tree 2 files changed +57
-6
lines changed
2 files changed +57
-6
lines changed Original file line number Diff line number Diff line change @@ -61,8 +61,6 @@ class SelectorLibrary {
61
61
/**
62
62
* gets all selectors
63
63
*
64
- * @todo add combination with isSelectors and extended
65
- *
66
64
* @param {getAllOptions } [options]
67
65
* @return {String | Object } returns either a regex string or an object with elements, depends on the setted options
68
66
*/
@@ -125,14 +123,32 @@ class SelectorLibrary {
125
123
}
126
124
127
125
return result ;
128
- }
126
+ } // !options.extended
127
+
128
+ // reset result
129
+ result = { } ;
129
130
130
- // if it is extended
131
131
if ( options . origValues ) {
132
- return this . selectors ;
132
+ result = this . selectors ;
133
+ } else {
134
+ result = this . compressedSelectors ;
133
135
}
134
136
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 ;
136
152
}
137
153
138
154
/**
Original file line number Diff line number Diff line change @@ -158,5 +158,40 @@ describe('rcs selector library', () => {
158
158
159
159
done ( ) ;
160
160
} ) ;
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
+ } ) ;
161
196
} ) ;
162
197
} ) ;
You can’t perform that action at this time.
0 commit comments