Commit ab071ca0 authored by 张九刚's avatar 张九刚

名字删除空格

parent f595df62
{
"name": "psd-parse-web",
"version": "2.0.2",
"version": "2.0.3",
"main": "src/index.js",
"module": "dist/index.es.js",
"license": "MIT",
......
......@@ -5,7 +5,7 @@
*/
var { getTree } = require("./psd-tree");
var { walkNode } = require("./utils");
var { walkNode, trimCustom } = require("./utils");
var path = require('path');
var Color = require('color');
var generateUUID = require('uuid/v4');
......@@ -54,7 +54,8 @@ async function compilePsdToJson(psdFile, options) {
}
}
const pr = pageList.map(async (page, index) => {
const folderName = page.name || `未命名页面${Math.random().toFixed(2) * 100}`;
let folderName = page.name || `未命名页面${Math.random().toFixed(2) * 100}`;
folderName = trimCustom(folderName);
if (!page.children) {
console.warn(`${page.name}不合法,请保持设计稿根目录为全部文件夹形式`);
} else {
......@@ -79,6 +80,7 @@ async function compilePsdToJson(psdFile, options) {
}
await walkNode(page, async (node, parent) => {
let { name } = node;
name = trimCustom(name);
const { x, y, width, height, origin: { layer, layer: { typeTool, solidColor } } } = node;
let properties = {
style: {
......
......@@ -23,7 +23,14 @@ async function walkObject(obj, callback) {
}
}
}
function trimCustom(str) {
var result;
result = str.replace(/(^\s+)|(\s+$)/g, "");
result = result.replace(/\s/g, "");
return result;
}
module.exports = {
walkNode,
walkObject
walkObject,
trimCustom
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment