Debian Codegraph @

resources/src/mediawiki.rcfilters/utils.js

raw symbols SCIP
1 /**
2 * Utils used by RecentChanges Filters.
3 *
4 * @namespace rcfilters.utils
5 * @private
6 */
7 module.exports = {
8 /**
9 * @param {Node[]} arr
10 * @param {Node[]|Node} elements
11 * @return {Node[]}
12 */
13 addArrayElementsUnique: function ( arr, elements ) {
14 elements = Array.isArray( elements ) ? elements : [ elements ];
15
16 elements.forEach( ( element ) => {
17 if ( arr.indexOf( element ) === -1 ) {
18 arr.push( element );
19 }
20 } );
21
22 return arr;
23 },
24 /**
25 * @param {string[]} givenOptions
26 * @param {string[]} legalOptions
27 * @param {boolean} [supportsAll] defaults to true.
28 * @return {string[]}
29 */
30 normalizeParamOptions: function ( givenOptions, legalOptions, supportsAll ) {
31 const result = [];
32 supportsAll = supportsAll === undefined ? true : !!supportsAll;
33
34 if ( supportsAll && givenOptions.indexOf( 'all' ) > -1 ) {
35 // If anywhere in the values there's 'all', we
36 // treat it as if only 'all' was selected.
37 // Example: param=valid1,valid2,all
38 // Result: param=all
39 return [ 'all' ];
40 }
41
42 // Get rid of any dupe and invalid parameter, only output
43 // valid ones
44 // Example: param=valid1,valid2,invalid1,valid1
45 // Result: param=valid1,valid2
46 givenOptions.forEach( ( value ) => {
47 if (
48 legalOptions.indexOf( value ) > -1 &&
49 result.indexOf( value ) === -1
50 ) {
51 result.push( value );
52 }
53 } );
54
55 return result;
56 }
57 };