OpoTests/Public/ecma/Modules/Format/RangeFormat.ecma.js
2025-10-25 17:34:51 +02:00

80 lines
2.0 KiB
JavaScript

"use strict";
import {Utils} from "../../Utils/Utils.ecma.js";
import {Check} from "../../Utils/Check.ecma.js";
/**
* @typedef {import("../FormatModule.ecma.js").FormatModule} FormatModule
*/
/**
* @class RangeFormat
* @constructor
* @param {!FormatModule} format
* @returns {void}
* @access public
* @static
*/
export const RangeFormat = (function(){
/**
* @constructs RangeFormat
* @param {!FormatModule} format
* @returns {void}
* @access private
* @static
*/
const RangeFormat = function(format){
/** @type {RangeFormat} */
const self = this;
/**
* @returns {void}
* @access private
*/
const constructor = () => {
format.modes.range = self.get;
format.checks.range = self.check;
};
/**
* @param {!(string|Array.<any|null>)} inputs
* @param {!Object.<string, any|null>} [shared = {}]
* @param {!Array.<string>} [fragments = []]
* @returns {string}
* @access public
*/
this.get = (inputs, shared = {}, fragments = []) => {
if(Check.is_number(inputs = (
Check.is_string(inputs) ? Utils.get_random(inputs.split("|")).split("-").map(Number) :
Check.is_array(inputs) ? inputs :
[])))
return "" + inputs;
/** @type {number} */
const l = inputs.length;
return "" + (
!l ? null :
l == 1 ? inputs[0] :
Utils.get_random(...inputs));
};
/**
* @param {!string} string
* @param {!(string|Array.<string>)} inputs
* @param {!Object.<string, any|null>} [shared = {}]
* @param {!Array.<string>} [fragments = []]
* @returns {number}
* @access public
*/
this.check = (string, inputs, shared = {}, fragments = []) => FormatModule.check_range(string, inputs);
constructor();
};
return RangeFormat;
})();