UNPKG

@apicart/js-utils

Version:

A small set of useful utilities for easier development

32 lines (23 loc) 449 B
class Json { public isJson(content: any|null): boolean { if (typeof content !== 'string') { return false; } try { JSON.parse(content); } catch (e) { return false; } return true; } public parse(content: any|null): any { return this.isJson(content) ? JSON.parse(content) : {}; } public stringify(data: any): string { return typeof data === 'object' ? JSON.stringify(data) : ''; } } export default new Json();