Dev: Table log

This commit is contained in:
surunzi
2017-01-16 16:15:21 +08:00
parent 1217cb918c
commit 1c83329564
4 changed files with 81 additions and 2 deletions

View File

@@ -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.

View File

@@ -1,6 +1,6 @@
{
"name": "eruda",
"version": "1.2.1",
"version": "1.2.2",
"description": "Console for Mobile Browsers",
"main": "eruda.js",
"scripts": {

View File

@@ -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 += `<tr><td>${idx}</td>`;
columns.forEach(column => ret += `<td>${obj[column] || ''}</td>`);
columns.forEach(column =>
{
let val = obj[column];
if (util.isUndef(val))
{
val = '';
} else if (util.isObj(val))
{
val = util.getObjType(val);
}
ret += `<td>${val}</td>`;
});
ret += '</tr>'
});

View File

@@ -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('<th>(index)</th><th>a</th><th>c</th><th>d</th>');
});
it('basic', function ()
{
tool.clear().table([{test: 1}, {test: 2, test2: 3}]);