mirror of
https://github.com/lux-tel/session-desktop.git
synced 2026-10-30 20:33:24 +00:00
17 lines
511 B
TypeScript
17 lines
511 B
TypeScript
function strOrToString(value: unknown): string {
|
|
return typeof value === 'string' ? value : Object.prototype.toString.call(value);
|
|
}
|
|
|
|
/**
|
|
* Returns `JSON.stringify(value)` if that returns a string, otherwise returns a value
|
|
* like `[object Object]` or `[object Undefined]`.
|
|
* Always returns a string, and does not throw.
|
|
*/
|
|
export function reallyJsonStringify(value: unknown): string {
|
|
try {
|
|
return strOrToString(JSON.stringify(value));
|
|
} catch (_err) {
|
|
return strOrToString(undefined);
|
|
}
|
|
}
|