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

80 lines
2.2 KiB
JavaScript

"use strict";
import {Utils} from "../../Utils/Utils.ecma.js";
import {Check} from "../../Utils/Check.ecma.js";
import {FormatModule} from "../FormatModule.ecma.js";
/**
* @typedef {import("../FormatModule.ecma.js").FormatModule} FormatModule
*/
/**
* @class PlainFormat
* @constructor
* @param {!FormatModule} format
* @returns {void}
* @access public
* @static
*/
export const PlainFormat = (function(){
/**
* @constructs PlainFormat
* @param {!FormatModule} format
* @returns {void}
* @access private
* @static
*/
const PlainFormat = function(format){
/** @type {PlainFormat} */
const self = this;
/**
* @returns {void}
* @access private
*/
const constructor = () => {
format.modes.plain = self.get;
format.checks.plain = 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 = []) => format.execute(
Check.is_string(inputs) ? inputs :
Check.is_string(inputs[0]) ? inputs[0] :
"", shared, fragments);
/**
* @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 = []) => {
/** @type {string} */
const substring = format.set_fragments_level((
Check.is_string(inputs) ? inputs.split("|") :
Check.is_string(inputs[0]) ? inputs[0] :
""), fragments);
return (
/\{[^\{\}]+\}/.test(format.set_fragments_level(substring, fragments)) ? format.get_check_length(string, [substring], shared, fragments, false) :
FormatModule.prepare_result(string, substring, shared));
};
constructor();
};
return PlainFormat;
})();