UNPKG

@polgubau/utils

Version:

A collection of utility functions for TypeScript

44 lines 832 B
// src/parsers/handle-json/handle-json.ts var errorLabel = "parsing error on value: "; function parseJSON(value) { try { if (!value) { return void 0; } return JSON.parse(value ?? ""); } catch { console.error(errorLabel, { value }); throw new Error(errorLabel + value); } } function saveParseJson(value) { try { if (!value) { return void 0; } return JSON.parse(value ?? ""); } catch { console.error(errorLabel, { value }); return void 0; } } function stringify(value) { try { return JSON.stringify(value); } catch { console.error(errorLabel, { value }); return void 0; } } var json = { saveParse: saveParseJson, parse: parseJSON, stringify }; export { json, parseJSON, saveParseJson, stringify }; //# sourceMappingURL=handle-json.mjs.map