90 lines
2.4 KiB
JavaScript
90 lines
2.4 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 SerieFormat
|
|
* @constructor
|
|
* @param {!FormatModule} format
|
|
* @returns {void}
|
|
* @access public
|
|
* @static
|
|
*/
|
|
export const SerieFormat = (function(){
|
|
|
|
/**
|
|
* @constructs SerieFormat
|
|
* @param {!FormatModule} format
|
|
* @returns {void}
|
|
* @access private
|
|
* @static
|
|
*/
|
|
const SerieFormat = function(format){
|
|
|
|
/** @type {SerieFormat} */
|
|
const self = this;
|
|
|
|
/**
|
|
* @returns {void}
|
|
* @access private
|
|
*/
|
|
const constructor = () => {
|
|
format.modes.serie = self.get;
|
|
format.checks.serie = 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 = []) => {
|
|
|
|
Check.is_string(inputs) &&
|
|
(inputs = inputs.split("|").map(range => range.split("-").map(Number)));
|
|
|
|
shared.serie === undefined ||
|
|
(inputs = inputs.filter(range => (
|
|
!Check.is_array(range) ? shared.serie < range :
|
|
range.length == 1 ? shared.serie < range[0] :
|
|
shared.serie < range[1])));
|
|
|
|
/** @type {number|[number]|[number, number]} */
|
|
const range = Utils.get_random(inputs);
|
|
|
|
if(!Check.is_array(range))
|
|
return shared.serie = range;
|
|
if(range.length == 1)
|
|
return shared.serie = range[0];
|
|
|
|
/** @type {number} */
|
|
let value;
|
|
|
|
while((value = Utils.get_random(...range)) <= shared.serie);
|
|
|
|
return shared.serie = value;
|
|
};
|
|
|
|
/**
|
|
* @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 SerieFormat;
|
|
})(); |