MCPcopy
hub / github.com/vuejs/core / replacer

Function replacer

packages/shared/src/toDisplayString.ts:38–62  ·  view source on GitHub ↗
(_key: string, val: unknown)

Source from the content-addressed store, hash-verified

36}
37
38const replacer = (_key: string, val: unknown): any => {
39 if (isRef(val)) {
40 return replacer(_key, val.value)
41 } else if (isMap(val)) {
42 return {
43 [`Map(${val.size})`]: [...val.entries()].reduce(
44 (entries, [key, val], i) => {
45 entries[stringifySymbol(key, i) + ' =>'] = val
46 return entries
47 },
48 {} as Record<string, any>,
49 ),
50 }
51 } else if (isSet(val)) {
52 return {
53 [`Set(${val.size})`]: [...val.values()].map(v => stringifySymbol(v)),
54 }
55 } else if (isSymbol(val)) {
56 return stringifySymbol(val)
57 } else if (isObject(val) && !isArray(val) && !isPlainObject(val)) {
58 // native elements
59 return String(val)
60 }
61 return val
62}
63
64const stringifySymbol = (v: unknown, i: number | string = ''): any =>
65 // Symbol.description in es2019+ so we need to cast here to pass

Callers

nothing calls this directly

Calls 9

isMapFunction · 0.90
isSetFunction · 0.90
isSymbolFunction · 0.90
isObjectFunction · 0.90
isPlainObjectFunction · 0.90
stringifySymbolFunction · 0.85
StringInterface · 0.85
mapMethod · 0.80
isRefFunction · 0.70

Tested by

no test coverage detected