提交 6b2a54bb 编写于 作者: fxy060608's avatar fxy060608

fixt(cli): format-log.js(es6=>es5)

上级 27411818
function typof (v) { function typof (v) {
const s = Object.prototype.toString.call(v) var s = Object.prototype.toString.call(v)
return s.substring(8, s.length - 1) return s.substring(8, s.length - 1)
} }
export default function formatLog (...args) { export default function formatLog () {
const msgs = args.map((v) => { for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
const type = Object.prototype.toString.call(v) args[_key] = arguments[_key]
}
var msgs = args.map(function (v) {
var type = Object.prototype.toString.call(v)
if (type.toLowerCase() === '[object object]') { if (type.toLowerCase() === '[object object]') {
try { try {
v = '---BEGIN:JSON---' + JSON.stringify(v) + '---END:JSON---' v = '---BEGIN:JSON---' + JSON.stringify(v) + '---END:JSON---'
...@@ -18,7 +23,8 @@ export default function formatLog (...args) { ...@@ -18,7 +23,8 @@ export default function formatLog (...args) {
} else if (v === undefined) { } else if (v === undefined) {
v = '---UNDEFINED---' v = '---UNDEFINED---'
} else { } else {
const vType = typof(v).toUpperCase() var vType = typof(v).toUpperCase()
if (vType === 'NUMBER' || vType === 'BOOLEAN') { if (vType === 'NUMBER' || vType === 'BOOLEAN') {
v = '---BEGIN:' + vType + '---' + v + '---END:' + vType + '---' v = '---BEGIN:' + vType + '---' + v + '---END:' + vType + '---'
} else { } else {
...@@ -26,12 +32,15 @@ export default function formatLog (...args) { ...@@ -26,12 +32,15 @@ export default function formatLog (...args) {
} }
} }
} }
return v return v
}) })
let msg = '' var msg = ''
if (msgs.length > 1) { if (msgs.length > 1) {
const lastMsg = msgs.pop() var lastMsg = msgs.pop()
msg = msgs.join('---COMMA---') msg = msgs.join('---COMMA---')
if (lastMsg.indexOf(' at ') === 0) { if (lastMsg.indexOf(' at ') === 0) {
msg += lastMsg msg += lastMsg
} else { } else {
...@@ -40,5 +49,6 @@ export default function formatLog (...args) { ...@@ -40,5 +49,6 @@ export default function formatLog (...args) {
} else { } else {
msg = msgs[0] msg = msgs[0]
} }
return msg return msg
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册