Debian Codegraph @

resources/src/mediawiki.special.apisandbox/LimitParamWidget.js

raw symbols SCIP
1 const TextParamMixin = require( './TextParamMixin.js' );
2
3 /**
4 * A wrapper for OO.ui.TextInputWidget
5 *
6 * @class
7 * @private
8 * @constructor
9 * @param {Object} config Configuration options
10 */
11 function LimitParamWidget( config ) {
12 LimitParamWidget.super.call( this, config );
13 }
14
15 OO.inheritClass( LimitParamWidget, OO.ui.TextInputWidget );
16 OO.mixinClass( LimitParamWidget, TextParamMixin );
17
18 /**
19 * For a limit parameter, a value can either be "max" or a number
20 * that is
21 * - not NaN (not "Not-A-Number")
22 * - finite
23 * - not a decimal (identical to Math.floor with that number)
24 * - at least the minimum set in paramInfo.min
25 * - at most the maximum set in paramInfo.apiSandboxMax
26 *
27 * this.paramInfo should be set by the code using this widget, and
28 * should have `min` and `apiSandboxMax` set as intergers
29 *
30 * @param {string} value
31 * @return {boolean}
32 */
33 LimitParamWidget.prototype.validate = function ( value ) {
34 let n;
35 if ( value === 'max' ) {
36 return true;
37 } else {
38 n = +value;
39 return !isNaN( n ) &&
40 isFinite( n ) &&
41 Math.floor( n ) === n &&
42 n >= this.paramInfo.min &&
43 n <= this.paramInfo.apiSandboxMax;
44 }
45 };
46
47 module.exports = LimitParamWidget;