* feature(dashboard): add polar / subscription * wip(payments): manage subscription * wip(payments): add free product, faq and some other improvements * fix(root): change node to bundler in tsconfig * wip(payments): display current subscription * feat(dashboard): schedule project for deletion * wip(payments): support custom products/subscriptions * wip(payments): fix polar scripts * wip(payments): add json package to dockerfiles
22 lines
474 B
TypeScript
22 lines
474 B
TypeScript
import superjson from 'superjson';
|
|
|
|
export function getSafeJson<T>(str: string): T | null {
|
|
try {
|
|
return JSON.parse(str);
|
|
} catch (e) {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
export function getSuperJson<T>(str: string): T | null {
|
|
const json = getSafeJson<T>(str);
|
|
if (typeof json === 'object' && json !== null && 'json' in json) {
|
|
return superjson.parse<T>(str);
|
|
}
|
|
return json;
|
|
}
|
|
|
|
export function setSuperJson(str: any): string {
|
|
return superjson.stringify(str);
|
|
}
|