UNPKG

@yookue/ts-lang-utils

Version:

Common lang utilities for typescript

16 lines 449 B
import _typeof from "@babel/runtime/helpers/esm/typeof"; import { isPlain } from "../ObjectUtils/isPlain"; export function toJsonString(target) { if (typeof target === 'string' && target.length > 0) { try { var json = JSON.parse(target); if (_typeof(json) === 'object') { return JSON.stringify(json); } } catch (_unused) {} } if (isPlain(target)) { return JSON.stringify(target); } return undefined; }