"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var MathUtil_1 = require("./MathUtil"); var Config_1 = require("./Config"); var StringUtil = /** @class */ (function () { function StringUtil() { } StringUtil.getCheckString = function (address, headInfo) { return "\u914D\u7F6E\u6587\u4EF6:".concat(headInfo.excelPath, ": ").concat(headInfo.sheetname, " :").concat(address); }; StringUtil.getTsClassString = function (jsobj, filename, TStsr, headInfo) { var index = filename.indexOf('Object'); if (index >= 0) { filename = filename.slice(0, index); } var s = "export class ".concat(filename); s += '\r\n{\r\n'; for (var col = 0; col < headInfo.keys.length; col++) { var cur = headInfo.keys[col]; if (cur.outputclient) { var many = ''; if (cur.arrayNum == 2) { many = '[]'; } else if (cur.arrayNum == 3) { many = '[][]'; } s += " public ".concat(cur.name, ": ").concat(cur.type).concat(many, ";\r\n"); } } s += '}\r\n'; TStsr += s; return TStsr; }; /** * * @param jsobj * @param filename * @param TStsr */ StringUtil.getTsFileString = function (jsobj, filename, TStsr, headInfo) { var s = ''; var headKeys = headInfo.keys.filter(function (val) { return val.outputclient; }); for (var i = 0; i < jsobj.length; i++) { s += "\r\n ".concat(Config_1.Config.objectKey ? "'".concat(jsobj[i][Config_1.Config.objectKey], "':") : '', "{ "); var keys = Object.keys(jsobj[i]); for (var j = 0; j < keys.length; j++) { // s += '\r\n\t\t\t' var value = jsobj[i][keys[j]]; var cur = headKeys[j]; if (cur.type == 'string') { value = "'".concat(value, "'"); } s += "".concat(keys[j], ": ").concat(value, ", "); } if (s.substr(s.length - 2, 2) == ', ') { s = s.substr(0, s.length - 2); } s += ' },'; } if (Config_1.Config.objectKey) { s = s.substr(0, s.length - 1); // 单个对象为表去掉多余的数组逗号 return "".concat(TStsr).concat(s); } var index = filename.indexOf('Object'); if (index != -1) { filename = filename.slice(0, index); s = s.substr(0, s.length - 1); // 单个对象为表去掉多余的数组逗号 return "".concat(TStsr, "\r\n public static ").concat(filename, ": ").concat(filename, " = ").concat(s, ";\r\n"); } return "".concat(TStsr, "\r\n public static ").concat(filename, ": ").concat(filename, "[] = [").concat(s, "\r\n ];"); }; StringUtil.getTsFileString2 = function (jsobj, filename, TStsr, headInfo) { var ss = "import { Config } from './Config';"; var s = ''; var headKeys = headInfo.keys.filter(function (val) { return val.outputclient; }); for (var i = 0; i < jsobj.length; i++) { s += '\r\n {'; var keys = Object.keys(jsobj[i]); for (var j = 0; j < keys.length; j++) { var value = jsobj[i][keys[j]]; var cur = headKeys[j]; if (cur.type == 'string' || cur.type == 'String') { value = "'".concat(value, "'"); } s += "".concat(keys[j], ": ").concat(value, ", "); } if (s.substr(s.length - 2, 2) == ', ') { s = s.substr(0, s.length - 2); } s += '},'; } var index = filename.indexOf('Object'); if (index != -1) { filename = filename.slice(0, index); s = s.substr(0, s.length - 1); // 单个对象为表去掉多余的数组逗号 return "".concat(ss, "\r\n\r\nConfig.").concat(filename, " = ").concat(s, ";\r\n"); } return "".concat(ss, "\r\n\r\nConfig.").concat(filename, " = [").concat(s, "\r\n];"); }; StringUtil.getTsFileString3 = function (jsobj, headInfo) { var headKeys = headInfo.keys.filter(function (val) { return val.outputclient; }); for (var i = 0; i < jsobj.length; i++) { var keys = Object.keys(jsobj[i]); for (var j = 0; j < keys.length; j++) { var value = jsobj[i][keys[j]]; var cur = headKeys[j]; if (cur.isArray) { jsobj[i][keys[j]] = eval(value); } } } }; StringUtil.getTsFileHead = function (filename, TStsr) { return "".concat(TStsr, "\r\n public static ").concat(filename, ": ").concat(filename, "[] = [];"); }; /** * * @param jsobj * @param filename * @param configData */ StringUtil.getJsFileString = function (jsobj, filename, configData, headInfo) { var s = ''; var headKeys = headInfo.keys.filter(function (val) { return val.outputclient; }); for (var i = 0; i < jsobj.length; i++) { s += '\r\n\t\t{'; var keys = Object.keys(jsobj[i]); for (var j = 0; j < keys.length; j++) { s += '\r\n\t\t\t'; var value = jsobj[i][keys[j]]; var cur = headKeys[j]; if (cur.type == 'string') { value = "'".concat(value, "'"); } s += "".concat(keys[j], ": ").concat(value, ","); } s += '\r\n\t\t},'; } var index = filename.indexOf('Object'); if (index != -1) { filename = filename.slice(0, index); return "".concat(configData, "\t").concat(filename, ":").concat(s, "\r\n"); } return "".concat(configData, "\t").concat(filename, ": [").concat(s, "\r\n\t],\r\n"); }; StringUtil.getCsvFileString = function (csvobj) { var ret = ''; for (var i = 0; i < csvobj.length; i++) { var arr = Object.values(csvobj[i]); for (var j = 0; j < arr.length; j++) { if (j == arr.length - 1) { ret = "".concat(ret + arr[j], "\n"); } else { ret = "".concat(ret + arr[j], ","); } } } return ret; }; StringUtil.getHsvFileString = function (csvobj) { var ret = ''; for (var i = -1; i < csvobj.length; i++) { var arr = null; if (i == -1) { arr = Object.keys(csvobj[0]); } else { arr = Object.values(csvobj[i]); } for (var j = 0; j < arr.length; j++) { if (j == arr.length - 1) { ret = "".concat(ret + arr[j], "\n"); } else { ret = "".concat(ret + arr[j], ","); } } } return ret; }; StringUtil.replaceAll = function (text, oldString, newString) { return text.replace(new RegExp(oldString, 'g'), newString); }; ; StringUtil.replaceDoubleMid = function (text, oldString, newStringCallback, checkIsNumber) { if (checkIsNumber === void 0) { checkIsNumber = false; } var globalReg = new RegExp("\\".concat(oldString, "[^\\").concat(oldString, "]+\\").concat(oldString), 'g'); var reg = new RegExp("\\".concat(oldString, "[^\\").concat(oldString, "]+\\").concat(oldString)); var arr = text.match(globalReg); if (arr) { for (var i = 0; i < arr.length; i++) { var mid = arr[i].substr(1, arr[i].length - 2); if (checkIsNumber) { if (MathUtil_1.default.isNumber(mid)) { var newString = newStringCallback(mid); // text = text.replace(reg, newString); // 从左到右逐个替换 } else { // 报错 } } else { var newString = newStringCallback(mid); text = text.replace(reg, newString); // 从左到右逐个替换 } } } return text; }; return StringUtil; }()); exports.default = StringUtil;