MCPcopy Create free account
hub / github.com/apitable/apitable / debugString

Function debugString

packages/databus-wasm-nodejs/databus_wasm.js:130–193  ·  view source on GitHub ↗
(val)

Source from the content-addressed store, hash-verified

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

Callers 1

databus_wasm.jsFile · 0.70

Calls 2

execMethod · 0.80
stringifyMethod · 0.80

Tested by

no test coverage detected