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

Function format

client/src/utils/format.js:3–19  ·  view source on GitHub ↗
(x)

Source from the content-addressed store, hash-verified

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

Callers 5

format.test.tsFile · 0.90
createErrorFunction · 0.90
formatDateFunction · 0.50
getTodayUsCentralFunction · 0.50
formatDisplayDateFunction · 0.50

Calls

no outgoing calls

Tested by

no test coverage detected