From 1c83329564630182b376dce77c8bcc333ff82fab Mon Sep 17 00:00:00 2001 From: surunzi Date: Mon, 16 Jan 2017 16:15:21 +0800 Subject: [PATCH] Dev: Table log --- doc/UTIL_API.md | 60 +++++++++++++++++++++++++++++++++++++++++++++ package.json | 2 +- src/Console/Log.es6 | 15 +++++++++++- test/console.js | 6 +++++ 4 files changed, 81 insertions(+), 2 deletions(-) diff --git a/doc/UTIL_API.md b/doc/UTIL_API.md index b5a4c4a..d78f559 100644 --- a/doc/UTIL_API.md +++ b/doc/UTIL_API.md @@ -594,6 +594,53 @@ Used to create extend, extendOwn and defaults. |defaults|boolean |No override when set to true | |return |function|Result function, extend... | +## dateFormat + +Simple but extremely useful date format function. + +|Name |Type |Desc | +|---------------|-------|---------------------| +|[date=new Date]|Date |Date object to format| +|mask |string |Format mask | +|[utc=false] |boolean|UTC or not | +|[gmt=false] |boolean|GMT or not | + +|Mask|Description | +|----|-----------------------------------------------------------------| +|d |Day of the month as digits; no leading zero for single-digit days| +|dd |Day of the month as digits; leading zero for single-digit days | +|ddd |Day of the week as a three-letter abbreviation | +|dddd|Day of the week as its full name | +|m |Month as digits; no leading zero for single-digit months | +|mm |Month as digits; leading zero for single-digit months | +|mmm |Month as a three-letter abbreviation | +|mmmm|Month as its full name | +|yy |Year as last two digits; leading zero for years less than 10 | +|yyyy|Year represented by four digits | +|h |Hours; no leading zero for single-digit hours (12-hour clock) | +|hh |Hours; leading zero for single-digit hours (12-hour clock) | +|H |Hours; no leading zero for single-digit hours (24-hour clock) | +|HH |Hours; leading zero for single-digit hours (24-hour clock) | +|M |Minutes; no leading zero for single-digit minutes | +|MM |Minutes; leading zero for single-digit minutes | +|s |Seconds; no leading zero for single-digit seconds | +|ss |Seconds; leading zero for single-digit seconds | +|l L |Milliseconds. l gives 3 digits. L gives 2 digits | +|t |Lowercase, single-character time marker string: a or p | +|tt |Lowercase, two-character time marker string: am or pm | +|T |Uppercase, single-character time marker string: A or P | +|TT |Uppercase, two-character time marker string: AM or PM | +|Z |US timezone abbreviation, e.g. EST or MDT | +|o |GMT/UTC timezone offset, e.g. -0500 or +0230 | +|S |The date's ordinal suffix (st, nd, rd, or th) | +|UTC:|Must be the first four characters of the mask | + +```javascript +dateFormat('isoDate'); // -> 2016-11-19 +dateFormat('yyyy-mm-dd HH:MM:ss'); // -> 2016-11-19 19:00:04 +dateFormat(new Date(), 'yyyy-mm-dd'); // -> 2016-11-19 +``` + ## defaults Fill in undefined properties in object with the first value present in the following list of defaults objects. @@ -892,6 +939,19 @@ isBool(1); // -> false No documentation. +## isDate + +Check if value is classified as a Date object. + +|Name |Type |Desc | +|------|-------|------------------------------| +|val |* |value to check | +|return|boolean|True if value is a Date object| + +```javascript +isDate(new Date()); // -> true +``` + ## isEl Check if value is a DOM element. diff --git a/package.json b/package.json index 15081db..f7c6e45 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "eruda", - "version": "1.2.1", + "version": "1.2.2", "description": "Console for Mobile Browsers", "main": "eruda.js", "scripts": { diff --git a/src/Console/Log.es6 b/src/Console/Log.es6 index 362dbc6..32f3938 100644 --- a/src/Console/Log.es6 +++ b/src/Console/Log.es6 @@ -203,6 +203,7 @@ function formatTable(args) columns = columns.concat(Object.getOwnPropertyNames(val)); }); columns = util.unique(columns); + columns.sort(); if (filter) columns = columns.filter(val => util.contain(filter, val)); if (util.isEmpty(columns)) return formatMsg(args); @@ -214,7 +215,19 @@ function formatTable(args) { if (!util.isObj(obj)) return; ret += `${idx}`; - columns.forEach(column => ret += `${obj[column] || ''}`); + columns.forEach(column => + { + let val = obj[column]; + if (util.isUndef(val)) + { + val = ''; + } else if (util.isObj(val)) + { + val = util.getObjType(val); + } + + ret += `${val}`; + }); ret += '' }); diff --git a/test/console.js b/test/console.js index 4f52b92..cd07e18 100644 --- a/test/console.js +++ b/test/console.js @@ -127,6 +127,12 @@ describe('table', function () expect($tool.find('.eruda-table')).not.toContainElement('table'); }); + it('sort keys', function () + { + tool.clear().table([{a: 1}, {d: 2, a: 2}, {c: 1}]); + expect($tool.find('.eruda-table thead tr')).toContainHtml('(index)acd'); + }); + it('basic', function () { tool.clear().table([{test: 1}, {test: 2, test2: 3}]);