MCPcopy Index your code
hub / github.com/Effect-TS/effect / go

Function go

packages/effect/src/Inspectable.ts:100–157  ·  view source on GitHub ↗
(v: unknown, d = 0)

Source from the content-addressed store, hash-verified

98 }
99
100 function go(v: unknown, d = 0): string {
101 if (Array.isArray(v)) {
102 if (seen.has(v)) return CIRCULAR
103 seen.add(v)
104 if (!gap || v.length <= 1) return `[${v.map((x) => go(x, d)).join(",")}]`
105 const inner = v.map((x) => go(x, d + 1)).join(",\n" + ind(d + 1))
106 return `[\n${ind(d + 1)}${inner}\n${ind(d)}]`
107 }
108
109 if (Predicate.isDate(v)) return formatDate(v)
110
111 if (
112 !options?.ignoreToString &&
113 Predicate.hasProperty(v, "toString") &&
114 Predicate.isFunction(v["toString"]) &&
115 v["toString"] !== Object.prototype.toString &&
116 v["toString"] !== Array.prototype.toString
117 ) {
118 const s = safeToString(v)
119 if (v instanceof Error && v.cause) {
120 return `${s} (cause: ${go(v.cause, d)})`
121 }
122 return s
123 }
124
125 if (Predicate.isString(v)) return JSON.stringify(v)
126
127 if (
128 Predicate.isNumber(v) ||
129 v == null ||
130 Predicate.isBoolean(v) ||
131 Predicate.isSymbol(v)
132 ) return String(v)
133
134 if (Predicate.isBigInt(v)) return String(v) + "n"
135
136 if (v instanceof Set || v instanceof Map) {
137 if (seen.has(v)) return CIRCULAR
138 seen.add(v)
139 return `${v.constructor.name}(${go(Array.from(v), d)})`
140 }
141
142 if (Predicate.isObject(v)) {
143 if (seen.has(v)) return CIRCULAR
144 seen.add(v)
145 const keys = ownKeys(v)
146 if (!gap || keys.length <= 1) {
147 const body = `{${keys.map((k) => `${formatPropertyKey(k)}:${go((v as any)[k], d)}`).join(",")}}`
148 return wrap(v, body)
149 }
150 const body = `{\n${
151 keys.map((k) => `${ind(d + 1)}${formatPropertyKey(k)}: ${go((v as any)[k], d + 1)}`).join(",\n")
152 }\n${ind(d)}}`
153 return wrap(v, body)
154 }
155
156 return String(v)
157 }

Callers 1

formatUnknownFunction · 0.70

Calls 10

indFunction · 0.85
formatDateFunction · 0.85
safeToStringFunction · 0.85
StringInterface · 0.85
ownKeysFunction · 0.70
formatPropertyKeyFunction · 0.70
wrapFunction · 0.70
addMethod · 0.65
joinMethod · 0.65
mapMethod · 0.65

Tested by

no test coverage detected