mirror of
https://github.com/fofolee/uTools-quickcommand.git
synced 2025-07-01 05:23:54 +08:00
完善格式化输出
This commit is contained in:
parent
e950aa1d91
commit
d755df87f2
@ -61,8 +61,6 @@ const shortCodes = [
|
|||||||
|
|
||||||
const ctlKey = utools.isMacOs() ? 'command' : 'control'
|
const ctlKey = utools.isMacOs() ? 'command' : 'control'
|
||||||
|
|
||||||
const createBrowserWindow = utools.createBrowserWindow
|
|
||||||
let browserWindow
|
|
||||||
window.quickcommand = {
|
window.quickcommand = {
|
||||||
// 模拟复制操作
|
// 模拟复制操作
|
||||||
simulateCopy: function() {
|
simulateCopy: function() {
|
||||||
@ -418,35 +416,33 @@ window.convertFilePathToUtoolsPayload = files => files.map(file => {
|
|||||||
let stringifyAll = item => {
|
let stringifyAll = item => {
|
||||||
var cache = [];
|
var cache = [];
|
||||||
var string = JSON.stringify(item, (key, value) => {
|
var string = JSON.stringify(item, (key, value) => {
|
||||||
|
if (typeof value === 'function') return value.toString().replace(/\{[\s\S]*\}/, '{...}');
|
||||||
if (typeof value === 'object' && value !== null) {
|
if (typeof value === 'object' && value !== null) {
|
||||||
if (cache.indexOf(value) !== -1) return
|
if (cache.includes(value)) return value.toString()
|
||||||
cache.push(value);
|
cache.push(value);
|
||||||
}
|
}
|
||||||
return value;
|
return value;
|
||||||
}, '\t')
|
}, 2);
|
||||||
if (string != "{}") return string
|
return string
|
||||||
else return item.toString()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let parseItem = item => {
|
let parseItem = item => {
|
||||||
if (typeof item == "object") {
|
if (typeof item === "undefined") return "undefined"
|
||||||
|
if (typeof item !== "object") return item.toString()
|
||||||
|
if (Object.keys(item).length == 0) return "{}"
|
||||||
if (Buffer.isBuffer(item)) {
|
if (Buffer.isBuffer(item)) {
|
||||||
var bufferString = `[Buffer ${item.slice(0, 50).toString('hex').match(/\w{1,2}/g).join(" ")}`
|
var bufferString = `[Buffer ${item.slice(0, 50).toString('hex').match(/\w{1,2}/g).join(" ")}`;
|
||||||
if (item.length > 50) bufferString += `... ${(item.length / 1000).toFixed(2)}kb`
|
if (item.length > 50) bufferString += `...${(item.length / 1000).toFixed(2)} kb `;
|
||||||
return bufferString + ']'
|
return bufferString + ']'
|
||||||
} else if (item instanceof ArrayBuffer) {
|
}
|
||||||
return `ArrayBuffer(${item.byteLength})`
|
if (item instanceof ArrayBuffer) return `ArrayBuffer(${item.byteLength})`;
|
||||||
} else if (item instanceof Blob) {
|
if (item instanceof Blob) return `Blob { size: ${item.size}, type: "${item.type}" }`;
|
||||||
return `Blob {size: ${item.size}, type: "${item.type}"}`
|
|
||||||
} else {
|
|
||||||
try {
|
try {
|
||||||
return stringifyAll(item)
|
return stringifyAll(item)
|
||||||
} catch (error) {}
|
} catch (error) {
|
||||||
}
|
console.log(error);
|
||||||
} else if (typeof item == "undefined") {
|
|
||||||
return "undefined"
|
|
||||||
}
|
|
||||||
return item.toString()
|
return item.toString()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let parseStdout = stdout => stdout.map(x => parseItem(x)).join("\n")
|
let parseStdout = stdout => stdout.map(x => parseItem(x)).join("\n")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user