增加移除规则标记末尾的中文

This commit is contained in:
onvia 2023-09-15 09:50:55 +08:00
parent 34615d4b6e
commit 12975ba1a8
3 changed files with 28 additions and 7 deletions

View File

@ -1,6 +1,6 @@
{
"name": "ccc-tnt-psd2ui",
"version": "1.0.1",
"version": "1.0.2",
"description": "",
"main": "index.js",
"scripts": {

View File

@ -1166,7 +1166,7 @@
this.scale = new Vec3(1, 1, 1);
}
parseNameRule(name) {
var _a, _b;
var _a, _b, _c;
if (!name) {
return;
}
@ -1177,11 +1177,11 @@
return;
}
let obj = {
name: (_b = (_a = fragments[0]) === null || _a === void 0 ? void 0 : _a.replace(/\.|>|\/|\ /g, "_")) !== null && _b !== void 0 ? _b : "unknow",
name: (_c = (_b = (_a = fragments[0]) === null || _a === void 0 ? void 0 : _a.trim()) === null || _b === void 0 ? void 0 : _b.replace(/\.|>|\/|\ /g, "_")) !== null && _c !== void 0 ? _c : "unknow",
comps: {},
};
for (let i = 1; i < fragments.length; i++) {
const fragment = fragments[i].trim();
const fragment = this.removeChineseFromEnd(fragments[i].trim()).trim(); // 删除规则尾部的中文
let attr = {};
let startIdx = fragment.indexOf("{");
let comp = fragment;
@ -1255,6 +1255,15 @@
// }
return obj;
}
removeChineseFromEnd(inputString) {
const chineseRegex = /[\u4e00-\u9fa5]+$/;
const match = inputString.match(chineseRegex);
if (match && match[0]) {
const chineseLength = match[0].length;
return inputString.slice(0, -chineseLength);
}
return inputString;
}
/** 解析数据 */
parseSource() {
var _a, _b;

View File

@ -112,11 +112,13 @@ export abstract class PsdLayer {
return;
}
let obj: PsdAttr = {
name: fragments[0]?.replace(/\.|>|\/|\ /g, "_") ?? "unknow",
name: fragments[0]?.trim()?.replace(/\.|>|\/|\ /g, "_") ?? "unknow",
comps: {},
}
for (let i = 1; i < fragments.length; i++) {
const fragment = fragments[i].trim();
const fragment = this.removeChineseFromEnd(fragments[i].trim()).trim(); // 删除规则尾部的中文
let attr = {};
let startIdx = fragment.indexOf("{");
let comp = fragment;
@ -203,7 +205,17 @@ export abstract class PsdLayer {
return obj;
}
removeChineseFromEnd(inputString: string): string {
const chineseRegex = /[\u4e00-\u9fa5]+$/;
const match = inputString.match(chineseRegex);
if (match && match[0]) {
const chineseLength = match[0].length;
return inputString.slice(0, -chineseLength);
}
return inputString;
}
/** 解析数据 */
parseSource() {
let _source = this.source;