UNPKG

safers

Version:

Safely convert to the desired data and error-free refine values.

35 lines (34 loc) 743 B
import { toString as o } from "./toString.js"; import { isArray as n } from "../utils/isArray.js"; import { isObject as e } from "../utils/isObject.js"; import "../utils/isBoolean.js"; import "../../lib/identifyType-d39b7385.js"; import "../utils/isNumber.js"; import "../utils/isString.js"; function y(r) { if (e(r)) return r; if (r instanceof Map) try { return Object.fromEntries(r); } catch { return {}; } if (r instanceof Set) try { const t = Array.from(r, (i) => [i, i]); return Object.fromEntries(t); } catch { return {}; } if (n(r)) try { return Object.fromEntries(r); } catch { return {}; } return { [o(r)]: r }; } export { y as toObject };