|
679 | 679 | //: |
680 | 680 |
|
681 | 681 |
|
| 682 | + function datatype(v){return Object.prototype.toString.call(v).slice(8,-1).toLowerCase()} |
| 683 | + |
| 684 | + |
682 | 685 | function format(args){ |
683 | 686 |
|
684 | 687 | if (typeof args[0] !== "string") return args; |
|
731 | 734 |
|
732 | 735 | format.fn = function(val,seen=new WeakSet()){ |
733 | 736 |
|
734 | | - if (val === null) return 'null'; |
735 | | - if (val === undefined) return 'undefined'; |
| 737 | + if(val === null)return 'null'; |
| 738 | + if(val === undefined)return 'undefined'; |
736 | 739 |
|
737 | 740 | // Prevent circular references |
738 | | - if (typeof val === 'object' || typeof val === 'function') { |
739 | | - if (seen.has(val)) return '[Circular]'; |
| 741 | + if(typeof val==='object' || typeof val==='function'){ |
| 742 | + if(seen.has(val))return '[Circular]'; |
740 | 743 | seen.add(val); |
741 | 744 | } |
742 | 745 |
|
743 | 746 | // Primitive types |
744 | | - switch (typeof val) { |
745 | | - |
746 | | - case 'number': return String(val); |
747 | | - case 'string': return val; |
748 | | - case 'boolean': return String(val); |
749 | | - case 'bigint': return val.toString() + 'n'; |
750 | | - case 'symbol': return val.toString(); |
751 | | - case 'function': return `[Function${val.name ? ': ' + val.name : ''}]`; |
| 747 | + switch(typeof val){ |
| 748 | + |
| 749 | + case 'number' : return String(val); |
| 750 | + case 'string' : return val; |
| 751 | + case 'boolean' : return String(val); |
| 752 | + case 'bigint' : return val.toString() + 'n'; |
| 753 | + case 'symbol' : return val.toString(); |
| 754 | + case 'function' : return `[Function${val.name ? ': '+val.name : ''}]`; |
752 | 755 |
|
753 | 756 | }//switch |
754 | 757 |
|
755 | | - if(Array.isArray(val)){ |
| 758 | + var type = datatype(val); |
| 759 | + |
| 760 | + if(type=='array'){ |
756 | 761 | return '['+val.map(v=>fn(v,seen)).join(', ')+']'; |
757 | 762 | } |
758 | 763 |
|
759 | | - if(val instanceof Date){ |
| 764 | + if(type=='date'){//val instanceof Date){ |
760 | 765 | return `Date("${val.toISOString()}")`; |
761 | 766 | } |
762 | 767 |
|
|
0 commit comments