Add: Show unenumerable, show getter value options
This commit is contained in:
@@ -8,5 +8,6 @@ focusin
|
||||
iframe
|
||||
onerror
|
||||
postcss
|
||||
scss
|
||||
textarea
|
||||
scss
|
||||
unenumerable
|
||||
@@ -186,6 +186,8 @@ export default class Console extends Tool
|
||||
catchGlobalErr: true,
|
||||
overrideConsole: true,
|
||||
displayExtraInfo: false,
|
||||
displayUnenumerable: true,
|
||||
displayGetterVal: false,
|
||||
displayIfErr: false,
|
||||
maxLogNum: 'infinite'
|
||||
}));
|
||||
@@ -196,6 +198,8 @@ export default class Console extends Tool
|
||||
if (cfg.get('catchGlobalErr')) this.catchGlobalErr();
|
||||
if (cfg.get('overrideConsole')) this.overrideConsole();
|
||||
if (cfg.get('displayExtraInfo')) logger.displayHeader(true);
|
||||
if (cfg.get('displayUnenumerable')) logger.displayUnenumerable(true);
|
||||
if (cfg.get('displayGetterVal')) logger.displayGetterVal(true);
|
||||
logger.maxNum(maxLogNum);
|
||||
|
||||
cfg.on('change', (key, val) =>
|
||||
@@ -206,6 +210,8 @@ export default class Console extends Tool
|
||||
case 'overrideConsole': return val ? this.overrideConsole() : this.restoreConsole();
|
||||
case 'maxLogNum': return logger.maxNum(val === 'infinite' ? val : +val);
|
||||
case 'displayExtraInfo': return logger.displayHeader(val);
|
||||
case 'displayUnenumerable': return logger.displayUnenumerable(val);
|
||||
case 'displayGetterVal': return logger.displayGetterVal(val);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -216,6 +222,8 @@ export default class Console extends Tool
|
||||
.switch(cfg, 'overrideConsole', 'Override Console')
|
||||
.switch(cfg, 'displayIfErr', 'Auto Display If Error Occurs')
|
||||
.switch(cfg, 'displayExtraInfo', 'Display Extra Information')
|
||||
.switch(cfg, 'displayUnenumerable', 'Display Unenumerable Properties')
|
||||
.switch(cfg, 'displayGetterVal', 'Access Getter Value')
|
||||
.select(cfg, 'maxLogNum', 'Max Log Number', ['infinite', '250', '125', '100', '50', '10'])
|
||||
.separator()
|
||||
}
|
||||
|
||||
@@ -75,7 +75,7 @@ export default class Log
|
||||
|
||||
if (this._needSrc())
|
||||
{
|
||||
this.src = extractObj(args.length === 1 && util.isObj(args[0]) ? args[0] : args, false);
|
||||
this.src = extractObj(args.length === 1 && util.isObj(args[0]) ? args[0] : args, {simple: false});
|
||||
}
|
||||
|
||||
let msg = '', icon;
|
||||
@@ -161,6 +161,23 @@ export default class Log
|
||||
}
|
||||
}
|
||||
|
||||
// Looks like es6 doesn't support static properties yet.
|
||||
Log.showGetterVal = false;
|
||||
Log.showUnenumerable = true;
|
||||
|
||||
function stringifyWrapper(obj, options = {})
|
||||
{
|
||||
util.defaults(options, {
|
||||
simple: true,
|
||||
highlight: true,
|
||||
keyQuotes: false,
|
||||
getterVal: Log.showGetterVal,
|
||||
unenumerable: Log.showUnenumerable
|
||||
});
|
||||
|
||||
return stringify(obj, options);
|
||||
}
|
||||
|
||||
function formatTable(args)
|
||||
{
|
||||
let table = args[0],
|
||||
@@ -292,7 +309,7 @@ function substituteStr(args)
|
||||
case 'O':
|
||||
if (util.isObj(arg))
|
||||
{
|
||||
newStr += stringify(arg, {simple: true, keyQuotes: false, highlight: true});
|
||||
newStr += stringifyWrapper(arg);
|
||||
}
|
||||
break;
|
||||
case 'o':
|
||||
@@ -301,7 +318,7 @@ function substituteStr(args)
|
||||
newStr += formatEl(arg);
|
||||
} else if (util.isObj(arg))
|
||||
{
|
||||
newStr += stringify(arg, {simple: true, keyQuotes: false, highlight: true});
|
||||
newStr += stringifyWrapper(arg);
|
||||
}
|
||||
break;
|
||||
case 'c':
|
||||
@@ -328,7 +345,7 @@ function substituteStr(args)
|
||||
|
||||
function formatObj(val)
|
||||
{
|
||||
return `${getObjType(val)} ${stringify(val, {keyQuotes: false, simple: true, highlight: true})}`;
|
||||
return `${getObjType(val)} ${stringifyWrapper(val)}`;
|
||||
}
|
||||
|
||||
function formatFn(val)
|
||||
@@ -379,4 +396,12 @@ var padZero = (num) => util.lpad(util.toStr(num), 2, '0');
|
||||
var tpl = require('./Log.hbs');
|
||||
var render = data => tpl(data);
|
||||
|
||||
var extractObj = (obj, simple) => JSON.parse(stringify(obj, {simple}));
|
||||
function extractObj(obj, options = {})
|
||||
{
|
||||
util.defaults(options, {
|
||||
highlight: false,
|
||||
keyQuotes: true
|
||||
});
|
||||
|
||||
return JSON.parse(stringifyWrapper(obj, options));
|
||||
}
|
||||
|
||||
@@ -37,6 +37,14 @@ export default class Logger extends util.Emitter
|
||||
this.render();
|
||||
}
|
||||
}
|
||||
displayUnenumerable(flag)
|
||||
{
|
||||
Log.showUnenumerable = flag;
|
||||
}
|
||||
displayGetterVal(flag)
|
||||
{
|
||||
Log.showGetterVal = flag;
|
||||
}
|
||||
filter(val)
|
||||
{
|
||||
this._filter = val;
|
||||
|
||||
@@ -7,8 +7,9 @@ export default function stringify(obj, {
|
||||
simple = false,
|
||||
keyQuotes = true,
|
||||
getterVal = false,
|
||||
highlight = false
|
||||
} = {})
|
||||
highlight = false,
|
||||
unenumerable = true
|
||||
} = {})
|
||||
{
|
||||
let json = '',
|
||||
type = '',
|
||||
@@ -80,16 +81,16 @@ export default function stringify(obj, {
|
||||
visited.push(obj);
|
||||
|
||||
json = '[';
|
||||
util.each(obj, val => parts.push(`${stringify(val, {visited, simple, getterVal, keyQuotes, highlight})}`));
|
||||
util.each(obj, val => parts.push(`${stringify(val, {visited, simple, getterVal, keyQuotes, highlight, unenumerable})}`));
|
||||
json += parts.join(', ') + ']';
|
||||
} else if (isObj || isFn)
|
||||
{
|
||||
visited.push(obj);
|
||||
|
||||
names = Object.getOwnPropertyNames(obj);
|
||||
names = unenumerable ? Object.getOwnPropertyNames(obj) : Object.keys(obj);
|
||||
proto = Object.getPrototypeOf(obj);
|
||||
if (proto === Object.prototype || isFn || simple) proto = null;
|
||||
if (proto) proto = `${wrapKey('erudaProto')}: ${stringify(proto, {visited, getterVal, topObj, keyQuotes, highlight})}`;
|
||||
if (proto) proto = `${wrapKey('erudaProto')}: ${stringify(proto, {visited, getterVal, topObj, keyQuotes, highlight, unenumerable})}`;
|
||||
names.sort(sortObjName);
|
||||
if (isFn)
|
||||
{
|
||||
@@ -121,7 +122,7 @@ export default function stringify(obj, {
|
||||
return parts.push(`${key}: "(...)"`);
|
||||
}
|
||||
}
|
||||
parts.push(`${key}: ${stringify(topObj[name], {visited, getterVal, simple, keyQuotes, highlight})}`);
|
||||
parts.push(`${key}: ${stringify(topObj[name], {visited, getterVal, simple, keyQuotes, highlight, unenumerable})}`);
|
||||
});
|
||||
if (proto) parts.push(proto);
|
||||
json += parts.join(', ') + '}';
|
||||
@@ -161,14 +162,14 @@ export default function stringify(obj, {
|
||||
|
||||
json = '{\n';
|
||||
if (!simple) parts.push(`${wrapKey('erudaObjAbstract')}: "${type.replace(/(\[object )|]/g, '')}"`);
|
||||
names = Object.getOwnPropertyNames(obj);
|
||||
names = unenumerable ? Object.getOwnPropertyNames(obj) : Object.keys(obj);
|
||||
proto = Object.getPrototypeOf(obj);
|
||||
if (proto === Object.prototype || simple) proto = null;
|
||||
if (proto)
|
||||
{
|
||||
try
|
||||
{
|
||||
proto = `${wrapKey('erudaProto')}: ${stringify(proto, {visited, topObj, getterVal, keyQuotes, highlight})}`;
|
||||
proto = `${wrapKey('erudaProto')}: ${stringify(proto, {visited, topObj, getterVal, keyQuotes, highlight, unenumerable})}`;
|
||||
} catch(e)
|
||||
{
|
||||
proto = `${wrapKey('erudaProto')}: ${wrapStr('"' + escapeJsonStr(e.message) + '"')}`;
|
||||
@@ -187,7 +188,7 @@ export default function stringify(obj, {
|
||||
return parts.push(`${key}: "(...)"`);
|
||||
}
|
||||
}
|
||||
parts.push(`${key}: ${stringify(topObj[name], {visited, getterVal, simple, keyQuotes, highlight})}`);
|
||||
parts.push(`${key}: ${stringify(topObj[name], {visited, getterVal, simple, keyQuotes, highlight, unenumerable})}`);
|
||||
});
|
||||
if (proto) parts.push(proto);
|
||||
json += parts.join(',\n') + '\n}';
|
||||
|
||||
Reference in New Issue
Block a user