Skip to content

Commit

Permalink
修改JSON对象解析,解析几乎所有对象
Browse files Browse the repository at this point in the history
  • Loading branch information
65147400 committed May 16, 2018
1 parent 6e18497 commit cae4286
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 15 deletions.
19 changes: 12 additions & 7 deletions src/lib/tool.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,27 +137,32 @@ export function htmlEncode(text) {

export function JSONStringify(stringObject, formatOption = '\t', replaceString = 'CIRCULAR_DEPENDECY_OBJECT') {
let cache = [];
const returnStringObject = JSON.stringify(stringObject, (key, value) => {
/* const returnStringObject = JSON.stringify(stringObject, (key, value) => {
if (typeof value === 'object' && value !== null) {
if (~cache.indexOf(value)) {
return replaceString;
}
}
cache.push(value);
}
return value;
}, formatOption);
cache = null;
cache = null;*/
var returnStringObject = '{\n';
for (let key of Reflect.ownKeys(stringObject)) {
returnStringObject+=key+':'+stringObject[key]+',\n';
}
returnStringObject+='}';
return returnStringObject;
}

window.JSON.stringify=JSONStringify;
/**
* get an object's all keys ignore whether they are not enumerable
*/
export function getObjAllKeys(obj) {
if (!isObject(obj) && !isArray(obj)) {
return [];
}
let dontEnums = [
/* let dontEnums = [
'toString',
'toLocaleString',
'valueOf',
Expand All @@ -172,8 +177,8 @@ export function getObjAllKeys(obj) {
keys.push(key);
}
}
keys = keys.sort();
return keys;
keys = keys.sort();*/
return Object.getOwnPropertyNames(obj).sort();
}

/**
Expand Down
12 changes: 4 additions & 8 deletions src/log/default.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class VConsoleDefaultTab extends VConsoleLogTab {
onReady() {
let that = this;
super.onReady();
var winKeys = [];
var winKeys = Object.getOwnPropertyNames(window).sort();

var cache_obj = {};
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) {
Expand Down Expand Up @@ -69,10 +69,10 @@ class VConsoleDefaultTab extends VConsoleLogTab {
if ('.' == value.substring(value.length - 1)) {
var key = value.substring(0, value.length - 1);
if (!cache_obj[key]) {
var val = [];
/* var val = [];
cache_obj[key] = {};
JSONStringify(eval('(' + key + ')'), val);
cache_obj[key] = val;
JSONStringify(eval('(' + key + ')'), val);*/
cache_obj[key] = Object.getOwnPropertyNames(eval('(' + key + ')')).sort();
}
cache_obj[key].sort();
for (var i = 0; i < cache_obj[key].length; i++) {
Expand All @@ -87,7 +87,6 @@ class VConsoleDefaultTab extends VConsoleLogTab {
prompted.appendChild(li);
}
} else if ('.' != value.substring(value.length - 1) && value.indexOf('.') < 0) {
winKeys.sort();
for (var i = 0; i < winKeys.length; i++) {
if (winKeys[i].toLowerCase().indexOf(value.toLowerCase()) >= 0) {
var li = document.createElement('li');
Expand Down Expand Up @@ -132,9 +131,6 @@ class VConsoleDefaultTab extends VConsoleLogTab {
prompted.style.display = 'none';
}
};
setTimeout(function () {
JSONStringify(this, winKeys);
},200);


$.bind($.one('.vc-cmd', this.$tabbox), 'submit', function(e) {
Expand Down

0 comments on commit cae4286

Please sign in to comment.