MCPcopy Create free account
hub / github.com/ICBNetwork/web3-Wallet / debugString

Function debugString

ppom/src/ppom.js:122–185  ·  view source on GitHub ↗
(val)

Source from the content-addressed store, hash-verified

120}
121
122function debugString(val) {
123 // primitive types
124 const type = typeof val;
125 if (type == 'number' || type == 'boolean' || val == null) {
126 return `${val}`;
127 }
128 if (type == 'string') {
129 return `"${val}"`;
130 }
131 if (type == 'symbol') {
132 const description = val.description;
133 if (description == null) {
134 return 'Symbol';
135 } else {
136 return `Symbol(${description})`;
137 }
138 }
139 if (type == 'function') {
140 const name = val.name;
141 if (typeof name == 'string' && name.length > 0) {
142 return `Function(${name})`;
143 } else {
144 return 'Function';
145 }
146 }
147 // objects
148 if (Array.isArray(val)) {
149 const length = val.length;
150 let debug = '[';
151 if (length > 0) {
152 debug += debugString(val[0]);
153 }
154 for(let i = 1; i < length; i++) {
155 debug += ', ' + debugString(val[i]);
156 }
157 debug += ']';
158 return debug;
159 }
160 // Test for built-in
161 const builtInMatches = /\[object ([^\]]+)\]/.exec(toString.call(val));
162 let className;
163 if (builtInMatches.length > 1) {
164 className = builtInMatches[1];
165 } else {
166 // Failed to match the standard '[object ClassName]'
167 return toString.call(val);
168 }
169 if (className == 'Object') {
170 // we're a user defined class or Object
171 // JSON.stringify avoids problems with cycles, and is generally much
172 // easier than looping through ownProperties of `val`.
173 try {
174 return 'Object(' + JSON.stringify(val) + ')';
175 } catch (_) {
176 return 'Object';
177 }
178 }
179 // errors

Callers 1

__wbg_get_importsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected