ucbuilder
Version:
For Developing Applications with multiple form/usercontrols etc.. In Single BrowserWindow...
46 lines (45 loc) • 1.75 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.switchRegs = void 0;
const common_1 = require("ucbuilder/build/common");
class switchRegs {
constructor() {
this.switchPattern = new RegExp(/`\s*{(switch\w*)=([\.\w]+?)}\s*`([^]*?)`\s*{\/\1}\s*`/g);
this.casePattern = new RegExp(/`\s*\[(case\w*)=([\.\|\w]+?)\]\s*`([^]*?)`\s*\[\/\1\]\s*`/g);
}
/**
*
* @param {string} content
* @param {{}} node
* @param {Function} caseText
* @returns
*/
parse(content, node, caseText = (val) => { return val; }) {
let _this = this;
return content.replace(this.switchPattern, function (match, switchCode, valtoFind, subcontent, offset, input_string) {
let casetofind = caseText(common_1.objectOpt.getValByNameSpace(node, valtoFind));
return _this.parseCase(subcontent.trim(), casetofind);
});
}
parseDirect(node, valtoFind, subcontent, caseText = (val) => { return val; }) {
let casetofind = caseText(common_1.objectOpt.getValByNameSpace(node, valtoFind));
return this.parseCase(subcontent.trim(), casetofind);
}
/**
*
* @param {string} content
* @param {string} valtoMatch
* @returns
*/
parseCase(content, valtoMatch) {
return content.replace(this.casePattern, function (match, caseCode, valInCase, subcontent, offset, input_string) {
/**
* @type {[]}
*/
let ar = valInCase.split("|");
valtoMatch = "" + valtoMatch;
return (ar.includes(valtoMatch)) ? subcontent : "";
}).trimEnd();
}
}
exports.switchRegs = switchRegs;