MCPcopy Create free account
hub / github.com/cyrus-and/fracker / stringify

Method stringify

app/lib/stringifier.js:10–105  ·  view source on GitHub ↗
(object)

Source from the content-addressed store, hash-verified

8 }
9
10 stringify(object) {
11 let matched = false;
12 let string = '';
13 if (typeof(object) === 'object' && object !== null) {
14 if (Array.isArray(object)) {
15 string += '[';
16 let i = 0;
17 for (const element of object) {
18 // separator
19 if (i++ !== 0) {
20 string += ', ';
21 }
22
23 // stringify the element
24 const result = this.stringify(element);
25 if (!result) {
26 return null;
27 }
28 string += result.string;
29 matched = matched || result.matched;
30 }
31 string += ']';
32 } else {
33 string += '{';
34 let i = 0;
35 for (const key of Object.keys(object)) {
36 let result;
37
38 // separator
39 if (i++ !== 0) {
40 string += ', ';
41 }
42
43 // stringify the key
44 result = this.stringify(key);
45 if (!result) {
46 return null;
47 }
48 string += result.string;
49 matched = matched || result.matched;
50
51 // separator
52 string += ': ';
53
54 // stringify the value
55 result = this.stringify(object[key]);
56 if (!result) {
57 return null;
58 }
59 string += result.string;
60 matched = matched || result.matched;
61 }
62 string += '}';
63 }
64 } else {
65 // non-string objects are just converted, strings are matched and highlighted
66 if (typeof(object) !== 'string') {
67 string += String(object);

Callers 5

runFunction · 0.95
formatCallMethod · 0.80
formatReturnMethod · 0.80
_formatHeaderIfNeededMethod · 0.80

Calls 3

excludeMethod · 0.80
getMethod · 0.80
isEmptyMethod · 0.80

Tested by

no test coverage detected