Skip to content

Commit f3991b9

Browse files
save file
1 parent d69a607 commit f3991b9

File tree

1 file changed

+68
-38
lines changed

1 file changed

+68
-38
lines changed

utils/editors/js-console/html/output-console/output-console.html

Lines changed: 68 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,16 @@
5454
<script>
5555

5656
(function output_console({mod,dom,host}){
57-
//console.log('output');
57+
5858
var obj = {
5959
version : 'v2.0',
6060
};
6161

62-
62+
var df=false,did='output-console'
63+
;
64+
65+
66+
6367
var ext,$
6468
;
6569

@@ -100,7 +104,7 @@
100104

101105

102106
obj.init = async function(){
103-
107+
debug('init',obj.version);
104108
await libs();
105109

106110
}//init
@@ -118,7 +122,7 @@
118122

119123

120124
obj.initdom = function(rootnode){
121-
125+
debug('initdom');
122126
shadow = host.shadowRoot;
123127

124128
chk.persist = $.chkbox(shadow,'#console-persist',false);
@@ -140,14 +144,14 @@
140144

141145

142146
btn.kill = function(){
143-
147+
debug('btn.kill');
144148
kill();
145149

146150
}//kill
147151

148152

149153
btn.clear = function(){
150-
154+
debug('btn.clear');
151155
clear();
152156

153157
}//clear
@@ -165,7 +169,7 @@
165169

166170

167171
obj.run = async function(js,params={}){
168-
console.log('run');
172+
debug('run');
169173
var sandbox = (()=>{
170174

171175
var console = {};
@@ -221,7 +225,7 @@
221225

222226

223227
obj.run.iframe = async function(js,params={}){
224-
console.log('run.iframe');
228+
debug('run.iframe');
225229
var resolve,promise=new Promise(res=>resolve=res);
226230

227231
if(iframe){
@@ -271,7 +275,7 @@
271275

272276

273277
obj.run.iframe2 = async function(js,params={}){
274-
console.log('run.iframe2');
278+
debug('run.iframe2');
275279
var resolve,promise=new Promise(res=>resolve=res);
276280

277281
if(iframe){
@@ -675,6 +679,9 @@
675679
//:
676680

677681

682+
function datatype(v){return Object.prototype.toString.call(v).slice(8,-1).toLowerCase()}
683+
684+
678685
function format(args){
679686

680687
if (typeof args[0] !== "string") return args;
@@ -727,82 +734,84 @@
727734

728735
format.fn = function(val,seen=new WeakSet()){
729736

730-
if (val === null) return 'null';
731-
if (val === undefined) return 'undefined';
737+
if(val === null)return 'null';
738+
if(val === undefined)return 'undefined';
732739

733740
// Prevent circular references
734-
if (typeof val === 'object' || typeof val === 'function') {
735-
if (seen.has(val)) return '[Circular]';
741+
if(typeof val==='object' || typeof val==='function'){
742+
if(seen.has(val))return '[Circular]';
736743
seen.add(val);
737744
}
738745

739746
// Primitive types
740-
switch (typeof val) {
741-
742-
case 'number': return String(val);
743-
case 'string': return val;
744-
case 'boolean': return String(val);
745-
case 'bigint': return val.toString() + 'n';
746-
case 'symbol': return val.toString();
747-
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 : ''}]`;
748755

749756
}//switch
750757

751-
if (Array.isArray(val)) {
752-
return '[' + val.map(v => fn(v, seen)).join(', ') + ']';
758+
var type = datatype(val);
759+
760+
if(type=='array'){
761+
return '['+val.map(v=>fn(v,seen)).join(', ')+']';
753762
}
754763

755-
if (val instanceof Date) {
764+
if(type=='date'){//val instanceof Date){
756765
return `Date("${val.toISOString()}")`;
757766
}
758767

759-
if (val instanceof RegExp) {
768+
if(val instanceof RegExp){
760769
return val.toString();
761770
}
762771

763-
if (val instanceof Error) {
772+
if(val instanceof Error){
764773
return `${val.name}: ${val.message}`;
765774
}
766775

767-
if (val instanceof Map) {
776+
if(val instanceof Map){
768777
const entries = [];
769778
for (const [k, v] of val.entries()) {
770779
entries.push(`${fn(k, seen)} => ${fn(v, seen)}`);
771780
}
772781
return `Map { ${entries.join(', ')} }`;
773782
}
774783

775-
if (val instanceof Set) {
776-
const entries = [...val].map(v => fn(v, seen));
784+
if(val instanceof Set){
785+
const entries = [...val].map(v=>fn(v,seen));
777786
return `Set { ${entries.join(', ')} }`;
778787
}
779788

780-
if (ArrayBuffer.isView(val) && !(val instanceof DataView)) {
789+
if(ArrayBuffer.isView(val) && !(val instanceof DataView)){
781790
return `${val.constructor.name} [ ${Array.from(val).join(', ')} ]`;
782791
}
783792

784-
if (val instanceof Node) {
785-
if (val.nodeType === 1) {
786-
return `<${val.tagName.toLowerCase()}>`;
793+
if(val instanceof Node){
794+
if(val.nodeType===1){
795+
return `<${val.tagName.toLowerCase()}>`;
787796
}
788797
return val.toString();
789798
}
790799

791-
if (typeof val === 'object') {
792-
const entries = Object.entries(val).map(([k, v]) => {
800+
if(typeof val==='object'){
801+
const entries = Object.entries(val).map(([k, v])=>{
793802

794803
return `${k}: ${fn(v, seen)}`;
795804

796805
});
797806
return `{ ${entries.join(', ')} }`;
798807
}
799808

800-
try {
809+
try{
801810

802811
return JSON.stringify(val);
803812

804813
}//try
805-
catch {
814+
catch{
806815

807816
return String(val);
808817

@@ -881,11 +890,32 @@
881890

882891

883892

893+
function debug(...args){
894+
895+
if(!df && !obj.df)return;
896+
args.unshift(`[ ${did} ]`);
897+
var fmt = Array.from({length:args.length}).fill('%O').join(' ');
898+
var args2 = [fmt].concat(args);
899+
console.groupCollapsed.apply(console,args2);
900+
console.trace();
901+
console.groupEnd();
902+
903+
}//debug
904+
905+
906+
907+
908+
884909
return obj;
885910

886-
})//output_console
911+
//output_console
912+
})
913+
887914

888915
</script>
889916

917+
890918
</output-console>
891919

920+
921+

0 commit comments

Comments
 (0)