40 lines
439 B
TypeScript
40 lines
439 B
TypeScript
namespace formgen.helpers.json
|
|
{
|
|
|
|
/**
|
|
* @todo handle errors
|
|
*/
|
|
export function decode(
|
|
json : string
|
|
) : unknown
|
|
{
|
|
return JSON.parse(json);
|
|
}
|
|
|
|
|
|
/**
|
|
* @todo handle errors
|
|
*/
|
|
export function encode(
|
|
value : unknown,
|
|
{
|
|
"formatted": formatted = false,
|
|
}
|
|
:
|
|
{
|
|
formatted ?: boolean;
|
|
}
|
|
=
|
|
{
|
|
}
|
|
) : string
|
|
{
|
|
return JSON.stringify(
|
|
value,
|
|
undefined,
|
|
(formatted ? " " : undefined)
|
|
);
|
|
}
|
|
|
|
}
|