Merge "resourceloader: Simplify StringSet fallback"
[lhc/web/wiklou.git] / resources / src / mediawiki.rcfilters / mw.rcfilters.js
1 ( function () {
2 /**
3 * @class
4 * @singleton
5 */
6 mw.rcfilters = {
7 dm: {},
8 ui: {},
9 utils: {
10 addArrayElementsUnique: function ( arr, elements ) {
11 elements = Array.isArray( elements ) ? elements : [ elements ];
12
13 elements.forEach( function ( element ) {
14 if ( arr.indexOf( element ) === -1 ) {
15 arr.push( element );
16 }
17 } );
18
19 return arr;
20 },
21 normalizeParamOptions: function ( givenOptions, legalOptions ) {
22 var result = [];
23
24 if ( givenOptions.indexOf( 'all' ) > -1 ) {
25 // If anywhere in the values there's 'all', we
26 // treat it as if only 'all' was selected.
27 // Example: param=valid1,valid2,all
28 // Result: param=all
29 return [ 'all' ];
30 }
31
32 // Get rid of any dupe and invalid parameter, only output
33 // valid ones
34 // Example: param=valid1,valid2,invalid1,valid1
35 // Result: param=valid1,valid2
36 givenOptions.forEach( function ( value ) {
37 if (
38 legalOptions.indexOf( value ) > -1 &&
39 result.indexOf( value ) === -1
40 ) {
41 result.push( value );
42 }
43 } );
44
45 return result;
46 }
47 }
48 };
49 }() );