Comparing version 3.2.0 to 3.2.1
[English](./CHANGELOG.md) | 简体中文 | ||
#### V3.2.1 (2019-01-16) | ||
- 【特性】新增控制台输入提示。 (by @65147400) | ||
- 【修复】修复 `JSON.stringify` 函数被错误地改写的问题。 | ||
- 【修复】修复清空日志时没有重置 `logNumber` 的问题。 (by @liuyuekeng) | ||
- 【修复】修复 Network 面板中 HTML 标签未被 encode 的问题。 (by @mokang) | ||
- 【修复】修复 Storage 面板 decode 内容时可能会导致崩溃的问题。 (by @wolfsilver) | ||
- 【优化】增加底部安全区域,适配 iPhone X 等全面屏。 (by @dingyi1993) | ||
#### V3.2.0 (2018-04-10) | ||
@@ -4,0 +14,0 @@ |
English | [简体中文](./CHANGELOG_CN.md) | ||
#### V3.2.1 (2019-01-16) | ||
- [FEATURE] Add console command prompt. (by @65147400) | ||
- [FIX] Fix `JSON.stringify` function which was incorrectly rewritten. | ||
- [FIX] Fix `logNumber` bug which was not reset when clear logs. (by @liuyuekeng) | ||
- [FIX] Fix unencoded HTML tag in Network tab. (by @mokang) | ||
- [FIX] Fix possible crash when decode content in Storage tab. (by @wolfsilver) | ||
- [IMPROVE] Add bottom safe area to adapt to full screen such as iPhone X. (by @dingyi1993) | ||
#### V3.2.0 (2018-04-10) | ||
@@ -4,0 +14,0 @@ |
@@ -61,4 +61,4 @@ [English](./tutorial.md) | 简体中文 | ||
vConsole.setOption({maxLogNumber: 5000}); | ||
``` | ||
### 打印日志 | ||
@@ -139,2 +139,2 @@ | ||
[前往:文档索引](./a_doc_index_CN.md) | ||
[前往:文档索引](./a_doc_index_CN.md) |
{ | ||
"name": "vconsole", | ||
"version": "3.2.0", | ||
"version": "3.2.1", | ||
"description": "A lightweight, extendable front-end developer tool for mobile web page.", | ||
@@ -22,18 +22,20 @@ "homepage": "https://github.com/Tencent/vConsole", | ||
"devDependencies": { | ||
"babel-core": "^6.7.7", | ||
"babel-loader": "^6.2.4", | ||
"babel-plugin-add-module-exports": "^0.1.4", | ||
"babel-preset-es2015": "^6.6.0", | ||
"babel-preset-stage-3": "^6.5.0", | ||
"chai": "^3.5.0", | ||
"css-loader": "^0.23.1", | ||
"extract-text-webpack-plugin": "^1.0.1", | ||
"html-loader": "^0.4.3", | ||
"jsdom": "^9.2.1", | ||
"json-loader": "^0.5.4", | ||
"less": "^2.5.3", | ||
"less-loader": "^2.2.3", | ||
"mocha": "^2.5.3", | ||
"style-loader": "^0.13.1", | ||
"webpack": "~1.12.11" | ||
"@babel/core": "^7.2.2", | ||
"@babel/preset-env": "^7.2.3", | ||
"@babel/plugin-proposal-class-properties": "^7.2.3", | ||
"@babel/plugin-proposal-export-namespace-from": "^7.2.0", | ||
"@babel/plugin-proposal-object-rest-spread": "^7.2.0", | ||
"babel-loader": "^8.0.4", | ||
"babel-plugin-add-module-exports": "^1.0.0", | ||
"chai": "^4.2.0", | ||
"css-loader": "^2.1.0", | ||
"html-loader": "^0.5.5", | ||
"jsdom": "^13.1.0", | ||
"json-loader": "^0.5.7", | ||
"less": "^3.9.0", | ||
"less-loader": "^4.1.0", | ||
"mocha": "^5.2.0", | ||
"style-loader": "^0.23.1", | ||
"webpack": "^4.28.4", | ||
"webpack-cli": "^3.2.1" | ||
}, | ||
@@ -40,0 +42,0 @@ "author": "Tencent", |
@@ -84,9 +84,2 @@ [English](./README.md) | 简体中文 | ||
## CDN | ||
- [v3.0.0](https://res.wx.qq.com/mmbizwap/zh_CN/htmledition/js/vconsole/3.0.0/vconsole.min.js) (推荐) | ||
- [v2.5.2](https://res.wx.qq.com/mmbizwap/zh_CN/htmledition/js/vconsole/2.5.2/vconsole.min.js) | ||
## 交流反馈 | ||
@@ -93,0 +86,0 @@ |
@@ -72,10 +72,4 @@ English | [简体中文](./README_CN.md) | ||
- [vconsole-webpack-plugin](https://github.com/diamont1001/vconsole-webpack-plugin) | ||
## CDN | ||
- [v3.0.0](https://res.wx.qq.com/mmbizwap/zh_CN/htmledition/js/vconsole/3.0.0/vconsole.min.js) (Recommended) | ||
- [v2.5.2](https://res.wx.qq.com/mmbizwap/zh_CN/htmledition/js/vconsole/2.5.2/vconsole.min.js) | ||
## Changelog | ||
@@ -82,0 +76,0 @@ |
@@ -55,3 +55,3 @@ /* | ||
let toolList = [{ | ||
name: 'Expend', | ||
name: 'Expand', | ||
global: false, | ||
@@ -237,3 +237,3 @@ onClick: function(e) { | ||
node.view = $view; | ||
// expend | ||
// expand | ||
$.delegate($view, 'click', '.vcelm-node', function(event) { | ||
@@ -360,2 +360,2 @@ event.stopPropagation(); | ||
export default VConsoleElementsTab; | ||
export default VConsoleElementsTab; |
@@ -68,3 +68,3 @@ /** | ||
if (scriptList.length > 0) { | ||
nonce = scriptList[0].getAttribute('nonce') || ''; // get nonce to avoid `unsafe-inline` | ||
nonce = scriptList[0].nonce || ''; // get nonce to avoid `unsafe-inline` | ||
} | ||
@@ -71,0 +71,0 @@ let script = document.createElement('SCRIPT'); |
@@ -61,6 +61,6 @@ /* | ||
export function isUndefined(value) { | ||
return Object.prototype.toString.call(value) == '[object Undefined]'; | ||
return value === undefined; | ||
} | ||
export function isNull(value) { | ||
return Object.prototype.toString.call(value) == '[object Null]'; | ||
return value === null; | ||
} | ||
@@ -136,18 +136,47 @@ export function isSymbol(value) { | ||
/** | ||
* JSON stringify, support circular structure | ||
* Simple JSON stringify, stringify top level key-value | ||
*/ | ||
export function JSONStringify(stringObject) { | ||
if (!isObject(stringObject) && !isArray(stringObject)) { | ||
return JSON.stringify(stringObject); | ||
} | ||
export function JSONStringify(stringObject, formatOption = '\t', replaceString = 'CIRCULAR_DEPENDECY_OBJECT') { | ||
let cache = []; | ||
const returnStringObject = JSON.stringify(stringObject, (key, value) => { | ||
if (typeof value === 'object' && value !== null) { | ||
if (~cache.indexOf(value)) { | ||
return replaceString; | ||
} | ||
cache.push(value); | ||
let prefix = '{', suffix = '}'; | ||
if (isArray(stringObject)) { | ||
prefix = '['; | ||
suffix = ']' | ||
} | ||
let str = prefix; | ||
const keys = getObjAllKeys(stringObject); | ||
for (let i = 0; i < keys.length; i ++) { | ||
const key = keys[i]; | ||
const value = stringObject[key]; | ||
try { | ||
// key | ||
if (!isArray(stringObject)) { | ||
if (isObject(key) || isArray(key) || isSymbol(key)) { | ||
str += Object.prototype.toString.call(key); | ||
} else { | ||
str += key; | ||
} | ||
str += ': '; | ||
} | ||
// value | ||
if (isArray(value)) { | ||
str += 'Array[' + value.length + ']'; | ||
} else if (isObject(value) || isSymbol(value) || isFunction(value)) { | ||
str += Object.prototype.toString.call(value); | ||
} else { | ||
str += JSON.stringify(value); | ||
} | ||
if (i < keys.length - 1) { | ||
str += ', '; | ||
} | ||
} catch (e) { | ||
continue; | ||
} | ||
return value; | ||
}, formatOption); | ||
cache = null; | ||
return returnStringObject; | ||
} | ||
str += suffix; | ||
return str; | ||
} | ||
@@ -162,19 +191,10 @@ | ||
} | ||
let dontEnums = [ | ||
'toString', | ||
'toLocaleString', | ||
'valueOf', | ||
'hasOwnProperty', | ||
'isPrototypeOf', | ||
'propertyIsEnumerable', | ||
'constructor' | ||
]; | ||
let keys = []; | ||
for (let key in obj) { | ||
if (dontEnums.indexOf(key) < 0) { | ||
keys.push(key); | ||
} | ||
if (isArray(obj)) { | ||
const m = []; | ||
obj.forEach((_, index) => { | ||
m.push(index) | ||
}); | ||
return m; | ||
} | ||
keys = keys.sort(); | ||
return keys; | ||
return Object.getOwnPropertyNames(obj).sort(); | ||
} | ||
@@ -181,0 +201,0 @@ |
@@ -27,10 +27,134 @@ /* | ||
this.tplTabbox = tplTabbox; | ||
this.windowOnError = null; | ||
} | ||
onReady() { | ||
let that = this; | ||
const that = this; | ||
super.onReady(); | ||
$.bind($.one('.vc-cmd', this.$tabbox), 'submit', function(e) { | ||
window.winKeys = Object.getOwnPropertyNames(window).sort(); | ||
window.keyTypes = {}; | ||
for (let i = 0; i < winKeys.length; i++) { | ||
keyTypes[winKeys[i]] = typeof window[winKeys[i]]; | ||
} | ||
const cacheObj = {}; | ||
const ID_REGEX = /[a-zA-Z_0-9\$\-\u00A2-\uFFFF]/; | ||
const retrievePrecedingIdentifier = (text, pos, regex) => { | ||
regex = regex || ID_REGEX; | ||
const buf = []; | ||
for (let i = pos - 1; i >= 0; i--) { | ||
if (regex.test(text[i])) { | ||
buf.push(text[i]); | ||
} else { | ||
break; | ||
} | ||
} | ||
if (buf.length == 0) { | ||
regex = /\./; | ||
for (let i = pos - 1; i >= 0; i--) { | ||
if (regex.test(text[i])) { | ||
buf.push(text[i]); | ||
} else { | ||
break; | ||
} | ||
} | ||
} | ||
if (buf.length === 0) { | ||
const arr = (text.match(/[\(\)\[\]\{\}]/gi) || []); | ||
return arr[arr.length - 1]; | ||
} | ||
return buf.reverse().join(''); | ||
}; | ||
$.bind($.one('.vc-cmd-input'), 'keyup', function (e) { | ||
const isDeleteKeyCode = e.keyCode === 8 || e.keyCode === 46; | ||
const $prompted = $.one('.vc-cmd-prompted'); | ||
$prompted.style.display = 'none'; | ||
$prompted.innerHTML = ''; | ||
const tempValue = this.value; | ||
const value = retrievePrecedingIdentifier(this.value, this.value.length); | ||
if (value && value.length > 0) { | ||
if (/\(/.test(value) && !isDeleteKeyCode) { | ||
$.one('.vc-cmd-input').value += ')'; | ||
return; | ||
} | ||
if (/\[/.test(value) && !isDeleteKeyCode) { | ||
$.one('.vc-cmd-input').value += ']'; | ||
return; | ||
} | ||
if (/\{/.test(value) && !isDeleteKeyCode) { | ||
$.one('.vc-cmd-input').value += '}'; | ||
return; | ||
} | ||
if ('.' === value) { | ||
const key = retrievePrecedingIdentifier(tempValue, tempValue.length - 1); | ||
if (!cacheObj[key]) { | ||
try { | ||
cacheObj[key] = Object.getOwnPropertyNames(eval('(' + key + ')')).sort(); | ||
} catch (e) { | ||
; | ||
} | ||
} | ||
try { | ||
for (let i = 0; i < cacheObj[key].length; i++) { | ||
const $li = document.createElement('li'); | ||
const _key = cacheObj[key][i]; | ||
$li.innerHTML = _key; | ||
$li.onclick = function () { | ||
$.one('.vc-cmd-input').value = ''; | ||
$.one('.vc-cmd-input').value = tempValue + this.innerHTML; | ||
$prompted.style.display = 'none'; | ||
}; | ||
$prompted.appendChild($li); | ||
} | ||
} catch (e) { | ||
; | ||
} | ||
} else if ('.' !== value.substring(value.length - 1) && value.indexOf('.') < 0) { | ||
for (let i = 0; i < winKeys.length; i++) { | ||
if (winKeys[i].toLowerCase().indexOf(value.toLowerCase()) >= 0) { | ||
const $li = document.createElement('li'); | ||
$li.innerHTML = winKeys[i]; | ||
$li.onclick = function () { | ||
$.one('.vc-cmd-input').value = ''; | ||
$.one('.vc-cmd-input').value = this.innerHTML; | ||
if (keyTypes[this.innerHTML] == 'function') { | ||
$.one('.vc-cmd-input').value += '()'; | ||
} | ||
$prompted.style.display = 'none'; | ||
}; | ||
$prompted.appendChild($li); | ||
} | ||
} | ||
} else { | ||
const arr = value.split('.'); | ||
if (cacheObj[arr[0]]) { | ||
cacheObj[arr[0]].sort(); | ||
for (let i = 0; i < cacheObj[arr[0]].length; i++) { | ||
const $li = document.createElement('li'); | ||
const _key = cacheObj[arr[0]][i]; | ||
if (_key.indexOf(arr[1]) >= 0) { | ||
$li.innerHTML = _key; | ||
$li.onclick = function () { | ||
$.one('.vc-cmd-input').value = ''; | ||
$.one('.vc-cmd-input').value = tempValue + this.innerHTML; | ||
$prompted.style.display = 'none'; | ||
}; | ||
$prompted.appendChild($li); | ||
} | ||
} | ||
} | ||
} | ||
if ($prompted.children.length > 0) { | ||
const m = Math.min(200, $prompted.children.length * 31); | ||
$prompted.style.display = 'block'; | ||
$prompted.style.height = m + 'px'; | ||
$prompted.style.marginTop = -m + 'px'; | ||
} | ||
} else { | ||
$prompted.style.display = 'none'; | ||
} | ||
}); | ||
$.bind($.one('.vc-cmd', this.$tabbox), 'submit', function (e) { | ||
e.preventDefault(); | ||
@@ -43,5 +167,9 @@ let $input = $.one('.vc-cmd-input', e.target), | ||
} | ||
const $prompted = $.one('.vc-cmd-prompted'); | ||
if ($prompted) { | ||
$prompted.style.display = 'none'; | ||
} | ||
}); | ||
// create a global variable to save custom command's result | ||
// create a global letiable to save custom command's result | ||
let code = ''; | ||
@@ -55,3 +183,3 @@ code += 'if (!!window) {'; | ||
if (scriptList.length > 0) { | ||
nonce = scriptList[0].getAttribute('nonce') || ''; // get nonce to avoid `unsafe-inline` | ||
nonce = scriptList[0].nonce || ''; // get nonce to avoid `unsafe-inline` | ||
} | ||
@@ -71,7 +199,7 @@ let script = document.createElement('SCRIPT'); | ||
super.mockConsole(); | ||
var that = this; | ||
let that = this; | ||
if (tool.isFunction(window.onerror)) { | ||
this.windowOnError = window.onerror; | ||
} | ||
window.onerror = function(message, source, lineNo, colNo, error) { | ||
window.onerror = function (message, source, lineNo, colNo, error) { | ||
let msg = message; | ||
@@ -87,3 +215,3 @@ if (source) { | ||
let statckInfo = (stack && error.stack.toString()) || ''; | ||
that.printLog({logType:'error', logs:[msg, statckInfo], noOrigin:true}); | ||
that.printLog({logType: 'error', logs: [msg, statckInfo], noOrigin: true}); | ||
if (tool.isFunction(that.windowOnError)) { | ||
@@ -108,55 +236,67 @@ that.windowOnError.call(window, message, source, lineNo, colNo, error); | ||
// do not use `eval` or `new Function` to avoid `unsafe-eval` CSP rule | ||
let code = ''; | ||
code += 'try {\n'; | ||
code += 'window.__vConsole_cmd_result = (function() {\n'; | ||
code += 'return ' + cmd + ';\n'; | ||
code += '})();\n'; | ||
code += 'window.__vConsole_cmd_error = false;\n'; | ||
code += '} catch (e) {\n'; | ||
code += 'window.__vConsole_cmd_result = e.message;\n'; | ||
code += 'window.__vConsole_cmd_error = true;\n'; | ||
code += '}'; | ||
let scriptList = document.getElementsByTagName('script'); | ||
let nonce = ''; | ||
if (scriptList.length > 0) { | ||
nonce = scriptList[0].getAttribute('nonce') || ''; // get nonce to avoid `unsafe-inline` | ||
/* let code = ''; | ||
code += 'try {\n'; | ||
code += 'window.__vConsole_cmd_result = (function() {\n'; | ||
code += 'return ' + cmd + ';\n'; | ||
code += '})();\n'; | ||
code += 'window.__vConsole_cmd_error = false;\n'; | ||
code += '} catch (e) {\n'; | ||
code += 'window.__vConsole_cmd_result = e.message;\n'; | ||
code += 'window.__vConsole_cmd_error = true;\n'; | ||
code += '}'; | ||
let scriptList = document.getElementsByTagName('script'); | ||
let nonce = ''; | ||
if (scriptList.length > 0) { | ||
nonce = scriptList[0].getAttribute('nonce') || ''; // get nonce to avoid `unsafe-inline` | ||
} | ||
let script = document.createElement('SCRIPT'); | ||
script.innerHTML = code; | ||
script.setAttribute('nonce', nonce); | ||
document.documentElement.appendChild(script); | ||
let result = window.__vConsole_cmd_result, | ||
error = window.__vConsole_cmd_error; | ||
document.documentElement.removeChild(script);*/ | ||
/* let code = ' try {'; | ||
code += cmd; | ||
code += ' } catch (e) {'; | ||
code += 'window.__vConsole_cmd_error = true;window.__vConsole_cmd_result = e.message;}'; | ||
eval(code.replace(new RegExp('\n', 'gi'), ''));*/ | ||
let result = void 0; | ||
try { | ||
result = eval.call(window, '(' + cmd + ')'); | ||
} catch (e) { | ||
try { | ||
result = eval.call(window, cmd); | ||
} catch (e) { | ||
; | ||
} | ||
} | ||
let script = document.createElement('SCRIPT'); | ||
script.innerHTML = code; | ||
script.setAttribute('nonce', nonce); | ||
document.documentElement.appendChild(script); | ||
let result = window.__vConsole_cmd_result, | ||
error = window.__vConsole_cmd_error; | ||
document.documentElement.removeChild(script); | ||
/* debugger | ||
let result = window.__vConsole_cmd_result, | ||
error = window.__vConsole_cmd_error;*/ | ||
// print result to console | ||
if (error == false) { | ||
let $content; | ||
if (tool.isArray(result) || tool.isObject(result)) { | ||
$content = this.getFoldedLine(result); | ||
} else { | ||
if (tool.isNull(result)) { | ||
result = 'null'; | ||
} else if (tool.isUndefined(result)) { | ||
result = 'undefined'; | ||
} else if (tool.isFunction(result)) { | ||
result = 'function()' | ||
} else if (tool.isString(result)) { | ||
result = '"' + result + '"'; | ||
} | ||
$content = $.render(tplItemCode, {content: result, type: 'output'}); | ||
let $content; | ||
if (tool.isArray(result) || tool.isObject(result)) { | ||
$content = this.getFoldedLine(result); | ||
} else { | ||
if (tool.isNull(result)) { | ||
result = 'null'; | ||
} else if (tool.isUndefined(result)) { | ||
result = 'undefined'; | ||
} else if (tool.isFunction(result)) { | ||
result = 'function()' | ||
} else if (tool.isString(result)) { | ||
result = '"' + result + '"'; | ||
} | ||
this.printLog({ | ||
logType: 'log', | ||
content: $content, | ||
noMeta: true, | ||
style: '' | ||
}); | ||
} else { | ||
this.printLog({ | ||
logType: 'error', | ||
logs: [result], | ||
noMeta: true, | ||
style: '' | ||
}); | ||
$content = $.render(tplItemCode, {content: result, type: 'output'}); | ||
} | ||
this.printLog({ | ||
logType: 'log', | ||
content: $content, | ||
noMeta: true, | ||
style: '' | ||
}); | ||
window.winKeys = Object.getOwnPropertyNames(window).sort(); | ||
} | ||
@@ -163,0 +303,0 @@ |
@@ -74,3 +74,3 @@ /* | ||
className: '', | ||
onClick: function() { | ||
onClick: function () { | ||
if (!$.hasClass(this, 'vc-actived')) { | ||
@@ -93,3 +93,3 @@ that.showLogType(this.dataset.type || 'all'); | ||
global: false, | ||
onClick: function() { | ||
onClick: function () { | ||
that.clearLog(); | ||
@@ -112,3 +112,3 @@ that.vConsole.triggerEvent('clearLog'); | ||
let $subTabs = $.all('.vc-subtab', that.$tabbox); | ||
$.bind($subTabs, 'click', function(e) { | ||
$.bind($subTabs, 'click', function (e) { | ||
e.preventDefault(); | ||
@@ -136,3 +136,3 @@ if ($.hasClass(this, 'vc-actived')) { | ||
let $content = $.one('.vc-content'); | ||
$.bind($content, 'scroll', function(e) { | ||
$.bind($content, 'scroll', function (e) { | ||
if (!that.isShow) { | ||
@@ -148,3 +148,3 @@ return; | ||
for (let i=0; i<that.logList.length; i++) { | ||
for (let i = 0; i < that.logList.length; i++) { | ||
that.printLog(that.logList[i]); | ||
@@ -252,3 +252,3 @@ } | ||
} else { | ||
methodList.map(function(method) { | ||
methodList.map(function (method) { | ||
that.console[method] = window.console[method]; | ||
@@ -271,6 +271,6 @@ }); | ||
const timeLog = {} | ||
window.console.time = function(label) { | ||
window.console.time = function (label) { | ||
timeLog[label] = Date.now(); | ||
}; | ||
window.console.timeEnd = function(label) { | ||
window.console.timeEnd = function (label) { | ||
var pre = timeLog[label]; | ||
@@ -293,3 +293,3 @@ if (pre) { | ||
$.one('.vc-log', this.$tabbox).innerHTML = ''; | ||
this.logNumber = 0; | ||
} | ||
@@ -388,3 +388,3 @@ | ||
// generate content from item.logs | ||
for (let i=0; i<logs.length; i++) { | ||
for (let i = 0; i < logs.length; i++) { | ||
let log; | ||
@@ -447,5 +447,5 @@ try { | ||
let json = tool.JSONStringify(obj); | ||
let preview = json.substr(0, 26); | ||
let preview = json.substr(0, 36); | ||
outer = tool.getObjName(obj); | ||
if (json.length > 26) { | ||
if (json.length > 36) { | ||
preview += '...'; | ||
@@ -459,3 +459,3 @@ } | ||
}); | ||
$.bind($.one('.vc-fold-outer', $line), 'click', function(e) { | ||
$.bind($.one('.vc-fold-outer', $line), 'click', function (e) { | ||
e.preventDefault(); | ||
@@ -473,86 +473,92 @@ e.stopPropagation(); | ||
let $content = $.one('.vc-fold-inner', $line); | ||
if ($content.children.length == 0 && !!obj) { | ||
// render object's keys | ||
let keys = tool.getObjAllKeys(obj); | ||
for (let i = 0; i < keys.length; i++) { | ||
let val = obj[keys[i]], | ||
valueType = 'undefined', | ||
keyType = '', | ||
$line; | ||
// handle value | ||
if (tool.isString(val)) { | ||
valueType = 'string'; | ||
val = '"' + val + '"'; | ||
} else if (tool.isNumber(val)) { | ||
valueType = 'number'; | ||
} else if (tool.isBoolean(val)) { | ||
valueType = 'boolean'; | ||
} else if (tool.isNull(val)) { | ||
valueType = 'null'; | ||
val = 'null'; | ||
} else if (tool.isUndefined(val)) { | ||
valueType = 'undefined'; | ||
val = 'undefined'; | ||
} else if (tool.isFunction(val)) { | ||
valueType = 'function'; | ||
val = 'function()'; | ||
} else if (tool.isSymbol(val)) { | ||
valueType = 'symbol'; | ||
setTimeout(function () { | ||
if ($content.children.length == 0 && !!obj) { | ||
// render object's keys | ||
let keys = tool.getObjAllKeys(obj); | ||
for (let i = 0; i < keys.length; i++) { | ||
let val, | ||
valueType = 'undefined', | ||
keyType = ''; | ||
try { | ||
val = obj[keys[i]]; | ||
} catch (e) { | ||
continue; | ||
} | ||
// handle value | ||
if (tool.isString(val)) { | ||
valueType = 'string'; | ||
val = '"' + val + '"'; | ||
} else if (tool.isNumber(val)) { | ||
valueType = 'number'; | ||
} else if (tool.isBoolean(val)) { | ||
valueType = 'boolean'; | ||
} else if (tool.isNull(val)) { | ||
valueType = 'null'; | ||
val = 'null'; | ||
} else if (tool.isUndefined(val)) { | ||
valueType = 'undefined'; | ||
val = 'undefined'; | ||
} else if (tool.isFunction(val)) { | ||
valueType = 'function'; | ||
val = 'function()'; | ||
} else if (tool.isSymbol(val)) { | ||
valueType = 'symbol'; | ||
} | ||
// render | ||
let $sub; | ||
if (tool.isArray(val)) { | ||
let name = tool.getObjName(val) + '[' + val.length + ']'; | ||
$sub = that.getFoldedLine(val, $.render(tplFoldCode, { | ||
key: keys[i], | ||
keyType: keyType, | ||
value: name, | ||
valueType: 'array' | ||
}, true)); | ||
} else if (tool.isObject(val)) { | ||
let name = tool.getObjName(val); | ||
$sub = that.getFoldedLine(val, $.render(tplFoldCode, { | ||
key: tool.htmlEncode(keys[i]), | ||
keyType: keyType, | ||
value: name, | ||
valueType: 'object' | ||
}, true)); | ||
} else { | ||
if (obj.hasOwnProperty && !obj.hasOwnProperty(keys[i])) { | ||
keyType = 'private'; | ||
} | ||
let renderData = { | ||
lineType: 'kv', | ||
key: tool.htmlEncode(keys[i]), | ||
keyType: keyType, | ||
value: tool.htmlEncode(val), | ||
valueType: valueType | ||
}; | ||
$sub = $.render(tplFold, renderData); | ||
} | ||
$content.insertAdjacentElement('beforeend', $sub); | ||
} | ||
// render | ||
let $sub; | ||
if (tool.isArray(val)) { | ||
let name = tool.getObjName(val) + '[' + val.length + ']'; | ||
$sub = that.getFoldedLine(val, $.render(tplFoldCode, { | ||
key: keys[i], | ||
keyType: keyType, | ||
value: name, | ||
valueType: 'array' | ||
}, true)); | ||
} else if (tool.isObject(val)) { | ||
let name = tool.getObjName(val); | ||
$sub = that.getFoldedLine(val, $.render(tplFoldCode, { | ||
key: tool.htmlEncode(keys[i]), | ||
keyType: keyType, | ||
value: name, | ||
valueType: 'object' | ||
}, true)); | ||
} else { | ||
if (obj.hasOwnProperty && !obj.hasOwnProperty(keys[i])) { | ||
keyType = 'private'; | ||
// render object's prototype | ||
if (tool.isObject(obj)) { | ||
let proto = obj.__proto__, | ||
$proto; | ||
if (tool.isObject(proto)) { | ||
$proto = that.getFoldedLine(proto, $.render(tplFoldCode, { | ||
key: '__proto__', | ||
keyType: 'private', | ||
value: tool.getObjName(proto), | ||
valueType: 'object' | ||
}, true)); | ||
} else { | ||
// if proto is not an object, it should be `null` | ||
$proto = $.render(tplFoldCode, { | ||
key: '__proto__', | ||
keyType: 'private', | ||
value: 'null', | ||
valueType: 'null' | ||
}); | ||
} | ||
let renderData = { | ||
lineType: 'kv', | ||
key: tool.htmlEncode(keys[i]), | ||
keyType: keyType, | ||
value: tool.htmlEncode(val), | ||
valueType: valueType | ||
}; | ||
$sub = $.render(tplFold, renderData); | ||
$content.insertAdjacentElement('beforeend', $proto); | ||
} | ||
$content.insertAdjacentElement('beforeend', $sub); | ||
} | ||
// render object's prototype | ||
if (tool.isObject(obj)) { | ||
let proto = obj.__proto__, | ||
$proto; | ||
if (tool.isObject(proto)) { | ||
$proto = that.getFoldedLine(proto, $.render(tplFoldCode, { | ||
key: '__proto__', | ||
keyType: 'private', | ||
value: tool.getObjName(proto), | ||
valueType: 'object' | ||
}, true)); | ||
} else { | ||
// if proto is not an object, it should be `null` | ||
$proto = $.render(tplFoldCode, { | ||
key: '__proto__', | ||
keyType: 'private', | ||
value: 'null', | ||
valueType: 'null' | ||
}); | ||
} | ||
$content.insertAdjacentElement('beforeend', $proto); | ||
} | ||
} | ||
}) | ||
return false; | ||
@@ -559,0 +565,0 @@ }); |
@@ -211,2 +211,3 @@ /* | ||
domData.response = JSON.stringify(item.response, null, 1); | ||
domData.response = tool.htmlEncode(domData.response); | ||
} | ||
@@ -213,0 +214,0 @@ break; |
@@ -153,5 +153,11 @@ /* | ||
value = item.join('='); | ||
try { | ||
name = decodeURIComponent(name); | ||
value = decodeURIComponent(value); | ||
} catch(e) { | ||
console.log(e, name, value); | ||
} | ||
list.push({ | ||
name: decodeURIComponent(name), | ||
value: decodeURIComponent(value) | ||
name: name, | ||
value: value | ||
}); | ||
@@ -158,0 +164,0 @@ } |
var pkg = require('./package.json'); | ||
var webpack = require('webpack'); | ||
var ExtractTextPlugin = require('extract-text-webpack-plugin'); | ||
var Webpack = require('webpack'); | ||
var Path = require('path'); | ||
module.exports = { | ||
mode: 'production', | ||
devtool: false, | ||
entry: { | ||
vconsole : './src/vconsole.js' | ||
vconsole : Path.resolve(__dirname, './src/vconsole.js') | ||
}, | ||
output: { | ||
path: './dist', | ||
path: Path.resolve(__dirname, './dist'), | ||
filename: '[name].min.js', | ||
library: 'VConsole', | ||
libraryTarget: 'umd', | ||
umdNameDefine: true | ||
umdNamedDefine: true | ||
}, | ||
module: { | ||
loaders: [ | ||
rules: [ | ||
{ | ||
test: /\.html$/, loader: 'html?minimize=false' | ||
test: /\.html$/, loader: 'html-loader?minimize=false' | ||
}, | ||
{ | ||
test: /\.js$/, loader: 'babel' | ||
test: /\.js$/, loader: 'babel-loader' | ||
}, | ||
{ | ||
test: /\.less$/, | ||
loader: 'style!css!less' | ||
// loader: ExtractTextPlugin.extract('style-loader', 'css-loader!less-loader') // 将css独立打包 | ||
}, | ||
{ | ||
test: /\.json$/, loader: 'json' | ||
loader: 'style-loader!css-loader!less-loader' | ||
} | ||
] | ||
}, | ||
stats: { | ||
colors: true, | ||
}, | ||
plugins: [ | ||
new webpack.BannerPlugin([ | ||
new Webpack.BannerPlugin([ | ||
'vConsole v' + pkg.version + ' (' + pkg.homepage + ')', | ||
@@ -45,9 +45,3 @@ '', | ||
].join('\n')) | ||
,new webpack.optimize.UglifyJsPlugin({ | ||
compress: { | ||
warnings: false | ||
} | ||
}) | ||
// ,new ExtractTextPlugin('[name].min.css') // 将css独立打包 | ||
] | ||
}; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
423458
3622
18
89
3