@prefecthq/prefect-ui-library
Version:
This library is the Vue and Typescript component library for [Prefect 2](https://github.com/PrefectHQ/prefect) and [Prefect Cloud 2](https://www.prefect.io/cloud/). _The components and utilities in this project are not meant to be used independently_.
28 lines (23 loc) • 635 B
text/typescript
import { isRecord } from '@/utilities'
type JsonStringify = Parameters<typeof JSON.stringify>
type JsonValue = JsonStringify[0]
type JsonReplacer = JsonStringify[1]
export function stringify(value: JsonValue, replacer?: JsonReplacer): string {
return JSON.stringify(value, replacer, 2)
}
export function isValidJsonRecord(value: unknown): value is string {
try {
const parsed = JSON.parse(value as string)
return isRecord(parsed)
} catch {
return false
}
}
export function isValidJson(value: unknown): value is string {
try {
JSON.parse(value as string)
return true
} catch {
return false
}
}