poku
Version:
🐷 Poku makes testing easy for Node.js, Bun, Deno, and you at the same time.
26 lines (25 loc) • 950 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.parseResultType = void 0;
const recurse = (value) => {
if (typeof value === 'undefined' ||
typeof value === 'function' ||
typeof value === 'bigint' ||
typeof value === 'symbol' ||
value instanceof RegExp)
return String(value);
if (Array.isArray(value))
return value.map(recurse);
if (value instanceof Set)
return Array.from(value).map(recurse);
if (value instanceof Map)
return recurse(Object.fromEntries(value));
if (value !== null && typeof value === 'object')
return Object.fromEntries(Object.entries(value).map(([key, val]) => [key, recurse(val)]));
return value;
};
const parseResultType = (type) => {
const result = recurse(type);
return typeof result === 'string' ? result : JSON.stringify(result, null, 2);
};
exports.parseResultType = parseResultType;