datasquirel/dist/package-shared/utils/ejson.js
Benjamin Toby 186cc76ffb Updates
2025-01-12 18:19:20 +01:00

36 lines
709 B
JavaScript

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
/**
* # EJSON parse string
*/
function parse(string, reviver) {
if (!string)
return undefined;
if (typeof string == "object")
return string;
if (typeof string !== "string")
return undefined;
try {
return JSON.parse(string, reviver);
}
catch (error) {
return undefined;
}
}
/**
* # EJSON stringify object
*/
function stringify(value, replacer, space) {
try {
return JSON.stringify(value, replacer || undefined, space);
}
catch (error) {
return undefined;
}
}
const EJSON = {
parse,
stringify,
};
exports.default = EJSON;