MCPcopy Create free account
hub / github.com/freeCodeCamp/freeCodeCamp / format

Function format

tools/client-plugins/browser-scripts/utils/format.js:6–22  ·  view source on GitHub ↗
(x)

Source from the content-addressed store, hash-verified

4import { inspect } from 'util/util.js';
5
6export function format(x) {
7 // we're trying to mimic console.log, so we avoid wrapping strings in quotes:
8 if (typeof x === 'string') return x;
9 else if (x instanceof Set) {
10 return `Set(${x.size}) {${Array.from(x).join(', ')}}`;
11 } else if (x instanceof Map) {
12 return `Map(${x.size}) {${Array.from(
13 x.entries(),
14 ([k, v]) => `${k} => ${v}`
15 ).join(', ')}})`;
16 } else if (typeof x === 'bigint') {
17 return x.toString() + 'n';
18 } else if (typeof x === 'symbol') {
19 return x.toString();
20 }
21 return inspect(x);
22}

Callers 4

updateIntroJsonFunction · 0.50
updateIntroJsonFunction · 0.50
updateIntroJsonFunction · 0.50
renameBlockFunction · 0.50

Calls

no outgoing calls

Tested by

no test coverage detected